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
package com.vci.client.uif.engine.client;
 
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Frame;
import java.awt.Image;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import javax.swing.JDialog;
 
import com.vci.client.ui.swing.VCISwingUtil;
import com.vci.client.ui.swing.components.VCIJButton;
import com.vci.client.ui.swing.components.VCIJOptionPane;
import com.vci.client.ui.swing.components.VCIJPanel;
import com.vci.client.uif.engine.client.tableArea.TablePanel;
import com.vci.client.uif.engine.client.tree.TreePanel;
 
/**
 * 添加按钮事件中使用的选择窗口
 * @author VCI-STGK006
 *
 */
public class ChooseBusinessObjectDialog extends JDialog {
    
    /**
     * 
     */
    private static final long serialVersionUID = 7337695196482233220L;
 
    /**
     * 图标
     */
    private Image img = VCISwingUtil.createImageIcon("search.png").getImage();
    /**
     * 父窗口
     */
    private Window owner = null;
    /**
     * ui上下文
     */
    private String context = "";
    /**
     * 显示类型
     */
    private String type = "";
    /**
     * 显示中选中类型的oid
     */
    private String oid = "";
    /**
     * UILayoutPanel
     */
    private UILayoutPanel uipl = null;
    /**
     * 是否可以多选
     */
    private boolean multiplechoice = false;
    /**
     * 用户选择数据
     */
    private Object[] selectedDatas = null;
    /**
     * 是确定还是取消
     */
    private boolean isOk = false;
    
    /**
     * 查询选择窗口
     * @param owner
     * @param context ui上下文
     * @param type 显示类型
     * @param multiplechoice 是否可以多选
     * @param oid sourceOID
     */
    public ChooseBusinessObjectDialog(Frame owner, String type, String context, boolean multiplechoice,String oid){
        super(owner, "选择", true);
        this.owner = owner;
        this.context = context;
        this.type = type;
        this.oid = oid;
        this.multiplechoice = multiplechoice;
        init();
    }
    
    private HashMap<String, String> souceMap = null;
    /**
     * 
     * @Title        :
     * @Description    :
     * @param owner
     * @param type
     * @param context
     * @param multiplechoice
     * @param oid
     * @param souceMap   //Add by zhonggy 2015-08 (计价系统提出需求,by xiejun)
     */
    public ChooseBusinessObjectDialog(Frame owner, String type, String context, boolean multiplechoice,String oid,HashMap<String, String> souceMap){
        super(owner, "选择", true);
        this.owner = owner;
        this.context = context;
        this.type = type;
        this.oid = oid;
        this.multiplechoice = multiplechoice;
        this.souceMap = souceMap;
        init();
    }
    
    /**
     * 绘制窗体
     */
    public void init(){
        setIconImage(img);
        setLayout(new BorderLayout());
        add(getCenterDataPanel(), BorderLayout.CENTER);
        add(getSouthButtonPanel(), BorderLayout.SOUTH);
        setSize(UIHelper.DIALOG_DEFAULT_WIDTH, UIHelper.DIALOG_DEFAULT_HEIGHT);
        setLocationRelativeTo(owner);
        setVisible(true);
    }
    
    /**
     * 创建数据区域
     * @return
     */
    private VCIJPanel getCenterDataPanel(){
        VCIJPanel pal = new VCIJPanel(new BorderLayout());
        //HashMap<String, String> map = new HashMap<String, String>();
        if (souceMap == null) {
            souceMap = new HashMap<String, String>();
        }
        souceMap.put(UIHelper.TYPE, type);
        souceMap.put(UIHelper.CONTEXT, context);
        souceMap.put(UIHelper.OID, oid);
        //map.put(UIHelper.OID, map.get(UIHelper.OID));
        // 加入来源参数
        //map.put("fromType", type);
        //map.put("fromContext", context);
        //map.put("fromObjectId", map.get(UIHelper.OID));
 
        UILayoutPanel uipl = getUILayoutPanel(souceMap);
        pal.add(uipl, BorderLayout.CENTER);
        return pal;
    }
    
    private UILayoutPanel getUILayoutPanel(HashMap<String, String> map){
        uipl = new UILayoutPanel(map);
        uipl.setDataValueMap(map);
        uipl.prep();
        uipl.initMainPanel();
        return uipl;
    }
    
    /**
     * 创建按钮区域
     * @return
     */
    private VCIJPanel getSouthButtonPanel(){
        VCIJPanel pal = new VCIJPanel();
        VCIJButton btnOk = VCISwingUtil.createVCIJButton("ok", "确定", "确定", "accept.png");
        VCIJButton btnCancel = VCISwingUtil.createVCIJButton("cancel", "取消", "取消", "cancel.png");
        btnOk.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                ok();
            }
        });
        btnCancel.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                cancel();
            }
        });
        pal.add(btnOk);
        pal.add(btnCancel);
        return pal;
    }
    
    /**
     * 确定事件
     */
    public void ok(){
        Component compt = uipl.getTabPanel();
        Object[] objs = null;
        if(compt instanceof TablePanel){
            TablePanel tablePanel = (TablePanel) compt;
            objs = tablePanel.getTablePanelModel().getSelectObjects();
        }else if(compt instanceof TreePanel){
            TreePanel  panel = (TreePanel ) compt;
            Object obj = panel.getSelectTreeNode().getObj();
            objs=new Object[]{obj};
        }
        if(objs == null || objs.length <= 0) {
            VCIJOptionPane.showError(this, "请先选择数据!");
            return;
        }
        if(!multiplechoice){
            if(objs.length > 1) {
                VCIJOptionPane.showError(this, "一次只能选择一条数据!");
                return;
            }
        }
        this.selectedDatas = objs;
        this.isOk = true;
        this.dispose();
    }
    /**
     * 关闭窗口
     */
    private void cancel(){
        this.dispose();
    }
    
    /**
     * 是否继续执行操作
     * @return
     */
    public boolean isOk(){
        return this.isOk;
    }
    
    /**
     * 得到用户选择的数据
     * @return
     */
    public Object[] getSelectedData(){
        return this.selectedDatas;
    }
}