Browse Source

Merge branch 'feature/10.0' of http://cloud.finedevelop.com:2015/scm/~plough/10-design into feature/10.0

master
plough 7 years ago
parent
commit
7a589be3aa
  1. 21
      designer-base/src/com/fr/design/formula/FunctionNAD.java
  2. 26
      designer-base/src/com/fr/design/gui/itree/checkboxtree/CheckBoxTreeCellRenderer.java
  3. 23
      designer-base/src/com/fr/design/gui/itree/filetree/EnvFileTree.java
  4. 31
      designer-base/src/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java
  5. 49
      designer-base/src/com/fr/design/remote/RemoteDesignAuthorityCreator.java
  6. 72
      designer-base/src/com/fr/design/remote/RemoteMember.java
  7. 47
      designer-base/src/com/fr/design/remote/Utils.java
  8. 67
      designer-base/src/com/fr/design/remote/action/RemoteDesignAuthorityManagerAction.java
  9. BIN
      designer-base/src/com/fr/design/remote/images/icon_List_Folder_normal@1x.png
  10. BIN
      designer-base/src/com/fr/design/remote/images/icon_List_Folder_normal@2x.png
  11. BIN
      designer-base/src/com/fr/design/remote/images/icon_Member_normal@1x.png
  12. BIN
      designer-base/src/com/fr/design/remote/images/icon_Member_normal@2x.png
  13. BIN
      designer-base/src/com/fr/design/remote/images/icon_Member_white@1x.png
  14. BIN
      designer-base/src/com/fr/design/remote/images/icon_Member_white@2x.png
  15. BIN
      designer-base/src/com/fr/design/remote/images/icon_NewFolderIcon_normal.png
  16. BIN
      designer-base/src/com/fr/design/remote/images/icon_NewFolderIcon_normal@2x.png
  17. BIN
      designer-base/src/com/fr/design/remote/images/icon_Remote_Design_Permission_Manager_normal@1x.png
  18. BIN
      designer-base/src/com/fr/design/remote/images/icon_Remote_Design_Permission_Manager_normal@2x.png
  19. BIN
      designer-base/src/com/fr/design/remote/images/icon_Remove_x.png
  20. 88
      designer-base/src/com/fr/design/remote/ui/AuthorityEditorPane.java
  21. 522
      designer-base/src/com/fr/design/remote/ui/AuthorityListControlPane.java
  22. 37
      designer-base/src/com/fr/design/remote/ui/AuthorityManagerPane.java
  23. 298
      designer-base/src/com/fr/design/remote/ui/UserManagerPane.java
  24. 44
      designer-base/src/com/fr/design/remote/ui/list/AddedMemberList.java
  25. 45
      designer-base/src/com/fr/design/remote/ui/list/AddedMemberListCellRender.java
  26. 45
      designer-base/src/com/fr/design/remote/ui/list/AddingMemberList.java
  27. 47
      designer-base/src/com/fr/design/remote/ui/list/AddingMemberListCellRender.java
  28. 28
      designer-base/src/com/fr/design/remote/ui/list/AuthorityList.java
  29. 129
      designer-base/src/com/fr/design/remote/ui/list/AuthorityListCellRenderer.java
  30. 84
      designer-base/src/com/fr/design/remote/ui/list/MemberList.java
  31. 7
      designer-base/src/com/fr/design/remote/ui/list/MemberListSelectedChangeListener.java
  32. 72
      designer-base/src/com/fr/design/remote/ui/tree/FileAuthorityTree.java
  33. 148
      designer-base/src/com/fr/design/remote/ui/tree/FileAuthorityTreeNode.java
  34. 10
      designer-base/src/com/fr/env/DesignAuthorityConfigurable.java
  35. 91
      designer-base/src/com/fr/env/RemoteEnv.java
  36. 86
      designer-base/src/com/fr/env/RemoteEnvUtils.java

21
designer-base/src/com/fr/design/formula/FunctionNAD.java

