1 19 20 package org.netbeans.core; 21 22 import java.io.IOException ; 23 import java.util.ArrayList ; 24 import java.util.List ; 25 import java.util.StringTokenizer ; 26 import javax.swing.event.ChangeEvent ; 27 import javax.swing.event.ChangeListener ; 28 import org.openide.filesystems.FileObject; 29 import org.openide.filesystems.FileSystem; 30 import org.openide.filesystems.FileUtil; 31 import org.openide.filesystems.Repository; 32 import org.openide.loaders.DataFolder; 33 import org.openide.nodes.Node; 34 35 39 public final class NbPlaces extends Object { 40 private final List <ChangeListener > listeners = new ArrayList <ChangeListener >(); 41 42 44 private NbPlaces() { 45 } 46 47 private static NbPlaces DEFAULT; 48 49 51 public static synchronized NbPlaces getDefault() { 52 if (DEFAULT == null) { 53 DEFAULT = new NbPlaces(); 54 } 55 return DEFAULT; 56 } 57 58 public void addChangeListener(ChangeListener l) { 59 synchronized (listeners) { 60 listeners.add(l); 61 } 62 } 63 64 public void removeChangeListener(ChangeListener l) { 65 synchronized (listeners) { 66 listeners.remove(l); 67 } 68 } 69 70 void fireChange() { 71 ChangeListener [] l; 72 synchronized (listeners) { 73 l = listeners.toArray(new ChangeListener [listeners.size()]); 74 } 75 ChangeEvent ev = new ChangeEvent (this); 76 for (int i = 0; i < l.length; i++) { 77 l[i].stateChanged(ev); 78 } 79 } 80 81 84 public Node environment () { 85 return EnvironmentNode.find(EnvironmentNode.TYPE_ENVIRONMENT); 86 } 87 88 89 90 public Node session () { 91 return EnvironmentNode.find(EnvironmentNode.TYPE_SESSION); 92 } 93 94 96 public Node[] roots () { 97 return EnvironmentNode.find(EnvironmentNode.TYPE_ROOTS).getChildren ().getNodes (); 98 } 99 100 102 public DataFolder toolbars () { 103 return findSessionFolder ("Toolbars"); } 105 106 108 public DataFolder menus () { 109 return findSessionFolder ("Menu"); } 111 112 114 public DataFolder actions () { 115 return findSessionFolder ("Actions"); } 117 118 123 public static DataFolder findSessionFolder (String name) { 124 try { 125 FileSystem fs = Repository.getDefault().getDefaultFileSystem (); 126 FileObject fo = fs.findResource(name); 127 if (fo == null) { 128 fo = FileUtil.createFolder(fs.getRoot(), name); 130 } 131 return DataFolder.findFolder(fo); 132 } catch (IOException ex) { 133 throw (IllegalStateException ) new IllegalStateException ("Folder not found and cannot be created: " + name).initCause(ex); } 135 } 136 137 } 138 | Popular Tags |