KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > model > AntProjectNode


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ant.internal.ui.model;
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.List JavaDoc;
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 JavaDoc fLabel;
30     
31     public AntProjectNode(AntModelProject project, IAntModel antModel) {
32         super("project"); //$NON-NLS-1$
33
fProject= project;
34         fModel= antModel;
35     }
36     
37     /* (non-Javadoc)
38      * @see org.eclipse.ant.internal.ui.model.AntElementNode#getLabel()
39      */

40     public String JavaDoc 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"; //$NON-NLS-1$
49
}
50         }
51         return fLabel;
52     }
53     
54     /* (non-Javadoc)
55      * @see org.eclipse.ant.internal.ui.editor.model.AntElementNode#getBaseImageDescriptor()
56      */

57     protected ImageDescriptor getBaseImageDescriptor() {
58         return AntUIImages.getImageDescriptor(IAntUIConstants.IMG_ANT_PROJECT);
59     }
60
61     /**
62      * Returns the Ant project associated with this project node.
63      * @return the Ant project
64      */

65     public Project getProject() {
66         return fProject;
67     }
68     
69     protected IAntModel getAntModel() {
70         return fModel;
71     }
72     
73     /* (non-Javadoc)
74      * @see org.eclipse.ant.internal.ui.editor.model.AntElementNode#reset()
75      */

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 JavaDoc getDescription() {
86         return fProject.getDescription();
87     }
88
89     public String JavaDoc 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 JavaDoc getDefaultTargetName() {
101         return fProject.getDefaultTarget();
102     }
103     
104     /**
105      * @param node the property node that is currently being configured
106      */

107     public void setCurrentConfiguringProperty(AntPropertyNode node) {
108         AntModelProject project= (AntModelProject) getProject();
109         project.setCurrentConfiguringProperty(node);
110     }
111     
112     /* (non-Javadoc)
113      * @see org.eclipse.ant.internal.ui.model.AntElementNode#getProjectNode()
114      */

115     public AntProjectNode getProjectNode() {
116         return this;
117     }
118
119     /* (non-Javadoc)
120      * @see org.eclipse.ant.internal.ui.model.AntElementNode#containsOccurrence(java.lang.String)
121      */

122     public boolean containsOccurrence(String JavaDoc identifier) {
123         return identifier.equals(getDefaultTargetName());
124     }
125     
126     public List JavaDoc computeIdentifierOffsets(String JavaDoc identifier) {
127         String JavaDoc textToSearch= getAntModel().getText(getOffset(), getLength());
128         if (textToSearch == null || textToSearch.length() == 0 || identifier.length() == 0) {
129             return null;
130         }
131         List JavaDoc results= new ArrayList JavaDoc(1);
132         identifier= new StringBuffer JavaDoc("\"").append(identifier).append('"').toString(); //$NON-NLS-1$
133
int defaultTargetNameOffset= textToSearch.indexOf("default"); //$NON-NLS-1$
134
defaultTargetNameOffset= textToSearch.indexOf(identifier, defaultTargetNameOffset);
135         results.add(new Integer JavaDoc(getOffset() + defaultTargetNameOffset + 1));
136         return results;
137     }
138     
139     /* (non-Javadoc)
140      * @see org.eclipse.ant.internal.ui.model.AntElementNode#isRegionPotentialReference(org.eclipse.jface.text.IRegion)
141      */

142     public boolean isRegionPotentialReference(IRegion region) {
143         if (!super.isRegionPotentialReference(region)) {
144             return false;
145         }
146         
147         String JavaDoc textToSearch= getAntModel().getText(getOffset(), getLength());
148         if (textToSearch == null) {
149             return false;
150         }
151         
152         return checkReferenceRegion(region, textToSearch, "default"); //$NON-NLS-1$
153
}
154 }
Popular Tags