@ -1,12 +1,15 @@
package com.fr.design.formula; package com.fr.design.formula;
import java.util.Locale;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.script.CalculatorEmbeddedFunction;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.stable.script.Function; import com.fr.stable.script.Function;
import java.util.Locale;
public class FunctionNAD extends AbstractNameAndDescription { public class FunctionNAD extends AbstractNameAndDescription {
private Function fn; private Function fn;
FunctionNAD(Function fn) { FunctionNAD(Function fn) {
@ -20,13 +23,15 @@ public class FunctionNAD extends AbstractNameAndDescription {
public String getDesc() { public String getDesc() {
if (fn == null) { if (fn == null) {
return StringUtils.EMPTY; return StringUtils.EMPTY;
} else {
if (Locale.CHINA.equals(FRContext.getLocale())) {
return fn.getCN();
} else {
return fn.getEN();
}
} }
Locale locale = FRContext.getLocale();
String describtion = fn.getDescribtion(locale);
if (describtion.startsWith(CalculatorEmbeddedFunction.LOCALE_PREFIX)) {
// 老的自定义函数兼容, 没有重写getDescribtion
return Locale.CHINA.equals(locale) ? fn.getCN() : fn.getEN();
}
return describtion;
} }
@Override @Override

26
designer-base/src/com/fr/design/gui/itree/checkboxtree/CheckBoxTreeCellRenderer.java

@ -6,24 +6,18 @@
package com.fr.design.gui.itree.checkboxtree; package com.fr.design.gui.itree.checkboxtree;
import java.awt.BorderLayout; import com.fr.design.gui.icheckbox.UICheckBox;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.io.Serializable;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import javax.swing.JTree; import com.fr.design.layout.FRGUIPaneFactory;
import javax.swing.*;
import javax.swing.border.Border; import javax.swing.border.Border;
import javax.swing.border.EmptyBorder; import javax.swing.border.EmptyBorder;
import javax.swing.tree.TreeCellRenderer; import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreePath; import javax.swing.tree.TreePath;
import java.awt.*;
import com.fr.design.gui.icheckbox.UICheckBox; import java.awt.event.MouseEvent;
import com.fr.design.layout.FRGUIPaneFactory; import java.io.Serializable;
/** /**
@ -52,7 +46,7 @@ public class CheckBoxTreeCellRenderer extends NullPanel implements TreeCellRende
public CheckBoxTreeCellRenderer() { public CheckBoxTreeCellRenderer() {
this(null); this(null);
} }
public CheckBoxTreeCellRenderer(TreeCellRenderer renderer) { public CheckBoxTreeCellRenderer(TreeCellRenderer renderer) {
if (noFocusBorder == null) { if (noFocusBorder == null) {
noFocusBorder = new EmptyBorder(1, 1, 1, 1); noFocusBorder = new EmptyBorder(1, 1, 1, 1);
@ -84,8 +78,7 @@ public class CheckBoxTreeCellRenderer extends NullPanel implements TreeCellRende
if (selectionModel.isPathSelected(path, selectionModel.isDigIn())) { if (selectionModel.isPathSelected(path, selectionModel.isDigIn())) {
_checkBox.setState(TristateCheckBox.SELECTED); _checkBox.setState(TristateCheckBox.SELECTED);
_checkBox.setSelected(true); _checkBox.setSelected(true);
} } else {
else {
_checkBox.setState(selectionModel.isDigIn() && selectionModel.isPartiallySelected(path) ? null : TristateCheckBox.NOT_SELECTED); _checkBox.setState(selectionModel.isDigIn() && selectionModel.isPartiallySelected(path) ? null : TristateCheckBox.NOT_SELECTED);
_checkBox.setSelected(false); _checkBox.setSelected(false);
} }
@ -102,6 +95,7 @@ public class CheckBoxTreeCellRenderer extends NullPanel implements TreeCellRende
Border border = treeCellRendererComponent.getBorder(); Border border = treeCellRendererComponent.getBorder();
setBorder(border); setBorder(border);
treeCellRendererComponent.setBorder(BorderFactory.createEmptyBorder()); treeCellRendererComponent.setBorder(BorderFactory.createEmptyBorder());
//todo 可能会发生数组越界,需要处理一下
if (getComponentCount() == 2) { if (getComponentCount() == 2) {
remove(1); remove(1);
} }

23
designer-base/src/com/fr/design/gui/itree/filetree/EnvFileTree.java

@ -48,7 +48,14 @@ public class EnvFileTree extends RefreshableJTree {
this.setFileNodeFilter(filter); this.setFileNodeFilter(filter);
this.setSubPathes(subPathes); this.setSubPathes(subPathes);
this.init(); /*一些自己的 init 放在这里,防止直接错误重写了父类的 init 方法导致子类不能使用 CheckBoxTree 的一些特性。*/
this.putClientProperty("JTree.lineStyle", "Angled");
this.setCellRenderer(fileTreeCellRenderer);
this.setRootVisible(false);
this.setShowsRootHandles(true);
this.setEditable(false);
} }
private void setTreeRootPath(String path) { private void setTreeRootPath(String path) {
@ -63,16 +70,6 @@ public class EnvFileTree extends RefreshableJTree {
this.filter = filter; this.filter = filter;
} }
protected void init() {
this.putClientProperty("JTree.lineStyle", "Angled");
this.setCellRenderer(fileTreeCellRenderer);
this.setRootVisible(false);
this.setShowsRootHandles(true);
this.setEditable(false);
}
// CellRenderer // CellRenderer
private DefaultTreeCellRenderer fileTreeCellRenderer = new DefaultTreeCellRenderer() { private DefaultTreeCellRenderer fileTreeCellRenderer = new DefaultTreeCellRenderer() {
@ -284,7 +281,7 @@ public class EnvFileTree extends RefreshableJTree {
/** /**
* currentTreeNode下面如果是PENDING的节点,加载之... * currentTreeNode下面如果是PENDING的节点,加载之...
*/ */
private void loadPendingChildTreeNode(ExpandMutableTreeNode currentTreeNode) { protected void loadPendingChildTreeNode(ExpandMutableTreeNode currentTreeNode) {
if (currentTreeNode.isLeaf()) { if (currentTreeNode.isLeaf()) {
return; return;
} }
@ -342,7 +339,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 parentFile = new File(parentFilePath);
File childFile = new File(childFilePath); File childFile = new File(childFilePath);

31
designer-base/src/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java

@ -46,6 +46,7 @@ import com.fr.design.menu.MenuDef;
import com.fr.design.menu.SeparatorDef; import com.fr.design.menu.SeparatorDef;
import com.fr.design.menu.ShortCut; import com.fr.design.menu.ShortCut;
import com.fr.design.menu.ToolBarDef; import com.fr.design.menu.ToolBarDef;
import com.fr.design.remote.action.RemoteDesignAuthorityManagerAction;
import com.fr.design.utils.ThemeUtils; import com.fr.design.utils.ThemeUtils;
import com.fr.env.RemoteEnv; import com.fr.env.RemoteEnv;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
@ -58,11 +59,20 @@ import com.fr.plugin.observer.PluginEvent;
import com.fr.plugin.observer.PluginEventListener; import com.fr.plugin.observer.PluginEventListener;
import com.fr.plugin.observer.PluginEventType; import com.fr.plugin.observer.PluginEventType;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import com.fr.stable.ProductConstants;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import javax.swing.*; import javax.swing.Icon;
import java.awt.*; import javax.swing.JComponent;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -103,10 +113,12 @@ public abstract class ToolBarMenuDock {
return new JPanel[0]; return new JPanel[0];
} }
@Override
public JComponent[] toolBarButton4Form() { public JComponent[] toolBarButton4Form() {
return new JComponent[0]; return new JComponent[0];
} }
@Override
public JComponent toolBar4Authority() { public JComponent toolBar4Authority() {
return new JPanel(); return new JPanel();
} }
@ -116,6 +128,7 @@ public abstract class ToolBarMenuDock {
return DesignState.WORK_SHEET; return DesignState.WORK_SHEET;
} }
@Override
public int getToolBarHeight() { public int getToolBarHeight() {
return PANLE_HEIGNT; return PANLE_HEIGNT;
} }
@ -125,6 +138,7 @@ public abstract class ToolBarMenuDock {
* *
* @return 子菜单 * @return 子菜单
*/ */
@Override
public ShortCut[] shortcut4ExportMenu() { public ShortCut[] shortcut4ExportMenu() {
return new ShortCut[0]; return new ShortCut[0];
} }
@ -404,6 +418,10 @@ public abstract class ToolBarMenuDock {
new PlatformManagerAction() new PlatformManagerAction()
); );
if (shouldShowRemotePermission()) {
menuDef.addShortCut(new RemoteDesignAuthorityManagerAction());
}
if (!BaseUtils.isAuthorityEditing()) { if (!BaseUtils.isAuthorityEditing()) {
if (shouldShowPlugin()) { if (shouldShowPlugin()) {
menuDef.addShortCut( menuDef.addShortCut(
@ -425,6 +443,10 @@ public abstract class ToolBarMenuDock {
return processor == null ? new GlobalTableDataAction() : processor.createServerTDAction(); return processor == null ? new GlobalTableDataAction() : processor.createServerTDAction();
} }
private boolean shouldShowRemotePermission() {
return FRContext.getCurrentEnv() != null && !FRContext.getCurrentEnv().isLocalEnv() && FRContext.getCurrentEnv().isRoot();
}
protected boolean shouldShowPlugin() { protected boolean shouldShowPlugin() {
return !(FRContext.getCurrentEnv() instanceof RemoteEnv) && FRContext.isChineseEnv(); return !(FRContext.getCurrentEnv() instanceof RemoteEnv) && FRContext.isChineseEnv();
} }
@ -527,6 +549,7 @@ public abstract class ToolBarMenuDock {
protected JPanel polyToolBar(String text) { protected JPanel polyToolBar(String text) {
JPanel panel = new JPanel(new BorderLayout()) { JPanel panel = new JPanel(new BorderLayout()) {
@Override
public Dimension getPreferredSize() { public Dimension getPreferredSize() {
Dimension dim = super.getPreferredSize(); Dimension dim = super.getPreferredSize();
dim.height = PANLE_HEIGNT; dim.height = PANLE_HEIGNT;
@ -711,6 +734,7 @@ public abstract class ToolBarMenuDock {
private abstract class AbstractShortCutMethodAction implements ShortCutMethodAction { private abstract class AbstractShortCutMethodAction implements ShortCutMethodAction {
@Override
public ShortCut methodAction(MenuHandler handler) { public ShortCut methodAction(MenuHandler handler) {
return handler.shortcut(); return handler.shortcut();
} }
@ -731,6 +755,7 @@ public abstract class ToolBarMenuDock {
this.plus = plus; this.plus = plus;
} }
@Override
public ShortCut methodAction(MenuHandler handler) { public ShortCut methodAction(MenuHandler handler) {
return handler.shortcut(plus); return handler.shortcut(plus);
} }

49
designer-base/src/com/fr/design/remote/RemoteDesignAuthorityCreator.java

@ -0,0 +1,49 @@
package com.fr.design.remote;
import com.fr.design.beans.BasicBeanPane;
import com.fr.report.DesignAuthority;
import javax.swing.*;
public class RemoteDesignAuthorityCreator {
private String name;
private Icon icon;
private Class clazz;
private Class<? extends BasicBeanPane> editorClazz;
public RemoteDesignAuthorityCreator(String name, Icon icon, Class clazz, Class<? extends BasicBeanPane> editorClazz) {
this.name = name;
this.icon = icon;
this.clazz = clazz;
this.editorClazz = editorClazz;
}
public boolean accept(Object object) {
return this.clazz != null && this.clazz.isInstance(object);
}
public String getName() {
return name;
}
public Icon getIcon() {
return icon;
}
public Class getClazz() {
return clazz;
}
public Class<? extends BasicBeanPane> getEditorClazz() {
return editorClazz;
}
public void saveUpdatedBean(DesignAuthority authority, Object bean) {
if (authority == null) {
return;
}
authority.setItems(((DesignAuthority) bean).getItems());
}
}

72
designer-base/src/com/fr/design/remote/RemoteMember.java

@ -0,0 +1,72 @@
package com.fr.design.remote;
import com.fr.general.Inter;
public class RemoteMember {
public static final RemoteMember DEFAULT_MEMBER =
new RemoteMember(Inter.getLocText("FR-Designer_Remote_Design_Loading"));
private String username;
private String realName;
private String userId;
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;
}
public RemoteMember userId(String userId) {
this.userId = userId;
return this;
}
public String getRealName() {
return realName;
}
public void setRealName(String realName) {
this.realName = realName;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
}

47
designer-base/src/com/fr/design/remote/Utils.java

@ -0,0 +1,47 @@
package com.fr.design.remote;
import com.fr.base.FRContext;
import com.fr.decision.webservice.bean.user.UserAdditionBean;
import com.fr.decision.webservice.v10.user.UserService;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
public class Utils {
private Utils() {
}
public static Collection<? extends RemoteMember> getRemoteMember(String keyword) {
List<UserAdditionBean> userBeans = new ArrayList<>();
try {
Map<String, Object> result =
UserService.getInstance().getAllUsers(
FRContext.getCurrentEnv().getUser(),
1,
10,
keyword,
"",
true);
userBeans = (List<UserAdditionBean>) result.get("items");
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage());
}
List<RemoteMember> res = new ArrayList<>();
for (UserAdditionBean userBean : userBeans) {
res.add(
new RemoteMember()
.username(userBean.getUsername())
.realName(userBean.getRealName())
.userId(userBean.getId())
);
}
return res;
}
}

67
designer-base/src/com/fr/design/remote/action/RemoteDesignAuthorityManagerAction.java

@ -0,0 +1,67 @@
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.general.Inter;
import com.fr.report.DesignAuthority;
import java.awt.event.ActionEvent;
/**
* @author yaohwu
*/
public class RemoteDesignAuthorityManagerAction extends UpdateAction {
public RemoteDesignAuthorityManagerAction() {
this.setName(Inter.getLocText("FR-Designer_Remote_Design_Authority_Manager"));
this.setSmallIcon(BaseUtils.readIcon("com/fr/design/remote/images/icon_Remote_Design_Permission_Manager_normal@1x.png"));
}
@Override
public void actionPerformed(ActionEvent e) {
final AuthorityManagerPane managerPane = new AuthorityManagerPane();
BasicDialog dialog = managerPane.showWindow(DesignerContext.getDesignerFrame());
if (!FRContext.getCurrentEnv().isLocalEnv()) {
try {
DesignAuthority[] authorities = ((RemoteEnv) FRContext.getCurrentEnv()).getAuthorities();
if (authorities != null && authorities.length != 0) {
managerPane.populate(authorities);
}
} catch (Exception exception) {
FRContext.getLogger().error(exception.getMessage());
}
}
dialog.addDialogActionListener(new DialogActionAdapter() {
@Override
public void doOk() {
DesignAuthority[] authorities = managerPane.update();
if (!FRContext.getCurrentEnv().isLocalEnv()) {
try {
((RemoteEnv) FRContext.getCurrentEnv()).updateAuthorities(authorities);
} catch (Exception exception) {
FRContext.getLogger().error(exception.getMessage());
}
}
}
@Override
public void doCancel() {
super.doCancel();
}
});
dialog.setModal(true);
dialog.setVisible(true);
}
}

BIN
designer-base/src/com/fr/design/remote/images/icon_List_Folder_normal@1x.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 B

BIN
designer-base/src/com/fr/design/remote/images/icon_List_Folder_normal@2x.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 548 B

BIN
designer-base/src/com/fr/design/remote/images/icon_Member_normal@1x.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 525 B

BIN
designer-base/src/com/fr/design/remote/images/icon_Member_normal@2x.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
designer-base/src/com/fr/design/remote/images/icon_Member_white@1x.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 350 B

BIN
designer-base/src/com/fr/design/remote/images/icon_Member_white@2x.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 746 B

BIN
designer-base/src/com/fr/design/remote/images/icon_NewFolderIcon_normal.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 288 B

BIN
designer-base/src/com/fr/design/remote/images/icon_NewFolderIcon_normal@2x.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 531 B

BIN
designer-base/src/com/fr/design/remote/images/icon_Remote_Design_Permission_Manager_normal@1x.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 575 B

BIN
designer-base/src/com/fr/design/remote/images/icon_Remote_Design_Permission_Manager_normal@2x.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
designer-base/src/com/fr/design/remote/images/icon_Remove_x.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

88
designer-base/src/com/fr/design/remote/ui/AuthorityEditorPane.java

@ -0,0 +1,88 @@
package com.fr.design.remote.ui;
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.ui.tree.FileAuthorityTree;
import com.fr.file.filetree.FileNode;
import com.fr.file.filetree.IOFileNodeFilter;
import com.fr.general.Inter;
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<DesignAuthority> {
private UILabel label = new UILabel();
private FileAuthorityTree tree = new FileAuthorityTree();
public AuthorityEditorPane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.setBorder(BorderFactory.createEmptyBorder());
this.add(label, BorderLayout.NORTH);
IOFileNodeFilter filter = new IOFileNodeFilter(new String[]{".cpt", ".class", ".frm", ".form"});
tree.setDigIn(true);
tree.setFileNodeFilter(filter);
this.add(new UIScrollPane(tree), BorderLayout.CENTER);
tree.refreshEnv(FRContext.getCurrentEnv());
}
@Override
protected String title4PopupWindow() {
return Inter.getLocText("FR-Designer_Remote_Design_Configure_Authority");
}
@Override
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 DesignAuthority updateBean() {
DesignAuthority da = new DesignAuthority();
TreePath[] treePaths = tree.getCheckBoxTreeSelectionModel().getSelectionPaths();
List<DesignAuthority.Item> 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]));
return da;
}
}

522
designer-base/src/com/fr/design/remote/ui/AuthorityListControlPane.java

@ -0,0 +1,522 @@
package com.fr.design.remote.ui;
import com.fr.base.BaseUtils;
import com.fr.design.actions.UpdateAction;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.BasicPane;
import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.gui.controlpane.ShortCut4JControlPane;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itoolbar.UIToolbar;
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.RemoteDesignAuthorityCreator;
import com.fr.design.remote.RemoteMember;
import com.fr.design.remote.ui.list.AuthorityList;
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;
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.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;
public class AuthorityListControlPane extends BasicPane {
private static final String LIST_NAME = "AuthorityListControlPaneList";
private static final String UNSELECTED_EDITOR_NAME = "UNSELECTED";
private static final String SELECTED_EDITOR_NAME = "SELECTED";
private AuthorityList authorityList;
private static final int SHORT_WIDTH = 90;
private ListEditorControlPane editorCtrl;
private CardLayout cardLayout;
private JPanel cardPane;
private ShortCut4JControlPane[] shortCuts;
private RemoteDesignAuthorityCreator[] authorityCreators;
private ToolBarDef toolbarDef;
private UIToolbar toolBar;
public AuthorityListControlPane() {
super();
initComponentPane();
}
private void initComponentPane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.authorityCreators = new RemoteDesignAuthorityCreator[]{
new RemoteDesignAuthorityCreator(
Inter.getLocText("FR-Designer_Remote_Design_User"),
BaseUtils.readIcon("com/fr/design/remote/images/icon_Member_normal@1x.png"),
DesignAuthority.class,
AuthorityEditorPane.class)
};
editorCtrl = new ListEditorControlPane();
// 左侧列表面板
JPanel leftPane = new JPanel(new BorderLayout());
initLeftList(leftPane);
initLeftToolbar(leftPane);
// 右侧卡片布局
cardLayout = new CardLayout();
cardPane = new JPanel(cardLayout);
UILabel selectLabel = new UILabel();
cardPane.add(selectLabel, UNSELECTED_EDITOR_NAME);
cardPane.add(editorCtrl, SELECTED_EDITOR_NAME);
// 左右分割布局
JSplitPane mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, leftPane, cardPane);
mainSplitPane.setBorder(BorderFactory.createLineBorder(GUICoreUtils.getTitleLineBorderColor()));
mainSplitPane.setOneTouchExpandable(true);
add(mainSplitPane, BorderLayout.CENTER);
mainSplitPane.setDividerLocation(shortCuts.length * SHORT_WIDTH);
checkButtonEnabled();
}
private void initLeftToolbar(JPanel leftPane) {
shortCuts = createShortcuts();
if (ArrayUtils.isEmpty(shortCuts)) {
return;
}
toolbarDef = new ToolBarDef();
for (ShortCut4JControlPane sj : shortCuts) {
toolbarDef.addShortCut(sj.getShortCut());
}
toolBar = ToolBarDef.createJToolBar();
toolbarDef.updateToolBar(toolBar);
leftPane.add(toolBar, BorderLayout.NORTH);
}
private void initLeftList(JPanel leftPane) {
authorityList = createList();
authorityList.setName(LIST_NAME);
leftPane.add(new UIScrollPane(authorityList), BorderLayout.CENTER);
authorityList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
authorityList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent evt) {
//避免多次update和populate大大降低效率
if (!evt.getValueIsAdjusting()) {
//切换的时候加检验
if (hasInvalid()) {
return;
}
AuthorityListControlPane.this.editorCtrl.update();
AuthorityListControlPane.this.editorCtrl.populate();
AuthorityListControlPane.this.checkButtonEnabled();
}
}
});
}
private AuthorityList createList() {
AuthorityList list = new AuthorityList(new DefaultListModel<DesignAuthority>());
list.setCellRenderer(new AuthorityListCellRenderer());
return list;
}
private void doWhenPopulate() {
}
private void doBeforePopulate() {
}
public DesignAuthority[] update() {
List<DesignAuthority> res = new ArrayList<>();
this.editorCtrl.update();
DefaultListModel listModel = (DefaultListModel) this.authorityList.getModel();
for (int i = 0, len = listModel.getSize(); i < len; i++) {
res.add((DesignAuthority) listModel.getElementAt(i));
}
return res.toArray(new DesignAuthority[0]);
}
public void populate(DesignAuthority[] authorities) {
DefaultListModel<DesignAuthority> listModel = (DefaultListModel<DesignAuthority>) this.authorityList.getModel();
listModel.removeAllElements();
if (ArrayUtils.isEmpty(authorities)) {
return;
}
for (DesignAuthority authority : authorities) {
listModel.addElement(authority);
}
if (listModel.size() > 0) {
this.authorityList.setSelectedIndex(0);
}
this.checkButtonEnabled();
}
public void updateEditorCtrlPane() {
editorCtrl.update();
}
/*
* 刷新当前的选中的UpdatePane
*/
public void populateEditorCtrlPane() {
this.editorCtrl.populate();
}
public void setSelectedName(String name) {
DefaultListModel listModel = (DefaultListModel) this.authorityList.getModel();
for (int i = 0, len = listModel.getSize(); i < len; i++) {
DesignAuthority authority = (DesignAuthority) listModel.getElementAt(i);
if (ComparatorUtils.equals(name, authority.getUsername())) {
this.authorityList.setSelectedIndex(i);
break;
}
}
}
/**
* 获取选中的名字
*/
public String getSelectedName() {
DesignAuthority authority = this.authorityList.getSelectedValue();
return authority == null ? null : authority.getUsername();
}
/**
* 添加 RemoteDesignAuthority
*
* @param authority authority
* @param index 序号
*/
public void addAuthority(DesignAuthority authority, int index) {
DefaultListModel<DesignAuthority> model = (DefaultListModel<DesignAuthority>) authorityList.getModel();
model.add(index, authority);
authorityList.setSelectedIndex(index);
authorityList.ensureIndexIsVisible(index);
authorityList.revalidate();
authorityList.repaint();
}
protected DefaultListModel<DesignAuthority> getModel() {
return (DefaultListModel<DesignAuthority>) this.authorityList.getModel();
}
/**
* 检查按钮可用状态 Check button enabled.
*/
public void checkButtonEnabled() {
if (authorityList.getSelectedIndex() == -1) {
this.cardLayout.show(cardPane, UNSELECTED_EDITOR_NAME);
} else {
this.cardLayout.show(cardPane, SELECTED_EDITOR_NAME);
}
for (ShortCut4JControlPane shortCut : shortCuts) {
shortCut.checkEnable();
}
}
public class AbsoluteEnableShortCut extends ShortCut4JControlPane {
AbsoluteEnableShortCut(ShortCut shortCut) {
this.shortCut = shortCut;
}
/**
* 检查是否可用
*/
@Override
public void checkEnable() {
this.shortCut.setEnabled(true);
}
}
public class NormalEnableShortCut extends ShortCut4JControlPane {
NormalEnableShortCut(ShortCut shortCut) {
this.shortCut = shortCut;
}
/**
* 检查是否可用
*/
@Override
public void checkEnable() {
this.shortCut.setEnabled(authorityList.getModel()
.getSize() > 0
&& AuthorityListControlPane.this.authorityList.getSelectedIndex() != -1);
}
}
private BasicBeanPane createPaneByCreators(RemoteDesignAuthorityCreator creator) {
try {
return creator.getEditorClazz().newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
/**
* 检查是否符合规范
*
* @throws Exception e
*/
@Override
public void checkValid() throws Exception {
this.editorCtrl.checkValid();
}
private int getInValidIndex() {
BasicBeanPane[] p = editorCtrl.editorPanes;
if (p != null) {
for (int i = 0; i < p.length; i++) {
if (p[i] != null) {
try {
p[i].checkValid();
} catch (Exception e) {
return i;
}
}
}
}
return -1;
}
private boolean hasInvalid() {
int idx = AuthorityListControlPane.this.getInValidIndex();
if (authorityList.getSelectedIndex() != idx) {
try {
checkValid();
} catch (Exception exp) {
JOptionPane.showMessageDialog(AuthorityListControlPane.this, exp.getMessage());
authorityList.setSelectedIndex(idx);
return true;
}
}
return false;
}
/**
* 设置选中项
*
* @param index 选中项的序列号
*/
public void setSelectedIndex(int index) {
authorityList.setSelectedIndex(index);
}
private ShortCut4JControlPane[] createShortcuts() {
return new ShortCut4JControlPane[]{
new AbsoluteEnableShortCut(new AddItemUpdateAction()),
new NormalEnableShortCut(new RemoveItemAction())
};
}
private void doBeforeRemove() {
}
private void doAfterRemove() {
}
/**
* 刷新 creators
*
* @param creators 生成器
*/
public void refreshCreator(RemoteDesignAuthorityCreator[] creators) {
this.authorityCreators = creators;
shortCuts = this.createShortcuts();
toolbarDef.clearShortCuts();
for (ShortCut4JControlPane sj : shortCuts) {
toolbarDef.addShortCut(sj.getShortCut());
}
toolbarDef.updateToolBar(toolBar);
toolBar.validate();
toolBar.repaint();
this.repaint();
}
@Override
protected String title4PopupWindow() {
return null;
}
private class ListEditorControlPane extends JPanel {
private CardLayout card;
private JPanel cardPane;
private BasicBeanPane[] editorPanes;
private DesignAuthority authority;
ListEditorControlPane() {
initUpdatePane();
}
private void initUpdatePane() {
card = new CardLayout();
cardPane = FRGUIPaneFactory.createCardLayout_S_Pane();
cardPane.setLayout(card);
this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.add(cardPane);
editorPanes = new BasicBeanPane[authorityCreators.length];
}
public void populate() {
authority = AuthorityListControlPane.this.authorityList.getSelectedValue();
if (authority == null) {
return;
}
for (int i = 0, len = editorPanes.length; i < len; i++) {
if (authorityCreators[i].accept(authority)) {
editorPanes[i] = createPaneByCreators(authorityCreators[i]);
cardPane.add(editorPanes[i], String.valueOf(i));
card.show(cardPane, String.valueOf(i));
doBeforePopulate();
editorPanes[i].populateBean(authority);
doWhenPopulate();
break;
}
}
}
public void update() {
for (int i = 0; i < editorPanes.length; i++) {
BasicBeanPane pane = editorPanes[i];
if (pane != null && pane.isVisible()) {
Object bean = pane.updateBean();
if (i < authorityCreators.length) {
authorityCreators[i].saveUpdatedBean(authority, bean);
}
}
}
}
public void checkValid() throws Exception {
if (editorPanes != null) {
for (BasicBeanPane updatePane : editorPanes) {
if (updatePane != null) {
updatePane.checkValid();
}
}
}
}
}
/**
* 添加按钮
*/
private class AddItemUpdateAction extends UpdateAction {
AddItemUpdateAction() {
this.setName(Inter.getLocText("FR-Action_Add"));
this.setMnemonic('A');
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/buttonicon/add.png"));
}
@Override
public void actionPerformed(ActionEvent e) {
final UserManagerPane userManagerPane = new UserManagerPane();
BasicDialog dialog = userManagerPane.showWindow(SwingUtilities.getWindowAncestor(AuthorityListControlPane.this));
dialog.addDialogActionListener(new DialogActionAdapter() {
@Override
public void doOk() {
// 获取添加的用户到权限编辑面板
List<RemoteMember> members = userManagerPane.update();
for (RemoteMember member : members) {
DesignAuthority authority = new DesignAuthority();
authority.setUsername(member.getUsername());
authority.setUserId(member.getUserId());
authority.setRealName(member.getRealName());
AuthorityListControlPane.this.addAuthority(authority, getModel().getSize());
}
}
@Override
public void doCancel() {
super.doCancel();
}
});
dialog.setModal(true);
dialog.setVisible(true);
}
}
/*
* 删除按钮
*/
private class RemoveItemAction extends UpdateAction {
RemoveItemAction() {
this.setName(Inter.getLocText("FR-Action_Remove"));
this.setMnemonic('R');
this.setSmallIcon(BaseUtils
.readIcon(IconPathConstants.TD_REMOVE_ICON_PATH));
}
@Override
public void actionPerformed(ActionEvent evt) {
doBeforeRemove();
if (GUICoreUtils.removeJListSelectedNodes(SwingUtilities
.getWindowAncestor(AuthorityListControlPane.this), authorityList)) {
checkButtonEnabled();
doAfterRemove();
}
}
}
}

37
designer-base/src/com/fr/design/remote/ui/AuthorityManagerPane.java

@ -0,0 +1,37 @@
package com.fr.design.remote.ui;
import com.fr.design.dialog.BasicPane;
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 {
private AuthorityListControlPane list;
public AuthorityManagerPane() {
this.setLayout(new BorderLayout());
this.setBorder(BorderFactory.createEmptyBorder());
list = new AuthorityListControlPane();
this.add(list, BorderLayout.CENTER);
}
@Override
protected String title4PopupWindow() {
return Inter.getLocText("FR-Designer_Remote_Design_Authority_Manager");
}
public void populate(DesignAuthority[] authorities) {
list.populate(authorities);
}
public DesignAuthority[] update() {
return list.update();
}
}

298
designer-base/src/com/fr/design/remote/ui/UserManagerPane.java

@ -0,0 +1,298 @@
package com.fr.design.remote.ui;
import com.fr.design.border.UITitledBorder;
import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextfield.UITextField;
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.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.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.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;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @author yaohwu
*/
public class UserManagerPane extends BasicPane {
/**
* 获取的决策平台成员
*/
private List<RemoteMember> addingMembers = new ArrayList<>();
/**
* 添加到设计的决策平台成员
*/
private List<RemoteMember> addedMembers = new ArrayList<>();
/**
* 决策平台成员列表model
*/
private DefaultListModel<RemoteMember> addingListModel = new DefaultListModel<>();
/**
* 搜索输入框
*/
private UITextField keyField = new UITextField();
/**
* 搜索按钮
*/
private UIButton keyButton = new UIButton();
/**
* 搜索按钮绑定事件
*/
private ActionListener keyButtonActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
searchAddingMembers(keyField.getText());
}
};
/**
* 输入框绑定事件
*/
private KeyAdapter keyFieldKeyListener = new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
// 判断按下的键是否是回车键
// todo 对话框回车键绑定的是对话框的确定按钮
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
searchAddingMembers(keyField.getText());
}
}
};
/**
* 添加到设计的决策成员计数标签
*/
private UILabel countLabel = new UILabel();
/**
* 添加到设计的决策成员计数标签
*/
private DefaultListModel<RemoteMember> addedListModel;
private MemberListSelectedChangeListener addingListChangeListener = new MemberListSelectedChangeListener() {
@Override
public void selectedChange() {
resetAddedMembers();
sync2AddedMembersFromAdding();
addToAddedMemberList();
}
};
private MemberListSelectedChangeListener addedListChangeListener = new MemberListSelectedChangeListener() {
@Override
public void selectedChange() {
addingList.revalidate();
addingList.repaint();
resetAddedMembers();
sync2AddedMembersFormAdded();
// 不需要重复更新右侧列表显示 但是更新一下计数显示
countLabel.setText(
Inter.getLocText("FR-Designer_Remote_Design_Selected_Member_Count",
String.valueOf(addedMembers.size())
)
);
}
};
private AddedMemberList addedList;
private AddingMemberList addingList;
public UserManagerPane() {
this.setBorder(BorderFactory.createEmptyBorder());
this.setLayout(new BorderLayout());
this.add(
TableLayoutHelper.createTableLayoutPane(
new Component[][]{
new Component[]{createLeftPanel(), createRightPanel()}
},
new double[]{TableLayout.FILL},
new double[]{TableLayout.FILL, TableLayout.FILL}
),
BorderLayout.CENTER);
}
@Override
protected String title4PopupWindow() {
return Inter.getLocText("FR-Designer_Remote_Design_Add_Member");
}
private JPanel createLeftPanel() {
JPanel content = new JPanel(new BorderLayout());
content.setBorder(
BorderFactory.createCompoundBorder(
new EmptyBorder(6, 0, 0, 0),
UITitledBorder.createBorderWithTitle(
Inter.getLocText("FR-Designer_Remote_Design_Decision_Member")
)
)
);
// 搜索
JPanel searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
searchPanel.setBorder(BorderFactory.createEmptyBorder());
keyField.setPreferredSize(new Dimension(200, 20));
keyField.requestFocus();
keyField.addKeyListener(keyFieldKeyListener);
keyButton.setText(Inter.getLocText("FR-Designer_Remote_Design_Search"));
keyButton.addActionListener(keyButtonActionListener);
searchPanel.add(keyField);
searchPanel.add(keyButton);
// 内容列表
addingListModel = new DefaultListModel<>();
addingList = new AddingMemberList(addingListModel);
addingList.setCellRenderer(new AddingMemberListCellRender());
addingList.addSelectedChangeListener(addingListChangeListener);
resetMembers();
addToMemberList();
searchAddingMembers(StringUtils.EMPTY);
UIScrollPane listPane = new UIScrollPane(addingList);
listPane.setBorder(BorderFactory.createEmptyBorder());
content.add(searchPanel, BorderLayout.NORTH);
content.add(listPane, BorderLayout.CENTER);
return content;
}
private JPanel createRightPanel() {
JPanel content = new JPanel(new BorderLayout());
content.setBorder(
BorderFactory.createCompoundBorder(
new EmptyBorder(6, 0, 0, 0),
UITitledBorder.createBorderWithTitle(
Inter.getLocText("FR-Designer_Remote_Design_Selected_Member")
)
)
);
// 计数
countLabel.setText(
Inter.getLocText("FR-Designer_Remote_Design_Selected_Member_Count",
String.valueOf(addedMembers.size()))
);
addedListModel = new DefaultListModel<>();
addedList = new AddedMemberList(addedListModel);
addedList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
addedList.setCellRenderer(new AddedMemberListCellRender());
addedList.addSelectedChangeListener(addedListChangeListener);
resetAddedMembers();
addToAddedMemberList();
UIScrollPane listPane = new UIScrollPane(addedList);
listPane.setBorder(BorderFactory.createEmptyBorder());
content.add(countLabel, BorderLayout.NORTH);
content.add(listPane, BorderLayout.CENTER);
return content;
}
private void addToMemberList() {
addingListModel.clear();
for (RemoteMember member : addingMembers) {
addingListModel.addElement(member);
}
addingList.revalidate();
addingList.repaint();
}
private void addToAddedMemberList() {
addedListModel.clear();
for (RemoteMember member : addedMembers) {
addedListModel.addElement(member);
}
addedList.revalidate();
addedList.repaint();
countLabel.setText(
Inter.getLocText("FR-Designer_Remote_Design_Selected_Member_Count",
String.valueOf(addedMembers.size())
));
}
private void resetMembers() {
addingMembers.clear();
addingMembers.add(RemoteMember.DEFAULT_MEMBER);
}
private void resetAddedMembers() {
addedMembers.clear();
}
private void searchAddingMembers(final String keyword) {
final SwingWorker getMemberWorker = new SwingWorker<List<RemoteMember>, Void>() {
@Override
protected List<RemoteMember> doInBackground() {
addingMembers.clear();
addingMembers.addAll(Utils.getRemoteMember(keyword));
return addingMembers;
}
@Override
protected void done() {
addToMemberList();
}
};
getMemberWorker.execute();
}
private void sync2AddedMembersFromAdding() {
RemoteMember[] members = new RemoteMember[addingListModel.getSize()];
// shallow copy
addingListModel.copyInto(members);
for (RemoteMember member : members) {
if (member.isSelected()) {
addedMembers.add(member);
}
}
}
private void sync2AddedMembersFormAdded() {
RemoteMember[] members = new RemoteMember[addedListModel.getSize()];
// shallow copy
addedListModel.copyInto(members);
addedMembers.addAll(Arrays.asList(members));
}
public ImmutableList<RemoteMember> update() {
return ImmutableList.copyOf(addedMembers);
}
}

44
designer-base/src/com/fr/design/remote/ui/list/AddedMemberList.java

@ -0,0 +1,44 @@
package com.fr.design.remote.ui.list;
import com.fr.design.remote.RemoteMember;
import javax.swing.*;
import java.awt.event.MouseEvent;
import java.util.Vector;
public class AddedMemberList extends MemberList {
public AddedMemberList() {
super();
}
public AddedMemberList(DefaultListModel<RemoteMember> dataModel) {
super(dataModel);
}
public AddedMemberList(RemoteMember[] listData) {
super(listData);
}
public AddedMemberList(Vector<? extends RemoteMember> listData) {
super(listData);
}
@Override
protected boolean shouldDisplaySelected(MouseEvent e) {
return true;
}
@Override
protected void displaySelected() {
RemoteMember member = getSelectedValue();
if (member != null) {
member.setSelected(!member.isSelected());
((DefaultListModel<RemoteMember>) getModel()).removeElement(member);
}
revalidate();
repaint();
fireSelectedChange();
}
}

45
designer-base/src/com/fr/design/remote/ui/list/AddedMemberListCellRender.java

@ -0,0 +1,45 @@
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.RemoteMember;
import javax.swing.BorderFactory;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
import java.awt.Component;
import java.awt.FlowLayout;
public class AddedMemberListCellRender extends JPanel implements ListCellRenderer<RemoteMember> {
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"));
this.add(label);
this.add(uiButton);
}
@Override
public Component getListCellRendererComponent(JList<? extends RemoteMember> list, RemoteMember member, int index, boolean isSelected, boolean cellHasFocus) {
this.setLabelText(member.getUsername());
return this;
}
private void setLabelText(String name) {
label.setText(name);
}
}

45
designer-base/src/com/fr/design/remote/ui/list/AddingMemberList.java

@ -0,0 +1,45 @@
package com.fr.design.remote.ui.list;
import com.fr.design.remote.RemoteMember;
import javax.swing.DefaultListModel;
import java.awt.event.MouseEvent;
import java.util.Vector;
public class AddingMemberList extends MemberList {
public AddingMemberList() {
super();
}
public AddingMemberList(DefaultListModel<RemoteMember> dataModel) {
super(dataModel);
}
public AddingMemberList(RemoteMember[] listData) {
super(listData);
}
public AddingMemberList(Vector<? extends RemoteMember> listData) {
super(listData);
}
@Override
protected void displaySelected() {
RemoteMember member = getSelectedValue();
member.setSelected(!member.isSelected());
revalidate();
repaint();
fireSelectedChange();
}
@Override
protected boolean shouldDisplaySelected(MouseEvent e) {
return true;
}
}

47
designer-base/src/com/fr/design/remote/ui/list/AddingMemberListCellRender.java

@ -0,0 +1,47 @@
package com.fr.design.remote.ui.list;
import com.fr.base.BaseUtils;
import com.fr.design.gui.icheckbox.UICheckBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.remote.RemoteMember;
import javax.swing.BorderFactory;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
import java.awt.Component;
import java.awt.FlowLayout;
public class AddingMemberListCellRender extends JPanel implements ListCellRenderer<RemoteMember> {
private UILabel label;
private UICheckBox check;
public AddingMemberListCellRender() {
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"));
check = new UICheckBox();
check.setSelected(false);
check.setEnabled(true);
this.add(label);
this.add(check);
}
@Override
public Component getListCellRendererComponent(JList list, RemoteMember member, int index, boolean isSelected, boolean cellHasFocus) {
this.setLabelText(member.getUsername());
check.setSelected(member.isSelected());
return this;
}
private void setLabelText(String name) {
label.setText(name);
}
}

28
designer-base/src/com/fr/design/remote/ui/list/AuthorityList.java

@ -0,0 +1,28 @@
package com.fr.design.remote.ui.list;
import com.fr.report.DesignAuthority;
import javax.swing.JList;
import javax.swing.ListModel;
import java.util.Vector;
public class AuthorityList extends JList<DesignAuthority> {
public AuthorityList() {
super();
}
public AuthorityList(ListModel<DesignAuthority> dataModel) {
super(dataModel);
}
public AuthorityList(final DesignAuthority[] listData) {
super(listData);
}
public AuthorityList(final Vector<? extends DesignAuthority> listData) {
super(listData);
}
}

129
designer-base/src/com/fr/design/remote/ui/list/AuthorityListCellRenderer.java

@ -0,0 +1,129 @@
package com.fr.design.remote.ui.list;
import com.fr.base.BaseUtils;
import com.fr.report.DesignAuthority;
import sun.swing.DefaultLookup;
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.Color;
import java.awt.Component;
public class AuthorityListCellRenderer extends
JLabel implements ListCellRenderer<DesignAuthority> {
/**
* An empty <code>Border</code>. This field might not be used. To change the
* <code>Border</code> used by this renderer override the
* <code>getListCellRendererComponent</code> method and set the border
* of the returned component directly.
*/
private static final Border SAFE_NO_FOCUS_BORDER = new EmptyBorder(1, 1, 1, 1);
private static final Border DEFAULT_NO_FOCUS_BORDER = new EmptyBorder(1, 1, 1, 1);
private static Border noFocusBorder = DEFAULT_NO_FOCUS_BORDER;
/**
* Constructs a default renderer object for an item
* in a list.
*/
public AuthorityListCellRenderer() {
super();
setOpaque(true);
setBorder(getNoFocusBorder());
setName("List.cellRenderer");
}
@Override
public Component getListCellRendererComponent(JList list, DesignAuthority authority,
int index, boolean isSelected, boolean cellHasFocus) {
setComponentOrientation(list.getComponentOrientation());
Color bg = null;
Color fg = null;
JList.DropLocation dropLocation = list.getDropLocation();
if (dropLocation != null
&& !dropLocation.isInsert()
&& dropLocation.getIndex() == index) {
bg = DefaultLookup.getColor(this, ui, "List.dropCellBackground");
fg = DefaultLookup.getColor(this, ui, "List.dropCellForeground");
isSelected = true;
}
if (isSelected) {
setBackground(bg == null ? list.getSelectionBackground() : bg);
setForeground(fg == null ? list.getSelectionForeground() : fg);
} else {
setBackground(list.getBackground());
setForeground(list.getForeground());
}
setEnabled(list.isEnabled());
setFont(list.getFont());
Border border = null;
if (cellHasFocus) {
if (isSelected) {
border = DefaultLookup.getBorder(this, ui, "List.focusSelectedCellHighlightBorder");
}
if (border == null) {
border = DefaultLookup.getBorder(this, ui, "List.focusCellHighlightBorder");
}
} else {
border = getNoFocusBorder();
}
setBorder(border);
this.setIcon(BaseUtils.readIcon("com/fr/design/remote/images/icon_Member_normal@1x.png"));
this.setText(authority.getUsername());
return this;
}
private Border getNoFocusBorder() {
Border border = DefaultLookup.getBorder(this, ui, "List.cellNoFocusBorder");
if (System.getSecurityManager() != null) {
if (border != null) return border;
return SAFE_NO_FOCUS_BORDER;
} else {
if (border != null &&
(noFocusBorder == null ||
noFocusBorder == DEFAULT_NO_FOCUS_BORDER)) {
return border;
}
return noFocusBorder;
}
}
/**
* Overridden for performance reasons.
* See the <a href="#override">Implementation Note</a>
* for more information.
*
* @return <code>true</code> if the background is completely opaque
* and differs from the JList's background;
* <code>false</code> otherwise
* @since 1.5
*/
@Override
public boolean isOpaque() {
Color back = getBackground();
Component p = getParent();
if (p != null) {
p = p.getParent();
}
// p should now be the JList.
boolean colorMatch = (back != null) && (p != null) &&
back.equals(p.getBackground()) &&
p.isOpaque();
return !colorMatch && super.isOpaque();
}
}

84
designer-base/src/com/fr/design/remote/ui/list/MemberList.java

@ -0,0 +1,84 @@
package com.fr.design.remote.ui.list;
import com.fr.design.remote.RemoteMember;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.ListSelectionModel;
import java.awt.Color;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Vector;
public abstract class MemberList extends JList<RemoteMember> {
public MemberList(DefaultListModel<RemoteMember> dataModel) {
super(dataModel);
init();
}
public MemberList(RemoteMember[] listData) {
super(listData);
init();
}
public MemberList(Vector<? extends RemoteMember> listData) {
super(listData);
init();
}
public MemberList() {
super();
init();
}
public void addSelectedChangeListener(MemberListSelectedChangeListener l) {
this.listenerList.add(MemberListSelectedChangeListener.class, l);
}
public void removeSelectedChangeListener(MemberListSelectedChangeListener l) {
this.listenerList.remove(MemberListSelectedChangeListener.class, l);
}
public void fireSelectedChange() {
Object[] listeners = listenerList.getListenerList();
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == MemberListSelectedChangeListener.class) {
((MemberListSelectedChangeListener) listeners[i + 1]).selectedChange();
}
}
}
private void init() {
setBackground(new Color(0xF5F5F7));
this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
this.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
super.mouseReleased(e);
if (shouldDisplaySelected(e)) {
displaySelected();
}
}
});
this.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
super.keyReleased(e);
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
displaySelected();
}
}
});
}
abstract protected void displaySelected();
abstract protected boolean shouldDisplaySelected(MouseEvent e);
}

