package com.vci.client.uif.actions.client; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Insets; import java.awt.Point; import java.awt.Toolkit; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import javax.swing.JFrame; import javax.swing.WindowConstants; import com.vci.client.bof.ClientBusinessObject; import com.vci.client.bof.ClientLinkObject; import com.vci.client.common.FreeMarkerCommon; import com.vci.client.common.FreemarkerParamObject; import com.vci.client.logon.client.VciFrame; import com.vci.client.uif.engine.client.UIHelper; import com.vci.client.uif.engine.client.UILayoutPanel; import com.vci.client.uif.engine.common.DefaultTableNode; import com.vci.client.uif.engine.common.IDataNode; import com.vci.corba.omd.data.AttributeValue; import com.vci.mw.ClientContextVariable; /** * 浏览操作 * 在新的frame页中根据type、context打开窗口 * 接受参数信息为: * btmname(业务对象类型) * context * oid(业务对象oid) * @author VCI-STGK006 * */ public class ViewFrameAction extends AbstractBusionessOperationAction{ /** * 方法集合 */ protected UIFUtils operation = new UIFUtils(); /** * 按钮参数 */ private Map paramsMap = null; /** * BO对象 */ protected ClientBusinessObject cbo = null; public ViewFrameAction(){ super(); } @Override public String getKey() { return VIEW; } @Override public boolean checkHasRight(){ // 按BO进行数据权限检查 setDataRightCheckType(RightCheckConstants.RIGHT_CHECK_TYPE_B); return super.checkHasRight(); } @Override public boolean doPost() { try{ //获得按钮参数 paramsMap = getButtonParams(); //得到打开窗口的上下文信息 String type = paramsMap.get("type"); String context = paramsMap.get("context"); String oidKey = paramsMap.get("oid"); String showName = paramsMap.get("showname"); if(type == null || type.equals("") || context == null || context.equals("")){ UIFUtils.showMessage(ClientContextVariable.getFrame(), "uifmodel.plm.uif.actions.syserror.parmerror", ""); return false; } if(oidKey == null){ oidKey = ""; } // 得到业务对象、设置需要显示的属性值 IDataNode idn = getBusinessObject(type, oidKey); if(idn.getMaterObject() == null){ return false; } Map map = idn.getValueMap(); // 从主管理界面的数据列表中跳转到数据对象明细数据展示(Navigation\MainData\TabPage) map.put(UIHelper.TYPE, type); map.put(UIHelper.CONTEXT, context); map.put(UIHelper.OID, cbo.getBusinessObject().oid); Object[] objs = getDataModel().getSelectObjects(); IDataNode inputData = (IDataNode)objs[objs.length - 1]; UILayoutPanel uipl = new UILayoutPanel(map); // 注入此action当前选择的数据 uipl.setInputData(inputData); uipl.setSourceDataNode(idn); uipl.setDataValueMap(map); uipl.prep(); uipl.initMainPanel(); //在按钮参数中增加一个参数 showName 用来作为tab页的名称 String tabName = ""; if(showName == null || showName.equals("")){ tabName = map.get("name"); } else { if(showName.indexOf("${") != -1){ Map freeMap = getFreemarkerParamMap(map); tabName = FreeMarkerCommon.getValueByTempRule(freeMap, showName); } else { tabName = showName; } } JFrame frame = new JFrame(); frame.setTitle(tabName); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(uipl, BorderLayout.CENTER); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); setSizeAndLocation(frame); frame.setVisible(true); return false; } catch(Throwable e){ UIFUtils.showErrorMessage(ClientContextVariable.getFrame(), e); return false; } } 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; } /** * 根据用户所选数据获得打开上下文的SourceData * 判断oidKey是否为空 * 如果oidKey为空,如果是BO则只用BO作为From * 如果是LO则使用LO的to端对象作为From * 如果oidKey不为空,则根据上下文类型和oidKey对应的oid获得BO作为From * @return */ protected IDataNode getBusinessObject(String type, String oidKey){ IDataNode idn = new DefaultTableNode(); //获得业务对象数据 Object[] objs = getDataModel().getSelectObjects(); if(objs == null || objs.length < 1){ cbo = null; } //modify 2014.03.07 start DefaultTableNode dtn = (DefaultTableNode) objs[0]; try { if(dtn.getMaterObject() instanceof ClientBusinessObject){ Map valueMap = dtn.getValueMap(); if(!oidKey.equals("")){ String oid = valueMap.get(oidKey);; String btmName = type; if(oid != null && !oid.equals("") && btmName != null && !btmName.equals("")) { //需要重新下载cbo对象 cbo = UIFUtils.queryBusinessObject(oid, btmName, true); //对象不存在或者已经被删除 if(cbo.getBusinessObject().oid == null || cbo.getBusinessObject().oid.equals("")){ UIFUtils.showMessage(ClientContextVariable.getFrame(), "uifmodel.plm.uif.actions.notexistmsg", ""); idn.setMasterObject(null); return idn; } } } else { cbo = (ClientBusinessObject) dtn.getMaterObject(); } if(cbo == null){ UIFUtils.showMessage(ClientContextVariable.getFrame(), "uifmodel.plm.uif.actions.notexistmsg", dtn.getValueMap().get("name")); idn.setMasterObject(null); return idn; } } else if (dtn.getMaterObject() instanceof String){ UIFUtils.showMessage(ClientContextVariable.getFrame(), "uifmodel.plm.uif.engine.folder.root.disabled"); idn.setMasterObject(null); return idn; } else if(dtn.getMaterObject() instanceof ClientLinkObject){ ClientLinkObject clo = (ClientLinkObject) dtn.getMaterObject(); Map valueMap = dtn.getValueMap(); if(!oidKey.equals("")){ String oid = valueMap.get(oidKey); String btmName = type; if(oid != null && !oid.equals("") && btmName != null && !btmName.equals("")) { //需要重新下载cbo对象 cbo = UIFUtils.queryBusinessObject(oid, btmName, true); //对象不存在或者已经被删除 if(cbo.getBusinessObject().oid == null || cbo.getBusinessObject().oid.equals("")){ UIFUtils.showMessage(ClientContextVariable.getFrame(), "uifmodel.plm.uif.actions.notexistmsg", ""); idn.setMasterObject(null); return idn; } } } else { //如果是LO,获得头端对象信 String oid = clo.getLinkObject().toOid; String btmName = clo.getLinkObject().toBTName; if(oid != null && !oid.equals("") && btmName != null && !btmName.equals("")) { //需要重新下载cbo对象 cbo = UIFUtils.queryBusinessObject(oid, btmName, true); //对象不存在或者已经被删除 if(cbo.getBusinessObject().oid == null || cbo.getBusinessObject().oid.equals("")){ UIFUtils.showMessage(ClientContextVariable.getFrame(), "uifmodel.plm.uif.actions.notexistmsg", ""); idn.setMasterObject(null); return idn; } } } } Map boMap = getValueMap(cbo); idn.setMasterObject(cbo); idn.setValueMap(boMap); } catch (Exception e){ e.printStackTrace(); UIFUtils.showMessage( ClientContextVariable.getFrame(), "uifmodel.plm.uif.actions.syserror.btnconferror"); idn.setMasterObject(null); return idn; } return idn; //modify 2014.03.07 end } /** * 获得属性集合 * @param cbo * @return */ public Map getValueMap(ClientBusinessObject cbo){ if(cbo == null){ return new HashMap(); } Map valueMap = new HashMap(); AttributeValue[] arrts = cbo.getBusinessObject().hisAttrValList; if(arrts != null){ for(AttributeValue attr : arrts){ if(attr != null){ try{ valueMap.put(attr.attrName.toLowerCase(), attr.attrVal); } catch (Exception e){ e.printStackTrace(); } } } } return valueMap; } /** * 获得木板数据 * @param map * @return */ public Map getFreemarkerParamMap(Map map){ Map freeMap = new HashMap(); if(map == null){ return freeMap; } Iterator it = map.keySet().iterator(); while(it.hasNext()){ String key = (String) it.next(); FreemarkerParamObject fpo = new FreemarkerParamObject(); fpo.setName(key); fpo.setValue(map.get(key)); key = key.replaceAll("\\.", "Ψ"); freeMap.put(key, fpo); } return freeMap; } }