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
package com.vci.client.framework.systemConfig.specialCharacter;
 
 
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Locale;
 
import javax.swing.JPanel;
import javax.swing.tree.TreePath;
 
import com.vci.client.LogonApplication;
import com.vci.client.common.TransmitTreeObject;
import com.vci.client.framework.delegate.SystemCfgClientDelegate;
import com.vci.client.framework.systemConfig.object.SpecialCharClsfObject;
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.tree.VCIBaseTreeNode;
 
/***
 * 特殊字符分类删除监听
 * @author Administrator
 *
 */
public class SpecialCharacterClsActionListener  implements ActionListener{
    
    /****************************国际化信息**********************************/
    //请选择要删除的节点!
    private String SELECTDELETENODE = LocaleDisplay.getI18nString("rmip.framework.sysconfig.selectDeleteNode", "RMIPFramework",Locale.getDefault());
    //选择删除的节点包括非特殊字符分类节点,请重新选择!
    private String DELETECLSFALERT = LocaleDisplay.getI18nString("rmip.framework.sysconfig.deleteClsfAlert", "RMIPFramework",Locale.getDefault());
    //您确定要删除选中的分类吗?
    private String DELETECLSFCONFIRM = LocaleDisplay.getI18nString("rmip.framework.sysconfig.deleteClsfConfirm", "RMIPFramework",Locale.getDefault());
    //名称不能为空,请重新填写!
    private String NAMEALERT = LocaleDisplay.getI18nString("rmip.framework.sysconfig.nameAlert", "RMIPFramework",Locale.getDefault());
    //名称的长度不能超过128个字符!
    private String ROLELENGTHALERT = LocaleDisplay.getI18nString("rmip.framework.sysconfig.nameLengthAlert", "RMIPFramework",Locale.getDefault());
    //描述的长度不能超过255个字符!
    private String DESCLENGTHALERT = LocaleDisplay.getI18nString("rmip.framework.sysconfig.descLengthAlert", "RMIPFramework",Locale.getDefault());
    //修改成功!
    private String MODIFYSUCCESS = LocaleDisplay.getI18nString("rmip.framework.sysconfig.modifySuccess", "RMIPFramework",Locale.getDefault());
    
    private TransmitTreeObject transmitTreeObject;
    private String type = "";
    private SpecialCharacterPanel specialCharacterPanel = null;
    private String name = "";  //分类的名称
    private String des = "";   //分类的描述
    private JPanel jpanel = null;
    private SpecialCharacterDialog dialog;
    private SpecialCharacterPanel panel;
    private SpecialCharClsfObject obj;
    
    public SpecialCharacterClsActionListener(SpecialCharacterDialog dialog,String type,SpecialCharacterPanel panel,SpecialCharClsfObject obj) {
        this.type = type;
        this.dialog = dialog;
        this.panel = panel;
        this.obj = obj;
    }
    
    public void actionPerformed(ActionEvent e) {
        if (type.equals("add")) {
            add_actionPerformed();
        } else if (type.equals("modify")) {
            edit_actionPerformed();
        }  else if (type.equals("delete")) {
            delete_actionPerformed();
        }  
        
    }
    
    private SpecialCharClsfObject getSpecialCharacterClsInfo() {
        SpecialCharClsfObject specialCharClsfInfo = new SpecialCharClsfObject();
        specialCharClsfInfo.setName(dialog.getNameFieldText());
        specialCharClsfInfo.setDesc(dialog.getDescriptionArea());
        if("modify".equalsIgnoreCase(type)){
            specialCharClsfInfo.setId(obj.getId());
        }
        return specialCharClsfInfo;
    }
    
    private void delete_actionPerformed() {
        TreePath[] treePaths = transmitTreeObject.getTree().getSelectionPaths();
        if (treePaths.length < 1) {
            VCIOptionPane.showMessageDialog(LogonApplication.frame, SELECTDELETENODE);
            return;
        }
        deleteSpecialCharClsfInfo(treePaths);
        
    }
    
