1 11 12 package org.eclipse.ant.internal.ui.model; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 import org.apache.tools.ant.Project; 18 import org.eclipse.ant.internal.ui.AntUIImages; 19 import org.eclipse.ant.internal.ui.IAntUIConstants; 20 import org.eclipse.core.resources.IFile; 21 import org.eclipse.jface.resource.ImageDescriptor; 22 import org.eclipse.jface.text.IRegion; 23 24 25 public class AntProjectNode extends AntElementNode { 26 27 protected AntModelProject fProject; 28 protected IAntModel fModel; 29 protected String fLabel; 30 31 public AntProjectNode(AntModelProject project, IAntModel antModel) { 32 super("project"); fProject= project; 34 fModel= antModel; 35 } 36 37 40 public String getLabel() { 41 if (fLabel == null) { 42 if (fProject != null) { 43 fLabel= fProject.getName(); 44 } else { 45 fLabel= AntModelMessages.AntProjectNode_0; 46 } 47 if (fLabel == null || fLabel.length() == 0) { 48 fLabel= "project"; } 50 } 51 return fLabel; 52 } 53 54 57 protected ImageDescriptor getBaseImageDescriptor() { 58 return AntUIImages.getImageDescriptor(IAntUIConstants.IMG_ANT_PROJECT); 59 } 60 61 65 public Project getProject() { 66 return fProject; 67 } 68 69 protected IAntModel getAntModel() { 70 return fModel; 71 } 72 73 76 public void reset() { 77 super.reset(); 78 fProject.reset(); 79 setProblemSeverity(AntModelProblem.NO_PROBLEM); 80 setProblemMessage(null); 81 fOffset= -1; 82 fLength= -1; 83 } 84 85 public String getDescription() { 86 return fProject.getDescription(); 87 } 88 89 public String getBuildFileName() { 90 LocationProvider locationProvider= getAntModel().getLocationProvider(); 91 if (locationProvider != null) { 92 IFile file= locationProvider.getFile(); 93 if (file != null) { 94 return file.getFullPath().toOSString(); 95 } 96 } 97 return null; 98 } 99 100 public String getDefaultTargetName() { 101 return fProject.getDefaultTarget(); 102 } 103 104 107 public void setCurrentConfiguringProperty(AntPropertyNode node) { 108 AntModelProject project= (AntModelProject) getProject(); 109 project.setCurrentConfiguringProperty(node); 110 } 111 112 115 public AntProjectNode getProjectNode() { 116 return this; 117 } 118 119 122 public boolean containsOccurrence(String identifier) { 123 return identifier.equals(getDefaultTargetName()); 124 } 125 126 public List computeIdentifierOffsets(String identifier) { 127 String textToSearch= getAntModel().getText(getOffset(), getLength()); 128 if (textToSearch == null || textToSearch.length() == 0 || identifier.length() == 0) { 129 return null; 130 } 131 List results= new ArrayList (1); 132 identifier= new StringBuffer ("\"").append(identifier).append('"').toString(); int defaultTargetNameOffset= textToSearch.indexOf("default"); defaultTargetNameOffset= textToSearch.indexOf(identifier, defaultTargetNameOffset); 135 results.add(new Integer (getOffset() + defaultTargetNameOffset + 1)); 136 return results; 137 } 138 139 142 public boolean isRegionPotentialReference(IRegion region) { 143 if (!super.isRegionPotentialReference(region)) { 144 return false; 145 } 146 147 String textToSearch= getAntModel().getText(getOffset(), getLength()); 148 if (textToSearch == null) { 149 return false; 150 } 151 152 return checkReferenceRegion(region, textToSearch, "default"); } 154 } | Popular Tags |