package com.vci.client.logon.base;
|
|
import java.awt.BorderLayout;
|
import java.awt.Container;
|
import java.awt.Dimension;
|
import java.awt.Frame;
|
import java.awt.Graphics;
|
import java.awt.Insets;
|
import java.awt.Point;
|
import java.awt.Rectangle;
|
import java.awt.Toolkit;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.awt.event.ComponentAdapter;
|
import java.awt.event.ComponentEvent;
|
import java.lang.reflect.InvocationTargetException;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.swing.AbstractButton;
|
import javax.swing.JComponent;
|
import javax.swing.JDialog;
|
import javax.swing.JFrame;
|
import javax.swing.JMenuItem;
|
import javax.swing.JPanel;
|
import javax.swing.JToolBar;
|
import javax.swing.UIManager;
|
import javax.swing.WindowConstants;
|
import javax.swing.plaf.metal.MetalButtonUI;
|
|
import com.vci.client.ClientSession;
|
import com.vci.client.LogonApplication;
|
import com.vci.client.framework.rightConfig.object.FunctionObject;
|
import com.vci.client.framework.rightdistribution.object.RoleRightObject;
|
import com.vci.client.framework.scaffold.GenericMenuBar;
|
import com.vci.client.framework.util.RightControlUtil;
|
import com.vci.client.logon.client.VciFrame;
|
import com.vci.client.ui.exception.VCIException;
|
import com.vci.client.ui.frame.UIConstructorInterface;
|
import com.vci.client.ui.swing.VCIOptionPane;
|
import com.vci.client.ui.swing.VCISwingUtil;
|
import com.vci.client.ui.swing.components.VCIJButton;
|
import com.vci.client.ui.swing.components.VCIJMenu;
|
import com.vci.client.ui.swing.components.VCIJMenuItem;
|
import com.vci.client.ui.swing.components.VCIJPanel;
|
import com.vci.client.uif.engine.client.UIBaseLayoutPanel;
|
import com.vci.corba.common.VCIError;
|
|
|
public class SysCofigMenuBar extends GenericMenuBar{
|
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 1L;
|
|
public SysCofigMenuBar(Frame frame) {
|
super(frame);
|
}
|
|
@Override
|
public void initSpecialMenuBar(){
|
String userName = LogonApplication.getUserEntityObject().getUserName();
|
String parentId = "business";
|
|
if (RightControlUtil.isAdminOrDeveloperOrRoot(userName)) {
|
// 系统菜单
|
parentId = "system" ;
|
BuildMenu(userName, parentId);
|
|
// 业务菜单
|
//parentId = "business" ;
|
//BuildMenu(userName, parentId);
|
|
} else if (RightControlUtil.isThreeAdminCurUser()) {
|
parentId = "system" ;
|
BuildMenu(userName, parentId);
|
} else {
|
parentId = "business" ;
|
BuildMenu(userName, parentId);
|
}
|
|
/* VCIJMenu menuEmpty = new VCIJMenu("");
|
menuEmpty.addSeparator();
|
this.add(menuEmpty);*/
|
}
|
|
private void BuildMenu(String userName, String parentId) {
|
try{
|
RoleRightObject[] userRoleRights = RightControlUtil.getRoleRightByUserName(userName);
|
Map<String, List<FunctionObject>> map = RightControlUtil.getAllChildrenFunctionsByUserName(
|
parentId, userName, userRoleRights);
|
LogonApplication.currentUserRoleRights = userRoleRights;
|
List<FunctionObject> list = map.get(parentId);
|
if (list == null || list.size() == 0) {
|
return;
|
}
|
for (int i = 0; i < list.size(); i++) {
|
FunctionObject funcObj = list.get(i);
|
if (!funcObj.getIsValid()) {
|
continue;
|
}
|
String csModulePath = funcObj.getResourceC();
|
if(csModulePath != null && !"".equals(csModulePath)){
|
//List<FunctionObject> listSub = map.get(funcObj.getId());
|
|
int childType = getChildType(map.get(funcObj.getId()));
|
if(childType == 1){// 有模块
|
VCIJMenu menu = new VCIJMenu();
|
menu.setName(funcObj.getName());
|
menu.setObj(funcObj);
|
menu.setText(funcObj.getName());
|
menu.setIcon(VCISwingUtil.createImageIcon(funcObj.getImage()));
|
initMenuBar(menu, funcObj.getId(), map);
|
this.add(menu);
|
} else if(childType == 2){ // 有操作
|
String name = funcObj.getName();
|
String text = funcObj.getName();
|
String toolTip = text;
|
String icon = funcObj.getImage();
|
VCIJButton btn = VCISwingUtil.createVCIJButton(
|
text, text, toolTip, icon, new ActionListener(){
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
command_actionEvent(e);
|
}
|
});
|
btn.setBorderPainted(false);
|
btn.setName(name);
|
btn.setObj(funcObj);
|
// 重置UI,修复按钮点击或有过焦点时,外围有连线
|
btn.setUI(new MetalButtonUI(){
|
private boolean borderPaintsFocus;
|
@Override
|
public void installDefaults(AbstractButton b) {
|
super.installDefaults(b);
|
this.borderPaintsFocus = Boolean.TRUE.equals(UIManager
|
.get("Button.borderPaintsFocus"));
|
}
|
@Override
|
public void update(Graphics g, JComponent c) {
|
if (c.isOpaque()) {
|
AbstractButton b = (AbstractButton) c;
|
if (isToolBarButton(b)) {
|
c.setOpaque(false);
|
} else if (b.isContentAreaFilled()) {
|
g.setColor(c.getBackground());
|
g.fillRect(0, 0, c.getWidth(),
|
c.getHeight());
|
}
|
}
|
paint(g, c);
|
}
|
@Override
|
protected void paintFocus(Graphics g,
|
AbstractButton b, Rectangle viewRect,
|
Rectangle textRect, Rectangle iconRect) {
|
if (this.borderPaintsFocus) {
|
return;
|
}
|
}
|
protected boolean isToolBarButton(AbstractButton b) {
|
Container parent = b.getParent();
|
return ((parent != null) && (((parent instanceof JToolBar) || (parent
|
.getParent() instanceof JToolBar))));
|
}
|
});
|
this.add(btn);
|
}
|
}
|
}
|
} catch (VCIException e1) {
|
e1.printStackTrace();
|
VCIOptionPane.showError(LogonApplication.frame, "加载系统功能模块菜单时发生错误!\n" + e1.toString());
|
}
|
}
|
|
private void initMenuBar(JMenuItem parentMenu, String parentId, Map<String, List<FunctionObject>> map) throws VCIException {
|
List<FunctionObject> list = map.get(parentId);
|
if (list == null || list.size() == 0) {
|
return;
|
}
|
for (int i = 0; i < list.size(); i++) {
|
FunctionObject funcObj = list.get(i);
|
if (!funcObj.getIsValid()) {
|
continue;
|
}
|
String csModulePath = funcObj.getResourceC();
|
if(csModulePath != null && !"".equals(csModulePath)){
|
int childType = getChildType(map.get(funcObj.getId()));
|
if(childType == 1){// 有模块
|
VCIJMenu menu = new VCIJMenu();
|
menu.setName(funcObj.getName());
|
menu.setObj(funcObj);
|
menu.setText(funcObj.getName());
|
menu.setIcon(VCISwingUtil.createImageIcon(funcObj.getImage()));
|
initMenuBar(menu, funcObj.getId(), map);
|
parentMenu.add(menu);
|
} else if(childType == 2){ // 有操作
|
String name = funcObj.getName();
|
String text = funcObj.getName();
|
String toolTip = text;
|
String icon = funcObj.getImage();
|
VCIJMenuItem menuItem = new VCIJMenuItem();
|
menuItem.addActionListener(new ActionListener(){
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
command_actionEvent(e);
|
}
|
});
|
if(!"".equals(icon)){
|
menuItem.setIcon(VCISwingUtil.createImageIcon(icon));
|
}
|
menuItem.setToolTipText(toolTip);
|
menuItem.setName(name);
|
menuItem.setObj(funcObj);
|
menuItem.setText(text);
|
parentMenu.add(menuItem);
|
}
|
}
|
}
|
}
|
|
private int getChildType(List<FunctionObject> list) {
|
int childType = -1;
|
if (list == null) {
|
childType = 2;
|
} else {
|
childType = list.size() >= 1 ? 1 : 2;
|
}
|
|
return childType;
|
}
|
|
private void command_actionEvent(ActionEvent e) {
|
boolean isExpired = ClientSession.checkExpired();
|
if(isExpired){
|
ClientSession.relogin();
|
return;
|
}
|
Object source = e.getSource();
|
FunctionObject funcObj = null;
|
if(source instanceof VCIJMenuItem){
|
VCIJMenuItem menuItem = (VCIJMenuItem)e.getSource();
|
funcObj = (FunctionObject)menuItem.getObj();
|
} else if(source instanceof VCIJMenu){
|
VCIJMenu menu = (VCIJMenu)source;
|
funcObj = (FunctionObject)menu.getObj();
|
} else if(source instanceof VCIJButton){
|
VCIJButton menu = (VCIJButton)source;
|
funcObj = (FunctionObject)menu.getObj();
|
} else {
|
return;
|
}
|
boolean isExist = TabPanelManage.getInstance().isTabPanelExist(funcObj.getName());
|
if (isExist) {
|
return;
|
}
|
Object obj = getNewPanel(funcObj);
|
if (obj == null) {
|
return;
|
}
|
if (!(obj instanceof JPanel)) {
|
return;
|
}
|
JPanel cPanel = (JPanel)obj;
|
|
boolean isPopFrame = false;
|
boolean isPopDialog = false;
|
if (funcObj.getResourceC().indexOf("UILayoutPanel") >= 0) {
|
String url = funcObj.getResourceC();
|
String cparameter = url.substring(url.indexOf("?") + 1);
|
String[] cparameters = cparameter.split("&");
|
for (int i = 0; i < cparameters.length; i++) {
|
if (cparameters[i] == null) {
|
continue;
|
}
|
String[] paramVals = cparameters[i].split("=");
|
if (paramVals.length != 2) {
|
continue;
|
}
|
if (paramVals[0].equalsIgnoreCase("popFrame") && paramVals[1].equalsIgnoreCase("true")) {
|
isPopFrame = true;
|
} else if (paramVals[0].equalsIgnoreCase("popDialog") && paramVals[1].equalsIgnoreCase("true")) {
|
isPopDialog = true;
|
}
|
}
|
}
|
if (isPopFrame) {
|
popupFrame(cPanel, funcObj);
|
} else if (isPopDialog) {
|
popupDialog(cPanel, funcObj);
|
} else {
|
TabPanelManage.getInstance().addTabPanel(cPanel, funcObj.getName());
|
}
|
}
|
|
private void popupFrame(JPanel cPanel, FunctionObject funcObj) {
|
JFrame frame = new JFrame();
|
frame.setTitle(funcObj.getName());
|
frame.getContentPane().setLayout(new BorderLayout());
|
frame.getContentPane().add(cPanel, BorderLayout.CENTER);
|
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
setSizeAndLocation(frame);
|
frame.setVisible(true);
|
}
|
|
private void popupDialog(JPanel cPanel, FunctionObject funcObj) {
|
JDialog dialog = new JDialog(LogonApplication.frame);
|
dialog.setTitle(funcObj.getName());
|
dialog.getContentPane().setLayout(new BorderLayout());
|
dialog.getContentPane().add(cPanel, BorderLayout.CENTER);
|
dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
setSizeAndLocation(dialog);
|
dialog.setModal(true);
|
dialog.setResizable(true);
|
dialog.setVisible(true);
|
}
|
|
private Object getNewPanel(FunctionObject funcObj) {
|
Object res = new VCIJPanel();
|
try {
|
int index = funcObj.getResourceC().indexOf("?");
|
if (index > 0) {
|
String clsStr = funcObj.getResourceC().substring(0, index);
|
Class<?> cls = Class.forName(clsStr);
|
|
if (clsStr.indexOf("UILayoutPanel") >= 0) {
|
UIBaseLayoutPanel uiPanel = (UIBaseLayoutPanel)cls.getConstructor(String.class, java.util.Map.class).newInstance(funcObj.getResourceC(), null);
|
boolean rs = uiPanel.prep();
|
if (!rs) {
|
return null;
|
}
|
uiPanel.initMainPanel();
|
res = uiPanel;
|
return res;
|
}
|
// else if (clsStr.indexOf("VCIModuleMainPanel") > 0){
|
// SpecialRoleClientObject[] specialRoleList = new SpecialRoleClientDelegate().getSpecialRoleList();
|
//
|
// String panelName = funcObj.getResourceC().substring(index + 1);
|
// JPanel panel = null;
|
// if(panelName.contains("@")){
|
// String[] split = panelName.split("@");
|
// if(split!=null){
|
// cls = Class.forName(split[0]);
|
// String param = split[1];
|
// if(param.contains(",")){
|
// String[] params = param.split(",");
|
// panel = (JPanel)cls.getConstructor(FunctionObject.class,String.class).newInstance(new FunctionObject(),params[1]);
|
// }else{
|
// panel = (JPanel) cls.getConstructor(FunctionObject.class).newInstance(new FunctionObject());
|
// }
|
// }
|
// }
|
//
|
// res = panel;
|
//
|
// return res;
|
// }
|
}
|
Class<?> cls = Class.forName(funcObj.getResourceC());
|
try {
|
res = cls.getConstructor(FunctionObject.class).newInstance(funcObj);
|
} catch (NoSuchMethodException nse) {
|
UIConstructorInterface instance = (UIConstructorInterface)cls.newInstance();
|
instance.init();
|
res = instance.start();
|
}
|
|
} catch (SecurityException e) {
|
e.printStackTrace();
|
} catch (ClassNotFoundException e) {
|
e.printStackTrace();
|
}catch (IllegalArgumentException e) {
|
e.printStackTrace();
|
} catch (InstantiationException e) {
|
e.printStackTrace();
|
} catch (IllegalAccessException e) {
|
e.printStackTrace();
|
} catch (InvocationTargetException e) {
|
e.printStackTrace();
|
} catch (VCIError e) {
|
e.printStackTrace();
|
} catch (NoSuchMethodException nse) {
|
nse.printStackTrace();
|
}
|
return res;
|
}
|
|
private void setSizeAndLocation(final JFrame frame){
|
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(frame.getGraphicsConfiguration());
|
Dimension size = getCurrentSizeAndSetLocation(frame);
|
frame.setPreferredSize(size);
|
frame.setSize(size);
|
Point location = new Point(insets.left, insets.top);
|
frame.setLocation(location);
|
frame.setLocationByPlatform(true);
|
frame.setLocationRelativeTo(null);
|
frame.addComponentListener(new ComponentAdapter() {
|
|
@Override
|
public void componentResized(ComponentEvent e) {
|
if(e.getSource() instanceof VciFrame){
|
JFrame vf = (JFrame)e.getSource();
|
int extendedState = vf.getExtendedState();
|
if((extendedState & JFrame.MAXIMIZED_BOTH) == JFrame.MAXIMIZED_BOTH){
|
Dimension size = getCurrentSizeAndSetLocation(frame);
|
frame.setPreferredSize(size);
|
frame.setSize(size);
|
return;
|
}
|
}
|
}
|
});
|
}
|
|
private Dimension getCurrentSizeAndSetLocation(JFrame frame){
|
Dimension d = new Dimension();
|
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
|
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(frame.getGraphicsConfiguration());
|
int top = insets.top;
|
int left = insets.left;
|
int right = insets.right;
|
int bottom = insets.bottom;
|
int width = dim.width - left - right;
|
int height = dim.height - top - bottom;
|
int x = insets.left;
|
int y = insets.top;
|
frame.setLocation(x, y);
|
d = new Dimension(width, height);
|
return d;
|
}
|
|
private Dimension getCurrentSizeAndSetLocation(JDialog dialog){
|
Dimension d = new Dimension();
|
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
|
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(LogonApplication.frame.getGraphicsConfiguration());
|
int top = insets.top;
|
int left = insets.left;
|
int right = insets.right;
|
int bottom = insets.bottom;
|
int width = dim.width - left - right - 2 * 100;
|
int height = dim.height - top - bottom - 2 * 50;
|
int x = insets.left + 100;
|
int y = insets.top + 50;
|
dialog.setLocation(x, y);
|
d = new Dimension(width, height);
|
return d;
|
}
|
|
private void setSizeAndLocation(JDialog dialog){
|
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(LogonApplication.frame.getGraphicsConfiguration());
|
Dimension size = getCurrentSizeAndSetLocation(dialog);
|
dialog.setPreferredSize(size);
|
dialog.setSize(size);
|
Point location = new Point(insets.left, insets.top);
|
dialog.setLocation(location);
|
dialog.setLocationByPlatform(true);
|
dialog.setLocationRelativeTo(null);
|
}
|
}
|