PageRenderTime 46ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/compapp.casaeditor/src/org/netbeans/modules/compapp/casaeditor/nodes/ServiceUnitProcessNode.java

https://bitbucket.org/rsaqc/netbeans-soa
Java | 301 lines | 194 code | 29 blank | 78 comment | 29 complexity | 735eb2d096c480d5f09684eeb4792078 MD5 | raw file
  1. /*
  2. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  3. *
  4. * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
  5. *
  6. * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  7. * Other names may be trademarks of their respective owners.
  8. *
  9. * The contents of this file are subject to the terms of either the GNU
  10. * General Public License Version 2 only ("GPL") or the Common
  11. * Development and Distribution License("CDDL") (collectively, the
  12. * "License"). You may not use this file except in compliance with the
  13. * License. You can obtain a copy of the License at
  14. * http://www.netbeans.org/cddl-gplv2.html
  15. * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  16. * specific language governing permissions and limitations under the
  17. * License. When distributing the software, include this License Header
  18. * Notice in each file and include the License file at
  19. * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
  20. * particular file as subject to the "Classpath" exception as provided
  21. * by Oracle in the GPL Version 2 section of the License file that
  22. * accompanied this code. If applicable, add the following below the
  23. * License Header, with the fields enclosed by brackets [] replaced by
  24. * your own identifying information:
  25. * "Portions Copyrighted [year] [name of copyright owner]"
  26. *
  27. * Contributor(s):
  28. *
  29. * The Original Software is NetBeans. The Initial Developer of the Original
  30. * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
  31. * Microsystems, Inc. All Rights Reserved.
  32. *
  33. * If you wish your version of this file to be governed by only the CDDL
  34. * or only the GPL Version 2, indicate your decision by adding
  35. * "[Contributor] elects to include this software in this distribution
  36. * under the [CDDL or GPL Version 2] license." If you do not indicate a
  37. * single choice of license, a recipient has the option to distribute
  38. * your version of this file under either the CDDL, the GPL Version 2 or
  39. * to extend the choice of license to its licensees as provided above.
  40. * However, if you add GPL Version 2 code and therefore, elected the GPL
  41. * Version 2 license, then the option applies only if the new code is
  42. * made subject to such option by the copyright holder.
  43. */
  44. package org.netbeans.modules.compapp.casaeditor.nodes;
  45. import java.awt.Image;
  46. import java.io.IOException;
  47. import java.net.URL;
  48. import java.util.ArrayList;
  49. import java.util.List;
  50. import javax.imageio.ImageIO;
  51. import org.netbeans.modules.compapp.casaeditor.model.casa.CasaWrapperModel;
  52. import org.netbeans.modules.compapp.casaeditor.model.casa.CasaServiceEngineServiceUnit;
  53. import org.netbeans.modules.compapp.casaeditor.properties.PropertyUtils;
  54. import org.openide.nodes.Node;
  55. import org.openide.nodes.PropertySupport;
  56. import org.openide.nodes.Sheet;
  57. import org.openide.util.Exceptions;
  58. import org.openide.util.ImageUtilities;
  59. import org.openide.util.NbBundle;
  60. import org.openide.util.Utilities;
  61. import org.openide.util.actions.SystemAction;
  62. import javax.swing.*;
  63. import org.netbeans.modules.compapp.casaeditor.Constants;
  64. import org.netbeans.modules.compapp.casaeditor.model.casa.CasaConsumes;
  65. import org.netbeans.modules.compapp.casaeditor.model.casa.CasaEndpoint;
  66. import org.netbeans.modules.compapp.casaeditor.model.casa.CasaEndpointRef;
  67. import org.netbeans.modules.compapp.casaeditor.model.casa.CasaProvides;
  68. import org.netbeans.modules.compapp.casaeditor.nodes.actions.GoToSourceAction;
  69. import org.netbeans.modules.compapp.projects.jbi.api.JbiDefaultComponentInfo;
  70. import org.netbeans.modules.sun.manager.jbi.management.model.JBIComponentStatus;
  71. /**
  72. *
  73. * @author jqian
  74. */
  75. // HACK: since there is currently no corresponding model component for process,
  76. // we use the endpoint instead.
  77. public class ServiceUnitProcessNode extends CasaNode {
  78. public static final Image DEFAULT_ICON = ImageUtilities.loadImage(
  79. "org/netbeans/modules/compapp/casaeditor/nodes/resources/ServiceUnitNode.png"); // NOI18N
  80. private static final String CHILD_ID_PROVIDES_LIST = "ProvidesList"; // NOI18N
  81. private static final String CHILD_ID_CONSUMES_LIST = "ConsumesList"; // NOI18N
  82. public ServiceUnitProcessNode(CasaEndpoint component, CasaNodeFactory factory) {
  83. super(component, new MyChildren(component, factory), factory);
  84. assert component != null;
  85. //System.out.println("***CREATING SERVICE_UNIT_PROCESS_NODE: " + this + " component=" + component);
  86. }
  87. public String getProcessName() {
  88. return ((CasaEndpoint)getData()).getProcessName();
  89. }
  90. public String getFilePath() {
  91. return ((CasaEndpoint)getData()).getFilePath();
  92. }
  93. public CasaServiceEngineServiceUnit getServiceEngineServiceUnit() {
  94. CasaEndpoint endpoint = (CasaEndpoint)getData();
  95. return getServiceEngineServiceUnit(endpoint);
  96. }
  97. private static CasaServiceEngineServiceUnit getServiceEngineServiceUnit(CasaEndpoint endpoint) {
  98. CasaWrapperModel model = (CasaWrapperModel) endpoint.getModel();
  99. CasaEndpointRef endpointRef = model.getServiceEngineEndpointRef(endpoint);
  100. return model.getCasaEngineServiceUnit(endpointRef);
  101. }
  102. @Override
  103. protected void addCustomActions(List<Action> actions) {
  104. CasaEndpoint endpoint = (CasaEndpoint)getData();
  105. CasaServiceEngineServiceUnit su = getServiceEngineServiceUnit(endpoint);
  106. if (su != null && su.isInternal()) {
  107. actions.add(SystemAction.get(GoToSourceAction.class));
  108. }
  109. }
  110. @Override
  111. public String getName() {
  112. /*
  113. CasaServiceEngineServiceUnit su = getServiceEngineServiceUnit();
  114. if (su != null) {
  115. return NbBundle.getMessage(getClass(), "LBL_Process"); // NOI18N
  116. }
  117. return super.getName();
  118. */
  119. return getProcessName();
  120. }
  121. /*
  122. @Override
  123. public String getHtmlDisplayName() {
  124. try {
  125. String htmlDisplayName = getName();
  126. CasaServiceEngineServiceUnit casaSU = getServiceEngineServiceUnit();
  127. String decoration = null;
  128. if (casaSU != null) {
  129. decoration = NbBundle.getMessage(WSDLEndpointNode.class, "LBL_NameAttr", // NOI18N
  130. getProcessName());
  131. }
  132. if (decoration == null) {
  133. return htmlDisplayName;
  134. }
  135. return htmlDisplayName + " <font color='#999999'>"+decoration+"</font>"; // NOI18N
  136. } catch (Throwable t) {
  137. // getHtmlDisplayName MUST recover gracefully.
  138. return getBadName();
  139. }
  140. }
  141. */
  142. @Override
  143. protected void setupPropertySheet(Sheet sheet) {
  144. final CasaServiceEngineServiceUnit casaSU = getServiceEngineServiceUnit();
  145. if (casaSU == null) {
  146. return;
  147. }
  148. Sheet.Set identificationProperties =
  149. getPropertySet(sheet, PropertyUtils.PropertiesGroups.IDENTIFICATION_SET);
  150. Node.Property<String> descriptionSupport = new PropertySupport.ReadOnly<String>(
  151. "processName", // NOI18N
  152. String.class,
  153. NbBundle.getMessage(getClass(), "PROP_ProcessName"), // NOI18N
  154. Constants.EMPTY_STRING) {
  155. public String getValue() {
  156. return getProcessName();
  157. }
  158. };
  159. identificationProperties.put(descriptionSupport);
  160. Node.Property<String> filePathSupport = new PropertySupport.ReadOnly<String>(
  161. "filePath", // NOI18N
  162. String.class,
  163. NbBundle.getMessage(getClass(), "PROP_FilePath"), // NOI18N
  164. Constants.EMPTY_STRING) {
  165. public String getValue() {
  166. return getFilePath();
  167. }
  168. };
  169. identificationProperties.put(filePathSupport);
  170. }
  171. private static class MyChildren extends CasaNodeChildren {
  172. public MyChildren(CasaEndpoint component,CasaNodeFactory factory) {
  173. super(component, factory);
  174. }
  175. protected Node[] createNodes(Object key) {
  176. assert key instanceof String;
  177. CasaEndpoint endpoint = (CasaEndpoint)getData();
  178. CasaServiceEngineServiceUnit serviceUnit = getServiceEngineServiceUnit(endpoint);
  179. if (serviceUnit != null) {
  180. CasaWrapperModel model = mNodeFactory.getCasaModel();
  181. if (model != null) {
  182. String keyName = (String) key;
  183. if (keyName.equals(CHILD_ID_CONSUMES_LIST)) {
  184. return new Node[] { mNodeFactory.createNode_consumesList(getConsumeEndpointRefs()) };
  185. } else if (keyName.equals(CHILD_ID_PROVIDES_LIST)) {
  186. return new Node[] { mNodeFactory.createNode_providesList(getProvideEndpointRefs()) };
  187. }
  188. }
  189. }
  190. return null;
  191. }
  192. @Override
  193. public Object getChildKeys(Object data) {
  194. List<String> children = new ArrayList<String>();
  195. children.add(CHILD_ID_CONSUMES_LIST);
  196. children.add(CHILD_ID_PROVIDES_LIST);
  197. return children;
  198. }
  199. private String getProcessName() {
  200. CasaEndpoint endpoint = (CasaEndpoint)getData();
  201. return endpoint.getProcessName();
  202. }
  203. private List<CasaConsumes> getConsumeEndpointRefs() {
  204. List<CasaConsumes> ret = new ArrayList<CasaConsumes>();
  205. CasaEndpoint endpoint = (CasaEndpoint)getData();
  206. CasaServiceEngineServiceUnit serviceUnit = getServiceEngineServiceUnit(endpoint);
  207. if (serviceUnit != null) {
  208. for (CasaConsumes endpointRef : serviceUnit.getConsumes()) {
  209. CasaEndpoint ep = endpointRef.getEndpoint().get();
  210. String pName = ep.getProcessName();
  211. if (pName != null && pName.equals(getProcessName())) {
  212. ret.add(endpointRef);
  213. }
  214. }
  215. }
  216. return ret;
  217. }
  218. private List<CasaProvides> getProvideEndpointRefs() {
  219. List<CasaProvides> ret = new ArrayList<CasaProvides>();
  220. CasaEndpoint endpoint = (CasaEndpoint)getData();
  221. CasaServiceEngineServiceUnit serviceUnit = getServiceEngineServiceUnit(endpoint);
  222. if (serviceUnit != null) {
  223. for (CasaProvides endpointRef : serviceUnit.getProvides()) {
  224. CasaEndpoint ep = endpointRef.getEndpoint().get();
  225. String pName = ep.getProcessName();
  226. if (pName != null && pName.equals(getProcessName())) {
  227. ret.add(endpointRef);
  228. }
  229. }
  230. }
  231. return ret;
  232. }
  233. }
  234. @Override
  235. public Image getIcon(int type) {
  236. return getFileIconImage((CasaEndpoint) getData());
  237. }
  238. @Override
  239. public Image getOpenedIcon(int type) {
  240. return getIcon(type);
  241. }
  242. @Override
  243. public boolean isEditable(String propertyType) {
  244. return false;
  245. }
  246. @Override
  247. public boolean isDeletable() {
  248. return false;
  249. }
  250. public static Image getFileIconImage(CasaEndpoint endpoint) {
  251. Image ret = DEFAULT_ICON;
  252. CasaWrapperModel model = (CasaWrapperModel) endpoint.getModel();
  253. CasaEndpointRef endpointRef = model.getServiceEngineEndpointRef((CasaEndpoint)endpoint);
  254. CasaServiceEngineServiceUnit sesu = (CasaServiceEngineServiceUnit) endpointRef.getParent();
  255. String compName = sesu.getComponentName();
  256. JbiDefaultComponentInfo defaultCompInfo =
  257. JbiDefaultComponentInfo.getJbiDefaultComponentInfo();
  258. JBIComponentStatus compStatus = defaultCompInfo.getComponentHash().get(compName);
  259. URL fileIconURL = null;
  260. if (compStatus != null) {
  261. fileIconURL = compStatus.getFileIconURL();
  262. if (fileIconURL != null) {
  263. try {
  264. ret = ImageIO.read(fileIconURL);
  265. } catch (IOException ex) {
  266. Exceptions.printStackTrace(ex);
  267. }
  268. }
  269. }
  270. return ret;
  271. }
  272. }