* commit '64de3e05a8b0b00697b277dbf5064abd16f73cce': doc 删除无用代码 REPORT-6700 国际化 REPORT-6700 数据传输 和 存储 REPORT-6700 远程设计权限 REPORT-6700 update remote design pilot remote design use http get method remote design use http get method todo update tree todo update tree file tree file tree update save REPORT-6700 远程设计权限 REPORT-6700 远程设计权限master
@ -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()); |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
After Width: | Height: | Size: 337 B |
After Width: | Height: | Size: 548 B |
After Width: | Height: | Size: 525 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 350 B |
After Width: | Height: | Size: 746 B |
After Width: | Height: | Size: 288 B |
After Width: | Height: | Size: 531 B |
After Width: | Height: | Size: 575 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 238 B |
@ -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; |
||||
} |
||||
} |
@ -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(); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -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(); |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
@ -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(); |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
||||
|
||||
|
@ -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); |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
|
||||
} |
@ -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(); |
||||
} |
||||
} |
@ -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); |
||||
|
||||
|
||||
} |
@ -0,0 +1,7 @@
|
||||
package com.fr.design.remote.ui.list; |
||||
|
||||
import java.util.EventListener; |
||||
|
||||
public interface MemberListSelectedChangeListener extends EventListener { |
||||
void selectedChange(); |
||||
} |
@ -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; |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,10 @@
|
||||
package com.fr.env; |
||||
|
||||
import com.fr.report.DesignAuthority; |
||||
|
||||
public interface DesignAuthorityConfigurable { |
||||
|
||||
DesignAuthority[] getAuthorities(); |
||||
|
||||
boolean updateAuthorities(DesignAuthority[] authorities) throws Exception; |
||||
} |
@ -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; |
||||
|
||||
} |
||||
|
||||
} |