ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
package com.vci.client.oq.ui.linkqtexport;
 
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.filechooser.FileFilter;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
 
import com.vci.client.LogonApplication;
import com.vci.client.common.providers.ServiceProvider;
import com.vci.client.omd.linktype.LinkTypeStart;
import com.vci.client.oq.QTClient;
import com.vci.client.oq.QTDClient;
import com.vci.client.portal.UI.dialog.VCIGuideStepPanel;
import com.vci.client.ui.swing.components.VCIJOptionPane;
import com.vci.corba.omd.qtm.QTInfo;
/**
 * Action导出步骤1界面
 * @Title        :ExpActionStep1Panel.java
 * @Description    : 
 * @Copyright    :宏博远达科技有限公司
 * @Author        :平台与规划部/ZhongGY/E-mail:zhonggy@vci-tech.com
 * @Date        :2015-6-5
 * @Version        :1
 * @Other        :产生注释:Alt+Shift+J
 */
public class LinkQTExpQTStep1Panel extends VCIGuideStepPanel {
    
    private static final long serialVersionUID = 1L;
    
    private LinkQTExportTree exportTree ;
    private JTextField txtDirectory;
    private JButton btnSelDirectory;
    private String exportFilePath = "c"+File.pathSeparator;
    private JScrollPane scrollPane = new JScrollPane();
    public LinkQTExpQTStep1Panel() {
        
        GridBagLayout gridBagLayout = new GridBagLayout();
        gridBagLayout.columnWidths = new int[]{0, 0, 0, 0};
        gridBagLayout.rowHeights = new int[]{0, 30, 0};
        gridBagLayout.columnWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE};
        gridBagLayout.rowWeights = new double[]{1.0, 0.0, Double.MIN_VALUE};
        setLayout(gridBagLayout);
 
        
        JLabel label_2 = new JLabel(" ");
        GridBagConstraints gbc_label_2 = new GridBagConstraints();
        gbc_label_2.insets = new Insets(0, 0, 5, 5);
        gbc_label_2.gridx = 0;
        gbc_label_2.gridy = 0;
        add(label_2, gbc_label_2);
        
//        JScrollPane scrollPane = new JScrollPane();
        GridBagConstraints gbc_scrollPane = new GridBagConstraints();
        gbc_scrollPane.fill = GridBagConstraints.BOTH;
        gbc_scrollPane.insets = new Insets(0, 0, 5, 5);
        gbc_scrollPane.gridx = 1;
        gbc_scrollPane.gridy = 0;
        add(scrollPane, gbc_scrollPane);
    
        
        JLabel label = new JLabel(" ");
        GridBagConstraints gbc_label = new GridBagConstraints();
        gbc_label.insets = new Insets(0, 0, 5, 0);
        gbc_label.gridx = 2;
        gbc_label.gridy = 0;
        add(label, gbc_label);
        
