ludc
2024-09-14 36c2449aec5b51e5ed4e5c6841154b746060e09a
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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
package com.vci.client.portal.UI;
 
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
 
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.EmptyBorder;
import javax.swing.filechooser.FileFilter;
import javax.swing.tree.TreePath;
 
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 
import com.vci.client.LogonApplication;
import com.vci.client.framework.rightConfig.modelConfig.ModuleTreeCellRenderer;
import com.vci.client.portal.utility.UITools;
import com.vci.client.ui.swing.VCIOptionPane;
import com.vci.client.ui.tree.CheckBoxTreeManager;
import com.vci.client.ui.tree.VCIBaseTree;
import com.vci.client.ui.tree.VCIBaseTreeModel;
import com.vci.client.ui.tree.VCIBaseTreeNode;
import com.vci.corba.common.VCIError;
import com.vci.corba.omd.btm.BtmItem;
import com.vci.corba.portal.data.PLAction;
import com.vci.corba.portal.data.PLCommandParameter;
import com.vci.corba.portal.data.PLPageDefination;
import com.vci.corba.portal.data.PLUILayout;
import com.vci.corba.portal.data.PLTabButton;
import com.vci.corba.portal.data.PLTabPage;
 
public class ExpDialog extends JDialog {
 
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
 
    private final JPanel contentPanel = new JPanel();
 
    private VCIBaseTree tree;
    private VCIBaseTreeModel treeModel;
    private CheckBoxTreeManager treeManager;
    private VCIBaseTreeNode rootNode;
    private JScrollPane scrollPane ;
 
    private BtmItem btmItem;
    private PLUILayout[] expDatas = null;
 
    private String btname;
    
    private String plpageLayoutDefinationId= "";
    List<String> nodeList = new ArrayList<String>();
    
    HSSFWorkbook workbook;
    HSSFSheet sheet_pagelayoutdefination;
    HSSFSheet sheet_pagedefination;
    HSSFSheet sheet_tabpage;
    HSSFSheet sheet_tabbutton;
    HSSFSheet sheet_commondParam;
    int pageLayoutDefinationindex = 0;
    int tabpageIndex = 0;
    int pagedefinationIndex = 0;
    int tabbuttonIndex = 0;
    int commondParamIndex = 0;
    
    private String xfileName = "";
    /**
     * Create the dialog.
     */
    public ExpDialog(BtmItem btmItem, PLUILayout[] expDatas) {
        super(LogonApplication.frame,true);
        this.btmItem = btmItem;
        this.expDatas = expDatas;
        init();
        initTreeNode();
        this.setLocationRelativeTo(null);
    }
 
