From b20500ac93987efe69fedf9ec4b6557cf8dff2ab Mon Sep 17 00:00:00 2001 From: finereport Date: Fri, 1 Sep 2017 16:08:28 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=95=B0=E6=8D=AE=E9=9B=86=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E9=9A=8F=E6=84=8F=E9=80=89=E5=8F=96=E5=85=B6=E4=BB=96=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E7=9A=84=E6=95=B0=E6=8D=AE=E8=BF=9E=E6=8E=A5=E7=9A=84?= =?UTF-8?q?BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../connect/ConnectionTableProcedurePane.java | 13 +++++++++++++ .../tabledata/tabledatapane/DBTableDataPane.java | 13 ++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/designer_base/src/com/fr/design/data/datapane/connect/ConnectionTableProcedurePane.java b/designer_base/src/com/fr/design/data/datapane/connect/ConnectionTableProcedurePane.java index 23b62431ec..0377f0bd4a 100644 --- a/designer_base/src/com/fr/design/data/datapane/connect/ConnectionTableProcedurePane.java +++ b/designer_base/src/com/fr/design/data/datapane/connect/ConnectionTableProcedurePane.java @@ -1,6 +1,8 @@ package com.fr.design.data.datapane.connect; import com.fr.base.BaseUtils; +import com.fr.data.impl.AbstractDatabaseConnection; +import com.fr.data.impl.Connection; import com.fr.design.constants.UIConstants; import com.fr.data.core.db.TableProcedure; import com.fr.design.border.UIRoundedBorder; @@ -20,6 +22,7 @@ import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import java.awt.*; import java.awt.event.*; +import java.util.List; /** * 数据集编辑面板左边的部分 @@ -39,6 +42,12 @@ public class ConnectionTableProcedurePane extends BasicPane { public ConnectionTableProcedurePane() { this.setLayout(new BorderLayout(4, 4)); connectionComboBox = new ConnectionComboBoxPanel(com.fr.data.impl.Connection.class) { + + @Override + protected void filterConnection(Connection connection, String conName, List nameList) { + filter(connection, conName, nameList); + } + protected void refreshItems() { super.refreshItems(); if (tableViewList != null) { @@ -83,6 +92,10 @@ public class ConnectionTableProcedurePane extends BasicPane { this.setPreferredSize(new Dimension(WIDTH, getPreferredSize().height)); } + protected void filter(Connection connection, String conName, List nameList) { + connection.addConnection(nameList, conName, new Class[]{AbstractDatabaseConnection.class}); + } + protected JPanel createCheckBoxgroupPane() { JPanel checkBoxgroupPane = FRGUIPaneFactory.createNColumnGridInnerContainer_S_Pane(2); JPanel first = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); diff --git a/designer_base/src/com/fr/design/data/tabledata/tabledatapane/DBTableDataPane.java b/designer_base/src/com/fr/design/data/tabledata/tabledatapane/DBTableDataPane.java index 75b3219ebd..947e17106b 100644 --- a/designer_base/src/com/fr/design/data/tabledata/tabledatapane/DBTableDataPane.java +++ b/designer_base/src/com/fr/design/data/tabledata/tabledatapane/DBTableDataPane.java @@ -5,7 +5,11 @@ import com.fr.base.FRContext; import com.fr.base.Parameter; import com.fr.base.ParameterHelper; import com.fr.data.core.db.TableProcedure; +import com.fr.data.impl.AbstractDatabaseConnection; +import com.fr.data.impl.Connection; import com.fr.data.impl.DBTableData; +import com.fr.data.impl.JDBCDatabaseConnection; +import com.fr.data.impl.JNDIDatabaseConnection; import com.fr.data.impl.NameDatabaseConnection; import com.fr.design.ExtraDesignClassManager; import com.fr.design.actions.UpdateAction; @@ -37,6 +41,7 @@ import com.fr.script.Calculator; import com.fr.stable.ArrayUtils; import com.fr.stable.ParameterProvider; import com.fr.stable.StringUtils; +import org.sqlite.JDBC; import javax.swing.*; import javax.swing.text.BadLocationException; @@ -102,7 +107,12 @@ public class DBTableDataPane extends AbstractTableDataPane { sqlSplitPane.add(box, BorderLayout.CENTER); // 左边的Panel,上面是选择DatabaseConnection的ComboBox,下面DatabaseConnection对应的Table - connectionTableProcedurePane = new ConnectionTableProcedurePane(); + connectionTableProcedurePane = new ConnectionTableProcedurePane() { + @Override + protected void filter(Connection connection, String conName, List nameList) { + connection.addConnection(nameList, conName, new Class[]{JDBCDatabaseConnection.class, JNDIDatabaseConnection.class}); + } + }; connectionTableProcedurePane.addDoubleClickListener(new DoubleClickSelectedNodeOnTreeListener() { @Override @@ -138,6 +148,7 @@ public class DBTableDataPane extends AbstractTableDataPane { this.add(mainSplitPane, BorderLayout.CENTER); } + private boolean isPreviewOrRefreshButton (FocusEvent e) { if (e.getOppositeComponent() != null) { String name = e.getOppositeComponent().getName(); From aaeb8067456e30b2d272513eb4d993ab59b8e2fd Mon Sep 17 00:00:00 2001 From: zhouping Date: Mon, 4 Sep 2017 15:10:33 +0800 Subject: [PATCH 2/5] =?UTF-8?q?REPORT-2975=209.0=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=20=E5=90=8C=E6=AD=A5=E4=B8=80=E4=BB=BD?= =?UTF-8?q?=E5=88=B0master?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- designer_base/src/com/fr/design/gui/ilable/UILabel.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/designer_base/src/com/fr/design/gui/ilable/UILabel.java b/designer_base/src/com/fr/design/gui/ilable/UILabel.java index b1c90d8ff5..c0b921dee1 100644 --- a/designer_base/src/com/fr/design/gui/ilable/UILabel.java +++ b/designer_base/src/com/fr/design/gui/ilable/UILabel.java @@ -29,6 +29,11 @@ public class UILabel extends JLabel { super(text); } + public UILabel(String text, boolean enable) { + super(text); + this.setEnabled(enable); + } + public UILabel(Icon image, int horizontalAlignment) { super(image, horizontalAlignment); } From 3165d1fcfe0631add57eb6f56c9d770d0c97000f Mon Sep 17 00:00:00 2001 From: juhaoyu <2335173323@qq.com> Date: Wed, 13 Sep 2017 18:45:59 +0800 Subject: [PATCH 3/5] =?UTF-8?q?BI=E5=90=AF=E5=8A=A8=E7=94=A8=E4=BA=86UIbut?= =?UTF-8?q?ton=EF=BC=8C=E5=AF=BC=E8=87=B4FRCoreContext=E6=8F=90=E5=89=8D?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/fr/design/roleAuthority/ReportAndFSManagePane.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/designer_base/src/com/fr/design/roleAuthority/ReportAndFSManagePane.java b/designer_base/src/com/fr/design/roleAuthority/ReportAndFSManagePane.java index 4555c336bb..98c570786c 100644 --- a/designer_base/src/com/fr/design/roleAuthority/ReportAndFSManagePane.java +++ b/designer_base/src/com/fr/design/roleAuthority/ReportAndFSManagePane.java @@ -1 +1 @@ -package com.fr.design.roleAuthority; import com.fr.base.BaseUtils; import com.fr.base.FRCoreContext; import com.fr.design.actions.UpdateAction; import com.fr.design.constants.UIConstants; import com.fr.design.data.DesignTableDataManager; import com.fr.design.data.tabledata.Prepare4DataSourceChange; import com.fr.design.gui.ibutton.UIHeadGroup; import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.itoolbar.UIToolbar; import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DockingView; import com.fr.design.menu.ToolBarDef; import com.fr.general.Inter; import com.fr.general.VT4FR; import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.TreeSelectionEvent; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.Enumeration; /** * 设计器左下角面板,用于在权限编辑时存放角色 * Author : daisy * Date: 13-8-30 * Time: 下午2:22 */ public class ReportAndFSManagePane extends DockingView implements Prepare4DataSourceChange { private static final int REPORT_PLATEFORM_MANAGE = 0; private static final int FS_MANAGE = 1; private static final int LEFT_GAP = -125; private static boolean isSupportFS = false; private TreePath treePath = null; private static ReportAndFSManagePane singleton = new ReportAndFSManagePane(); private static RoleTree roleTree; // carl:我先屏了,现在半拉子,等客户要了再好好做 // private AddAction addAction = new AddAction(); // private RemoveAction removeAction = new RemoveAction(); private RefreshAction refreshAction = new RefreshAction(); private UIHeadGroup buttonGroup; private RoleSourceOP op; protected String[] roleNames = new String[2]; public synchronized static ReportAndFSManagePane getInstance() { singleton.op = new RoleSourceOP(); singleton.op.setDataMode(isSupportFS ? FS_MANAGE : REPORT_PLATEFORM_MANAGE); singleton.setDefaultSelectedRole(); return singleton; } public ReportAndFSManagePane() { initRoleTree(); this.setLayout(new BorderLayout(4, 0)); this.setBorder(null); this.add(iniToolBarPane(), BorderLayout.NORTH); refreshAction.setEnabled(true); UIScrollPane scrollPane = new UIScrollPane(roleTree); scrollPane.setBorder(BorderFactory.createEmptyBorder(0, 24, 0, 0)); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); initbuttonGroup(); JPanel jPanel = new JPanel(new BorderLayout(4, 4)); JPanel buttonPane = new JPanel(new GridLayout()); buttonPane.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIConstants.LINE_COLOR)); buttonPane.add(buttonGroup, BorderLayout.CENTER); jPanel.add(buttonPane, BorderLayout.NORTH); jPanel.add(scrollPane, BorderLayout.CENTER); this.add(jPanel, BorderLayout.CENTER); registerDSChangeListener(); } private void initRoleTree() { roleTree = new RoleTree() { public void refreshRoleTree(String selectedRole) { super.refreshRoleTree(selectedRole); changeAlreadyEditedPaneRole(selectedRole); } protected void doWithValueChanged(TreeSelectionEvent e) { super.doWithValueChanged(e); TreeNode root = (TreeNode) roleTree.getModel().getRoot(); TreePath parent = new TreePath(root); setSelectedRole(roleTree.getSelectedRoleName(), parent); } protected void setTabRoleName(String roleName) { roleNames[getMode()] = roleTree.getSelectedRoleName(); } }; roleTree.setEnabled(true); roleTree.setEditable(false); // RoleTreeCellEditor treeCellEditor = new RoleTreeCellEditor(new UITextField()); // treeCellEditor.addCellEditorListener(treeCellEditor); // roleTree.setCellEditor(treeCellEditor); roleTree.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { super.mouseClicked(e); roleTree.setEditable(false); // int row = roleTree.getRowForLocation(e.getX(), e.getY()); // TreePath path = roleTree.getPathForLocation(e.getX(), e.getY()); // if (e.getClickCount() == 2 && buttonGroup.getSelectedIndex() == REPORT_PLATEFORM_MANAGE) { // PrivilegeManagerProvider pm = PrivilegeManager.getProviderInstance(); // AuthenticationProvider ap = pm.getAuthenticationProvider(); // if (!(ap instanceof DaoAuthenticationProvider)) { // roleTree.setEditable(true); // roleTree.startEditingAtPath(path); // treePath = path; // } // } } }); } private void changeAlreadyEditedPaneRole(String selectedRole) { RolesAlreadyEditedPane.getInstance().refreshDockingView(); RoleTree roleTree = RolesAlreadyEditedPane.getInstance().getRoleTree(); TreeNode root = (TreeNode) roleTree.getModel().getRoot(); TreePath parent = new TreePath(root); roleTree.setSelectedRole(selectedRole, parent); } public void setDefaultSelectedRole() { //设置选中的节点 TreeNode root = (TreeNode) roleTree.getModel().getRoot(); TreePath parent = new TreePath(root); ExpandMutableTreeNode node = (ExpandMutableTreeNode) parent.getLastPathComponent(); String selectedRole = null; if (singleton != null) { selectedRole = roleNames[getMode()]; } if (selectedRole == null) { if (node.getChildCount() <= 0 || node.getFirstChild().getChildCount() <= 0) { return; } selectedRole = node.getFirstChild().getChildAt(0).toString(); } roleTree.setSelectedRole(selectedRole, parent); } public RoleTree getRoleTree() { return roleTree; } /** * 检查f) 每增删改一个角色信息(及时保存),先对比下privilege下之前的角色信息有没有发生变化(即在此期间有没有在其他途径中修改过) */ private void checkChanges() { //如若有变化,则弹出下面的对话框 int returnVal = JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("FR-Designer_Role_changed_isRefresh") + "?", Inter.getLocText("FR-Designer_Refresh"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE); if (returnVal == JOptionPane.OK_OPTION) { roleTree.refreshTreeNode(); expandTree(roleTree, true); roleTree.updateUI(); } } private JPanel iniToolBarPane() { ToolBarDef toolbarDef = new ToolBarDef(); toolbarDef.addShortCut(refreshAction); UIToolbar toolBar = ToolBarDef.createJToolBar(); toolbarDef.updateToolBar(toolBar); JPanel toolbarPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); toolbarPane.add(toolBar, BorderLayout.CENTER); return toolbarPane; } private void initbuttonGroup() { isSupportFS = supportFineDecision(); Icon[] iconArray = null; String[] textArray = null; if (isSupportFS) { iconArray = new Icon[]{BaseUtils.readIcon("/com/fr/web/images/platform/demo.png")}; textArray = new String[]{Inter.getLocText("FR-Designer_FS_Name")}; } else { iconArray = new Icon[]{BaseUtils.readIcon("/com/fr/web/images/platform/platform_16_16.png")}; textArray = new String[]{Inter.getLocText("M_Server-Platform_Manager")}; } buttonGroup = new UIHeadGroup(iconArray, textArray) { public void tabChanged(int index) { roleTree.setEditable(false); if (op != null) { op.setDataMode(getMode()); //判断是否可编辑 refreshDockingView(); } setDefaultSelectedRole(); if (singleton != null) { changeAlreadyEditedPaneRole(roleNames[getMode()]); } } }; buttonGroup.setBorder(BorderFactory.createMatteBorder(1, LEFT_GAP, 0, 0, UIConstants.LINE_COLOR)); buttonGroup.setNeedLeftRightOutLine(false); } private boolean supportFineDecision() { byte[] bytes = FRCoreContext.getBytes(); return VT4FR.isLicAvailable(bytes) && VT4FR.FS_BI.support(); } private int getMode(){ return isSupportFS?FS_MANAGE: REPORT_PLATEFORM_MANAGE; } // /** // * 检查看看是否可以增删刷新按钮是都可以编辑,并且检查角色树是不是可以编辑 // */ // public void checkToolButtonsEnabled() { // if (buttonGroup.getSelectedIndex() == REPORT_PLATEFORM_MANAGE) { // PrivilegeManagerProvider pm = PrivilegeManager.getProviderInstance(); // AuthenticationProvider ap = pm.getAuthenticationProvider(); // PrivilegeFilter pf = pm.getPrivilegeFilter(); // boolean isClickable = !(ap instanceof DaoAuthenticationProvider) // && pf instanceof AuthorityControlFilter; // addAction.setEnabled(isClickable); // removeAction.setEnabled(isClickable); // } else { // addAction.setEnabled(false); // removeAction.setEnabled(false); // } // // } /** * 刷新界面 */ public void refreshDockingView() { populate(new RoleSourceOP()); // this.checkToolButtonsEnabled(); } private void populate(RoleSourceOP op) { this.op = op; roleTree.populate(op); expandTree(roleTree, true); } public String getViewTitle() { return null; } public Icon getViewIcon() { return null; } /** * 最佳定位 * @return 定位 */ public Location preferredLocation() { return null; } /** * 注册数据库改变的响应的Listener */ public void registerDSChangeListener() { DesignTableDataManager.addDsChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { roleTree.refreshTreeNode(); expandTree(roleTree, true); roleTree.updateUI(); } }); } // private class AddAction extends UpdateAction { // public AddAction() { // this.setName(Inter.getLocText("Add")); // this.setSmallIcon(BaseUtils.readIcon("/com/fr/base/images/cell/control/add.png")); // } // // @Override // public void actionPerformed(ActionEvent e) { // refreshDockingView(); // // DefaultTreeModel treeModel = (DefaultTreeModel) roleTree.getModel(); // ExpandMutableTreeNode root = (ExpandMutableTreeNode) treeModel.getRoot(); // ExpandMutableTreeNode parentNode = (ExpandMutableTreeNode) root.getChildAt(0); // String newName = Inter.getLocText("newNode") + (++newIndex); // parentNode.add(new ExpandMutableTreeNode(newName)); // op.addAction(newName); // roleTree.updateUI(); // // try { // synchronized (AuthorityRoleDAOManager.class) { // AuthorityControlFilter pf = AuthorityRoleDAOManager.getAuthControlFilter(true); // // if (AuthorityRoleDAOManager.getAuthorityAllocation(pf, newName) != null) { // newName = Inter.getLocText("newNode") + (++newIndex); // roleTree.refreshTreeNode(); // expandTree(roleTree, true); // } // // AuthorityRoleDAOManager.addAuthorityRole(pf, new Authority(newName), new Allocation(), false, true); // // AuthorityRoleDAOManager.doEnd(pf); // } // } catch (Exception e1) { // FRContext.getLogger().error(e1.getMessage(), e1); // } // } // } // private class RemoveAction extends UpdateAction { // // public RemoveAction() { // this.setName(Inter.getLocText("Remove")); // this.setSmallIcon(UIConstants.CLEAR_ICON); // } // // @Override // public void actionPerformed(ActionEvent e) { // // // NameObject selectedNO = roleTree.getSelectedNameObject(); // // if (selectedNO == null) { // return; // } // // int returnVal = JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("Utils-Are_you_sure_to_remove_the_selected_item") + ":" + selectedNO.getName() + "?", // Inter.getLocText("Remove"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); // if (returnVal == JOptionPane.OK_OPTION) { // op.removeAction(selectedNO.getName()); // // try { // AuthorityControlFilter pf = AuthorityRoleDAOManager.getAuthControlFilter(true); // // AuthorityRoleDAOManager.removeAuthorityRole(pf, new Authority(selectedNO.getName()), true); // AuthorityRoleDAOManager.doEnd(pf); // } catch (Exception e1) { // FRContext.getLogger().error(e1.getMessage(), e1); // } // // roleTree.refreshTreeNode(); // expandTree(roleTree, true); // roleTree.updateUI(); // roleTree.requestFocus(); // roleTree.setSelectionRow(roleTree.getRowCount() - 1); // } // } // } /* * 刷新ReportletsTree */ private class RefreshAction extends UpdateAction { public RefreshAction() { this.setName(Inter.getLocText("FR-Designer_Refresh")); this.setSmallIcon(UIConstants.REFRESH_ICON); } @Override public void actionPerformed(ActionEvent evt) { roleTree.refreshTreeNode(); expandTree(roleTree, true); roleTree.updateUI(); } } // private class RoleTreeCellEditor extends DefaultCellEditor implements TreeCellEditor, CellEditorListener { // // private NameObject editingNO; // private String oldName; // private String newName; // private UITextField jTextField; // // public RoleTreeCellEditor(final UITextField textField) { // super(textField); // this.jTextField = textField; // this.jTextField.setPreferredSize(new Dimension(DesignerEnvManager.getEnvManager().getLastWestRegionContainerWidth() - 5, this.jTextField.getHeight())); // } // // @Override // public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) { // editingNO = ReportAndFSManagePane.this.roleTree.getSelectedNameObject(); // oldName = editingNO.getName(); // // delegate.setValue(oldName); // // editorComponent.setPreferredSize(new java.awt.Dimension(ReportAndFSManagePane.this.getPreferredSize().width, editorComponent.getPreferredSize().height)); // // return editorComponent; // } // // @Override // // public boolean isCellEditable(EventObject anEvent) { // NameObject no = ReportAndFSManagePane.this.roleTree.getSelectedNameObject(); // return !(no.getName() == Inter.getLocText("Role")); // } // // @Override // public Object getCellEditorValue() { // newName = super.getCellEditorValue().toString(); // editingNO.setName(newName); // return editingNO; // } // // // private boolean checkRoleNameNotEmpty() { // refreshDockingView(); // // String currentText = delegate.getCellEditorValue().toString(); // boolean isContained = false; // AuthorityControlFilter pf = AuthorityRoleDAOManager.getAuthControlFilter(false); // if (pf != null && // !ComparatorUtils.equals(oldName, currentText)) { // try { // Iterator iterator = AuthorityRoleDAOManager.authorityAllocationIterator(pf); // // while (iterator.hasNext()) { // AuthorityAllocation authorityAllocation = (AuthorityAllocation) ((Map.Entry) iterator.next()) // .getValue(); // Authority _authority = authorityAllocation.getAuthority(); // if(ComparatorUtils.equals(_authority.getName(), currentText)){ // isContained = true; // break; // } // } // } catch (Exception e) { // } // } // // if (currentText.isEmpty() || isContained) { // JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("RoleName_Can_Not_Be_Null") + "!"); // roleTree.refreshTreeNode(); // expandTree(roleTree, true); // delegate.setValue(oldName); // return false; // } // return true; // } // // /* // * 下面两个方法是CellEditorListener的 // */ // @Override // public void editingCanceled(ChangeEvent e) { // if (!checkRoleNameNotEmpty()) { // treePath = null; // return; // } // roleTree.stopEditing(); // if (treePath == null) { // return; // } // changeValue(); // roleTree.refreshTreeNode(); // expandTree(roleTree, true); // } // // @Override // public void editingStopped(ChangeEvent e) { // if (!checkRoleNameNotEmpty()) { // treePath = null; // return; // } // changeValue(); // roleTree.refreshTreeNode(); // expandTree(roleTree, true); // roleTree.updateUI(); // } // // private void changeValue() { // newName = delegate.getCellEditorValue().toString(); // if (!newName.isEmpty() && newName != oldName) { // roleTree.setSelectedRoleName(newName); // op.rename(oldName, newName); // // AuthorityControlFilter pf = AuthorityRoleDAOManager.getAuthControlFilter(false); // if (pf != null) { // try { // Iterator iterator = AuthorityRoleDAOManager.authorityAllocationIterator(pf); // // while (iterator.hasNext()) { // AuthorityAllocation authorityAllocation = (AuthorityAllocation) ((Map.Entry) iterator.next()) // .getValue(); // Authority _authority = authorityAllocation.getAuthority(); // if (ComparatorUtils.equals(_authority.getName(), oldName)) { // _authority.setName(newName); // } // } // } catch (Exception e) { // } // } // // try { // AuthorityRoleDAOManager.doEnd(pf); // } catch (Exception e) { // FRContext.getLogger().error(e.getMessage(), e); // } // } // } // } /** * 展开树 * @param tree 树 * @param isExpand 是否展开 */ public void expandTree(JTree tree, boolean isExpand) { TreeNode root = (TreeNode) tree.getModel().getRoot(); expandAll(tree, new TreePath(root), isExpand); } private void expandAll(JTree tree, TreePath parent, boolean expand) { TreeNode node = (TreeNode) parent.getLastPathComponent(); if (node.getChildCount() >= 0) { for (Enumeration e = node.children(); e.hasMoreElements(); ) { TreeNode n = (TreeNode) e.nextElement(); TreePath path = parent.pathByAddingChild(n); expandAll(tree, path, expand); } } if (expand) { tree.expandPath(parent); } else { tree.collapsePath(parent); } } } \ No newline at end of file +package com.fr.design.roleAuthority; import com.fr.base.BaseUtils; import com.fr.base.FRCoreContext; import com.fr.design.actions.UpdateAction; import com.fr.design.constants.UIConstants; import com.fr.design.data.DesignTableDataManager; import com.fr.design.data.tabledata.Prepare4DataSourceChange; import com.fr.design.gui.ibutton.UIHeadGroup; import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.itoolbar.UIToolbar; import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DockingView; import com.fr.design.menu.ToolBarDef; import com.fr.general.Inter; import com.fr.general.VT4FR; import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.TreeSelectionEvent; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.Enumeration; /** * 设计器左下角面板,用于在权限编辑时存放角色 * Author : daisy * Date: 13-8-30 * Time: 下午2:22 */ public class ReportAndFSManagePane extends DockingView implements Prepare4DataSourceChange { private static final int REPORT_PLATEFORM_MANAGE = 0; private static final int FS_MANAGE = 1; private static final int LEFT_GAP = -125; private static boolean isSupportFS = false; private TreePath treePath = null; private static ReportAndFSManagePane singleton = new ReportAndFSManagePane(); private static RoleTree roleTree; // carl:我先屏了,现在半拉子,等客户要了再好好做 // private AddAction addAction = new AddAction(); // private RemoveAction removeAction = new RemoveAction(); private RefreshAction refreshAction = new RefreshAction(); private UIHeadGroup buttonGroup; private RoleSourceOP op; protected String[] roleNames = new String[2]; public synchronized static ReportAndFSManagePane getInstance() { singleton.op = new RoleSourceOP(); singleton.op.setDataMode(isSupportFS ? FS_MANAGE : REPORT_PLATEFORM_MANAGE); singleton.setDefaultSelectedRole(); return singleton; } public ReportAndFSManagePane() { initRoleTree(); this.setLayout(new BorderLayout(4, 0)); this.setBorder(null); this.add(iniToolBarPane(), BorderLayout.NORTH); refreshAction.setEnabled(true); UIScrollPane scrollPane = new UIScrollPane(roleTree); scrollPane.setBorder(BorderFactory.createEmptyBorder(0, 24, 0, 0)); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); initbuttonGroup(); JPanel jPanel = new JPanel(new BorderLayout(4, 4)); JPanel buttonPane = new JPanel(new GridLayout()); buttonPane.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIConstants.LINE_COLOR)); buttonPane.add(buttonGroup, BorderLayout.CENTER); jPanel.add(buttonPane, BorderLayout.NORTH); jPanel.add(scrollPane, BorderLayout.CENTER); this.add(jPanel, BorderLayout.CENTER); registerDSChangeListener(); } private void initRoleTree() { roleTree = new RoleTree() { public void refreshRoleTree(String selectedRole) { super.refreshRoleTree(selectedRole); changeAlreadyEditedPaneRole(selectedRole); } protected void doWithValueChanged(TreeSelectionEvent e) { super.doWithValueChanged(e); TreeNode root = (TreeNode) roleTree.getModel().getRoot(); TreePath parent = new TreePath(root); setSelectedRole(roleTree.getSelectedRoleName(), parent); } protected void setTabRoleName(String roleName) { roleNames[getMode()] = roleTree.getSelectedRoleName(); } }; roleTree.setEnabled(true); roleTree.setEditable(false); // RoleTreeCellEditor treeCellEditor = new RoleTreeCellEditor(new UITextField()); // treeCellEditor.addCellEditorListener(treeCellEditor); // roleTree.setCellEditor(treeCellEditor); roleTree.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { super.mouseClicked(e); roleTree.setEditable(false); // int row = roleTree.getRowForLocation(e.getX(), e.getY()); // TreePath path = roleTree.getPathForLocation(e.getX(), e.getY()); // if (e.getClickCount() == 2 && buttonGroup.getSelectedIndex() == REPORT_PLATEFORM_MANAGE) { // PrivilegeManagerProvider pm = PrivilegeManager.getProviderInstance(); // AuthenticationProvider ap = pm.getAuthenticationProvider(); // if (!(ap instanceof DaoAuthenticationProvider)) { // roleTree.setEditable(true); // roleTree.startEditingAtPath(path); // treePath = path; // } // } } }); } private void changeAlreadyEditedPaneRole(String selectedRole) { RolesAlreadyEditedPane.getInstance().refreshDockingView(); RoleTree roleTree = RolesAlreadyEditedPane.getInstance().getRoleTree(); TreeNode root = (TreeNode) roleTree.getModel().getRoot(); TreePath parent = new TreePath(root); roleTree.setSelectedRole(selectedRole, parent); } public void setDefaultSelectedRole() { //设置选中的节点 TreeNode root = (TreeNode) roleTree.getModel().getRoot(); TreePath parent = new TreePath(root); ExpandMutableTreeNode node = (ExpandMutableTreeNode) parent.getLastPathComponent(); String selectedRole = null; if (singleton != null) { selectedRole = roleNames[getMode()]; } if (selectedRole == null) { if (node.getChildCount() <= 0 || node.getFirstChild().getChildCount() <= 0) { return; } selectedRole = node.getFirstChild().getChildAt(0).toString(); } roleTree.setSelectedRole(selectedRole, parent); } public RoleTree getRoleTree() { return roleTree; } /** * 检查f) 每增删改一个角色信息(及时保存),先对比下privilege下之前的角色信息有没有发生变化(即在此期间有没有在其他途径中修改过) */ private void checkChanges() { //如若有变化,则弹出下面的对话框 int returnVal = JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("FR-Designer_Role_changed_isRefresh") + "?", Inter.getLocText("FR-Designer_Refresh"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE); if (returnVal == JOptionPane.OK_OPTION) { roleTree.refreshTreeNode(); expandTree(roleTree, true); roleTree.updateUI(); } } private JPanel iniToolBarPane() { ToolBarDef toolbarDef = new ToolBarDef(); toolbarDef.addShortCut(refreshAction); UIToolbar toolBar = ToolBarDef.createJToolBar(); toolbarDef.updateToolBar(toolBar); JPanel toolbarPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); toolbarPane.add(toolBar, BorderLayout.CENTER); return toolbarPane; } private void initbuttonGroup() { Icon[] iconArray = new Icon[]{BaseUtils.readIcon("/com/fr/web/images/platform/demo.png")}; String[] textArray = new String[]{Inter.getLocText("FR-Designer_FS_Name")}; buttonGroup = new UIHeadGroup(iconArray, textArray) { public void tabChanged(int index) { roleTree.setEditable(false); if (op != null) { op.setDataMode(getMode()); //判断是否可编辑 refreshDockingView(); } setDefaultSelectedRole(); if (singleton != null) { changeAlreadyEditedPaneRole(roleNames[getMode()]); } } }; buttonGroup.setBorder(BorderFactory.createMatteBorder(1, LEFT_GAP, 0, 0, UIConstants.LINE_COLOR)); buttonGroup.setNeedLeftRightOutLine(false); } private int getMode(){ return isSupportFS?FS_MANAGE: REPORT_PLATEFORM_MANAGE; } // /** // * 检查看看是否可以增删刷新按钮是都可以编辑,并且检查角色树是不是可以编辑 // */ // public void checkToolButtonsEnabled() { // if (buttonGroup.getSelectedIndex() == REPORT_PLATEFORM_MANAGE) { // PrivilegeManagerProvider pm = PrivilegeManager.getProviderInstance(); // AuthenticationProvider ap = pm.getAuthenticationProvider(); // PrivilegeFilter pf = pm.getPrivilegeFilter(); // boolean isClickable = !(ap instanceof DaoAuthenticationProvider) // && pf instanceof AuthorityControlFilter; // addAction.setEnabled(isClickable); // removeAction.setEnabled(isClickable); // } else { // addAction.setEnabled(false); // removeAction.setEnabled(false); // } // // } /** * 刷新界面 */ public void refreshDockingView() { populate(new RoleSourceOP()); // this.checkToolButtonsEnabled(); } private void populate(RoleSourceOP op) { this.op = op; roleTree.populate(op); expandTree(roleTree, true); } public String getViewTitle() { return null; } public Icon getViewIcon() { return null; } /** * 最佳定位 * @return 定位 */ public Location preferredLocation() { return null; } /** * 注册数据库改变的响应的Listener */ public void registerDSChangeListener() { DesignTableDataManager.addDsChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { roleTree.refreshTreeNode(); expandTree(roleTree, true); roleTree.updateUI(); } }); } // private class AddAction extends UpdateAction { // public AddAction() { // this.setName(Inter.getLocText("Add")); // this.setSmallIcon(BaseUtils.readIcon("/com/fr/base/images/cell/control/add.png")); // } // // @Override // public void actionPerformed(ActionEvent e) { // refreshDockingView(); // // DefaultTreeModel treeModel = (DefaultTreeModel) roleTree.getModel(); // ExpandMutableTreeNode root = (ExpandMutableTreeNode) treeModel.getRoot(); // ExpandMutableTreeNode parentNode = (ExpandMutableTreeNode) root.getChildAt(0); // String newName = Inter.getLocText("newNode") + (++newIndex); // parentNode.add(new ExpandMutableTreeNode(newName)); // op.addAction(newName); // roleTree.updateUI(); // // try { // synchronized (AuthorityRoleDAOManager.class) { // AuthorityControlFilter pf = AuthorityRoleDAOManager.getAuthControlFilter(true); // // if (AuthorityRoleDAOManager.getAuthorityAllocation(pf, newName) != null) { // newName = Inter.getLocText("newNode") + (++newIndex); // roleTree.refreshTreeNode(); // expandTree(roleTree, true); // } // // AuthorityRoleDAOManager.addAuthorityRole(pf, new Authority(newName), new Allocation(), false, true); // // AuthorityRoleDAOManager.doEnd(pf); // } // } catch (Exception e1) { // FRContext.getLogger().error(e1.getMessage(), e1); // } // } // } // private class RemoveAction extends UpdateAction { // // public RemoveAction() { // this.setName(Inter.getLocText("Remove")); // this.setSmallIcon(UIConstants.CLEAR_ICON); // } // // @Override // public void actionPerformed(ActionEvent e) { // // // NameObject selectedNO = roleTree.getSelectedNameObject(); // // if (selectedNO == null) { // return; // } // // int returnVal = JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("Utils-Are_you_sure_to_remove_the_selected_item") + ":" + selectedNO.getName() + "?", // Inter.getLocText("Remove"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); // if (returnVal == JOptionPane.OK_OPTION) { // op.removeAction(selectedNO.getName()); // // try { // AuthorityControlFilter pf = AuthorityRoleDAOManager.getAuthControlFilter(true); // // AuthorityRoleDAOManager.removeAuthorityRole(pf, new Authority(selectedNO.getName()), true); // AuthorityRoleDAOManager.doEnd(pf); // } catch (Exception e1) { // FRContext.getLogger().error(e1.getMessage(), e1); // } // // roleTree.refreshTreeNode(); // expandTree(roleTree, true); // roleTree.updateUI(); // roleTree.requestFocus(); // roleTree.setSelectionRow(roleTree.getRowCount() - 1); // } // } // } /* * 刷新ReportletsTree */ private class RefreshAction extends UpdateAction { public RefreshAction() { this.setName(Inter.getLocText("FR-Designer_Refresh")); this.setSmallIcon(UIConstants.REFRESH_ICON); } @Override public void actionPerformed(ActionEvent evt) { roleTree.refreshTreeNode(); expandTree(roleTree, true); roleTree.updateUI(); } } // private class RoleTreeCellEditor extends DefaultCellEditor implements TreeCellEditor, CellEditorListener { // // private NameObject editingNO; // private String oldName; // private String newName; // private UITextField jTextField; // // public RoleTreeCellEditor(final UITextField textField) { // super(textField); // this.jTextField = textField; // this.jTextField.setPreferredSize(new Dimension(DesignerEnvManager.getEnvManager().getLastWestRegionContainerWidth() - 5, this.jTextField.getHeight())); // } // // @Override // public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) { // editingNO = ReportAndFSManagePane.this.roleTree.getSelectedNameObject(); // oldName = editingNO.getName(); // // delegate.setValue(oldName); // // editorComponent.setPreferredSize(new java.awt.Dimension(ReportAndFSManagePane.this.getPreferredSize().width, editorComponent.getPreferredSize().height)); // // return editorComponent; // } // // @Override // // public boolean isCellEditable(EventObject anEvent) { // NameObject no = ReportAndFSManagePane.this.roleTree.getSelectedNameObject(); // return !(no.getName() == Inter.getLocText("Role")); // } // // @Override // public Object getCellEditorValue() { // newName = super.getCellEditorValue().toString(); // editingNO.setName(newName); // return editingNO; // } // // // private boolean checkRoleNameNotEmpty() { // refreshDockingView(); // // String currentText = delegate.getCellEditorValue().toString(); // boolean isContained = false; // AuthorityControlFilter pf = AuthorityRoleDAOManager.getAuthControlFilter(false); // if (pf != null && // !ComparatorUtils.equals(oldName, currentText)) { // try { // Iterator iterator = AuthorityRoleDAOManager.authorityAllocationIterator(pf); // // while (iterator.hasNext()) { // AuthorityAllocation authorityAllocation = (AuthorityAllocation) ((Map.Entry) iterator.next()) // .getValue(); // Authority _authority = authorityAllocation.getAuthority(); // if(ComparatorUtils.equals(_authority.getName(), currentText)){ // isContained = true; // break; // } // } // } catch (Exception e) { // } // } // // if (currentText.isEmpty() || isContained) { // JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("RoleName_Can_Not_Be_Null") + "!"); // roleTree.refreshTreeNode(); // expandTree(roleTree, true); // delegate.setValue(oldName); // return false; // } // return true; // } // // /* // * 下面两个方法是CellEditorListener的 // */ // @Override // public void editingCanceled(ChangeEvent e) { // if (!checkRoleNameNotEmpty()) { // treePath = null; // return; // } // roleTree.stopEditing(); // if (treePath == null) { // return; // } // changeValue(); // roleTree.refreshTreeNode(); // expandTree(roleTree, true); // } // // @Override // public void editingStopped(ChangeEvent e) { // if (!checkRoleNameNotEmpty()) { // treePath = null; // return; // } // changeValue(); // roleTree.refreshTreeNode(); // expandTree(roleTree, true); // roleTree.updateUI(); // } // // private void changeValue() { // newName = delegate.getCellEditorValue().toString(); // if (!newName.isEmpty() && newName != oldName) { // roleTree.setSelectedRoleName(newName); // op.rename(oldName, newName); // // AuthorityControlFilter pf = AuthorityRoleDAOManager.getAuthControlFilter(false); // if (pf != null) { // try { // Iterator iterator = AuthorityRoleDAOManager.authorityAllocationIterator(pf); // // while (iterator.hasNext()) { // AuthorityAllocation authorityAllocation = (AuthorityAllocation) ((Map.Entry) iterator.next()) // .getValue(); // Authority _authority = authorityAllocation.getAuthority(); // if (ComparatorUtils.equals(_authority.getName(), oldName)) { // _authority.setName(newName); // } // } // } catch (Exception e) { // } // } // // try { // AuthorityRoleDAOManager.doEnd(pf); // } catch (Exception e) { // FRContext.getLogger().error(e.getMessage(), e); // } // } // } // } /** * 展开树 * @param tree 树 * @param isExpand 是否展开 */ public void expandTree(JTree tree, boolean isExpand) { TreeNode root = (TreeNode) tree.getModel().getRoot(); expandAll(tree, new TreePath(root), isExpand); } private void expandAll(JTree tree, TreePath parent, boolean expand) { TreeNode node = (TreeNode) parent.getLastPathComponent(); if (node.getChildCount() >= 0) { for (Enumeration e = node.children(); e.hasMoreElements(); ) { TreeNode n = (TreeNode) e.nextElement(); TreePath path = parent.pathByAddingChild(n); expandAll(tree, path, expand); } } if (expand) { tree.expandPath(parent); } else { tree.collapsePath(parent); } } } \ No newline at end of file From a67e88d662297a5f2846a49244f0c075bcf0779e Mon Sep 17 00:00:00 2001 From: juhaoyu <2335173323@qq.com> Date: Wed, 13 Sep 2017 18:48:13 +0800 Subject: [PATCH 4/5] fix --- .../roleAuthority/ReportAndFSManagePane.java | 541 +++++++++++++++++- 1 file changed, 540 insertions(+), 1 deletion(-) diff --git a/designer_base/src/com/fr/design/roleAuthority/ReportAndFSManagePane.java b/designer_base/src/com/fr/design/roleAuthority/ReportAndFSManagePane.java index 98c570786c..2c332c3129 100644 --- a/designer_base/src/com/fr/design/roleAuthority/ReportAndFSManagePane.java +++ b/designer_base/src/com/fr/design/roleAuthority/ReportAndFSManagePane.java @@ -1 +1,540 @@ -package com.fr.design.roleAuthority; import com.fr.base.BaseUtils; import com.fr.base.FRCoreContext; import com.fr.design.actions.UpdateAction; import com.fr.design.constants.UIConstants; import com.fr.design.data.DesignTableDataManager; import com.fr.design.data.tabledata.Prepare4DataSourceChange; import com.fr.design.gui.ibutton.UIHeadGroup; import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.itoolbar.UIToolbar; import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DockingView; import com.fr.design.menu.ToolBarDef; import com.fr.general.Inter; import com.fr.general.VT4FR; import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.TreeSelectionEvent; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.Enumeration; /** * 设计器左下角面板,用于在权限编辑时存放角色 * Author : daisy * Date: 13-8-30 * Time: 下午2:22 */ public class ReportAndFSManagePane extends DockingView implements Prepare4DataSourceChange { private static final int REPORT_PLATEFORM_MANAGE = 0; private static final int FS_MANAGE = 1; private static final int LEFT_GAP = -125; private static boolean isSupportFS = false; private TreePath treePath = null; private static ReportAndFSManagePane singleton = new ReportAndFSManagePane(); private static RoleTree roleTree; // carl:我先屏了,现在半拉子,等客户要了再好好做 // private AddAction addAction = new AddAction(); // private RemoveAction removeAction = new RemoveAction(); private RefreshAction refreshAction = new RefreshAction(); private UIHeadGroup buttonGroup; private RoleSourceOP op; protected String[] roleNames = new String[2]; public synchronized static ReportAndFSManagePane getInstance() { singleton.op = new RoleSourceOP(); singleton.op.setDataMode(isSupportFS ? FS_MANAGE : REPORT_PLATEFORM_MANAGE); singleton.setDefaultSelectedRole(); return singleton; } public ReportAndFSManagePane() { initRoleTree(); this.setLayout(new BorderLayout(4, 0)); this.setBorder(null); this.add(iniToolBarPane(), BorderLayout.NORTH); refreshAction.setEnabled(true); UIScrollPane scrollPane = new UIScrollPane(roleTree); scrollPane.setBorder(BorderFactory.createEmptyBorder(0, 24, 0, 0)); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); initbuttonGroup(); JPanel jPanel = new JPanel(new BorderLayout(4, 4)); JPanel buttonPane = new JPanel(new GridLayout()); buttonPane.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIConstants.LINE_COLOR)); buttonPane.add(buttonGroup, BorderLayout.CENTER); jPanel.add(buttonPane, BorderLayout.NORTH); jPanel.add(scrollPane, BorderLayout.CENTER); this.add(jPanel, BorderLayout.CENTER); registerDSChangeListener(); } private void initRoleTree() { roleTree = new RoleTree() { public void refreshRoleTree(String selectedRole) { super.refreshRoleTree(selectedRole); changeAlreadyEditedPaneRole(selectedRole); } protected void doWithValueChanged(TreeSelectionEvent e) { super.doWithValueChanged(e); TreeNode root = (TreeNode) roleTree.getModel().getRoot(); TreePath parent = new TreePath(root); setSelectedRole(roleTree.getSelectedRoleName(), parent); } protected void setTabRoleName(String roleName) { roleNames[getMode()] = roleTree.getSelectedRoleName(); } }; roleTree.setEnabled(true); roleTree.setEditable(false); // RoleTreeCellEditor treeCellEditor = new RoleTreeCellEditor(new UITextField()); // treeCellEditor.addCellEditorListener(treeCellEditor); // roleTree.setCellEditor(treeCellEditor); roleTree.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { super.mouseClicked(e); roleTree.setEditable(false); // int row = roleTree.getRowForLocation(e.getX(), e.getY()); // TreePath path = roleTree.getPathForLocation(e.getX(), e.getY()); // if (e.getClickCount() == 2 && buttonGroup.getSelectedIndex() == REPORT_PLATEFORM_MANAGE) { // PrivilegeManagerProvider pm = PrivilegeManager.getProviderInstance(); // AuthenticationProvider ap = pm.getAuthenticationProvider(); // if (!(ap instanceof DaoAuthenticationProvider)) { // roleTree.setEditable(true); // roleTree.startEditingAtPath(path); // treePath = path; // } // } } }); } private void changeAlreadyEditedPaneRole(String selectedRole) { RolesAlreadyEditedPane.getInstance().refreshDockingView(); RoleTree roleTree = RolesAlreadyEditedPane.getInstance().getRoleTree(); TreeNode root = (TreeNode) roleTree.getModel().getRoot(); TreePath parent = new TreePath(root); roleTree.setSelectedRole(selectedRole, parent); } public void setDefaultSelectedRole() { //设置选中的节点 TreeNode root = (TreeNode) roleTree.getModel().getRoot(); TreePath parent = new TreePath(root); ExpandMutableTreeNode node = (ExpandMutableTreeNode) parent.getLastPathComponent(); String selectedRole = null; if (singleton != null) { selectedRole = roleNames[getMode()]; } if (selectedRole == null) { if (node.getChildCount() <= 0 || node.getFirstChild().getChildCount() <= 0) { return; } selectedRole = node.getFirstChild().getChildAt(0).toString(); } roleTree.setSelectedRole(selectedRole, parent); } public RoleTree getRoleTree() { return roleTree; } /** * 检查f) 每增删改一个角色信息(及时保存),先对比下privilege下之前的角色信息有没有发生变化(即在此期间有没有在其他途径中修改过) */ private void checkChanges() { //如若有变化,则弹出下面的对话框 int returnVal = JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("FR-Designer_Role_changed_isRefresh") + "?", Inter.getLocText("FR-Designer_Refresh"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE); if (returnVal == JOptionPane.OK_OPTION) { roleTree.refreshTreeNode(); expandTree(roleTree, true); roleTree.updateUI(); } } private JPanel iniToolBarPane() { ToolBarDef toolbarDef = new ToolBarDef(); toolbarDef.addShortCut(refreshAction); UIToolbar toolBar = ToolBarDef.createJToolBar(); toolbarDef.updateToolBar(toolBar); JPanel toolbarPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); toolbarPane.add(toolBar, BorderLayout.CENTER); return toolbarPane; } private void initbuttonGroup() { Icon[] iconArray = new Icon[]{BaseUtils.readIcon("/com/fr/web/images/platform/demo.png")}; String[] textArray = new String[]{Inter.getLocText("FR-Designer_FS_Name")}; buttonGroup = new UIHeadGroup(iconArray, textArray) { public void tabChanged(int index) { roleTree.setEditable(false); if (op != null) { op.setDataMode(getMode()); //判断是否可编辑 refreshDockingView(); } setDefaultSelectedRole(); if (singleton != null) { changeAlreadyEditedPaneRole(roleNames[getMode()]); } } }; buttonGroup.setBorder(BorderFactory.createMatteBorder(1, LEFT_GAP, 0, 0, UIConstants.LINE_COLOR)); buttonGroup.setNeedLeftRightOutLine(false); } private int getMode(){ return isSupportFS?FS_MANAGE: REPORT_PLATEFORM_MANAGE; } // /** // * 检查看看是否可以增删刷新按钮是都可以编辑,并且检查角色树是不是可以编辑 // */ // public void checkToolButtonsEnabled() { // if (buttonGroup.getSelectedIndex() == REPORT_PLATEFORM_MANAGE) { // PrivilegeManagerProvider pm = PrivilegeManager.getProviderInstance(); // AuthenticationProvider ap = pm.getAuthenticationProvider(); // PrivilegeFilter pf = pm.getPrivilegeFilter(); // boolean isClickable = !(ap instanceof DaoAuthenticationProvider) // && pf instanceof AuthorityControlFilter; // addAction.setEnabled(isClickable); // removeAction.setEnabled(isClickable); // } else { // addAction.setEnabled(false); // removeAction.setEnabled(false); // } // // } /** * 刷新界面 */ public void refreshDockingView() { populate(new RoleSourceOP()); // this.checkToolButtonsEnabled(); } private void populate(RoleSourceOP op) { this.op = op; roleTree.populate(op); expandTree(roleTree, true); } public String getViewTitle() { return null; } public Icon getViewIcon() { return null; } /** * 最佳定位 * @return 定位 */ public Location preferredLocation() { return null; } /** * 注册数据库改变的响应的Listener */ public void registerDSChangeListener() { DesignTableDataManager.addDsChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { roleTree.refreshTreeNode(); expandTree(roleTree, true); roleTree.updateUI(); } }); } // private class AddAction extends UpdateAction { // public AddAction() { // this.setName(Inter.getLocText("Add")); // this.setSmallIcon(BaseUtils.readIcon("/com/fr/base/images/cell/control/add.png")); // } // // @Override // public void actionPerformed(ActionEvent e) { // refreshDockingView(); // // DefaultTreeModel treeModel = (DefaultTreeModel) roleTree.getModel(); // ExpandMutableTreeNode root = (ExpandMutableTreeNode) treeModel.getRoot(); // ExpandMutableTreeNode parentNode = (ExpandMutableTreeNode) root.getChildAt(0); // String newName = Inter.getLocText("newNode") + (++newIndex); // parentNode.add(new ExpandMutableTreeNode(newName)); // op.addAction(newName); // roleTree.updateUI(); // // try { // synchronized (AuthorityRoleDAOManager.class) { // AuthorityControlFilter pf = AuthorityRoleDAOManager.getAuthControlFilter(true); // // if (AuthorityRoleDAOManager.getAuthorityAllocation(pf, newName) != null) { // newName = Inter.getLocText("newNode") + (++newIndex); // roleTree.refreshTreeNode(); // expandTree(roleTree, true); // } // // AuthorityRoleDAOManager.addAuthorityRole(pf, new Authority(newName), new Allocation(), false, true); // // AuthorityRoleDAOManager.doEnd(pf); // } // } catch (Exception e1) { // FRContext.getLogger().error(e1.getMessage(), e1); // } // } // } // private class RemoveAction extends UpdateAction { // // public RemoveAction() { // this.setName(Inter.getLocText("Remove")); // this.setSmallIcon(UIConstants.CLEAR_ICON); // } // // @Override // public void actionPerformed(ActionEvent e) { // // // NameObject selectedNO = roleTree.getSelectedNameObject(); // // if (selectedNO == null) { // return; // } // // int returnVal = JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("Utils-Are_you_sure_to_remove_the_selected_item") + ":" + selectedNO.getName() + "?", // Inter.getLocText("Remove"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); // if (returnVal == JOptionPane.OK_OPTION) { // op.removeAction(selectedNO.getName()); // // try { // AuthorityControlFilter pf = AuthorityRoleDAOManager.getAuthControlFilter(true); // // AuthorityRoleDAOManager.removeAuthorityRole(pf, new Authority(selectedNO.getName()), true); // AuthorityRoleDAOManager.doEnd(pf); // } catch (Exception e1) { // FRContext.getLogger().error(e1.getMessage(), e1); // } // // roleTree.refreshTreeNode(); // expandTree(roleTree, true); // roleTree.updateUI(); // roleTree.requestFocus(); // roleTree.setSelectionRow(roleTree.getRowCount() - 1); // } // } // } /* * 刷新ReportletsTree */ private class RefreshAction extends UpdateAction { public RefreshAction() { this.setName(Inter.getLocText("FR-Designer_Refresh")); this.setSmallIcon(UIConstants.REFRESH_ICON); } @Override public void actionPerformed(ActionEvent evt) { roleTree.refreshTreeNode(); expandTree(roleTree, true); roleTree.updateUI(); } } // private class RoleTreeCellEditor extends DefaultCellEditor implements TreeCellEditor, CellEditorListener { // // private NameObject editingNO; // private String oldName; // private String newName; // private UITextField jTextField; // // public RoleTreeCellEditor(final UITextField textField) { // super(textField); // this.jTextField = textField; // this.jTextField.setPreferredSize(new Dimension(DesignerEnvManager.getEnvManager().getLastWestRegionContainerWidth() - 5, this.jTextField.getHeight())); // } // // @Override // public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) { // editingNO = ReportAndFSManagePane.this.roleTree.getSelectedNameObject(); // oldName = editingNO.getName(); // // delegate.setValue(oldName); // // editorComponent.setPreferredSize(new java.awt.Dimension(ReportAndFSManagePane.this.getPreferredSize().width, editorComponent.getPreferredSize().height)); // // return editorComponent; // } // // @Override // // public boolean isCellEditable(EventObject anEvent) { // NameObject no = ReportAndFSManagePane.this.roleTree.getSelectedNameObject(); // return !(no.getName() == Inter.getLocText("Role")); // } // // @Override // public Object getCellEditorValue() { // newName = super.getCellEditorValue().toString(); // editingNO.setName(newName); // return editingNO; // } // // // private boolean checkRoleNameNotEmpty() { // refreshDockingView(); // // String currentText = delegate.getCellEditorValue().toString(); // boolean isContained = false; // AuthorityControlFilter pf = AuthorityRoleDAOManager.getAuthControlFilter(false); // if (pf != null && // !ComparatorUtils.equals(oldName, currentText)) { // try { // Iterator iterator = AuthorityRoleDAOManager.authorityAllocationIterator(pf); // // while (iterator.hasNext()) { // AuthorityAllocation authorityAllocation = (AuthorityAllocation) ((Map.Entry) iterator.next()) // .getValue(); // Authority _authority = authorityAllocation.getAuthority(); // if(ComparatorUtils.equals(_authority.getName(), currentText)){ // isContained = true; // break; // } // } // } catch (Exception e) { // } // } // // if (currentText.isEmpty() || isContained) { // JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("RoleName_Can_Not_Be_Null") + "!"); // roleTree.refreshTreeNode(); // expandTree(roleTree, true); // delegate.setValue(oldName); // return false; // } // return true; // } // // /* // * 下面两个方法是CellEditorListener的 // */ // @Override // public void editingCanceled(ChangeEvent e) { // if (!checkRoleNameNotEmpty()) { // treePath = null; // return; // } // roleTree.stopEditing(); // if (treePath == null) { // return; // } // changeValue(); // roleTree.refreshTreeNode(); // expandTree(roleTree, true); // } // // @Override // public void editingStopped(ChangeEvent e) { // if (!checkRoleNameNotEmpty()) { // treePath = null; // return; // } // changeValue(); // roleTree.refreshTreeNode(); // expandTree(roleTree, true); // roleTree.updateUI(); // } // // private void changeValue() { // newName = delegate.getCellEditorValue().toString(); // if (!newName.isEmpty() && newName != oldName) { // roleTree.setSelectedRoleName(newName); // op.rename(oldName, newName); // // AuthorityControlFilter pf = AuthorityRoleDAOManager.getAuthControlFilter(false); // if (pf != null) { // try { // Iterator iterator = AuthorityRoleDAOManager.authorityAllocationIterator(pf); // // while (iterator.hasNext()) { // AuthorityAllocation authorityAllocation = (AuthorityAllocation) ((Map.Entry) iterator.next()) // .getValue(); // Authority _authority = authorityAllocation.getAuthority(); // if (ComparatorUtils.equals(_authority.getName(), oldName)) { // _authority.setName(newName); // } // } // } catch (Exception e) { // } // } // // try { // AuthorityRoleDAOManager.doEnd(pf); // } catch (Exception e) { // FRContext.getLogger().error(e.getMessage(), e); // } // } // } // } /** * 展开树 * @param tree 树 * @param isExpand 是否展开 */ public void expandTree(JTree tree, boolean isExpand) { TreeNode root = (TreeNode) tree.getModel().getRoot(); expandAll(tree, new TreePath(root), isExpand); } private void expandAll(JTree tree, TreePath parent, boolean expand) { TreeNode node = (TreeNode) parent.getLastPathComponent(); if (node.getChildCount() >= 0) { for (Enumeration e = node.children(); e.hasMoreElements(); ) { TreeNode n = (TreeNode) e.nextElement(); TreePath path = parent.pathByAddingChild(n); expandAll(tree, path, expand); } } if (expand) { tree.expandPath(parent); } else { tree.collapsePath(parent); } } } \ No newline at end of file +package com.fr.design.roleAuthority; + +import com.fr.base.BaseUtils; +import com.fr.base.FRCoreContext; +import com.fr.design.actions.UpdateAction; +import com.fr.design.constants.UIConstants; +import com.fr.design.data.DesignTableDataManager; +import com.fr.design.data.tabledata.Prepare4DataSourceChange; +import com.fr.design.gui.ibutton.UIHeadGroup; +import com.fr.design.gui.icontainer.UIScrollPane; +import com.fr.design.gui.itoolbar.UIToolbar; +import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.DockingView; +import com.fr.design.menu.ToolBarDef; +import com.fr.general.Inter; +import com.fr.general.VT4FR; + +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.tree.TreeNode; +import javax.swing.tree.TreePath; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.Enumeration; + +/** + * 设计器左下角面板,用于在权限编辑时存放角色 + * Author : daisy + * Date: 13-8-30 + * Time: 下午2:22 + */ +public class ReportAndFSManagePane extends DockingView implements Prepare4DataSourceChange { + + private static final int REPORT_PLATEFORM_MANAGE = 0; + private static final int FS_MANAGE = 1; + private static final int LEFT_GAP = -125; + private static boolean isSupportFS = false; + private TreePath treePath = null; + + private static ReportAndFSManagePane singleton = new ReportAndFSManagePane(); + + private static RoleTree roleTree; + // carl:我先屏了,现在半拉子,等客户要了再好好做 +// private AddAction addAction = new AddAction(); +// private RemoveAction removeAction = new RemoveAction(); + private RefreshAction refreshAction = new RefreshAction(); + private UIHeadGroup buttonGroup; + private RoleSourceOP op; + protected String[] roleNames = new String[2]; + + public synchronized static ReportAndFSManagePane getInstance() { + singleton.op = new RoleSourceOP(); + singleton.op.setDataMode(isSupportFS ? FS_MANAGE : REPORT_PLATEFORM_MANAGE); + singleton.setDefaultSelectedRole(); + return singleton; + + } + + public ReportAndFSManagePane() { + initRoleTree(); + this.setLayout(new BorderLayout(4, 0)); + this.setBorder(null); + this.add(iniToolBarPane(), BorderLayout.NORTH); + refreshAction.setEnabled(true); + UIScrollPane scrollPane = new UIScrollPane(roleTree); + scrollPane.setBorder(BorderFactory.createEmptyBorder(0, 24, 0, 0)); + scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); + scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); + initbuttonGroup(); + JPanel jPanel = new JPanel(new BorderLayout(4, 4)); + JPanel buttonPane = new JPanel(new GridLayout()); + buttonPane.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIConstants.LINE_COLOR)); + buttonPane.add(buttonGroup, BorderLayout.CENTER); + jPanel.add(buttonPane, BorderLayout.NORTH); + jPanel.add(scrollPane, BorderLayout.CENTER); + this.add(jPanel, BorderLayout.CENTER); + registerDSChangeListener(); + } + + private void initRoleTree() { + roleTree = new RoleTree() { + public void refreshRoleTree(String selectedRole) { + super.refreshRoleTree(selectedRole); + changeAlreadyEditedPaneRole(selectedRole); + } + + + protected void doWithValueChanged(TreeSelectionEvent e) { + super.doWithValueChanged(e); + TreeNode root = (TreeNode) roleTree.getModel().getRoot(); + TreePath parent = new TreePath(root); + setSelectedRole(roleTree.getSelectedRoleName(), parent); + + } + + protected void setTabRoleName(String roleName) { + roleNames[getMode()] = roleTree.getSelectedRoleName(); + } + }; + roleTree.setEnabled(true); + roleTree.setEditable(false); +// RoleTreeCellEditor treeCellEditor = new RoleTreeCellEditor(new UITextField()); +// treeCellEditor.addCellEditorListener(treeCellEditor); +// roleTree.setCellEditor(treeCellEditor); + roleTree.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + super.mouseClicked(e); + roleTree.setEditable(false); +// int row = roleTree.getRowForLocation(e.getX(), e.getY()); +// TreePath path = roleTree.getPathForLocation(e.getX(), e.getY()); +// if (e.getClickCount() == 2 && buttonGroup.getSelectedIndex() == REPORT_PLATEFORM_MANAGE) { +// PrivilegeManagerProvider pm = PrivilegeManager.getProviderInstance(); +// AuthenticationProvider ap = pm.getAuthenticationProvider(); +// if (!(ap instanceof DaoAuthenticationProvider)) { +// roleTree.setEditable(true); +// roleTree.startEditingAtPath(path); +// treePath = path; +// } +// } + } + }); + } + + private void changeAlreadyEditedPaneRole(String selectedRole) { + RolesAlreadyEditedPane.getInstance().refreshDockingView(); + RoleTree roleTree = RolesAlreadyEditedPane.getInstance().getRoleTree(); + TreeNode root = (TreeNode) roleTree.getModel().getRoot(); + TreePath parent = new TreePath(root); + roleTree.setSelectedRole(selectedRole, parent); + } + + public void setDefaultSelectedRole() { + //设置选中的节点 + TreeNode root = (TreeNode) roleTree.getModel().getRoot(); + TreePath parent = new TreePath(root); + ExpandMutableTreeNode node = (ExpandMutableTreeNode) parent.getLastPathComponent(); + String selectedRole = null; + if (singleton != null) { + selectedRole = roleNames[getMode()]; + } + if (selectedRole == null) { + if (node.getChildCount() <= 0 || node.getFirstChild().getChildCount() <= 0) { + return; + } + selectedRole = node.getFirstChild().getChildAt(0).toString(); + } + roleTree.setSelectedRole(selectedRole, parent); + } + + + public RoleTree getRoleTree() { + return roleTree; + } + + /** + * 检查f) 每增删改一个角色信息(及时保存),先对比下privilege下之前的角色信息有没有发生变化(即在此期间有没有在其他途径中修改过) + */ + private void checkChanges() { + //如若有变化,则弹出下面的对话框 + int returnVal = JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("FR-Designer_Role_changed_isRefresh") + "?", + Inter.getLocText("FR-Designer_Refresh"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE); + if (returnVal == JOptionPane.OK_OPTION) { + roleTree.refreshTreeNode(); + expandTree(roleTree, true); + roleTree.updateUI(); + } + + } + + private JPanel iniToolBarPane() { + ToolBarDef toolbarDef = new ToolBarDef(); + toolbarDef.addShortCut(refreshAction); + UIToolbar toolBar = ToolBarDef.createJToolBar(); + toolbarDef.updateToolBar(toolBar); + JPanel toolbarPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + toolbarPane.add(toolBar, BorderLayout.CENTER); + return toolbarPane; + } + + private void initbuttonGroup() { + Icon[] iconArray = new Icon[]{BaseUtils.readIcon("/com/fr/web/images/platform/demo.png")}; + String[] textArray = new String[]{Inter.getLocText("FR-Designer_FS_Name")}; + buttonGroup = new UIHeadGroup(iconArray, textArray) { + public void tabChanged(int index) { + roleTree.setEditable(false); + if (op != null) { + op.setDataMode(getMode()); + //判断是否可编辑 + refreshDockingView(); + } + setDefaultSelectedRole(); + if (singleton != null) { + changeAlreadyEditedPaneRole(roleNames[getMode()]); + } + } + }; + buttonGroup.setBorder(BorderFactory.createMatteBorder(1, LEFT_GAP, 0, 0, UIConstants.LINE_COLOR)); + buttonGroup.setNeedLeftRightOutLine(false); + } + + + private int getMode(){ + return isSupportFS?FS_MANAGE: REPORT_PLATEFORM_MANAGE; + } + + +// /** +// * 检查看看是否可以增删刷新按钮是都可以编辑,并且检查角色树是不是可以编辑 +// */ +// public void checkToolButtonsEnabled() { +// if (buttonGroup.getSelectedIndex() == REPORT_PLATEFORM_MANAGE) { +// PrivilegeManagerProvider pm = PrivilegeManager.getProviderInstance(); +// AuthenticationProvider ap = pm.getAuthenticationProvider(); +// PrivilegeFilter pf = pm.getPrivilegeFilter(); +// boolean isClickable = !(ap instanceof DaoAuthenticationProvider) +// && pf instanceof AuthorityControlFilter; +// addAction.setEnabled(isClickable); +// removeAction.setEnabled(isClickable); +// } else { +// addAction.setEnabled(false); +// removeAction.setEnabled(false); +// } +// +// } + + + /** + * 刷新界面 + */ + public void refreshDockingView() { + populate(new RoleSourceOP()); +// this.checkToolButtonsEnabled(); + } + + private void populate(RoleSourceOP op) { + this.op = op; + roleTree.populate(op); + expandTree(roleTree, true); + } + + public String getViewTitle() { + return null; + } + + public Icon getViewIcon() { + return null; + } + + /** + * 最佳定位 + * @return 定位 + */ + public Location preferredLocation() { + return null; + } + + /** + * 注册数据库改变的响应的Listener + */ + public void registerDSChangeListener() { + DesignTableDataManager.addDsChangeListener(new ChangeListener() { + + public void stateChanged(ChangeEvent e) { + roleTree.refreshTreeNode(); + expandTree(roleTree, true); + roleTree.updateUI(); + } + }); + + } + +// private class AddAction extends UpdateAction { +// public AddAction() { +// this.setName(Inter.getLocText("Add")); +// this.setSmallIcon(BaseUtils.readIcon("/com/fr/base/images/cell/control/add.png")); +// } +// +// @Override +// public void actionPerformed(ActionEvent e) { +// refreshDockingView(); +// +// DefaultTreeModel treeModel = (DefaultTreeModel) roleTree.getModel(); +// ExpandMutableTreeNode root = (ExpandMutableTreeNode) treeModel.getRoot(); +// ExpandMutableTreeNode parentNode = (ExpandMutableTreeNode) root.getChildAt(0); +// String newName = Inter.getLocText("newNode") + (++newIndex); +// parentNode.add(new ExpandMutableTreeNode(newName)); +// op.addAction(newName); +// roleTree.updateUI(); +// +// try { +// synchronized (AuthorityRoleDAOManager.class) { +// AuthorityControlFilter pf = AuthorityRoleDAOManager.getAuthControlFilter(true); +// +// if (AuthorityRoleDAOManager.getAuthorityAllocation(pf, newName) != null) { +// newName = Inter.getLocText("newNode") + (++newIndex); +// roleTree.refreshTreeNode(); +// expandTree(roleTree, true); +// } +// +// AuthorityRoleDAOManager.addAuthorityRole(pf, new Authority(newName), new Allocation(), false, true); +// +// AuthorityRoleDAOManager.doEnd(pf); +// } +// } catch (Exception e1) { +// FRContext.getLogger().error(e1.getMessage(), e1); +// } +// } +// } + +// private class RemoveAction extends UpdateAction { +// +// public RemoveAction() { +// this.setName(Inter.getLocText("Remove")); +// this.setSmallIcon(UIConstants.CLEAR_ICON); +// } +// +// @Override +// public void actionPerformed(ActionEvent e) { +// +// +// NameObject selectedNO = roleTree.getSelectedNameObject(); +// +// if (selectedNO == null) { +// return; +// } +// +// int returnVal = JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("Utils-Are_you_sure_to_remove_the_selected_item") + ":" + selectedNO.getName() + "?", +// Inter.getLocText("Remove"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); +// if (returnVal == JOptionPane.OK_OPTION) { +// op.removeAction(selectedNO.getName()); +// +// try { +// AuthorityControlFilter pf = AuthorityRoleDAOManager.getAuthControlFilter(true); +// +// AuthorityRoleDAOManager.removeAuthorityRole(pf, new Authority(selectedNO.getName()), true); +// AuthorityRoleDAOManager.doEnd(pf); +// } catch (Exception e1) { +// FRContext.getLogger().error(e1.getMessage(), e1); +// } +// +// roleTree.refreshTreeNode(); +// expandTree(roleTree, true); +// roleTree.updateUI(); +// roleTree.requestFocus(); +// roleTree.setSelectionRow(roleTree.getRowCount() - 1); +// } +// } +// } + + + /* + * 刷新ReportletsTree + */ + private class RefreshAction extends UpdateAction { + + public RefreshAction() { + this.setName(Inter.getLocText("FR-Designer_Refresh")); + this.setSmallIcon(UIConstants.REFRESH_ICON); + } + + @Override + public void actionPerformed(ActionEvent evt) { + roleTree.refreshTreeNode(); + expandTree(roleTree, true); + roleTree.updateUI(); + } + } + + +// private class RoleTreeCellEditor extends DefaultCellEditor implements TreeCellEditor, CellEditorListener { +// +// private NameObject editingNO; +// private String oldName; +// private String newName; +// private UITextField jTextField; +// +// public RoleTreeCellEditor(final UITextField textField) { +// super(textField); +// this.jTextField = textField; +// this.jTextField.setPreferredSize(new Dimension(DesignerEnvManager.getEnvManager().getLastWestRegionContainerWidth() - 5, this.jTextField.getHeight())); +// } +// +// @Override +// public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) { +// editingNO = ReportAndFSManagePane.this.roleTree.getSelectedNameObject(); +// oldName = editingNO.getName(); +// +// delegate.setValue(oldName); +// +// editorComponent.setPreferredSize(new java.awt.Dimension(ReportAndFSManagePane.this.getPreferredSize().width, editorComponent.getPreferredSize().height)); +// +// return editorComponent; +// } +// +// @Override +// +// public boolean isCellEditable(EventObject anEvent) { +// NameObject no = ReportAndFSManagePane.this.roleTree.getSelectedNameObject(); +// return !(no.getName() == Inter.getLocText("Role")); +// } +// +// @Override +// public Object getCellEditorValue() { +// newName = super.getCellEditorValue().toString(); +// editingNO.setName(newName); +// return editingNO; +// } +// +// +// private boolean checkRoleNameNotEmpty() { +// refreshDockingView(); +// +// String currentText = delegate.getCellEditorValue().toString(); +// boolean isContained = false; +// AuthorityControlFilter pf = AuthorityRoleDAOManager.getAuthControlFilter(false); +// if (pf != null && +// !ComparatorUtils.equals(oldName, currentText)) { +// try { +// Iterator iterator = AuthorityRoleDAOManager.authorityAllocationIterator(pf); +// +// while (iterator.hasNext()) { +// AuthorityAllocation authorityAllocation = (AuthorityAllocation) ((Map.Entry) iterator.next()) +// .getValue(); +// Authority _authority = authorityAllocation.getAuthority(); +// if(ComparatorUtils.equals(_authority.getName(), currentText)){ +// isContained = true; +// break; +// } +// } +// } catch (Exception e) { +// } +// } +// +// if (currentText.isEmpty() || isContained) { +// JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("RoleName_Can_Not_Be_Null") + "!"); +// roleTree.refreshTreeNode(); +// expandTree(roleTree, true); +// delegate.setValue(oldName); +// return false; +// } +// return true; +// } +// +// /* +// * 下面两个方法是CellEditorListener的 +// */ +// @Override +// public void editingCanceled(ChangeEvent e) { +// if (!checkRoleNameNotEmpty()) { +// treePath = null; +// return; +// } +// roleTree.stopEditing(); +// if (treePath == null) { +// return; +// } +// changeValue(); +// roleTree.refreshTreeNode(); +// expandTree(roleTree, true); +// } +// +// @Override +// public void editingStopped(ChangeEvent e) { +// if (!checkRoleNameNotEmpty()) { +// treePath = null; +// return; +// } +// changeValue(); +// roleTree.refreshTreeNode(); +// expandTree(roleTree, true); +// roleTree.updateUI(); +// } +// +// private void changeValue() { +// newName = delegate.getCellEditorValue().toString(); +// if (!newName.isEmpty() && newName != oldName) { +// roleTree.setSelectedRoleName(newName); +// op.rename(oldName, newName); +// +// AuthorityControlFilter pf = AuthorityRoleDAOManager.getAuthControlFilter(false); +// if (pf != null) { +// try { +// Iterator iterator = AuthorityRoleDAOManager.authorityAllocationIterator(pf); +// +// while (iterator.hasNext()) { +// AuthorityAllocation authorityAllocation = (AuthorityAllocation) ((Map.Entry) iterator.next()) +// .getValue(); +// Authority _authority = authorityAllocation.getAuthority(); +// if (ComparatorUtils.equals(_authority.getName(), oldName)) { +// _authority.setName(newName); +// } +// } +// } catch (Exception e) { +// } +// } +// +// try { +// AuthorityRoleDAOManager.doEnd(pf); +// } catch (Exception e) { +// FRContext.getLogger().error(e.getMessage(), e); +// } +// } +// } +// } + + + /** + * 展开树 + * @param tree 树 + * @param isExpand 是否展开 + */ + public void expandTree(JTree tree, boolean isExpand) { + TreeNode root = (TreeNode) tree.getModel().getRoot(); + expandAll(tree, new TreePath(root), isExpand); + } + + + private void expandAll(JTree tree, TreePath parent, boolean expand) { + TreeNode node = (TreeNode) parent.getLastPathComponent(); + if (node.getChildCount() >= 0) { + for (Enumeration e = node.children(); e.hasMoreElements(); ) { + TreeNode n = (TreeNode) e.nextElement(); + TreePath path = parent.pathByAddingChild(n); + expandAll(tree, path, expand); + } + } + if (expand) { + tree.expandPath(parent); + } else { + tree.collapsePath(parent); + } + } + +} \ No newline at end of file From cb9cfc27efff79baf05303ac539ae12665bd7331 Mon Sep 17 00:00:00 2001 From: finereport Date: Mon, 18 Sep 2017 22:11:41 +0800 Subject: [PATCH 5/5] =?UTF-8?q?RES-2=20=E5=85=B3=E8=81=94=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E9=9B=86=E9=A2=84=E8=A7=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/data/DesignTableDataManager.java | 62 +++++++++++++++---- .../datapane/preview/PreviewTablePane.java | 5 +- .../wrapper/AbstractTableDataWrapper.java | 2 +- designer_base/src/com/fr/env/RemoteEnv.java | 13 +++- 4 files changed, 67 insertions(+), 15 deletions(-) diff --git a/designer_base/src/com/fr/design/data/DesignTableDataManager.java b/designer_base/src/com/fr/design/data/DesignTableDataManager.java index 5248c9626a..17afec4717 100644 --- a/designer_base/src/com/fr/design/data/DesignTableDataManager.java +++ b/designer_base/src/com/fr/design/data/DesignTableDataManager.java @@ -6,19 +6,24 @@ import com.fr.base.StoreProcedureParameter; import com.fr.base.TableData; import com.fr.data.TableDataSource; import com.fr.data.core.DataCoreXmlUtils; -import com.fr.design.data.datapane.preview.PreviewTablePane; import com.fr.data.impl.EmbeddedTableData; import com.fr.data.impl.storeproc.ProcedureDataModel; import com.fr.data.impl.storeproc.StoreProcedure; import com.fr.data.impl.storeproc.StoreProcedureConstants; -import com.fr.design.data.tabledata.wrapper.*; import com.fr.design.DesignModelAdapter; +import com.fr.design.data.datapane.preview.PreviewTablePane; +import com.fr.design.data.tabledata.wrapper.ServerTableDataWrapper; +import com.fr.design.data.tabledata.wrapper.StoreProcedureDataWrapper; +import com.fr.design.data.tabledata.wrapper.StoreProcedureNameWrapper; +import com.fr.design.data.tabledata.wrapper.TableDataFactory; +import com.fr.design.data.tabledata.wrapper.TableDataWrapper; +import com.fr.design.data.tabledata.wrapper.TemplateTableDataWrapper; +import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.gui.iprogressbar.AutoProgressBar; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.JTemplate; import com.fr.design.parameter.ParameterInputPane; -import com.fr.design.dialog.DialogActionAdapter; import com.fr.file.DatasourceManager; import com.fr.file.DatasourceManagerProvider; import com.fr.general.ComparatorUtils; @@ -34,9 +39,16 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import java.io.ByteArrayOutputStream; import java.text.Collator; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; +import java.util.Timer; +import java.util.TimerTask; /** * 设计器管理操作数据集的类: @@ -55,11 +67,11 @@ public abstract class DesignTableDataManager { * 其实globalDsCache没有绝对的必要,只是为了操作方便。如果没有它,那么每次清空服务器数据集或者存储过程的时候,还要去遍历找一下, * 这个操作可能比较复杂 。 从减少代码复杂度的角度看,还是很有必要的 */ - private static java.util.Map globalDsCache = new ConcurrentHashMap(); - private static java.util.Map dsNameChangedMap = new ConcurrentHashMap(); + private static java.util.Map globalDsCache = new java.util.HashMap(); + private static java.util.Map dsNameChangedMap = new HashMap(); // private static List dsListeners = new ArrayList(); - private static Map> dsListenersMap = new ConcurrentHashMap>();; + private static Map> dsListenersMap = new HashMap>(); public static String NO_PARAMETER = "no_paramater_pane"; @@ -352,7 +364,20 @@ public abstract class DesignTableDataManager { * @throws Exception 异常 */ public static EmbeddedTableData previewTableDataNeedInputParameters(TableData tabledata, int rowCount, boolean needLoadingBar) throws Exception { - return previewTableData(tabledata, rowCount, true, needLoadingBar); + return previewTableData(null, tabledata, rowCount, true, needLoadingBar); + } + + /** + * 预览需要参数的数据集 + * + * @param tabledata 数据集 + * @param rowCount 需要预览的行数 + * @param needLoadingBar 是否需要加载进度条 + * @return 数据集 + * @throws Exception 异常 + */ + public static EmbeddedTableData previewTableDataNeedInputParameters(TableDataSource tableDataSource, TableData tabledata, int rowCount, boolean needLoadingBar) throws Exception { + return previewTableData(tableDataSource, tabledata, rowCount, true, needLoadingBar); } /** @@ -365,7 +390,20 @@ public abstract class DesignTableDataManager { * @throws Exception 异常 */ public static EmbeddedTableData previewTableDataNotNeedInputParameters(TableData tabledata, int rowCount, boolean needLoadingBar) throws Exception { - return previewTableData(tabledata, rowCount, false, needLoadingBar); + return previewTableData(null, tabledata, rowCount, false, needLoadingBar); + } + + /** + * 预览不需要参数的数据集 + * + * @param tabledata 数据集 + * @param rowCount 需要预览的行数 + * @param needLoadingBar 是否需要加载进度条 + * @return 数据集 + * @throws Exception 异常 + */ + public static EmbeddedTableData previewTableDataNotNeedInputParameters(TableDataSource tableDataSource, TableData tabledata, int rowCount, boolean needLoadingBar) throws Exception { + return previewTableData(tableDataSource, tabledata, rowCount, false, needLoadingBar); } /** @@ -377,7 +415,7 @@ public abstract class DesignTableDataManager { * 而获取数据集的字段名字时,则没必要 * @return */ - private static EmbeddedTableData previewTableData(TableData tabledata, int rowCount, boolean isMustInputParameters, boolean needLoadingBar) throws Exception { + private static EmbeddedTableData previewTableData(TableDataSource tableDataSource, TableData tabledata, int rowCount, boolean isMustInputParameters, boolean needLoadingBar) throws Exception { final AutoProgressBar loadingBar = PreviewTablePane.getInstance().getProgressBar(); Env currentEnv = FRContext.getCurrentEnv(); ParameterProvider[] parameters = currentEnv.getTableDataParameters(tabledata); @@ -407,7 +445,7 @@ public abstract class DesignTableDataManager { parameter.setValue(parameterMap.get(parameter.getName())); } } - return currentEnv.previewTableData(tabledata, parameterMap, rowCount); + return currentEnv.previewTableData(tableDataSource, tabledata, parameterMap, rowCount); } catch (TableDataException e) { throw new TableDataException(e.getMessage(), e); } finally { diff --git a/designer_base/src/com/fr/design/data/datapane/preview/PreviewTablePane.java b/designer_base/src/com/fr/design/data/datapane/preview/PreviewTablePane.java index 28e421b542..71e10728bd 100644 --- a/designer_base/src/com/fr/design/data/datapane/preview/PreviewTablePane.java +++ b/designer_base/src/com/fr/design/data/datapane/preview/PreviewTablePane.java @@ -6,6 +6,7 @@ package com.fr.design.data.datapane.preview; 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.DBTableData; import com.fr.data.impl.EmbeddedTableData; import com.fr.data.impl.storeproc.ProcedureDataModel; @@ -13,6 +14,7 @@ import com.fr.design.DesignerEnvManager; import com.fr.design.data.DesignTableDataManager; import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.BasicPane; +import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.gui.frpane.UITabbedPane; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.iprogressbar.AutoProgressBar; @@ -362,7 +364,8 @@ public class PreviewTablePane extends BasicPane { } } connectionBar.close(); - previewTableData = DesignTableDataManager.previewTableDataNeedInputParameters(tableData, (int) maxPreviewNumberField.getValue(), true); + TableDataSource dataSource = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().getTarget(); + previewTableData = DesignTableDataManager.previewTableDataNeedInputParameters(dataSource, tableData, (int) maxPreviewNumberField.getValue(), true); // parameterInputDialog // update之后的parameters,转成一个parameterMap,用于预览TableData PreviewTableModel previewModel = new PreviewTableModel(previewTableData.createDataModel(null), (int) maxPreviewNumberField.getValue()); diff --git a/designer_base/src/com/fr/design/data/tabledata/wrapper/AbstractTableDataWrapper.java b/designer_base/src/com/fr/design/data/tabledata/wrapper/AbstractTableDataWrapper.java index 90e2adfab7..17d42b0e15 100644 --- a/designer_base/src/com/fr/design/data/tabledata/wrapper/AbstractTableDataWrapper.java +++ b/designer_base/src/com/fr/design/data/tabledata/wrapper/AbstractTableDataWrapper.java @@ -58,7 +58,7 @@ public abstract class AbstractTableDataWrapper implements TableDataWrapper { EmbeddedTableData embeddedTableData = null; try { - embeddedTableData = DesignTableDataManager.previewTableDataNotNeedInputParameters(tabledata, TableData.RESULT_NOT_NEED, false); + embeddedTableData = DesignTableDataManager.previewTableDataNotNeedInputParameters(tds, tabledata, TableData.RESULT_NOT_NEED, false); } catch (Exception e) { if (e.getMessage()!=null) { DesignUtils.errorMessage(e.getMessage()); diff --git a/designer_base/src/com/fr/env/RemoteEnv.java b/designer_base/src/com/fr/env/RemoteEnv.java index 3c25fc7ff0..61ccb3ebaa 100644 --- a/designer_base/src/com/fr/env/RemoteEnv.java +++ b/designer_base/src/com/fr/env/RemoteEnv.java @@ -10,6 +10,7 @@ import com.fr.base.StoreProcedureParameter; import com.fr.base.TableData; import com.fr.base.Utils; import com.fr.base.remote.RemoteDeziConstants; +import com.fr.data.TableDataSource; import com.fr.data.core.DataCoreUtils; import com.fr.data.core.db.TableProcedure; import com.fr.data.impl.Connection; @@ -1253,6 +1254,11 @@ public class RemoteEnv extends AbstractEnv { return DavXMLUtils.readXMLParameters(input); } + @Override + public EmbeddedTableData previewTableData(Object tableData, Map parameterMap, int rowCount) throws Exception { + return previewTableData(null, tableData, parameterMap, rowCount); + } + /** * 根据指定的参数生成一个实际可预览的数据集 * @@ -1262,7 +1268,7 @@ public class RemoteEnv extends AbstractEnv { * @return 实际的二维数据集 * @throws Exception 如果生成数据失败则抛出此异常 */ - public EmbeddedTableData previewTableData(Object tableData, java.util.Map parameterMap, int rowCount) throws Exception { + public EmbeddedTableData previewTableData(TableDataSource dataSource, Object tableData, java.util.Map parameterMap, int rowCount) throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); // 把tableData写成xml文件到out @@ -1301,6 +1307,11 @@ public class RemoteEnv extends AbstractEnv { return previewTableData(tableData, parameterMap, -1); } + @Override + public Object previewTableData(TableDataSource dataSource, Object tableData, Map parameterMap, int start, int end, String[] cols, int[] colIdx) throws Exception { + return previewTableData(dataSource, tableData, parameterMap, -1); + } + /** * nameValuePairs,这个参数要接着this.path,拼成一个URL,否则服务器端req.getParameter是无法得到的 *