7
designer-base/src/com/fr/design/remote/ui/list/MemberListSelectedChangeListener.java

@ -0,0 +1,7 @@
package com.fr.design.remote.ui.list;
import java.util.EventListener;
public interface MemberListSelectedChangeListener extends EventListener {
void selectedChange();
}

72
designer-base/src/com/fr/design/remote/ui/tree/FileAuthorityTree.java

@ -0,0 +1,72 @@
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 {
@Override
public boolean isCheckBoxVisible(TreePath path) {
return true;
}
public void selectCheckBoxPaths(String[] paths) {
if (paths == null || paths.length == 0) {
return;
}
DefaultTreeModel model = (DefaultTreeModel) this.getModel();
ExpandMutableTreeNode treeNode = (ExpandMutableTreeNode) model.getRoot();
List<TreePath> 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;
}
}

148
designer-base/src/com/fr/design/remote/ui/tree/FileAuthorityTreeNode.java

@ -0,0 +1,148 @@
package com.fr.design.remote.ui.tree;
import javax.swing.tree.DefaultMutableTreeNode;
public class FileAuthorityTreeNode extends DefaultMutableTreeNode {
public enum Status {
SELECTED,
UNSELECTED,
INDETERMINATE
}
private Status status;
public FileAuthorityTreeNode() {
this(null);
}
public FileAuthorityTreeNode(Object userObject) {
this(userObject, true, Status.UNSELECTED);
}
public FileAuthorityTreeNode(Object userObject, boolean allowsChildren, Status status) {
super(userObject, allowsChildren);
this.status = status;
}
public Status getStatus() {
return status;
}
public boolean isSelected() {
return status == Status.SELECTED;
}
public boolean isUnselected() {
return status == Status.UNSELECTED;
}
public boolean isIndeterminate() {
return status == Status.INDETERMINATE;
}
public void setSelected(boolean selected) {
setStatus(selected ? Status.SELECTED : Status.UNSELECTED);
}
public void setStatus(Status status) {
this.status = status;
switch (status) {
case SELECTED:
// 标记为选中
// 向下
// 如果选中,则所有的子结点都要选中
if (children != null) {
for (Object obj : children) {
FileAuthorityTreeNode node = (FileAuthorityTreeNode) obj;
if (!node.isSelected()) {
node.setSelected(true);
}
}
}
// 向上
// 检查其父节点
if (parent != null) {
FileAuthorityTreeNode pNode = (FileAuthorityTreeNode) parent;
int index = 0;
for (; index < pNode.children.size(); ++index) {
FileAuthorityTreeNode pChildNode = (FileAuthorityTreeNode) pNode.children.get(index);
if (!pChildNode.isSelected()) {
break;
}
}
// 如果父结点下的子结点都被选中了,那么选中父节点
if (index == pNode.children.size()) {
if (!pNode.isSelected()) {
pNode.setSelected(true);
}
}
// 如果父结点下的子结点有部分没被选中,那么标记父结点选中状况为未知
else {
if (!pNode.isIndeterminate()) {
pNode.setStatus(Status.INDETERMINATE);
}
}
}
break;
case UNSELECTED:
//标记为未被选中
// 向下
// 子结点都要取消选中
if (children != null) {
for (Object aChildren : children) {
FileAuthorityTreeNode node = (FileAuthorityTreeNode) aChildren;
if (!node.isUnselected()) {
node.setSelected(false);
}
}
}
// 向上
// 查看父节点的选中情况
if (parent != null) {
FileAuthorityTreeNode pNode = (FileAuthorityTreeNode) parent;
int index = 0;
for (; index < pNode.children.size(); ++index) {
FileAuthorityTreeNode pChildNode = (FileAuthorityTreeNode) pNode.children.get(index);
if (!pChildNode.isUnselected()) {
break;
}
}
// 如果父结点下的子结点都是未被选中的,那么取消选中父节点
if (index == pNode.children.size()) {
if (!pNode.isUnselected()) {
pNode.setSelected(false);
}
}
// 如果父结点下的子结点有部分不是未被选中的,那么标记父结点选中状况为未知
else {
if (!pNode.isIndeterminate()) {
pNode.setStatus(Status.INDETERMINATE);
}
}
}
break;
case INDETERMINATE:
// 标记为未知
// 向下
// 不做改动
// 向上
// 需要将父结点标记为未知
if (parent != null) {
FileAuthorityTreeNode pNode = (FileAuthorityTreeNode) parent;
if (!pNode.isIndeterminate()) {
pNode.setStatus(Status.INDETERMINATE);
}
}
break;
default:
break;
}
}
}

