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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
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<TransitionVOExt> statusList = new Vector<TransitionVOExt>();
    
    /**
     * 业务对象生命周期
     */
    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);
    }
}