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
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
package com.vci.client.uif.engine.client.compare.dialog.treenode;
 
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
 
import javax.swing.tree.DefaultMutableTreeNode;
 
import com.vci.client.bof.ClientBusinessObject;
import com.vci.client.bof.ClientLinkObject;
import com.vci.client.uif.engine.client.compare.enumeration.CompareState;
import com.vci.client.uif.engine.common.CBOHelper;
 
/**
 * 系统业务对象节点
 * 
 * 对于系统的业务对象,存在不同的链接关系下使用同一个业务对象的情况
 * 所以在创建的时候确定不同的TreeNodeObject使用相同的业务对象时,对象
 * 所引用的主对象是同一个对象,这样就可以保证一个节点修改时,所有使用
 * 该对象的节点都得到了修改。
 * @author VCI-STGK006
 *
 */
public class BusinessTreeNodeObject implements TreeNodeObject {
    
    /**
     * 存储使用当前节点的树节点对象
     * 当树中创建新的节点时已存储的对象可能被释放
     */
    private Set<DefaultMutableTreeNode> ownedNodes = new HashSet<DefaultMutableTreeNode>();
    
    /**
     * 当前节点所有子节点对象列表
     */
    private List<TreeNodeObject> childList = new ArrayList<TreeNodeObject>();
    
    /**
     * 当前节点相对节点
     */
    private TreeNodeObject relativeNode = null;
    
    /**
     * 节点主对象
     */
    private MainObject mo = null;
    
    /**
     * 节点关系对象
     */
    private RelationObject ro = null;
    
    /**
     * 是否是根节点
     */
    private boolean isRoot = false;
    
    /**
     * 节点比较状态
     */
    private CompareState cs = CompareState.SAME;
    
    /**
     * 构造器
     */
    public BusinessTreeNodeObject() {
        this.mo = new MainObject();
        this.ro = new RelationObject();
    }
    
    /**
     * 构造器
     * @param mo 主对象
     * @param ro 关系对象
     */
    public BusinessTreeNodeObject(MainObject mo, RelationObject ro) {
        this.mo = mo;
        this.ro = ro;
    }
    
    @Override
    public boolean isRoot() {
        return this.isRoot;
    }
    
    /**
     * 得到主对象或关系对象所有属性<br>
     * <br>
     * 此方法总是返回关系或业务对象中hisAttrValList中的属性<br>
     * 
     * @return 当执行类型对象属性不存时返回""
     */
    @Override
    public Map<String, String> attributes(int type) {
        if(type == TreeNodeObject.MAINOBJECT) {
            if(this.getMo().getCbo() == null) {
                return null;
            }
            return CBOHelper.getBOValueMap(
                    this.getMo().getCbo().getBusinessObject());
        } else {
            if(this.getRo().getClo() == null) {
                return null;
            }
            return CBOHelper.getLOValueMap(this.getRo().getClo().getLinkObject());
        }
    }
 
    /**
     * 得到主对象或关系对象属性<br>
     * <br>
     * 方法首先在newAttrValList中查找属性是否存在,如果不存在则到hisAttrValList中查找
     * 
     * @return 当执行类型对象属性不存时返回""
     */
    @Override
    public String getAttribute(String key, int type) {
        if(type == TreeNodeObject.MAINOBJECT) {
            if(this.getMo().getCbo() == null) {
                return null;
            }
            return this.getMo().getCbo().getAttributeValue(key);
        } else {
            if(this.getRo().getClo() == null) {
                return null;
            }
            return this.getRo().getClo().getAttributeValue(key);
        }
    }
 
    @Override
    public String getKey() {
        return this.ro.getKey() + "##" + this.mo.getKey();
    }
 
    @Override
    public ClientBusinessObject getMainObject() {
        return this.getMo().getCbo();
    }
 
    @Override
    public String getMainObjectKey() {
        return this.mo.getKey();
    }
    
    @Override
    public ClientLinkObject getRelationObject() {
        return this.getRo().getClo();
    }
 
    @Override
    public String getRelationObjectKey() {
        return this.ro.getKey();
    }
    
    @Override
    public CompareState getCompareState() {
        return this.cs;
    }
    
    @Override
    public void setCompareState(CompareState cs) {
        this.cs = cs;
    }
 
