1 19 20 package org.netbeans.modules.apisupport.project.ui; 21 22 import java.awt.Image ; 23 import java.beans.PropertyChangeEvent ; 24 import java.beans.PropertyChangeListener ; 25 import java.util.Enumeration ; 26 import java.util.HashSet ; 27 import java.util.Set ; 28 import javax.swing.Action ; 29 import org.netbeans.api.project.FileOwnerQuery; 30 import org.netbeans.api.project.ProjectInformation; 31 import org.netbeans.api.project.ProjectUtils; 32 import org.netbeans.modules.apisupport.project.suite.SuiteProject; 33 import org.netbeans.spi.project.ui.LogicalViewProvider; 34 import org.netbeans.spi.project.ui.support.DefaultProjectOperations; 35 import org.netbeans.spi.project.ui.support.NodeFactorySupport; 36 import org.openide.filesystems.FileObject; 37 import org.openide.filesystems.FileUtil; 38 import org.openide.loaders.DataObject; 39 import org.openide.loaders.DataObjectNotFoundException; 40 import org.openide.nodes.Node; 41 import org.openide.util.NbBundle; 42 import org.openide.util.Utilities; 43 import org.openide.util.WeakListeners; 44 import org.openide.util.lookup.Lookups; 45 46 51 public final class SuiteLogicalView implements LogicalViewProvider { 52 53 private final SuiteProject suite; 54 55 public SuiteLogicalView(final SuiteProject suite) { 56 this.suite = suite; 57 } 58 59 public Node createLogicalView() { 60 return new SuiteRootNode(suite); 61 } 62 63 public Node findPath(Node root, Object target) { 64 if (root.getLookup().lookup(SuiteProject.class) != suite) { 65 return null; 67 } 68 69 DataObject file; 70 if (target instanceof FileObject) { 71 try { 72 file = DataObject.find((FileObject) target); 73 } catch (DataObjectNotFoundException e) { 74 return null; } 76 } else if (target instanceof DataObject) { 77 file = (DataObject) target; 78 } else { 79 return null; 81 } 82 83 Node impFilesNode = root.getChildren().findChild("important.files"); if (impFilesNode != null) { 85 Node[] impFiles = impFilesNode.getChildren().getNodes(true); 86 for (int i = 0; i < impFiles.length; i++) { 87 if (impFiles[i].getCookie(DataObject.class) == file) { 88 return impFiles[i]; 89 } 90 } 91 } 92 93 return null; 94 } 95 96 97 static final class SuiteRootNode extends AnnotatedNode 98 implements PropertyChangeListener { 99 100 private static final Image ICON = Utilities.loadImage(SuiteProject.SUITE_ICON_PATH, true); 101 102 private final SuiteProject suite; 103 private final ProjectInformation info; 104 105 SuiteRootNode(final SuiteProject suite) { 106 super(NodeFactorySupport.createCompositeChildren(suite, "Projects/org-netbeans-modules-apisupport-project-suite/Nodes"), 107 Lookups.fixed(new Object [] {suite})); 108 this.suite = suite; 109 info = ProjectUtils.getInformation(suite); 110 info.addPropertyChangeListener(WeakListeners.propertyChange(this, info)); 111 setFiles(getProjectFiles()); 112 } 113 114 115 Set getProjectFiles() { 116 Set files = new HashSet (); 117 Enumeration en = suite.getProjectDirectory().getChildren(false); 118 while (en.hasMoreElements()) { 119 FileObject child = (FileObject) en.nextElement(); 120 if (FileOwnerQuery.getOwner(child) == suite) { 121 files.add(child); 122 } 123 } 124 return files; 125 } 126 127 public String getName() { 128 return info.getDisplayName(); 129 } 130 131 public String getDisplayName() { 132 return info.getDisplayName(); 133 } 134 135 public String getShortDescription() { 136 return NbBundle.getMessage(SuiteLogicalView.class, "HINT_suite_project_root_node", 137 FileUtil.getFileDisplayName(suite.getProjectDirectory())); 138 } 139 140 public Action [] getActions(boolean context) { 141 return SuiteActions.getProjectActions(suite); 142 } 143 144 public Image getIcon(int type) { 145 return annotateIcon(ICON, type); 146 } 147 148 public Image getOpenedIcon(int type) { 149 return getIcon(type); } 151 152 public void propertyChange(PropertyChangeEvent evt) { 153 if (evt.getPropertyName().equals(ProjectInformation.PROP_NAME)) { 154 fireNameChange(null, getName()); 155 } else if (evt.getPropertyName().equals(ProjectInformation.PROP_DISPLAY_NAME)) { 156 fireDisplayNameChange(null, getDisplayName()); 157 } 158 } 159 160 public boolean canRename() { 161 return true; 162 } 163 164 public void setName(String name) { 165 DefaultProjectOperations.performDefaultRenameOperation(suite, name); 166 } 167 168 } 169 } 170 | Popular Tags |