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.List;
047: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaWrapperModel;
048: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaComponent;
049: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaServiceEngineServiceUnit;
050: import org.netbeans.modules.compapp.casaeditor.properties.PropertyUtils;
051: import org.openide.nodes.Node;
052: import org.openide.nodes.PropertySupport;
053: import org.openide.nodes.Sheet;
054: import org.openide.util.NbBundle;
055: import org.openide.util.Utilities;
056: import org.openide.util.actions.SystemAction;
057:
058: import javax.swing.*;
059: import org.netbeans.modules.compapp.casaeditor.Constants;
060: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaConsumes;
061: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaEndpoint;
062: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaEndpointRef;
063: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaProvides;
064: import org.netbeans.modules.compapp.casaeditor.nodes.actions.GoToSourceAction;
065:
066: /**
067: *
068: * @author jqian
069: */
070: // HACK: since there is currently no corresponding model component for process,
071: // we use the endpoint instead.
072: public class ServiceUnitProcessNode extends CasaNode {
073:
074: private static final Image ICON = Utilities
075: .loadImage("org/netbeans/modules/compapp/casaeditor/nodes/resources/ServiceUnitNode.png"); // NOI18N
076:
077: private static final String CHILD_ID_PROVIDES_LIST = "ProvidesList"; // NOI18N
078: private static final String CHILD_ID_CONSUMES_LIST = "ConsumesList"; // NOI18N
079:
080: public ServiceUnitProcessNode(CasaEndpoint component,
081: CasaNodeFactory factory) {
082: super (component, new MyChildren(component, factory), factory);
083: assert component != null;
084: //System.out.println("***CREATING SERVICE_UNIT_PROCESS_NODE: " + this + " component=" + component);
085: }
086:
087: public String getProcessName() {
088: return ((CasaEndpoint) getData()).getProcessName();
089: }
090:
091: public String getFilePath() {
092: return ((CasaEndpoint) getData()).getFilePath();
093: }
094:
095: public CasaServiceEngineServiceUnit getServiceEngineServiceUnit() {
096: CasaEndpoint endpoint = (CasaEndpoint) getData();
097: return getServiceEngineServiceUnit(endpoint);
098: }
099:
100: private static CasaServiceEngineServiceUnit getServiceEngineServiceUnit(
101: CasaEndpoint endpoint) {
102: CasaWrapperModel model = (CasaWrapperModel) endpoint.getModel();
103: CasaEndpointRef endpointRef = model
104: .getServiceEngineEndpointRef(endpoint);
105: return model.getCasaEngineServiceUnit(endpointRef);
106: }
107:
108: @Override
109: protected void addCustomActions(List<Action> actions) {
110: CasaEndpoint endpoint = (CasaEndpoint) getData();
111: CasaServiceEngineServiceUnit su = getServiceEngineServiceUnit(endpoint);
112: if (su != null && su.isInternal()) {
113: actions.add(SystemAction.get(GoToSourceAction.class));
114: }
115: }
116:
117: @Override
118: public String getName() {
119: CasaServiceEngineServiceUnit su = getServiceEngineServiceUnit();
120: if (su != null) {
121: return NbBundle.getMessage(getClass(), "LBL_Process"); // NOI18N
122: }
123: return super .getName();
124: }
125:
126: @Override
127: public String getHtmlDisplayName() {
128: try {
129: String htmlDisplayName = getName();
130: CasaServiceEngineServiceUnit casaSU = getServiceEngineServiceUnit();
131: String decoration = null;
132: if (casaSU != null) {
133: decoration = NbBundle.getMessage(
134: WSDLEndpointNode.class, "LBL_NameAttr", // NOI18N
135: getProcessName());
136: }
137: if (decoration == null) {
138: return htmlDisplayName;
139: }
140: return htmlDisplayName + " <font color='#999999'>"
141: + decoration + "</font>"; // NOI18N
142: } catch (Throwable t) {
143: // getHtmlDisplayName MUST recover gracefully.
144: return getBadName();
145: }
146: }
147:
148: @Override
149: protected void setupPropertySheet(Sheet sheet) {
150: final CasaServiceEngineServiceUnit casaSU = getServiceEngineServiceUnit();
151: if (casaSU == null) {
152: return;
153: }
154: Sheet.Set identificationProperties = getPropertySet(sheet,
155: PropertyUtils.PropertiesGroups.IDENTIFICATION_SET);
156:
157: Node.Property<String> descriptionSupport = new PropertySupport.ReadOnly<String>(
158: "processName", // NOI18N
159: String.class, NbBundle.getMessage(getClass(),
160: "PROP_ProcessName"), // NOI18N
161: Constants.EMPTY_STRING) {
162: public String getValue() {
163: return getProcessName();
164: }
165: };
166: identificationProperties.put(descriptionSupport);
167:
168: Node.Property<String> filePathSupport = new PropertySupport.ReadOnly<String>(
169: "filePath", // NOI18N
170: String.class, NbBundle.getMessage(getClass(),
171: "PROP_FilePath"), // NOI18N
172: Constants.EMPTY_STRING) {
173: public String getValue() {
174: return getFilePath();
175: }
176: };
177: identificationProperties.put(filePathSupport);
178: }
179:
180: private static class MyChildren extends CasaNodeChildren {
181:
182: public MyChildren(CasaEndpoint component,
183: CasaNodeFactory factory) {
184: super (component, factory);
185: }
186:
187: protected Node[] createNodes(Object key) {
188: assert key instanceof String;
189: CasaEndpoint endpoint = (CasaEndpoint) getData();
190: CasaServiceEngineServiceUnit serviceUnit = getServiceEngineServiceUnit(endpoint);
191: if (serviceUnit != null) {
192: CasaWrapperModel model = mNodeFactory.getCasaModel();
193: if (model != null) {
194: String keyName = (String) key;
195: if (keyName.equals(CHILD_ID_CONSUMES_LIST)) {
196: return new Node[] { mNodeFactory
197: .createNode_consumesList(getConsumeEndpointRefs()) };
198: } else if (keyName.equals(CHILD_ID_PROVIDES_LIST)) {
199: return new Node[] { mNodeFactory
200: .createNode_providesList(getProvideEndpointRefs()) };
201: }
202: }
203: }
204: return null;
205: }
206:
207: @Override
208: public Object getChildKeys(Object data) {
209: List<String> children = new ArrayList<String>();
210: children.add(CHILD_ID_CONSUMES_LIST);
211: children.add(CHILD_ID_PROVIDES_LIST);
212: return children;
213: }
214:
215: private String getProcessName() {
216: CasaEndpoint endpoint = (CasaEndpoint) getData();
217: return endpoint.getProcessName();
218: }
219:
220: private List<CasaConsumes> getConsumeEndpointRefs() {
221: List<CasaConsumes> ret = new ArrayList<CasaConsumes>();
222:
223: CasaEndpoint endpoint = (CasaEndpoint) getData();
224: CasaServiceEngineServiceUnit serviceUnit = getServiceEngineServiceUnit(endpoint);
225: if (serviceUnit != null) {
226: for (CasaConsumes endpointRef : serviceUnit
227: .getConsumes()) {
228: CasaEndpoint ep = endpointRef.getEndpoint().get();
229: String pName = ep.getProcessName();
230: if (pName != null && pName.equals(getProcessName())) {
231: ret.add(endpointRef);
232: }
233: }
234: }
235: return ret;
236: }
237:
238: private List<CasaProvides> getProvideEndpointRefs() {
239: List<CasaProvides> ret = new ArrayList<CasaProvides>();
240:
241: CasaEndpoint endpoint = (CasaEndpoint) getData();
242: CasaServiceEngineServiceUnit serviceUnit = getServiceEngineServiceUnit(endpoint);
243: if (serviceUnit != null) {
244: for (CasaProvides endpointRef : serviceUnit
245: .getProvides()) {
246: CasaEndpoint ep = endpointRef.getEndpoint().get();
247: String pName = ep.getProcessName();
248: if (pName != null && pName.equals(getProcessName())) {
249: ret.add(endpointRef);
250: }
251: }
252: }
253: return ret;
254: }
255: }
256:
257: @Override
258: public Image getIcon(int type) {
259: return ICON;
260: }
261:
262: @Override
263: public Image getOpenedIcon(int type) {
264: return ICON;
265: }
266:
267: @Override
268: public boolean isEditable(String propertyType) {
269: return false;
270: }
271:
272: @Override
273: public boolean isDeletable() {
274: return false;
275: }
276: }
|