    private void deleteSpecialCharClsfInfo(TreePath[] deleteTreePaths) {
        int len = deleteTreePaths.length;
        String[] puids = new String[len];
        VCIBaseTreeNode[] removeNodes = new VCIBaseTreeNode[len];
        for (int i = 0; i < len; i++) {
            VCIBaseTreeNode treeNode = (VCIBaseTreeNode)deleteTreePaths[i].getLastPathComponent();
            boolean canDelete = true; //选择的节点是否可以删除
            SpecialCharClsfObject specialCharClsfObject = null;
            if (!(treeNode.getObj() instanceof SpecialCharClsfObject)) {
                canDelete = false;
            } else {
                specialCharClsfObject = (SpecialCharClsfObject) treeNode.getObj();
                if ("root".equals(specialCharClsfObject.getId())) {
                    canDelete = false;
                }
            }
            if (!canDelete) {
                VCIOptionPane.showMessageDialog(LogonApplication.frame, DELETECLSFALERT);
                return;
            }
            
            removeNodes[i] = treeNode;
            puids[i] = specialCharClsfObject.getId();
        }
        int ok=VCIOptionPane.showQuestion(LogonApplication.frame,DELETECLSFCONFIRM);
       
        if (ok == 0) {
            boolean rs=true;
            try {
                rs = new SystemCfgClientDelegate(LogonApplication.getUserEntityObject()).deletSpecialCharClsf(puids);
            } catch (VCIException e) {
                VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework",e);
                return;
            }
            if (!rs) {
                return;
            }
            VCIBaseTreeNode parentNode = (VCIBaseTreeNode) transmitTreeObject.getCurrentTreeNode().getParent();
            for (int i = 0; i < len; i++) {
                transmitTreeObject.getTreeModel().removeNodeFromParent(removeNodes[i]);
            }
            transmitTreeObject.getTree().setSelectionPath(new TreePath(parentNode.getPath()));
        }
    }
    
    private boolean checkName(boolean isAddOrEdit){
        name = dialog.getNameFieldText();
        des = dialog.getDescriptionArea();
        if("".equalsIgnoreCase(name)){
            VCIOptionPane.showMessageDialog(LogonApplication.frame,NAMEALERT);
            return false;
        }
        if (name.getBytes().length > 128) {
            VCIOptionPane.showMessageDialog(LogonApplication.frame, ROLELENGTHALERT);
            return false;
        }
        if (des.getBytes().length > 255) {
            VCIOptionPane.showMessageDialog(LogonApplication.frame, DESCLENGTHALERT);
            return false;
        }
        
        SpecialCharClsfObject[] objs = getSpecialCharClsfObjs();
        /***特殊字符分类名称重复的校验**/
        if(isAddOrEdit) {
            for(SpecialCharClsfObject obj : objs) {
                if(name.equals(obj.getName())) {
                    VCIOptionPane.showMessageDialog(this.dialog, "分类名称存在重复,请重新输入!");
                    return false;
                }
            }
        } else {
            for(SpecialCharClsfObject clsfObj : objs) {
                if(name.equals(clsfObj.getName()) && !(clsfObj.getId().equals(obj.getId()))) {
                    VCIOptionPane.showMessageDialog(this.dialog, "分类名称存在重复,请重新输入!");
                    return false;
                }
            }
        }
        
        return true;
    }
    
    public SpecialCharClsfObject[] getSpecialCharClsfObjs() {
        SpecialCharClsfObject[] Objects = null;
        try {
            Objects = new SystemCfgClientDelegate(LogonApplication.getUserEntityObject())
                    .getSpecialCharClsfList(1,10000);
        } catch (VCIException e) {
            VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework", e);
            return null;
        }
 
        return Objects;
    }
    
    private void add_actionPerformed() {
        boolean rs = checkName(true);
        if (!rs) {
            return;
        }
        SpecialCharClsfObject specialCharClsfInfo = getSpecialCharacterClsInfo();
        try {
            String id = new SystemCfgClientDelegate(LogonApplication.getUserEntityObject()).saveSpecialCharClsf(specialCharClsfInfo);
            specialCharClsfInfo.setId(id);
        } catch (VCIException e) {
            VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework",e);
            return;
        }
        VCIOptionPane.showMessage(LogonApplication.frame, "保存成功!");
        dialog.dispose();
    }
    
    private void edit_actionPerformed() {
        boolean rs = checkName(false);
        if (!rs) {
            return;
        }
        SpecialCharClsfObject specialCharClsfInfo = getSpecialCharacterClsInfo();
        try {
            new SystemCfgClientDelegate(LogonApplication.getUserEntityObject()).updateSpecialCharClsf(specialCharClsfInfo);
        } catch (VCIException e) {
            VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework",e);
            return;
        }
        VCIOptionPane.showMessage(LogonApplication.frame, "修改成功!");
        dialog.dispose();
    }
 
}