Added initial (external) Service Unit DnD support for CASA.
1.1 --- a/compapp.casaeditor/src/org/netbeans/modules/compapp/casaeditor/graph/actions/CasaPaletteAcceptProvider.java Wed Mar 21 00:53:21 2007 +0000
1.2 +++ b/compapp.casaeditor/src/org/netbeans/modules/compapp/casaeditor/graph/actions/CasaPaletteAcceptProvider.java Wed Mar 21 09:50:14 2007 +0000
1.3 @@ -2,16 +2,16 @@
1.4 * The contents of this file are subject to the terms of the Common Development
1.5 * and Distribution License (the License). You may not use this file except in
1.6 * compliance with the License.
1.7 - *
1.8 + *
1.9 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
1.10 * or http://www.netbeans.org/cddl.txt.
1.11 - *
1.12 + *
1.13 * When distributing Covered Code, include this CDDL Header Notice in each file
1.14 * and include the License file at http://www.netbeans.org/cddl.txt.
1.15 * If applicable, add the following below the CDDL Header, with the fields
1.16 * enclosed by brackets [] replaced by your own identifying information:
1.17 * "Portions Copyrighted [year] [name of copyright owner]"
1.18 - *
1.19 + *
1.20 * The Original Software is NetBeans. The Initial Developer of the Original
1.21 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
1.22 * Microsystems, Inc. All Rights Reserved.
1.23 @@ -28,6 +28,7 @@
1.24 import java.util.List;
1.25 import java.util.ArrayList;
1.26 import java.util.Iterator;
1.27 +import javax.swing.SwingUtilities;
1.28 import org.netbeans.api.visual.action.ConnectorState;
1.29 import org.netbeans.api.visual.widget.Widget;
1.30 import org.netbeans.api.project.ProjectManager;
1.31 @@ -36,11 +37,15 @@
1.32 import org.netbeans.modules.compapp.casaeditor.design.CasaModelGraphScene;
1.33 import org.netbeans.modules.compapp.casaeditor.graph.CasaNodeWidgetEngineExternal;
1.34 import org.netbeans.modules.compapp.casaeditor.graph.CasaRegionWidget;
1.35 +import org.netbeans.modules.compapp.casaeditor.model.casa.CasaEndpoint;
1.36 +import org.netbeans.modules.compapp.casaeditor.model.casa.CasaEndpointRef;
1.37 +import org.netbeans.modules.compapp.casaeditor.model.casa.CasaServiceEngineServiceUnit;
1.38 import org.netbeans.modules.compapp.casaeditor.model.casa.CasaWrapperModel;
1.39 import org.netbeans.modules.compapp.casaeditor.palette.CasaCommonAcceptProvider;
1.40 import org.netbeans.modules.compapp.casaeditor.palette.CasaPalette;
1.41 import org.netbeans.modules.compapp.casaeditor.palette.CasaPaletteItem;
1.42 import org.netbeans.modules.compapp.projects.jbi.api.JbiProjectConstants;
1.43 +import org.netbeans.modules.xml.xam.Model;
1.44 import org.netbeans.spi.project.ant.AntArtifactProvider;
1.45 import org.openide.ErrorManager;
1.46 import org.openide.filesystems.FileObject;
1.47 @@ -52,18 +57,18 @@
1.48 * @author rdara
1.49 */
1.50 public class CasaPaletteAcceptProvider extends CasaCommonAcceptProvider {
1.51 -
1.52 +
1.53 private CasaWrapperModel mModel;
1.54 private List<String> artifactTypes = new ArrayList<String>();
1.55
1.56 -
1.57 +
1.58 public CasaPaletteAcceptProvider(CasaModelGraphScene scene, CasaWrapperModel model) {
1.59 super(scene);
1.60 mModel = model;
1.61 artifactTypes.add(JbiProjectConstants.ARTIFACT_TYPE_JBI_ASA);
1.62 }
1.63
1.64 -
1.65 +
1.66 private String getJbiProjectType(Project p) {
1.67 if (p == null) {
1.68 return null;
1.69 @@ -87,13 +92,24 @@
1.70 }
1.71 }
1.72 }
1.73 -
1.74 +
1.75 return null;
1.76 }
1.77 -
1.78 - public ConnectorState isAcceptable (Widget widget, Point point, Transferable transferable){
1.79 +
1.80 + public ConnectorState isAcceptable(Widget widget, Point point, Transferable transferable){
1.81 ConnectorState retState = ConnectorState.REJECT;
1.82 try {
1.83 + // JBIMGR
1.84 + // Due to the class loader limitation of JBI Manager, we
1.85 + Object transferData = transferable.getTransferData(CasaPalette.CasaPaletteDataFlavor); //?
1.86 + if (transferData instanceof List &&
1.87 + ((List)transferData).size() == 3 &&
1.88 + ((List)transferData).get(0) instanceof String &&
1.89 + ((List)transferData).get(0).equals("JBIMGR_SU_TRANSFER")) {
1.90 + return isAcceptableFromJBIManager(widget, point, transferData);
1.91 + }
1.92 + // JBIMGR
1.93 +
1.94 if (transferable.isDataFlavorSupported(CasaPalette.CasaPaletteDataFlavor)) {
1.95 CasaPaletteItem selNode = (CasaPaletteItem) transferable.getTransferData(CasaPalette.CasaPaletteDataFlavor);
1.96 if (selNode != null) {
1.97 @@ -110,6 +126,18 @@
1.98 return retState;
1.99 }
1.100
1.101 + // JBIMGR
1.102 + private ConnectorState isAcceptableFromJBIManager(Widget widget, Point point,
1.103 + Object transferData) {
1.104 + ConnectorState retState = ConnectorState.REJECT;
1.105 + CasaRegionWidget extRegion = getScene().getExternalRegion();
1.106 + if (extRegion.getBounds().contains(extRegion.convertSceneToLocal(point))) {
1.107 + retState = ConnectorState.ACCEPT;
1.108 + }
1.109 + return retState;
1.110 + }
1.111 + // JBIMGR
1.112 +
1.113 private ConnectorState isAcceptableFromPalette(Widget widget, Point point, CasaPaletteItem selNode) {
1.114 CasaRegionWidget region = getApplicableRegion(selNode);
1.115 ConnectorState retState = ConnectorState.REJECT;
1.116 @@ -121,8 +149,9 @@
1.117 return retState;
1.118 }
1.119
1.120 - private ConnectorState isAcceptableFromOther(Widget widget, Point point, Transferable transferable)
1.121 + private ConnectorState isAcceptableFromOther(Widget widget, Point point, Transferable transferable)
1.122 throws Exception {
1.123 +
1.124 DataFlavor[] dfs = transferable.getTransferDataFlavors();
1.125 CasaRegionWidget region = getScene().getEngineRegion();
1.126 if (region.getBounds().contains(region.convertSceneToLocal(point))) {
1.127 @@ -152,8 +181,27 @@
1.128
1.129 public void accept(Widget widget, Point point, Transferable transferable) {
1.130 try {
1.131 + // JBIMGR
1.132 if (transferable.isDataFlavorSupported(CasaPalette.CasaPaletteDataFlavor)) {
1.133 - CasaPaletteItem selNode =
1.134 + Object data = transferable.getTransferData(CasaPalette.CasaPaletteDataFlavor);
1.135 + if (data instanceof List &&
1.136 + ((List)data).size() == 3 &&
1.137 + ((List)data).get(0) instanceof String &&
1.138 + ((List)data).get(0).equals("JBIMGR_SU_TRANSFER")) {
1.139 +
1.140 + JBIServiceUnitTransferObject suTransfer =
1.141 + new JBIServiceUnitTransferObject(
1.142 + (String) ((List)data).get(1),
1.143 + (String) ((List)data).get(2));
1.144 + acceptFromJBIManager(widget, point, suTransfer);
1.145 + return;
1.146 + }
1.147 + }
1.148 + // JBIMGR
1.149 +
1.150 + if (transferable.isDataFlavorSupported(CasaPalette.CasaPaletteDataFlavor)) {
1.151 +
1.152 + CasaPaletteItem selNode =
1.153 (CasaPaletteItem) transferable.getTransferData(CasaPalette.CasaPaletteDataFlavor);
1.154 if (selNode != null) {
1.155 acceptFromPalette(widget, point, selNode);
1.156 @@ -194,7 +242,7 @@
1.157 }
1.158 }
1.159
1.160 - private void acceptFromOther(Widget widget, Point point, Transferable transferable)
1.161 + private void acceptFromOther(Widget widget, Point point, Transferable transferable)
1.162 throws Exception {
1.163 // check for SU project node
1.164 DataFlavor[] dfs = transferable.getTransferDataFlavors();
1.165 @@ -209,7 +257,69 @@
1.166 }
1.167 }
1.168 }
1.169 -
1.170 +
1.171 + // JBIMGR
1.172 + private void acceptFromJBIManager(Widget widget, Point point,
1.173 + //String suName, String descriptor) throws Exception {
1.174 + final JBIServiceUnitTransferObject suTransfer) throws Exception {
1.175 +
1.176 + point = getScene().getExternalRegion().convertSceneToLocal(point);
1.177 + final CasaServiceEngineServiceUnit seSU =
1.178 + mModel.addUnknownEngineServiceUnit(false, point.x, point.y);
1.179 + final Model model = seSU.getModel();
1.180 + String suName = suTransfer.getServiceUnitName();
1.181 +
1.182 + model.startTransaction();
1.183 + try {
1.184 + seSU.setName(suName);
1.185 + seSU.setUnitName(suName);
1.186 + } finally {
1.187 + if (model.isIntransaction()) {
1.188 + model.endTransaction();
1.189 + }
1.190 + }
1.191 +
1.192 + SwingUtilities.invokeLater(new Runnable() {
1.193 + public void run() {
1.194 + List<JBIServiceUnitTransferObject.Endpoint> pList = suTransfer.getProvidesEndpoints();
1.195 + for (JBIServiceUnitTransferObject.Endpoint p : pList) {
1.196 + CasaEndpointRef endpointRef =
1.197 + mModel.addEndpointToExternalServiceUnit(seSU, false);
1.198 + CasaEndpoint endpoint = endpointRef.getEndpoint().get();
1.199 +
1.200 + model.startTransaction();
1.201 + try {
1.202 + endpoint.setInterfaceQName(p.getInterfaceQName());
1.203 + endpoint.setServiceQName(p.getServiceQName());
1.204 + endpoint.setEndpointName(p.getEndpointName());
1.205 + } finally {
1.206 + if (model.isIntransaction()) {
1.207 + model.endTransaction();
1.208 + }
1.209 + }
1.210 + }
1.211 + List<JBIServiceUnitTransferObject.Endpoint> cList = suTransfer.getConsumesEndpoints();
1.212 + for (JBIServiceUnitTransferObject.Endpoint c : cList) {
1.213 + CasaEndpointRef endpointRef =
1.214 + mModel.addEndpointToExternalServiceUnit(seSU, false);
1.215 + CasaEndpoint endpoint = endpointRef.getEndpoint().get();
1.216 +
1.217 + model.startTransaction();
1.218 + try {
1.219 + endpoint.setInterfaceQName(c.getInterfaceQName());
1.220 + endpoint.setServiceQName(c.getServiceQName());
1.221 + endpoint.setEndpointName(c.getEndpointName());
1.222 + } finally {
1.223 + if (model.isIntransaction()) {
1.224 + model.endTransaction();
1.225 + }
1.226 + }
1.227 + }
1.228 + }
1.229 + });
1.230 + }
1.231 + // JBIMGR
1.232 +
1.233 // todo: 02/15/07 fix the problem created by bpel project changes...
1.234 private Project getProjectFromDataObject(DataObject obj) throws Exception {
1.235 if (obj == null) {
1.236 @@ -225,7 +335,7 @@
1.237 }
1.238 return p;
1.239 }
1.240 -
1.241 +
1.242
1.243 public void acceptStarted(Transferable transferable) {
1.244 super.acceptStarted(transferable);
1.245 @@ -234,7 +344,7 @@
1.246 if (region != null) { //Region can take the drop -- highlight it!
1.247 highlightRegion(region);
1.248 } else { // Its WSDL Points and hence highlight external SUs
1.249 - // Sanity check...
1.250 + // Sanity check...
1.251 if(selNode != null) {
1.252 if(selNode.getCategory() == CasaPalette.CASA_CATEGORY_TYPE.END_POINTS) {
1.253 highlightExtSUs(true);
1.254 @@ -255,16 +365,16 @@
1.255 region.setHighlighted(true);
1.256 showRegion(region);
1.257 }
1.258 -
1.259 +
1.260 private void highlightExtSUs(boolean bValue) {
1.261 - for (Widget widget : getScene().getExternalRegion().getChildren()) {
1.262 + for (Widget widget : getScene().getExternalRegion().getChildren()) {
1.263 if (widget instanceof CasaNodeWidgetEngineExternal) {
1.264 ((CasaNodeWidgetEngineExternal) widget).setHighlighted(bValue);
1.265 }
1.266 - }
1.267 - if (bValue) {
1.268 + }
1.269 + if (bValue) {
1.270 showRegion(getScene().getExternalRegion());
1.271 - }
1.272 + }
1.273 }
1.274
1.275 private void showRegion(CasaRegionWidget region) {
1.276 @@ -276,7 +386,7 @@
1.277 getScene().getViewComponent().scrollRectToVisible(visibleRect);
1.278
1.279 }
1.280 -
1.281 +
1.282 private CasaRegionWidget getApplicableRegion(CasaPaletteItem selNode) {
1.283 CasaRegionWidget region = null;
1.284 if (selNode != null) {
1.285 @@ -291,9 +401,9 @@
1.286 region = getScene().getExternalRegion();
1.287 }
1.288 break;
1.289 - default:
1.290 - break;
1.291 - }
1.292 + default:
1.293 + break;
1.294 + }
1.295 } else {
1.296 region = getScene().getEngineRegion();
1.297 }
1.298 @@ -314,4 +424,4 @@
1.299 return selNode;
1.300 }
1.301 }
1.302 -
1.303 +
2.1 --- a/compapp.manager.jbi/src/org/netbeans/modules/sun/manager/jbi/GenericConstants.java Wed Mar 21 00:53:21 2007 +0000
2.2 +++ b/compapp.manager.jbi/src/org/netbeans/modules/sun/manager/jbi/GenericConstants.java Wed Mar 21 09:50:14 2007 +0000
2.3 @@ -164,6 +164,7 @@
2.4
2.5 public static final String GET_COMPONENT_INSTALLATION_DESCRIPTOR_NAME = "getComponentInstallationDescriptor"; // NOI18N
2.6 public static final String GET_SHARED_LIBRARY_INSTALLATION_DESCRIPTOR_NAME = "getSharedLibraryInstallationDescriptor"; // NOI18N
2.7 + public static final String GET_SERVICE_UNIT_DEPLOYMENT_DESCRIPTOR_NAME = "getServiceUnitDeploymentDescriptor"; // NOI18N
2.8
2.9 public static final String DEPLOY_SERVICE_ASSEMBLY_OPERATION_NAME = "deployServiceAssembly"; // NOI18N
2.10 public static final String INSTALL_COMPONENT_OPERATION_NAME = "installComponent"; // NOI18N
3.1 --- a/compapp.manager.jbi/src/org/netbeans/modules/sun/manager/jbi/nodes/JBIServiceUnitNode.java Wed Mar 21 00:53:21 2007 +0000
3.2 +++ b/compapp.manager.jbi/src/org/netbeans/modules/sun/manager/jbi/nodes/JBIServiceUnitNode.java Wed Mar 21 09:50:14 2007 +0000
3.3 @@ -2,16 +2,16 @@
3.4 * The contents of this file are subject to the terms of the Common Development
3.5 * and Distribution License (the License). You may not use this file except in
3.6 * compliance with the License.
3.7 - *
3.8 + *
3.9 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
3.10 * or http://www.netbeans.org/cddl.txt.
3.11 - *
3.12 + *
3.13 * When distributing Covered Code, include this CDDL Header Notice in each file
3.14 * and include the License file at http://www.netbeans.org/cddl.txt.
3.15 * If applicable, add the following below the CDDL Header, with the fields
3.16 * enclosed by brackets [] replaced by your own identifying information:
3.17 * "Portions Copyrighted [year] [name of copyright owner]"
3.18 - *
3.19 + *
3.20 * The Original Software is NetBeans. The Initial Developer of the Original
3.21 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
3.22 * Microsystems, Inc. All Rights Reserved.
3.23 @@ -20,16 +20,29 @@
3.24 package org.netbeans.modules.sun.manager.jbi.nodes;
3.25
3.26 import java.awt.Image;
3.27 +import java.awt.datatransfer.DataFlavor;
3.28 +import java.awt.datatransfer.Transferable;
3.29 +import java.awt.datatransfer.UnsupportedFlavorException;
3.30 +import java.io.IOException;
3.31 +import java.io.StringReader;
3.32 +import java.util.ArrayList;
3.33 +import java.util.List;
3.34 import java.util.Map;
3.35
3.36 import javax.management.Attribute;
3.37 import javax.management.MBeanAttributeInfo;
3.38 +import javax.xml.parsers.DocumentBuilder;
3.39 +import javax.xml.parsers.DocumentBuilderFactory;
3.40
3.41 import org.netbeans.modules.sun.manager.jbi.management.model.JBIComponentStatus;
3.42 import org.netbeans.modules.sun.manager.jbi.management.model.JBIServiceUnitStatus;
3.43 import org.netbeans.modules.sun.manager.jbi.util.AppserverJBIMgmtController;
3.44 import org.netbeans.modules.sun.manager.jbi.util.NodeTypes;
3.45 import org.netbeans.modules.sun.manager.jbi.util.Utils;
3.46 +import org.openide.util.datatransfer.ExTransferable;
3.47 +import org.w3c.dom.Document;
3.48 +import org.w3c.dom.Element;
3.49 +import org.xml.sax.InputSource;
3.50
3.51 /**
3.52 * Node for one JBI Service Unit.
3.53 @@ -96,7 +109,73 @@
3.54 } else if (!JBIComponentStatus.STARTED_STATE.equals(status)) {
3.55 externalBadgeIconName = IconConstants.UNKNOWN_ICON;
3.56 }
3.57 -
3.58 +
3.59 return Utils.getBadgedIcon(getClass(), baseIconName, null, externalBadgeIconName);
3.60 }
3.61 +
3.62 +
3.63 + // DnD Support for CASA
3.64 +
3.65 + public static final DataFlavor ServiceUnitDataFlavor =
3.66 + new DataFlavor(Object.class, "JBIServiceUnitDataFlavor" ) { // NOI18N
3.67 + };
3.68 +
3.69 + public Transferable drag() throws IOException {
3.70 + ExTransferable retValue = ExTransferable.create( super.drag() );
3.71 + //add the 'data' into the Transferable
3.72 + final String descriptor = getDeploymentDescriptor();
3.73 +
3.74 + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
3.75 + factory.setNamespaceAware(true);
3.76 +
3.77 + try {
3.78 + DocumentBuilder builder = factory.newDocumentBuilder();
3.79 + Document doc = builder.parse(new InputSource(new StringReader(descriptor)));
3.80 + Element services = (Element) doc.getElementsByTagName("services").item(0);
3.81 + boolean isBC = services.getAttribute("binding-component").equals("true");
3.82 +
3.83 + if (!isBC) {
3.84 + retValue.put( new ExTransferable.Single(ServiceUnitDataFlavor) {
3.85 + protected Object getData() throws IOException, UnsupportedFlavorException {
3.86 + List<String> ret = new ArrayList<String>();
3.87 + ret.add("JBIMGR_SU_TRANSFER"); // NOI18N
3.88 + ret.add(getName());
3.89 + ret.add(descriptor);
3.90 + return ret;
3.91 + }
3.92 + });
3.93 + }
3.94 + } catch (Exception ex) {
3.95 + ex.printStackTrace();
3.96 + }
3.97 +
3.98 + /*
3.99 + return new Transferable() {
3.100 + public DataFlavor[] getTransferDataFlavors() {
3.101 + return new DataFlavor[] {
3.102 + JBIServiceUnitTransferObject.ServiceUnitDataFlavor};
3.103 + }
3.104 +
3.105 + public boolean isDataFlavorSupported(DataFlavor flavor) {
3.106 + return JBIServiceUnitTransferObject.ServiceUnitDataFlavor.equals(flavor);
3.107 + }
3.108 +
3.109 + public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
3.110 + return suTransfer;
3.111 + }
3.112 +
3.113 + };*/
3.114 +
3.115 + return retValue;
3.116 + }
3.117 +
3.118 + private String getDeploymentDescriptor() {
3.119 + AppserverJBIMgmtController controller = getAppserverJBIMgmtController();
3.120 + String assemblyName = getParentNode().getName();
3.121 + String descriptor = controller.getJBIAdministrationService().
3.122 + getServiceUnitDeploymentDescriptor(assemblyName, getName());
3.123 + return descriptor;
3.124 + }
3.125 +
3.126 +
3.127 }
4.1 --- a/compapp.manager.jbi/src/org/netbeans/modules/sun/manager/jbi/util/ProgressUI.java Wed Mar 21 00:53:21 2007 +0000
4.2 +++ b/compapp.manager.jbi/src/org/netbeans/modules/sun/manager/jbi/util/ProgressUI.java Wed Mar 21 09:50:14 2007 +0000
4.3 @@ -23,7 +23,6 @@
4.4 import java.awt.Insets;
4.5 import java.awt.event.ActionEvent;
4.6 import java.awt.event.ActionListener;
4.7 -
4.8 import javax.enterprise.deploy.shared.StateType;
4.9 import javax.enterprise.deploy.spi.status.DeploymentStatus;
4.10 import javax.enterprise.deploy.spi.status.ProgressEvent;
4.11 @@ -34,13 +33,9 @@
4.12 import javax.swing.JDialog;
4.13 import javax.swing.JLabel;
4.14 import javax.swing.JPanel;
4.15 -
4.16 import org.netbeans.api.progress.ProgressHandle;
4.17 import org.netbeans.api.progress.ProgressHandleFactory;
4.18 -import org.netbeans.modules.sun.manager.jbi.util.Utils;
4.19 import org.openide.util.NbBundle;
4.20 -//import org.openide.util.Utilities;
4.21 -//import org.openide.windows.WindowManager;
4.22
4.23
4.24 /**
4.25 @@ -54,7 +49,6 @@
4.26
4.27 private String title;
4.28 private boolean modal;
4.29 -// private Deployment.Logger logger;
4.30
4.31 private ProgressHandle handle;
4.32 private ProgressObject progObj;
4.33 @@ -67,13 +61,8 @@
4.34
4.35 /** Creates a new instance of ProgressUI */
4.36 public ProgressUI(String title, boolean modal) {
4.37 -// this(title, modal, null);
4.38 -// }
4.39 -//
4.40 -// public ProgressUI(String title, boolean modal, Deployment.Logger logger) {
4.41 this.modal = modal;
4.42 this.title = title;
4.43 -// this.logger = logger;
4.44 handle = ProgressHandleFactory.createHandle(title);
4.45 }
4.46
4.47 @@ -116,7 +105,6 @@
4.48 }
4.49 });
4.50 }
4.51 -// log(message);
4.52 }
4.53
4.54 /** Finish the task, unregister the progress object listener and dispose the ui. */
4.55 @@ -141,9 +129,6 @@
4.56 /** Display a failure dialog with the specified message and call finish. */
4.57 public void failed(String message) {
4.58 finish();
4.59 -// if (logger != null) {
4.60 -// log(message);
4.61 -// }
4.62 }
4.63
4.64 /** Set a progress object this progress UI will monitor. */
4.65 @@ -157,20 +142,7 @@
4.66 progObj.addProgressListener(this);
4.67 }
4.68 }
4.69 -
4.70 -// /** Set a logger to where all the progress messages will be copied. */
4.71 -// public void setLogger(Deployment.Logger logger) {
4.72 -// this.logger = logger;
4.73 -// }
4.74 -//
4.75 -// // private helper methods
4.76 -//
4.77 -// private void log(String msg) {
4.78 -// if (logger != null && msg != null) {
4.79 -// logger.log(msg);
4.80 -// }
4.81 -// }
4.82 -
4.83 +
4.84 private JComponent createProgressDialog(ProgressHandle handle, String message) {
4.85 JPanel panel = new JPanel();
4.86 messageLabel = new JLabel();