KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 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 package org.eclipse.ant.internal.ui.model;
12
13 import java.io.File JavaDoc;
14
15 import org.apache.tools.ant.Task;
16 import org.apache.tools.ant.util.FileUtils;
17 import org.eclipse.ant.internal.ui.editor.AntEditorCompletionProcessor;
18 import org.xml.sax.Attributes JavaDoc;
19
20 public class AntAntNode extends AntTaskNode {
21
22     private String JavaDoc fFile;
23
24     public AntAntNode(Task task, Attributes JavaDoc attributes) {
25         super(task);
26         StringBuffer JavaDoc label= new StringBuffer JavaDoc("ant "); //$NON-NLS-1$
27
fFile= attributes.getValue(IAntModelConstants.ATTR_DIR);
28         if (fFile != null) {
29             if (!FileUtils.isAbsolutePath(fFile)) {
30                 File JavaDoc basedir= task.getProject().getBaseDir();
31                 if (basedir != null) {
32                     fFile= basedir.getAbsolutePath() + File.separatorChar + fFile;
33                 }
34             }
35             label.append(fFile);
36             label.append(File.separatorChar);
37         } else {
38             File JavaDoc basedir= task.getProject().getBaseDir();
39             if (basedir != null) {
40                 fFile=basedir.getAbsolutePath();
41             }
42         }
43         String JavaDoc fileName = attributes.getValue(IAntModelConstants.ATTR_ANT_FILE);
44         if (fileName == null) {
45             fileName= "build.xml"; //$NON-NLS-1$
46
}
47         label.append(fileName);
48         if (fFile == null || FileUtils.isAbsolutePath(fileName)) {
49             fFile= fileName;
50         } else {
51             fFile+=File.separatorChar + fileName;
52         }
53         
54         String JavaDoc more = attributes.getValue(IAntModelConstants.ATTR_TARGET);
55         if(more != null) {
56             label.append(' ');
57             label.append(more);
58         }
59         setBaseLabel(label.toString());
60     }
61     
62     /* (non-Javadoc)
63      * @see org.eclipse.ant.internal.ui.model.AntElementNode#getReferencedElement(int)
64      */

65     public String JavaDoc getReferencedElement(int offset) {
66         if (fFile != null) {
67             String JavaDoc textToSearch= getAntModel().getText(getOffset(), offset - getOffset());
68             if (textToSearch != null && textToSearch.length() != 0) {
69                 String JavaDoc attributeString = AntEditorCompletionProcessor.getAttributeStringFromDocumentStringToPrefix(textToSearch);
70                 if (IAntModelConstants.ATTR_ANT_FILE.equals(attributeString)) {
71                     return fFile;
72                 }
73             }
74         }
75         return null;
76     }
77 }
78
Popular Tags