KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.tools.ant.BuildException;
15 import org.apache.tools.ant.Task;
16 import org.eclipse.ant.core.AntSecurityException;
17 import org.eclipse.ant.internal.ui.AntUIImages;
18 import org.eclipse.ant.internal.ui.AntUtil;
19 import org.eclipse.ant.internal.ui.IAntUIConstants;
20 import org.eclipse.ant.internal.ui.editor.AntEditorCompletionProcessor;
21 import org.eclipse.ant.internal.ui.preferences.AntEditorPreferenceConstants;
22 import org.eclipse.core.resources.IFile;
23 import org.eclipse.jface.resource.ImageDescriptor;
24 import org.xml.sax.Attributes JavaDoc;
25
26 public class AntImportNode extends AntTaskNode {
27     
28     private String JavaDoc fFile= null;
29     
30     public AntImportNode(Task task, Attributes JavaDoc attributes) {
31         super(task);
32          fFile= attributes.getValue(IAntModelConstants.ATTR_FILE);
33     }
34     
35     public String JavaDoc getFile() {
36         return fFile;
37     }
38     
39     /* (non-Javadoc)
40      * @see org.eclipse.ant.internal.ui.editor.model.AntElementNode#getBaseImageDescriptor()
41      */

42     protected ImageDescriptor getBaseImageDescriptor() {
43         return AntUIImages.getImageDescriptor(IAntUIConstants.IMG_ANT_IMPORT);
44     }
45     
46     public String JavaDoc getLabel() {
47         if (fLabel == null) {
48             StringBuffer JavaDoc label= new StringBuffer JavaDoc(getTask().getTaskName());
49             label.append(' ');
50             label.append(fFile);
51             
52             if (isExternal()) {
53                 appendEntityName(label);
54             }
55             fLabel= label.toString();
56         }
57         return fLabel;
58     }
59
60     /**
61      * Execute the import.
62      * Returns <code>true</code> as the import adds to the Ant model
63      */

64     public boolean configure(boolean validateFully) {
65         if (fConfigured) {
66             return false;
67         }
68         try {
69             getTask().maybeConfigure();
70             getTask().execute();
71             fConfigured= true;
72             return true;
73         } catch (BuildException be) {
74             handleBuildException(be, AntEditorPreferenceConstants.PROBLEM_IMPORTS);
75         } catch (AntSecurityException se) {
76             //either a system exit or setting of system property was attempted
77
handleBuildException(new BuildException(AntModelMessages.AntImportNode_0), AntEditorPreferenceConstants.PROBLEM_SECURITY);
78         }
79         return false;
80     }
81     
82     public IFile getIFile() {
83         IFile file;
84         if (isExternal()) {
85             file= AntUtil.getFileForLocation(getFilePath(), null);
86         } else {
87             String JavaDoc path= getFile();
88             file= AntUtil.getFileForLocation(path, getAntModel().getEditedFile().getParentFile());
89         }
90         return file;
91     }
92     
93     /* (non-Javadoc)
94      * @see org.eclipse.ant.internal.ui.model.AntElementNode#getReferencedElement(int)
95      */

96     public String JavaDoc getReferencedElement(int offset) {
97         if (fFile != null) {
98             String JavaDoc textToSearch= getAntModel().getText(getOffset(), offset - getOffset());
99             if (textToSearch != null && textToSearch.length() != 0) {
100                 String JavaDoc attributeString = AntEditorCompletionProcessor.getAttributeStringFromDocumentStringToPrefix(textToSearch);
101                 if (IAntModelConstants.ATTR_FILE.equals(attributeString)) {
102                     return fFile;
103                 }
104             }
105         }
106         return null;
107     }
108 }
109
Popular Tags