KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Enumeration JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.apache.tools.ant.Target;
18 import org.eclipse.ant.internal.ui.editor.outline.XMLProblem;
19 import org.eclipse.ant.internal.ui.model.AntUIImages;
20 import org.eclipse.ant.internal.ui.model.IAntUIConstants;
21 import org.eclipse.jface.resource.ImageDescriptor;
22
23 public class AntTargetNode extends AntElementNode {
24
25     private Target fTarget= null;
26     
27     public AntTargetNode(Target target) {
28         super("target"); //$NON-NLS-1$
29
fTarget= target;
30     }
31     
32     /* (non-Javadoc)
33      * @see org.eclipse.ant.internal.ui.editor.model.AntElementNode#getDisplayName()
34      */

35     public String JavaDoc getLabel() {
36         String JavaDoc targetName= fTarget.getName();
37         if (targetName == null) {
38             targetName= "target"; //$NON-NLS-1$
39
setProblemSeverity(XMLProblem.SEVERITY_ERROR);
40         }
41         
42         StringBuffer JavaDoc displayName= new StringBuffer JavaDoc(targetName);
43         if (isDefaultTarget()) {
44             displayName.append(AntModelMessages.getString("AntTargetNode.2")); //$NON-NLS-1$
45
}
46         if (isExternal()) {
47             appendEntityName(displayName);
48         }
49         
50         return displayName.toString();
51     }
52     
53     public Target getTarget() {
54         return fTarget;
55     }
56     
57     public boolean isDefaultTarget() {
58         String JavaDoc targetName= fTarget.getName();
59         if (targetName == null) {
60             return false;
61         }
62         return targetName.equals(fTarget.getProject().getDefaultTarget());
63     }
64     
65     /* (non-Javadoc)
66      * @see org.eclipse.ant.internal.ui.editor.model.AntElementNode#getBaseImageDescriptor()
67      */

68     protected ImageDescriptor getBaseImageDescriptor() {
69         ImageDescriptor base= null;
70         if (isDefaultTarget()) {
71             base = AntUIImages.getImageDescriptor(IAntUIConstants.IMG_ANT_DEFAULT_TARGET);
72         } else if (getTarget().getDescription() == null) {
73             base = AntUIImages.getImageDescriptor(IAntUIConstants.IMG_ANT_TARGET_INTERNAL);
74         } else {
75             base = AntUIImages.getImageDescriptor(IAntUIConstants.IMG_ANT_TARGET);
76         }
77         return base;
78     }
79     /**
80      * @param target The Target to set.
81      */

82     public void setTarget(Target target) {
83         fTarget = target;
84     }
85     
86     /* (non-Javadoc)
87      * @see org.eclipse.ant.internal.ui.editor.model.AntElementNode#reset()
88      */

89     public void reset() {
90         super.reset();
91          Map JavaDoc currentTargets = fTarget.getProject().getTargets();
92          if (currentTargets.get(fTarget.getName()) != null) {
93             currentTargets.remove(fTarget.getName());
94          }
95     }
96
97     /**
98      * Returns the name of a missing dependency or <code>null</code> if all
99      * dependencies exist in the project.
100      */

101     public String JavaDoc checkDependencies() {
102         Enumeration JavaDoc dependencies= fTarget.getDependencies();
103         while (dependencies.hasMoreElements()) {
104             String JavaDoc dependency = (String JavaDoc) dependencies.nextElement();
105              if (fTarget.getProject().getTargets().get(dependency) == null) {
106                 return dependency;
107              }
108         }
109         return null;
110     }
111 }
Popular Tags