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.
162 lines
5.1 KiB
162 lines
5.1 KiB
package com.fr.plugin.db.redis.ui; |
|
|
|
import com.fanruan.api.cal.ParameterKit; |
|
import com.fanruan.api.design.DesignKit; |
|
import com.fanruan.api.design.ui.action.UpdateAction; |
|
import com.fanruan.api.design.ui.component.UIToolbar; |
|
import com.fanruan.api.design.ui.component.table.UITableEditorPane; |
|
import com.fanruan.api.design.ui.component.table.action.UITableEditAction; |
|
import com.fanruan.api.design.ui.component.table.model.ParameterTableModel; |
|
import com.fanruan.api.design.ui.toolbar.ToolBarDef; |
|
import com.fanruan.api.design.work.AbstractTableDataPane; |
|
import com.fanruan.api.util.ArrayKit; |
|
import com.fanruan.api.util.IOKit; |
|
import com.fr.base.TableData; |
|
import com.fr.plugin.db.redis.core.order.OrderValue; |
|
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 = DesignKit.i18nText("Plugin-Redis_Preview"); |
|
private static final String REFRESH_BUTTON = DesignKit.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 new UITableEditAction[]{new MoveUpAction(), new MoveDownAction(), 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 DesignKit.i18nText("Plugin-Redis_Query"); |
|
} |
|
|
|
protected abstract JComponent createQueryPane(); |
|
|
|
protected abstract String[] paramTexts(); |
|
|
|
public abstract OrderValue getOrderValue(); |
|
|
|
|
|
private void refresh() { |
|
String[] paramTexts = paramTexts(); |
|
|
|
ParameterProvider[] parameters = ParameterKit.analyze4Parameters(paramTexts, false); |
|
|
|
ParameterProvider[] providers = getOrderValue().analyze4Parameters(); |
|
|
|
editorPane.populate(ArrayKit.addAll(parameters, providers)); |
|
} |
|
|
|
|
|
private void checkParameter() { |
|
String[] paramTexts = paramTexts(); |
|
|
|
ParameterProvider[] parameters = ParameterKit.analyze4Parameters(paramTexts, false); |
|
parameters = ArrayKit.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(IOKit.readIcon("/com/fr/design/images/m_file/preview.png")); |
|
} |
|
|
|
public void actionPerformed(ActionEvent evt) { |
|
checkParameter(); |
|
DesignKit.previewTableData(RedisBaseTableDataPane.this.updateBean()); |
|
} |
|
} |
|
|
|
|
|
protected class RefreshAction extends UITableEditAction { |
|
public RefreshAction() { |
|
this.setName(REFRESH_BUTTON); |
|
this.setSmallIcon(IOKit.readIcon("/com/fr/design/images/control/refresh.png")); |
|
} |
|
|
|
public void actionPerformed(ActionEvent e) { |
|
refresh(); |
|
} |
|
|
|
@Override |
|
public void checkEnabled() { |
|
} |
|
} |
|
|
|
|
|
}
|
|
|