    @Override
    public void setOwnedTreeNode(DefaultMutableTreeNode dmtn) {
        this.ownedNodes.add(dmtn);
    }
 
    @Override
    public void removeOwnedTreeNode(DefaultMutableTreeNode dmtn) {
        this.ownedNodes.remove(dmtn);
    }
    
    @Override
    public Set<DefaultMutableTreeNode> getOwnedTreeNode() {
        return this.ownedNodes;
    }
 
    @Override
    public void setRelativeTreeNodeObject(TreeNodeObject relativeNode) {
        this.relativeNode = relativeNode;
    }
    
    @Override
    public void setChildNodeList(TreeNodeObject tno) {
        if(!this.childList.contains(tno)) {
            this.childList.add(tno);
        }
    }
 
    @Override
    public void removeChildNode(TreeNodeObject tno) {
        this.childList.remove(tno);
    }
 
    @Override
    public List<TreeNodeObject> getChildNodeList() {
        return this.childList;
    }
    
    public void setMo(MainObject mo) {
        this.mo = mo;
    }
    
    public MainObject getMo() {
        return this.mo;
    }
    
    public void setRo(RelationObject ro) {
        this.ro = ro;
    }
    
    public RelationObject getRo() {
        return this.ro;
    }
    
    public void setRelationKey(String key) {
        this.ro.setKey(key);
    }
 
    public void setRelationClo(ClientLinkObject clo) {
        this.ro.setClo(clo);
    }
    
    public void setMainKey(String key) {
        this.mo.setKey(key);
    }
    
    public void setMainCbo(ClientBusinessObject cbo) {
        this.mo.setCbo(cbo);
    }
    
    /**
     * 设置是否为根节点
     * @param isRoot
     */
    public void setIsRoot(boolean isRoot) {
        this.isRoot = isRoot;
    }
    
    @Override
    public String toString() {
        if(this.cs != CompareState.ISNULL) {
            return this.mo.getCbo().getId() 
                    + " " + this.mo.getCbo().getName() 
                    + " " + this.mo.getCbo().getRevisionValue();
        }
        if(this.relativeNode.getCompareState() != CompareState.ISNULL) {
            return this.relativeNode.toString();
        }
        return "                               ";
    }
    
    /**
     * 主对象
     * @author VCI-STGK006
     *
     */
    public class MainObject {
        
        /**
         * 主对象标识
         */
        private String key;
        
        /**
         * 主对象
         */
        private ClientBusinessObject cbo;
        
        /**
         * 使用当前对象的所有TreeNodeObject
         */
        private Vector<BusinessTreeNodeObject> ownedNodeObject = new Vector<BusinessTreeNodeObject>();
        
        /**
         * 构造器
         */
        public MainObject() {}
        /**
         * 构造器
         * @param key 主对象标识
         * @param cbo 主对象
         */
        public MainObject(String key, ClientBusinessObject cbo) {
            this.key = key;
            this.cbo = cbo;
        }
 
        public Vector<BusinessTreeNodeObject> getOwnedNodeObject() {
            return ownedNodeObject;
        }
 
        public void setOwnedNodeObject(BusinessTreeNodeObject ownedNodeObject) {
            this.ownedNodeObject.add(ownedNodeObject);
        }
 
        public String getKey() {
            return key;
        }
 
        public void setKey(String key) {
            this.key = key;
        }
 
        public ClientBusinessObject getCbo() {
            return cbo;
        }
 
        public void setCbo(ClientBusinessObject cbo) {
            this.cbo = cbo;
        }
    }
    
    /**
     * 关系对象
     * @author VCI-STGK006
     *
     */
    public class RelationObject {
        
        /**
         * 所属父节点主对象标识
         */
        private String key;
        
        /**
         * 关系对象
         */
        private ClientLinkObject clo;
        
        /**
         * 构造器
         */
        public RelationObject(){}
        
        /**
         * 构造器
         * @param parentKey 所属父节点主对象标识
         * @param clo 关系对象
         */
        public RelationObject(String parentKey, ClientLinkObject clo) {
            this.key = parentKey;
            this.clo = clo;
        }
 
        public String getKey() {
            return key;
        }
 
        public void setKey(String key) {
            this.key = key;
        }
 
        public ClientLinkObject getClo() {
            return clo;
        }
 
        public void setClo(ClientLinkObject clo) {
            this.clo = clo;
        }
    }
}