KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

59     public boolean configure(boolean validateFully) {
60         if (configured) {
61             return false;
62         }
63         try {
64             getTask().maybeConfigure();
65             getTask().execute();
66             configured= true;
67             return true;
68         } catch (BuildException be) {
69             handleBuildException(be, AntEditorPreferenceConstants.PROBLEM_IMPORTS);
70         }
71         return false;
72     }
73     
74     public IFile getIFile() {
75         IFile file;
76         if (isExternal()) {
77             file= AntUtil.getFileForLocation(getFilePath(), null);
78         } else {
79             String JavaDoc path= getFile();
80             file= AntUtil.getFileForLocation(path, getAntModel().getEditedFile().getParentFile());
81         }
82         return file;
83     }
84 }
Popular Tags