wangting
2024-12-26 fa261e8c1220b31af54e8167e4de9c3320b1af27
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
package com.vci.client.framework.specialrole;
 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
 
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.border.EmptyBorder;
import javax.swing.event.TreeExpansionEvent;
import javax.swing.event.TreeExpansionListener;
import javax.swing.tree.TreePath;
 
import com.vci.client.LogonApplication;
import com.vci.client.common.objects.DeptObject;
import com.vci.client.common.objects.UserObject;
import com.vci.client.framework.delegate.RightManagementClientDelegate;
import com.vci.client.framework.systemConfig.stafforgmanage.DeptInfoTreeTableCellRender;
import com.vci.client.framework.systemConfig.stafforgmanage.PLDeptInfoDataTreeModel;
import com.vci.client.logon.base.BaseJDialog;
import com.vci.client.ui.exception.VCIException;
import com.vci.client.ui.locale.LocaleDisplay;
import com.vci.client.ui.swing.VCIOptionPane;
import com.vci.client.ui.treeTable.InterfaceTreeTableModel;
import com.vci.client.ui.treeTable.JTreeTable;
import com.vci.client.ui.treeTable.TreeTableModel;
 
/**
 * <p>Title: DeptingDialog</p>
 * <p>Description:为人员分配部门 </p>
 * <p>Copyright: Copyright (c) 2012</p>
 * <p>Company: VCI</p>
 * @author wangxl
 * @time 2012-5-13
 * @version 1.0
 */
public class DeptingTreeDialog extends BaseJDialog{
 
    private static final long serialVersionUID = 1L;
    private JButton conformBut = new JButton(LocaleDisplay.getI18nString("rmip.stafforg.operate.conform", "RMIPFramework", getLocale()));
    private JButton cancelBut = new JButton(LocaleDisplay.getI18nString("rmip.stafforg.operate.cancel", "RMIPFramework", getLocale()));
    private UserTablePanel userPanel;
    private List<UserObject> userList;
    
    private boolean fromManualExpand = false;
//    private boolean fromManualSelectedTreeNode = false;
    private String[] columns = {"名称","编号","代号","描述"};
    DeptObject rootObj;
    private Class[] classes = {InterfaceTreeTableModel.class,String.class,String.class,String.class} ;
    private PLDeptInfoDataTreeModel treeTableModel = null;
    private Object transObject = "";
    private JTreeTable treeTable = null;
    private TreeTableModel.TreeTableNode rootNode = null;
    
    private DeptObject deptObj = null;
    
    private String type = "0";
    public boolean isgetDatas = false;
    public boolean isIsgetDatas() {
        return isgetDatas;
    }
    public void setIsgetDatas(boolean isgetDatas) {
        this.isgetDatas = isgetDatas;
    }
 
    public List<DeptObject> deptList = new ArrayList<DeptObject>();
    public List<DeptObject> getDeptList() {
        return deptList;
    }
    public void setDeptList(List<DeptObject> deptList) {
        this.deptList = deptList;
    }
 
    public DeptingTreeDialog(UserTablePanel userPanel ,List<UserObject> userList){
        super(LogonApplication.frame);
        this.userList = userList;
        this.userPanel = userPanel;
        this.setModal(true);
        init();
    }
    
    public DeptingTreeDialog(String type) {
        super(LogonApplication.frame);
        this.type = type;
        this.setModal(true);
        init();
    }
     
    
    /**
     * 初始化界面
     */
    private void init() {
        initControl();
    }
    
    private void initControl() {
        this.setLayout(new BorderLayout());
        this.setTitle("选择部门");
        try{
            JScrollPane jspTable = reloadTree();
            this.add(jspTable, BorderLayout.CENTER);
        }catch (VCIException e) {
            VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework",e);
            return ;
        }
 
        JPanel palSubmit = new JPanel();
        palSubmit.setLayout(new FlowLayout());
        palSubmit.setBorder(new EmptyBorder(7, 7, 7, 7));
        
        palSubmit.add(conformBut);
        palSubmit.add(cancelBut);
        conformBut.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                addButton_actionPerformed();
            }
        });
        cancelBut.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                cancelCreate();
            }
        });
        
        this.add(palSubmit, BorderLayout.SOUTH);
        
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        int x = dim.width/2 - 200;
        int y = dim.height/2 - 200;
        
