1 19 20 package org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.entity; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.util.*; 25 import javax.swing.SwingUtilities ; 26 import org.netbeans.api.java.classpath.ClassPath; 27 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; 28 import org.netbeans.modules.j2ee.dd.api.ejb.Entity; 29 import org.openide.filesystems.FileObject; 30 import org.openide.nodes.Children; 31 import org.openide.nodes.Node; 32 33 34 38 public final class EntityChildren extends Children.Keys<EntityChildren.KEY> implements PropertyChangeListener { 39 40 protected enum KEY { REMOTE, LOCAL, CMP_FIELDS } 41 42 private final Entity model; 43 private final ClassPath srcPath; 44 48 public EntityChildren(Entity model, ClassPath srcPath, EjbJar jar, FileObject ddFile) { 49 this.srcPath = srcPath; 50 this.model = model; 51 } 56 57 protected void addNotify() { 58 super.addNotify(); 59 updateKeys(); 60 model.addPropertyChangeListener(this); 61 srcPath.addPropertyChangeListener(this); 62 } 63 64 private void updateKeys() { 65 SwingUtilities.invokeLater(new Runnable () { 66 public void run() { 67 List<KEY> keys = new ArrayList<KEY>(); 68 if (model.getRemote() != null) { 69 keys.add(KEY.REMOTE); 70 } 71 if (model.getLocal()!=null) { 72 keys.add(KEY.LOCAL); 73 } 74 if (Entity.PERSISTENCE_TYPE_CONTAINER.equals(model.getPersistenceType())) { 75 keys.add(KEY.CMP_FIELDS); 76 } 77 setKeys(keys); 78 } 79 }); 80 } 81 82 protected void removeNotify() { 83 model.removePropertyChangeListener(this); 84 srcPath.removePropertyChangeListener(this); 85 setKeys(Collections.<KEY>emptySet()); 86 super.removeNotify(); 87 } 88 89 protected Node[] createNodes(KEY key) { 90 return null; 112 } 113 114 public void propertyChange(PropertyChangeEvent propertyChangeEvent) { 115 SwingUtilities.invokeLater(new Runnable () { 117 public void run() { 118 updateKeys(); 119 } 120 }); 121 } 122 123 } 124 | Popular Tags |