From bab0b9db35974c96f9fa08afa93d5addeeb4d84e Mon Sep 17 00:00:00 2001 From: "yaoh.wu" Date: Tue, 22 May 2018 22:52:10 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-6700=20=E8=BF=9C=E7=A8=8B=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gui/itree/filetree/EnvFileTree.java | 4 +- .../design/remote/RemoteDesignAuthority.java | 14 ----- .../remote/RemoteDesignAuthorityCreator.java | 5 +- .../com/fr/design/remote/RemoteMember.java | 9 +++ .../src/com/fr/design/remote/Utils.java | 8 ++- .../RemoteDesignAuthorityManagerAction.java | 12 +++- .../design/remote/ui/AuthorityEditorPane.java | 55 +++++++++++++++--- .../remote/ui/AuthorityListControlPane.java | 50 ++++++++-------- .../remote/ui/AuthorityManagerPane.java | 12 ++-- .../fr/design/remote/ui/UserManagerPane.java | 22 ++++--- .../design/remote/ui/list/AuthorityList.java | 10 ++-- .../ui/list/AuthorityListCellRenderer.java | 15 +++-- .../remote/ui/tree/FileAuthorityTree.java | 57 +++++++++++++++++++ .../fr/env/DesignAuthorityConfigurable.java | 10 ++++ designer-base/src/com/fr/env/RemoteEnv.java | 57 +++++++++++++++++-- 15 files changed, 254 insertions(+), 86 deletions(-) delete mode 100644 designer-base/src/com/fr/design/remote/RemoteDesignAuthority.java create mode 100644 designer-base/src/com/fr/env/DesignAuthorityConfigurable.java diff --git a/designer-base/src/com/fr/design/gui/itree/filetree/EnvFileTree.java b/designer-base/src/com/fr/design/gui/itree/filetree/EnvFileTree.java index eecd623004..460a05f82c 100644 --- a/designer-base/src/com/fr/design/gui/itree/filetree/EnvFileTree.java +++ b/designer-base/src/com/fr/design/gui/itree/filetree/EnvFileTree.java @@ -284,7 +284,7 @@ public class EnvFileTree extends RefreshableJTree { /** * currentTreeNode下面如果是PENDING的节点,加载之... */ - private void loadPendingChildTreeNode(ExpandMutableTreeNode currentTreeNode) { + protected void loadPendingChildTreeNode(ExpandMutableTreeNode currentTreeNode) { if (currentTreeNode.isLeaf()) { return; } @@ -342,7 +342,7 @@ public class EnvFileTree extends RefreshableJTree { /* * 是否是父子关系的文件. */ - private static boolean isParentFile(String parentFilePath, String childFilePath) { + protected static boolean isParentFile(String parentFilePath, String childFilePath) { File parentFile = new File(parentFilePath); File childFile = new File(childFilePath); diff --git a/designer-base/src/com/fr/design/remote/RemoteDesignAuthority.java b/designer-base/src/com/fr/design/remote/RemoteDesignAuthority.java deleted file mode 100644 index ffad37e772..0000000000 --- a/designer-base/src/com/fr/design/remote/RemoteDesignAuthority.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.fr.design.remote; - -public class RemoteDesignAuthority { - - private String name; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -} diff --git a/designer-base/src/com/fr/design/remote/RemoteDesignAuthorityCreator.java b/designer-base/src/com/fr/design/remote/RemoteDesignAuthorityCreator.java index dc77e92331..a4a08fe2f0 100644 --- a/designer-base/src/com/fr/design/remote/RemoteDesignAuthorityCreator.java +++ b/designer-base/src/com/fr/design/remote/RemoteDesignAuthorityCreator.java @@ -1,6 +1,7 @@ package com.fr.design.remote; import com.fr.design.beans.BasicBeanPane; +import com.fr.report.DesignAuthority; import javax.swing.Icon; @@ -39,7 +40,7 @@ public class RemoteDesignAuthorityCreator { return editorClazz; } - public void saveUpdatedBean(RemoteDesignAuthority authority, Object bean) { - + public void saveUpdatedBean(DesignAuthority authority, Object bean) { + authority.setItems(((DesignAuthority) bean).getItems()); } } diff --git a/designer-base/src/com/fr/design/remote/RemoteMember.java b/designer-base/src/com/fr/design/remote/RemoteMember.java index c3da597e3e..4d8b6b97cd 100644 --- a/designer-base/src/com/fr/design/remote/RemoteMember.java +++ b/designer-base/src/com/fr/design/remote/RemoteMember.java @@ -11,10 +11,19 @@ public class RemoteMember { private boolean selected; + public RemoteMember() { + + } + public RemoteMember(String username) { this.username = username; } + public RemoteMember username(String username) { + this.username = username; + return this; + } + public RemoteMember realName(String realName) { this.realName = realName; return this; diff --git a/designer-base/src/com/fr/design/remote/Utils.java b/designer-base/src/com/fr/design/remote/Utils.java index ec0a7ddeed..daed94092b 100644 --- a/designer-base/src/com/fr/design/remote/Utils.java +++ b/designer-base/src/com/fr/design/remote/Utils.java @@ -28,9 +28,11 @@ public class Utils { List res = new ArrayList<>(); for (UserAdditionBean userBean : userBeans) { - res.add(new RemoteMember(userBean.getUsername()) - .realName(userBean.getRealName()) - .userId(userBean.getId()) + res.add( + new RemoteMember() + .username(userBean.getUsername()) + .realName(userBean.getRealName()) + .userId(userBean.getId()) ); } return res; diff --git a/designer-base/src/com/fr/design/remote/action/RemoteDesignAuthorityManagerAction.java b/designer-base/src/com/fr/design/remote/action/RemoteDesignAuthorityManagerAction.java index 2326bcbf59..990569b325 100644 --- a/designer-base/src/com/fr/design/remote/action/RemoteDesignAuthorityManagerAction.java +++ b/designer-base/src/com/fr/design/remote/action/RemoteDesignAuthorityManagerAction.java @@ -1,11 +1,14 @@ package com.fr.design.remote.action; import com.fr.base.BaseUtils; +import com.fr.base.FRContext; import com.fr.design.actions.UpdateAction; import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.mainframe.DesignerContext; import com.fr.design.remote.ui.AuthorityManagerPane; +import com.fr.env.RemoteEnv; +import com.fr.report.DesignAuthority; import java.awt.event.ActionEvent; @@ -34,7 +37,14 @@ public class RemoteDesignAuthorityManagerAction extends UpdateAction { dialog.addDialogActionListener(new DialogActionAdapter() { @Override public void doOk() { - managerPane.update(); + DesignAuthority[] authorities = managerPane.update(); + if (!FRContext.getCurrentEnv().isLocalEnv()) { + try { + ((RemoteEnv) FRContext.getCurrentEnv()).updateAuthorities(authorities); + } catch (Exception exception) { + FRContext.getLogger().error(exception.getMessage()); + } + } } @Override diff --git a/designer-base/src/com/fr/design/remote/ui/AuthorityEditorPane.java b/designer-base/src/com/fr/design/remote/ui/AuthorityEditorPane.java index f74cc504e6..dd4b569e38 100644 --- a/designer-base/src/com/fr/design/remote/ui/AuthorityEditorPane.java +++ b/designer-base/src/com/fr/design/remote/ui/AuthorityEditorPane.java @@ -4,16 +4,22 @@ import com.fr.base.FRContext; import com.fr.design.beans.BasicBeanPane; import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; import com.fr.design.layout.FRGUIPaneFactory; -import com.fr.design.remote.RemoteDesignAuthority; import com.fr.design.remote.ui.tree.FileAuthorityTree; +import com.fr.file.filetree.FileNode; import com.fr.file.filetree.IOFileNodeFilter; +import com.fr.report.DesignAuthority; +import com.fr.stable.CoreConstants; import javax.swing.BorderFactory; +import javax.swing.tree.TreePath; import java.awt.BorderLayout; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; -public class AuthorityEditorPane extends BasicBeanPane { +public class AuthorityEditorPane extends BasicBeanPane { private UILabel label = new UILabel(); @@ -29,6 +35,7 @@ public class AuthorityEditorPane extends BasicBeanPane { tree.setFileNodeFilter(filter); this.add(new UIScrollPane(tree), BorderLayout.CENTER); tree.refreshEnv(FRContext.getCurrentEnv()); + } @Override @@ -37,15 +44,45 @@ public class AuthorityEditorPane extends BasicBeanPane { } @Override - public void populateBean(RemoteDesignAuthority ob) { - label.setText(ob.getName()); - // todo 选中树的结点 + public void populateBean(DesignAuthority ob) { + if (ob == null) { + return; + } + label.setText(ob.getUsername()); + + DesignAuthority.Item[] items = ob.getItems(); + if (items == null) { + return; + } + String[] paths = new String[items.length]; + for (int i = 0; i < items.length; i++) { + paths[i] = items[i].getPath(); + } + tree.selectCheckBoxPaths(paths); } @Override - public RemoteDesignAuthority updateBean() { - // todo 更新权限信息 - System.out.println(Arrays.toString(tree.getCheckBoxTreeSelectionModel().getSelectionPaths())); - return new RemoteDesignAuthority(); + public DesignAuthority updateBean() { + DesignAuthority da = new DesignAuthority(); + TreePath[] treePaths = tree.getCheckBoxTreeSelectionModel().getSelectionPaths(); + + List items = new ArrayList<>(); + for (TreePath treePath : treePaths) { + StringBuilder tempSpot = new StringBuilder(); + boolean type = true; + for (int counter = 1, maxCounter = treePath.getPathCount(); counter < maxCounter; + counter++) { + if (counter > 1) { + tempSpot.append(CoreConstants.SEPARATOR); + } + FileNode fileNode = (FileNode) ((ExpandMutableTreeNode) treePath.getPathComponent(counter)).getUserObject(); + type = type && fileNode.isDirectory(); + tempSpot.append(fileNode.getName()); + } + items.add(new DesignAuthority.Item(tempSpot.toString(), type)); + } + da.setItems(items.toArray(new DesignAuthority.Item[0])); + System.out.println(Arrays.toString(da.getItems())); + return da; } } diff --git a/designer-base/src/com/fr/design/remote/ui/AuthorityListControlPane.java b/designer-base/src/com/fr/design/remote/ui/AuthorityListControlPane.java index b6094e427d..61ff35fded 100644 --- a/designer-base/src/com/fr/design/remote/ui/AuthorityListControlPane.java +++ b/designer-base/src/com/fr/design/remote/ui/AuthorityListControlPane.java @@ -14,7 +14,6 @@ import com.fr.design.icon.IconPathConstants; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.menu.ShortCut; import com.fr.design.menu.ToolBarDef; -import com.fr.design.remote.RemoteDesignAuthority; import com.fr.design.remote.RemoteDesignAuthorityCreator; import com.fr.design.remote.RemoteMember; import com.fr.design.remote.ui.list.AuthorityList; @@ -22,6 +21,7 @@ import com.fr.design.remote.ui.list.AuthorityListCellRenderer; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.ComparatorUtils; import com.fr.general.Inter; +import com.fr.report.DesignAuthority; import com.fr.stable.ArrayUtils; import javax.swing.BorderFactory; @@ -79,7 +79,7 @@ public class AuthorityListControlPane extends BasicPane { new RemoteDesignAuthorityCreator( "远程设计用户", BaseUtils.readIcon("com/fr/design/remote/images/icon_Member_normal@1x.png"), - RemoteDesignAuthority.class, + DesignAuthority.class, AuthorityEditorPane.class) }; editorCtrl = new ListEditorControlPane(); @@ -147,7 +147,7 @@ public class AuthorityListControlPane extends BasicPane { } private AuthorityList createList() { - AuthorityList list = new AuthorityList(new DefaultListModel()); + AuthorityList list = new AuthorityList(new DefaultListModel()); list.setCellRenderer(new AuthorityListCellRenderer()); return list; } @@ -162,24 +162,24 @@ public class AuthorityListControlPane extends BasicPane { } - public RemoteDesignAuthority[] update() { - List res = new ArrayList<>(); + public DesignAuthority[] update() { + List res = new ArrayList<>(); this.editorCtrl.update(); DefaultListModel listModel = (DefaultListModel) this.authorityList.getModel(); for (int i = 0, len = listModel.getSize(); i < len; i++) { - res.add((RemoteDesignAuthority) listModel.getElementAt(i)); + res.add((DesignAuthority) listModel.getElementAt(i)); } - return res.toArray(new RemoteDesignAuthority[0]); + return res.toArray(new DesignAuthority[0]); } - public void populate(RemoteDesignAuthority[] authorities) { - DefaultListModel listModel = (DefaultListModel) this.authorityList.getModel(); + public void populate(DesignAuthority[] authorities) { + DefaultListModel listModel = (DefaultListModel) this.authorityList.getModel(); listModel.removeAllElements(); if (ArrayUtils.isEmpty(authorities)) { return; } - for (RemoteDesignAuthority authority : authorities) { + for (DesignAuthority authority : authorities) { listModel.addElement(authority); } @@ -205,8 +205,8 @@ public class AuthorityListControlPane extends BasicPane { public void setSelectedName(String name) { DefaultListModel listModel = (DefaultListModel) this.authorityList.getModel(); for (int i = 0, len = listModel.getSize(); i < len; i++) { - RemoteDesignAuthority authority = (RemoteDesignAuthority) listModel.getElementAt(i); - if (ComparatorUtils.equals(name, authority.getName())) { + DesignAuthority authority = (DesignAuthority) listModel.getElementAt(i); + if (ComparatorUtils.equals(name, authority.getUsername())) { this.authorityList.setSelectedIndex(i); break; } @@ -218,8 +218,8 @@ public class AuthorityListControlPane extends BasicPane { * 获取选中的名字 */ public String getSelectedName() { - RemoteDesignAuthority authority = this.authorityList.getSelectedValue(); - return authority == null ? null : authority.getName(); + DesignAuthority authority = this.authorityList.getSelectedValue(); + return authority == null ? null : authority.getUsername(); } /** @@ -228,8 +228,8 @@ public class AuthorityListControlPane extends BasicPane { * @param authority authority * @param index 序号 */ - public void addAuthority(RemoteDesignAuthority authority, int index) { - DefaultListModel model = (DefaultListModel) authorityList.getModel(); + public void addAuthority(DesignAuthority authority, int index) { + DefaultListModel model = (DefaultListModel) authorityList.getModel(); model.add(index, authority); authorityList.setSelectedIndex(index); @@ -240,8 +240,8 @@ public class AuthorityListControlPane extends BasicPane { } - protected DefaultListModel getModel() { - return (DefaultListModel) this.authorityList.getModel(); + protected DefaultListModel getModel() { + return (DefaultListModel) this.authorityList.getModel(); } @@ -353,7 +353,7 @@ public class AuthorityListControlPane extends BasicPane { private ShortCut4JControlPane[] createShortcuts() { return new ShortCut4JControlPane[]{ - new AbsoluteEnableShortCut(new AddItemUpdateAction(authorityCreators)), + new AbsoluteEnableShortCut(new AddItemUpdateAction()), new NormalEnableShortCut(new RemoveItemAction()) }; } @@ -397,7 +397,7 @@ public class AuthorityListControlPane extends BasicPane { private JPanel cardPane; private BasicBeanPane[] editorPanes; - private RemoteDesignAuthority authority; + private DesignAuthority authority; ListEditorControlPane() { initUpdatePane(); @@ -460,10 +460,8 @@ public class AuthorityListControlPane extends BasicPane { * 添加按钮 */ private class AddItemUpdateAction extends UpdateAction { - private RemoteDesignAuthorityCreator creator; - AddItemUpdateAction(RemoteDesignAuthorityCreator[] creators) { - this.creator = creators[0]; + AddItemUpdateAction() { this.setName(Inter.getLocText("FR-Action_Add")); this.setMnemonic('A'); this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/buttonicon/add.png")); @@ -480,8 +478,10 @@ public class AuthorityListControlPane extends BasicPane { // 获取添加的用户到权限编辑面板 List members = userManagerPane.update(); for (RemoteMember member : members) { - RemoteDesignAuthority authority = new RemoteDesignAuthority(); - authority.setName(member.getUsername()); + DesignAuthority authority = new DesignAuthority(); + authority.setUsername(member.getUsername()); + authority.setUserId(member.getUserId()); + authority.setRealName(member.getRealName()); AuthorityListControlPane.this.addAuthority(authority, getModel().getSize()); } } diff --git a/designer-base/src/com/fr/design/remote/ui/AuthorityManagerPane.java b/designer-base/src/com/fr/design/remote/ui/AuthorityManagerPane.java index 46943677a7..fa235ca254 100644 --- a/designer-base/src/com/fr/design/remote/ui/AuthorityManagerPane.java +++ b/designer-base/src/com/fr/design/remote/ui/AuthorityManagerPane.java @@ -1,11 +1,12 @@ package com.fr.design.remote.ui; import com.fr.design.dialog.BasicPane; -import com.fr.design.remote.RemoteDesignAuthority; import com.fr.general.Inter; +import com.fr.report.DesignAuthority; import javax.swing.BorderFactory; import java.awt.BorderLayout; +import java.util.Arrays; public class AuthorityManagerPane extends BasicPane { @@ -26,12 +27,13 @@ public class AuthorityManagerPane extends BasicPane { return Inter.getLocText("远程设计权限管理"); } - public void populate(RemoteDesignAuthority[] authorities) { + public void populate(DesignAuthority[] authorities) { list.populate(authorities); } - public RemoteDesignAuthority[] update() { - - return list.update(); + public DesignAuthority[] update() { + DesignAuthority[] authorities = list.update(); + System.out.println(Arrays.toString(authorities)); + return authorities; } } diff --git a/designer-base/src/com/fr/design/remote/ui/UserManagerPane.java b/designer-base/src/com/fr/design/remote/ui/UserManagerPane.java index 41e1cfe07a..19473f7f18 100644 --- a/designer-base/src/com/fr/design/remote/ui/UserManagerPane.java +++ b/designer-base/src/com/fr/design/remote/ui/UserManagerPane.java @@ -10,14 +10,25 @@ import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.remote.RemoteMember; import com.fr.design.remote.Utils; -import com.fr.design.remote.ui.list.*; +import com.fr.design.remote.ui.list.AddedMemberList; +import com.fr.design.remote.ui.list.AddedMemberListCellRender; +import com.fr.design.remote.ui.list.AddingMemberList; +import com.fr.design.remote.ui.list.AddingMemberListCellRender; +import com.fr.design.remote.ui.list.MemberListSelectedChangeListener; import com.fr.general.Inter; import com.fr.stable.StringUtils; import com.fr.third.guava.collect.ImmutableList; -import javax.swing.*; +import javax.swing.BorderFactory; +import javax.swing.DefaultListModel; +import javax.swing.JPanel; +import javax.swing.ListSelectionModel; +import javax.swing.SwingWorker; import javax.swing.border.EmptyBorder; -import java.awt.*; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; @@ -234,11 +245,6 @@ public class UserManagerPane extends BasicPane { protected List doInBackground() { addingMembers.clear(); addingMembers.addAll(Utils.getRemoteMember(keyword)); - try { - Thread.sleep(2000L); - } catch (InterruptedException e) { - e.printStackTrace(); - } return addingMembers; } diff --git a/designer-base/src/com/fr/design/remote/ui/list/AuthorityList.java b/designer-base/src/com/fr/design/remote/ui/list/AuthorityList.java index 6d0502ff13..75c70aa98b 100644 --- a/designer-base/src/com/fr/design/remote/ui/list/AuthorityList.java +++ b/designer-base/src/com/fr/design/remote/ui/list/AuthorityList.java @@ -1,27 +1,27 @@ package com.fr.design.remote.ui.list; -import com.fr.design.remote.RemoteDesignAuthority; +import com.fr.report.DesignAuthority; import javax.swing.JList; import javax.swing.ListModel; import java.util.Vector; -public class AuthorityList extends JList { +public class AuthorityList extends JList { public AuthorityList() { super(); } - public AuthorityList(ListModel dataModel) { + public AuthorityList(ListModel dataModel) { super(dataModel); } - public AuthorityList(final RemoteDesignAuthority[] listData) { + public AuthorityList(final DesignAuthority[] listData) { super(listData); } - public AuthorityList(final Vector listData) { + public AuthorityList(final Vector listData) { super(listData); } diff --git a/designer-base/src/com/fr/design/remote/ui/list/AuthorityListCellRenderer.java b/designer-base/src/com/fr/design/remote/ui/list/AuthorityListCellRenderer.java index 2d3c407f13..100e68ee1f 100644 --- a/designer-base/src/com/fr/design/remote/ui/list/AuthorityListCellRenderer.java +++ b/designer-base/src/com/fr/design/remote/ui/list/AuthorityListCellRenderer.java @@ -1,16 +1,19 @@ package com.fr.design.remote.ui.list; import com.fr.base.BaseUtils; -import com.fr.design.remote.RemoteDesignAuthority; +import com.fr.report.DesignAuthority; import sun.swing.DefaultLookup; -import javax.swing.*; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.ListCellRenderer; import javax.swing.border.Border; import javax.swing.border.EmptyBorder; -import java.awt.*; +import java.awt.Color; +import java.awt.Component; public class AuthorityListCellRenderer extends - JLabel implements ListCellRenderer { + JLabel implements ListCellRenderer { /** * An empty Border. This field might not be used. To change the @@ -35,7 +38,7 @@ public class AuthorityListCellRenderer extends } @Override - public Component getListCellRendererComponent(JList list, RemoteDesignAuthority authority, + public Component getListCellRendererComponent(JList list, DesignAuthority authority, int index, boolean isSelected, boolean cellHasFocus) { setComponentOrientation(list.getComponentOrientation()); @@ -79,7 +82,7 @@ public class AuthorityListCellRenderer extends setBorder(border); this.setIcon(BaseUtils.readIcon("com/fr/design/remote/images/icon_Member_normal@1x.png")); - this.setText(authority.getName()); + this.setText(authority.getUsername()); return this; } diff --git a/designer-base/src/com/fr/design/remote/ui/tree/FileAuthorityTree.java b/designer-base/src/com/fr/design/remote/ui/tree/FileAuthorityTree.java index a1503de54c..2b22703f77 100644 --- a/designer-base/src/com/fr/design/remote/ui/tree/FileAuthorityTree.java +++ b/designer-base/src/com/fr/design/remote/ui/tree/FileAuthorityTree.java @@ -1,8 +1,17 @@ package com.fr.design.remote.ui.tree; import com.fr.design.gui.itree.filetree.TemplateFileTree; +import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; +import com.fr.file.filetree.FileNode; +import com.fr.general.ComparatorUtils; +import com.fr.stable.CoreConstants; +import com.fr.stable.StringUtils; +import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; +import java.io.File; +import java.util.ArrayList; +import java.util.List; public class FileAuthorityTree extends TemplateFileTree { @@ -12,4 +21,52 @@ public class FileAuthorityTree extends TemplateFileTree { } + public void selectCheckBoxPaths(String[] paths) { + if (paths == null || paths.length == 0) { + return; + } + + DefaultTreeModel model = (DefaultTreeModel) this.getModel(); + ExpandMutableTreeNode treeNode = (ExpandMutableTreeNode) model.getRoot(); + List res = new ArrayList<>(); + for (int i = 0, len = treeNode.getChildCount(); i < len; i++) { + ExpandMutableTreeNode childTreeNode = (ExpandMutableTreeNode) treeNode.getChildAt(i); + for (String path : paths) { + TreePath tPath = getSelectingPath(childTreeNode, StringUtils.EMPTY, path, model); + if (tPath != null) { + res.add(tPath); + } + } + } + // 勾选中这些结点 + this.getCheckBoxTreeSelectionModel().setSelectionPaths(res.toArray(new TreePath[0])); + } + + + private TreePath getSelectingPath(ExpandMutableTreeNode currentTreeNode, String prefix, String filePath, DefaultTreeModel model) { + FileNode fileNode = (FileNode) currentTreeNode.getUserObject(); + String nodePath = fileNode.getName(); + String currentTreePath = prefix + nodePath; + TreePath res; + + // 判断是否是希望选中的 + if (ComparatorUtils.equals(new File(currentTreePath), new File(filePath))) { + return new TreePath(model.getPathToRoot(currentTreeNode)); + } + // 如果当前路径是currentFilePath的ParentFile,则expandTreeNode,并继续往下找 + else if (isParentFile(currentTreePath, filePath)) { + loadPendingChildTreeNode(currentTreeNode); + prefix = currentTreePath + CoreConstants.SEPARATOR; + for (int i = 0, len = currentTreeNode.getChildCount(); i < len; i++) { + ExpandMutableTreeNode childTreeNode = (ExpandMutableTreeNode) currentTreeNode.getChildAt(i); + // 继续在子结点里面找 + res = getSelectingPath(childTreeNode, prefix, filePath, model); + if (res != null) { + return res; + } + } + return null; + } + return null; + } } diff --git a/designer-base/src/com/fr/env/DesignAuthorityConfigurable.java b/designer-base/src/com/fr/env/DesignAuthorityConfigurable.java new file mode 100644 index 0000000000..301c36b386 --- /dev/null +++ b/designer-base/src/com/fr/env/DesignAuthorityConfigurable.java @@ -0,0 +1,10 @@ +package com.fr.env; + +import com.fr.report.DesignAuthority; + +public interface DesignAuthorityConfigurable { + + DesignAuthority[] getAuthorities(); + + boolean updateAuthorities(DesignAuthority[] authorities) throws Exception; +} diff --git a/designer-base/src/com/fr/env/RemoteEnv.java b/designer-base/src/com/fr/env/RemoteEnv.java index bb0b592ded..03d565acbb 100644 --- a/designer-base/src/com/fr/env/RemoteEnv.java +++ b/designer-base/src/com/fr/env/RemoteEnv.java @@ -41,6 +41,7 @@ import com.fr.json.JSONException; import com.fr.json.JSONObject; import com.fr.license.function.VT4FR; import com.fr.regist.License; +import com.fr.report.DesignAuthority; import com.fr.share.ShareConstants; import com.fr.stable.ArrayUtils; import com.fr.stable.EncodeConstants; @@ -56,6 +57,7 @@ import com.fr.stable.xml.XMLPrintWriter; import com.fr.stable.xml.XMLTools; import com.fr.stable.xml.XMLableReader; import com.fr.web.ResourceConstants; +import com.fr.web.utils.AuthorityXMLUtils; import javax.swing.JOptionPane; import javax.swing.UIManager; @@ -95,7 +97,7 @@ import java.util.regex.Pattern; /** * @author null */ -public class RemoteEnv extends AbstractEnv { +public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurable { private static final int TIME_OUT = 30 * 1000; private static final int PLAIN_SOCKET_PORT = 80; private static final int SSL_PORT = 443; @@ -228,7 +230,13 @@ public class RemoteEnv extends AbstractEnv { if (!isSignIn) { methodPath = methodPath + "?id=" + createUserID(); } - HttpClient client = new HttpClient(methodPath,para); + HttpClient client = new HttpClient(methodPath, para); + /* + todo post 方法好象过去不了 + 但是get方法也会有一些url参数问题,尤其是图表部分 + 比如: + op=fr_remote_design&cmd=design_get_plugin_service_data&serviceID=plugin.phantomjs&req= + */ client.asGet(); return client; } @@ -236,9 +244,20 @@ public class RemoteEnv extends AbstractEnv { /** * 根据nameValuePairs,也就是参数对,生成PostMethod,不同之处在于,参数拼在path后面,不是method.addParameters */ - private HttpClient createHttpMethod2(HashMap para) throws EnvException { + private HttpClient createHttpMethod2(HashMap para) throws EnvException, UnsupportedEncodingException { String methodPath = path + '?' + "id=" + createUserID(); - return new HttpClient(methodPath, para, true); + StringBuilder pathBuilder = new StringBuilder(); + pathBuilder.append(methodPath); + pathBuilder.append('&'); + for (Object o : para.entrySet()) { + Map.Entry entry = (Map.Entry) o; + pathBuilder.append('&'); + pathBuilder.append(URLEncoder.encode((String) entry.getKey(), "UTF-8")); + pathBuilder.append('='); + pathBuilder.append(URLEncoder.encode((String) entry.getValue(), "UTF-8")); + } + methodPath = pathBuilder.toString(); + return new HttpClient(methodPath); } @@ -826,6 +845,27 @@ public class RemoteEnv extends AbstractEnv { return Boolean.valueOf(IOUtils.inputStream2String(input, EncodeConstants.ENCODING_UTF_8)); } + @Override + public boolean updateAuthorities(DesignAuthority[] authorities) throws Exception { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + + // 序列化到输出流 + AuthorityXMLUtils.writeDesignAuthoritiesXML(authorities, out); + + HashMap para = new HashMap<>(); + para.put("op", "remote_design_authority"); + para.put("cmd", "update_authorities"); + + InputStream input = postBytes2ServerB(out.toByteArray(), para); + + return input != null && Boolean.valueOf(IOUtils.inputStream2String(input, EncodeConstants.ENCODING_UTF_8)); + } + + @Override + public DesignAuthority[] getAuthorities() { + return new DesignAuthority[0]; + } + /** * ben:取schema */ @@ -1366,6 +1406,13 @@ public class RemoteEnv extends AbstractEnv { */ public InputStream postBytes2ServerB(byte[] bytes, HashMap para) throws Exception { HttpClient client = createHttpMethod2(para); + /* + todo post 方法好象过去不了 + 但是get方法也会有一些url参数问题,尤其是图表部分 + 比如: + op=fr_remote_design&cmd=design_get_plugin_service_data&serviceID=plugin.phantomjs&req= + */ +// client.asGet(); client.setContent(bytes); return execute4InputStream(client); } @@ -1900,8 +1947,6 @@ public class RemoteEnv extends AbstractEnv { } - //TODO: - /** * 预览存储过程 *