| 1 19 package org.openharmonise.him.serverconfig.permissions.tree; 20 21 import java.util.Iterator ; 22 import java.util.List ; 23 24 import javax.swing.Icon ; 25 import javax.swing.tree.DefaultMutableTreeNode ; 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 40 public class PermissionsTreeNode extends DefaultMutableTreeNode { 41 42 45 private PropertyInstance m_propInst; 46 47 50 private String m_sHREF = null; 51 52 55 private String m_sDisplayName = ""; 56 57 60 private Icon m_iDisplayIcon = null; 61 62 65 private Icon m_iDisplayIconExpanded = null; 66 67 70 private boolean m_bIsLeaf=false; 71 72 75 private boolean m_bChildrenPopulated = false; 76 77 80 private boolean m_bSelected = false; 81 82 85 private PermissionsTreeCell m_cell=null; 86 87 90 private boolean m_bEnabled=true; 91 92 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 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 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 158 public boolean getEnabled() { 159 return this.m_bEnabled; 160 } 161 162 167 public boolean isSelected() { 168 if(this.m_bIsLeaf) { 169 List vals = this.m_propInst.getValues(); 170 Iterator 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 189 private void addAllValues(PropertyInstance propInst, ValueGroup valGrp) { 190 List subGrps = valGrp.getSubGroups(); 191 Iterator itor = subGrps.iterator(); 192 while(itor.hasNext()) { 193 ValueGroup subGrp = (ValueGroup)itor.next(); 194 this.addAllValues(propInst, subGrp); 195 } 196 197 List 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 213 private void removeAllValues(PropertyInstance propInst, ValueGroup valGrp) { 214 List subGrps = valGrp.getSubGroups(); 215 Iterator itor = subGrps.iterator(); 216 while(itor.hasNext()) { 217 ValueGroup subGrp = (ValueGroup)itor.next(); 218 this.removeAllValues(propInst, subGrp); 219 } 220 221 List 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 238 private boolean checkAllValues(PropertyInstance propInst, ValueGroup valGrp) { 239 boolean bChecked = true; 240 241 List subGrps = valGrp.getSubGroups(); 242 Iterator 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 children = valGrp.getChildren(); 252 itor = children.iterator(); 253 while(itor.hasNext()) { 254 Value val = (Value)itor.next(); 255 256 boolean bFound=false; 257 List vals = this.m_propInst.getValues(); 258 Iterator 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 280 public Icon getDisplayIcon(boolean bExpanded) { 281 return this.m_iDisplayIcon; 282 } 283 284 289 public ValueGroup getValueGroup() { 290 return ValueCache.getInstance().getValueGroup(this.m_sHREF); 291 } 292 293 298 public Value getValue() { 299 return ValueCache.getInstance().getValue(this.m_sHREF); 300 } 301 302 307 public PropertyInstance getPropertyInstance() { 308 return this.m_propInst; 309 } 310 311 316 public String getDisplayName() { 317 return this.m_sDisplayName; 318 } 319 320 325 public boolean isLeaf() { 326 return this.m_bIsLeaf; 327 } 328 329 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 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 419 public String getHREF() { 420 return this.m_sHREF; 421 } 422 423 426 private PermissionsTreeNode(Object userObject) { 427 super(userObject); 428 } 429 430 434 private PermissionsTreeNode(Object userObject, boolean allowsChildren) { 435 super(userObject, allowsChildren); 436 } 437 438 443 public void setEnabled(boolean bEnable) { 444 this.m_bEnabled = bEnable; 445 } 446 447 } 448 | Popular Tags |