1 19 20 package org.netbeans.modules.web.project.ui; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.util.ArrayList ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import javax.swing.SwingUtilities ; 28 import javax.swing.event.ChangeEvent ; 29 import javax.swing.event.ChangeListener ; 30 import org.netbeans.api.project.Project; 31 import org.netbeans.modules.j2ee.spi.ejbjar.support.J2eeProjectView; 32 import org.netbeans.modules.web.project.WebProject; 33 import org.netbeans.spi.project.ui.support.NodeFactory; 34 import org.netbeans.spi.project.ui.support.NodeList; 35 import org.openide.nodes.Node; 36 37 41 public final class SetupDirNodeFactory implements NodeFactory { 42 43 44 public SetupDirNodeFactory() { 45 } 46 47 public NodeList createNodes(Project p) { 48 WebProject project = (WebProject) p.getLookup().lookup(WebProject.class); 49 assert project != null; 50 return new SetupDirNodeList(project); 51 } 52 53 private static class SetupDirNodeList implements NodeList<String >, PropertyChangeListener { 54 private static final String SETUP_DIR = "setupDir"; 56 private final WebProject project; 57 private final ArrayList <ChangeListener > listeners = new ArrayList <ChangeListener >(); 58 59 SetupDirNodeList(WebProject proj) { 60 project = proj; 61 WebLogicalViewProvider logView = (WebLogicalViewProvider) project.getLookup().lookup(WebLogicalViewProvider.class); 62 assert logView != null; 63 } 64 65 public List <String > keys() { 66 List <String > result = new ArrayList <String >(); 67 result.add(SETUP_DIR); 68 return result; 69 } 70 71 public synchronized void addChangeListener(ChangeListener l) { 72 listeners.add(l); 73 } 74 75 public synchronized void removeChangeListener(ChangeListener l) { 76 listeners.remove(l); 77 } 78 79 private void fireChange() { 80 ArrayList <ChangeListener > list = new ArrayList <ChangeListener >(); 81 synchronized (this) { 82 list.addAll(listeners); 83 } 84 Iterator <ChangeListener > it = list.iterator(); 85 while (it.hasNext()) { 86 ChangeListener elem = it.next(); 87 elem.stateChanged(new ChangeEvent ( this )); 88 } 89 } 90 91 public Node node(String key) { 92 if (key == SETUP_DIR) { 93 return J2eeProjectView.createServerResourcesNode(project); 94 } 95 assert false: "No node for key: " + key; 96 return null; 97 } 98 99 public void addNotify() { 100 } 101 102 public void removeNotify() { 103 } 104 105 public void propertyChange(PropertyChangeEvent evt) { 106 SwingUtilities.invokeLater(new Runnable () { 108 public void run() { 109 fireChange(); 110 } 111 }); 112 } 113 114 } 115 116 } 117 | Popular Tags |