From fd939227fc4cde566cb9040ad413a8de8fdd06c7 Mon Sep 17 00:00:00 2001 From: zack Date: Mon, 25 Apr 2016 20:01:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=B8=8B=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=9B=86=E5=88=86=E7=BB=84=E7=9A=84=E4=BB=A3=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E7=88=B6=E7=B1=BB=E9=87=8C=E9=9D=A2=E5=A4=9A=E6=94=BE=E7=82=B9?= =?UTF-8?q?=E4=B8=9C=E8=A5=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/data/BasicTableDataTreePane.java | 422 ++++++++++++++- .../data/datapane/TableDataSourceOP.java | 8 +- .../data/datapane/TableDataTreePane.java | 494 +----------------- 3 files changed, 429 insertions(+), 495 deletions(-) diff --git a/designer_base/src/com/fr/design/data/BasicTableDataTreePane.java b/designer_base/src/com/fr/design/data/BasicTableDataTreePane.java index 96ecd3fe5..92771cf3a 100644 --- a/designer_base/src/com/fr/design/data/BasicTableDataTreePane.java +++ b/designer_base/src/com/fr/design/data/BasicTableDataTreePane.java @@ -1,41 +1,443 @@ package com.fr.design.data; +import com.fr.base.BaseUtils; +import com.fr.base.FRContext; +import com.fr.base.TableData; +import com.fr.data.impl.storeproc.StoreProcedure; +import com.fr.design.DesignModelAdapter; +import com.fr.design.actions.UpdateAction; +import com.fr.design.data.datapane.TableDataCreatorProducer; +import com.fr.design.data.datapane.TableDataNameObjectCreator; +import com.fr.design.data.datapane.TableDataSourceOP; import com.fr.design.data.datapane.TableDataTree; +import com.fr.design.data.tabledata.ResponseDataSourceChange; import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane; +import com.fr.design.data.tabledata.wrapper.StoreProcedureDataWrapper; +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.gui.ibutton.UIHeadGroup; +import com.fr.design.gui.itextfield.UITextField; +import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; +import com.fr.design.icon.IconPathConstants; import com.fr.design.mainframe.DockingView; +import com.fr.design.menu.LineSeparator; +import com.fr.design.menu.MenuDef; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; +import com.fr.general.NameObject; +import com.fr.stable.StringUtils; import javax.swing.*; +import javax.swing.event.CellEditorListener; +import javax.swing.event.ChangeEvent; +import javax.swing.tree.TreeCellEditor; +import java.awt.*; +import java.awt.event.*; +import java.util.EventObject; +import java.util.HashMap; +import java.util.Map; /** * Coder: zack * Date: 2016/4/22 * Time: 16:23 */ -public class BasicTableDataTreePane extends DockingView{ - @Override - public void refreshDockingView() { +public abstract class BasicTableDataTreePane extends DockingView implements ResponseDataSourceChange { + protected static final int PROCEDURE_NAME_INDEX = 4; + protected static final int TEMPLATE_TABLE_DATA = 0; + protected static final int SERVER_TABLE_DATA = 1; + protected MenuDef addMenuDef; + protected DesignModelAdapter tc; + protected UIHeadGroup buttonGroup; + protected String[] allDSNames; + protected ConnectionTableAction connectionTableAction; + + + private String type = ""; + /** + * 最佳位置 + * + * @return 返回位置 + */ + public Location preferredLocation() { + return Location.WEST_ABOVE; } + /** + * getViewTitle() + * + * @return + */ @Override public String getViewTitle() { - return null; + return Inter.getLocText("FR-Designer_TableData"); } + /** + * getViewIcon + * + * @return + */ @Override public Icon getViewIcon() { - return null; + return BaseUtils.readIcon(IconPathConstants.DS_ICON_PATH); } - @Override - public Location preferredLocation() { - return null; + /** + * 响应数据集改变 + */ + public void fireDSChanged() { + fireDSChanged(new HashMap()); + } + + + /** + * 响应数据集改变 + * + * @param map 数据集变化Map + */ + public void fireDSChanged(Map map) { + DesignTableDataManager.fireDSChanged(map); } public void dgEdit(final AbstractTableDataPane uPanel, String originalName) { + dgEdit(uPanel, originalName, false); + } + + public abstract void dgEdit(final AbstractTableDataPane uPanel, String originalName, boolean isUpdate); + + protected void doPropertyChange(BasicDialog dg, BasicPane.NamePane nPanel, final String oldName) { + type = dg.getTitle(); + nPanel.setShowText(StringUtils.BLANK); + dg.setButtonEnabled(true); + String tempName = nPanel.getObjectName(); + if (StringUtils.isBlank(tempName)) { + nPanel.setShowText(Inter.getLocText(new String[]{"DS-TableData", "ISEMPTY", "PLEASE", "GIVE-NAME"}, new String[]{"", ",", "", "!"})); + dg.setButtonEnabled(false); + } else if (!ComparatorUtils.equals(oldName, tempName) && isDsNameRepeaded(tempName, allDSNames)) { + String[] waring = new String[]{"DS-TableData", "Utils-has_been_existed", "PLEASE", "Rename"}; + String[] sign = new String[]{tempName, ",", "", "!"}; + nPanel.setShowText(Inter.getLocText(waring, sign)); + dg.setButtonEnabled(false); + } else if (isProcedureName(oldName)) { + if (isIncludeUnderline(tempName)) { + String[] datasource_underline = new String[]{"Datasource-Stored_Procedure", "Name", "can_not_include_underline"}; + String[] sign = new String[]{"", "", "!"}; + nPanel.setShowText(Inter.getLocText(datasource_underline, sign)); + dg.setButtonEnabled(false); + } + } else { + nPanel.setShowText(StringUtils.BLANK); + dg.setButtonEnabled(true); + } + } + + private boolean isProcedureName(String oldName) { + return oldName.length() >= PROCEDURE_NAME_INDEX && ComparatorUtils.equals(type, Inter.getLocText("Datasource-Stored_Procedure")); + } + + + private boolean isIncludeUnderline(String name) { + return ComparatorUtils.equals(name.indexOf(StoreProcedure.SPLIT), -1) ? false : true; + } + + public abstract TableDataTree getDataTree(); + + public abstract void refreshDockingView(); + + protected void checkButtonEnabled(UpdateAction editAction, UpdateAction previewTableDataAction, UpdateAction removeAction, TableDataSourceOP op, TableDataTree dataTree) { + // august:BUG 9344 + addMenuDef.setEnabled(true); + connectionTableAction.setEnabled(FRContext.getCurrentEnv() != null && FRContext.getCurrentEnv().isRoot()); + if (op == null || op.interceptButtonEnabled()) { + addMenuDef.setEnabled(false); + editAction.setEnabled(false); + removeAction.setEnabled(false); + previewTableDataAction.setEnabled(false); + return; + } + if (op.getDataMode() == SERVER_TABLE_DATA) { + addMenuDef.setEnabled(false); + removeAction.setEnabled(false); + } + int selectioncount = dataTree.getSelectionCount(); + switch (selectioncount) { + case 0: + editAction.setEnabled(false); + removeAction.setEnabled(false); + previewTableDataAction.setEnabled(false); + break; + case 1: + boolean istmp = false; + if (dataTree.getSelectedNameObject().getObject() == null || dataTree.getSelectedNameObject().getObject() instanceof TemplateTableDataWrapper) { + istmp = true; + } + editAction.setEnabled(istmp); + removeAction.setEnabled(istmp); + previewTableDataAction.setEnabled(true); + break; + default: + editAction.setEnabled(false); + previewTableDataAction.setEnabled(false); + + } + if (dataTree.getSelectionPath() != null) { + ExpandMutableTreeNode selectedTreeNode = (ExpandMutableTreeNode) dataTree.getSelectionPath().getLastPathComponent(); + if (selectedTreeNode.getUserObject() instanceof String) { + previewTableDataAction.setEnabled(false); + editAction.setEnabled(false); + removeAction.setEnabled(false); + } + } + } + + protected class TableDataTreeCellEditor extends DefaultCellEditor implements TreeCellEditor, CellEditorListener { + private NameObject editingNO; + private String oldName; + private String newName; + private UITextField jTextField; + private TableDataTree dataTree; + private BasicTableDataTreePane pane; + + public TableDataTreeCellEditor(final UITextField textField, TableDataTree dataTree, BasicTableDataTreePane pane) { + super(textField); + this.jTextField = textField; + this.dataTree = dataTree; + this.pane = pane; + } + + @Override + public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) { + editingNO = dataTree.getSelectedNameObject(); + + oldName = editingNO.getName(); + + delegate.setValue(oldName); + + if (jTextField != null) { + jTextField.addFocusListener(new FocusAdapter() { + + @Override + public void focusLost(FocusEvent e) { + // stopCellEditing 执行过程中会调用到 getCellEditorValue + stopCellEditing(); + } + }); + } + + editorComponent.setPreferredSize(new java.awt.Dimension(pane.getPreferredSize().width, editorComponent.getPreferredSize().height)); + + return editorComponent; + } + + @Override + public boolean isCellEditable(EventObject anEvent) { + NameObject no = dataTree.getSelectedNameObject(); + return no != null && anEvent == null; + + } + + @Override + public Object getCellEditorValue() { + newName = super.getCellEditorValue().toString(); + + editingNO.setName(newName); + + // 如果没有重命名成功,则还原成原来的oldName + if (tc != null && !tc.renameTableData(oldName, newName)) { + editingNO.setName(oldName); + } + if (dataTree.isNameRepeated(newName)) { + editingNO.setName(oldName); + } + + return editingNO; + } + + /* + * 下面两个方法是CellEditorListener的 + */ + @Override + public void editingCanceled(ChangeEvent e) { + } + + @Override + public void editingStopped(ChangeEvent e) { + } + } + + protected void initbuttonGroup(final TableDataSourceOP op) { + 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 = {Inter.getLocText(new String[]{"Template", "DS-TableData"}), Inter.getLocText("DS-Server_TableData")}; + buttonGroup = new UIHeadGroup(iconArray, 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(); + } + + } + }; + buttonGroup.setNeedLeftRightOutLine(false); + } + + protected void createAddMenuDef() { + TableDataNameObjectCreator[] creators = TableDataCreatorProducer.getInstance().createReportTableDataCreator(); + for (final TableDataNameObjectCreator creator : creators) { + if (creator.shouldInsertSeparator()) { + addMenuDef.addShortCut(new LineSeparator()); + } + + addMenuDef.addShortCut(new TDAction() { + @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() { + return new TemplateTableDataWrapper((TableData) creator.createObject()); + } + }); + } + } + + private abstract class TDAction extends UpdateAction { + + protected abstract String getTDName(); + + protected abstract Icon getTDIcon(); + + protected abstract String getNamePrefix(); + + protected abstract TemplateTableDataWrapper getTableDataInstance(); + + public TDAction() { + this.setName(this.getTDName()); + this.setSmallIcon(this.getTDIcon()); + } + + public void actionPerformed(ActionEvent e) { + dgEdit(getTableDataInstance().creatTableDataPane(), createDsName(getNamePrefix()), false); + } } - public TableDataTree getDataTree() { - return null; + private String createDsName(String prefix) { + int count = 1; + allDSNames = DesignTableDataManager.getAllDSNames(tc.getBook()); + while (isDsNameRepeaded(prefix + count, allDSNames)) { + count++; + } + return prefix + count; + } + + private boolean isDsNameRepeaded(String name, String[] names) { + boolean repeat = false; + for (int i = 0; i < names.length; i++) { + if (ComparatorUtils.equals(name, names[i])) { + repeat = true; + } + } + return repeat; + } + + protected KeyAdapter getTableTreeNodeListener(final UpdateAction editAction, final UpdateAction previewTableDataAction, final UpdateAction removeAction, final TableDataSourceOP op, final TableDataTree dataTree) { + return new KeyAdapter() { + + @Override + public void keyPressed(KeyEvent e) { + //F2重命名先屏蔽了, 有bug没时间弄 + if (e.getKeyCode() == KeyEvent.VK_F2) { + return; + } + + super.keyPressed(e); + } + + @Override + public void keyReleased(KeyEvent e) { + checkButtonEnabled(editAction, previewTableDataAction, removeAction, op, dataTree); + } + }; + } + + /** + * 创建不重复的名字即初始的默认名 + * + * @param tree 树 + * @param prefix 后缀 + * @return 返回名字 + */ + public static String createUnrepeatedName(TableDataTree tree, String prefix) { + int count = 1; + + while (tree.isNameRepeated(prefix + count)) { + count++; + } + return prefix + count; + } + + protected class PreviewTableDataAction extends UpdateAction { + private TableDataTree dataTree; + + public PreviewTableDataAction(TableDataTree dataTree) { + this.setName(Inter.getLocText("FR-Designer_Preview")); + this.setMnemonic('p'); + this.setSmallIcon(BaseUtils.readIcon(IconPathConstants.PREVIEW_ICON_PATH)); + this.dataTree = dataTree; + } + + @Override + public void actionPerformed(ActionEvent e) { + NameObject selectedNO = dataTree.getRealSelectedNameObject(); + Object data = null; + if (selectedNO != null) { + data = selectedNO.getObject(); + } + try { + if (((TableDataWrapper) data).getTableData() instanceof StoreProcedure) { + ((StoreProcedure) (((TableDataWrapper) data).getTableData())).resetDataModelList(); + if (data instanceof StoreProcedureDataWrapper) { + StoreProcedureDataWrapper oldSdw = ((StoreProcedureDataWrapper) data); + StoreProcedureDataWrapper newSdw = new StoreProcedureDataWrapper((StoreProcedure) oldSdw.getTableData(), oldSdw.getStoreprocedureName(), oldSdw.getTableDataName()); + newSdw.previewData(StoreProcedureDataWrapper.PREVIEW_ONE); + } else { + StoreProcedure storeProcedure = (StoreProcedure) ((TableDataWrapper) data).getTableData(); + StoreProcedureDataWrapper storeProcedureDataWrapper = new StoreProcedureDataWrapper(storeProcedure, StringUtils.EMPTY, StringUtils.EMPTY); + storeProcedureDataWrapper.previewData(StoreProcedureDataWrapper.PREVIEW_ALL); + } + } else { + ((TableDataWrapper) data).previewData(); + } + + } catch (Exception ex) { + FRContext.getLogger().error(ex.getMessage(), ex); + } + + } + } + + protected class ConnectionTableAction extends com.fr.design.actions.server.ConnectionListAction { + + public ConnectionTableAction() { + this.setName(Inter.getLocText("Server-Define_Data_Connection")); + this.setMnemonic('D'); + this.setSmallIcon(BaseUtils.readIcon(IconPathConstants.TD_CONNECTION_ICON_PATH)); + } } } diff --git a/designer_base/src/com/fr/design/data/datapane/TableDataSourceOP.java b/designer_base/src/com/fr/design/data/datapane/TableDataSourceOP.java index da85a4241..2c7d7726f 100644 --- a/designer_base/src/com/fr/design/data/datapane/TableDataSourceOP.java +++ b/designer_base/src/com/fr/design/data/datapane/TableDataSourceOP.java @@ -84,7 +84,7 @@ public class TableDataSourceOP implements UserObjectOP { } } - private ExpandMutableTreeNode[] getNodeArrayFromMap(Map map) { + protected ExpandMutableTreeNode[] getNodeArrayFromMap(Map map) { List dataList = new ArrayList(); Iterator> entryIt = map.entrySet().iterator(); while (entryIt.hasNext()) { @@ -181,7 +181,7 @@ public class TableDataSourceOP implements UserObjectOP { } } - private void setStoreProcedureTree(TableData tableData, ExpandMutableTreeNode tmpNode) { + protected void setStoreProcedureTree(TableData tableData, ExpandMutableTreeNode tmpNode) { ArrayList nodeName = new ArrayList(); StoreProcedure storeProcedure = (StoreProcedure) tableData; String name = ((NameObject) tmpNode.getUserObject()).getName(); @@ -229,11 +229,11 @@ public class TableDataSourceOP implements UserObjectOP { } - protected void setDataMode(int i) { + public void setDataMode(int i) { this.dataMode = i; } - protected int getDataMode() { + public int getDataMode() { return dataMode; } diff --git a/designer_base/src/com/fr/design/data/datapane/TableDataTreePane.java b/designer_base/src/com/fr/design/data/datapane/TableDataTreePane.java index 375f455a5..e9f1074ff 100644 --- a/designer_base/src/com/fr/design/data/datapane/TableDataTreePane.java +++ b/designer_base/src/com/fr/design/data/datapane/TableDataTreePane.java @@ -1,35 +1,26 @@ package com.fr.design.data.datapane; import com.fr.base.BaseUtils; -import com.fr.base.FRContext; import com.fr.base.TableData; import com.fr.data.TableDataSource; -import com.fr.data.impl.storeproc.StoreProcedure; import com.fr.design.DesignModelAdapter; import com.fr.design.ExtraDesignClassManager; import com.fr.design.actions.UpdateAction; import com.fr.design.data.BasicTableDataTreePane; import com.fr.design.data.DesignTableDataManager; -import com.fr.design.data.tabledata.ResponseDataSourceChange; import com.fr.design.data.tabledata.StoreProcedureWorkerListener; import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane; import com.fr.design.data.tabledata.wrapper.AbstractTableDataWrapper; -import com.fr.design.data.tabledata.wrapper.StoreProcedureDataWrapper; -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.fun.TableDataTreePaneProcessor; -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.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; @@ -37,36 +28,22 @@ import com.fr.general.ComparatorUtils; import com.fr.general.GeneralContext; import com.fr.general.Inter; import com.fr.general.NameObject; -import com.fr.stable.StringUtils; import com.fr.stable.core.PropertyChangeAdapter; import com.fr.stable.plugin.PluginReadListener; import javax.swing.*; -import javax.swing.event.CellEditorListener; -import javax.swing.event.ChangeEvent; -import javax.swing.tree.TreeCellEditor; import java.awt.*; import java.awt.dnd.DnDConstants; -import java.awt.event.*; -import java.util.EventObject; +import java.awt.event.ActionEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.util.HashMap; import java.util.Map; -public class TableDataTreePane extends BasicTableDataTreePane implements ResponseDataSourceChange { - - protected static final int PROCEDURE_NAME_INDEX = 4; - protected static final int TEMPLATE_TABLE_DATA = 0; - protected static final int SERVER_TABLE_DATA = 1; - private static final long serialVersionUID = -12168467370000617L; +public class TableDataTreePane extends BasicTableDataTreePane { private static TableDataTreePane singleton = new TableDataTreePane(); - private String type = ""; - /** - * 得到实例 - * - * @param tc - * @return - */ + public synchronized static BasicTableDataTreePane getInstance(DesignModelAdapter tc) { TableDataTreePaneProcessor treePaneProcessor = ExtraDesignClassManager.getInstance().getTableDataTreePaneProcessor(); @@ -84,17 +61,11 @@ public class TableDataTreePane extends BasicTableDataTreePane implements Respons return singleton; } - private TableDataTree dataTree; private TableDataSourceOP op; - - private MenuDef addMenuDef; + private TableDataTree dataTree; private EditAction editAction; private RemoveAction removeAction; - private DesignModelAdapter tc; private PreviewTableDataAction previewTableDataAction; - private ConnectionTableAction connectionTableAction; - private UIHeadGroup buttonGroup; - private String[] allDSNames; private TableDataTreePane() { this.setLayout(new BorderLayout(4, 0)); @@ -118,7 +89,7 @@ public class TableDataTreePane extends BasicTableDataTreePane implements Respons editAction = new EditAction(); removeAction = new RemoveAction(); - previewTableDataAction = new PreviewTableDataAction(); + previewTableDataAction = new PreviewTableDataAction(dataTree); connectionTableAction = new ConnectionTableAction(); ToolBarDef toolbarDef = new ToolBarDef(); toolbarDef.addShortCut(addMenuDef, SeparatorDef.DEFAULT, editAction, removeAction, SeparatorDef.DEFAULT, previewTableDataAction, connectionTableAction); @@ -131,7 +102,7 @@ public class TableDataTreePane extends BasicTableDataTreePane implements Respons UIScrollPane scrollPane = new UIScrollPane(dataTree); scrollPane.setBorder(null); - initbuttonGroup(); + initbuttonGroup(op); JPanel jPanel = new JPanel(new BorderLayout(4, 4)); JPanel buttonPane = new JPanel(new GridLayout()); buttonPane.add(buttonGroup, BorderLayout.CENTER); @@ -144,211 +115,21 @@ public class TableDataTreePane extends BasicTableDataTreePane implements Respons checkButtonEnabled(); } }); - dataTree.addKeyListener(getTableTreeNodeListener()); + dataTree.addKeyListener(getTableTreeNodeListener(editAction, previewTableDataAction, removeAction, op, dataTree)); // TreeCellEditor dataTree.setEditable(true); - TableDataTreeCellEditor treeCellEditor = new TableDataTreeCellEditor(new UITextField()); + TableDataTreeCellEditor treeCellEditor = new TableDataTreeCellEditor(new UITextField(), dataTree, this); treeCellEditor.addCellEditorListener(treeCellEditor); dataTree.setCellEditor(treeCellEditor); new TableDataTreeDragSource(dataTree, DnDConstants.ACTION_COPY); checkButtonEnabled(); } - public void setDataTree(TableDataTree dataTree) { - this.dataTree = dataTree; - } - - public TableDataSourceOP getOp() { - return op; - } - - public void setOp(TableDataSourceOP op) { - this.op = op; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public MenuDef getAddMenuDef() { - return addMenuDef; - } - - public void setAddMenuDef(MenuDef addMenuDef) { - this.addMenuDef = addMenuDef; - } - - public EditAction getEditAction() { - return editAction; - } - - public void setEditAction(EditAction editAction) { - this.editAction = editAction; - } - - public RemoveAction getRemoveAction() { - return removeAction; - } - - public void setRemoveAction(RemoveAction removeAction) { - this.removeAction = removeAction; - } - - public DesignModelAdapter getTc() { - return tc; - } - - public void setTc(DesignModelAdapter tc) { - this.tc = tc; - } - - public PreviewTableDataAction getPreviewTableDataAction() { - return previewTableDataAction; - } - - public void setPreviewTableDataAction(PreviewTableDataAction previewTableDataAction) { - this.previewTableDataAction = previewTableDataAction; - } - - public ConnectionTableAction getConnectionTableAction() { - return connectionTableAction; - } - - public void setConnectionTableAction(ConnectionTableAction connectionTableAction) { - this.connectionTableAction = connectionTableAction; - } - - private KeyAdapter getTableTreeNodeListener() { - return new KeyAdapter() { - - @Override - public void keyPressed(KeyEvent e) { - //F2重命名先屏蔽了, 有bug没时间弄 - if (e.getKeyCode() == KeyEvent.VK_F2){ - return; - } - - super.keyPressed(e); - } - - @Override - public void keyReleased(KeyEvent e) { - checkButtonEnabled(); - } - }; - } - - private void createAddMenuDef() { - TableDataNameObjectCreator[] creators = TableDataCreatorProducer.getInstance().createReportTableDataCreator(); - for (final TableDataNameObjectCreator creator : creators) { - if (creator.shouldInsertSeparator()) { - addMenuDef.addShortCut(new LineSeparator()); - } - - addMenuDef.addShortCut(new TDAction() { - @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() { - return new TemplateTableDataWrapper((TableData) creator.createObject()); - } - }); - } - } - - private 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 = {Inter.getLocText(new String[]{"Template", "DS-TableData"}), Inter.getLocText("DS-Server_TableData")}; - buttonGroup = new UIHeadGroup(iconArray, 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(); - } - - } - }; - buttonGroup.setNeedLeftRightOutLine(false); - } - - /** - * getViewIcon - * - * @return - */ - public Icon getViewIcon() { - return BaseUtils.readIcon(IconPathConstants.DS_ICON_PATH); - } - - /** - * 刷新 - */ - public void refresh() { - dataTree.refresh(); - } protected void checkButtonEnabled() { - // august:BUG 9344 - addMenuDef.setEnabled(true); - connectionTableAction.setEnabled(FRContext.getCurrentEnv() != null && FRContext.getCurrentEnv().isRoot()); - if (this.op == null || this.op.interceptButtonEnabled()) { - addMenuDef.setEnabled(false); - editAction.setEnabled(false); - removeAction.setEnabled(false); - previewTableDataAction.setEnabled(false); - return; - } - if (this.op.getDataMode() == SERVER_TABLE_DATA) { - addMenuDef.setEnabled(false); - removeAction.setEnabled(false); - } - int selectioncount = dataTree.getSelectionCount(); - switch (selectioncount) { - case 0: - editAction.setEnabled(false); - removeAction.setEnabled(false); - previewTableDataAction.setEnabled(false); - break; - case 1: - boolean istmp = dataTree.getSelectedNameObject().getObject() instanceof TemplateTableDataWrapper; - editAction.setEnabled(istmp); - removeAction.setEnabled(istmp); - previewTableDataAction.setEnabled(true); - break; - default: - editAction.setEnabled(false); - previewTableDataAction.setEnabled(false); - - } - if (dataTree.getSelectionPath() != null) { - if (((ExpandMutableTreeNode) dataTree.getSelectionPath().getLastPathComponent()).getUserObject() instanceof String) { - previewTableDataAction.setEnabled(false); - editAction.setEnabled(false); - removeAction.setEnabled(false); - } - } + super.checkButtonEnabled(editAction, previewTableDataAction, removeAction, op, dataTree); } - /** * 刷新 */ @@ -357,122 +138,13 @@ public class TableDataTreePane extends BasicTableDataTreePane implements Respons this.checkButtonEnabled(); } - /** - * getViewTitle() - * - * @return - */ - public String getViewTitle() { - return Inter.getLocText("FR-Designer_TableData"); - } - - - /** - * 最佳位置 - * - * @return 返回位置 - */ - public Location preferredLocation() { - return Location.WEST_ABOVE; - } - - /** - * 响应数据集改变 - */ - public void fireDSChanged() { - fireDSChanged(new HashMap()); - } - - - /** - * 响应数据集改变 - * - * @param map 数据集变化Map - */ - public void fireDSChanged(Map map) { - DesignTableDataManager.fireDSChanged(map); - } - - private class TableDataTreeCellEditor extends DefaultCellEditor implements TreeCellEditor, CellEditorListener { - - private NameObject editingNO; - private String oldName; - private String newName; - private UITextField jTextField; - - public TableDataTreeCellEditor(final UITextField textField) { - super(textField); - this.jTextField = textField; - } - - @Override - public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) { - editingNO = dataTree.getSelectedNameObject(); - - oldName = editingNO.getName(); - - delegate.setValue(oldName); - - if (jTextField != null) { - jTextField.addFocusListener(new FocusAdapter() { - - @Override - public void focusLost(FocusEvent e) { - // stopCellEditing 执行过程中会调用到 getCellEditorValue - stopCellEditing(); - } - }); - } - - editorComponent.setPreferredSize(new java.awt.Dimension(TableDataTreePane.this.getPreferredSize().width, editorComponent.getPreferredSize().height)); - - return editorComponent; - } - - @Override - public boolean isCellEditable(EventObject anEvent) { - NameObject no = dataTree.getSelectedNameObject(); - return no != null && anEvent == null; - - } - - @Override - public Object getCellEditorValue() { - newName = super.getCellEditorValue().toString(); - - editingNO.setName(newName); - - // 如果没有重命名成功,则还原成原来的oldName - if (tc != null && !tc.renameTableData(oldName, newName)) { - editingNO.setName(oldName); - } - if (dataTree.isNameRepeated(newName)) { - editingNO.setName(oldName); - } - - return editingNO; - } - - /* - * 下面两个方法是CellEditorListener的 - */ - @Override - public void editingCanceled(ChangeEvent e) { - } - - @Override - public void editingStopped(ChangeEvent e) { - } - } - - /** * 编辑面板 * * @param uPanel 面板 * @param originalName 原始名字 */ - public void dgEdit(final AbstractTableDataPane uPanel, String originalName) { + public void dgEdit(final AbstractTableDataPane uPanel, String originalName, boolean isUpdate) { uPanel.addStoreProcedureWorkerListener(new StoreProcedureWorkerListener() { public void fireDoneAction() { if (dataTree.getSelectionPath() == null) { @@ -519,137 +191,6 @@ public class TableDataTreePane extends BasicTableDataTreePane implements Respons dg.setVisible(true); } - private void doPropertyChange(BasicDialog dg, BasicPane.NamePane nPanel, final String oldName) { - type = dg.getTitle(); - nPanel.setShowText(StringUtils.BLANK); - dg.setButtonEnabled(true); - String tempName = nPanel.getObjectName(); - if (StringUtils.isBlank(tempName)) { - nPanel.setShowText(Inter.getLocText(new String[]{"DS-TableData", "ISEMPTY", "PLEASE", "GIVE-NAME"}, new String[]{"", ",", "", "!"})); - dg.setButtonEnabled(false); - } else if (!ComparatorUtils.equals(oldName, tempName) && isDsNameRepeaded(tempName, allDSNames)) { - String[] waring = new String[]{"DS-TableData", "Utils-has_been_existed", "PLEASE", "Rename"}; - String[] sign = new String[]{tempName, ",", "", "!"}; - nPanel.setShowText(Inter.getLocText(waring, sign)); - dg.setButtonEnabled(false); - } else if (isProcedureName(oldName)) { - if (isIncludeUnderline(tempName)) { - String[] datasource_underline = new String[]{"Datasource-Stored_Procedure", "Name", "can_not_include_underline"}; - String[] sign = new String[]{"", "", "!"}; - nPanel.setShowText(Inter.getLocText(datasource_underline, sign)); - dg.setButtonEnabled(false); - } - } else { - nPanel.setShowText(StringUtils.BLANK); - dg.setButtonEnabled(true); - } - } - - - private boolean isProcedureName(String oldName) { - return oldName.length() >= PROCEDURE_NAME_INDEX && ComparatorUtils.equals(type, Inter.getLocText("Datasource-Stored_Procedure")); - } - - - private boolean isDsNameRepeaded(String name, String[] names) { - boolean repeat = false; - for (int i = 0; i < names.length; i++) { - if (ComparatorUtils.equals(name, names[i])) { - repeat = true; - } - } - return repeat; - } - - - private boolean isIncludeUnderline(String name) { - return ComparatorUtils.equals(name.indexOf(StoreProcedure.SPLIT), -1) ? false : true; - } - - - private abstract class TDAction extends UpdateAction { - - protected abstract String getTDName(); - - protected abstract Icon getTDIcon(); - - protected abstract String getNamePrefix(); - - protected abstract TemplateTableDataWrapper getTableDataInstance(); - - public TDAction() { - this.setName(this.getTDName()); - this.setSmallIcon(this.getTDIcon()); - } - - public void actionPerformed(ActionEvent e) { - dgEdit(getTableDataInstance().creatTableDataPane(), createDsName(getNamePrefix())); - } - } - - private String createDsName(String prefix) { - int count = 1; - allDSNames = DesignTableDataManager.getAllDSNames(tc.getBook()); - while (isDsNameRepeaded(prefix + count, allDSNames)) { - count++; - } - return prefix + count; - } - - /** - * 创建不重复的名字即初始的默认名 - * - * @param tree 树 - * @param prefix 后缀 - * @return 返回名字 - */ - public static String createUnrepeatedName(TableDataTree tree, String prefix) { - int count = 1; - - while (tree.isNameRepeated(prefix + count)) { - count++; - } - return prefix + count; - } - - private class PreviewTableDataAction extends UpdateAction { - - public PreviewTableDataAction() { - this.setName(Inter.getLocText("FR-Designer_Preview")); - this.setMnemonic('p'); - this.setSmallIcon(BaseUtils.readIcon(IconPathConstants.PREVIEW_ICON_PATH)); - } - - @Override - public void actionPerformed(ActionEvent e) { - NameObject selectedNO = dataTree.getRealSelectedNameObject(); - Object data = null; - if (selectedNO != null) { - data = selectedNO.getObject(); - } - try { - if (((TableDataWrapper) data).getTableData() instanceof StoreProcedure) { - ((StoreProcedure) (((TableDataWrapper) data).getTableData())).resetDataModelList(); - if (data instanceof StoreProcedureDataWrapper) { - StoreProcedureDataWrapper oldSdw = ((StoreProcedureDataWrapper) data); - StoreProcedureDataWrapper newSdw = new StoreProcedureDataWrapper((StoreProcedure) oldSdw.getTableData(), oldSdw.getStoreprocedureName(), oldSdw.getTableDataName()); - newSdw.previewData(StoreProcedureDataWrapper.PREVIEW_ONE); - } else { - StoreProcedure storeProcedure = (StoreProcedure) ((TableDataWrapper) data).getTableData(); - StoreProcedureDataWrapper storeProcedureDataWrapper = new StoreProcedureDataWrapper(storeProcedure, StringUtils.EMPTY, StringUtils.EMPTY); - storeProcedureDataWrapper.previewData(StoreProcedureDataWrapper.PREVIEW_ALL); - } - } else { - ((TableDataWrapper) data).previewData(); - } - - } catch (Exception ex) { - FRContext.getLogger().error(ex.getMessage(), ex); - } - - } - } - private class EditAction extends UpdateAction { public EditAction() { this.setName(Inter.getLocText("FR-Designer_Edit")); @@ -662,8 +203,7 @@ public class TableDataTreePane extends BasicTableDataTreePane implements Respons if (selectedNO == null) { return; } - - dgEdit(((AbstractTableDataWrapper) selectedNO.getObject()).creatTableDataPane(), selectedNO.getName()); + dgEdit(((AbstractTableDataWrapper) selectedNO.getObject()).creatTableDataPane(), selectedNO.getName(), false); } } @@ -704,14 +244,6 @@ public class TableDataTreePane extends BasicTableDataTreePane implements Respons checkButtonEnabled(); } - private class ConnectionTableAction extends com.fr.design.actions.server.ConnectionListAction { - - public ConnectionTableAction() { - this.setName(Inter.getLocText("Server-Define_Data_Connection")); - this.setMnemonic('D'); - this.setSmallIcon(BaseUtils.readIcon(IconPathConstants.TD_CONNECTION_ICON_PATH)); - } - } /** * @return