    private void init() {
        setBounds(100, 100, 450, 300);
        getContentPane().setLayout(new BorderLayout());
        contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
        getContentPane().add(contentPanel, BorderLayout.CENTER);
        contentPanel.setLayout(new BorderLayout(0, 0));
        {
            scrollPane = new JScrollPane();
            contentPanel.add(scrollPane, BorderLayout.CENTER);
        }
        {
            JPanel buttonPane = new JPanel();
            buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
            getContentPane().add(buttonPane, BorderLayout.SOUTH);
            {
                JButton okButton = new JButton("确定");
                okButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent arg0) {
                        TreePath[] treePath = treeManager.getSelectionModel().getSelectionPaths();
                        openFileChoser();
                        if (treePath != null) {
                            pageLayoutDefinationindex = 0;
                            tabpageIndex = 0;
                            pagedefinationIndex = 0;
                            tabbuttonIndex = 0;
                            commondParamIndex = 0;
                            for(int i = 0;i < treePath.length;i++){
                                VCIBaseTreeNode node = (VCIBaseTreeNode)treePath[i].getLastPathComponent();
                                Object obj = node.getObj();
                                if(obj instanceof String){//如果是root节点,则保存所有模块
                                    getNextNode(node,false);//向下获取所有几点
                                }else if(obj instanceof PLUILayout){
                                    getNextNode(node,false);//向下处理(包含当前节点)
                                }else if (obj instanceof PLTabPage){
                                    getNextNode(node,true);
                                    savePlpageLayoutDefinationRelation(obj);
                                }
                            }
                        }else{
                            VCIOptionPane.showMessage(LogonApplication.frame, "请选择要导出的节点!");
                            return;
                        }
                        if(writeFile()){
                            VCIOptionPane.showMessage(LogonApplication.frame, "导出成功");
                            dispose();
                        }
                    }
                });
                buttonPane.add(okButton);
                getRootPane().setDefaultButton(okButton);
            }
            {
                JButton cancelButton = new JButton("关闭");
                cancelButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent arg0) {
                        dispose();
                    }
                });
                buttonPane.add(cancelButton);
            }
        }
        workbook = new HSSFWorkbook();
        sheet_pagelayoutdefination = workbook.createSheet();
        workbook.setSheetName(0, "PlpageLayoutDefnation");
        
        sheet_tabpage = workbook.createSheet();
        workbook.setSheetName(1, "Pltabpage");
        
        sheet_pagedefination = workbook.createSheet();
        workbook.setSheetName(2, "Plpagedefination");
        
        sheet_tabbutton = workbook.createSheet();
        workbook.setSheetName(3, "Pltabbutton");
        
        sheet_commondParam = workbook.createSheet();
        workbook.setSheetName(4, "PlcommondParam");
    }
 
    
    public void initTreeNode(){
        rootNode = new VCIBaseTreeNode("区域", "root");
        treeModel = new VCIBaseTreeModel(rootNode);
        tree = new VCIBaseTree(treeModel, new ModuleTreeCellRenderer());
        
        btname = btmItem.name;
        try {
            PLUILayout[] plpagelayoutdefinations = expDatas;
            for(int i=0;i<plpagelayoutdefinations.length;i++){
                VCIBaseTreeNode treeNode = new VCIBaseTreeNode(plpagelayoutdefinations[i].plName, plpagelayoutdefinations[i]);
                treeModel.insertNodeInto(treeNode, rootNode,rootNode.getChildCount());
                insertNode(plpagelayoutdefinations, i, treeNode, (short)1);
                insertNode(plpagelayoutdefinations, i, treeNode, (short)2);
                insertNode(plpagelayoutdefinations, i, treeNode, (short)3);
 
                tree.expandPath(new TreePath(treeNode.getPath()));
            }
        } catch (VCIError e) {
            e.printStackTrace();
        }
        tree.setModel(treeModel);
        treeManager = new CheckBoxTreeManager(tree);
        scrollPane.getViewport().removeAll();
        scrollPane.setViewportView(tree);
        scrollPane.repaint();
        tree.expandPath(new TreePath(rootNode.getPath()));
    }
 
    private PLTabPage[] insertNode(
            PLUILayout[] plpagelayoutdefinations, int i,
            VCIBaseTreeNode treeNode, short disType) throws VCIError {
        PLTabPage[] o = UITools.getService().getTabPagesByContextIdAndType(plpagelayoutdefinations[i].plOId, disType);
        for(int j=0;j<o.length;j++){
            VCIBaseTreeNode areaNode = new VCIBaseTreeNode(o[j].plName, o[j]);
            areaNode.setExpand(true);
            areaNode.setLeaf(true);
            treeModel.insertNodeInto(areaNode, treeNode,treeNode.getChildCount());
        }
        return o;
    }
    
    private void getNextNode(VCIBaseTreeNode node,boolean isUp){
        if(isUp){//向上获取,存储每个上级模块的权限值
            VCIBaseTreeNode parentNode = (VCIBaseTreeNode)node.getParent();
            while(!"root".equals(parentNode.getObj())){
                Object obj = parentNode.getObj();
                Object userObject = parentNode.getUserObject();
                if(!nodeList.contains((String)userObject)){
                    nodeList.add((String)userObject);
                    savePlpageLayoutDefnation(obj);
                }
                parentNode = (VCIBaseTreeNode)parentNode.getParent();
            }
        }else{//向下获取,无需判断是否选中,但需要判断其子级是否是操作
            //先存储当前节点
            Object obj = node.getObj();
            if(obj instanceof PLUILayout){
                savePlpageLayoutDefnation(obj);
            }else if(obj instanceof PLTabPage){
                savePlpageLayoutDefinationRelation(obj);
            }
            for(int i = 0;i < node.getChildCount();i++){
                //对每个子向下递归遍历
                getNextNode((VCIBaseTreeNode)node.getChildAt(i),false);
            }
        }
    }
 
    private void savePlpageLayoutDefnation(Object object) {
        PLUILayout obj = (PLUILayout)object;
        plpageLayoutDefinationId = obj.plOId;
//        try {
            HSSFRow row = sheet_pagelayoutdefination.createRow(pageLayoutDefinationindex++);
            HSSFCell cell = row.createCell(0);
            cell.setCellValue(obj.plName);
            cell = row.createCell(1);
            cell.setCellValue(obj.plCode);
            cell = row.createCell(2);
            cell.setCellValue(obj.plOId);
            cell = row.createCell(3);
            cell.setCellValue(btname);
            cell = row.createCell(4);
            cell.setCellValue(obj.plRelatedType);
            cell = row.createCell(5);
            cell.setCellValue(obj.plIsShowNavigator);
            cell = row.createCell(6);
            cell.setCellValue(obj.plIsShowTab);
            cell = row.createCell(7);
            cell.setCellValue(obj.plIsShowForm);
//            Tool.getService().savePLUILayout(obj);
//        } catch (VCIError e) {
//            e.printStackTrace();
//        }
    }
    
    private void savePlpageLayoutDefinationRelation(Object obj) {
        PLTabPage pt = (PLTabPage)obj;
        pt.plContextOId = plpageLayoutDefinationId;
        HSSFRow row = sheet_tabpage.createRow(tabpageIndex++);
        HSSFCell cell = row.createCell(0);
        cell.setCellValue(pt.plName);
        cell = row.createCell(1);
        cell.setCellValue(pt.plCode);
        cell = row.createCell(2);
        cell.setCellValue(pt.plSeq);
        cell = row.createCell(3);
        cell.setCellValue(pt.plContextOId);
        cell = row.createCell(4);
        cell.setCellValue(pt.plDesc);
        cell = row.createCell(5);
        cell.setCellValue(pt.plIsOpen);
        cell = row.createCell(6);
        cell.setCellValue(pt.plAreaType);
        cell = row.createCell(7);
        cell.setCellValue(pt.plOpenExpression);
        cell = row.createCell(8);
        cell.setCellValue(pt.plLicensOrs);
        cell = row.createCell(9);
        cell.setCellValue(pt.plLabel);
        cell = row.createCell(10);
        cell.setCellValue(pt.plOId);
        try {
            
            PLPageDefination[] pLPageDefinations = UITools.getService().getPLPageDefinationsByPageContextOId(
                pt.plOId);
            
            for(int j=0;j<pLPageDefinations.length;j++){
                PLPageDefination plPageDefination = pLPageDefinations[j];
                
                plPageDefination.plTabPageOId = pt.plOId;
                HSSFRow row1 = sheet_pagedefination.createRow(j+pagedefinationIndex);
                HSSFCell cell1 = row1.createCell(0);
                cell1.setCellValue(plPageDefination.name);
                cell1 = row1.createCell(1);
                cell1.setCellValue(plPageDefination.plDefination);
                cell1 = row1.createCell(2);
                cell1.setCellValue(plPageDefination.seq);
                cell1 = row1.createCell(3);
                cell1.setCellValue(plPageDefination.plTabPageOId);
                cell1 = row1.createCell(4);
                cell1.setCellValue(plPageDefination.desc);
                cell1 = row1.createCell(5);
                cell1.setCellValue(plPageDefination.plType);
                cell1 = row1.createCell(6);
                cell1.setCellValue(plPageDefination.plOId);
                
                PLTabButton[] pLTabButtons = UITools.getService().getPLTabButtonsByTableOId(plPageDefination.plOId);
                for(int b=0;b<pLTabButtons.length;b++){
                    PLTabButton plTabButton = pLTabButtons[b];
                    plTabButton.plTableOId = plPageDefination.plOId;
                    HSSFRow row2 = sheet_tabbutton.createRow(b+tabbuttonIndex);
                    HSSFCell cell2 = row2.createCell(0);
                    cell2.setCellValue(plTabButton.plLabel);
                    cell2 = row2.createCell(1);
                    cell2.setCellValue(plTabButton.plAreaType);
                    cell2 = row2.createCell(2);
                    cell2.setCellValue(plTabButton.plTableOId);
                    cell2 = row2.createCell(3);
                    cell2.setCellValue(plTabButton.plSeq);
                    cell2 = row2.createCell(4);
                    PLAction plAction = UITools.getService().getPLActionById(plTabButton.plActionOId);
                    cell2.setCellValue(plAction.plCode);
                    cell2 = row2.createCell(5);
                    cell2.setCellValue(plTabButton.plAreaType);
                    cell2 = row2.createCell(6);
                    cell2.setCellValue(plTabButton.plDesc);
                    cell2 = row2.createCell(7);
                    cell2.setCellValue(plTabButton.plOId);
                    cell2 = row2.createCell(8);//层级关系
                    cell2.setCellValue(plTabButton.plParentOid);
                    cell2 = row2.createCell(9);
                    cell2.setCellValue(plTabButton.displayMode);
                    cell2 = row2.createCell(10);
                    cell2.setCellValue(plTabButton.iconPath);
                    cell2 = row2.createCell(11);
                    cell2.setCellValue(plTabButton.authorization);
                    cell2 = row2.createCell(12);
                    cell2.setCellValue(plTabButton.show);
                    PLCommandParameter[] pLCommandParameters = UITools.getService().getPLCommandParametersByCommandOId(plTabButton.plOId);
                    for(int c=0;c<pLCommandParameters.length;c++){
                        PLCommandParameter plCommandParameter = pLCommandParameters[c];
                        plCommandParameter.plCommandOId = plTabButton.plOId;
                        HSSFRow row3 = sheet_commondParam.createRow(c+commondParamIndex);
                        HSSFCell cell3 = row3.createCell(0);
                        cell3.setCellValue(plCommandParameter.plCommandOId);
                        cell3 = row3.createCell(1);
                        cell3.setCellValue(plCommandParameter.plKey);
                        cell3 = row3.createCell(2);
                        cell3.setCellValue(plCommandParameter.plValue);
                        cell3 = row3.createCell(3);
                        cell3.setCellValue(plCommandParameter.plOId);
                    }
                    if(pLCommandParameters.length>0){
                        commondParamIndex += pLCommandParameters.length;
                    }
                }
                tabbuttonIndex += pLTabButtons.length;
            }
            pagedefinationIndex += pLPageDefinations.length;
        } catch (VCIError e) {
            e.printStackTrace();
        }
    }
    
    private void openFileChoser(){
        JFileChooser jf = new JFileChooser();
        jf.setDialogTitle("打开");
        jf.removeChoosableFileFilter(jf.getFileFilter());
        jf.setFileFilter(new FileFilter() {
            
            @Override
            public String getDescription() {
                return "xls";
            }
            
            @Override
            public boolean accept(File f) {
                if(f.isDirectory()||f.getName().endsWith(".xls")){
                    return true;
                }else{
                    return false;
                }
            }
        });
        int showOpenDialog = jf.showOpenDialog(LogonApplication.frame);
        if (showOpenDialog == JFileChooser.APPROVE_OPTION) {
            File file = jf.getSelectedFile();
            xfileName = file.getAbsolutePath();
            if(!xfileName.endsWith(".xls")){
                xfileName = xfileName+".xls";
            }
        }
    }
    
    private boolean writeFile(){
        try {
            FileOutputStream fout = new FileOutputStream(xfileName);
            workbook.write(fout);
            fout.flush();
            fout.close();
            System.out.println("文件生成.....");
            return true;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return false;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }
}