1 package org.oddjob.jobs.structural; 2 3 4 import org.oddjob.Iconic; 5 import org.oddjob.Stoppable; 6 import org.oddjob.Structural; 7 import org.oddjob.arooa.Lifecycle; 8 import org.oddjob.images.IconEvent; 9 import org.oddjob.images.IconHelper; 10 import org.oddjob.images.IconListener; 11 import org.oddjob.images.IconTip; 12 import org.oddjob.structural.ChildHelper; 13 import org.oddjob.structural.StructuralListener; 14 15 34 35 public class FolderJob 36 implements Structural, Iconic, Stoppable { 37 38 40 protected transient ChildHelper childHelper 41 = new ChildHelper(this); 42 43 48 private String name; 49 50 54 protected transient volatile boolean destroyed; 55 56 61 synchronized public void setName(String name) { 62 if (destroyed) { 63 throw new IllegalStateException ("[" + this + "] destroyed"); 64 } 65 this.name = name; 66 } 67 68 73 synchronized public String getName() { 74 return name; 75 } 76 77 86 public void addComponent(Object child) { 87 childHelper.addChild(child); 88 } 89 90 96 public void addStructuralListener(StructuralListener listener) { 97 if (destroyed) { 98 throw new IllegalStateException ("[" + this + "] destroyed"); 99 } 100 childHelper.addStructuralListener(listener); 101 } 102 103 108 public void removeStructuralListener(StructuralListener listener) { 109 childHelper.removeStructuralListener(listener); 110 } 111 112 115 public String toString() { 116 if (name == null) { 117 return getClass().getName(); 118 } 119 else { 120 return name; 121 } 122 } 123 124 128 public IconTip iconForId(String iconId) { 129 if (iconId.equals("folder")) { 130 return new IconTip( 131 IconHelper.class.getResource("Open16.gif"), 132 "folder"); 133 } 134 else { 135 return null; 136 } 137 } 138 139 145 public void addIconListener(IconListener listener) { 146 if (destroyed) { 147 throw new IllegalStateException ("[" + this + "] destroyed"); 148 } 149 listener.iconEvent(new IconEvent(this, "folder")); 150 } 151 152 158 public void removeIconListener(IconListener listener) { 159 } 160 161 164 public void stop() { 165 childHelper.stopChildren(); 166 } 167 168 171 public void destroy() { 172 if (destroyed) { 173 throw new IllegalStateException ("[" + this + "] destroyed"); 174 } 175 childHelper.stopChildren(); 176 Lifecycle.destroy(childHelper.getChildren()); 177 childHelper.removeAllChildren(); 178 destroyed = true; 179 } 180 181 } 182 | Popular Tags |