1 23 24 package org.objectweb.fractal.gui.tree.model; 25 26 import org.objectweb.fractal.api.control.BindingController; 27 28 import org.objectweb.fractal.gui.model.ClientInterface; 29 import org.objectweb.fractal.gui.model.Component; 30 import org.objectweb.fractal.gui.model.Configuration; 31 import org.objectweb.fractal.gui.model.ConfigurationListener; 32 import org.objectweb.fractal.gui.model.Interface; 33 import org.objectweb.fractal.gui.model.ServerInterface; 34 35 import java.util.EventListener ; 36 37 import javax.swing.event.EventListenerList ; 38 import javax.swing.event.TreeModelEvent ; 39 import javax.swing.event.TreeModelListener ; 40 import javax.swing.tree.TreeModel ; 41 import javax.swing.tree.TreePath ; 42 43 49 50 public class BasicTreeModel implements 51 TreeModel , 52 ConfigurationListener, 53 BindingController 54 { 55 56 60 61 public final static String CONFIGURATION_BINDING = "configuration"; 62 63 66 67 private final static Object EMPTY_TREE = new Object (); 68 69 72 73 private Configuration configuration; 74 75 78 79 private EventListenerList listeners; 80 81 84 85 public BasicTreeModel () { 86 this.listeners = new EventListenerList (); 87 } 88 89 93 public String [] listFc () { 94 return new String [] { CONFIGURATION_BINDING }; 95 } 96 97 public Object lookupFc (final String clientItfName) { 98 if (CONFIGURATION_BINDING.equals(clientItfName)) { 99 return configuration; 100 } 101 return null; 102 } 103 104 public void bindFc ( 105 final String clientItfName, 106 final Object serverItf) 107 { 108 if (CONFIGURATION_BINDING.equals(clientItfName)) { 109 configuration = (Configuration)serverItf; 110 } 111 } 112 113 public void unbindFc (final String clientItfName) { 114 if (CONFIGURATION_BINDING.equals(clientItfName)) { 115 configuration = null; 116 } 117 } 118 119 123 public void changeCountChanged (Component component, long changeCount) { 124 } 126 127 public void rootComponentChanged (final Component oldValue) { 128 Object oldRoot = oldValue == null ? EMPTY_TREE : oldValue; 129 TreeModelEvent e = new TreeModelEvent ( 130 this, 131 new Object []{oldRoot}, 132 null, 133 null 134 ); 135 EventListener [] l = listeners.getListeners(TreeModelListener .class); 136 for (int i = 0; i < l.length; ++i) { 137 ((TreeModelListener )l[i]).treeStructureChanged(e); 138 } 139 } 140 141 public void nameChanged (final Component component, final String oldValue) { 142 if (!configuration.getRootComponent().contains(component)) { 143 return; 144 } 145 TreeModelEvent e; 146 if (component == configuration.getRootComponent()) { 147 e = new TreeModelEvent ( 148 this, 149 new Object []{component}, 150 new int[]{0}, 151 new Object []{component}); 152 } else { 153 e = new TreeModelEvent ( 154 this, 155 component.getParent().getPath(), 156 new int[]{getIndexOfChild(component.getParent(), component)}, 157 new Object []{component}); 158 } 159 EventListener [] l = listeners.getListeners(TreeModelListener .class); 160 for (int i = 0; i < l.length; ++i) { 161 ((TreeModelListener )l[i]).treeNodesChanged(e); 162 } 163 } 164 165 public void typeChanged (final Component component, final String oldValue) { 166 } 168 169 public void implementationChanged ( 170 final Component component, 171 final String oldValue) 172 { 173 } 175 176 public void interfaceNameChanged (final Interface i, final String oldValue) { 177 } 179 180 public void interfaceSignatureChanged ( 181 final Interface i, 182 final String oldValue) 183 { 184 } 186 187 public void interfaceContingencyChanged ( 188 final Interface i, 189 final boolean oldValue) 190 { 191 } 193 194 public void interfaceCardinalityChanged ( 195 final Interface i, 196 final boolean oldValue) 197 { 198 } 200 201 public void clientInterfaceAdded ( 202 final Component component, 203 final ClientInterface i, 204 final int index) 205 { 206 } 208 209 public void clientInterfaceRemoved ( 210 final Component component, 211 final ClientInterface i, 212 final int index) 213 { 214 } 216 217 public void serverInterfaceAdded ( 218 final Component component, 219 final ServerInterface i, 220 final int index) 221 { 222 } 224 225 public void serverInterfaceRemoved ( 226 final Component component, 227 final ServerInterface i, 228 final int index) 229 { 230 } 232 233 public void interfaceBound ( 234 final ClientInterface citf, 235 final ServerInterface sitf) 236 { 237 } 239 240 public void interfaceRebound ( 241 final ClientInterface citf, 242 final ServerInterface oldSitf) 243 { 244 } 246 247 public void interfaceUnbound ( 248 final ClientInterface citf, 249 final ServerInterface sitf) 250 { 251 } 253 254 public void attributeControllerChanged ( 255 final Component component, 256 final String oldValue) 257 { 258 } 260 261 public void attributeChanged ( 262 final Component component, 263 final String attributeName, 264 final String oldValue) 265 { 266 } 268 269 public void templateControllerDescriptorChanged ( 270 final Component component, 271 final String oldValue) 272 { 273 } 275 276 public void componentControllerDescriptorChanged ( 277 final Component component, 278 final String oldValue) 279 { 280 } 282 283 public void subComponentAdded ( 284 final Component parent, 285 final Component child, 286 final int index) 287 { 288 if (!configuration.getRootComponent().contains(parent)) { 289 return; 290 } 291 TreeModelEvent e = new TreeModelEvent ( 292 this, 293 parent.getPath(), 294 new int[]{index}, 295 new Object []{child}); 296 EventListener [] l = listeners.getListeners(TreeModelListener .class); 297 for (int i = 0; i < l.length; ++i) { 298 ((TreeModelListener )l[i]).treeNodesInserted(e); 299 } 300 } 301 302 public void subComponentRemoved ( 303 final Component parent, 304 final Component child, 305 final int index) 306 { 307 if (!configuration.getRootComponent().contains(parent)) { 308 return; 309 } 310 TreeModelEvent e = new TreeModelEvent ( 311 this, 312 parent.getPath(), 313 new int[]{index}, 314 new Object []{child}); 315 EventListener [] l = listeners.getListeners(TreeModelListener .class); 316 for (int i = 0; i < l.length; ++i) { 317 ((TreeModelListener )l[i]).treeNodesRemoved(e); 318 } 319 } 320 321 325 public Object getRoot () { 326 if (configuration == null) { 327 return EMPTY_TREE; 328 } else { 329 return configuration.getRootComponent(); 330 } 331 } 332 333 public int getChildCount (final Object parent) { 334 if (parent == EMPTY_TREE) { 335 return 0; 336 } else { 337 return ((Component)parent).getSubComponents().size(); 338 } 339 } 340 341 public Object getChild (final Object parent, final int index) { 342 return ((Component)parent).getSubComponents().get(index); 343 } 344 345 public int getIndexOfChild (final Object parent, final Object child) { 346 if (parent == null) { 347 return 0; 348 } 349 return ((Component)parent).getSubComponents().indexOf(child); 350 } 351 352 public boolean isLeaf (final Object node) { 353 if (node == EMPTY_TREE) { 354 return true; 355 } else { 356 return ((Component)node).getSubComponents().size() == 0; 357 } 358 } 359 360 public void valueForPathChanged (final TreePath path, final Object newValue) { 361 } 363 364 public void addTreeModelListener (final TreeModelListener l) { 365 listeners.add(TreeModelListener .class, l); 366 } 367 368 public void removeTreeModelListener (final TreeModelListener l) { 369 listeners.remove(TreeModelListener .class, l); 370 } 371 } 372 | Popular Tags |