KickJava   Java API By Example, From Geeks To Geeks.

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


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.editor.outline.XMLProblem;
17 import org.eclipse.ant.internal.ui.model.AntUIImages;
18 import org.eclipse.ant.internal.ui.model.IAntUIConstants;
19 import org.eclipse.ant.internal.ui.preferences.AntEditorPreferenceConstants;
20 import org.eclipse.jface.resource.ImageDescriptor;
21
22
23 public class AntTaskNode extends AntElementNode {
24
25     private Task fTask= null;
26     private String JavaDoc fLabel= null;
27     private String JavaDoc fId= null;
28     protected boolean configured= false;
29     
30     public AntTaskNode(Task task) {
31         super(task.getTaskName());
32         fTask= task;
33     }
34     
35     public AntTaskNode(Task task, String JavaDoc label) {
36         super(task.getTaskName());
37         fTask= task;
38         fLabel= label;
39     }
40     
41     public String JavaDoc getLabel() {
42         StringBuffer JavaDoc label= new StringBuffer JavaDoc();
43         if (fLabel != null) {
44             label.append(fLabel);
45         } else if (fId != null) {
46             label.append(fId);
47         } else {
48             label.append(fTask.getTaskName());
49         }
50         if (isExternal()) {
51             appendEntityName(label);
52         }
53         return label.toString();
54     }
55     
56     public void setLabel(String JavaDoc label) {
57         fLabel= label;
58     }
59     
60     public Task getTask() {
61         return fTask;
62     }
63     
64     public void setTask(Task task) {
65         fTask= task;
66     }
67     
68     protected ImageDescriptor getBaseImageDescriptor() {
69         if (fId != null) {
70             return AntUIImages.getImageDescriptor(IAntUIConstants.IMG_ANT_TYPE);
71         }
72         
73         return super.getBaseImageDescriptor();
74     }
75
76     /**
77      * The reference id for this task
78      * @param id The reference id for this task
79      */

80     public void setId(String JavaDoc id) {
81         fId= id;
82     }
83     
84     /**
85      * Returns the reference id for this task or <code>null</code>
86      * if it has no reference id.
87      * @return The reference id for this task
88      */

89     public String JavaDoc getId() {
90         return fId;
91     }
92     
93     /**
94      * Configures the associated task if required.
95      * Allows subclasses to do specific configuration (such as executing the task) by
96      * calling <code>nodeSpecificConfigure</code>
97      *
98      * @return whether the configuration of this node could have impact on other nodes
99      */

100     public boolean configure(boolean validateFully) {
101         if (!validateFully || (getParentNode() instanceof AntTaskNode)) {
102             return false;
103         }
104         if (configured) {
105             return false;
106         }
107         try {
108             getTask().maybeConfigure();
109             nodeSpecificConfigure();
110             configured= true;
111             return true;
112         } catch (BuildException be) {
113             handleBuildException(be, AntEditorPreferenceConstants.PROBLEM_TASKS);
114         }
115         return false;
116     }
117
118     protected void nodeSpecificConfigure() {
119         //by default do nothing
120
}
121
122     protected void handleBuildException(BuildException be, String JavaDoc preferenceKey) {
123         int severity= XMLProblem.getSeverity(preferenceKey);
124         if (severity != XMLProblem.NO_PROBLEM) {
125             getAntModel().handleBuildException(be, this, severity);
126         }
127     }
128 }
Popular Tags