001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.compapp.casaeditor.nodes;
043:
044: import java.awt.Image;
045: import java.util.ArrayList;
046: import java.util.HashSet;
047: import java.util.List;
048: import java.util.Set;
049: import javax.swing.Action;
050: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaWrapperModel;
051: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaComponent;
052: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaServiceEngineServiceUnit;
053: import org.netbeans.modules.compapp.casaeditor.nodes.actions.LoadWSDLPortsAction;
054: import org.netbeans.modules.compapp.casaeditor.nodes.actions.AddConsumesPinAction;
055: import org.netbeans.modules.compapp.casaeditor.nodes.actions.AddProvidesPinAction;
056: import org.netbeans.modules.compapp.casaeditor.properties.PropertyUtils;
057: import org.openide.nodes.Node;
058: import org.openide.nodes.PropertySupport;
059: import org.openide.nodes.Sheet;
060: import org.openide.util.NbBundle;
061: import org.openide.util.Utilities;
062: import org.openide.util.actions.SystemAction;
063:
064: import org.netbeans.modules.compapp.casaeditor.Constants;
065: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaEndpoint;
066: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaEndpointRef;
067: import org.netbeans.modules.compapp.casaeditor.model.casa.impl.CasaAttribute;
068:
069: /**
070: *
071: * @author Josh Sandusky
072: */
073: public class ServiceUnitNode extends CasaNode {
074:
075: private static final Image ICON = Utilities
076: .loadImage("org/netbeans/modules/compapp/casaeditor/nodes/resources/ServiceUnitNode.png"); // NOI18N
077:
078: private static final String CHILD_ID_PROVIDES_LIST = "ProvidesList"; // NOI18N
079: private static final String CHILD_ID_CONSUMES_LIST = "ConsumesList"; // NOI18N
080:
081: public ServiceUnitNode(CasaServiceEngineServiceUnit component,
082: CasaNodeFactory factory) {
083: super (component, new MyChildren(component, factory), factory);
084: }
085:
086: @Override
087: protected void addCustomActions(List<Action> actions) {
088: CasaServiceEngineServiceUnit su = (CasaServiceEngineServiceUnit) getData();
089: if (su == null) {
090: return;
091: }
092:
093: if (su.isInternal()) {
094: actions.add(SystemAction.get(LoadWSDLPortsAction.class));
095: } else {
096: actions.add(SystemAction.get(AddConsumesPinAction.class));
097: actions.add(SystemAction.get(AddProvidesPinAction.class));
098: }
099: }
100:
101: @Override
102: public String getName() {
103: CasaServiceEngineServiceUnit su = (CasaServiceEngineServiceUnit) getData();
104: if (su != null) {
105: return NbBundle.getMessage(getClass(), "LBL_ServiceUnit"); // NOI18N
106: }
107: return super .getName();
108: }
109:
110: @Override
111: public String getHtmlDisplayName() {
112: try {
113: String htmlDisplayName = getName();
114: CasaServiceEngineServiceUnit casaSU = (CasaServiceEngineServiceUnit) getData();
115: String decoration = null;
116: if (casaSU != null) {
117: decoration = NbBundle.getMessage(
118: WSDLEndpointNode.class, "LBL_NameAttr", // NOI18N
119: casaSU.getUnitName());
120: }
121: if (decoration == null) {
122: return htmlDisplayName;
123: }
124: return htmlDisplayName + " <font color='#999999'>"
125: + decoration + "</font>"; // NOI18N
126: } catch (Throwable t) {
127: // getHtmlDisplayName MUST recover gracefully.
128: return getBadName();
129: }
130: }
131:
132: @Override
133: protected void setupPropertySheet(Sheet sheet) {
134: final CasaServiceEngineServiceUnit casaSU = (CasaServiceEngineServiceUnit) getData();
135: if (casaSU == null) {
136: return;
137: }
138: Sheet.Set identificationProperties = getPropertySet(sheet,
139: PropertyUtils.PropertiesGroups.IDENTIFICATION_SET);
140:
141: PropertyUtils.installServiceUnitNameProperty(
142: identificationProperties, this , casaSU,
143: CasaAttribute.UNIT_NAME.getName(), "serviceUnitName", // NOI18N
144: NbBundle.getMessage(getClass(), "PROP_Name"), // NOI18N
145: NbBundle.getMessage(getClass(), "PROP_Name")); // NOI18N
146:
147: Node.Property<String> descriptionSupport = new PropertySupport.ReadOnly<String>(
148: "description", // NOI18N
149: String.class, NbBundle.getMessage(getClass(),
150: "PROP_Description"), // NOI18N
151: Constants.EMPTY_STRING) {
152: public String getValue() {
153: return casaSU.getDescription();
154: }
155: };
156: identificationProperties.put(descriptionSupport);
157:
158: Sheet.Set targetProperties = getPropertySet(sheet,
159: PropertyUtils.PropertiesGroups.TARGET_SET);
160: Node.Property<String> artifactsZipSupport = new PropertySupport.ReadOnly<String>(
161: "artifactsZip", // NOI18N
162: String.class, NbBundle.getMessage(getClass(),
163: "PROP_ArtifactsZip"), // NOI18N
164: Constants.EMPTY_STRING) {
165: public String getValue() {
166: return casaSU.getArtifactsZip();
167: }
168: };
169: targetProperties.put(artifactsZipSupport);
170:
171: Node.Property<String> componentNameSupport = new PropertySupport.ReadOnly<String>(
172: "componentName", // NOI18N
173: String.class, NbBundle.getMessage(getClass(),
174: "PROP_ComponentName"), // NOI18N
175: Constants.EMPTY_STRING) {
176: public String getValue() {
177: return casaSU.getComponentName();
178: }
179: };
180: targetProperties.put(componentNameSupport);
181: }
182:
183: private static class MyChildren extends CasaNodeChildren {
184: public MyChildren(CasaComponent component,
185: CasaNodeFactory factory) {
186: super (component, factory);
187: }
188:
189: protected Node[] createNodes(Object key) {
190: assert key instanceof String;
191: CasaServiceEngineServiceUnit serviceUnit = (CasaServiceEngineServiceUnit) getData();
192: if (serviceUnit != null) {
193: CasaWrapperModel model = mNodeFactory.getCasaModel();
194: if (model != null) {
195: String keyName = (String) key;
196: if (keyName.equals(CHILD_ID_CONSUMES_LIST)) {
197: return new Node[] { mNodeFactory
198: .createNode_consumesList(serviceUnit
199: .getConsumes()) };
200: } else if (keyName.equals(CHILD_ID_PROVIDES_LIST)) {
201: return new Node[] { mNodeFactory
202: .createNode_providesList(serviceUnit
203: .getProvides()) };
204: } else {
205: CasaEndpoint endpoint = getEndpoint(keyName);
206: return new Node[] { mNodeFactory
207: .createNode_process(endpoint) };
208: }
209: }
210: }
211: return null;
212: }
213:
214: @Override
215: public Object getChildKeys(Object data) {
216: List<String> children = new ArrayList<String>();
217: Set<String> processInfo = getProcessNames();
218: if (processInfo.size() == 0) {
219: children.add(CHILD_ID_CONSUMES_LIST);
220: children.add(CHILD_ID_PROVIDES_LIST);
221: } else {
222: children.addAll(processInfo);
223: }
224: return children;
225: }
226:
227: private Set<String> getProcessNames() {
228: Set<String> ret = new HashSet<String>();
229:
230: List<CasaEndpointRef> endpointRefs = new ArrayList<CasaEndpointRef>();
231: CasaServiceEngineServiceUnit serviceUnit = (CasaServiceEngineServiceUnit) getData();
232: if (serviceUnit != null) {
233: endpointRefs.addAll(serviceUnit.getConsumes());
234: endpointRefs.addAll(serviceUnit.getProvides());
235: for (CasaEndpointRef endpointRef : endpointRefs) {
236: CasaEndpoint endpoint = endpointRef.getEndpoint()
237: .get();
238: String processName = endpoint.getProcessName();
239: if (processName != null && processName.length() > 0) {
240: ret.add(processName);
241: }
242: }
243: }
244: return ret;
245: }
246:
247: private CasaEndpoint getEndpoint(String processName) {
248:
249: List<CasaEndpointRef> endpointRefs = new ArrayList<CasaEndpointRef>();
250: CasaServiceEngineServiceUnit serviceUnit = (CasaServiceEngineServiceUnit) getData();
251: if (serviceUnit != null) {
252: endpointRefs.addAll(serviceUnit.getConsumes());
253: endpointRefs.addAll(serviceUnit.getProvides());
254: for (CasaEndpointRef endpointRef : endpointRefs) {
255: CasaEndpoint endpoint = endpointRef.getEndpoint()
256: .get();
257: String myProcessName = endpoint.getProcessName();
258: if (myProcessName != null
259: && myProcessName.equals(processName)) {
260: return endpoint;
261: }
262: }
263: }
264: return null;
265: }
266: }
267:
268: @Override
269: public Image getIcon(int type) {
270: return ICON;
271: }
272:
273: @Override
274: public Image getOpenedIcon(int type) {
275: return ICON;
276: }
277:
278: @Override
279: public boolean isEditable(String propertyType) {
280: CasaServiceEngineServiceUnit su = (CasaServiceEngineServiceUnit) getData();
281: if (su != null) {
282: return getModel().isEditable(su, propertyType);
283: }
284: return false;
285: }
286:
287: @Override
288: public boolean isDeletable() {
289: CasaServiceEngineServiceUnit su = (CasaServiceEngineServiceUnit) getData();
290: if (su != null) {
291: return getModel().isDeletable(su);
292: }
293: return false;
294: }
295: }
|