package com.vci.client.uif.engine.client; import java.awt.BorderLayout; import java.awt.Color; import java.awt.FlowLayout; import java.awt.Frame; import java.awt.Rectangle; import java.awt.Toolkit; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Vector; import javax.swing.BorderFactory; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.border.Border; import com.vci.client.bof.ClientBusinessObject; import com.vci.client.omd.lifecycle.LifeCycleStart; 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.VCIJComboBox; import com.vci.client.ui.swing.components.VCIJDialog; import com.vci.client.uif.actions.client.UIFUtils; import com.vci.corba.common.VCIError; import com.vci.corba.omd.lcm.Bound; import com.vci.corba.omd.lcm.LifeCycle; import com.vci.corba.omd.lcm.TransitionVO; /** * 选择业务对象生命周期跃迁状态对话框 * @author VCI-STGK006 * */ public class TransferBusinessObjectDialog extends VCIJDialog { /** * */ private static final long serialVersionUID = 1L; /** * 边框 */ private Border loweredBevel = BorderFactory.createLoweredBevelBorder(); /** * 生命周期状态选择框 */ private VCIJComboBox comboBox; /** * 业务对象 */ private ClientBusinessObject cbo = null; /** * 待选状态列表 */ private Vector statusList = new Vector(); /** * 业务对象生命周期 */ private LifeCycle lc = null; /** * 选择跃迁状态 */ //private TransitionVO selectedTransitionVO = null; /** * 用于判断用户点击了确定按钮还是取消按钮 */ private boolean isOk = false; /** * 父窗口 */ private Frame owner; /** * 选择业务对象生命周期跃迁状态对话框 * @param cbo 业务对象 */ public TransferBusinessObjectDialog(Frame owner, ClientBusinessObject cbo){ super(owner,"设置生命周期状态",true); this.owner = owner; this.cbo = cbo; try { getLifeCyle(); if(this.lc == null){ VCIOptionPane.showMessage(owner, "“"+ cbo.getName() +"”生命周期不存在!"); return; } getStatusList(); if(this.statusList.isEmpty()){ VCIOptionPane.showMessage(owner, "“"+ cbo.getName() +"”已经是生命周期的最后一个状态"); return; } } catch (Exception e) { VCIOptionPane.showMessage(owner, "创建跃迁对话框失败:" + e.getMessage()); return; } init(); setWindowLocation(this); setVisible(true); validate(); } /** * 绘制窗口 */ public void init(){ setSize(700, 600); //标题部分 JPanel toPanel = new JPanel(); toPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); //JLabel titleLable = new JLabel("选择跃迁状态"); //toPanel.add(titleLable); //中间内容面板 JPanel centerPanel = new JPanel(); centerPanel.setBorder(loweredBevel); //创建生命周期图面板 // ArrowLinePanel lifePanel = createLifePanel(); LifeCyclePanel lifePanel = createLifePanel(lc); centerPanel.setLayout(new BorderLayout(0, 0)); centerPanel.add(lifePanel); //底部按钮面板 JPanel bottomPanel = new JPanel(); VCIJButton okBtn = VCISwingUtil.createVCIJButton("ok", "确定", "确定", "accept.png"); okBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { okBtn_Action(); } }); VCIJButton cancelBtn = VCISwingUtil.createVCIJButton("cancel", "取消", "取消", "cancel.png"); cancelBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cancelBtn_Action(); } }); bottomPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5)); bottomPanel.add(okBtn); bottomPanel.add(cancelBtn); getContentPane().setLayout(new BorderLayout(0, 0)); //... getContentPane().add(toPanel, BorderLayout.NORTH); getContentPane().add(centerPanel, BorderLayout.CENTER); JPanel panel = new JPanel(); FlowLayout flowLayout = (FlowLayout) panel.getLayout(); flowLayout.setAlignment(FlowLayout.LEFT); centerPanel.add(panel, BorderLayout.NORTH); JLabel comLabel = new JLabel(); panel.add(comLabel); comLabel.setText("请选择生命周期:"); JLabel lifeLabel = new JLabel(); //panel.add(lifeLabel); lifeLabel.setText("所属生命周期:"); comboBox = new VCIJComboBox(statusList); panel.add(comboBox); getContentPane().add(bottomPanel, BorderLayout.SOUTH); setResizable(false); } public LifeCyclePanel createLifePanel(LifeCycle lc){ LifeCyclePanel line = new LifeCyclePanel(lc,cbo); return line; } /** * 得到业务对象对应生命周期 * @throws Exception */ private void getLifeCyle() throws Exception{ if(this.cbo == null){ throw new Exception("业务对象为空!"); } //得到所有LifeCyle对象 try { LifeCycle[] lifeCyles = LifeCycleStart.getService().getLifeCycles(); for(int i = 0; i < lifeCyles.length; i++){ LifeCycle lc = lifeCyles[i]; //得到业务对象的生命周期 if(lc.name.equals(cbo.getBusinessObject().lctId)){ this.lc = lc; } } } catch (VCIError e) { throw e; } } /** * 得到所有待跃迁的状态 */ private void getStatusList(){ String currentState = cbo.getLcStatus(); for (int i = 0; i < lc.routes.length; ++i) { TransitionVO route = lc.routes[i]; if (route.source.equals(currentState)){ //得到状态 if(lc.bounds != null){ for(Bound bound : lc.bounds){ if(bound.name.equals(route.destination)){ statusList.add(new TransitionVOExt(route, bound)); } } } } } } /** * 确定按钮事件 */ public void okBtn_Action(){ this.isOk = true; this.dispose(); } /** * 取消按钮事件 */ public void cancelBtn_Action(){ this.isOk = false; this.dispose(); } /** * 用于判断用户点击了确定按钮还是取消按钮 * @return true 点击确定 */ public boolean isOk(){ return isOk; } /** * 得到跃迁对象 * @return */ public TransitionVO getTransitionVO(){ TransitionVOExt ext = (TransitionVOExt) this.comboBox.getSelectedItem(); return ext.getTransitionVO(); } /** * 绘制生命周期状态类 * @author VCI-STGK006 * */ private class PrintLifeCyleStatus extends JPanel{ /** * 面板宽度 */ private final int STATUS_WIDTH = 50; /** * 面板高度 */ private final int STATUS_HEIGHT = 50; /** * 面板边框 */ private Border lineBorder = BorderFactory.createLineBorder(Color.BLACK); /** * 生命周期状态 */ private Bound bound = null; /** * 绘制生命周期状态类 */ private PrintLifeCyleStatus(Bound bound){ super(); this.bound = bound; this.setSize(STATUS_WIDTH, STATUS_HEIGHT); this.setToolTipText(bound.name); this.setBorder(lineBorder); this.setBackground(Color.WHITE); } public PrintLifeCyleStatus(Bound bound, Rectangle r){ super(); this.bound = bound; setSize(STATUS_WIDTH, STATUS_HEIGHT); setToolTipText(bound.name); setBorder(lineBorder); setBackground(Color.WHITE); setBounds(r); setLayout(new BorderLayout()); String text = ""; if(bound != null){ text = bound.name; } JLabel textLabel = new JLabel(text); add(textLabel); } /** * 获得状态对象 * @return */ public Bound getBound(){ return bound; } } /** * 用于存储下拉框选项 * @author VCI-STGK006 * */ private class TransitionVOExt { private TransitionVO vo = null; private Bound bound = null; public TransitionVOExt(TransitionVO vo, Bound bound){ this.vo = vo; this.bound = bound; } @Override public String toString(){ if(bound == null){ return ""; } else { String boundLabel = new UIFUtils() .transferLifecycle(bound.name); return boundLabel; } } /** * 获得vo; * @return */ public TransitionVO getTransitionVO(){ return vo; } } /** * 设置窗体居中 * @param window */ public static void setWindowLocation(Window window){ //屏幕大小 int width = Toolkit.getDefaultToolkit().getScreenSize().width; int height = Toolkit.getDefaultToolkit().getScreenSize().height - 20; //窗口大小 int windowWidth = window.getSize().width; int windowHeight = window.getSize().height; //窗口定点位置 int left = (width - windowWidth) / 2; int top = (height - windowHeight) / 2; window.setBounds(left, top, windowWidth, windowHeight); } }