//        int x = (int)(this.getParent().getLocationOnScreen().getX()) + 200;
//        int y = (int)(this.getParent().getLocationOnScreen().getY()) + 80;
        this.setLocation(x , y);
        this.setSize(550, 450);
        this.setVisible(true);
        
    }
    
    public JScrollPane reloadTree() throws VCIException{
        DeptObject rootDeptObj = new DeptObject();
        treeTableModel = new PLDeptInfoDataTreeModel(transObject, columns, classes);
        rootNode = treeTableModel.getRootNode();
        rootObj = new DeptObject(); rootObj.setName("部门");
        rootNode.setObj(rootObj);
        this.loadTreeTableData(rootNode, rootDeptObj);
        treeTable = new JTreeTable(treeTableModel);
        treeTable.setRowHeight(25);
        treeTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        treeTable.getTableHeader().setReorderingAllowed(false);
        treeTable.getTableHeader().setResizingAllowed(true);
        treeTable.setColumnSelectionAllowed(false);
        treeTable.setShowGrid(true);
        treeTable.getColumnModel().getColumn(0).setMinWidth(200);
        treeTable.getTree().setCellRenderer(new DeptInfoTreeTableCellRender());
        treeTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
 
 
        treeTable.getColumnModel().getColumn(1).setMinWidth(100);
        treeTable.getColumnModel().getColumn(2).setMinWidth(250);
        
        treeTable.getTree().addTreeExpansionListener(new TreeExpansionListener(){
            public void treeExpanded(TreeExpansionEvent e) {
                if(fromManualExpand) return;
                TreePath path = e.getPath();
                TreeTableModel.TreeTableNode tableNode = (TreeTableModel.TreeTableNode)path.getLastPathComponent();
                if(!tableNode.isExpand()){
                    loadSelectedTreeNodeChild(tableNode);
                    // 展开过就不再加载数据
                    tableNode.setExpand(true);
                }
            }
            public void treeCollapsed(TreeExpansionEvent e) {}
        });
        JScrollPane jspTable = new JScrollPane();
        jspTable.getViewport().add(treeTable);
        return jspTable;
    }
    
    /**
     * <p>Description:获取子部门 </p>
     * 
     * @author wangxl
     * @time 2012-5-14
     * @param parentTableNode
     */
    private void loadSelectedTreeNodeChild(TreeTableModel.TreeTableNode parentTableNode){
        try{
            if(parentTableNode.getObj() instanceof DeptObject){
                DeptObject parentObj = (DeptObject)parentTableNode.getObj();
                DeptObject[] childStructDatas = null ; 
                if (parentObj.getId() == null ){
                    parentTableNode.removeAll();
                    childStructDatas = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).fetchDepartmentInfoRoot();
                }else {
                    childStructDatas = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).fetchDepartmentInfoByParentId(parentObj.getId());
                }
                parentTableNode.setExpand(true);
                if (childStructDatas != null){
                    for (int i = 0 ; i < childStructDatas.length ; i ++){
                        TreeTableModel.TreeTableNode tableNode = treeTableModel.new TreeTableNode(parentTableNode, childStructDatas[i]);
                        parentTableNode.addChild(tableNode);
                        setPropertyValue(tableNode);
                    }
                }
                
                // 设置选择节点
//                this.treeTable.repaint();
                this.treeTable.getTree().setSelectionPath(new TreePath(parentTableNode));
            }
        } catch (VCIException e) {
            VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e);
            return;
        }
    }
    
    /**
     * <p>Description:单元格属性填充 </p>
     * 
     * @author wangxl
     * @time 2012-5-14
     * @param tableNode
     */
    private void setPropertyValue(TreeTableModel.TreeTableNode tableNode){
        DeptObject deptObj = (DeptObject)tableNode.getObj();
        tableNode.setPropertyValueByName(columns[1], deptObj.getNum() == null ? "" : deptObj.getNum());
        tableNode.setPropertyValueByName(columns[2], deptObj.getCode() == null ? "" : deptObj.getCode());
        tableNode.setPropertyValueByName(columns[3], deptObj.getDescription() == null ? "" : deptObj.getDescription());
        
    }
    
    /**
     * <p>Description: 获取顶级部门</p>
     * 
     * @author wangxl
     * @time 2012-5-14
     * @param rootNode
     * @param rootDeptObj
     */
    private void loadTreeTableData(TreeTableModel.TreeTableNode rootNode, DeptObject rootDeptObj){
        DeptObject[] deptObjs  = null;
        try {
            deptObjs = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).fetchDepartmentInfoRoot();
            if (deptObjs.length > 0){
                for (int i = 0 ; i < deptObjs.length ; i ++){
                    TreeTableModel.TreeTableNode tableNode = treeTableModel.new TreeTableNode(rootNode, deptObjs[i]);
                    rootNode.addChild(tableNode);
                    setPropertyValue(tableNode);
                }
            }
        }catch(VCIException e) {
            VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework",e);
            return;
        }
    }
 
 
    private void addButton_actionPerformed() {
        if("1".equals(type)) {
            if (null == this.treeTable.getTree().getSelectionPaths()){
                deptObj = new DeptObject();
                return;
            }
            
            if( this.treeTable.getTree().getSelectionPaths().length > 1) {
                deptObj = new DeptObject();
                VCIOptionPane.showMessage(this, "系统当前只支持单个部门的查询,请重新选择!");
                return;
            }
            TreePath path = this.treeTable.getTree().getSelectionPaths()[0];
            TreeTableModel.TreeTableNode treeNode = (TreeTableModel.TreeTableNode)path.getLastPathComponent();
            deptObj =(DeptObject)treeNode.getObj();
        }else if("2".equals(type)){//业务系统调用此dialog
            if (null == this.treeTable.getTree().getSelectionPaths()){
                deptObj = new DeptObject();
                return;
            }
            int len = this.treeTable.getTree().getSelectionPaths().length;
            for(int i = 0;i<len;i++) {
                TreePath path = this.treeTable.getTree().getSelectionPaths()[i];
                TreeTableModel.TreeTableNode treeNode = (TreeTableModel.TreeTableNode)path.getLastPathComponent();
                deptObj =(DeptObject)treeNode.getObj();
                deptList.add(deptObj);
                setIsgetDatas(true);
            }
        }else {
            if (null == this.treeTable.getTree().getSelectionPaths()){
                VCIOptionPane.showMessage(this, "请选择部门节点!");
                return;
            }
            
            if( this.treeTable.getTree().getSelectionPaths().length > 1) {
                VCIOptionPane.showMessage(this, "每次只能选择一个部门节点!");
                return;
            }
            TreePath path = this.treeTable.getTree().getSelectionPaths()[0];
            TreeTableModel.TreeTableNode treeNode = (TreeTableModel.TreeTableNode)path.getLastPathComponent();
            DeptObject parentObj =(DeptObject)treeNode.getObj();
            String detpId = parentObj.getId();
            if("".equals(detpId) || null == detpId || "null".equals(detpId)) {
                VCIOptionPane.showMessage(this, "选择的是部门根节点,请重新选择!!");
                return;
            }
            String[] userIds = new String[userList.size()];
            for (int i = 0 ; i < userList.size() ; i ++){
                userIds[i] = userList.get(i).getId();
            }
            try{
                
                new RightManagementClientDelegate(LogonApplication.getUserEntityObject())
                            .saveUserDept(userIds,parentObj.getId());
                
            }catch(VCIException e) {
                VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework", e);
                return ;
            }
             userPanel.tablePanel.refreshTableData();
        }
       this.dispose();
    }
    
    public void cancelCreate(){
        this.dispose();
    }
    
    public DeptObject getDeptObj() {
        return deptObj;
    }
    
}