KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > serverconfig > permissions > tree > PermissionsTreeNode


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.serverconfig.permissions.tree;
20
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23
24 import javax.swing.Icon JavaDoc;
25 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
26
27 import org.openharmonise.vfs.gui.*;
28 import org.openharmonise.vfs.metadata.*;
29 import org.openharmonise.vfs.metadata.range.*;
30 import org.openharmonise.vfs.metadata.value.*;
31
32
33 /**
34  * Tree node for the permissions tree.
35  *
36  * @author Matthew Large
37  * @version $Revision: 1.1 $
38  *
39  */

40 public class PermissionsTreeNode extends DefaultMutableTreeNode JavaDoc {
41
42     /**
43      * Property Instance for this object on the selected Role.
44      */

45     private PropertyInstance m_propInst;
46
47     /**
48      * Full path to the object/permission.
49      */

50     private String JavaDoc m_sHREF = null;
51     
52     /**
53      * Name for this object/permission.
54      */

55     private String JavaDoc m_sDisplayName = "";
56     
57     /**
58      * Icon for this object/permission.
59      */

60     private Icon JavaDoc m_iDisplayIcon = null;
61     
62     /**
63      * Expanded icon for this object/permission.
64      */

65     private Icon JavaDoc m_iDisplayIconExpanded = null;
66     
67     /**
68      * True if this is a leaf node.
69      */

70     private boolean m_bIsLeaf=false;
71     
72     /**
73      * True if the children of this node are populated.
74      */

75     private boolean m_bChildrenPopulated = false;
76     
77     /**
78      * True if this node is selected.
79      */

80     private boolean m_bSelected = false;
81     
82     /**
83      * Cell for this node.
84      */

85     private PermissionsTreeCell m_cell=null;
86     
87     /**
88      * True if this node is enabled.
89      */

90     private boolean m_bEnabled=true;
91
92     /**
93      * Constructs a new permissions tree node.
94      *
95      * @param propInst property Instance for this object on the selected Role.
96      * @param value permission value object.
97      * @param bEnabled true if this node is enabled.
98      */

99     public PermissionsTreeNode(PropertyInstance propInst, Value value, boolean bEnabled) {
100         super(value.getHREF());
101         this.m_propInst = propInst;
102         this.m_sHREF=value.getHREF();
103         this.m_bEnabled = bEnabled;
104         
105         this.m_sDisplayName = value.getDisplayName();
106         this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-value.gif");
107         this.m_iDisplayIconExpanded = IconManager.getInstance().getIcon("16-value.gif");
108         this.m_bIsLeaf = true;
109         
110         this.populateChildren();
111     }
112
113     /**
114      * Constructs a new permissions tree node.
115      *
116      * @param propInst property Instance for this object on the selected Role.
117      * @param valuegroup object valuegroup object.
118      * @param bEnabled true if this node is enabled.
119      */

120     public PermissionsTreeNode(PropertyInstance propInst, ValueGroup valuegroup, boolean bEnabled) {
121         super(valuegroup.getHREF());
122         this.m_propInst = propInst;
123         this.m_sHREF=valuegroup.getHREF();
124         this.m_bEnabled = bEnabled;
125         
126         this.m_sDisplayName = propInst.getDefinition().getDisplayName();
127         this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-value-container.gif");
128         this.m_iDisplayIconExpanded = IconManager.getInstance().getIcon("16-value-container.gif");
129         this.m_bIsLeaf = false;
130         
131         this.populateChildren();
132     }
133     
134     /**
135      * Sets whether this node is selected.
136      *
137      * @param bSelected true to select this node.
138      */

139     public void setSelected(boolean bSelected) {
140         ValueValue val = (ValueValue) this.m_propInst.getNewValueInstance();
141         val.setValue(this.getValue().getHREF());
142         if(bSelected && this.m_bIsLeaf && this.getValue()!=null) {
143             this.m_propInst.addValue( val );
144         } else if(!bSelected && this.m_bIsLeaf && this.getValue()!=null) {
145             this.m_propInst.removeValue( val );
146         } else if(bSelected && this.getValueGroup()!=null) {
147             this.addAllValues(this.m_propInst, this.getValueGroup());
148         } else if(!bSelected && this.getValueGroup()!=null) {
149             this.removeAllValues(this.m_propInst, this.getValueGroup());
150         }
151     }
152     
153     /**
154      * Checks if this node is enabled.
155      *
156      * @return true if this node is enabled.
157      */

158     public boolean getEnabled() {
159         return this.m_bEnabled;
160     }
161     
162     /**
163      * Checks if this node is selected.
164      *
165      * @return true if this node is selected.
166      */

167     public boolean isSelected() {
168         if(this.m_bIsLeaf) {
169             List JavaDoc vals = this.m_propInst.getValues();
170             Iterator JavaDoc itor = vals.iterator();
171             while (itor.hasNext()) {
172                 ValueValue value = (ValueValue) itor.next();
173                 if(value.getValue().equalsIgnoreCase(this.getValue().getHREF())) {
174                     return true;
175                 }
176             }
177             return false;
178         } else {
179             return this.checkAllValues(this.m_propInst, this.getValueGroup());
180         }
181     }
182     
183     /**
184      * Adds all the values from a valuegroup to the children of this node.
185      *
186      * @param propInst property Instance for this object on the selected Role.
187      * @param valGrp valuegroup to get children from.
188      */

189     private void addAllValues(PropertyInstance propInst, ValueGroup valGrp) {
190         List JavaDoc subGrps = valGrp.getSubGroups();
191         Iterator JavaDoc itor = subGrps.iterator();
192         while(itor.hasNext()) {
193             ValueGroup subGrp = (ValueGroup)itor.next();
194             this.addAllValues(propInst, subGrp);
195         }
196         
197         List JavaDoc children = valGrp.getChildren();
198         itor = children.iterator();
199         while(itor.hasNext()) {
200             Value val = (Value)itor.next();
201             ValueValue valInst = (ValueValue) propInst.getNewValueInstance();
202             valInst.setValue(val.getHREF());
203             propInst.addValue(valInst);
204         }
205     }
206     
207     /**
208      * Removes all the values from a valuegroup from the children of this node.
209      *
210      * @param propInst property Instance for this object on the selected Role.
211      * @param valGrp valuegroup to get children to remove from.
212      */

213     private void removeAllValues(PropertyInstance propInst, ValueGroup valGrp) {
214         List JavaDoc subGrps = valGrp.getSubGroups();
215         Iterator JavaDoc itor = subGrps.iterator();
216         while(itor.hasNext()) {
217             ValueGroup subGrp = (ValueGroup)itor.next();
218             this.removeAllValues(propInst, subGrp);
219         }
220         
221         List JavaDoc children = valGrp.getChildren();
222         itor = children.iterator();
223         while(itor.hasNext()) {
224             Value val = (Value)itor.next();
225             ValueValue valInst = (ValueValue) propInst.getNewValueInstance();
226             valInst.setValue(val.getHREF());
227             propInst.removeValue(valInst);
228         }
229     }
230     
231     /**
232      * Checks all the values from a valuegroup as children of this node.
233      *
234      * @param propInst property Instance for this object on the selected Role.
235      * @param valGrp valuegroup to get children to check from.
236      * @return true if all values where successfully checked.
237      */

238     private boolean checkAllValues(PropertyInstance propInst, ValueGroup valGrp) {
239         boolean bChecked = true;
240         
241         List JavaDoc subGrps = valGrp.getSubGroups();
242         Iterator JavaDoc itor = subGrps.iterator();
243         while(itor.hasNext()) {
244             ValueGroup subGrp = (ValueGroup)itor.next();
245             if(!this.checkAllValues(propInst, subGrp)) {
246                 bChecked=false;
247             }
248         }
249         
250         if(bChecked) {
251             List JavaDoc children = valGrp.getChildren();
252             itor = children.iterator();
253             while(itor.hasNext()) {
254                 Value val = (Value)itor.next();
255                 
256                 boolean bFound=false;
257                 List JavaDoc vals = this.m_propInst.getValues();
258                 Iterator JavaDoc itor2 = vals.iterator();
259                 while (itor2.hasNext()) {
260                     ValueValue value = (ValueValue) itor2.next();
261                     if(value.getValue().equalsIgnoreCase(val.getHREF())) {
262                         bFound = true;
263                     }
264                 }
265                 if(!bFound) {
266                     bChecked=false;
267                 }
268             }
269         }
270
271         return bChecked;
272     }
273
274     /**
275      * Gets the icon for this node.
276      *
277      * @param bExpanded true to get the expanded version icon.
278      * @return icon for this node.
279      */

280     public Icon JavaDoc getDisplayIcon(boolean bExpanded) {
281         return this.m_iDisplayIcon;
282     }
283     
284     /**
285      * Gets the valuegroup this node represents.
286      *
287      * @return valuegroup this node represents.
288      */

289     public ValueGroup getValueGroup() {
290         return ValueCache.getInstance().getValueGroup(this.m_sHREF);
291     }
292     
293     /**
294      * Gets the value this node represents.
295      *
296      * @return value this node represents.
297      */

298     public Value getValue() {
299         return ValueCache.getInstance().getValue(this.m_sHREF);
300     }
301     
302     /**
303      * Gets the property instance for this object on the selected Role.
304      *
305      * @return property instance for this object on the selected Role.
306      */

307     public PropertyInstance getPropertyInstance() {
308         return this.m_propInst;
309     }
310     
311     /**
312      * Gets the name for this node.
313      *
314      * @return name for this node.
315      */

316     public String JavaDoc getDisplayName() {
317         return this.m_sDisplayName;
318     }
319     
320     /**
321      * Checks if this is a leaf node.
322      *
323      * @return true if this is a leaf node.
324      */

325     public boolean isLeaf() {
326         return this.m_bIsLeaf;
327     }
328     
329     /**
330      * Populates the children of this node.
331      *
332      */

333     protected void populateChildren() {
334         if(!this.isLeaf()) {
335             if(this.m_sDisplayName.equalsIgnoreCase("Asset")) {
336                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-image.gif");
337             } else if(this.m_sDisplayName.equalsIgnoreCase("Document")) {
338                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-document.gif");
339             } else if(this.m_sDisplayName.equalsIgnoreCase("Property")) {
340                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-property.gif");
341             } else if (this.m_sDisplayName.equalsIgnoreCase("Property Group")) {
342                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-property-container.gif");
343             } else if (this.m_sDisplayName.equalsIgnoreCase("Section")) {
344                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-section.gif");
345             } else if (this.m_sDisplayName.equalsIgnoreCase("User")) {
346                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-user.gif");
347             } else if (this.m_sDisplayName.equalsIgnoreCase("User Group")) {
348                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-user-container.gif");
349             } else if (this.m_sDisplayName.equalsIgnoreCase("Value")) {
350                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-value.gif");
351             } else if (this.m_sDisplayName.equalsIgnoreCase("Value Group")) {
352                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-value-container.gif");
353             } else if (this.m_sDisplayName.equalsIgnoreCase("XML Resource")) {
354                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-page-definition.gif");
355             } else if (this.m_sDisplayName.equalsIgnoreCase("XML Resource Group")) {
356                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-page-definition-folder.gif");
357             } else if (this.m_sDisplayName.equalsIgnoreCase("XSL Resource")) {
358                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-xslt.gif");
359             } else if (this.m_sDisplayName.equalsIgnoreCase("XSL Resource Group")) {
360                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-xslt-folder.gif");
361             } else if (this.m_sDisplayName.equalsIgnoreCase("WebPage Group")) {
362                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-page-definition-folder.gif");
363             } else if (this.m_sDisplayName.equalsIgnoreCase("WebPage")) {
364                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-page-definition.gif");
365             } else if (this.m_sDisplayName.equalsIgnoreCase("Template")) {
366                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-object-template.gif");
367             } else if (this.m_sDisplayName.equalsIgnoreCase("Template Group")) {
368                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-object-template-folder.gif");
369             } else if (this.m_sDisplayName.equalsIgnoreCase("Workflow")) {
370                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-command-change-status.gif");
371             } else if (this.m_sDisplayName.equalsIgnoreCase("Workflow Group")) {
372                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-folder.gif");
373             } else if (this.m_sDisplayName.equalsIgnoreCase("Workflow Stage")) {
374                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-workflow-container.gif");
375             } else if (this.m_sDisplayName.equalsIgnoreCase("Workflow Stage Group")) {
376                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-folder.gif");
377             }
378         } else {
379             if(this.getDisplayName().equalsIgnoreCase("Archive")) {
380                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-archive-container.gif");
381             } else if(this.getDisplayName().equalsIgnoreCase("Publish")) {
382                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-command-publish.gif");
383             } else if(this.getDisplayName().equalsIgnoreCase("Lock")) {
384                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-command-lock.gif");
385             } else if(this.getDisplayName().equalsIgnoreCase("Unlock")) {
386                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-command-unlock.gif");
387             } else if(this.getDisplayName().equalsIgnoreCase("Move/Copy")) {
388                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-command-move.gif");
389             } else if(this.getDisplayName().equalsIgnoreCase("Retrieve")) {
390                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-command-retrieve.gif");
391             } else if(this.getDisplayName().equalsIgnoreCase("Submit to Server")) {
392                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-command-sync-all.gif");
393             } else if(this.getDisplayName().equalsIgnoreCase("View")) {
394                 this.m_iDisplayIcon = IconManager.getInstance().getIcon("16-command-preview.gif");
395             }
396         }
397         
398         if(!this.m_bIsLeaf && !m_bChildrenPopulated) {
399             Iterator JavaDoc itor = ValueCache.getInstance().getValueGroup(this.m_sHREF).getSubGroups().iterator();
400             int nCount = 0;
401             while(itor.hasNext()) {
402                 this.add( new PermissionsTreeNode(this.m_propInst, (ValueGroup)itor.next(), this.m_bEnabled));
403                 nCount++;
404             }
405             itor = ValueCache.getInstance().getValueGroup(this.m_sHREF).getChildren().iterator();
406             while(itor.hasNext()) {
407                 this.add( new PermissionsTreeNode(this.m_propInst, (Value)itor.next(), this.m_bEnabled));
408                 nCount++;
409             }
410             m_bChildrenPopulated = true;
411         }
412     }
413     
414     /**
415      * Gets the full path to the object/permission this node represents.
416      *
417      * @return full path to the object/permission this node represents.
418      */

419     public String JavaDoc getHREF() {
420         return this.m_sHREF;
421     }
422
423     /**
424      * @param userObject
425      */

426     private PermissionsTreeNode(Object JavaDoc userObject) {
427         super(userObject);
428     }
429
430     /**
431      * @param userObject
432      * @param allowsChildren
433      */

434     private PermissionsTreeNode(Object JavaDoc userObject, boolean allowsChildren) {
435         super(userObject, allowsChildren);
436     }
437     
438     /**
439      * Sets whether this node is enabled.
440      *
441      * @param bEnable true to enable this node.
442      */

443     public void setEnabled(boolean bEnable) {
444         this.m_bEnabled = bEnable;
445     }
446
447 }
448
Popular Tags