redis数据集插件。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

143 lines
3.8 KiB

package com.fr.plugin.db.redis.ui.value;
import com.fanruan.api.design.DesignKit;
import com.fanruan.api.design.ui.component.UITextField;
import com.fanruan.api.design.util.GUICoreKit;
import com.fanruan.api.design.work.formula.FormulaUIKit;
import com.fr.base.BaseFormula;
import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.editor.editor.Editor;
import com.fr.design.formula.UIFormula;
import com.fr.plugin.db.redis.core.order.impl.FormulaOrderValue;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class FormulaEditor extends Editor<FormulaOrderValue> {
private UITextField currentTextField;
private FormulaEditor.ShowPaneListener listener = new FormulaEditor.ShowPaneListener();
private FormulaOrderValue orderValue = new FormulaOrderValue(BaseFormula.createFormulaBuilder().build());
/**
* Constructor.
*/
public FormulaEditor() {
this(DesignKit.i18nText("Plugin-Redis_Formula"));
}
public FormulaEditor(String name) {
this(name, null);
}
public FormulaEditor(String name, FormulaOrderValue formula) {
if (formula != null) {
this.orderValue = formula;
}
this.setLayout(new BorderLayout());
JPanel editPane = GUICoreKit.createBorderLayoutPane();
currentTextField = new UITextField(28);
currentTextField.setText(this.orderValue.getValue().getContent());
editPane.add(currentTextField, BorderLayout.CENTER);
currentTextField.setEditable(false);
currentTextField.addMouseListener(listener);
this.add(editPane, BorderLayout.CENTER);
this.setName(name);
}
private class ShowPaneListener extends MouseAdapter {
public void mousePressed(MouseEvent e) {
if (currentTextField.isEnabled()) {
showFormulaPane();
}
}
}
public void setColumns(int i) {
this.currentTextField.setColumns(i);
}
/**
* 选中时弹出公å¼<EFBFBD>编辑框
*/
public void selected() {
showFormulaPane();
}
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
currentTextField.setEnabled(enabled);
}
protected void showFormulaPane() {
final UIFormula formulaPane = FormulaUIKit.createFormulaPaneWhenReserveFormula();
formulaPane.populate(orderValue.getValue());
formulaPane.showLargeWindow(SwingUtilities.getWindowAncestor(FormulaEditor.this), new DialogActionAdapter() {
@Override
public void doOk() {
orderValue.setValue(formulaPane.update());
setValue(orderValue);
fireStateChanged();
}
}).setVisible(true);
}
/**
* Return the value of the CellEditor.
*/
@Override
public FormulaOrderValue getValue() {
return orderValue;
}
/**
* Set the value to the CellEditor.
*/
@Override
public void setValue(FormulaOrderValue value) {
if (value == null) {
value = new FormulaOrderValue(BaseFormula.createFormulaBuilder().build());
}
this.orderValue = value;
currentTextField.setText(value.toString());
}
public String getIconName() {
return "type_formula";
}
/**
* object是å<EFBFBD>¦æ˜¯å…¬å<EFBFBD>¸ç±»åž‹å¯¹è±¡
*
* @param object 需判断的对象
* @return 是公å¼<EFBFBD>类型则返回true
*/
public boolean accept(Object object) {
return object instanceof FormulaOrderValue;
}
/**
* é‡<EFBFBD>ç½®
*/
public void reset() {
currentTextField.setText("=");
orderValue = new FormulaOrderValue(BaseFormula.createFormulaBuilder().build());
}
/**
* 清楚数æ<EFBFBD>®
*/
public void clearData() {
reset();
}
}