        JPanel panel = new JPanel();
        GridBagConstraints gbc_panel = new GridBagConstraints();
        gbc_panel.insets = new Insets(0, 0, 0, 5);
        gbc_panel.fill = GridBagConstraints.BOTH;
        gbc_panel.gridx = 1;
        gbc_panel.gridy = 1;
        add(panel, gbc_panel);
        GridBagLayout gbl_panel = new GridBagLayout();
        gbl_panel.columnWidths = new int[]{0, 0, 0, 0};
        gbl_panel.rowHeights = new int[]{0, 0};
        gbl_panel.columnWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE};
        gbl_panel.rowWeights = new double[]{0.0, Double.MIN_VALUE};
        panel.setLayout(gbl_panel);
        
        JLabel label_3 = new JLabel("导出目录:");
        GridBagConstraints gbc_label_3 = new GridBagConstraints();
        gbc_label_3.insets = new Insets(0, 0, 0, 5);
        gbc_label_3.anchor = GridBagConstraints.EAST;
        gbc_label_3.gridx = 0;
        gbc_label_3.gridy = 0;
        panel.add(label_3, gbc_label_3);
        
        txtDirectory = new JTextField();
        txtDirectory.setForeground(Color.BLACK);
        txtDirectory.setText("请选择导出目录...");
        txtDirectory.setEditable(false);
        txtDirectory.setBackground(SystemColor.control);
        GridBagConstraints gbc_txtDirectory = new GridBagConstraints();
        gbc_txtDirectory.insets = new Insets(0, 0, 0, 5);
        gbc_txtDirectory.fill = GridBagConstraints.HORIZONTAL;
        gbc_txtDirectory.gridx = 1;
        gbc_txtDirectory.gridy = 0;
        panel.add(txtDirectory, gbc_txtDirectory);
        txtDirectory.setColumns(10);
        
        btnSelDirectory = new JButton("...");
        btnSelDirectory.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                LinkQTExpQTStep1Panel.this.selectDirectory(e);
            }
        });
        GridBagConstraints gbc_btnSelDirectory = new GridBagConstraints();
        gbc_btnSelDirectory.anchor = GridBagConstraints.EAST;
        gbc_btnSelDirectory.gridx = 2;
        gbc_btnSelDirectory.gridy = 0;
        panel.add(btnSelDirectory, gbc_btnSelDirectory);
    }
 
    /**
     * 选择目录
     * @Title        :selectDirectory
     * @Description    :
     * @param e
     */
    public void selectDirectory(ActionEvent e) {
        //TODO:给txtDirectory赋值
        this.openFileChoser();
    }
    
    @Override
    public void initUI() {        
        Object shareTreeData = getGuidCommonShareData().get("exportTree");
        if(shareTreeData!=null){
            shareTreeData = null;
        }
        if (shareTreeData == null || !(shareTreeData instanceof LinkQTExportTree)) {
            exportTree = new LinkQTExportTree(); 
            getGuidCommonShareData().put("exportTree", exportTree);
            scrollPane.setViewportView(exportTree);
            exportTree.init();
        }
        initData();
    }
    
    @Override
    //执行“导出”树的初始化,并添加到scrollPane中
    public void initData() {
    }
 
    private void openFileChoser() {
        JFileChooser jf = new JFileChooser();
        jf.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        jf.removeChoosableFileFilter(jf.getFileFilter());
        jf.setFileFilter(new FileFilter() {
            public String getDescription() {
                return "文件夹";
            }
            public boolean accept(File f) {
                return (f.isDirectory());
            }
        });
        jf.setDialogTitle("选择导出目录");
        int showOpenDialog = jf.showOpenDialog(LogonApplication.frame);
        if (showOpenDialog == JFileChooser.APPROVE_OPTION) {
            File selectedFile = jf.getSelectedFile();
             exportFilePath = selectedFile.getAbsolutePath();
             this.getGuidCommonShareData().put("exportFilePath", exportFilePath);
             txtDirectory.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 12));
             txtDirectory.setForeground(Color.black);
             txtDirectory.setText(exportFilePath);
        }
    }
    @Override
    public String getStepName() {
/*        String firstStepName = null;
        if((firstStepName = (String)this.getCommonMap().get("firstStepName") )!= null){
            return firstStepName;
        }*/
        return "第一步:导出选择";
    }
 
    @Override
    public boolean isPreBtnVisible() {
        //第一步没有“上一步”
        return false;
    }
 
    @Override
    public String getPreBtnText() {
        return null;
    }
 
    @Override
    public boolean doPreBtnAction() {
        return false;
    }
 
    @Override
    public boolean isNextBtnVisible() {
        return true;
    }
 
    @Override
    public String getNextBtnText() {
        return "导出";
    }
    
    @Override
    public boolean doNextBtnAction() {
        // 判断当前是否选择正确(如果没有正确选择到模板那么直接提示并终止下一步)
        try {
            if (exportTree == null) {
                //TODO:提示
                VCIJOptionPane.showMessage(this, "树不存在!");
                return false;
            }
            TreePath[] selecPaths = exportTree.getSelectionPaths();
            Map<String/*查询模板名称*/, QTInfo/*查询模板对象*/> allQTs = new HashMap<String, QTInfo>();
            if (selecPaths == null || selecPaths.length ==0) {
                //TODO:提示
                VCIJOptionPane.showMessage(this, "您没有选择数据!");
                return false;
            } else {
                List<Object[]> selectedQTs = new ArrayList<Object[]>();
                // 判断selecPaths中是否存在查询模板,不存在也直接提示并退出
                TreePath[] treePath = ((LinkQTExportTree) exportTree)
                        .getTreeManager().getSelectionModel()
                        .getSelectionPaths();
                // 循环填充列表数据
                if (treePath != null) {
                    try {
                        int index = 1;
                        for (int i = 0; i < treePath.length; i++) {
                            DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath[i]
                                    .getLastPathComponent();
                            Object obj = node.getUserObject();
                            if (obj instanceof String) {// 如果是root节点,则保存所有模块 返回
                                String nodeName = (String) obj;
                                if ("业务类型".equals(nodeName)) {
                                    QTInfo[] qts = ServiceProvider.getOMDService().getQTDService().getAllQTs();
                                    List<QTInfo> list = new ArrayList<QTInfo>();
                                    for (QTInfo qtWrapper : qts) {
                                        if (!LinkTypeStart.getService().getLinkType(qtWrapper.btmName).oid.equals("")) {                                    
                                            list.add(qtWrapper);
                                        } ;
                                    }
                                    qts = list.toArray(new QTInfo[list.size()]);
                                    for (QTInfo qtWrapper : qts) {
                                        Object obj2[] = { "", "", "", "" };
                                        obj2[0] = index;
                                        obj2[1] = "成功";
                                        obj2[2] = qtWrapper.qtName;
                                        obj2[3] = qtWrapper.btmName;
                                        /* tblModel.addRow(obj2); */
                                        selectedQTs.add(obj2);
                                        allQTs.put(qtWrapper.qtName, qtWrapper);
                                        index++;
                                    }
 
                                }
                            }
 
                            if (obj instanceof LinkQTExportQTNode) {
                                // 递归所有父节点添加到exportBeans中
                                Object obj2[] = { "", "", "", "" };
                                obj2[0] = index;
                                obj2[1] = "成功";
                                obj2[2] = ((LinkQTExportQTNode) obj).getBean().qtName;
                                obj2[3] = ((LinkQTExportQTNode) obj).getBean().btmName;
                                /* tblModel.addRow(obj2); */
                                selectedQTs.add(obj2);
                                allQTs.put(((LinkQTExportQTNode) obj).getBean().qtName, ((LinkQTExportQTNode) obj).getBean());
                                index++;
                                // this.tableLog.addRow(bean.getLogRowObjcets());
 
                            } else if (obj instanceof LinkQTExportBTMNode) {
                                if(node.isLeaf()){
                                    continue;
                                }
                                qtwrappers.clear();
                                List<LinkQTExportQTNode> qts2 = getQtwrapper(node);
                                LinkQTExportQTNode[] qts = qts2.toArray(new LinkQTExportQTNode[qts2.size()]);
                                /*QTInfo[] qtWrappers = QTClient.getService()
                                        .getQTS(((QTExportBTMNode) obj)
                                                .getBean().name);*/
                                /*for (QTInfo qtWrapper : qtWrappers) {
                                    Object obj2[] = { "", "", "", "" };
                                    obj2[0] = index;
                                    obj2[1] = "成功";
                                    obj2[2] = qtWrapper.qtName;
                                    obj2[3] = qtWrapper.btmName;
                                    allQTs.put(qtWrapper.qtName, qtWrapper);
                                     tblModel.addRow(obj2); 
                                    selectedQTs.add(obj2);
                                    index++;
                                }*/
                                for (LinkQTExportQTNode qtWrapper : qts) {
                                    Object obj2[] = { "", "", "", "" };
                                    obj2[0] = index;
                                    obj2[1] = "成功";
                                    obj2[2] = qtWrapper.getBean().qtName;
                                    obj2[3] = qtWrapper.getBean().btmName;
                                    allQTs.put(qtWrapper.getBean().qtName, qtWrapper.getBean());
                                    /*tblModel.addRow(obj2);*/ 
                                    selectedQTs.add(obj2);                                    
                                    index++;
                                }
                            }
 
                        }
 
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                if(selectedQTs.size()==0){
                    //TODO:提示
                    VCIJOptionPane.showMessage(this, "您没有选择查询模版!");
                    return false;
                }
                this.getGuidCommonShareData().put("selectedQTs",selectedQTs);
            }
            String exportFilePath = (String)this.getGuidCommonShareData().get("exportFilePath");
            if (exportFilePath == null || exportFilePath.trim().equals("")) {
                //TODO:提示
                VCIJOptionPane.showMessage(this, "您没有选择导出目录!");
                return false;
            }
            LinkQTExportData exportData = new LinkQTExportData();
            exportData.setAllQTs(allQTs);
            /*if(!exportData.initData(this.getCommonMap())){
                //TODO:提示
                return false;
            }*/
            this.getGuidCommonShareData().put("exportData", exportData);        //刷新导出数据
            VCIGuideStepPanel nextStepUI = getNextStepUI(); 
            nextStepUI.initUI();
            return true;
        } catch (Throwable e) {
            //TODO:提示
            return false;
        }
    }
    List<LinkQTExportQTNode> qtwrappers = new ArrayList<LinkQTExportQTNode>();
    //选择根节点时递归寻找查询模板对象
    private List<LinkQTExportQTNode> getQtwrapper(DefaultMutableTreeNode node) {
        // TODO Auto-generated method stub
        @SuppressWarnings("unchecked")
        Enumeration<DefaultMutableTreeNode> enumeration = node.children();
        while(enumeration.hasMoreElements()){
            DefaultMutableTreeNode defaultMutableTreeNode = enumeration.nextElement();
            if(!defaultMutableTreeNode.isLeaf()){
                getQtwrapper(defaultMutableTreeNode);            
            }else{
                qtwrappers.add((((LinkQTExportQTNode)(defaultMutableTreeNode.getUserObject()))));
            }
        }
        return qtwrappers;
    }
 
    @Override
    public boolean isCancelBtnVisible() {
        return true;
    }
 
    @Override
    public String getcancelBtnText() {
        return "取消";
    }
 
    String dialogProcess = "";    //[第X步/共X步]
    public String getDialogProcess() {
        dialogProcess = "[第1步/共2步]";
        return dialogProcess;
    }
    
    public VCIGuideStepPanel getNextStepUI() {
        if (super.getNextStepUI() == null) {
            VCIGuideStepPanel nextStepUI = new LinkQTExpQTStep2Panel();
            nextStepUI.setPreStepUI(this);
            nextStepUI.setOwnParent(this.getOwnParent());
            super.setNextStepUI(nextStepUI);
        }
        
        return super.getNextStepUI() ;
    }
}