1 19 20 package org.netbeans.modules.ruby.railsprojects.ui; 21 22 import java.awt.Component ; 23 import java.awt.Image ; 24 import java.awt.Panel ; 25 import java.io.IOException ; 26 import java.net.URI ; 27 import java.net.URL ; 28 import java.net.MalformedURLException ; 29 import java.io.File ; 30 import java.text.MessageFormat ; 31 import java.util.Arrays ; 32 import java.util.Collection ; 33 import java.util.HashSet ; 34 import java.util.Set ; 35 import java.util.ArrayList ; 36 import java.util.List ; 37 import javax.swing.Action ; 38 import javax.swing.Icon ; 39 import org.netbeans.api.project.FileOwnerQuery; 40 import org.netbeans.api.project.ProjectUtils; 41 import org.openide.ErrorManager; 42 import org.openide.filesystems.FileUtil; 43 import org.openide.nodes.AbstractNode; 44 import org.openide.nodes.Children; 45 import org.openide.nodes.Node; 46 import org.openide.util.Lookup; 47 import org.openide.util.NbBundle; 48 import org.openide.util.Utilities; 49 import org.openide.util.HelpCtx; 50 import org.openide.util.lookup.Lookups; 51 import org.openide.util.actions.SystemAction; 52 import org.openide.util.actions.NodeAction; 53 import org.netbeans.api.project.Project; 54 import org.netbeans.api.project.ProjectInformation; 55 import org.netbeans.api.project.ProjectManager; 56 import org.netbeans.modules.ruby.api.project.rake.RakeArtifact; 57 import org.netbeans.api.project.ui.OpenProjects; 58 import org.netbeans.modules.ruby.spi.project.support.rake.EditableProperties; 59 import org.netbeans.modules.ruby.spi.project.support.rake.RakeProjectHelper; 60 import org.netbeans.modules.ruby.spi.project.support.rake.PropertyUtils; 61 import org.netbeans.modules.ruby.spi.project.support.rake.ReferenceHelper; 62 import org.netbeans.modules.ruby.railsprojects.UpdateHelper; 63 64 65 66 73 class ProjectNode extends AbstractNode { 74 75 private static final String PROJECT_ICON = "org/netbeans/modules/ruby/railsprojects/ui/resources/projectDependencies.gif"; 77 private final RakeArtifact antArtifact; 78 private final URI artifactLocation; 79 private Image cachedIcon; 80 81 ProjectNode (RakeArtifact antArtifact, URI artifactLocation, UpdateHelper helper,ReferenceHelper refHelper, String classPathId, String entryId) { 82 super (Children.LEAF, createLookup (antArtifact, artifactLocation, helper, refHelper, classPathId, entryId)); 83 this.antArtifact = antArtifact; 84 this.artifactLocation = artifactLocation; 85 } 86 87 public String getDisplayName () { 88 ProjectInformation info = getProjectInformation(); 89 if (info != null) { 90 return MessageFormat.format(NbBundle.getMessage(ProjectNode.class,"TXT_ProjectArtifactFormat"), 91 new Object [] {info.getDisplayName(), artifactLocation.toString()}); 92 } 93 else { 94 return NbBundle.getMessage (ProjectNode.class,"TXT_UnknownProjectName"); 95 } 96 } 97 98 public String getName () { 99 return this.getDisplayName(); 100 } 101 102 public Image getIcon(int type) { 103 if (cachedIcon == null) { 104 ProjectInformation info = getProjectInformation(); 105 if (info != null) { 106 Icon icon = info.getIcon(); 107 cachedIcon = Utilities.icon2Image(icon); 108 } 109 else { 110 cachedIcon = Utilities.loadImage(PROJECT_ICON); 111 } 112 } 113 return cachedIcon; 114 } 115 116 public Image getOpenedIcon(int type) { 117 return this.getIcon(type); 118 } 119 120 public boolean canCopy() { 121 return false; 122 } 123 124 public Action [] getActions(boolean context) { 125 return new Action [] { 126 SystemAction.get (OpenProjectAction.class), 127 SystemAction.get (ShowRDocAction.class), 128 SystemAction.get (RemoveClassPathRootAction.class), 129 }; 130 } 131 132 public Action getPreferredAction () { 133 return getActions(false)[0]; 134 } 135 136 private ProjectInformation getProjectInformation () { 137 Project p = this.antArtifact.getProject(); 138 if (p != null) { 139 return ProjectUtils.getInformation(p); 140 } 141 return null; 142 } 143 144 private static Lookup createLookup (RakeArtifact antArtifact, URI artifactLocation, 145 UpdateHelper helper, ReferenceHelper refHelper, String classPathId, String entryId) { 146 Project p = antArtifact.getProject(); 147 Object [] content; 148 if (p == null) { 158 content = new Object [0]; 159 } else { 160 content = new Object [1]; 161 content[0] = p; 163 } 164 Lookup lkp = Lookups.fixed(content); 165 return lkp; 166 } 167 168 private static class OpenProjectAction extends NodeAction { 169 170 protected void performAction(Node[] activatedNodes) { 171 Project[] projects = new Project[activatedNodes.length]; 172 for (int i=0; i<projects.length;i++) { 173 projects[i] = (Project) activatedNodes[i].getLookup().lookup(Project.class); 174 } 175 OpenProjects.getDefault().open(projects, false); 176 } 177 178 protected boolean enable(Node[] activatedNodes) { 179 final Collection openedProjects =Arrays.asList(OpenProjects.getDefault().getOpenProjects()); 180 for (int i=0; i<activatedNodes.length; i++) { 181 Project p; 182 if ((p = (Project) activatedNodes[i].getLookup().lookup(Project.class)) == null) { 183 return false; 184 } 185 if (openedProjects.contains(p)) { 186 return false; 187 } 188 } 189 return true; 190 } 191 192 public String getName() { 193 return NbBundle.getMessage (ProjectNode.class,"CTL_OpenProject"); 194 } 195 196 public HelpCtx getHelpCtx() { 197 return new HelpCtx (OpenProjectAction.class); 198 } 199 200 protected boolean asynchronous() { 201 return false; 202 } 203 } 204 } 205 | Popular Tags |