Browse Source

Pull request #3549: REPORT-46915 esd-design内置

Merge in DESIGN/design from ~RINOUX/design:feature/x to feature/x

* commit 'db43d776c7b83fc17c71489f7032db2713faa459':
  esd-design内置融合
  REPORT-46915 内置
research/11.0
ju|剧浩宇 4 years ago
parent
commit
f7592fa3e7
  1. 154
      designer-base/src/main/java/com/fr/design/data/DesignerStrategyConfigUtils.java
  2. 225
      designer-base/src/main/java/com/fr/design/data/datapane/ESDStrategyConfigPane.java
  3. 747
      designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java
  4. 500
      designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/DBTableDataPane.java
  5. BIN
      designer-base/src/main/resources/com/fr/design/images/control/batch_esd_off.png
  6. BIN
      designer-base/src/main/resources/com/fr/design/images/control/batch_esd_on.png

154
designer-base/src/main/java/com/fr/design/data/DesignerStrategyConfigUtils.java

@ -0,0 +1,154 @@
package com.fr.design.data;
import com.fr.base.io.IOFile;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.mainframe.JTemplate;
import com.fr.esd.core.strategy.config.StrategyConfig;
import com.fr.esd.core.strategy.config.StrategyConfigHelper;
import com.fr.esd.core.strategy.persistence.StrategyConfigsAttr;
import com.fr.esd.event.DSMapping;
import com.fr.esd.event.DsNameTarget;
import com.fr.esd.event.StrategyEventsNotifier;
import com.fr.esd.event.xml.XMLSavedHook;
import com.fr.file.FILE;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils;
import com.fr.workspace.WorkContext;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* @author rinoux
* @version 10.0
* Created by rinoux on 2020/10/28
*/
public class DesignerStrategyConfigUtils {
/**
* 获取当前编辑模版的数据集缓存配置属性
*
* @return
*/
private static StrategyConfigsAttr getStrategyConfigsAttr() {
StrategyConfigsAttr attr;
JTemplate<?, ?> jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
if (jTemplate != null) {
IOFile ioFile = (IOFile) jTemplate.getTarget();
attr = ioFile.getAttrMark(StrategyConfigsAttr.ATTR_MARK);
if (attr == null) {
attr = new StrategyConfigsAttr();
ioFile.addAttrMark(attr);
}
//新建模版此时不存在,不需要注册钩子
if (attr.getXmlSavedHook() == null && WorkContext.getWorkResource().exist(jTemplate.getPath())) {
attr.setXmlSavedHook(new StrategyConfigsAttrSavedHook(jTemplate.getPath(), attr));
}
return attr;
} else {
throw new IllegalStateException("[ESD]No editing template found.");
}
}
/**
* 当前编辑的模版是否被批量开启
*
* @return
*/
public static boolean isEditingTemplateRecommended() {
JTemplate<?, ?> jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
if (jTemplate != null) {
FILE file = jTemplate.getEditingFILE();
if (file != null) {
String path = file.getPath();
return StrategyConfigHelper.recommended(path);
}
}
return false;
}
/**
* 获取模版数据集配置
*
* @param dsName
* @return
*/
public static StrategyConfig getStrategyConfig(String dsName) {
return getStrategyConfigsAttr().getStrategyConfig(dsName);
}
/**
* 移除模版数据集配置
*
* @param dsName
* @return
*/
public static StrategyConfig removeStrategyConfig(String dsName) {
return getStrategyConfigsAttr().removeStrategyConfig(dsName);
}
/**
* 添加模版数据集配置
*
* @param strategyConfig
*/
public static void addStrategyConfig(StrategyConfig strategyConfig) {
getStrategyConfigsAttr().addStrategyConfig(strategyConfig);
}
private static class StrategyConfigsAttrSavedHook implements XMLSavedHook<StrategyConfigsAttr> {
private static final long serialVersionUID = -8843201977112289321L;
private final String tplPath;
private final Map<String, StrategyConfig> origStrategyConfigs;
public StrategyConfigsAttrSavedHook(String tplPath, StrategyConfigsAttr raw) {
this.tplPath = tplPath;
this.origStrategyConfigs = new HashMap<>();
this.initOrigStrategyConfigs(raw);
}
private void initOrigStrategyConfigs(StrategyConfigsAttr raw) {
origStrategyConfigs.clear();
raw.getStrategyConfigs().forEach((k, v) -> {
try {
origStrategyConfigs.put(k, v.clone());
} catch (CloneNotSupportedException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
});
}
@Override
public void doAfterSaved(StrategyConfigsAttr saved) {
FineLoggerFactory.getLogger().info("[ESD]Write StrategyConfigsAttr done, now check change.");
Set<String> dsNames = new HashSet<>();
dsNames.addAll(origStrategyConfigs.keySet());
dsNames.addAll(saved.getStrategyConfigs().keySet());
if (StringUtils.isNotEmpty(tplPath)) {
dsNames.forEach(dsName -> {
if (StringUtils.isNotEmpty(dsName)) {
StrategyEventsNotifier.compareAndFireConfigEvents(origStrategyConfigs.get(dsName), saved.getStrategyConfig(dsName), new DSMapping(tplPath, new DsNameTarget(dsName)));
}
});
}
initOrigStrategyConfigs(saved);
}
}
}

225
designer-base/src/main/java/com/fr/design/data/datapane/ESDStrategyConfigPane.java

@ -0,0 +1,225 @@
package com.fr.design.data.datapane;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.gui.ibutton.UIRadioButton;
import com.fr.design.gui.icheckbox.UICheckBox;
import com.fr.design.gui.ilable.ActionLabel;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.esd.common.CacheConstants;
import com.fr.esd.core.strategy.config.StrategyConfig;
import com.fr.esd.core.strategy.config.StrategyConfigHelper;
import com.fr.esd.util.Utils;
import com.fr.locale.InterProviderFactory;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils;
import javax.swing.AbstractAction;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Desktop;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* @author rinoux
* @version 10.0
* Created by rinoux on 2020/7/22
*/
public class ESDStrategyConfigPane extends BasicBeanPane<StrategyConfig> {
private UIRadioButton selectAutoUpdate;
private UIRadioButton selectBySchema;
private UICheckBox shouldEvolve;
private UILabel updateIntervalCheckTips;
private UITextField updateInterval;
private UITextField schemaTime;
private ActionLabel actionLabel;
private UILabel schemaTimeCheckTips;
private final boolean global;
private StrategyConfig strategyConfig;
private static final String CRON_HELP_URL = "http://help.fanruan.com/finereport/doc-view-693.html";
public ESDStrategyConfigPane(boolean global) {
this.global = global;
init();
}
private void init() {
setLayout(FRGUIPaneFactory.createM_BorderLayout());
this.selectAutoUpdate = new UIRadioButton(InterProviderFactory.getDesignI18nProvider().i18nText("Fine-Design_ESD_Every_Interval"));
this.updateInterval = new UITextField(4);
this.shouldEvolve = new UICheckBox(InterProviderFactory.getDesignI18nProvider().i18nText("Fine-Design_ESD_Auto_Evolved_Strategy"), false);
this.shouldEvolve.setEnabled(false);
this.updateIntervalCheckTips = new UILabel(InterProviderFactory.getDesignI18nProvider().i18nText("Fine-Design_ESD_Error_Interval_Format"));
this.updateIntervalCheckTips.setForeground(Color.RED);
this.updateIntervalCheckTips.setVisible(false);
this.selectBySchema = new UIRadioButton(InterProviderFactory.getDesignI18nProvider().i18nText("Fine-Design_ESD_Cron"));
this.schemaTime = new UITextField(10);
this.schemaTimeCheckTips = new UILabel(InterProviderFactory.getDesignI18nProvider().i18nText("Fine-Design_ESD_Error_Time_Format"));
this.schemaTimeCheckTips.setVisible(false);
this.schemaTimeCheckTips.setForeground(Color.RED);
this.selectAutoUpdate.addActionListener(new AbstractAction() {
public void actionPerformed(ActionEvent e) {
ESDStrategyConfigPane.this.selectBySchema.setSelected(!ESDStrategyConfigPane.this.selectAutoUpdate.isSelected());
ESDStrategyConfigPane.this.schemaTime.setEnabled(false);
ESDStrategyConfigPane.this.updateInterval.setEnabled(true);
ESDStrategyConfigPane.this.shouldEvolve.setEnabled(true);
}
});
this.selectBySchema.addActionListener(new AbstractAction() {
public void actionPerformed(ActionEvent e) {
ESDStrategyConfigPane.this.selectAutoUpdate.setSelected(!ESDStrategyConfigPane.this.selectBySchema.isSelected());
ESDStrategyConfigPane.this.schemaTime.setEnabled(true);
ESDStrategyConfigPane.this.updateInterval.setEnabled(false);
ESDStrategyConfigPane.this.shouldEvolve.setEnabled(false);
}
});
JPanel pane = FRGUIPaneFactory.createVerticalTitledBorderPane(InterProviderFactory.getDesignI18nProvider().i18nText("Fine-Design_ESD_Cache_Update_Strategy"));
add(pane, BorderLayout.NORTH);
JPanel row1 = GUICoreUtils.createFlowPane(new Component[]{
this.selectAutoUpdate,
this.updateInterval,
new UILabel(InterProviderFactory.getDesignI18nProvider().i18nText("Fine-Design_ESD_Minute_Update_Cache")),
this.shouldEvolve,
this.updateIntervalCheckTips
}, 0, 5);
pane.add(row1);
ActionLabel actionLabel = new ActionLabel(InterProviderFactory.getDesignI18nProvider().i18nText("Fine-Design_ESD_Cron_Help"));
actionLabel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
Desktop.getDesktop().browse(new URI(CRON_HELP_URL));
} catch (Exception exp) {
FineLoggerFactory.getLogger().error(exp.getMessage(), e);
}
}
});
JPanel row2 = GUICoreUtils.createFlowPane(new Component[]{
this.selectBySchema,
this.schemaTime,
actionLabel,
this.schemaTimeCheckTips
}, 0, 5);
pane.add(row2);
}
public void populateBean(StrategyConfig ob) {
if (ob == null && !global) {
ob = StrategyConfigHelper.createStrategyConfig(true, false, true);
}
this.strategyConfig = ob;
this.updateInterval.setText(ob.getUpdateInterval() <= 0 ? "0" : String.valueOf(ob.getUpdateInterval() / (double) CacheConstants.MILLIS_OF_MINUTE));
this.schemaTime.setText(StringUtils.join(",", ob.getUpdateSchema().toArray(new String[0])));
this.shouldEvolve.setSelected(ob.shouldEvolve());
this.selectBySchema.setSelected(ob.isScheduleBySchema());
this.selectAutoUpdate.setSelected(!ob.isScheduleBySchema());
if (global) {
//使用全局配置,禁用面板编辑
disablePane();
} else {
setSchemaEnable(!this.selectAutoUpdate.isSelected());
}
}
private void disablePane() {
this.selectAutoUpdate.setEnabled(false);
this.updateInterval.setEnabled(false);
this.shouldEvolve.setEnabled(false);
this.selectBySchema.setEnabled(false);
this.schemaTime.setEnabled(false);
}
private void setSchemaEnable(boolean enable) {
this.updateInterval.setEnabled(!enable);
this.shouldEvolve.setEnabled(!enable);
this.schemaTime.setEnabled(enable);
}
public StrategyConfig updateBean() {
StrategyConfig config = null;
if (!this.global) {
try {
//这里是new的config
config = this.strategyConfig.clone();
if (this.selectBySchema.isSelected()) {
List<String> schemaTimes = new ArrayList<>();
String text = this.schemaTime.getText();
if (Utils.checkUpdateTimeSchema(text)) {
if (Utils.isCronExpression(text)) {
schemaTimes.add(text);
} else {
Collections.addAll(schemaTimes, text.split(","));
}
} else {
this.schemaTimeCheckTips.setVisible(true);
throw new IllegalArgumentException("update schema time format error.");
}
config.setScheduleBySchema(true);
config.setUpdateSchema(schemaTimes);
} else {
String interval = this.updateInterval.getText();
if (checkUpdateInterval(interval)) {
long intervalMillis = StringUtils.isEmpty(interval) ? 0 : (long) (Double.parseDouble(interval) * CacheConstants.MILLIS_OF_MINUTE);
config.setUpdateInterval(intervalMillis);
} else {
this.updateIntervalCheckTips.setVisible(true);
throw new IllegalArgumentException("Error update interval format.");
}
config.setShouldEvolve(this.shouldEvolve.isSelected());
config.setScheduleBySchema(false);
}
} catch (CloneNotSupportedException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
return config;
}
private boolean checkUpdateInterval(String intervalValue) {
try {
return !StringUtils.isEmpty(intervalValue) && !(Double.parseDouble(intervalValue) <= 0);
} catch (NumberFormatException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return false;
}
protected String title4PopupWindow() {
return InterProviderFactory.getDesignI18nProvider().i18nText("Fine-Design_ESD_Cache_Strategy_Config_Title");
}
}

747
designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java

@ -2,6 +2,7 @@ package com.fr.design.data.datapane;
import com.fr.base.TableData;
import com.fr.data.TableDataSource;
import com.fr.data.impl.DBTableData;
import com.fr.data.impl.TableDataSourceDependent;
import com.fr.design.DesignModelAdapter;
import com.fr.design.ExtraDesignClassManager;
@ -10,52 +11,67 @@ import com.fr.design.constants.UIConstants;
import com.fr.design.data.BasicTableDataTreePane;
import com.fr.design.data.BasicTableDataUtils;
import com.fr.design.data.DesignTableDataManager;
import com.fr.design.data.DesignerStrategyConfigUtils;
import com.fr.design.data.tabledata.StoreProcedureWorkerListener;
import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane;
import com.fr.design.data.tabledata.tabledatapane.DBTableDataPane;
import com.fr.design.data.tabledata.wrapper.AbstractTableDataWrapper;
import com.fr.design.data.tabledata.wrapper.TableDataWrapper;
import com.fr.design.data.tabledata.wrapper.TemplateTableDataWrapper;
import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.BasicPane;
import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.fun.TableDataPaneProcessor;
import com.fr.design.gui.ibutton.UIHeadGroup;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.gui.itoolbar.UIToolbar;
import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode;
import com.fr.design.i18n.Toolkit;
import com.fr.design.icon.IconPathConstants;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.menu.LineSeparator;
import com.fr.design.menu.MenuDef;
import com.fr.design.menu.SeparatorDef;
import com.fr.design.menu.ToolBarDef;
import com.fr.esd.core.strategy.config.StrategyConfig;
import com.fr.esd.core.strategy.config.StrategyConfigHelper;
import com.fr.esd.event.DSMapping;
import com.fr.esd.event.DsNameTarget;
import com.fr.esd.event.StrategyEventsNotifier;
import com.fr.general.ComparatorUtils;
import com.fr.general.GeneralContext;
import com.fr.general.IOUtils;
import com.fr.general.NameObject;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.injectable.PluginModule;
import com.fr.plugin.manage.PluginFilter;
import com.fr.plugin.observer.PluginEvent;
import com.fr.plugin.observer.PluginEventListener;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.core.PropertyChangeAdapter;
import org.jetbrains.annotations.NotNull;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import javax.swing.ToolTipManager;
import javax.swing.tree.TreePath;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.dnd.DnDConstants;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
public class TableDataTreePane extends BasicTableDataTreePane {
private static TableDataTreePane singleton = new TableDataTreePane();
private static final TableDataTreePane singleton = new TableDataTreePane();
public static final int PLUGIN_LISTENER_PRIORITY = 1;
@ -77,31 +93,42 @@ public class TableDataTreePane extends BasicTableDataTreePane {
}
private TableDataSourceOP op;
private TableDataTree dataTree;
private TableDataTree tableDataTree;
private EditAction editAction;
private RemoveAction removeAction;
private EsdOnAction esdAction;
private EsdOffAction esdOffAction;
private PreviewTableDataAction previewTableDataAction;
private TableDataTreePane() {
initPane();
}
private void initPane() {
this.setLayout(new BorderLayout(4, 0));
this.setBorder(null);
dataTree = new TableDataTree();
ToolTipManager.sharedInstance().registerComponent(dataTree);
//TableDataTree
tableDataTree = new TableDataTree();
ToolTipManager.sharedInstance().registerComponent(tableDataTree);
ToolTipManager.sharedInstance().setDismissDelay(3000);
ToolTipManager.sharedInstance().setInitialDelay(0);
addMenuDef = new MenuDef(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Action_Add"));
addMenuDef.setIconPath(IconPathConstants.ADD_POPMENU_ICON_PATH);
addMenuDef = new MenuDef(Toolkit.i18nText("Fine-Design_Basic_Action_Add"));
addMenuDef.setIconPath(IconPathConstants.ADD_POPMENU_ICON_PATH);
createAddMenuDef();
// 创建插件监听
createPluginListener();
editAction = new EditAction();
removeAction = new RemoveAction();
previewTableDataAction = new PreviewTableDataAction(dataTree);
previewTableDataAction = new PreviewTableDataAction(tableDataTree);
connectionTableAction = new ConnectionTableAction();
esdAction = new EsdOnAction();
esdOffAction = new EsdOffAction();
ToolBarDef toolbarDef = new ToolBarDef();
toolbarDef.addShortCut(addMenuDef, SeparatorDef.DEFAULT, editAction, removeAction, SeparatorDef.DEFAULT, previewTableDataAction, connectionTableAction);
toolbarDef.addShortCut(addMenuDef, SeparatorDef.DEFAULT, editAction, removeAction, SeparatorDef.DEFAULT, previewTableDataAction, connectionTableAction, esdAction, esdOffAction);
UIToolbar toolBar = ToolBarDef.createJToolBar();
toolBar.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIConstants.TOOLBAR_BORDER_COLOR));
toolBar.setBorderPainted(true);
@ -111,198 +138,188 @@ public class TableDataTreePane extends BasicTableDataTreePane {
toolbarPane.add(toolBar, BorderLayout.CENTER);
this.add(toolbarPane, BorderLayout.NORTH);
UIScrollPane scrollPane = new UIScrollPane(dataTree);
UIScrollPane scrollPane = new UIScrollPane(tableDataTree);
scrollPane.setBorder(null);
initbuttonGroup();
initButtonGroup();
JPanel jPanel = new JPanel(new BorderLayout(0, 0));
JPanel buttonPane = new JPanel(new GridLayout());
buttonPane.add(buttonGroup, BorderLayout.CENTER);
jPanel.add(buttonPane, BorderLayout.NORTH);
jPanel.add(scrollPane, BorderLayout.CENTER);
this.add(jPanel, BorderLayout.CENTER);
dataTree.addMouseListener(new MouseAdapter() {
tableDataTree.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
checkButtonEnabled();
}
});
dataTree.addKeyListener(getTableTreeNodeListener(editAction, previewTableDataAction, removeAction, op, dataTree));
tableDataTree.addKeyListener(getTableTreeNodeListener(editAction, previewTableDataAction, removeAction, op, tableDataTree));
// TreeCellEditor
dataTree.setEditable(true);
TableDataTreeCellEditor treeCellEditor = new TableDataTreeCellEditor(new UITextField(), dataTree, this);
tableDataTree.setEditable(true);
TableDataTreeCellEditor treeCellEditor = new TableDataTreeCellEditor(new UITextField(), tableDataTree, this);
treeCellEditor.addCellEditorListener(treeCellEditor);
dataTree.setCellEditor(treeCellEditor);
new TableDataTreeDragSource(dataTree, DnDConstants.ACTION_COPY);
tableDataTree.setCellEditor(treeCellEditor);
new TableDataTreeDragSource(tableDataTree, DnDConstants.ACTION_COPY);
checkButtonEnabled();
}
private void createPluginListener() {
/**
* 刷新
*/
@Override
public void refreshDockingView() {
populate(new TableDataSourceOP(tc));
this.checkButtonEnabled();
}
//菜单栏监听
GeneralContext.listenPluginRunningChanged(new PluginEventListener(PLUGIN_LISTENER_PRIORITY) {
@Override
public void on(PluginEvent event) {
addMenuDef.clearShortCuts();
createAddMenuDef();
public final void createAddMenuDef() {
TableDataNameObjectCreator[] creators = TableDataCreatorProducer.getInstance().createReportTableDataCreator();
for (final TableDataNameObjectCreator creator : creators) {
if (creator.shouldInsertSeparator()) {
addMenuDef.addShortCut(new LineSeparator());
}
}, new PluginFilter() {
addMenuDef.addShortCut(new AddAction() {
@Override
public boolean accept(PluginContext context) {
return context.contain(PluginModule.ExtraDesign);
protected String getTDName() {
return creator.menuName();
}
});
}
protected void checkButtonEnabled() {
super.checkButtonEnabled(editAction, previewTableDataAction, removeAction, op, dataTree);
@Override
protected Icon getTDIcon() {
return creator.menuIcon();
}
/**
* 刷新
*/
public void refreshDockingView() {
populate(new TableDataSourceOP(tc));
this.checkButtonEnabled();
@Override
protected String getNamePrefix() {
return creator.getPrefix();
}
protected void initbuttonGroup() {
// Icon[] iconArray = {BaseUtils.readIcon("/com/fr/design/images/data/datasource.png"), BaseUtils.readIcon("/com/fr/design/images/data/dock/serverdatabase.png")};
final Integer[] modeArray = {TEMPLATE_TABLE_DATA, SERVER_TABLE_DATA};
String[] textArray = {com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Tabledata_Source_Type_Template"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_DS_Server_TableData")};
buttonGroup = new UIHeadGroup(textArray) {
public void tabChanged(int index) {
if (op != null) {
op.setDataMode(modeArray[buttonGroup.getSelectedIndex()]);
addMenuDef.setEnabled(modeArray[buttonGroup.getSelectedIndex()] == TEMPLATE_TABLE_DATA ? true : false);
refreshDockingView();
@Override
protected TemplateTableDataWrapper getTableDataInstance() {
TableData tableData = (TableData) creator.createObject();
//新建的DBTableData单独换为DBTableData
if (tableData instanceof DBTableData) {
tableData = new DBTableData();
String dsName = createDsName(creator.getPrefix());
((DBTableData) tableData).setDsName(dsName);
} else {
// TODO: 2020/11/10 后期支持其它数据集,这里转化可以不用侵入修改TableDataCreatorProducer
}
return new TemplateTableDataWrapper(tableData);
}
});
}
};
buttonGroup.setNeedLeftRightOutLine(false);
}
/**
* 编辑面板
*
* @param uPanel 面板
* @param tableDataPane 面板
* @param originalName 原始名字
*/
public void dgEdit(final AbstractTableDataPane<?> uPanel, String originalName, boolean isUpdate) {
uPanel.addStoreProcedureWorkerListener(new StoreProcedureWorkerListener() {
@Override
public void dgEdit(final AbstractTableDataPane<?> tableDataPane, String originalName, boolean isUpdate) {
tableDataPane.addStoreProcedureWorkerListener(new StoreProcedureWorkerListener() {
public void fireDoneAction() {
if (dataTree.getSelectionPath() == null) {
dataTree.refresh();
if (tableDataTree.getSelectionPath() == null) {
tableDataTree.refresh();
} else {
Object object = dataTree.getSelectionPath().getLastPathComponent();
int[] rows = dataTree.getSelectionRows();
dataTree.refreshChildByName(object.toString());
dataTree.setSelectionRows(rows);
Object object = tableDataTree.getSelectionPath().getLastPathComponent();
int[] rows = tableDataTree.getSelectionRows();
tableDataTree.refreshChildByName(object.toString());
tableDataTree.setSelectionRows(rows);
}
}
});
final BasicPane.NamePane nPanel = uPanel.asNamePane();
nPanel.setObjectName(originalName);
final NamePane tdNamePanel = tableDataPane.asNamePane();
tdNamePanel.setObjectName(originalName);
final String oldName = originalName;
final BasicDialog dg;
allDSNames = DesignTableDataManager.getAllDSNames(tc.getBook());
dg = nPanel.showLargeWindow(SwingUtilities.getWindowAncestor(TableDataTreePane.this), new DialogActionAdapter() {
final BasicDialog dg = tdNamePanel.showLargeWindow(SwingUtilities.getWindowAncestor(TableDataTreePane.this), new DialogActionAdapter() {
@Override
public void doOk() {
DesignTableDataManager.setThreadLocal(DesignTableDataManager.NO_PARAMETER);
tc.renameTableData(oldName, nPanel.getObjectName(), false);
tc.renameTableData(oldName, tdNamePanel.getObjectName(), false);
TableDataSource tds = tc.getBook();
TableData td = uPanel.updateBean();
TableData td = tableDataPane.updateBean();
if (td instanceof TableDataSourceDependent) {
((TableDataSourceDependent) td).setTableDataSource(tds);
}
String tdName = nPanel.getObjectName();
tds.putTableData(tdName, td);
Map<String, String> map = new HashMap<String, String>();
if (!ComparatorUtils.equals(oldName, tdName)) {
map.put(oldName, tdName);
}
fireDSChanged(map);
tc.fireTargetModified();
tc.parameterChanged();
int[] rows = dataTree.getSelectionRows();
dataTree.refreshChildByName(tdName);
dataTree.setSelectionRows(rows);
}
});
nPanel.addPropertyChangeListener(new PropertyChangeAdapter() {
@Override
public void propertyChange() {
doPropertyChange(dg, nPanel, oldName);
}
});
dg.setVisible(true);
}
String tdName = tdNamePanel.getObjectName();
private class EditAction extends UpdateAction {
public EditAction() {
this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Edit"));
this.setMnemonic('E');
this.setSmallIcon("/com/fr/design/images/control/edit");
}
public void actionPerformed(ActionEvent e) {
final NameObject selectedNO = dataTree.getSelectedNameObject();
if (selectedNO == null) {
return;
//模版还没保存的时候不知道后缀,不能设置到策略配置里面
if (tableDataPane instanceof DBTableDataPane) {
StrategyConfig editingConfig = ((DBTableDataPane) tableDataPane).updateStrategyConfig();
if (editingConfig != null) {
editingConfig.setDsName(tdName);
if (!ComparatorUtils.equals(oldName, tdName)) {
//重命名
DesignerStrategyConfigUtils.removeStrategyConfig(oldName);
}
DesignTableDataManager.removeSelectedColumnNames(selectedNO.getName());
dgEdit(((AbstractTableDataWrapper) selectedNO.getObject()).creatTableDataPane(), selectedNO.getName(), false);
DesignerStrategyConfigUtils.addStrategyConfig(editingConfig);
}
((DBTableData) td).setDsName(tdName);
}
private class RemoveAction extends UpdateAction {
public RemoveAction() {
this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Remove"));
this.setMnemonic('R');
this.setSmallIcon("/com/fr/design/images/control/remove");
//服务器数据集不会走这里,入口不一样
/*if (tableDataPane instanceof ServerDBTableDataPane) {
StrategyConfig editingConfig = ((ServerDBTableDataPane) tableDataPane).updateStrategyConfig();
if (editingConfig != null) {
editingConfig.setDsName(tdName);
if (!ComparatorUtils.equals(oldName, tdName)) {
//重命名
DesignerStrategyConfigUtils.removeServerStrategyConfig(oldName);
}
@Override
public void actionPerformed(ActionEvent e) {
NameObject selectedNO = dataTree.getSelectedNameObject();
DesignerStrategyConfigUtils.addServerStrategyConfig(editingConfig);
}
}*/
if (selectedNO == null) {
return;
tds.putTableData(tdName, td);
Map<String, String> map = new HashMap<String, String>();
if (!ComparatorUtils.equals(oldName, tdName)) {
map.put(oldName, tdName);
}
fireDSChanged(map);
tc.fireTargetModified();
tc.parameterChanged();
int[] rows = tableDataTree.getSelectionRows();
tableDataTree.refreshChildByName(tdName);
tableDataTree.setSelectionRows(rows);
int returnVal = FineJOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Utils_Are_You_Sure_To_Remove_The_Selected_Item") + ":" + selectedNO.getName() + "?",
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Remove"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (returnVal == JOptionPane.OK_OPTION) {
// richer:这个地方为什么要在DataSourceTree里面去remove呢?多此一举吧
op.removeAction(selectedNO.getName());
dataTree.refresh();
// Richie:默认最后一行获得焦点.
dataTree.requestFocus();
dataTree.setSelectionRow(dataTree.getRowCount() - 1);
fireDSChanged();
//单独编辑数据集关闭,修改缓存配置状态,刷新下一键开启/关闭按钮
checkButtonEnabled();
DesignTableDataManager.removeSelectedColumnNames(selectedNO.getName());
}
@Override
public void doCancel() {
super.doCancel();
}
});
tdNamePanel.addPropertyChangeListener(new PropertyChangeAdapter() {
@Override
public void propertyChange() {
doPropertyChange(dg, tdNamePanel, oldName);
}
private void populate(TableDataSourceOP op) {
this.op = op;
dataTree.populate(op);
checkButtonEnabled();
});
dg.setVisible(true);
}
/**
* @return
*/
public TableDataTree getDataTree() {
return dataTree;
@Override
public void removeTableData(String sourceName) {
TableDataSource tds = this.tc.getBook();
tds.removeTableData(sourceName);
this.tableDataTree.refresh();
}
/**
@ -311,6 +328,7 @@ public class TableDataTreePane extends BasicTableDataTreePane {
* @param srcName 数据集来源(比如报表块就是报表块的名称)
* @param tableDataSource 数据集
*/
@Override
public Map<String, String> addTableData(String srcName, TableDataSource tableDataSource, boolean isCover) {
Map<String, String> tdNameMap = new HashMap<>();
allDSNames = DesignTableDataManager.getAllDSNames(tc.getBook());
@ -329,29 +347,55 @@ public class TableDataTreePane extends BasicTableDataTreePane {
}
}
tc.parameterChanged();
dataTree.refresh();
tableDataTree.refresh();
return Collections.unmodifiableMap(tdNameMap);
}
/**
* 合并数据集
*
* @param srcName 数据集来源(比如报表块就是报表块的名称)
* @param tableDataSource 数据集
*/
@Override
public void removeTableData(String sourceName) {
public Map<String, String> addTableData(String srcName, TableDataSource tableDataSource) {
Map<String, String> tdNameMap = new HashMap<>();
allDSNames = DesignTableDataManager.getAllDSNames(tc.getBook());
DesignTableDataManager.setThreadLocal(DesignTableDataManager.NO_PARAMETER);
TableDataSource tds = tc.getBook();
tds.removeTableData(sourceName);
dataTree.refresh();
Iterator<String> tdIterator = tableDataSource.getTableDataNameIterator();
while (tdIterator.hasNext()) {
String tdName = tdIterator.next();
String oldName = tdName;
TableData td = tableDataSource.getTableData(tdName);
if (tds.getTableData(tdName) != null || isDsNameRepeaded(tdName)) {
//如果有同名的就拼上来源名称
tdName = srcName + tdName;
}
int i = 0;
while (tds.getTableData(tdName) != null) {
i++;//如果拼上名字后依然已经存在就加编号
tdName += i;
}
tds.putTableData(tdName, td);
if (!ComparatorUtils.equals(oldName, tdName)) {
tdNameMap.put(oldName, tdName);
}
}
tc.parameterChanged();
tableDataTree.refresh();
return Collections.unmodifiableMap(tdNameMap);
}
@Override
public void addDataPane(final AbstractTableDataPane<?> uPanel, String paneName) {
final NamePane nPanel = uPanel.asNamePane();
nPanel.setObjectName(paneName);
final String oldName = paneName;
allDSNames = DesignTableDataManager.getAllDSNames(tc.getBook());
DesignTableDataManager.setThreadLocal(DesignTableDataManager.NO_PARAMETER);
tc.renameTableData(oldName, nPanel.getObjectName(), false);
tc.renameTableData(paneName, nPanel.getObjectName(), false);
TableDataSource tds = tc.getBook();
TableData td = uPanel.updateBean();
if (td instanceof TableDataSourceDependent) {
@ -360,14 +404,409 @@ public class TableDataTreePane extends BasicTableDataTreePane {
String tdName = nPanel.getObjectName();
tds.putTableData(tdName, td);
Map<String, String> map = new HashMap<String, String>();
if (!ComparatorUtils.equals(oldName, tdName)) {
map.put(oldName, tdName);
if (!ComparatorUtils.equals(paneName, tdName)) {
map.put(paneName, tdName);
}
fireDSChanged(map);
tc.fireTargetModified();
tc.parameterChanged();
int[] rows = dataTree.getSelectionRows();
dataTree.refreshChildByName(tdName);
dataTree.setSelectionRows(rows);
int[] rows = tableDataTree.getSelectionRows();
tableDataTree.refreshChildByName(tdName);
tableDataTree.setSelectionRows(rows);
}
@Override
public TableDataTree getDataTree() {
return this.tableDataTree;
}
private void populate(TableDataSourceOP op) {
this.op = op;
tableDataTree.populate(op);
checkButtonEnabled();
}
private void resetAddMenuDef() {
this.addMenuDef.clearShortCuts();
this.createAddMenuDef();
}
private void checkButtonEnabled() {
super.checkButtonEnabled(editAction, previewTableDataAction, removeAction, op, tableDataTree);
this.checkESDComponentsEnabled();
}
private void checkESDComponentsEnabled() {
if (buttonGroup.getSelectedIndex() == 1) {
//切换到服务器数据集的tab,禁用
esdAction.setEnabled(false);
esdOffAction.setEnabled(false);
return;
}
new SwingWorker<ButtonStatus, Void>() {
@Override
protected ButtonStatus doInBackground() throws Exception {
ButtonStatus btnStatus = new ButtonStatus();
Map<DBTableData, ESDStatus> statusMap = checkCanBeEsdBatchEnableStatus();
if (statusMap.size() == 0) {
//没有db数据集
return btnStatus;
} else {
int canTurnOnCount = 0;
int canTurnOffCount = 0;
for (ESDStatus status : statusMap.values()) {
switch (status) {
case GLOBAL_ON:
case GLOBAL_OFF:
case SINGLE_OFF:
canTurnOnCount++;
break;
case SINGLE_ON:
canTurnOffCount++;
break;
default:
break;
}
}
btnStatus.setOnStatus(canTurnOnCount > 0);
btnStatus.setOffStatus(canTurnOffCount > 0);
}
return btnStatus;
}
@Override
protected void done() {
try {
ButtonStatus buttonStatus = get();
esdAction.setEnabled(buttonStatus.isOnStatus());
esdOffAction.setEnabled(buttonStatus.isOffStatus());
} catch (InterruptedException | ExecutionException e) {
FineLoggerFactory.getLogger().error("get esd status of ds error for " + e.getMessage(), e);
}
}
}.execute();
}
private static class ButtonStatus {
private boolean onStatus = false;
private boolean offStatus = false;
public boolean isOnStatus() {
return onStatus;
}
public void setOnStatus(boolean onStatus) {
this.onStatus = onStatus;
}
public boolean isOffStatus() {
return offStatus;
}
public void setOffStatus(boolean offStatus) {
this.offStatus = offStatus;
}
}
//模版数据集
private void initButtonGroup() {
final Integer[] modeArray = {TEMPLATE_TABLE_DATA, SERVER_TABLE_DATA};
String[] textArray = {Toolkit.i18nText("Fine-Design_Basic_Tabledata_Source_Type_Template"), Toolkit.i18nText("Fine-Design_Basic_DS_Server_TableData")};
buttonGroup = new UIHeadGroup(textArray) {
public void tabChanged(int index) {
if (op != null) {
op.setDataMode(modeArray[buttonGroup.getSelectedIndex()]);
addMenuDef.setEnabled(modeArray[buttonGroup.getSelectedIndex()] == TEMPLATE_TABLE_DATA);
refreshDockingView();
}
}
};
buttonGroup.setNeedLeftRightOutLine(false);
}
private TableDataWrapper findTableDataWrapper(TreePath treePath) {
if (treePath != null) {
ExpandMutableTreeNode selectedTreeNode = (ExpandMutableTreeNode) treePath.getLastPathComponent();
Object selectedUserObject = selectedTreeNode.getUserObject();
NameObject nameObject = null;
if (selectedUserObject instanceof NameObject) {
nameObject = (NameObject) selectedUserObject;
} else {
selectedTreeNode = (ExpandMutableTreeNode) selectedTreeNode.getParent();
selectedUserObject = selectedTreeNode.getUserObject();
if (selectedUserObject instanceof NameObject) {
nameObject = (NameObject) selectedUserObject;
}
}
if (nameObject != null && nameObject.getObject() instanceof TableDataWrapper) {
return (TableDataWrapper) nameObject.getObject();
}
}
return null;
}
private String getTplPath() {
return HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getPath();
}
enum ESDStatus {
GLOBAL_ON,
GLOBAL_OFF,
SINGLE_ON,
SINGLE_OFF;
}
private Map<DBTableData, ESDStatus> checkCanBeEsdBatchEnableStatus() {
//<数据集, 是否可以被单独开启>
Map<DBTableData, ESDStatus> result = new HashMap<>();
for (int i = 0; i < tableDataTree.getRowCount(); i++) {
TreePath treePath = tableDataTree.getPathForRow(i);
TableDataWrapper wrapper = findTableDataWrapper(treePath);
if (wrapper.getTableData() instanceof DBTableData) {
DBTableData td = (DBTableData) wrapper.getTableData();
StrategyConfig config = DesignerStrategyConfigUtils.getStrategyConfig(wrapper.getTableDataName());
if (config == null) {
result.put(td, td.isShare() ? ESDStatus.SINGLE_ON : ESDStatus.SINGLE_OFF);
} else {
if (config.isUseGlobal()) {
if (StrategyConfigHelper.recommended(getTplPath())) {
result.put(td, ESDStatus.GLOBAL_ON);
} else {
result.put(td, ESDStatus.GLOBAL_OFF);
}
} else {
if (config.enabled()) {
result.put(td, ESDStatus.SINGLE_ON);
} else {
result.put(td, ESDStatus.SINGLE_OFF);
}
}
}
}
}
return result;
}
private class EsdOnAction extends AbstractESDAction {
@Override
public String getName() {
return Toolkit.i18nText("Fine-Design_ESD_Batch_Enable");
}
@Override
public Icon getIcon() {
return IOUtils.readIcon("/com/fr/design/images/control/batch_esd_on.png");
}
@Override
public void doWithTableDataWrapper(TableDataWrapper wrapper) {
String dsName = wrapper.getTableDataName();
if (wrapper.getTableData() instanceof DBTableData) {
StrategyConfig strategyConfig = getOrCreateStrategyConfig(dsName);
strategyConfig.setEnable(true);
strategyConfig.setUseGlobal(false);
DesignerStrategyConfigUtils.addStrategyConfig(strategyConfig);
DesignerContext.getDesignerFrame().getSelectedJTemplate().fireTargetModified();
}
}
}
private @NotNull StrategyConfig getOrCreateStrategyConfig(String dsName) {
StrategyConfig config = DesignerStrategyConfigUtils.getStrategyConfig(dsName);
if (config == null) {
config = StrategyConfigHelper.createStrategyConfig(true);
config.setDsName(dsName);
}
return config;
}
private String createDsName(String prefix) {
int count = 1;
allDSNames = DesignTableDataManager.getAllDSNames(tc.getBook());
while (isDsNameRepeaded(prefix + count)) {
count++;
}
return prefix + count;
}
private class EsdOffAction extends AbstractESDAction {
@Override
public String getName() {
return Toolkit.i18nText("Fine-Design_ESD_Batch_Disable");
}
@Override
public Icon getIcon() {
return IOUtils.readIcon("/com/fr/design/images/control/batch_esd_off.png");
}
@Override
public void doWithTableDataWrapper(TableDataWrapper wrapper) {
String dsName = wrapper.getTableDataName();
if (wrapper.getTableData() instanceof DBTableData) {
((DBTableData) wrapper.getTableData()).setShare(false);
StrategyConfig strategyConfig = getOrCreateStrategyConfig(dsName);
strategyConfig.setEnable(false);
strategyConfig.setUseGlobal(false);
DesignerStrategyConfigUtils.addStrategyConfig(strategyConfig);
DesignerContext.getDesignerFrame().getSelectedJTemplate().fireTargetModified();
}
}
}
private abstract class AbstractESDAction extends UpdateAction {
public abstract String getName();
public abstract Icon getIcon();
public abstract void doWithTableDataWrapper(TableDataWrapper tableDataWrapper);
public AbstractESDAction() {
this.setName(getName());
this.setMnemonic('R');
this.setSmallIcon(getIcon());
}
@Override
public void actionPerformed(ActionEvent e) {
List<TableDataWrapper> tableDataWrapperList = new ArrayList<>();
for (int i = 0; i < tableDataTree.getRowCount(); i++) {
TreePath treePath = tableDataTree.getPathForRow(i);
TableDataWrapper wrapper = findTableDataWrapper(treePath);
if (wrapper != null) {
tableDataWrapperList.add(wrapper);
}
}
if (tableDataWrapperList.isEmpty()) {
return;
}
new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
for (TableDataWrapper tableDataWrapper : tableDataWrapperList) {
doWithTableDataWrapper(tableDataWrapper);
}
return null;
}
@Override
protected void done() {
refreshDockingView();
}
}.execute();
}
}
/**
* 新建数据集
* <p>
* 抽象化支持不同类型数据集创建
*/
private abstract class AddAction extends UpdateAction {
protected abstract String getTDName();
protected abstract Icon getTDIcon();
protected abstract String getNamePrefix();
protected abstract TemplateTableDataWrapper getTableDataInstance();
public AddAction() {
this.setName(this.getTDName());
this.setSmallIcon(this.getTDIcon());
}
@Override
public void actionPerformed(ActionEvent e) {
dgEdit(getTableDataInstance().creatTableDataPane(), createDsName(getNamePrefix()), false);
}
}
private class EditAction extends UpdateAction {
public EditAction() {
this.setName(Toolkit.i18nText("Fine-Design_Basic_Edit"));
this.setMnemonic('E');
this.setSmallIcon(IOUtils.readIcon(IconPathConstants.TD_EDIT_ICON_PATH));
}
@Override
public void actionPerformed(ActionEvent e) {
final NameObject selectedNO = tableDataTree.getSelectedNameObject();
if (selectedNO == null) {
return;
}
String dsName = selectedNO.getName();
DesignTableDataManager.removeSelectedColumnNames(dsName);
AbstractTableDataWrapper wrapper = (AbstractTableDataWrapper) selectedNO.getObject();
AbstractTableDataPane<?> tableDataPane = wrapper.creatTableDataPane();
//下面创建creatTableDataPane后会直接populate,所以populate时不能用后设置的一些参数,比如name
dgEdit(tableDataPane, dsName, false);
}
}
private class RemoveAction extends UpdateAction {
public RemoveAction() {
this.setName(Toolkit.i18nText("Fine-Design_Basic_Remove"));
this.setMnemonic('R');
this.setSmallIcon(IOUtils.readIcon(IconPathConstants.TD_REMOVE_ICON_PATH));
}
@Override
public void actionPerformed(ActionEvent e) {
NameObject selectedNO = tableDataTree.getSelectedNameObject();
if (selectedNO == null) {
return;
}
int returnVal = FineJOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Utils_Are_You_Sure_To_Remove_The_Selected_Item") + ":" + selectedNO.getName() + "?",
Toolkit.i18nText("Fine-Design_Basic_Remove"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (returnVal == JOptionPane.OK_OPTION) {
// richer:这个地方为什么要在DataSourceTree里面去remove呢?多此一举吧
op.removeAction(selectedNO.getName());
tableDataTree.refresh();
// Richie:默认最后一行获得焦点.
tableDataTree.requestFocus();
tableDataTree.setSelectionRow(tableDataTree.getRowCount() - 1);
fireDSChanged();
checkButtonEnabled();
//删掉缓存配置
DesignerStrategyConfigUtils.removeStrategyConfig(selectedNO.getName());
// 如果一个模版是平台开启,这个数据集的配置不会存xml,预览模版时直接从全局配置copy,这样
// 导致删除的时候StrategyConfigsAttrSavedHook没有通过前后配置比较感知数据集被删除,因此不会发出事件让其失效
// 这里额外发出一次数据集修改事件
StrategyEventsNotifier.modifyDataSet(new DSMapping(getTplPath(), new DsNameTarget(selectedNO.getName())));
DesignTableDataManager.removeSelectedColumnNames(selectedNO.getName());
}
}
}
}

500
designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/DBTableDataPane.java

@ -1,6 +1,5 @@
package com.fr.design.data.tabledata.tabledatapane;
import com.fr.base.BaseUtils;
import com.fr.base.Parameter;
import com.fr.base.ParameterHelper;
import com.fr.data.core.db.TableProcedure;
@ -13,15 +12,19 @@ import com.fr.design.ExtraDesignClassManager;
import com.fr.design.actions.UpdateAction;
import com.fr.design.border.UIRoundedBorder;
import com.fr.design.constants.UIConstants;
import com.fr.design.data.DesignerStrategyConfigUtils;
import com.fr.design.data.datapane.ESDStrategyConfigPane;
import com.fr.design.data.datapane.connect.ConnectionTableProcedurePane;
import com.fr.design.data.datapane.connect.ConnectionTableProcedurePane.DoubleClickSelectedNodeOnTreeListener;
import com.fr.design.data.datapane.preview.PreviewTablePane;
import com.fr.design.data.datapane.sqlpane.SQLEditPane;
import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.BasicPane;
import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.fun.DBTableDataMenuHandler;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icheckbox.UICheckBox;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itableeditorpane.ParameterTableModel;
import com.fr.design.gui.itableeditorpane.UITableEditAction;
@ -29,18 +32,26 @@ import com.fr.design.gui.itableeditorpane.UITableEditorPane;
import com.fr.design.gui.itoolbar.UIToolbar;
import com.fr.design.gui.syntax.ui.rsyntaxtextarea.SyntaxConstants;
import com.fr.design.gui.syntax.ui.rtextarea.RTextScrollPane;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.menu.SeparatorDef;
import com.fr.design.menu.ToolBarDef;
import com.fr.design.utils.ParameterUtils;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.esd.core.strategy.config.StrategyConfig;
import com.fr.esd.core.strategy.config.StrategyConfigHelper;
import com.fr.esd.event.DSMapping;
import com.fr.esd.event.DsNameTarget;
import com.fr.esd.event.StrategyEventsNotifier;
import com.fr.esd.event.xml.XMLSavedHook;
import com.fr.general.ComparatorUtils;
import com.fr.general.IOUtils;
import com.fr.general.sql.SqlUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.script.Calculator;
import com.fr.stable.ArrayUtils;
import com.fr.stable.ParameterProvider;
import com.fr.stable.StringUtils;
import com.fr.workspace.WorkContext;
import javax.swing.BorderFactory;
import javax.swing.Box;
@ -55,6 +66,7 @@ import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
@ -62,25 +74,39 @@ import java.awt.event.KeyListener;
import java.util.ArrayList;
import java.util.List;
/**
* @author rinoux
* @version 10.0
* Created by rinoux on 2020/7/22
*/
public class DBTableDataPane extends AbstractTableDataPane<DBTableData> {
private static final int BOTTOM = 6;
private static final String PREVIEW_BUTTON = com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Preview");
private static final String REFRESH_BUTTON = com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Refresh");
private static final String PREVIEW_BUTTON = Toolkit.i18nText("Fine-Design_Basic_Preview");
private static final String REFRESH_BUTTON = Toolkit.i18nText("Fine-Design_Basic_Refresh");
private ConnectionTableProcedurePane connectionTableProcedurePane;
private UITableEditorPane<ParameterProvider> editorPane;
private DBTableDataMenuHandler dbTableDataMenuHandler;
private SQLEditPane sqlTextPane;
private UICheckBox isShareCheckBox;
private MaxMemRowCountPanel maxPanel;
private String pageQuery = null;
UIComboBox configFromList;
UICheckBox esdEnabled;
private UIButton esdSettingsBtn;
private UILabel barErrorTips;
private String pageQuery;
private DBTableData dbTableData;
StrategyConfig strategyConfig;
public DBTableDataPane() {
init();
initMainSplitPane();
}
private void init() {
this.setLayout(new BorderLayout(4, 4));
setLayout(new BorderLayout(4, 4));
sqlTextPane = new SQLEditPane();
sqlTextPane.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_SQL);
this.sqlTextPane = new SQLEditPane();
this.sqlTextPane.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_SQL);
ParameterTableModel model = new ParameterTableModel() {
@Override
@ -88,25 +114,27 @@ public class DBTableDataPane extends AbstractTableDataPane<DBTableData> {
return ArrayUtils.add(super.createDBTableAction(), new RefreshAction());
}
};
editorPane = new UITableEditorPane<ParameterProvider>(model);
editorPane = new UITableEditorPane<>(model);
// 左边的Panel,上面是选择DatabaseConnection的ComboBox,下面DatabaseConnection对应的Table
connectionTableProcedurePane = new ConnectionTableProcedurePane() {
this.connectionTableProcedurePane = new ConnectionTableProcedurePane() {
@Override
protected void filter(Connection connection, String conName, List<String> nameList) {
connection.addConnection(nameList, conName, new Class[]{JDBCDatabaseConnection.class, JNDIDatabaseConnection.class});
connection.addConnection(nameList, conName, new Class[]{
JDBCDatabaseConnection.class,
JNDIDatabaseConnection.class
});
}
@Override
protected void addKeyMonitor() {
searchField.addKeyListener(new KeyListener() {
this.searchField.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
//do nothing
}
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
@ -115,39 +143,39 @@ public class DBTableDataPane extends AbstractTableDataPane<DBTableData> {
}
}
@Override
public void keyReleased(KeyEvent e) {
//do nothing
}
});
}
};
connectionTableProcedurePane.addDoubleClickListener(new DoubleClickSelectedNodeOnTreeListener() {
this.connectionTableProcedurePane.addDoubleClickListener(new ConnectionTableProcedurePane.DoubleClickSelectedNodeOnTreeListener() {
@Override
public void actionPerformed(TableProcedure target) {
Document document = sqlTextPane.getDocument();
Document document = DBTableDataPane.this.sqlTextPane.getDocument();
try {
document.insertString(sqlTextPane.getCaretPosition(), target.toString(), null);
document.insertString(DBTableDataPane.this.sqlTextPane.getCaretPosition(), target.toString(), null);
} catch (BadLocationException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
// 这里开始作色,本来可以给sqlTextPane添加DocumentListener来实现的,
// 后来发现insertString的时候,锁定了JTextPane,不能调用setXXX来作色,先这样了.
// sqlTextPane.syntaxTexts();
sqlTextPane.requestFocus();
DBTableDataPane.this.sqlTextPane.requestFocus();
}
});
sqlTextPane.addFocusListener(new FocusListener() {
this.sqlTextPane.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
// do nothing
barErrorTips.setVisible(false);
}
@Override
public void focusLost(FocusEvent e) {
if (isPreviewOrRefreshButton(e)) {
checkParameter();
if (DBTableDataPane.this.isPreviewOrRefreshButton(e)) {
DBTableDataPane.this.checkParameter();
}
}
});
@ -163,105 +191,189 @@ public class DBTableDataPane extends AbstractTableDataPane<DBTableData> {
northPane.add(editToolBar, BorderLayout.CENTER);
northPane.setBorder(BorderFactory.createEmptyBorder(0, 0, BOTTOM, 0));
RTextScrollPane sqlTextScrollPane = new RTextScrollPane(sqlTextPane);
RTextScrollPane sqlTextScrollPane = new RTextScrollPane(this.sqlTextPane);
sqlTextScrollPane.setLineNumbersEnabled(true);
sqlTextScrollPane.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, UIConstants.ARC));
sqlTextScrollPane.setPreferredSize(new Dimension(680, 600));
JPanel paraMeanPane = new JPanel(new BorderLayout());
paraMeanPane.setPreferredSize(new Dimension(680, 90));
UILabel paraMean = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Datasource_Param_DES"));
UILabel paraMean = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Datasource_Param_DES"));
paraMeanPane.add(paraMean, BorderLayout.CENTER);
box.add(northPane);
box.add(sqlTextScrollPane);
box.add(paraMeanPane);
box.add(editorPane);
box.add(this.editorPane);
JPanel sqlSplitPane = new JPanel(new BorderLayout(4, 4));
sqlSplitPane.add(box, BorderLayout.CENTER);
box.setMinimumSize(new Dimension(300, 400));
// 防止数据连接名过长时影响 split pane 分割效果
// 本界面中给MaxMemRowCountPanel留的空间太小,造成MaxMemRowCountPanel显示异常,这边减小一点最小宽度,拉长MaxMemRowCountPanel
connectionTableProcedurePane.setMinimumSize(new Dimension(230, 400));
connectionTableProcedurePane.setMaximumSize(new Dimension(500, 400));
// 使用SplitPane
JSplitPane mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, connectionTableProcedurePane, sqlSplitPane);
this.connectionTableProcedurePane.setMinimumSize(new Dimension(250, 400));
this.connectionTableProcedurePane.setMaximumSize(new Dimension(500, 400));
JSplitPane mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, this.connectionTableProcedurePane, sqlSplitPane);
mainSplitPane.setBorder(BorderFactory.createLineBorder(GUICoreUtils.getTitleLineBorderColor()));
mainSplitPane.setOneTouchExpandable(true);
this.add(mainSplitPane, BorderLayout.CENTER);
}
public DBTableDataPane() {
init();
initMainSplitPane();
add(mainSplitPane, BorderLayout.CENTER);
}
private boolean isPreviewOrRefreshButton(FocusEvent e) {
if (e.getOppositeComponent() != null) {
String name = e.getOppositeComponent().getName();
return ComparatorUtils.equals(name, PREVIEW_BUTTON) || ComparatorUtils.equals(name, REFRESH_BUTTON);
return (ComparatorUtils.equals(name, PREVIEW_BUTTON) || ComparatorUtils.equals(name, REFRESH_BUTTON));
}
return false;
}
@Override
protected String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_DS-Database_Query");
return Toolkit.i18nText("Fine-Design_Basic_DS-Database_Query");
}
private void refresh() {
String[] paramTexts = new String[2];
paramTexts[0] = SqlUtils.tryPureSqlText(sqlTextPane.getText());
paramTexts[1] = SqlUtils.tryPureSqlText(pageQuery);
List<ParameterProvider> existParameterList = editorPane.update();
Parameter[] ps = existParameterList == null ? new Parameter[0] : existParameterList.toArray(new Parameter[0]);
editorPane.populate(ParameterUtils.analyzeAndUnionParameters(paramTexts, ps));
paramTexts[0] = SqlUtils.tryPureSqlText(this.sqlTextPane.getText());
paramTexts[1] = SqlUtils.tryPureSqlText(this.pageQuery);
List<ParameterProvider> existParameterList = this.editorPane.update();
Parameter[] ps = (existParameterList == null) ? new Parameter[0] : (Parameter[]) existParameterList.toArray(new Parameter[0]);
this.editorPane.populate(ParameterHelper.analyzeAndUnionSameParameters(paramTexts, ps));
}
private JToolBar createToolBar() {
// p:工具栏.
ToolBarDef toolBarDef = new ToolBarDef();
toolBarDef.addShortCut(new PreviewAction());
toolBarDef.addShortCut(SeparatorDef.DEFAULT);
toolBarDef.addShortCut(new EditPageQueryAction());
dbTableDataMenuHandler = ExtraDesignClassManager.getInstance().getSingle(DBTableDataMenuHandler.MARK_STRING);
if (dbTableDataMenuHandler != null) {
this.dbTableDataMenuHandler = ExtraDesignClassManager.getInstance().getSingle("DBTableDataMenuHandler");
if (this.dbTableDataMenuHandler != null) {
toolBarDef.addShortCut(SeparatorDef.DEFAULT);
toolBarDef.addShortCut(dbTableDataMenuHandler.createQueryAction());
toolBarDef.addShortCut(this.dbTableDataMenuHandler.createQueryAction());
}
UILabel esdSettingsLabel = new UILabel(Toolkit.i18nText("Fine-Design_ESD_Cache_Settings"));
this.configFromList = new UIComboBox(ConfigFrom.values());
this.esdEnabled = new UICheckBox(Toolkit.i18nText("Fine-Design_ESD_Enable_Cache"));
this.barErrorTips = new UILabel();
this.barErrorTips.setForeground(Color.RED);
this.barErrorTips.setVisible(false);
esdSettingsBtn = new UIButton(Toolkit.i18nText("Fine-Design_ESD_Strategy_Config"));
esdSettingsBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final boolean global = (DBTableDataPane.this.configFromList.getSelectedIndex() == DBTableDataPane.ConfigFrom.GLOBAL.getIndex());
final ESDStrategyConfigPane strategyConfigPane = new ESDStrategyConfigPane(global);
StrategyConfig populateStrategyConfig = null;
if (global) {
populateStrategyConfig = StrategyConfigHelper.getGlobalStrategyConfig();
} else {
populateStrategyConfig = strategyConfig;
}
//显示对应的配置
strategyConfigPane.populateBean(populateStrategyConfig);
BasicDialog dlg = strategyConfigPane.showMediumWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() {
@Override
public void doOk() {
super.doOk();
if (!global) {
//点击策略配置面板的确定,重新设置策略配置
strategyConfig = strategyConfigPane.updateBean();
}
}
isShareCheckBox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Is_Share_DBTableData"));
isShareCheckBox.setBackground(Color.WHITE);
maxPanel = new MaxMemRowCountPanel();
maxPanel.setBorder(null);
});
dlg.setAlwaysOnTop(true);
dlg.setVisible(true);
}
});
this.configFromList.setSelectedIndex(DBTableDataPane.ConfigFrom.GLOBAL.getIndex());
this.configFromList.addActionListener(e -> setEsdEnabled());
UIToolbar editToolBar = ToolBarDef.createJToolBar();
toolBarDef.updateToolBar(editToolBar);
editToolBar.add(isShareCheckBox);
editToolBar.add(maxPanel);
editToolBar.add(esdSettingsLabel);
editToolBar.add(this.configFromList);
editToolBar.add(this.esdEnabled);
editToolBar.add(this.esdSettingsBtn);
editToolBar.add(this.barErrorTips);
return editToolBar;
}
/* private void showBarError(String errorTips) {
this.barErrorTips.setText(errorTips);
this.barErrorTips.setVisible(true);
}
private boolean checkQuery(String errorTips) {
if (StringUtils.isEmpty(this.sqlTextPane.getText())) {
showBarError(errorTips);
return false;
}
return true;
}*/
/**
* 设置是否开启
*/
protected void setEsdEnabled() {
boolean useIndividualConfig = configFromList.getSelectedIndex() == ConfigFrom.INDIVIDUAL.getIndex();
if (useIndividualConfig) {
if (this.strategyConfig == null) {
//新建的数据集,选择单独时,可用但是不勾选
this.esdEnabled.setSelected(false);
this.esdEnabled.setEnabled(true);
} else {
this.esdEnabled.setSelected(!this.strategyConfig.isUseGlobal() && this.strategyConfig.enabled());
this.esdEnabled.setEnabled(true);
}
} else {
this.esdEnabled.setSelected(DesignerStrategyConfigUtils.isEditingTemplateRecommended());
this.esdEnabled.setEnabled(false);
}
}
public StrategyConfig updateStrategyConfig() {
return this.strategyConfig;
}
private void checkParameter() {
String[] paramTexts = new String[2];
paramTexts[0] = sqlTextPane.getText();
paramTexts[1] = pageQuery;
paramTexts[0] = this.sqlTextPane.getText();
paramTexts[1] = this.pageQuery;
Parameter[] parameters = ParameterHelper.analyze4Parameters(paramTexts, false);
if (parameters.length < 1 && editorPane.update().size() < 1) {
if (parameters.length < 1 && this.editorPane.update().size() < 1) {
return;
}
boolean isIn = true;
List<ParameterProvider> list = editorPane.update();
List<String> name = new ArrayList<String>();
for (int i = 0; i < list.size(); i++) {
name.add(list.get(i).getName());
List<ParameterProvider> list = this.editorPane.update();
List<String> name = new ArrayList<>();
for (ParameterProvider parameter : list) {
name.add(parameter.getName());
}
for (int i = 0; i < parameters.length; i++) {
if (!name.contains(parameters[i].getName())) {
for (Parameter parameter : parameters) {
if (!name.contains(parameter.getName())) {
isIn = false;
break;
}
@ -269,115 +381,172 @@ public class DBTableDataPane extends AbstractTableDataPane<DBTableData> {
if (list.size() == parameters.length && isIn) {
return;
}
// bug:34175 删了是否刷新对话框, 均直接刷新
refresh();
}
@Override
public void populateBean(DBTableData dbtabledata) {
this.dbTableData = dbtabledata;
if (dbTableDataMenuHandler != null) {
dbTableDataMenuHandler.populate(dbtabledata);
public void populateBean(DBTableData dbTableData) {
this.dbTableData = dbTableData;
if (this.dbTableDataMenuHandler != null) {
this.dbTableDataMenuHandler.populate(dbTableData);
}
ParameterProvider[] parameters = null;
Calculator c = Calculator.createCalculator();
parameters = dbtabledata.getParameters(c);
editorPane.populate(parameters);
ParameterProvider[] parameters = dbTableData.getParameters(c);
this.editorPane.populate(parameters);
com.fr.data.impl.Connection db = null;
String query = null;
boolean isShare = false;
int maxMemeryRow = -1;
db = dbtabledata.getDatabase();
query = dbtabledata.getQuery();
isShare = dbtabledata.isShare();
maxMemeryRow = dbtabledata.getMaxMemRowCount();
this.pageQuery = dbtabledata.getPageQuerySql();
Connection db = dbTableData.getDatabase();
String query = dbTableData.getQuery();
this.pageQuery = dbTableData.getPageQuerySql();
this.connectionTableProcedurePane.setSelectedDatabaseConnection(db);
this.sqlTextPane.setText(query);
this.sqlTextPane.requestFocus();
this.sqlTextPane.moveCaretPosition(this.sqlTextPane.getCaretPosition());
isShareCheckBox.setSelected(isShare);
maxPanel.setValue(maxMemeryRow);
//查找映射的配置
this.strategyConfig = mapStrategyConfig(dbTableData);
boolean shouldEnable = false;
ConfigFrom from = ConfigFrom.GLOBAL;
if (this.strategyConfig != null) {
if (this.strategyConfig.enabled()) {
shouldEnable = true;
}
if (!this.strategyConfig.isUseGlobal()) {
from = ConfigFrom.INDIVIDUAL;
}
}
this.esdEnabled.setSelected(shouldEnable);
this.configFromList.setSelectedIndex(from.getIndex());
}
@Override
protected StrategyConfig mapStrategyConfig(DBTableData dbTableData) {
//获取配置,如果是模版数据集,dbTableData实例应该是DBTableData,如果是服务器数据集是DBTableData
StrategyConfig strategyConfig = null;
if (dbTableData != null) {
//设置保存数据集的事件检查钩子
String tplPath = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getEditingFILE().getPath();
//新建模版此时不存在,不需要注册钩子
if (dbTableData.getXmlSavedHook() == null && WorkContext.getWorkResource().exist(tplPath)) {
dbTableData.setXmlSavedHook(new DBTableDataSavedHook(tplPath, dbTableData));
}
//获取当前的缓存配置,没有就创建一份
String dsName = this.dbTableData.getDsName();
strategyConfig = DesignerStrategyConfigUtils.getStrategyConfig(dsName);
if (strategyConfig == null && dbTableData.isShare()) {
strategyConfig = StrategyConfigHelper.createStrategyConfig(true, false, true);
}
}
return strategyConfig;
}
public DBTableData updateBean() {
updateDBTableData();
//这边只修改enable和useGlobal
boolean global = DBTableDataPane.this.configFromList.getSelectedIndex() == DBTableDataPane.ConfigFrom.GLOBAL.getIndex();
boolean enable = DBTableDataPane.this.esdEnabled.isSelected();
//未开启缓存的,如果选择了单独配置,需要创建配置
if (this.strategyConfig == null && !global) {
this.strategyConfig = StrategyConfig.createDefault();
}
//设置配置来源和开启状态
if (this.strategyConfig != null) {
this.strategyConfig.setEnable(enable);
this.strategyConfig.setUseGlobal(global);
}
return this.dbTableData;
}
private void updateDBTableData() {
String dbName = this.connectionTableProcedurePane.getSelectedDatabaseConnnectonName();
if (StringUtils.isBlank(dbName) || StringUtils.isBlank(this.sqlTextPane.getText())) {
try {
throw new Exception(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Connect_SQL_Cannot_Null") + ".");
} catch (Exception ignore) {
// JOptionPane.showMessageDialog(DBTableDataPane.this,
// com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Connect_SQL_Cannot_Null") + ".");
throw new Exception(Toolkit.i18nText("Fine-Design_Basic_Connect_SQL_Cannot_Null") + ".");
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
// 保存前 刷新下参数列表 保证获取到最新的参数
refresh();
List<ParameterProvider> parameterList = editorPane.update();
Parameter[] parameters = parameterList.toArray(new Parameter[parameterList.size()]);
List<ParameterProvider> parameterList = this.editorPane.update();
ParameterProvider[] parameters = parameterList.toArray(new ParameterProvider[0]);
dbTableData.setDatabase(new NameDatabaseConnection(dbName));
// p:必须先设置Parameters数组,因为setQuery里面会自动设置的
dbTableData.setParameters(parameters);
dbTableData.setQuery(this.sqlTextPane.getText());
dbTableData.setQuery(this.sqlTextPane.getText().trim());
dbTableData.setShare(isShareCheckBox.isSelected());
dbTableData.setMaxMemRowCount(maxPanel.getValue());
dbTableData.setPageQuerySql(this.pageQuery);
if (dbTableDataMenuHandler != null) {
dbTableDataMenuHandler.update();
if (this.dbTableDataMenuHandler != null) {
this.dbTableDataMenuHandler.update();
}
return dbTableData;
}
protected class RefreshAction extends UITableEditAction {
public RefreshAction() {
this.setName(REFRESH_BUTTON);
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/control/refresh.png"));
setName(REFRESH_BUTTON);
setSmallIcon(IOUtils.readIcon("/com/fr/design/images/control/refresh.png"));
}
@Override
public void actionPerformed(ActionEvent e) {
refresh();
DBTableDataPane.this.refresh();
}
@Override
public void checkEnabled() {
// do nothing
}
}
private class PreviewAction extends UpdateAction {
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"));
setName(PREVIEW_BUTTON);
setMnemonic('P');
setSmallIcon(IOUtils.readIcon("/com/fr/design/images/m_file/preview.png"));
}
@Override
public void actionPerformed(ActionEvent evt) {
checkParameter();
DBTableDataPane.this.checkParameter();
PreviewTablePane.previewTableData(DBTableDataPane.this.updateBean());
}
}
private class EditPageQueryAction extends UpdateAction {
public EditPageQueryAction() {
this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Layer_Page_Report_Page_Query"));
this.setName(Toolkit.i18nText("Fine-Design_Basic_Layer_Page_Report_Page_Query"));
this.setMnemonic('L');
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_file/text.png"));
this.setSmallIcon(IOUtils.readIcon("/com/fr/design/images/m_file/text.png"));
}
@Override
public void actionPerformed(ActionEvent e) {
final QueryPane pane = new QueryPane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Layer_Page_Report_Define_Page_Query_SQL"));
final QueryPane pane = new QueryPane(Toolkit.i18nText("Fine-Design_Basic_Layer_Page_Report_Define_Page_Query_SQL"));
pane.populate(pageQuery);
BasicDialog dialog = pane.showWindow(DesignerContext.getDesignerFrame());
dialog.addDialogActionListener(new DialogActionAdapter() {
@ -391,9 +560,9 @@ public class DBTableDataPane extends AbstractTableDataPane<DBTableData> {
}
}
private class QueryPane extends BasicPane {
private static class QueryPane extends BasicPane {
private SQLEditPane pageQueryPane;
private String title;
private final String title;
public QueryPane(String title) {
this.title = title;
@ -410,21 +579,96 @@ public class DBTableDataPane extends AbstractTableDataPane<DBTableData> {
if (StringUtils.isBlank(text)) {
return;
}
pageQueryPane.setText(text);
this.pageQueryPane.setText(text);
}
public String update() {
String text = pageQueryPane.getText();
String text = this.pageQueryPane.getText();
if (StringUtils.isBlank(text)) {
return null;
} else {
return text;
}
return text;
}
@Override
protected String title4PopupWindow() {
return title;
return this.title;
}
}
enum ConfigFrom {
GLOBAL(0, Toolkit.i18nText("Fine-Design_ESD_Use_Global_Settings")),
INDIVIDUAL(1, Toolkit.i18nText("Fine-Design_ESD_Use_Individual_Settings"));
int index;
String displayText;
ConfigFrom(int index, String displayText) {
this.index = index;
this.displayText = displayText;
}
static int parse(StrategyConfig config) {
return (config == null || config.isUseGlobal()) ? ConfigFrom.GLOBAL.getIndex() : ConfigFrom.INDIVIDUAL.getIndex();
}
public int getIndex() {
return this.index;
}
public String getDisplayText() {
return this.displayText;
}
public String toString() {
return getDisplayText();
}
}
private static class DBTableDataSavedHook implements XMLSavedHook<DBTableData> {
private static final long serialVersionUID = 4925391747683335372L;
private final String tplPath;
private String origName;
private String origConnection;
private String origQuery;
public DBTableDataSavedHook(String tplPath, DBTableData origDBTableData) {
this.tplPath = tplPath;
this.origName = origDBTableData.getDsName();
this.origConnection = origDBTableData.getDatabase().toString();
this.origQuery = origDBTableData.getQuery();
}
@Override
public void doAfterSaved(DBTableData saved) {
String dsName = saved.getDsName();
String conn = saved.getDatabase().toString();
String query = saved.getQuery();
//检查数据集名称、数据链接和sql是否修改,如果修改需要触发缓存监听事件
if (!dsName.equals(origName) || !conn.equals(origConnection) || !query.equals(origQuery)) {
if (StringUtils.isNotEmpty(tplPath) && StringUtils.isNotEmpty(origName)) {
//新建数据集的origName为null,不用触发
StrategyEventsNotifier.modifyDataSet(new DSMapping(tplPath, new DsNameTarget(origName)));
}
}
this.origName = dsName;
this.origConnection = conn;
this.origQuery = query;
}
}
}

BIN
designer-base/src/main/resources/com/fr/design/images/control/batch_esd_off.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
designer-base/src/main/resources/com/fr/design/images/control/batch_esd_on.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Loading…
Cancel
Save