wangting
2024-09-27 a3e87f78ee262ca9bb7d9b0c997639d5f3295890
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package com.vci.client.uif.actions.client;
 
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;
 
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
 
import com.vci.client.bof.ClientBusinessObject;
import com.vci.client.bof.ClientLinkObject;
import com.vci.client.omd.lifecycle.LifeCycleStart;
import com.vci.client.uif.engine.common.DefaultTableNode;
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;
import com.vci.mw.ClientContextVariable;
 
/**
 * 简化版本跃迁Action
 * @author Administrator
 *
 */
public class SimpleTransferAction extends TransferAction{
 
    @Override
    public String getKey() {
        return "simpletransferaction";
    }
    
    @Override
    public boolean checkHasRight(){
        // 按BO进行数据权限检查
        setDataRightCheckType(RightCheckConstants.RIGHT_CHECK_TYPE_B);
        return super.checkHasRight();
    }
 
    @Override
    public boolean doPost() {
        ClientBusinessObject cbo = getClientBusinessObject();
        if(cbo == null) return false;
 
        Component btnCompt = getButtonComponent();
        JPopupMenu pm = getPopupMenu(cbo);
        pm.show(btnCompt, btnCompt.getWidth() / 2, btnCompt.getY() + btnCompt.getHeight() / 2);
        
        return false;
    }
 
    private ClientBusinessObject getClientBusinessObject(){
        Object[] objs = getDataModel().getSelectObjects();
        DefaultTableNode dtn = (DefaultTableNode) objs[0];
        ClientBusinessObject cbo = null;
        //判断主对象类型
        if(dtn.getMaterObject() instanceof ClientBusinessObject){
            //如果是业务类型
            cbo = (ClientBusinessObject) dtn.getMaterObject();
            if(cbo == null){
                UIFUtils.showMessage(ClientContextVariable.getFrame(), 
                        "uifmodel.plm.uif.actions.notexistmsg", 
                        this.getParameterValue(ValueType.RuntimeData, "t_oid.name", 0));
                return null;
            }
        } else if (dtn.getMaterObject() instanceof ClientLinkObject){
            //如果是link类型
            String oid = this.getParameterValue(ValueType.RuntimeData, "t_oid", 0);
            String btmName = this.getParameterValue(ValueType.RuntimeData, "t_btwname", 0);
            //如果操作所需参数不存在则直接停止操作
            if(oid == null || oid.equals("") ||btmName == null || btmName.equals("")){
                UIFUtils.showMessage(ClientContextVariable.getFrame(),
                        "uifmodel.plm.uif.actions.syserror.parmerror.bo");
                return null;
            }
            //需要重新下载cbo对象
            cbo = operation
                    .reloadClientBusinessObject(ClientContextVariable.getFrame(), oid, btmName);
            System.out.println("** TS:" + cbo.getBusinessObject().ts);
            //对象不存在或者已经被删除
            if(cbo.getBusinessObject().oid == null || cbo.getBusinessObject().oid.equals("")){
                UIFUtils.showMessage(ClientContextVariable.getFrame(), 
                        "uifmodel.plm.uif.actions.notexistmsg", 
                        this.getParameterValue(ValueType.RuntimeData, "t_oid.name", 0));
                return null;
            }                
        }
        return cbo;
    }
    
    private JPopupMenu getPopupMenu(ClientBusinessObject cbo){
        LifeCycle lc = getBOLC(cbo);
        TransitionVO[] tvos = getNextLCStatus(lc, cbo);
        
        JPopupMenu pm = new JPopupMenu();
        int height = 10;
        
        for(TransitionVO tvo : tvos){
            JMenuItemExt mi = getTransMenuItem(tvo, cbo);
            pm.add(mi);
            height += 25;
        }
        pm.setPopupSize(100, height);
        return pm;
    }
    
    private JMenuItemExt getTransMenuItem(TransitionVO tvo, ClientBusinessObject cbo){
        JMenuItemExt mi = new JMenuItemExt(tvo, cbo);
        mi.setActionCommand(tvo.destination);
        mi.setText(tvo.destination);
        mi.addActionListener(new TransitionActionListener());
        return mi;
    }
    
    private class TransitionActionListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            transitionMenuItem_actionPerformed(e);
        }
    }
    
    private void transitionMenuItem_actionPerformed(ActionEvent e){
        if(e.getSource() instanceof JMenuItemExt){
            JMenuItemExt mi = (JMenuItemExt)e.getSource();
            TransitionVO tvo = mi.getTvo();
            ClientBusinessObject cbo = mi.getCbo();
            if(tvo == null) return;
            if(cbo == null) return;
            
            boolean res = operation.transferBusinessObject(
                     ClientContextVariable.getFrame(), cbo, tvo);
            if(res){
                afterPostAfterRefresh();
            }
        }
    }
    
    private class JMenuItemExt extends JMenuItem {
        /**
         * 
         */
        private static final long serialVersionUID = 5153288169687055569L;
        private TransitionVO tvo = null;
        private ClientBusinessObject cbo = null;
        public JMenuItemExt(TransitionVO tvo, ClientBusinessObject cbo){
            this.tvo = tvo;
            this.cbo = cbo;
        }
        public TransitionVO getTvo(){
            return tvo;
        }
        public ClientBusinessObject getCbo(){
            return cbo;
        }
    }
    
    private LifeCycle getBOLC(ClientBusinessObject cbo){
        LifeCycle res = null;
        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)){
                    res = lc;
                    break;
                }
            }
        } catch (VCIError e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return res;
    }
    
    private TransitionVO[] getNextLCStatus(LifeCycle lc, ClientBusinessObject cbo){
        LinkedList<TransitionVO> list = new LinkedList<TransitionVO>();
        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)){
                            list.add(route);
                        }
                    }
                }
            }
        }
        return list.toArray(new TransitionVO[]{});
    }
}