diff --git a/designer-base/src/com/fr/design/gui/itree/filetree/TemplateFileTree.java b/designer-base/src/com/fr/design/gui/itree/filetree/TemplateFileTree.java index a90f25e893..fec5d1e2fe 100644 --- a/designer-base/src/com/fr/design/gui/itree/filetree/TemplateFileTree.java +++ b/designer-base/src/com/fr/design/gui/itree/filetree/TemplateFileTree.java @@ -1,20 +1,29 @@ package com.fr.design.gui.itree.filetree; +import com.fr.base.Env; +import com.fr.base.FRContext; +import com.fr.base.env.EnvContext; +import com.fr.base.env.proxy.EnvProxy; +import com.fr.base.env.resource.EnvConfigUtils; import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; +import com.fr.env.operator.file.TplFileOperator; import com.fr.file.filetree.FileNode; import com.fr.stable.ArrayUtils; +import com.fr.stable.StableUtils; import com.fr.stable.project.ProjectConstants; import javax.swing.text.Position; +import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /* * 显示Env下的reportlets目录下面的所有cpt文件 */ public class TemplateFileTree extends EnvFileTree { - + public TemplateFileTree() { super(ProjectConstants.REPORTLETS_NAME, null, null); @@ -42,33 +51,32 @@ public class TemplateFileTree extends EnvFileTree { return null; } - - public String[] getSelectedTemplatePaths(){ - TreePath[] selectedTreePaths = this.getSelectionPaths(); - if (ArrayUtils.isEmpty(selectedTreePaths)) { - return ArrayUtils.EMPTY_STRING_ARRAY; - } - List selectedPathList = new ArrayList(); - for(TreePath treepath : selectedTreePaths){ - ExpandMutableTreeNode currentTreeNode = (ExpandMutableTreeNode) treepath.getLastPathComponent(); - Object userObject = currentTreeNode.getUserObject(); - if (userObject instanceof FileNode) { - FileNode fn = (FileNode) userObject; - if (!fn.isDirectory()) { - String envPath = fn.getEnvPath(); - if (envPath.startsWith(ProjectConstants.REPORTLETS_NAME)) { - selectedPathList.add(envPath.substring(ProjectConstants.REPORTLETS_NAME.length())); - } - } - } - } - - - return selectedPathList.toArray(new String[0]); + + public String[] getSelectedTemplatePaths() { + TreePath[] selectedTreePaths = this.getSelectionPaths(); + if (ArrayUtils.isEmpty(selectedTreePaths)) { + return ArrayUtils.EMPTY_STRING_ARRAY; + } + List selectedPathList = new ArrayList(); + for (TreePath treepath : selectedTreePaths) { + ExpandMutableTreeNode currentTreeNode = (ExpandMutableTreeNode) treepath.getLastPathComponent(); + Object userObject = currentTreeNode.getUserObject(); + if (userObject instanceof FileNode) { + FileNode fn = (FileNode) userObject; + if (!fn.isDirectory()) { + String envPath = fn.getEnvPath(); + if (envPath.startsWith(ProjectConstants.REPORTLETS_NAME)) { + selectedPathList.add(envPath.substring(ProjectConstants.REPORTLETS_NAME.length())); + } + } + } + } + + + return selectedPathList.toArray(new String[0]); } - public TreePath getNextMatch(String prefix, int startingRow, - Position.Bias bias) { + public TreePath getNextMatch(String prefix, int startingRow, Position.Bias bias) { int max = getRowCount(); if (prefix == null) { @@ -78,9 +86,7 @@ public class TemplateFileTree extends EnvFileTree { throw new IllegalArgumentException(); } prefix = prefix.toUpperCase(); - - // start search from the next/previous element froom the - // selected element + // start search from the next/previous element from the selected element int increment = (bias == Position.Bias.Forward) ? 1 : -1; int row = startingRow; do { @@ -96,4 +102,110 @@ public class TemplateFileTree extends EnvFileTree { } while (row != startingRow); return null; } + + public FileNode[] listFile(String path) { + String username = EnvConfigUtils.getUsername(EnvContext.currentEnv()); + String extra = EnvProxy.get(TplFileOperator.class).readExtraResourcePath(path); + return EnvProxy.get(TplFileOperator.class).list(username, extra, path); + } + + /* + * 改变Env后,根据构造函数时设置的RootPaths,重新加载 + */ + public void refreshEnv(Env env) { + + DefaultTreeModel defaultTreeModel = (DefaultTreeModel) this.getModel(); + ExpandMutableTreeNode rootTreeNode = (ExpandMutableTreeNode) defaultTreeModel.getRoot(); + rootTreeNode.removeAllChildren(); + + FileNode[] fns; + + // 如果rootPaths是null的话列出所有文件 + if (subPathes == null) { + fns = listFileNodes(this.treeRootPath); + } else { + // 重新加载新的FileDirectoryNode + fns = new FileNode[subPathes.length]; + for (int i = 0; i < subPathes.length; i++) { + fns[i] = new FileNode(StableUtils.pathJoin(this.treeRootPath, subPathes[i]), true); + } + } + + ExpandMutableTreeNode[] subTreeNodes = fileNodeArray2TreeNodeArray(fns); + + for (ExpandMutableTreeNode node : subTreeNodes) { + rootTreeNode.add(node); + } + + defaultTreeModel.reload(rootTreeNode); + } + + protected ExpandMutableTreeNode[] loadChildTreeNodes(ExpandMutableTreeNode treeNode) { + FileNode[] fn_array = listFileNodes(treeNode); + + return fileNodeArray2TreeNodeArray(fn_array); + } + + /* + * 把FileNode[]转成ExpandMutableTreeNode[] + */ + private ExpandMutableTreeNode[] fileNodeArray2TreeNodeArray(FileNode[] fileNodes) { + ExpandMutableTreeNode[] res = new ExpandMutableTreeNode[fileNodes.length]; + for (int i = 0; i < res.length; i++) { + FileNode fn = fileNodes[i]; + res[i] = new ExpandMutableTreeNode(fn); + if (fn.isDirectory()) { + res[i].add(new ExpandMutableTreeNode()); + } + } + + return res; + } + + + private FileNode[] listFileNodes(String filePath) { + FileNode[] fileNodes = null; + try { + fileNodes = listFile(filePath); + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage(), e); + } + if (fileNodes == null) { + fileNodes = new FileNode[0]; + } + // 用FileNodeFilter过滤一下 + if (filter != null) { + List list = new ArrayList(); + for (FileNode fileNode : fileNodes) { + if (filter.accept(fileNode)) { + list.add(fileNode); + } + } + + fileNodes = list.toArray(new FileNode[list.size()]); + } + + Arrays.sort(fileNodes, new FileNodeComparator()); + + return fileNodes; + } + + /* + * 求当前TreeNode下所有的FileNode. + */ + private FileNode[] listFileNodes(ExpandMutableTreeNode currentTreeNode) { + if (currentTreeNode == null) { + return new FileNode[0]; + } + + Object object = currentTreeNode.getUserObject(); + + if (object instanceof FileNode) { + return this.listFileNodes(((FileNode) object).getEnvPath()); + } + + return new FileNode[0]; + } + + } \ No newline at end of file diff --git a/designer-base/src/com/fr/design/remote/button/IconButton.java b/designer-base/src/com/fr/design/remote/button/IconButton.java new file mode 100644 index 0000000000..78ebddb19b --- /dev/null +++ b/designer-base/src/com/fr/design/remote/button/IconButton.java @@ -0,0 +1,52 @@ +package com.fr.design.remote.button; + +import com.fr.base.BaseUtils; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.stable.StringUtils; + +import javax.swing.*; +import java.awt.*; + +public final class IconButton extends JButton { + public IconButton() { + super(StringUtils.EMPTY); + setContentAreaFilled(false); + setFocusPainted(false); + setIcon(BaseUtils.readIcon("com/fr/design/remote/images/icon_Remove_x.png")); + setBorder(null); + } + + @Override + protected void paintBorder(Graphics g) { + } + + @Override + protected void paintComponent(Graphics g) { + final Graphics2D g2 = (Graphics2D) g.create(); + g2.setPaint( + new GradientPaint( + new Point(0, 0), + new Color(0xF5F5F7), + new Point(0, getPreferredSize().height), + new Color(0xF5F5F7) + ) + ); + g2.fillRect(0, 0, getPreferredSize().width, getPreferredSize().height); + g2.dispose(); + + super.paintComponent(g); + } + + public static void main(String[] args) { + JFrame jf = new JFrame("test"); + jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + JPanel content = (JPanel) jf.getContentPane(); + content.setLayout(null); + IconButton a = new IconButton(); + a.setBounds(0, 0, a.getPreferredSize().width, a.getPreferredSize().height); + content.add(a); + GUICoreUtils.centerWindow(jf); + jf.setSize(400, 400); + jf.setVisible(true); + } +} 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 cb74dc5574..cf160a7959 100644 --- a/designer-base/src/com/fr/design/remote/ui/AuthorityListControlPane.java +++ b/designer-base/src/com/fr/design/remote/ui/AuthorityListControlPane.java @@ -24,17 +24,10 @@ import com.fr.general.Inter; import com.fr.report.DesignAuthority; import com.fr.stable.ArrayUtils; -import javax.swing.BorderFactory; -import javax.swing.DefaultListModel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JSplitPane; -import javax.swing.ListSelectionModel; -import javax.swing.SwingUtilities; +import javax.swing.*; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; -import java.awt.BorderLayout; -import java.awt.CardLayout; +import java.awt.*; import java.awt.event.ActionEvent; import java.util.ArrayList; import java.util.List; @@ -231,6 +224,12 @@ public class AuthorityListControlPane extends BasicPane { public void addAuthority(DesignAuthority authority, int index) { DefaultListModel model = (DefaultListModel) authorityList.getModel(); + for (int i = 0; i < model.size(); i++) { + if (model.get(i).getUserId().equals(authority.getUserId())) { + return; + } + } + model.add(index, authority); authorityList.setSelectedIndex(index); authorityList.ensureIndexIsVisible(index); 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 e1dcfa62c7..427bf6e6c6 100644 --- a/designer-base/src/com/fr/design/remote/ui/UserManagerPane.java +++ b/designer-base/src/com/fr/design/remote/ui/UserManagerPane.java @@ -163,7 +163,7 @@ public class UserManagerPane extends BasicPane { // 搜索 JPanel searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); searchPanel.setBorder(BorderFactory.createEmptyBorder()); - keyField.setPreferredSize(new Dimension(200, 20)); + keyField.setPreferredSize(new Dimension(250, 20)); keyField.requestFocus(); keyField.addKeyListener(keyFieldKeyListener); keyButton.setText(Inter.getLocText("FR-Designer_Remote_Design_Search")); @@ -205,6 +205,8 @@ public class UserManagerPane extends BasicPane { Inter.getLocText("FR-Designer_Remote_Design_Selected_Member_Count", String.valueOf(addedMembers.size())) ); + countLabel.setBorder(BorderFactory.createEmptyBorder(7, 12, 8, 0)); + countLabel.setForeground(new Color(0x8F8F92)); addedListModel = new DefaultListModel<>(); addedList = new AddedMemberList(addedListModel); diff --git a/designer-base/src/com/fr/design/remote/ui/list/AddedMemberList.java b/designer-base/src/com/fr/design/remote/ui/list/AddedMemberList.java index ff5d648ee0..8854f920f1 100644 --- a/designer-base/src/com/fr/design/remote/ui/list/AddedMemberList.java +++ b/designer-base/src/com/fr/design/remote/ui/list/AddedMemberList.java @@ -2,7 +2,8 @@ package com.fr.design.remote.ui.list; import com.fr.env.RemoteDesignMember; -import javax.swing.DefaultListModel; +import javax.swing.*; +import java.awt.*; import java.awt.event.MouseEvent; import java.util.Vector; @@ -27,7 +28,15 @@ public class AddedMemberList extends MemberList { @Override protected boolean shouldDisplaySelected(MouseEvent e) { - return true; + Point point = e.getPoint(); + int rX = point.x; + int rY = point.y; + int index = this.getSelectedIndex(); + int x = 280; + int y = 25 * index; + int width = 20; + int height = 25; + return x <= rX && rX <= x + width && y <= rY && rY <= y + height; } @Override diff --git a/designer-base/src/com/fr/design/remote/ui/list/AddedMemberListCellRender.java b/designer-base/src/com/fr/design/remote/ui/list/AddedMemberListCellRender.java index bbb8f314bb..71ec3bd61c 100644 --- a/designer-base/src/com/fr/design/remote/ui/list/AddedMemberListCellRender.java +++ b/designer-base/src/com/fr/design/remote/ui/list/AddedMemberListCellRender.java @@ -1,36 +1,29 @@ package com.fr.design.remote.ui.list; import com.fr.base.BaseUtils; -import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ilable.UILabel; +import com.fr.design.remote.button.IconButton; import com.fr.env.RemoteDesignMember; -import javax.swing.BorderFactory; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.ListCellRenderer; -import java.awt.Component; -import java.awt.FlowLayout; +import javax.swing.*; +import java.awt.*; public class AddedMemberListCellRender extends JPanel implements ListCellRenderer { private UILabel label; - private UIButton uiButton; - public AddedMemberListCellRender() { this.setBorder(BorderFactory.createEmptyBorder()); this.setLayout(new FlowLayout(FlowLayout.LEFT)); label = new UILabel(); label.setIcon(BaseUtils.readIcon("com/fr/design/remote/images/icon_Member_normal@1x.png")); - - uiButton = new UIButton(); - uiButton.setIcon(BaseUtils.readIcon("com/fr/design/remote/images/icon_Remove_x.png")); + label.setPreferredSize(new Dimension(270, 20)); + this.setPreferredSize(new Dimension(this.getPreferredSize().width, 25)); this.add(label); - this.add(uiButton); + this.add(new IconButton()); } @Override @@ -42,4 +35,5 @@ public class AddedMemberListCellRender extends JPanel implements ListCellRendere private void setLabelText(String name) { label.setText(name); } + } diff --git a/designer-base/src/com/fr/design/remote/ui/list/AddingMemberList.java b/designer-base/src/com/fr/design/remote/ui/list/AddingMemberList.java index 37675bac4f..289d76a607 100644 --- a/designer-base/src/com/fr/design/remote/ui/list/AddingMemberList.java +++ b/designer-base/src/com/fr/design/remote/ui/list/AddingMemberList.java @@ -2,7 +2,8 @@ package com.fr.design.remote.ui.list; import com.fr.env.RemoteDesignMember; -import javax.swing.DefaultListModel; +import javax.swing.*; +import java.awt.*; import java.awt.event.MouseEvent; import java.util.Vector; @@ -38,7 +39,15 @@ public class AddingMemberList extends MemberList { @Override protected boolean shouldDisplaySelected(MouseEvent e) { - return true; + Point point = e.getPoint(); + int rX = point.x; + int rY = point.y; + int index = this.getSelectedIndex(); + int x = 280; + int y = 25 * index; + int width = 25; + int height = 25; + return x <= rX && rX <= x + width && y <= rY && rY <= y + height; } } diff --git a/designer-base/src/com/fr/design/remote/ui/list/AddingMemberListCellRender.java b/designer-base/src/com/fr/design/remote/ui/list/AddingMemberListCellRender.java index 0e4dc221d0..f119432db9 100644 --- a/designer-base/src/com/fr/design/remote/ui/list/AddingMemberListCellRender.java +++ b/designer-base/src/com/fr/design/remote/ui/list/AddingMemberListCellRender.java @@ -5,12 +5,8 @@ import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.ilable.UILabel; import com.fr.env.RemoteDesignMember; -import javax.swing.BorderFactory; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.ListCellRenderer; -import java.awt.Component; -import java.awt.FlowLayout; +import javax.swing.*; +import java.awt.*; public class AddingMemberListCellRender extends JPanel implements ListCellRenderer { @@ -23,6 +19,8 @@ public class AddingMemberListCellRender extends JPanel implements ListCellRender this.setLayout(new FlowLayout(FlowLayout.LEFT)); label = new UILabel(); + label.setPreferredSize(new Dimension(270, 20)); + this.setPreferredSize(new Dimension(this.getPreferredSize().width, 25)); label.setIcon(BaseUtils.readIcon("com/fr/design/remote/images/icon_Member_normal@1x.png")); check = new UICheckBox();