10
designer-base/src/com/fr/env/DesignAuthorityConfigurable.java vendored

@ -0,0 +1,10 @@
package com.fr.env;
import com.fr.report.DesignAuthority;
public interface DesignAuthorityConfigurable {
DesignAuthority[] getAuthorities();
boolean updateAuthorities(DesignAuthority[] authorities) throws Exception;
}

91
designer-base/src/com/fr/env/RemoteEnv.java vendored

@ -1,13 +1,6 @@
package com.fr.env; package com.fr.env;
import com.fr.base.AbstractEnv; import com.fr.base.*;
import com.fr.base.EnvException;
import com.fr.base.FRContext;
import com.fr.base.ModifiedTable;
import com.fr.base.Parameter;
import com.fr.base.StoreProcedureParameter;
import com.fr.base.TableData;
import com.fr.base.Utils;
import com.fr.base.remote.RemoteDeziConstants; import com.fr.base.remote.RemoteDeziConstants;
import com.fr.data.TableDataSource; import com.fr.data.TableDataSource;
import com.fr.data.core.DataCoreUtils; import com.fr.data.core.DataCoreUtils;
@ -29,11 +22,7 @@ import com.fr.file.CacheManager;
import com.fr.file.ConnectionConfig; import com.fr.file.ConnectionConfig;
import com.fr.file.TableDataConfig; import com.fr.file.TableDataConfig;
import com.fr.file.filetree.FileNode; import com.fr.file.filetree.FileNode;
import com.fr.general.ComparatorUtils; import com.fr.general.*;
import com.fr.general.IOUtils;
import com.fr.general.Inter;
import com.fr.general.LogRecordTime;
import com.fr.general.LogUtils;
import com.fr.general.http.HttpClient; import com.fr.general.http.HttpClient;
import com.fr.io.utils.ResourceIOUtils; import com.fr.io.utils.ResourceIOUtils;
import com.fr.json.JSONArray; import com.fr.json.JSONArray;
@ -41,15 +30,9 @@ import com.fr.json.JSONException;
import com.fr.json.JSONObject; import com.fr.json.JSONObject;
import com.fr.license.function.VT4FR; import com.fr.license.function.VT4FR;
import com.fr.regist.License; import com.fr.regist.License;
import com.fr.report.DesignAuthority;
import com.fr.share.ShareConstants; import com.fr.share.ShareConstants;
import com.fr.stable.ArrayUtils; import com.fr.stable.*;
import com.fr.stable.EncodeConstants;
import com.fr.stable.Filter;
import com.fr.stable.JavaCompileInfo;
import com.fr.stable.ProductConstants;
import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.SvgProvider;
import com.fr.stable.file.XMLFileManagerProvider; import com.fr.stable.file.XMLFileManagerProvider;
import com.fr.stable.project.ProjectConstants; import com.fr.stable.project.ProjectConstants;
import com.fr.stable.xml.XMLPrintWriter; import com.fr.stable.xml.XMLPrintWriter;
@ -57,45 +40,26 @@ import com.fr.stable.xml.XMLTools;
import com.fr.stable.xml.XMLableReader; import com.fr.stable.xml.XMLableReader;
import com.fr.web.ResourceConstants; import com.fr.web.ResourceConstants;
import javax.swing.JOptionPane; import javax.swing.*;
import javax.swing.UIManager; import javax.xml.transform.*;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource; import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamResult;
import java.awt.Component; import java.awt.*;
import java.io.BufferedReader; import java.io.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.NoRouteToHostException; import java.net.NoRouteToHostException;
import java.net.Socket; import java.net.Socket;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/** /**
* @author null * @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 TIME_OUT = 30 * 1000;
private static final int PLAIN_SOCKET_PORT = 80; private static final int PLAIN_SOCKET_PORT = 80;
private static final int SSL_PORT = 443; private static final int SSL_PORT = 443;
@ -228,15 +192,23 @@ public class RemoteEnv extends AbstractEnv {
if (!isSignIn) { if (!isSignIn) {
methodPath = methodPath + "?id=" + createUserID(); methodPath = methodPath + "?id=" + createUserID();
} }
return 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;
} }
/** /**
* 根据nameValuePairs,也就是参数对,生成PostMethod,不同之处在于,参数拼在path后面,不是method.addParameters * 根据nameValuePairs,也就是参数对,生成PostMethod,不同之处在于,参数拼在path后面,不是method.addParameters
*/ */
private HttpClient createHttpMethod2(HashMap<String, String> para) throws EnvException { private HttpClient createHttpMethod2(HashMap<String, String> para) throws EnvException, UnsupportedEncodingException {
String methodPath = path + '?' + "id=" + createUserID(); String methodPath = path + '?' + "id=" + createUserID();
return new HttpClient(methodPath, para, true); return new HttpClient(methodPath);
} }
@ -824,6 +796,18 @@ public class RemoteEnv extends AbstractEnv {
return Boolean.valueOf(IOUtils.inputStream2String(input, EncodeConstants.ENCODING_UTF_8)); return Boolean.valueOf(IOUtils.inputStream2String(input, EncodeConstants.ENCODING_UTF_8));
} }
@Override
public boolean updateAuthorities(DesignAuthority[] authorities) throws Exception {
return RemoteEnvUtils.updateAuthorities(authorities, this);
}
@Override
public DesignAuthority[] getAuthorities() {
return RemoteEnvUtils.getAuthorities(this);
}
/** /**
* ben:取schema * ben:取schema
*/ */
@ -1364,6 +1348,13 @@ public class RemoteEnv extends AbstractEnv {
*/ */
public InputStream postBytes2ServerB(byte[] bytes, HashMap<String, String> para) throws Exception { public InputStream postBytes2ServerB(byte[] bytes, HashMap<String, String> para) throws Exception {
HttpClient client = createHttpMethod2(para); 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); client.setContent(bytes);
return execute4InputStream(client); return execute4InputStream(client);
} }
@ -1898,8 +1889,6 @@ public class RemoteEnv extends AbstractEnv {
} }
//TODO:
/** /**
* 预览存储过程 * 预览存储过程
* *

86
designer-base/src/com/fr/env/RemoteEnvUtils.java vendored

@ -0,0 +1,86 @@
package com.fr.env;
import com.fr.base.FRContext;
import com.fr.general.IOUtils;
import com.fr.report.DesignAuthority;
import com.fr.stable.EncodeConstants;
import com.fr.third.org.apache.http.HttpEntity;
import com.fr.third.org.apache.http.client.methods.CloseableHttpResponse;
import com.fr.third.org.apache.http.client.methods.HttpUriRequest;
import com.fr.third.org.apache.http.client.methods.RequestBuilder;
import com.fr.third.org.apache.http.entity.ContentType;
import com.fr.third.org.apache.http.entity.InputStreamEntity;
import com.fr.third.org.apache.http.impl.client.CloseableHttpClient;
import com.fr.third.org.apache.http.impl.client.HttpClients;
import com.fr.third.org.apache.http.util.EntityUtils;
import com.fr.web.utils.AuthorityXMLUtils;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class RemoteEnvUtils {
private RemoteEnvUtils() {
}
public static boolean updateAuthorities(DesignAuthority[] authorities, RemoteEnv env) {
String path = env.getPath();
String userID = env.getUserID();
String res = null;
CloseableHttpClient httpClient = HttpClients.createDefault();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
AuthorityXMLUtils.writeDesignAuthoritiesXML(authorities, outputStream);
InputStreamEntity reqEntity = new InputStreamEntity(new ByteArrayInputStream(outputStream.toByteArray()), ContentType.TEXT_XML);
HttpUriRequest request = RequestBuilder.post(path)
.addParameter("id", userID)
.addParameter("op", "remote_design_authority")
.addParameter("cmd", "update_authorities")
.setEntity(reqEntity)
.build();
try {
CloseableHttpResponse response = httpClient.execute(request);
HttpEntity entity = response.getEntity();
res = IOUtils.inputStream2String(entity.getContent(), EncodeConstants.ENCODING_UTF_8);
EntityUtils.consume(entity);
} catch (IOException e) {
FRContext.getLogger().error(e.getMessage());
}
return res != null && Boolean.valueOf(res);
}
public static DesignAuthority[] getAuthorities(RemoteEnv env) {
String path = env.getPath();
String userID = env.getUserID();
DesignAuthority[] authorities = null;
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpUriRequest request = RequestBuilder.get(path)
.addParameter("id", userID)
.addParameter("op", "remote_design_authority")
.addParameter("cmd", "get_authorities")
.build();
try {
CloseableHttpResponse response = httpClient.execute(request);
HttpEntity entity = response.getEntity();
authorities = AuthorityXMLUtils.readDesignAuthoritiesXML(entity.getContent());
EntityUtils.consume(entity);
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage());
}
return authorities;
}
}
Loading…
Cancel
Save