forked from fanruan/demo-tabledata-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.
165 lines
5.1 KiB
165 lines
5.1 KiB
6 years ago
|
package com.fr.plugin.db.redis.ui;
|
||
|
|
||
|
import com.fr.base.BaseUtils;
|
||
|
import com.fr.base.ParameterHelper;
|
||
|
import com.fr.base.TableData;
|
||
|
import com.fr.design.actions.UpdateAction;
|
||
|
import com.fr.design.data.datapane.preview.PreviewTablePane;
|
||
|
import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane;
|
||
|
import com.fr.design.gui.itableeditorpane.ParameterTableModel;
|
||
|
import com.fr.design.gui.itableeditorpane.UITableEditAction;
|
||
|
import com.fr.design.gui.itableeditorpane.UITableEditorPane;
|
||
|
import com.fr.design.gui.itoolbar.UIToolbar;
|
||
|
import com.fr.design.i18n.Toolkit;
|
||
|
import com.fr.design.menu.ToolBarDef;
|
||
|
import com.fr.plugin.db.redis.core.order.OrderValue;
|
||
|
import com.fr.stable.ArrayUtils;
|
||
|
import com.fr.stable.ParameterProvider;
|
||
|
|
||
|
import javax.swing.*;
|
||
|
import java.awt.*;
|
||
|
import java.awt.event.ActionEvent;
|
||
|
import java.util.ArrayList;
|
||
|
|
||
|
/**
|
||
|
* @author richie
|
||
|
* @version 10.0
|
||
|
* Created by richie on 2019-03-18
|
||
|
*/
|
||
|
public abstract class RedisBaseTableDataPane<T extends TableData> extends AbstractTableDataPane<T> {
|
||
|
|
||
|
private static final String PREVIEW_BUTTON = Toolkit.i18nText("Plugin-Redis_Preview");
|
||
|
private static final String REFRESH_BUTTON = Toolkit.i18nText("Plugin-Redis_Refresh");
|
||
|
|
||
|
protected RedisDBConnectionChosePane chosePane;
|
||
|
|
||
|
protected UITableEditorPane<ParameterProvider> editorPane;
|
||
|
|
||
|
|
||
|
public RedisBaseTableDataPane() {
|
||
|
this.setLayout(new BorderLayout(4, 4));
|
||
|
|
||
|
Box box = new Box(BoxLayout.Y_AXIS);
|
||
|
|
||
|
JPanel northPane = new JPanel(new BorderLayout(4, 4));
|
||
|
JToolBar editToolBar = createToolBar();
|
||
|
northPane.add(editToolBar, BorderLayout.CENTER);
|
||
|
northPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 6, 0));
|
||
|
|
||
|
|
||
|
ParameterTableModel model = new ParameterTableModel() {
|
||
|
@Override
|
||
|
public UITableEditAction[] createAction() {
|
||
|
return ArrayUtils.add(super.createDBTableAction(), new RedisBaseTableDataPane.RefreshAction());
|
||
|
}
|
||
|
};
|
||
|
editorPane = new UITableEditorPane<ParameterProvider>(model);
|
||
|
|
||
|
box.add(northPane);
|
||
|
|
||
|
box.add(createQueryPane());
|
||
|
|
||
|
box.add(editorPane);
|
||
|
|
||
|
JPanel sqlSplitPane = new JPanel(new BorderLayout(4, 4));
|
||
|
sqlSplitPane.add(box, BorderLayout.CENTER);
|
||
|
|
||
|
chosePane = new RedisDBConnectionChosePane();
|
||
|
chosePane.setPreferredSize(new Dimension(200, 200));
|
||
|
sqlSplitPane.add(chosePane, BorderLayout.WEST);
|
||
|
|
||
|
this.add(sqlSplitPane, BorderLayout.CENTER);
|
||
|
}
|
||
|
|
||
|
private JToolBar createToolBar() {
|
||
|
ToolBarDef toolBarDef = new ToolBarDef();
|
||
|
toolBarDef.addShortCut(new RedisBaseTableDataPane.PreviewAction());
|
||
|
UIToolbar editToolBar = ToolBarDef.createJToolBar();
|
||
|
toolBarDef.updateToolBar(editToolBar);
|
||
|
return editToolBar;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
protected String title4PopupWindow() {
|
||
|
return Toolkit.i18nText("Plugin-Redis_Query");
|
||
|
}
|
||
|
|
||
|
protected abstract JComponent createQueryPane();
|
||
|
|
||
|
protected abstract String[] paramTexts();
|
||
|
|
||
|
public abstract OrderValue getOrderValue();
|
||
|
|
||
|
|
||
|
private void refresh() {
|
||
|
String[] paramTexts = paramTexts();
|
||
|
|
||
|
ParameterProvider[] parameters = ParameterHelper.analyze4Parameters(paramTexts, false);
|
||
|
|
||
|
ParameterProvider[] providers = getOrderValue().analyze4Parameters();
|
||
|
|
||
|
editorPane.populate(ArrayUtils.addAll(parameters, providers));
|
||
|
}
|
||
|
|
||
|
|
||
|
private void checkParameter() {
|
||
|
String[] paramTexts = paramTexts();
|
||
|
|
||
|
ParameterProvider[] parameters = ParameterHelper.analyze4Parameters(paramTexts, false);
|
||
|
parameters = ArrayUtils.addAll(parameters, getOrderValue().analyze4Parameters());
|
||
|
|
||
|
if (parameters.length < 1 && editorPane.update().size() < 1) {
|
||
|
return;
|
||
|
}
|
||
|
boolean isIn = true;
|
||
|
java.util.List<ParameterProvider> list = editorPane.update();
|
||
|
java.util.List<String> name = new ArrayList<String>();
|
||
|
for (int i = 0; i < list.size(); i++) {
|
||
|
name.add(list.get(i).getName());
|
||
|
}
|
||
|
for (int i = 0; i < parameters.length; i++) {
|
||
|
if (!name.contains(parameters[i].getName())) {
|
||
|
isIn = false;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if (list.size() == parameters.length && isIn) {
|
||
|
return;
|
||
|
}
|
||
|
refresh();
|
||
|
}
|
||
|
|
||
|
|
||
|
private class PreviewAction extends UpdateAction {
|
||
|
public PreviewAction() {
|
||
|
this.setName(PREVIEW_BUTTON);
|
||
|
this.setMnemonic('P');
|
||
|
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_file/preview.png"));
|
||
|
}
|
||
|
|
||
|
public void actionPerformed(ActionEvent evt) {
|
||
|
checkParameter();
|
||
|
PreviewTablePane.previewTableData(RedisBaseTableDataPane.this.updateBean());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
protected class RefreshAction extends UITableEditAction {
|
||
|
public RefreshAction() {
|
||
|
this.setName(REFRESH_BUTTON);
|
||
|
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/control/refresh.png"));
|
||
|
}
|
||
|
|
||
|
public void actionPerformed(ActionEvent e) {
|
||
|
refresh();
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void checkEnabled() {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
}
|