001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019: package org.netbeans.modules.bpel.project.ui.customizer;
020:
021: import javax.swing.Icon;
022: import javax.swing.ImageIcon;
023: import org.netbeans.api.project.ant.AntArtifact;
024: import org.netbeans.api.project.libraries.Library;
025: import org.netbeans.api.project.*;
026: import org.netbeans.spi.project.support.ant.AntProjectHelper;
027: import org.openide.util.Utilities;
028: import org.netbeans.modules.compapp.projects.base.ui.customizer.IcanproProjectProperties;
029:
030: import java.net.URI;
031:
032: /** Represents classpath items of various types. Can be used in the model
033: * of classpath editing controls.
034: *
035: * @author phrebejk
036: */
037: public class VisualClassPathItem {
038:
039: // Types of the classpath elements
040: public static final int TYPE_JAR = 0;
041: public static final int TYPE_LIBRARY = 1; // XXX Not used yet
042: public static final int TYPE_ARTIFACT = 2;
043: public static final int TYPE_CLASSPATH = 3; // XXX Not used yet
044:
045: private static String RESOURCE_ICON_JAR = "org/netbeans/modules/bpel/project/ui/resources/jar.gif"; //NOI18N
046: private static String RESOURCE_ICON_LIBRARY = "org/netbeans/modules/bpel/project/ui/resources/libraries.gif"; //NOI18N
047: private static String RESOURCE_ICON_ARTIFACT = "org/netbeans/modules/bpel/project/ui/resources/projectDependencies.gif"; //NOI18N
048: private static String RESOURCE_ICON_CLASSPATH = "org/netbeans/modules/bpel/project/ui/resources/j2seProject.gif"; //NOI18N
049:
050: private static Icon ICON_JAR = new ImageIcon(Utilities
051: .loadImage(RESOURCE_ICON_JAR));
052: private static Icon ICON_LIBRARY = new ImageIcon(Utilities
053: .loadImage(RESOURCE_ICON_LIBRARY));
054: private static Icon ICON_ARTIFACT = new ImageIcon(Utilities
055: .loadImage(RESOURCE_ICON_ARTIFACT));
056: private static Icon ICON_CLASSPATH = new ImageIcon(Utilities
057: .loadImage(RESOURCE_ICON_CLASSPATH));
058:
059: private int type;
060: private Object cpElement;
061: private String raw;
062: private String eval;
063: private boolean inDeployment;
064:
065: private String shortName;
066: private String projectName;
067: private String asaType;
068:
069: public VisualClassPathItem(Object cpElement, int type, String raw,
070: String eval, boolean inDeployment) {
071: String src;
072: this .cpElement = cpElement;
073: this .type = type;
074: this .raw = raw;
075: this .eval = eval;
076: this .inDeployment = inDeployment;
077:
078: if (cpElement instanceof AntArtifact) {
079: AntArtifact aa = (AntArtifact) cpElement;
080:
081: Project p = aa.getProject();
082: ProjectInformation info = (ProjectInformation) p
083: .getLookup().lookup(ProjectInformation.class);
084: if (info != null) {
085: projectName = info.getName();
086: AntProjectHelper ah = (AntProjectHelper) p.getLookup()
087: .lookup(AntProjectHelper.class);
088: if (ah != null) {
089: src = ah.getStandardPropertyEvaluator()
090: .getProperty(
091: IcanproProjectProperties.SRC_DIR);
092: } else {
093: src = (aa.getArtifactLocations()[0]).toString(); //TBD temp test
094: }
095:
096: shortName = projectName
097: + " ("
098: + info.getProject().getProjectDirectory()
099: .getPath() + ")";
100: }
101:
102: // extract the JBI component type info
103: String aType = aa.getType();
104: int idx = aType.indexOf(':');
105: if (idx > 0) {
106: asaType = aType.substring(idx + 1);
107: }
108: }
109:
110: }
111:
112: public Object getObject() {
113: return cpElement;
114: }
115:
116: public int getType() {
117: return type;
118: }
119:
120: public String getRaw() {
121: return raw;
122: }
123:
124: public Boolean isInDeployment() {
125: return Boolean.valueOf(inDeployment);
126: }
127:
128: public void setInDeployment(Boolean inDeployment) {
129: this .inDeployment = inDeployment.booleanValue();
130: }
131:
132: public String getEvaluated() {
133: return eval == null ? getRaw() : eval;
134: }
135:
136: public boolean canDelete() {
137: return getType() != TYPE_CLASSPATH;
138: }
139:
140: public Icon getIcon() {
141:
142: switch (getType()) {
143: case TYPE_JAR:
144: return ICON_JAR;
145: case TYPE_LIBRARY:
146: return ICON_LIBRARY;
147: case TYPE_ARTIFACT:
148: return ICON_ARTIFACT;
149: case TYPE_CLASSPATH:
150: return ICON_CLASSPATH;
151: default:
152: return null;
153: }
154:
155: }
156:
157: private URI getArtifactLocation(AntArtifact artifact) {
158: URI[] us = artifact.getArtifactLocations();
159: if ((us != null) && (us.length > 0)) {
160: return us[0];
161: }
162: return null;
163: }
164:
165: public int hashCode() {
166:
167: int hash = getType();
168:
169: switch (getType()) {
170: case TYPE_ARTIFACT:
171: AntArtifact aa = (AntArtifact) getObject();
172:
173: hash += aa.getType().hashCode();
174: hash += aa.getScriptLocation().hashCode();
175: hash += getArtifactLocation(aa).hashCode();
176: break;
177: default:
178: hash += getObject().hashCode();
179: break;
180: }
181:
182: return hash;
183: }
184:
185: public boolean equals(Object object) {
186:
187: if (!(object instanceof VisualClassPathItem)) {
188: return false;
189: }
190: VisualClassPathItem vcpi = (VisualClassPathItem) object;
191:
192: if (getType() != vcpi.getType()) {
193: return false;
194: }
195:
196: switch (getType()) {
197: case TYPE_ARTIFACT:
198: AntArtifact aa1 = (AntArtifact) getObject();
199: AntArtifact aa2 = (AntArtifact) vcpi.getObject();
200:
201: if (aa1.getType() != aa2.getType()) {
202: return false;
203: }
204:
205: if (!aa1.getScriptLocation()
206: .equals(aa2.getScriptLocation())) {
207: return false;
208: }
209:
210: if (!getArtifactLocation(aa1).equals(
211: getArtifactLocation(aa2))) {
212: return false;
213: }
214:
215: return true;
216: default:
217: return getObject().equals(vcpi.getObject());
218: }
219:
220: }
221:
222: public String toString() {
223: switch (getType()) {
224: case TYPE_JAR:
225: return getEvaluated();
226: case TYPE_LIBRARY:
227: return ((Library) this .getObject()).getDisplayName();
228: case TYPE_ARTIFACT:
229: return shortName; // getEvaluated();
230: case TYPE_CLASSPATH:
231: return getEvaluated();
232: default:
233: assert true : "Unknown item type"; // NOI18N
234: return getEvaluated();
235: }
236: }
237: }
|