|
|
|
package com.fr.design.data.datapane;
|
|
|
|
|
|
|
|
import com.fr.base.TableData;
|
|
|
|
import com.fr.data.MultiResultTableData;
|
|
|
|
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.DesignerEnvManager;
|
|
|
|
import com.fr.design.ExtraDesignClassManager;
|
|
|
|
import com.fr.design.actions.UpdateAction;
|
|
|
|
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.StrategyConfigAttrUtils;
|
|
|
|
import com.fr.design.data.datapane.auth.TableDataAuthHelper;
|
|
|
|
import com.fr.design.data.datapane.management.clip.TableDataTreeClipboard;
|
|
|
|
import com.fr.design.data.datapane.management.search.TableDataTreeSearchManager;
|
|
|
|
import com.fr.design.data.datapane.management.search.pane.TableDataSearchRemindPane;
|
|
|
|
import com.fr.design.data.datapane.management.search.pane.TreeSearchToolbarPane;
|
|
|
|
import com.fr.design.data.datapane.management.search.searcher.TableDataSearchMode;
|
|
|
|
import com.fr.design.data.tabledata.StoreProcedureWorkerListener;
|
|
|
|
import com.fr.design.data.tabledata.paste.TableDataFollowingPasteUtils;
|
|
|
|
import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane;
|
|
|
|
import com.fr.design.data.tabledata.tabledatapane.DBTableDataPane;
|
|
|
|
import com.fr.design.data.tabledata.tabledatapane.loading.TableDataLoadingPane;
|
|
|
|
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.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.ilable.UILabel;
|
|
|
|
import com.fr.design.gui.ilist.CheckBoxListWithPartialSelect;
|
|
|
|
import com.fr.design.gui.imenu.UIPopupMenu;
|
|
|
|
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.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.design.utils.gui.GUICoreUtils;
|
|
|
|
import com.fr.design.worker.DefaultWorker;
|
|
|
|
import com.fr.design.worker.data.TableDataResult;
|
|
|
|
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.query.StrategicTableData;
|
|
|
|
import com.fr.general.ComparatorUtils;
|
|
|
|
import com.fr.general.GeneralContext;
|
|
|
|
import com.fr.general.NameObject;
|
|
|
|
import com.fr.log.FineLoggerFactory;
|
|
|
|
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.stable.StringUtils;
|
|
|
|
import com.fr.stable.core.PropertyChangeAdapter;
|
|
|
|
import com.fr.workspace.WorkContext;
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
|
|
|
import javax.swing.BorderFactory;
|
|
|
|
import javax.swing.Icon;
|
|
|
|
import javax.swing.JLabel;
|
|
|
|
import javax.swing.JPanel;
|
|
|
|
import javax.swing.SwingUtilities;
|
|
|
|
import javax.swing.SwingWorker;
|
|
|
|
import javax.swing.ToolTipManager;
|
|
|
|
import javax.swing.tree.TreePath;
|
|
|
|
import java.awt.*;
|
|
|
|
import java.awt.dnd.DnDConstants;
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
import java.awt.event.KeyAdapter;
|
|
|
|
import java.awt.event.KeyEvent;
|
|
|
|
import java.awt.event.MouseAdapter;
|
|
|
|
import java.awt.event.MouseEvent;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.concurrent.Callable;
|
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
|
|
|
|
public class TableDataTreePane extends BasicTableDataTreePane {
|
|
|
|
private static final TableDataTreePane singleton = new TableDataTreePane();
|
|
|
|
|
|
|
|
public static final int PLUGIN_LISTENER_PRIORITY = 1;
|
|
|
|
|
|
|
|
public synchronized static BasicTableDataTreePane getInstance(DesignModelAdapter<?, ?> tc) {
|
|
|
|
|
|
|
|
TableDataPaneProcessor treePaneProcessor = ExtraDesignClassManager.getInstance().getSingle(TableDataPaneProcessor.XML_TAG);
|
|
|
|
if (treePaneProcessor != null) {
|
|
|
|
return treePaneProcessor.createTableDataTreePane(tc);
|
|
|
|
}
|
|
|
|
if (singleton.tc == null) {
|
|
|
|
singleton.addMenuDef.clearShortCuts();
|
|
|
|
singleton.createAddMenuDef();
|
|
|
|
}
|
|
|
|
singleton.tc = tc;
|
|
|
|
singleton.op = new TableDataSourceOP(tc);
|
|
|
|
singleton.op.setDataMode(singleton.buttonGroup.getSelectedIndex() == 0 ? TEMPLATE_TABLE_DATA : SERVER_TABLE_DATA);
|
|
|
|
singleton.refreshDockingView();
|
|
|
|
return singleton;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取不必每次都refreshDockingView的数据集树面板
|
|
|
|
* 不会主动替换DesignModelAdapter,需要保证使用时没有跨模板动作,谨慎使用
|
|
|
|
*
|
|
|
|
* @param tc
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public synchronized static BasicTableDataTreePane getInstanceWithoutRefreshEverytime(DesignModelAdapter<?, ?> tc) {
|
|
|
|
TableDataPaneProcessor treePaneProcessor = ExtraDesignClassManager.getInstance().getSingle(TableDataPaneProcessor.XML_TAG);
|
|
|
|
if (treePaneProcessor != null) {
|
|
|
|
return treePaneProcessor.createTableDataTreePane(tc);
|
|
|
|
}
|
|
|
|
return singleton.tc == null ? getInstance(tc) : singleton;
|
|
|
|
}
|
|
|
|
|
|
|
|
private TableDataSourceOP op;
|
|
|
|
private TableDataTree tableDataTree;
|
|
|
|
private UIPopupMenu popupMenu;
|
|
|
|
private EditAction editAction;
|
|
|
|
private RemoveAction removeAction;
|
|
|
|
private CopyAction copyAction;
|
|
|
|
private PasteAction pasteAction;
|
|
|
|
private EsdOnAction esdAction;
|
|
|
|
private EsdOffAction esdOffAction;
|
|
|
|
private SwitchAction switchAction;
|
|
|
|
private PreviewTableDataAction previewTableDataAction;
|
|
|
|
private JPanel serverDatasetAuthTipJPanel = new JPanel();
|
|
|
|
|
|
|
|
private TableDataSearchRemindPane remindPane;
|
|
|
|
private TreeSearchToolbarPane toolbarPane;
|
|
|
|
|
|
|
|
private BasicDialog loadingDialog;
|
|
|
|
|
|
|
|
private TableDataTreePane() {
|
|
|
|
initPane();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initPane() {
|
|
|
|
this.setLayout(new BorderLayout(4, 0));
|
|
|
|
this.setBorder(null);
|
|
|
|
|
|
|
|
initTableDataTree();
|
|
|
|
toolbarPane = initToolBarPane();
|
|
|
|
JPanel treePane = initTreePane();
|
|
|
|
dealWithTableDataTree();
|
|
|
|
this.add(toolbarPane, BorderLayout.NORTH);
|
|
|
|
this.add(treePane, BorderLayout.CENTER);
|
|
|
|
checkButtonEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 处理TableDataTree的监听等
|
|
|
|
*/
|
|
|
|
private void dealWithTableDataTree() {
|
|
|
|
// tooltip
|
|
|
|
ToolTipManager.sharedInstance().registerComponent(tableDataTree);
|
|
|
|
ToolTipManager.sharedInstance().setDismissDelay(3000);
|
|
|
|
ToolTipManager.sharedInstance().setInitialDelay(0);
|
|
|
|
// 右键菜单
|
|
|
|
popupMenu = new UIPopupMenu();
|
|
|
|
popupMenu.add(editAction.createMenuItem());
|
|
|
|
popupMenu.add(previewTableDataAction.createMenuItem());
|
|
|
|
popupMenu.addSeparator();
|
|
|
|
popupMenu.add(copyAction.createMenuItem());
|
|
|
|
popupMenu.add(pasteAction.createMenuItem());
|
|
|
|
popupMenu.add(removeAction.createMenuItem());
|
|
|
|
popupMenu.addSeparator();
|
|
|
|
// 监听
|
|
|
|
tableDataTree.addMouseListener(new MouseAdapter() {
|
|
|
|
@Override
|
|
|
|
public void mousePressed(MouseEvent e) {
|
|
|
|
// 服务器暂不支持右键菜单
|
|
|
|
if (SwingUtilities.isRightMouseButton(e) && op.getDataMode() != TableDataSourceOP.SERVER_TABLE_DATA) {
|
|
|
|
GUICoreUtils.showPopupMenu(popupMenu, e.getComponent(), e.getX(), e.getY());
|
|
|
|
}
|
|
|
|
checkButtonEnabled();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
tableDataTree.addKeyListener(new KeyAdapter() {
|
|
|
|
@Override
|
|
|
|
public void keyPressed(KeyEvent e) {
|
|
|
|
//F2重命名先屏蔽了, 有bug没时间弄
|
|
|
|
if (e.getKeyCode() == KeyEvent.VK_F2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
super.keyPressed(e);
|
|
|
|
checkButtonEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void keyReleased(KeyEvent e) {
|
|
|
|
super.keyReleased(e);
|
|
|
|
checkButtonEnabled();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// TreeCellEditor
|
|
|
|
tableDataTree.setEditable(true);
|
|
|
|
TableDataTreeCellEditor treeCellEditor = new TableDataTreeCellEditor(new UITextField(), tableDataTree, this);
|
|
|
|
treeCellEditor.addCellEditorListener(treeCellEditor);
|
|
|
|
tableDataTree.setCellEditor(treeCellEditor);
|
|
|
|
new TableDataTreeDragSource(tableDataTree, DnDConstants.ACTION_COPY);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 工具栏面板
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
private TreeSearchToolbarPane initToolBarPane() {
|
|
|
|
// toolbar
|
|
|
|
addMenuDef = new MenuDef(Toolkit.i18nText("Fine-Design_Basic_Action_Add"));
|
|
|
|
addMenuDef.setDisabledIcon("/com/fr/design/standard/addpopup/addPopup", true);
|
|
|
|
createAddMenuDef();
|
|
|
|
// 创建插件监听
|
|
|
|
createPluginListener();
|
|
|
|
|
|
|
|
editAction = new EditAction();
|
|
|
|
copyAction = new CopyAction();
|
|
|
|
pasteAction = new PasteAction();
|
|
|
|
removeAction = new RemoveAction();
|
|
|
|
previewTableDataAction = new PreviewTableDataAction(tableDataTree);
|
|
|
|
connectionTableAction = new ConnectionTableAction();
|
|
|
|
esdAction = new EsdOnAction();
|
|
|
|
esdOffAction = new EsdOffAction();
|
|
|
|
switchAction = new SwitchAction();
|
|
|
|
|
|
|
|
toolbarDef = new ToolBarDef();
|
|
|
|
toolbarDef.addShortCut(addMenuDef, SeparatorDef.DEFAULT, editAction, removeAction, SeparatorDef.DEFAULT, previewTableDataAction, connectionTableAction, esdAction, esdOffAction, switchAction);
|
|
|
|
UIToolbar toolBar = ToolBarDef.createJToolBar();
|
|
|
|
toolBar.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIConstants.TOOLBAR_BORDER_COLOR));
|
|
|
|
toolBar.setBorderPainted(true);
|
|
|
|
toolbarDef.updateToolBar(toolBar);
|
|
|
|
|
|
|
|
TreeSearchToolbarPane searchLayerdPane = new TreeSearchToolbarPane(toolBar);
|
|
|
|
searchLayerdPane.setPreferredSize(new Dimension(this.getWidth(), 23));
|
|
|
|
|
|
|
|
return searchLayerdPane;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 数据集树面板
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
private JPanel initTreePane() {
|
|
|
|
JPanel treePane = new JPanel(new BorderLayout(0, 6));
|
|
|
|
// north
|
|
|
|
JPanel northPane = new JPanel(FRGUIPaneFactory.createBorderLayout());
|
|
|
|
initServerDatasetAuthTipJPanel();
|
|
|
|
initButtonGroup();
|
|
|
|
northPane.add(buttonGroup, BorderLayout.CENTER);
|
|
|
|
northPane.add(serverDatasetAuthTipJPanel, BorderLayout.SOUTH);
|
|
|
|
// center
|
|
|
|
remindPane = new TableDataSearchRemindPane(getDataTree());
|
|
|
|
|
|
|
|
treePane.add(northPane, BorderLayout.NORTH);
|
|
|
|
treePane.add(remindPane, BorderLayout.CENTER);
|
|
|
|
return treePane;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 初始化 TableDataTree
|
|
|
|
*/
|
|
|
|
private void initTableDataTree() {
|
|
|
|
tableDataTree = new TableDataTree();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initServerDatasetAuthTipJPanel() {
|
|
|
|
String datasetAuthTip = Toolkit.i18nText("Fine-Design_Server_Dataset_Auth_Tip");
|
|
|
|
List<String> lineTips = new ArrayList(Arrays.asList(datasetAuthTip.split("\n")));
|
|
|
|
if (datasetAuthTip.endsWith("\n")) {
|
|
|
|
lineTips.add(StringUtils.EMPTY);
|
|
|
|
}
|
|
|
|
serverDatasetAuthTipJPanel = new JPanel();
|
|
|
|
serverDatasetAuthTipJPanel.setLayout(new GridLayout(lineTips.size(), 1));
|
|
|
|
for (int i = 0; i < lineTips.size(); i++) {
|
|
|
|
String lineTip = lineTips.get(i);
|
|
|
|
List<JLabel> jLabels = new ArrayList<>();
|
|
|
|
JLabel lineJLabel = new JLabel(lineTip);
|
|
|
|
lineJLabel.setForeground(Color.lightGray);
|
|
|
|
jLabels.add(lineJLabel);
|
|
|
|
if (i == (lineTips.size() - 1)) {
|
|
|
|
JLabel jLabel = new JLabel(Toolkit.i18nText("Fine-Design_Basic_Alphafine_No_Remind"));
|
|
|
|
jLabel.setForeground(Color.blue);
|
|
|
|
jLabel.addMouseListener(new MouseAdapter() {
|
|
|
|
@Override
|
|
|
|
public void mouseClicked(MouseEvent e) {
|
|
|
|
DesignerEnvManager.getEnvManager().setShowServerDatasetAuthTip(false);
|
|
|
|
serverDatasetAuthTipJPanel.setVisible(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
jLabels.add(jLabel);
|
|
|
|
}
|
|
|
|
serverDatasetAuthTipJPanel.add(getLineTipJPanel(jLabels));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private JPanel getLineTipJPanel(List<JLabel> jLabels) {
|
|
|
|
JPanel jPanel = new JPanel(FRGUIPaneFactory.createLabelFlowLayout());
|
|
|
|
for (JLabel jLabel : jLabels) {
|
|
|
|
jPanel.add(jLabel);
|
|
|
|
}
|
|
|
|
return jPanel;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void createPluginListener() {
|
|
|
|
//菜单栏监听
|
|
|
|
GeneralContext.listenPluginRunningChanged(new PluginEventListener(PLUGIN_LISTENER_PRIORITY) {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void on(PluginEvent event) {
|
|
|
|
|
|
|
|
addMenuDef.clearShortCuts();
|
|
|
|
createAddMenuDef();
|
|
|
|
}
|
|
|
|
}, new PluginFilter() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean accept(PluginContext context) {
|
|
|
|
|
|
|
|
return context.contain(PluginModule.ExtraDesign);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 刷新
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void refreshDockingView() {
|
|
|
|
populate(new TableDataSourceOP(tc));
|
|
|
|
this.checkButtonEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public final void createAddMenuDef() {
|
|
|
|
TableDataNameObjectCreator[] creators = TableDataCreatorProducer.getInstance().createReportTableDataCreator();
|
|
|
|
for (final TableDataNameObjectCreator creator : creators) {
|
|
|
|
if (creator.shouldInsertSeparator()) {
|
|
|
|
addMenuDef.addShortCut(new LineSeparator());
|
|
|
|
}
|
|
|
|
|
|
|
|
addMenuDef.addShortCut(new AddAction() {
|
|
|
|
@Override
|
|
|
|
protected String getTDName() {
|
|
|
|
return creator.menuName();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Icon getTDIcon() {
|
|
|
|
return creator.menuIcon();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected String getNamePrefix() {
|
|
|
|
return creator.getPrefix();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected TemplateTableDataWrapper getTableDataInstance() {
|
|
|
|
TableData tableData = (TableData) creator.createObject();
|
|
|
|
|
|
|
|
//11中所有数据集都是StrategicTableData的子类
|
|
|
|
if (tableData instanceof StrategicTableData) {
|
|
|
|
StrategicTableData std = (StrategicTableData) tableData;
|
|
|
|
tableData = StrategicTableData.Binder
|
|
|
|
.bind(std)
|
|
|
|
.setDsName(createDsName(creator.getPrefix()))
|
|
|
|
.setScope(StrategicTableData.Scope.TEMPLATE)
|
|
|
|
.done();
|
|
|
|
}
|
|
|
|
return new TemplateTableDataWrapper(tableData);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 编辑面板
|
|
|
|
*
|
|
|
|
* @param tableDataPane 面板
|
|
|
|
* @param originalName 原始名字
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void dgEdit(final AbstractTableDataPane<?> tableDataPane, String originalName, boolean isUpdate) {
|
|
|
|
// 编辑时如果正在搜索,跳回原树
|
|
|
|
if (TableDataTreeSearchManager.getInstance().isInSearchMode()) {
|
|
|
|
TableDataTreeSearchManager.getInstance().outOfSearchMode();
|
|
|
|
}
|
|
|
|
tableDataPane.addStoreProcedureWorkerListener(new StoreProcedureWorkerListener() {
|
|
|
|
public void fireDoneAction() {
|
|
|
|
if (tableDataTree.getSelectionPath() == null) {
|
|
|
|
tableDataTree.refresh();
|
|
|
|
} else {
|
|
|
|
Object object = tableDataTree.getSelectionPath().getLastPathComponent();
|
|
|
|
int[] rows = tableDataTree.getSelectionRows();
|
|
|
|
tableDataTree.refreshChildByName(object.toString());
|
|
|
|
tableDataTree.setSelectionRows(rows);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
final NamePane tdNamePanel = tableDataPane.asNamePane();
|
|
|
|
tdNamePanel.setObjectName(originalName);
|
|
|
|
|
|
|
|
final String oldName = originalName;
|
|
|
|
allDSNames = DesignTableDataManager.getAllDSNames(tc.getBook());
|
|
|
|
|
|
|
|
final BasicDialog dg = tdNamePanel.showLargeWindow(SwingUtilities.getWindowAncestor(TableDataTreePane.this), new DialogActionAdapter() {
|
|
|
|
@Override
|
|
|
|
public void doOk() {
|
|
|
|
DesignTableDataManager.setThreadLocal(DesignTableDataManager.NO_PARAMETER);
|
|
|
|
tc.renameTableData(oldName, tdNamePanel.getObjectName(), false);
|
|
|
|
TableDataSource tds = tc.getBook();
|
|
|
|
TableData td = tableDataPane.updateBean();
|
|
|
|
if (td instanceof TableDataSourceDependent) {
|
|
|
|
((TableDataSourceDependent) td).setTableDataSource(tds);
|
|
|
|
}
|
|
|
|
String tdName = tdNamePanel.getObjectName();
|
|
|
|
|
|
|
|
|
|
|
|
//模版还没保存的时候不知道后缀,不能设置到策略配置里面
|
|
|
|
if (tableDataPane instanceof DBTableDataPane) {
|
|
|
|
StrategyConfig editingConfig = ((DBTableDataPane) tableDataPane).updateStrategyConfig();
|
|
|
|
if (editingConfig != null) {
|
|
|
|
editingConfig.setDsName(tdName);
|
|
|
|
if (!ComparatorUtils.equals(oldName, tdName)) {
|
|
|
|
//重命名
|
|
|
|
StrategyConfigAttrUtils.removeStrategyConfig(oldName);
|
|
|
|
}
|
|
|
|
|
|
|
|
StrategyConfigAttrUtils.addStrategyConfig(editingConfig);
|
|
|
|
}
|
|
|
|
((DBTableData) td).setDsName(tdName);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
//单独编辑数据集关闭,修改缓存配置状态,刷新下一键开启/关闭按钮
|
|
|
|
checkButtonEnabled();
|
|
|
|
|
|
|
|
if (listener != null) {
|
|
|
|
listener.doOk();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void doCancel() {
|
|
|
|
super.doCancel();
|
|
|
|
if (listener != null) {
|
|
|
|
listener.doCancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
tdNamePanel.addPropertyChangeListener(new PropertyChangeAdapter() {
|
|
|
|
@Override
|
|
|
|
public void propertyChange() {
|
|
|
|
checkNameChange(tableDataPane, dg, tdNamePanel, oldName);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// 有些数据集(DBTableData)面板的初始化过程中是包含了SwingWorker处理(查询数据连接、查表等)的
|
|
|
|
// 如果这里直接setVisible,可能阻塞SwingWorker的done方法,导致面板渲染出现问题
|
|
|
|
SwingUtilities.invokeLater(() -> {
|
|
|
|
dg.setVisible(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkNameChange(AbstractTableDataPane<?> tableDataPane, BasicDialog dg, BasicPane.NamePane nPanel, final String oldName) {
|
|
|
|
nPanel.setShowText(StringUtils.BLANK);
|
|
|
|
dg.setButtonEnabled(true);
|
|
|
|
String tempName = nPanel.getObjectName();
|
|
|
|
if (StringUtils.isBlank(tempName)) {
|
|
|
|
nPanel.setShowText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Table_Data_Empty_Name_Tips"));
|
|
|
|
dg.setButtonEnabled(false);
|
|
|
|
} else if (!ComparatorUtils.equals(oldName, tempName) && isDsNameRepeaded(tempName)) {
|
|
|
|
nPanel.setShowText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Table_Data_Duplicate_Name_Tips", tempName));
|
|
|
|
dg.setButtonEnabled(false);
|
|
|
|
} else if (oldName.length() >= PROCEDURE_NAME_INDEX && tableDataPane.updateBean() instanceof MultiResultTableData) {
|
|
|
|
if (isIncludeUnderline(tempName)) {
|
|
|
|
nPanel.setShowText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Multi_Result_Table_Data_Name_Tips"));
|
|
|
|
dg.setButtonEnabled(false);
|
|
|
|
}
|
|
|
|
} else if (!BasicTableDataUtils.checkName(tempName)) {
|
|
|
|
dg.setButtonEnabled(false);
|
|
|
|
} else {
|
|
|
|
nPanel.setShowText(StringUtils.BLANK);
|
|
|
|
dg.setButtonEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isIncludeUnderline(String name) {
|
|
|
|
return !ComparatorUtils.equals(name.indexOf(MultiResultTableData.GROUP_MARKER), -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void removeTableData(String sourceName) {
|
|
|
|
TableDataSource tds = this.tc.getBook();
|
|
|
|
tds.removeTableData(sourceName);
|
|
|
|
this.tableDataTree.refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 合并数据集
|
|
|
|
*
|
|
|
|
* @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());
|
|
|
|
DesignTableDataManager.setThreadLocal(DesignTableDataManager.NO_PARAMETER);
|
|
|
|
TableDataSource tds = tc.getBook();
|
|
|
|
Iterator tdIterator = tableDataSource.getTableDataNameIterator();
|
|
|
|
while (tdIterator.hasNext()) {
|
|
|
|
String tdName = (String) tdIterator.next();
|
|
|
|
String oldName = tdName;
|
|
|
|
TableData td = tableDataSource.getTableData(tdName);
|
|
|
|
boolean isDsNameRepeated = isDsNameRepeaded(tdName);
|
|
|
|
tdName = BasicTableDataUtils.getTableDataName(isCover, tds, tdName, srcName, isDsNameRepeated);
|
|
|
|
tds.putTableData(tdName, td);
|
|
|
|
if (!ComparatorUtils.equals(oldName, tdName)) {
|
|
|
|
tdNameMap.put(oldName, tdName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tc.parameterChanged();
|
|
|
|
tableDataTree.refresh();
|
|
|
|
return Collections.unmodifiableMap(tdNameMap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 合并数据集
|
|
|
|
*
|
|
|
|
* @param srcName 数据集来源(比如报表块,就是报表块的名称)
|
|
|
|
* @param tableDataSource 数据集
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
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();
|
|
|
|
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);
|
|
|
|
|
|
|
|
allDSNames = DesignTableDataManager.getAllDSNames(tc.getBook());
|
|
|
|
|
|
|
|
DesignTableDataManager.setThreadLocal(DesignTableDataManager.NO_PARAMETER);
|
|
|
|
tc.renameTableData(paneName, nPanel.getObjectName(), false);
|
|
|
|
TableDataSource tds = tc.getBook();
|
|
|
|
TableData td = uPanel.updateBean();
|
|
|
|
if (td instanceof TableDataSourceDependent) {
|
|
|
|
((TableDataSourceDependent) td).setTableDataSource(tds);
|
|
|
|
}
|
|
|
|
String tdName = nPanel.getObjectName();
|
|
|
|
|
|
|
|
//处理缓存策略配置
|
|
|
|
if (uPanel instanceof DBTableDataPane) {
|
|
|
|
StrategyConfig editingConfig = ((DBTableDataPane) uPanel).updateStrategyConfig();
|
|
|
|
if (editingConfig != null) {
|
|
|
|
editingConfig.setDsName(tdName);
|
|
|
|
StrategyConfigAttrUtils.addStrategyConfig(editingConfig);
|
|
|
|
}
|
|
|
|
((DBTableData) td).setDsName(tdName);
|
|
|
|
}
|
|
|
|
|
|
|
|
tds.putTableData(tdName, td);
|
|
|
|
Map<String, String> map = new HashMap<String, String>();
|
|
|
|
if (!ComparatorUtils.equals(paneName, tdName)) {
|
|
|
|
map.put(paneName, tdName);
|
|
|
|
}
|
|
|
|
fireDSChanged(map);
|
|
|
|
tc.fireTargetModified();
|
|
|
|
tc.parameterChanged();
|
|
|
|
int[] rows = tableDataTree.getSelectionRows();
|
|
|
|
tableDataTree.refreshChildByName(tdName);
|
|
|
|
tableDataTree.setSelectionRows(rows);
|
|
|
|
FineLoggerFactory.getLogger().info("add table data succeeded for {}", tdName);
|
|
|
|
}
|
|
|
|
|
|
|
|
@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();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 感觉这里,把一堆Action和Op之类的送到抽象类里去检查,很奇怪,抽象类本身定义的Action只有add和connection
|
|
|
|
* 另外因为改动了数据集树节点的选中逻辑,所以这边改成自己类内部实现
|
|
|
|
* 不直接改抽象类是怕影响到部分插件兼容
|
|
|
|
*/
|
|
|
|
private void checkButtonEnabled() {
|
|
|
|
// 检查添加与定义数据连接操作
|
|
|
|
this.checkAddAndConnectionEnabled();
|
|
|
|
// 检查编辑、预览、复制、粘贴、删除等基本操作
|
|
|
|
this.checkBasicButtonEnabled();
|
|
|
|
// 检查esd相关操作
|
|
|
|
this.checkESDComponentsEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkAddAndConnectionEnabled() {
|
|
|
|
connectionTableAction.setEnabled(WorkContext.getCurrent() != null && WorkContext.getCurrent().isRoot());
|
|
|
|
addMenuDef.setEnabled(!(op == null || op.interceptButtonEnabled() || op.getDataMode() == SERVER_TABLE_DATA));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkBasicButtonEnabled() {
|
|
|
|
// 设置下各个button的基本状态,避免代码重复
|
|
|
|
editAction.setEnabled(false);
|
|
|
|
copyAction.setEnabled(false);
|
|
|
|
pasteAction.setEnabled(false);
|
|
|
|
removeAction.setEnabled(false);
|
|
|
|
previewTableDataAction.setEnabled(false);
|
|
|
|
if (op == null || op.interceptButtonEnabled()) {
|
|
|
|
// 保持false状态
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// 获取选中的数据集数量
|
|
|
|
int selectioncount = getDataTree().getSelectedTableDataCounts();
|
|
|
|
if (op.getDataMode() == SERVER_TABLE_DATA) {
|
|
|
|
// 服务器数据集下,选中数据集数量为1时,可以预览
|
|
|
|
if (selectioncount == 1 && !getDataTree().hasSelectedIndependentColumns()) {
|
|
|
|
previewTableDataAction.setEnabled(true);
|
|
|
|
}
|
|
|
|
// 其它保持false状态
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// 模板数据集时,粘贴可用
|
|
|
|
pasteAction.setEnabled(true);
|
|
|
|
if (selectioncount == 0 || getDataTree().hasSelectedIndependentColumns()) {
|
|
|
|
// 未选中数据集,或存在单独选中的数据列时,其它保持false状态
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (selectioncount == 1) {
|
|
|
|
// 仅选中单个数据集时,才可以编译、预览
|
|
|
|
editAction.setEnabled(true);
|
|
|
|
previewTableDataAction.setEnabled(true);
|
|
|
|
}
|
|
|
|
removeAction.setEnabled(true);
|
|
|
|
copyAction.setEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 (isShowServerDatasetAuthTipJPanel(textArray[index])) {
|
|
|
|
serverDatasetAuthTipJPanel.setVisible(true);
|
|
|
|
} else {
|
|
|
|
serverDatasetAuthTipJPanel.setVisible(false);
|
|
|
|
}
|
|
|
|
if (op != null) {
|
|
|
|
op.setDataMode(modeArray[buttonGroup.getSelectedIndex()]);
|
|
|
|
addMenuDef.setEnabled(modeArray[buttonGroup.getSelectedIndex()] == TEMPLATE_TABLE_DATA);
|
|
|
|
if (TableDataTreeSearchManager.getInstance().isInSearchMode()) {
|
|
|
|
TableDataTreeSearchManager.getInstance().outOfSearchMode();
|
|
|
|
}
|
|
|
|
refreshDockingView();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isShowServerDatasetAuthTipJPanel(String name) {
|
|
|
|
if (ComparatorUtils.equals(name, Toolkit.i18nText("Fine-Design_Basic_DS_Server_TableData"))
|
|
|
|
&& DesignerEnvManager.getEnvManager().isShowServerDatasetAuthTip()
|
|
|
|
&& !WorkContext.getCurrent().isLocal()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
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 = StrategyConfigAttrUtils.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 String getIconResource() {
|
|
|
|
return "/com/fr/design/standard/batchesdon/batch_esd_on";
|
|
|
|
}
|
|
|
|
|
|
|
|
@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);
|
|
|
|
StrategyConfigAttrUtils.addStrategyConfig(strategyConfig);
|
|
|
|
DesignerContext.getDesignerFrame().getSelectedJTemplate().fireTargetModified();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private @NotNull StrategyConfig getOrCreateStrategyConfig(String dsName) {
|
|
|
|
StrategyConfig config = StrategyConfigAttrUtils.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 String getIconResource() {
|
|
|
|
return "/com/fr/design/standard/batchesdoff/batch_esd_off";
|
|
|
|
}
|
|
|
|
|
|
|
|
@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);
|
|
|
|
StrategyConfigAttrUtils.addStrategyConfig(strategyConfig);
|
|
|
|
DesignerContext.getDesignerFrame().getSelectedJTemplate().fireTargetModified();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private abstract class AbstractESDAction extends UpdateAction {
|
|
|
|
|
|
|
|
public abstract String getName();
|
|
|
|
|
|
|
|
public abstract String getIconResource();
|
|
|
|
|
|
|
|
public abstract void doWithTableDataWrapper(TableDataWrapper tableDataWrapper);
|
|
|
|
|
|
|
|
public AbstractESDAction() {
|
|
|
|
this.setName(getName());
|
|
|
|
this.setMnemonic('R');
|
|
|
|
this.setSmallIcon(getIconResource());
|
|
|
|
}
|
|
|
|
|
|
|
|
@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) {
|
|
|
|
TableDataResult result = getTableDataResult();
|
|
|
|
if (result != null) {
|
|
|
|
dgEditByResult(result);
|
|
|
|
} else {
|
|
|
|
if (loadingDialog == null) {
|
|
|
|
TableDataLoadingPane loadingPane = new TableDataLoadingPane();
|
|
|
|
loadingDialog = loadingPane.showLargeWindow(SwingUtilities.getWindowAncestor(TableDataTreePane.this), null);
|
|
|
|
}
|
|
|
|
loadingDialog.setVisible(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private TableDataResult getTableDataResult() {
|
|
|
|
DefaultWorker<TableDataResult> worker = new DefaultWorker<TableDataResult>(() -> new TableDataResult(getTableDataInstance())) {
|
|
|
|
@Override
|
|
|
|
public void dealResultWhenSlowly(TableDataResult result) {
|
|
|
|
dgEditByResult(result);
|
|
|
|
if (loadingDialog != null) {
|
|
|
|
loadingDialog.setVisible(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
worker.execute();
|
|
|
|
return worker.getResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void dgEditByResult(TableDataResult result) {
|
|
|
|
dgEdit(result.getWrapper().creatTableDataPane(), StringUtils.isEmpty(result.getName()) ? createDsName(getNamePrefix()) : result.getName(), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private class EditAction extends UpdateAction {
|
|
|
|
public EditAction() {
|
|
|
|
this.setName(Toolkit.i18nText("Fine-Design_Basic_Edit"));
|
|
|
|
this.setMnemonic('E');
|
|
|
|
this.setSmallIcon("/com/fr/design/standard/editdataset/edit");
|
|
|
|
}
|
|
|
|
|
|
|
|
@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();
|
|
|
|
|
|
|
|
if (TableDataAuthHelper.needCheckAuthWhenEdit(wrapper.getTableData())) {
|
|
|
|
// 先打开一个Loading面板
|
|
|
|
TableDataLoadingPane loadingPane = new TableDataLoadingPane();
|
|
|
|
BasicDialog loadingDialog = loadingPane.showLargeWindow(SwingUtilities.getWindowAncestor(TableDataTreePane.this), null);
|
|
|
|
// 查询权限
|
|
|
|
new SwingWorker<Boolean, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Boolean doInBackground() throws Exception {
|
|
|
|
// 获取无权限连接名称集合
|
|
|
|
Collection<String> noAuthConnections = TableDataAuthHelper.getNoAuthConnections();
|
|
|
|
// 获取当前数据集对应的数据连接名称
|
|
|
|
String connectionName = TableDataAuthHelper.getConnectionNameByDBTableData((DBTableData) wrapper.getTableData());
|
|
|
|
return !noAuthConnections.contains(connectionName);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void done() {
|
|
|
|
try {
|
|
|
|
Boolean hasAuth = get();
|
|
|
|
if (hasAuth) {
|
|
|
|
// 有权限时,关闭Loading面板,打开编辑面板
|
|
|
|
loadingDialog.setVisible(false);
|
|
|
|
dgEdit(tableDataPane, dsName, false);
|
|
|
|
} else {
|
|
|
|
// 无权限时,给出无权限提示
|
|
|
|
loadingPane.switchTo(TableDataLoadingPane.NO_AUTH_PANE_NAME);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FineLoggerFactory.getLogger().error("loading connection error in remote design", e.getMessage());
|
|
|
|
// 查询权限失败时,给出报错提示
|
|
|
|
loadingPane.switchTo(TableDataLoadingPane.ERROR_NAME);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.execute();
|
|
|
|
loadingDialog.setVisible(true);
|
|
|
|
} else {
|
|
|
|
// 无需检查权限时,直接打开数据库查询编辑面板
|
|
|
|
//下面创建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("/com/fr/design/standard/remove/remove");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
NameObject[] selectedNameObjects = tableDataTree.getSelectedTableDataNameObjects();
|
|
|
|
if (selectedNameObjects == null || selectedNameObjects.length == 0) {
|
|
|
|
FineLoggerFactory.getLogger().error("Table Data to remove is null or not selected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// 可以半选的CheckBoxList
|
|
|
|
CheckBoxListWithPartialSelect tableDataCheckBoxPane = new CheckBoxListWithPartialSelect(selectedNameObjects);
|
|
|
|
UIScrollPane scrollPane = new UIScrollPane(tableDataCheckBoxPane);
|
|
|
|
UILabel tips = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Select_Source_To_Remove"));
|
|
|
|
BasicPane basicPane = new BasicPane() {
|
|
|
|
@Override
|
|
|
|
protected String title4PopupWindow() {
|
|
|
|
return Toolkit.i18nText("Fine-Design_Basic_Remove");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
basicPane.setLayout(new BorderLayout());
|
|
|
|
basicPane.add(tips, BorderLayout.NORTH);
|
|
|
|
basicPane.add(scrollPane, BorderLayout.CENTER);
|
|
|
|
BasicDialog basicDialog = basicPane.showSmallWindow(SwingUtilities.getWindowAncestor(TableDataTreePane.this), new DialogActionAdapter() {
|
|
|
|
@Override
|
|
|
|
public void doOk() {
|
|
|
|
List selectedValues = tableDataCheckBoxPane.getSelectedObjects();
|
|
|
|
// 删除时如果正在搜索,跳回原树
|
|
|
|
if (TableDataTreeSearchManager.getInstance().isInSearchMode()) {
|
|
|
|
TableDataTreeSearchManager.getInstance().outOfSearchMode();
|
|
|
|
}
|
|
|
|
for (Object toRemove : selectedValues) {
|
|
|
|
try {
|
|
|
|
doRemove((String) toRemove);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FineLoggerFactory.getLogger().error(e, "remove table data failed for {}", toRemove);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void doCancel() {
|
|
|
|
super.doCancel();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
basicDialog.setVisible(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void doRemove(String toRemove) throws Exception {
|
|
|
|
// richer:这个地方为什么要在DataSourceTree里面去remove呢?多此一举吧
|
|
|
|
op.removeAction(toRemove);
|
|
|
|
tableDataTree.refresh();
|
|
|
|
// Richie:默认最后一行获得焦点.
|
|
|
|
tableDataTree.requestFocus();
|
|
|
|
tableDataTree.setSelectionRow(tableDataTree.getRowCount() - 1);
|
|
|
|
fireDSChanged();
|
|
|
|
checkButtonEnabled();
|
|
|
|
|
|
|
|
//删掉缓存配置
|
|
|
|
StrategyConfigAttrUtils.removeStrategyConfig(toRemove);
|
|
|
|
|
|
|
|
// 如果一个模版是平台开启,这个数据集的配置不会存xml,预览模版时直接从全局配置copy,这样
|
|
|
|
// 导致删除的时候StrategyConfigsAttrSavedHook没有通过前后配置比较感知数据集被删除,因此不会发出事件让其失效
|
|
|
|
// 这里额外发出一次数据集修改事件
|
|
|
|
StrategyEventsNotifier.modifyDataSet(new DSMapping(getTplPath(), new DsNameTarget(toRemove)));
|
|
|
|
DesignTableDataManager.removeSelectedColumnNames(toRemove);
|
|
|
|
DesignModelAdapter.getCurrentModelAdapter().removeTableDataParameters(toRemove);
|
|
|
|
FineLoggerFactory.getLogger().info("remove table data succeeded for {}", toRemove);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class CopyAction extends UpdateAction {
|
|
|
|
|
|
|
|
public CopyAction() {
|
|
|
|
this.setName(Toolkit.i18nText("Fine-Design_Basic_Copy"));
|
|
|
|
this.setMnemonic('C');
|
|
|
|
this.setSmallIcon("/com/fr/design/standard/copy/copy");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
NameObject[] selectedNameObjects = tableDataTree.getSelectedTableDataNameObjects();
|
|
|
|
Map<String, AbstractTableDataWrapper> dataWrapperMap = TableDataTreeClipboard.getInstance().transferNameObjectArray2Map(selectedNameObjects);
|
|
|
|
TableDataTreeClipboard.getInstance().addToClip(dataWrapperMap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class PasteAction extends UpdateAction {
|
|
|
|
|
|
|
|
public PasteAction() {
|
|
|
|
this.setName(Toolkit.i18nText("Fine-Design_Basic_Action_Paste_Name"));
|
|
|
|
this.setMnemonic('P');
|
|
|
|
this.setSmallIcon("/com/fr/design/images/m_edit/paste");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
// 粘贴时如果正在搜索,跳回原树
|
|
|
|
if (TableDataTreeSearchManager.getInstance().isInSearchMode()) {
|
|
|
|
TableDataTreeSearchManager.getInstance().outOfSearchMode();
|
|
|
|
}
|
|
|
|
Map<String, AbstractTableDataWrapper> dataWrapperMap = TableDataTreeClipboard.getInstance().takeFromClip();
|
|
|
|
for (Map.Entry<String, AbstractTableDataWrapper> dataWrapperEntry : dataWrapperMap.entrySet()) {
|
|
|
|
// 处理数据集名称
|
|
|
|
String dsName = getNoRepeatedDsName4Paste(dataWrapperEntry.getKey());
|
|
|
|
AbstractTableDataWrapper wrapper = dataWrapperEntry.getValue();
|
|
|
|
AbstractTableDataPane<?> tableDataPane = TableDataFollowingPasteUtils.generateTableDataPaneWhenPaste(wrapper);
|
|
|
|
if (tableDataPane != null) {
|
|
|
|
addDataPane(tableDataPane, dsName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getNoRepeatedDsName4Paste(String oldName) {
|
|
|
|
while (isDsNameRepeaded(oldName)) {
|
|
|
|
oldName = oldName + Toolkit.i18nText("Fine-Design_Table_Data_Copy_Of_Table_Data");
|
|
|
|
}
|
|
|
|
return oldName;
|
|
|
|
}
|
|
|
|
|
|
|
|
private class SwitchAction extends UpdateAction {
|
|
|
|
|
|
|
|
public SwitchAction() {
|
|
|
|
this.setName(Toolkit.i18nText("Fine-Design_Basic_Search"));
|
|
|
|
this.setMnemonic('S');
|
|
|
|
this.setSmallIcon("/com/fr/design/standard/search", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
// 交换层级
|
|
|
|
toolbarPane.switchPane(TreeSearchToolbarPane.SEARCH_PANE);
|
|
|
|
TableDataTreeSearchManager.getInstance().switchToSearch(TableDataSearchMode.match(buttonGroup.getSelectedIndex()), DesignTableDataManager.getEditingTableDataSource());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void checkEnable() {
|
|
|
|
this.checkButtonEnabled();
|
|
|
|
}
|
|
|
|
}
|