You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sa...@apache.org on 2014/04/14 20:31:10 UTC
[68/90] [abbrv] AIRAVATA-1124
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/service/echo/EchoClient.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/service/echo/EchoClient.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/service/echo/EchoClient.java
new file mode 100644
index 0000000..bc31eea
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/service/echo/EchoClient.java
@@ -0,0 +1,116 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.xbaya.test.service.echo;
+
+import java.net.URI;
+
+import org.apache.airavata.common.utils.XMLUtil;
+import org.apache.airavata.xbaya.XBayaConfiguration;
+import org.apache.airavata.xbaya.lead.LeadContextHeaderHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xmlpull.v1.builder.XmlElement;
+
+import xsul.lead.LeadContextHeader;
+import xsul.wsif.WSIFMessage;
+import xsul.wsif.WSIFOperation;
+import xsul.wsif.WSIFPort;
+import xsul.xhandler_soap_sticky_header.StickySoapHeaderHandler;
+import xsul.xwsif_runtime.WSIFClient;
+import xsul.xwsif_runtime.WSIFRuntime;
+import xsul.xwsif_runtime_async.WSIFAsyncResponsesCorrelator;
+
+public class EchoClient {
+
+ private final static Logger logger = LoggerFactory.getLogger(EchoClient.class);
+
+ private EchoService service;
+
+ /**
+ *
+ */
+ public void run() {
+ String wsdlLoc = startServer();
+ runClient(wsdlLoc);
+ shutdownServer();
+ }
+
+ private String startServer() {
+ this.service = new EchoService(0);
+ this.service.run();
+ return this.service.getServiceWsdlLocation();
+ }
+
+ private void shutdownServer() {
+ this.service.shutdownServer();
+ }
+
+ private void runClient(String wsdlLoc) {
+ logger.info("Starting " + EchoClient.class.getName());
+ logger.info("Invoking operation echoString using WSDL from " + wsdlLoc);
+
+ WSIFAsyncResponsesCorrelator correlator;
+ correlator = null;
+
+ // pass some headers
+ LeadContextHeaderHelper helper = new LeadContextHeaderHelper();
+ helper.setXBayaConfiguration(new XBayaConfiguration());
+ LeadContextHeader leadContext = helper.getLeadContextHeader();
+ leadContext.setWorkflowId(URI.create("http://host/2005/11/09/workflowinstace"));
+ leadContext.setNodeId("decoder1");
+ leadContext.setTimeStep("5");
+ leadContext.setServiceId("decoder-instance-10");
+
+ WSIFClient wclient = WSIFRuntime.newClient(wsdlLoc)
+ .addHandler(new StickySoapHeaderHandler("use-lead-header", leadContext)).useAsyncMessaging(correlator)
+ .setAsyncResponseTimeoutInMs(33000L); // to simplify testing set to just few
+ // seconds
+
+ WSIFPort port = wclient.getPort();
+ WSIFOperation operation = port.createOperation("echo");
+ WSIFMessage inputMessage = operation.createInputMessage();
+ WSIFMessage outputMessage = operation.createOutputMessage();
+ WSIFMessage faultMessage = operation.createFaultMessage();
+
+ inputMessage.setObjectPart("input", "test");
+
+ logger.info("Using WSIF to send message:\n" + XMLUtil.xmlElementToString((XmlElement) inputMessage));
+ boolean success = operation.executeRequestResponseOperation(inputMessage, outputMessage, faultMessage);
+
+ XmlElement result;
+ if (success) {
+ result = (XmlElement) outputMessage;
+ } else {
+ result = (XmlElement) faultMessage;
+ }
+ logger.info("Received message:\n" + XMLUtil.xmlElementToString(result));
+
+ logger.info("Finished");
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ (new EchoClient()).run();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/service/echo/EchoImpl.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/service/echo/EchoImpl.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/service/echo/EchoImpl.java
new file mode 100644
index 0000000..e0a0243
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/service/echo/EchoImpl.java
@@ -0,0 +1,73 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.xbaya.test.service.echo;
+
+import java.util.Random;
+
+import org.apache.airavata.common.utils.XMLUtil;
+import org.apache.airavata.xbaya.test.service.ServiceNotificationSender;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xmlpull.v1.builder.XmlElement;
+import org.xmlpull.v1.builder.XmlNamespace;
+
+import xsul.XmlConstants;
+
+public class EchoImpl implements Echo {
+
+ private final static Logger logger = LoggerFactory.getLogger(EchoImpl.class);
+
+ /**
+ * @see org.apache.airavata.xbaya.test.service.echo.Echo#echo(org.xmlpull.v1.builder.XmlElement)
+ */
+ public XmlElement echo(XmlElement inputElement) {
+ logger.info(XMLUtil.xmlElementToString(inputElement));
+
+ ServiceNotificationSender notifier = ServiceNotificationSender.invoked(inputElement);
+
+ XmlElement input = inputElement.requiredElement(null, "input");
+
+ Random random = new Random();
+ int msec = random.nextInt(5000);
+ logger.info("Sleep for " + msec + " msec");
+ try {
+ Thread.sleep(msec);
+ } catch (InterruptedException e) {
+ logger.error(e.getMessage(), e);
+ }
+
+ XmlElement output = input;
+ output.setParent(null);
+ output.setName("output");
+
+ XmlNamespace namespace = XmlConstants.BUILDER.newNamespace("echotypens",
+ "http://www.extreme.indiana.edu/math/echo/xsd/");
+ XmlElement outputElement = XmlConstants.BUILDER.newFragment(namespace, "EchoOutput");
+ outputElement.addElement(output);
+
+ if (notifier != null) {
+ notifier.sendingResult(outputElement);
+ }
+ logger.info(XMLUtil.xmlElementToString(outputElement));
+ return outputElement;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/service/echo/EchoService.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/service/echo/EchoService.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/service/echo/EchoService.java
new file mode 100644
index 0000000..c3c58a8
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/service/echo/EchoService.java
@@ -0,0 +1,113 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.xbaya.test.service.echo;
+
+import java.io.File;
+
+import org.apache.airavata.common.utils.XMLUtil;
+import org.apache.airavata.xbaya.test.service.Service;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import xsul.lead.LeadContextHeader;
+import xsul.wsdl.WsdlDefinitions;
+import xsul.xhandler_soap_sticky_header.StickySoapHeaderHandler;
+import xsul.xservo.XService;
+import xsul.xservo_soap.XSoapDocLiteralService;
+import xsul.xservo_soap_http.HttpBasedServices;
+
+public class EchoService implements Service {
+
+ private final static Logger logger = LoggerFactory.getLogger(EchoService.class);
+
+ private HttpBasedServices httpServices;
+
+ private XService xservice;
+
+ private int port;
+
+ /**
+ * Constructs an EchoService.
+ *
+ * @param port
+ */
+ public EchoService(int port) {
+ this.port = port;
+ }
+
+ /**
+ * Runs the service.
+ */
+ public void run() {
+ this.httpServices = new HttpBasedServices(this.port);
+ this.xservice = this.httpServices.addService(new XSoapDocLiteralService(Echo.SERVICE_NAME,
+ Service.MATH_DIRECTORY_NAME + File.separator + Echo.WSDL_PATH, new EchoImpl()));
+ this.xservice.addHandler(new StickySoapHeaderHandler("retrieve-lead-header", LeadContextHeader.TYPE));
+ this.xservice.startService();
+ }
+
+ /**
+ * Returns the location of the WSDL of the service.
+ *
+ * @return The location of the WSDL of the service.
+ */
+ public String getServiceWsdlLocation() {
+ return this.httpServices.getServer().getLocation() + "/" + Echo.SERVICE_NAME + "?wsdl";
+ }
+
+ /**
+ * Returns the WSDL of the service.
+ *
+ * @return The WSDL of the service.
+ */
+ public WsdlDefinitions getWsdl() {
+ return this.xservice.getWsdl();
+ }
+
+ /**
+ * Shutdowns the service.
+ */
+ public void shutdownServer() {
+ this.httpServices.getServer().shutdownServer();
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ try {
+ int port = 0;
+ if (args.length == 2) {
+ if ("-port".equalsIgnoreCase(args[0])) {
+ port = Integer.parseInt(args[1]);
+ }
+ }
+ EchoService service = new EchoService(port);
+ service.run();
+ WsdlDefinitions wsdl = service.getWsdl();
+ File wsdlFile = new File(SAMPLE_WSDL_DIRECTORY, Echo.WSDL_NAME);
+ XMLUtil.saveXML(wsdl, wsdlFile);
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/service/multiplier/Multiplier.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/service/multiplier/Multiplier.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/service/multiplier/Multiplier.java
new file mode 100644
index 0000000..c1cde5c
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/service/multiplier/Multiplier.java
@@ -0,0 +1,54 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.xbaya.test.service.multiplier;
+
+import java.io.File;
+
+import org.apache.airavata.xbaya.test.service.Service;
+import org.xmlpull.v1.builder.XmlElement;
+
+import xsul.xwsif_runtime.XmlElementBasedStub;
+
+public interface Multiplier extends XmlElementBasedStub {
+
+ /**
+ * SERVICE_NAME
+ */
+ public final static String SERVICE_NAME = "MultiplierService";
+
+ /**
+ * WSDL_NAME
+ */
+ public final static String WSDL_NAME = "multiplier.wsdl";
+
+ /**
+ * WSDL_PATH
+ */
+ public final static String WSDL_PATH = Service.MATH_DIRECTORY_NAME + File.separator + WSDL_NAME;
+
+ /**
+ * @param input
+ * the input message
+ * @return the output message
+ */
+ public XmlElement multiply(XmlElement input);
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/service/multiplier/MultiplierImpl.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/service/multiplier/MultiplierImpl.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/service/multiplier/MultiplierImpl.java
new file mode 100644
index 0000000..6b53c0a
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/service/multiplier/MultiplierImpl.java
@@ -0,0 +1,80 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.xbaya.test.service.multiplier;
+
+import java.util.Random;
+
+import org.apache.airavata.common.utils.XMLUtil;
+import org.apache.airavata.xbaya.test.service.ServiceNotificationSender;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xmlpull.v1.builder.XmlElement;
+import org.xmlpull.v1.builder.XmlNamespace;
+
+import xsul.XmlConstants;
+
+public class MultiplierImpl implements Multiplier {
+
+ private final static Logger logger = LoggerFactory.getLogger(MultiplierImpl.class);
+
+ /**
+ * @see org.apache.airavata.xbaya.test.service.multiplier.Multiplier#multiply(org.xmlpull.v1.builder.XmlElement)
+ */
+ public XmlElement multiply(XmlElement inputElement) {
+ logger.info(XMLUtil.xmlElementToString(inputElement));
+
+ ServiceNotificationSender notifier = ServiceNotificationSender.invoked(inputElement);
+
+ XmlElement xElement = inputElement.requiredElement(null, "x");
+ XmlElement yElement = inputElement.requiredElement(null, "y");
+ String xString = xElement.requiredTextContent();
+ String yString = yElement.requiredTextContent();
+
+ int x = Integer.parseInt(xString);
+ int y = Integer.parseInt(yString);
+
+ Random random = new Random();
+ int msec = random.nextInt(10000);
+ logger.info("Sleep for " + msec + " msec");
+ try {
+ Thread.sleep(msec);
+ } catch (InterruptedException e) {
+ logger.error(e.getMessage(), e);
+ }
+
+ int z = x * y;
+
+ String zString = "" + z;
+
+ XmlNamespace namespace = XmlConstants.BUILDER.newNamespace("multipliertypens",
+ "http://www.extreme.indiana.edu/math/multiplier/xsd/");
+ XmlElement outputElement = XmlConstants.BUILDER.newFragment(namespace, "MultiplyOutput");
+ XmlElement zElement = outputElement.addElement("z");
+ zElement.addChild(zString);
+
+ if (notifier != null) {
+ notifier.sendingResult(outputElement);
+ }
+ logger.info(XMLUtil.xmlElementToString(outputElement));
+ return outputElement;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/service/multiplier/MultiplierService.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/service/multiplier/MultiplierService.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/service/multiplier/MultiplierService.java
new file mode 100644
index 0000000..e4d910b
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/service/multiplier/MultiplierService.java
@@ -0,0 +1,132 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.xbaya.test.service.multiplier;
+
+import java.io.File;
+
+import org.apache.airavata.common.utils.XMLUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import xsul.lead.LeadContextHeader;
+import xsul.wsdl.WsdlDefinitions;
+import xsul.xhandler_soap_sticky_header.StickySoapHeaderHandler;
+import xsul.xservo.XService;
+import xsul.xservo_soap.XSoapDocLiteralService;
+import xsul.xservo_soap_http.HttpBasedServices;
+
+public class MultiplierService {
+
+ private final static String SERVICE_NAME = "MultiplierService";
+
+ private final static String BASE_WSDL_LOCATION = "wsdls/math/multiplier-wsdl.xml";
+
+ private final static String OUTPUT_WSDL_LOCATION = "wsdls/sample/multiplier-wsdl.xml";
+
+ private final static Logger logger = LoggerFactory.getLogger(MultiplierService.class);
+
+ private HttpBasedServices httpServices;
+
+ private XService xservice;
+
+ private int port;
+
+ /**
+ * Constructs a MultiplierService.
+ *
+ */
+ public MultiplierService() {
+ this(0);
+ }
+
+ /**
+ * Constructs a MultiplierService.
+ *
+ * @param port
+ */
+ public MultiplierService(int port) {
+ this.port = port;
+ }
+
+ /**
+ * Runs the service.
+ */
+ public void run() {
+ this.httpServices = new HttpBasedServices(this.port);
+ logger.info("Server started on " + this.httpServices.getServerPort());
+
+ logger.info("Using WSDL for service description from " + BASE_WSDL_LOCATION);
+ this.xservice = this.httpServices.addService(new XSoapDocLiteralService(SERVICE_NAME, BASE_WSDL_LOCATION,
+ new MultiplierImpl()));
+ this.xservice.addHandler(new StickySoapHeaderHandler("retrieve-lead-header", LeadContextHeader.TYPE));
+ this.xservice.startService();
+ logger.info("Service started");
+ logger.info("Service WSDL available at " + getServiceWsdlLocation());
+ }
+
+ /**
+ * Returns the location of the WSDL.
+ *
+ * @return The location of the WSDL
+ */
+ public String getServiceWsdlLocation() {
+ return this.httpServices.getServer().getLocation() + "/" + SERVICE_NAME + "?wsdl";
+ }
+
+ /**
+ * Returns the WSDL of the service.
+ *
+ * @return The WSDL of the service.
+ */
+ public WsdlDefinitions getWsdl() {
+ return this.xservice.getWsdl();
+ }
+
+ /**
+ * Shutdowns the service.
+ */
+ public void shutdownServer() {
+ this.httpServices.getServer().shutdownServer();
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ try {
+ int port = 0;
+ if (args.length == 2) {
+ if ("-port".equalsIgnoreCase(args[0])) {
+ port = Integer.parseInt(args[1]);
+ }
+ }
+ MultiplierService service = new MultiplierService(port);
+ service.run();
+ WsdlDefinitions wsdl = service.getWsdl();
+ File wsdlFile = new File(OUTPUT_WSDL_LOCATION);
+ XMLUtil.saveXML(wsdl, wsdlFile);
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/util/WorkflowCreator.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/util/WorkflowCreator.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/util/WorkflowCreator.java
new file mode 100644
index 0000000..708788a
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/test/util/WorkflowCreator.java
@@ -0,0 +1,741 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.xbaya.test.util;
+
+import java.awt.Point;
+
+import org.apache.airavata.workflow.model.component.Component;
+import org.apache.airavata.workflow.model.component.ComponentException;
+import org.apache.airavata.workflow.model.component.ComponentRegistryException;
+import org.apache.airavata.workflow.model.component.local.LocalComponentRegistry;
+import org.apache.airavata.workflow.model.component.system.ConstantComponent;
+import org.apache.airavata.workflow.model.component.system.DoWhileComponent;
+import org.apache.airavata.workflow.model.component.system.EndDoWhileComponent;
+import org.apache.airavata.workflow.model.component.system.EndForEachComponent;
+import org.apache.airavata.workflow.model.component.system.EndifComponent;
+import org.apache.airavata.workflow.model.component.system.ForEachComponent;
+import org.apache.airavata.workflow.model.component.system.IfComponent;
+import org.apache.airavata.workflow.model.component.system.InputComponent;
+import org.apache.airavata.workflow.model.component.system.OutputComponent;
+import org.apache.airavata.workflow.model.component.system.ReceiveComponent;
+import org.apache.airavata.workflow.model.graph.Graph;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.graph.Node;
+import org.apache.airavata.workflow.model.graph.system.ConstantNode;
+import org.apache.airavata.workflow.model.graph.system.DoWhileNode;
+import org.apache.airavata.workflow.model.graph.system.IfNode;
+import org.apache.airavata.workflow.model.graph.system.InputNode;
+import org.apache.airavata.workflow.model.graph.system.OutputNode;
+import org.apache.airavata.workflow.model.graph.system.ReceiveNode;
+import org.apache.airavata.workflow.model.wf.Workflow;
+import org.apache.airavata.xbaya.file.XBayaPathConstants;
+import org.apache.airavata.xbaya.test.service.adder.Adder;
+import org.apache.airavata.xbaya.test.service.approver.Approver;
+import org.apache.airavata.xbaya.test.service.arrayadder.ArrayAdder;
+import org.apache.airavata.xbaya.test.service.arraygen.ArrayGenerator;
+import org.apache.airavata.xbaya.test.service.echo.Echo;
+import org.apache.airavata.xbaya.test.service.multiplier.Multiplier;
+
+public class WorkflowCreator {
+
+ /**
+ * GFAC_TEST_AWSDL
+ */
+ public static final String GFAC_TEST_AWSDL = "TestCMD_Example1_AWSDL.xml";
+
+ private Component inputComponent;
+
+ private Component outputComponent;
+
+ private LocalComponentRegistry componentRegistry;
+
+ private ConstantComponent constantComponent;
+
+ private ForEachComponent splitComponent;
+
+ private EndForEachComponent mergeComponent;
+
+ private IfComponent ifComponent;
+
+ private EndifComponent endifComponent;
+
+ private ReceiveComponent receiveComponent;
+
+ private DoWhileComponent doWhileComponent;
+
+ private EndDoWhileComponent endDoWhileComponent;
+
+ /**
+ * Constructs a WorkflowCreator.
+ */
+ public WorkflowCreator() {
+ this.componentRegistry = new LocalComponentRegistry(XBayaPathConstants.WSDL_DIRECTORY);
+ this.inputComponent = new InputComponent();
+ this.outputComponent = new OutputComponent();
+ this.constantComponent = new ConstantComponent();
+ this.splitComponent = new ForEachComponent();
+ this.mergeComponent = new EndForEachComponent();
+ this.ifComponent = new IfComponent();
+ this.endifComponent = new EndifComponent();
+ this.receiveComponent = new ReceiveComponent();
+ this.doWhileComponent = new DoWhileComponent();
+ this.endDoWhileComponent = new EndDoWhileComponent();
+ }
+
+ /**
+ * @return The graph
+ * @throws ComponentException
+ * @throws GraphException
+ * @throws ComponentRegistryException
+ */
+ public Workflow createSimpleMathWorkflow() throws ComponentException, GraphException, ComponentRegistryException {
+ Workflow workflow = new Workflow();
+
+ // Name, description
+ workflow.setName("Simple math workflow");
+ workflow.setDescription("Simple math workflow");
+
+ Graph graph = workflow.getGraph();
+
+ // Adder node
+ Component adderComp = this.componentRegistry.getComponent(Adder.WSDL_PATH);
+ Node adderNode = workflow.addNode(adderComp);
+ adderNode.setPosition(new Point(250, 100));
+
+ // Input parameter node 1
+ InputNode paramNode1 = (InputNode) workflow.addNode(this.inputComponent);
+ paramNode1.setPosition(new Point(50, 50));
+
+ // Input parameter node 2
+ InputNode paramNode2 = (InputNode) workflow.addNode(this.inputComponent);
+ paramNode2.setPosition(new Point(50, 120));
+
+ // Output parameter
+ OutputNode outParamNode = (OutputNode) workflow.addNode(this.outputComponent);
+ outParamNode.setPosition(new Point(300, 220));
+
+ // Connect ports
+ graph.addEdge(paramNode1.getOutputPort(0), adderNode.getInputPort(0));
+ graph.addEdge(paramNode2.getOutputPort(0), adderNode.getInputPort(1));
+ graph.addEdge(adderNode.getOutputPort(0), outParamNode.getInputPort(0));
+
+ // Set the default values
+ // This needs to be after connection.
+ String paramValue1 = "2";
+ paramNode1.setDefaultValue(paramValue1);
+ String paramValue2 = "3";
+ paramNode2.setDefaultValue(paramValue2);
+ return workflow;
+ }
+
+ /**
+ * @return The graph
+ * @throws ComponentException
+ * @throws GraphException
+ * @throws ComponentRegistryException
+ */
+ public Workflow createMathWorkflow() throws ComponentException, GraphException, ComponentRegistryException {
+ Workflow workflow = new Workflow();
+
+ // Name, description
+ workflow.setName("Math workflow");
+ workflow.setDescription("A workflow that calculates (a + b) * c.");
+
+ Graph graph = workflow.getGraph();
+
+ // Adder node
+ Component adderComp = this.componentRegistry.getComponent(Adder.WSDL_PATH);
+
+ Node adderNode1 = workflow.addNode(adderComp);
+ adderNode1.setPosition(new Point(170, 50));
+
+ // Multiplier node
+ Component multiComp = this.componentRegistry.getComponent(Multiplier.WSDL_PATH);
+
+ Node multiNode = workflow.addNode(multiComp);
+ multiNode.setPosition(new Point(320, 130));
+
+ // Input node 1
+ InputNode inputNode1 = (InputNode) workflow.addNode(this.inputComponent);
+ inputNode1.setPosition(new Point(20, 30));
+
+ // Input node 2
+ InputNode inputNode2 = (InputNode) workflow.addNode(this.inputComponent);
+ inputNode2.setPosition(new Point(20, 100));
+
+ // Input node 3
+ InputNode inputNode3 = (InputNode) workflow.addNode(this.inputComponent);
+ inputNode3.setPosition(new Point(20, 170));
+
+ // Output
+ OutputNode outputNode = (OutputNode) workflow.addNode(this.outputComponent);
+ outputNode.setPosition(new Point(500, 130));
+
+ // Connect ports
+ graph.addEdge(inputNode1.getOutputPort(0), adderNode1.getInputPort(0));
+ graph.addEdge(inputNode2.getOutputPort(0), adderNode1.getInputPort(1));
+ graph.addEdge(adderNode1.getOutputPort(0), multiNode.getInputPort(0));
+ graph.addEdge(inputNode3.getOutputPort(0), multiNode.getInputPort(1));
+ graph.addEdge(multiNode.getOutputPort(0), outputNode.getInputPort(0));
+
+ // Set the default values
+ // This needs to be after connection.
+ inputNode1.setConfiguredName("a");
+ inputNode2.setConfiguredName("b");
+ inputNode3.setConfiguredName("c");
+ inputNode1.setConfigured(true);
+ inputNode2.setConfigured(true);
+ inputNode3.setConfigured(true);
+ inputNode1.setDefaultValue("2");
+ inputNode2.setDefaultValue("3");
+ inputNode3.setDefaultValue("4");
+ outputNode.setConfiguredName("z");
+ outputNode.setConfigured(true);
+
+ return workflow;
+ }
+
+ /**
+ * @return The graph
+ * @throws ComponentException
+ * @throws GraphException
+ * @throws ComponentRegistryException
+ */
+ public Workflow createComplexMathWorkflow() throws ComponentException, GraphException, ComponentRegistryException {
+ Workflow workflow = new Workflow();
+
+ // Name, description
+ workflow.setName("Complex math workflow");
+ workflow.setDescription("Complex math workflow");
+
+ Graph graph = workflow.getGraph();
+
+ // Adder nodes
+ Component adderComp = this.componentRegistry.getComponent(Adder.WSDL_PATH);
+
+ Node adderNode1 = workflow.addNode(adderComp);
+ adderNode1.setPosition(new Point(170, 50));
+
+ Node adderNode2 = workflow.addNode(adderComp);
+ adderNode2.setPosition(new Point(170, 210));
+
+ // Multiplier node
+ Component multiComp = this.componentRegistry.getComponent(Multiplier.WSDL_PATH);
+
+ Node multiNode = workflow.addNode(multiComp);
+ multiNode.setPosition(new Point(320, 130));
+
+ // Input node 1
+ InputNode inputNode1 = (InputNode) workflow.addNode(this.inputComponent);
+ inputNode1.setPosition(new Point(20, 30));
+
+ // Input node 2
+ InputNode inputNode2 = (InputNode) workflow.addNode(this.inputComponent);
+ inputNode2.setPosition(new Point(20, 100));
+
+ // Input node 3
+ InputNode inputNode3 = (InputNode) workflow.addNode(this.inputComponent);
+ inputNode3.setPosition(new Point(20, 170));
+
+ // Input node 4
+ InputNode inputNode4 = (InputNode) workflow.addNode(this.inputComponent);
+ inputNode4.setPosition(new Point(20, 240));
+
+ // Output
+ OutputNode outputNode = (OutputNode) workflow.addNode(this.outputComponent);
+ outputNode.setPosition(new Point(500, 130));
+
+ // Connect ports
+ graph.addEdge(inputNode1.getOutputPort(0), adderNode1.getInputPort(0));
+ graph.addEdge(inputNode2.getOutputPort(0), adderNode1.getInputPort(1));
+ graph.addEdge(inputNode3.getOutputPort(0), adderNode2.getInputPort(0));
+ graph.addEdge(inputNode4.getOutputPort(0), adderNode2.getInputPort(1));
+ graph.addEdge(adderNode1.getOutputPort(0), multiNode.getInputPort(0));
+ graph.addEdge(adderNode2.getOutputPort(0), multiNode.getInputPort(1));
+ graph.addEdge(multiNode.getOutputPort(0), outputNode.getInputPort(0));
+
+ // Set the default values
+ // This needs to be after connection.
+ inputNode1.setConfiguredName("a");
+ inputNode2.setConfiguredName("b");
+ inputNode3.setConfiguredName("c");
+ inputNode4.setConfiguredName("d");
+ inputNode1.setDescription("This is the first input.");
+ inputNode2.setDescription("This is the second input.");
+ inputNode3.setDescription("This is the third input.");
+ inputNode4.setDescription("This is the fourth input.");
+ inputNode1.setConfigured(true);
+ inputNode2.setConfigured(true);
+ inputNode3.setConfigured(true);
+ inputNode4.setConfigured(true);
+ inputNode1.setDefaultValue("2");
+ inputNode2.setDefaultValue("3");
+ inputNode3.setDefaultValue("4");
+ inputNode4.setDefaultValue("5");
+ outputNode.setConfiguredName("z");
+ outputNode.setConfigured(true);
+
+ return workflow;
+ }
+
+ /**
+ * @return The graph
+ * @throws ComponentException
+ * @throws GraphException
+ * @throws ComponentRegistryException
+ */
+ public Workflow createMathWithConstWorkflow() throws ComponentException, GraphException, ComponentRegistryException {
+
+ Workflow workflow = new Workflow();
+
+ // Name, description
+ workflow.setName("Math with const");
+ workflow.setDescription("Math with const");
+
+ Graph graph = workflow.getGraph();
+
+ // Adder node
+ Component adderComp = this.componentRegistry.getComponent(Adder.WSDL_PATH);
+ Node adderNode = workflow.addNode(adderComp);
+ adderNode.setPosition(new Point(250, 100));
+
+ // Input parameter node
+ InputNode inputNode = (InputNode) workflow.addNode(this.inputComponent);
+ inputNode.setPosition(new Point(50, 50));
+
+ // Constant node
+ ConstantNode constantNode = (ConstantNode) workflow.addNode(this.constantComponent);
+ constantNode.setPosition(new Point(50, 120));
+
+ // Output parameter
+ OutputNode outParamNode = (OutputNode) workflow.addNode(this.outputComponent);
+ outParamNode.setPosition(new Point(300, 220));
+
+ // Connect ports
+ graph.addEdge(inputNode.getOutputPort(0), adderNode.getInputPort(0));
+ graph.addEdge(constantNode.getOutputPort(0), adderNode.getInputPort(1));
+ graph.addEdge(adderNode.getOutputPort(0), outParamNode.getInputPort(0));
+
+ // Set the default value of an input and the constant.
+ // This needs to be after connection.
+ String paramValue1 = "2";
+ inputNode.setDefaultValue(paramValue1);
+ String paramValue2 = "3";
+ constantNode.setValue(paramValue2);
+ return workflow;
+ }
+
+ /**
+ * @return The workflow
+ * @throws ComponentException
+ * @throws GraphException
+ * @throws ComponentRegistryException
+ */
+ public Workflow createArrayWorkflow() throws ComponentException, GraphException, ComponentRegistryException {
+ Workflow workflow = new Workflow();
+
+ // Name, description
+ workflow.setName("Array test");
+ workflow.setDescription("A workflow that tests arrays");
+
+ Graph graph = workflow.getGraph();
+
+ // n
+ InputNode inputN = (InputNode) workflow.addNode(this.inputComponent);
+ inputN.setPosition(new Point(0, 80));
+
+ // Array generator
+ Component arrayGeneratorComponent = this.componentRegistry.getComponent(ArrayGenerator.WSDL_PATH);
+ Node arrayGenerator = workflow.addNode(arrayGeneratorComponent);
+ arrayGenerator.setPosition(new Point(150, 80));
+
+ // Array adder
+ Component arrayAdderComponent = this.componentRegistry.getComponent(ArrayAdder.WSDL_PATH);
+ Node arrayAdder = workflow.addNode(arrayAdderComponent);
+ arrayAdder.setPosition(new Point(400, 80));
+
+ // Output
+ OutputNode output = (OutputNode) workflow.addNode(this.outputComponent);
+ output.setConfiguredName("output");
+ output.setPosition(new Point(550, 80));
+
+ // Connect ports
+ graph.addEdge(inputN.getOutputPort(0), arrayGenerator.getInputPort(0));
+ graph.addEdge(arrayGenerator.getOutputPort(0), arrayAdder.getInputPort(0));
+ graph.addEdge(arrayAdder.getOutputPort(0), output.getInputPort(0));
+
+ // Set the default values
+ // This needs to be after connection.
+ String n = "5";
+ inputN.setDefaultValue(n);
+
+ return workflow;
+ }
+
+ /**
+ * @return The workflow
+ * @throws ComponentException
+ * @throws GraphException
+ * @throws ComponentRegistryException
+ */
+ public Workflow createForEachWorkflow() throws ComponentException, GraphException, ComponentRegistryException {
+ Workflow workflow = new Workflow();
+
+ // Name, description
+ workflow.setName("ForEach test");
+ workflow.setDescription("Workflow that tests if");
+
+ Graph graph = workflow.getGraph();
+
+ // x
+ InputNode inputX = (InputNode) workflow.addNode(this.inputComponent);
+ inputX.setPosition(new Point(0, 0));
+
+ // n
+ InputNode inputN = (InputNode) workflow.addNode(this.inputComponent);
+ inputN.setPosition(new Point(0, 80));
+
+ // Array generator
+ Component arrayGeneratorComponent = this.componentRegistry.getComponent(ArrayGenerator.WSDL_PATH);
+ Node arrayGenerator = workflow.addNode(arrayGeneratorComponent);
+ arrayGenerator.setPosition(new Point(120, 80));
+
+ // Split
+ Node split = workflow.addNode(this.splitComponent);
+ split.setPosition(new Point(310, 80));
+
+ // Adder
+ Component adderComponent = this.componentRegistry.getComponent(Adder.WSDL_PATH);
+ Node adder = workflow.addNode(adderComponent);
+ adder.setPosition(new Point(440, 40));
+
+ // Merge
+ Node merge = workflow.addNode(this.mergeComponent);
+ merge.setPosition(new Point(580, 40));
+
+ // Output
+ OutputNode output = (OutputNode) workflow.addNode(this.outputComponent);
+ output.setConfiguredName("output");
+ output.setPosition(new Point(720, 40));
+
+ // Connect ports
+ graph.addEdge(inputX.getOutputPort(0), adder.getInputPort(0));
+ graph.addEdge(inputN.getOutputPort(0), arrayGenerator.getInputPort(0));
+ graph.addEdge(arrayGenerator.getOutputPort(0), split.getInputPort(0));
+ graph.addEdge(split.getOutputPort(0), adder.getInputPort(1));
+ graph.addEdge(adder.getOutputPort(0), merge.getInputPort(0));
+ graph.addEdge(merge.getOutputPort(0), output.getInputPort(0));
+
+ // Set the default values
+ // This needs to be after connection.
+ String x = "2";
+ inputX.setDefaultValue(x);
+ String n = "3";
+ inputN.setDefaultValue(n);
+
+ return workflow;
+ }
+
+ /**
+ * @return The workflow
+ * @throws ComponentException
+ * @throws GraphException
+ * @throws ComponentRegistryException
+ * @throws ComponentException
+ * @throws ComponentRegistryException
+ */
+ public Workflow createIfWorkflow() throws GraphException, ComponentException, ComponentRegistryException {
+ Workflow workflow = new Workflow();
+
+ // Name, description
+ workflow.setName("If test");
+ workflow.setDescription("Workflow that tests if");
+
+ Graph graph = workflow.getGraph();
+
+ // x
+ InputNode x = (InputNode) workflow.addNode(this.inputComponent);
+ x.setPosition(new Point(10, 10));
+
+ // y
+ InputNode y = (InputNode) workflow.addNode(this.inputComponent);
+ y.setPosition(new Point(10, 90));
+
+ // const0
+ ConstantNode const0 = (ConstantNode) workflow.addNode(this.constantComponent);
+ const0.setPosition(new Point(20, 180));
+
+ // if
+ IfNode ifNode = (IfNode) workflow.addNode(this.ifComponent);
+ ifNode.setPosition(new Point(170, 180));
+
+ // Adder nodes
+ Component adderComp = this.componentRegistry.getComponent(Adder.WSDL_PATH);
+
+ Node adder = workflow.addNode(adderComp);
+ adder.setPosition(new Point(400, 10));
+
+ // Multiplier node
+ Component multiComp = this.componentRegistry.getComponent(Multiplier.WSDL_PATH);
+
+ Node multiplier = workflow.addNode(multiComp);
+ multiplier.setPosition(new Point(400, 90));
+
+ // endif
+ Node endif = workflow.addNode(this.endifComponent);
+ endif.setPosition(new Point(550, 40));
+
+ // Output
+ OutputNode output = (OutputNode) workflow.addNode(this.outputComponent);
+ output.setConfiguredName("output");
+ output.setPosition(new Point(700, 40));
+
+ // Connect ports
+ graph.addEdge(x.getOutputPort(0), adder.getInputPort(0));
+ graph.addEdge(x.getOutputPort(0), multiplier.getInputPort(0));
+ graph.addEdge(y.getOutputPort(0), adder.getInputPort(1));
+ graph.addEdge(y.getOutputPort(0), multiplier.getInputPort(1));
+ graph.addEdge(const0.getOutputPort(0), ifNode.getInputPort(0));
+ graph.addEdge(ifNode.getControlOutPorts().get(0), adder.getControlInPort());
+ graph.addEdge(ifNode.getControlOutPorts().get(1), multiplier.getControlInPort());
+ graph.addEdge(adder.getOutputPort(0), endif.getInputPort(0));
+ graph.addEdge(multiplier.getOutputPort(0), endif.getInputPort(1));
+ graph.addEdge(endif.getOutputPort(0), output.getInputPort(0));
+
+ // Set the default values
+ // This needs to be after connection.
+ x.setDefaultValue("2");
+ y.setDefaultValue("3");
+ const0.setValue("adder");
+ ifNode.setXPath("$0 = 'adder'");
+
+ return workflow;
+ }
+
+ /**
+ * @return The workflow
+ * @throws GraphException
+ * @throws ComponentRegistryException
+ * @throws ComponentException
+ */
+ public Workflow createReceiveWorkflow() throws GraphException, ComponentException, ComponentRegistryException {
+ Workflow workflow = new Workflow();
+
+ // Name, description
+ workflow.setName("Receive test");
+ workflow.setDescription("Workflow that tests receive");
+
+ Graph graph = workflow.getGraph();
+
+ // Adder nodes
+ Component echoComponent = this.componentRegistry.getComponent(Echo.WSDL_PATH);
+
+ Node echo = workflow.addNode(echoComponent);
+ echo.setPosition(new Point(40, 40));
+
+ // receive
+ ReceiveNode receive = (ReceiveNode) workflow.addNode(this.receiveComponent);
+ receive.setPosition(new Point(200, 200));
+
+ // Output
+ OutputNode output1 = (OutputNode) workflow.addNode(this.outputComponent);
+ output1.setPosition(new Point(350, 40));
+
+ OutputNode output2 = (OutputNode) workflow.addNode(this.outputComponent);
+ output2.setPosition(new Point(350, 200));
+
+ // Connect ports
+ graph.addEdge(receive.getEPRPort(), echo.getInputPort(0));
+ graph.addEdge(echo.getOutputPort(0), output1.getInputPort(0));
+ graph.addEdge(receive.getOutputPort(0), output2.getInputPort(0));
+ graph.addEdge(echo.getControlOutPorts().get(0), receive.getControlInPort());
+
+ // Confugure
+ output1.setConfiguredName("output1");
+ output1.setConfigured(true);
+ output2.setConfiguredName("output2");
+ output2.setConfigured(true);
+
+ return workflow;
+
+ }
+
+ /**
+ * @return The graph
+ * @throws ComponentException
+ * @throws GraphException
+ * @throws ComponentRegistryException
+ */
+ public Workflow createGFacWorkflow() throws ComponentException, GraphException, ComponentRegistryException {
+
+ Workflow workflow = new Workflow();
+
+ // Name, description
+ workflow.setName("GFac test workflow");
+ workflow.setDescription("GFac test workflow");
+
+ Graph graph = workflow.getGraph();
+
+ // Adder node
+ Component gfacComp = this.componentRegistry.getComponent(GFAC_TEST_AWSDL);
+ Node gfacNode = workflow.addNode(gfacComp);
+ gfacNode.setPosition(new Point(250, 100));
+
+ // Input parameter node 1
+ InputNode paramNode1 = (InputNode) workflow.addNode(this.inputComponent);
+ paramNode1.setPosition(new Point(50, 50));
+ String paramValue1 = "300";
+ paramNode1.setDefaultValue(paramValue1);
+
+ // Output parameter
+ OutputNode outParamNode = (OutputNode) workflow.addNode(this.outputComponent);
+ outParamNode.setPosition(new Point(300, 220));
+
+ // Connect ports
+ graph.addEdge(paramNode1.getOutputPort(0), gfacNode.getInputPort(0));
+ graph.addEdge(gfacNode.getOutputPort(0), outParamNode.getInputPort(0));
+
+ return workflow;
+ }
+
+ /**
+ * @return The workflow created.
+ * @throws GraphException
+ * @throws ComponentException
+ * @throws ComponentRegistryException
+ */
+ public Workflow createLoanWorkflow() throws GraphException, ComponentException, ComponentRegistryException {
+ Workflow workflow = new Workflow();
+
+ // Name, description
+ workflow.setName("Loan Approval");
+ workflow.setDescription("Loan Approval");
+
+ Graph graph = workflow.getGraph();
+
+ // amount
+ InputNode amount = (InputNode) workflow.addNode(this.inputComponent);
+ amount.setPosition(new Point(10, 10));
+
+ // if
+ IfNode ifNode = (IfNode) workflow.addNode(this.ifComponent);
+ ifNode.setPosition(new Point(200, 100));
+
+ // Approver nodes
+ Component approverComponent = this.componentRegistry.getComponent(Approver.WSDL_PATH);
+
+ Node approver = workflow.addNode(approverComponent);
+ approver.setPosition(new Point(350, 10));
+
+ // const
+ ConstantNode constYes = (ConstantNode) workflow.addNode(this.constantComponent);
+ constYes.setPosition(new Point(350, 200));
+
+ // endif
+ Node endif = workflow.addNode(this.endifComponent);
+ endif.setPosition(new Point(550, 100));
+
+ // Output
+ OutputNode output = (OutputNode) workflow.addNode(this.outputComponent);
+ output.setPosition(new Point(700, 100));
+
+ // Connect ports
+ graph.addEdge(amount.getOutputPort(0), approver.getInputPort(0));
+ graph.addEdge(amount.getOutputPort(0), ifNode.getInputPort(0));
+ graph.addEdge(ifNode.getControlOutPorts().get(0), approver.getControlInPort());
+ graph.addEdge(ifNode.getControlOutPorts().get(1), constYes.getControlInPort());
+ graph.addEdge(approver.getOutputPort(0), endif.getInputPort(0));
+ graph.addEdge(constYes.getOutputPort(0), endif.getInputPort(1));
+ graph.addEdge(endif.getOutputPort(0), output.getInputPort(0));
+
+ // Set the default values
+ // This needs to be after connection.
+ amount.setDefaultValue("500");
+ constYes.setValue("Yes");
+ ifNode.setXPath("$0 > 1000");
+ output.setConfiguredName("accept");
+ output.setConfigured(true);
+
+ return workflow;
+ }
+ /**
+ * Create a dowhile workflow
+ * @return Workflow created.
+ * @throws GraphException
+ * @throws ComponentException
+ * @throws ComponentRegistryException
+ */
+ public Workflow createDoWhileWorkflow() throws GraphException, ComponentException, ComponentRegistryException {
+ Workflow workflow = new Workflow();
+
+ // Name, description
+ workflow.setName("Do While");
+ workflow.setDescription("Do While");
+
+ Graph graph = workflow.getGraph();
+
+ // amount
+ InputNode amount = (InputNode) workflow.addNode(this.inputComponent);
+ amount.setPosition(new Point(10, 10));
+
+ // if
+ DoWhileNode doWhileNode = (DoWhileNode) workflow.addNode(this.doWhileComponent);
+ doWhileNode.setPosition(new Point(200, 100));
+
+ // Approver nodes
+ Component approverComponent = this.componentRegistry.getComponent(Approver.WSDL_PATH);
+
+ Node approver = workflow.addNode(approverComponent);
+ approver.setPosition(new Point(350, 10));
+
+ // const
+ ConstantNode constYes = (ConstantNode) workflow.addNode(this.constantComponent);
+ constYes.setPosition(new Point(350, 200));
+
+ // endif
+ Node endDoWhile = workflow.addNode(this.endDoWhileComponent);
+ endDoWhile.setPosition(new Point(550, 100));
+
+ // Output
+ OutputNode output = (OutputNode) workflow.addNode(this.outputComponent);
+ output.setPosition(new Point(700, 100));
+
+ // Connect ports
+ graph.addEdge(amount.getOutputPort(0), approver.getInputPort(0));
+ graph.addEdge(amount.getOutputPort(0), doWhileNode.getInputPort(0));
+ graph.addEdge(doWhileNode.getControlOutPorts().get(0), approver.getControlInPort());
+ graph.addEdge(doWhileNode.getControlOutPorts().get(1), constYes.getControlInPort());
+ graph.addEdge(approver.getOutputPort(0), endDoWhile.getInputPort(0));
+ graph.addEdge(constYes.getOutputPort(0), endDoWhile.getInputPort(1));
+ graph.addEdge(endDoWhile.getOutputPort(0), output.getInputPort(0));
+
+ // Set the default values
+ // This needs to be after connection.
+ amount.setDefaultValue("0");
+ constYes.setValue("Yes");
+ doWhileNode.setXpath("$1 = 1");
+ output.setConfiguredName("accept");
+ output.setConfigured(true);
+
+ return workflow;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/XBayaGUI.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/XBayaGUI.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/XBayaGUI.java
new file mode 100644
index 0000000..0e36d3e
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/XBayaGUI.java
@@ -0,0 +1,850 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.xbaya.ui;
+
+import java.awt.BorderLayout;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Toolkit;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ContainerEvent;
+import java.awt.event.ContainerListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.swing.JFrame;
+import javax.swing.JOptionPane;
+import javax.swing.JSplitPane;
+import javax.swing.JTabbedPane;
+import javax.swing.SwingUtilities;
+import javax.swing.UIManager;
+import javax.swing.WindowConstants;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+import org.apache.airavata.client.api.exception.AiravataAPIInvocationException;
+import org.apache.airavata.common.utils.SwingUtil;
+import org.apache.airavata.common.utils.XMLUtil;
+import org.apache.airavata.workflow.model.component.Component;
+import org.apache.airavata.workflow.model.component.ComponentException;
+import org.apache.airavata.workflow.model.exceptions.WorkflowException;
+import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.graph.Node;
+import org.apache.airavata.workflow.model.graph.Port;
+import org.apache.airavata.workflow.model.wf.Workflow;
+import org.apache.airavata.ws.monitor.MonitorException;
+import org.apache.airavata.ws.monitor.event.Event;
+import org.apache.airavata.ws.monitor.event.Event.Type;
+import org.apache.airavata.ws.monitor.event.EventListener;
+import org.apache.airavata.xbaya.XBayaConfiguration;
+import org.apache.airavata.xbaya.XBayaConfiguration.XBayaExecutionMode;
+import org.apache.airavata.xbaya.XBayaConstants;
+import org.apache.airavata.xbaya.XBayaEngine;
+import org.apache.airavata.xbaya.core.generators.WorkflowFiler;
+import org.apache.airavata.xbaya.core.ide.XBayaExecutionModeListener;
+import org.apache.airavata.xbaya.ui.dialogs.ErrorWindow;
+import org.apache.airavata.xbaya.ui.dialogs.workflow.WorkflowPropertyWindow;
+import org.apache.airavata.xbaya.ui.graph.GraphCanvas;
+import org.apache.airavata.xbaya.ui.graph.GraphCanvasEvent;
+import org.apache.airavata.xbaya.ui.graph.GraphCanvasEvent.GraphCanvasEventType;
+import org.apache.airavata.xbaya.ui.graph.GraphCanvasListener;
+import org.apache.airavata.xbaya.ui.menues.XBayaMenu;
+import org.apache.airavata.xbaya.ui.utils.ErrorMessages;
+import org.apache.airavata.xbaya.ui.views.ComponentViewer;
+import org.apache.airavata.xbaya.ui.views.JCRBrowserPanel;
+import org.apache.airavata.xbaya.ui.views.MonitorPanel;
+import org.apache.airavata.xbaya.ui.views.PortViewer;
+import org.apache.airavata.xbaya.ui.widgets.ScrollPanel;
+import org.apache.airavata.xbaya.ui.widgets.TabLabelButton;
+import org.apache.airavata.xbaya.ui.widgets.XBayaToolBar;
+import org.apache.airavata.xbaya.ui.widgets.component.ComponentSelector;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xmlpull.infoset.XmlElement;
+
+public class XBayaGUI implements EventListener, XBayaExecutionModeListener {
+
+ private static final Logger logger = LoggerFactory.getLogger(XBayaGUI.class);
+
+ private static final int STATIC_MENU_ITEMS = 4;
+
+ private XBayaEngine engine;
+
+ private JFrame frame;
+
+ private XBayaMenu menu;
+
+ private List<GraphCanvas> graphCanvases = new LinkedList<GraphCanvas>();
+
+ private PortViewer portViewer;
+
+ private ComponentViewer componentViewer;
+
+ private ComponentSelector componentSelector;
+
+ private MonitorPanel monitorPane;
+
+ private XBayaToolBar toolbar;
+
+ private ErrorWindow errorWindow;
+
+ private JTabbedPane rightBottomTabbedPane;
+
+ private JTabbedPane graphTabbedPane;
+
+ private boolean graphPanelMaximized;
+
+ private int previousMainDividerLocation;
+
+ private int previousRightDividerLocation;
+
+ private JSplitPane mainSplitPane;
+
+ private JSplitPane leftSplitPane;
+
+ private JSplitPane rightSplitPane;
+
+ private JTabbedPane componentTabbedPane;
+
+ private ScrollPanel compTreeXBayapanel;
+
+ private WorkflowFiler graphFiler;
+
+ private WorkflowPropertyWindow workflowPropertiesWindow;
+
+ /**
+ * Constructs an XBayaEngine.
+ *
+ * @param engine
+ */
+ public XBayaGUI(XBayaEngine engine) {
+ this.engine = engine;
+ this.engine.getMonitor().addEventListener(this);
+ graphFiler = new WorkflowFiler(engine);
+ engine.getConfiguration().registerExecutionModeChangeListener(this);
+
+ try {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ init();
+ }
+ });
+ } catch (InterruptedException e) {
+ // Shouldn't happen.
+ throw new WorkflowRuntimeException(e);
+ } catch (InvocationTargetException e) {
+ // Shouldn't happen.
+ //It happened
+ /* exception occurs when xbaya is opened twice from the jvm
+ * org.apache.airavata.xbaya.XBayaRuntimeException: java.lang.reflect.InvocationTargetException
+ at org.apache.airavata.xbaya.gui.XBayaGUI.<init>(XBayaGUI.java:148)
+ at org.apache.airavata.xbaya.XBayaEngine.<init>(XBayaEngine.java:106)
+ at org.apache.airavata.xbaya.XBaya.<init>(XBaya.java:51)
+ at org.ogce.paramchem.XBayaLauncher.run(XBayaLauncher.java:44)
+ at java.lang.Thread.run(Thread.java:662)
+ Caused by: java.lang.reflect.InvocationTargetException
+ at java.awt.EventQueue.invokeAndWait(EventQueue.java:1042)
+ at javax.swing.SwingUtilities.invokeAndWait(SwingUtilities.java:1326)
+ at org.apache.airavata.xbaya.gui.XBayaGUI.<init>(XBayaGUI.java:138)
+ ... 4 more
+ */
+ throw new WorkflowRuntimeException(e);
+ }
+
+ // Following suppsed to jump in the middle to save unsaved workflows when exiting xbaya
+ // but its not working because the UI is already disposed it seems :(
+// Runtime.getRuntime().addShutdownHook(new Thread(){
+// @Override
+// public void run() {
+// while (getGraphCanvases().size()>0){
+// removeGraphCanvasFromIndex(0);
+// }
+// }
+// });
+ }
+
+ /**
+ * Returns the notificationPane.
+ *
+ * @return The notificationPane
+ */
+ public MonitorPanel getMonitorPane() {
+ return this.monitorPane;
+ }
+
+ /**
+ * Returns the ComponentTreeViewer.
+ *
+ * @return The ComponentTreeViewer
+ */
+ public ComponentSelector getComponentSelector() {
+ return this.componentSelector;
+ }
+
+ /**
+ * Returns the ErrorWindow.
+ *
+ * @return the errorWindow
+ */
+ public ErrorWindow getErrorWindow() {
+ return this.errorWindow;
+ }
+
+ /**
+ * Returns the Frame.
+ *
+ * @return the Frame
+ */
+ public JFrame getFrame() {
+ return this.frame;
+ }
+
+ /**
+ * @return The list of GraphCanvases.
+ */
+ public List<GraphCanvas> getGraphCanvases() {
+ return this.graphCanvases;
+ }
+
+ /**
+ * Return the active GraphPanel.
+ *
+ * @return The GraphPanel
+ */
+ public GraphCanvas getGraphCanvas() {
+ int index = this.graphTabbedPane.getSelectedIndex();
+ if (index!=-1) {
+ return this.graphCanvases.get(index);
+ }else{
+ return null;
+ }
+ }
+
+ /**
+ * Returns the toolbar.
+ *
+ * @return The toolbar
+ */
+ public XBayaToolBar getToolbar() {
+ if (toolbar==null){
+ this.toolbar = new XBayaToolBar(this.engine);
+ }
+ return this.toolbar;
+ }
+
+ public GraphCanvas newGraphCanvas(boolean focus) {
+ return newGraphCanvas(focus, false);
+ }
+
+ /**
+ * Creates a new graph tab.
+ *
+ * This method needs to be called by Swing event thread.
+ *
+ * @param focus
+ *
+ * @return The graph canvas created
+ */
+ public GraphCanvas newGraphCanvas(boolean focus, boolean withID) {
+ GraphCanvas newGraphCanvas = new GraphCanvas(this.engine);
+ this.graphCanvases.add(newGraphCanvas);
+ this.graphTabbedPane.addTab(newGraphCanvas.getWorkflow().getName(), newGraphCanvas.getSwingComponent());
+ final int index = graphTabbedPane.getTabCount()-1;
+ TabLabelButton tabLabelButton = new TabLabelButton(graphTabbedPane,"Close this workflow");
+ graphTabbedPane.setTabComponentAt(index, tabLabelButton);
+ tabLabelButton.setCloseButtonListener(new ActionListener(){
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ removeGraphCanvasFromIndex(index);
+ }
+ });
+ graphTabbedPane.addContainerListener(new ContainerListener(){
+
+ @Override
+ public void componentAdded(ContainerEvent event) {
+ }
+
+ @Override
+ public void componentRemoved(ContainerEvent event) {
+ List<GraphCanvas> graphCanvases = engine.getGUI().getGraphCanvases();
+ for (GraphCanvas graphCanvas : graphCanvases) {
+ if (graphCanvas.getSwingComponent()==event.getComponent()){
+ if (graphCanvas.isWorkflowChanged()){
+ setFocus(graphCanvas);
+ if (JOptionPane.showConfirmDialog(null, "The workflow '"+graphCanvas.getWorkflow().getName()+"' has been modified. Save changes?", "Save Workflow", JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION){
+ graphFiler.saveWorkflow(graphCanvas);
+ }
+ }
+ break;
+ }
+ }
+ }
+
+ });
+ if (focus) {
+ setFocus(newGraphCanvas);
+ }
+ newGraphCanvas.addGraphCanvasListener(this.componentViewer);
+ newGraphCanvas.addGraphCanvasListener(this.portViewer);
+ newGraphCanvas.addGraphCanvasListener(new GraphCanvasListener() {
+
+ public void graphCanvasChanged(GraphCanvasEvent event) {
+ GraphCanvasEventType type = event.getType();
+ final GraphCanvas graphCanvas = event.getGraphCanvas();
+ final Workflow workflow = event.getWorkflow();
+ switch (type) {
+ case GRAPH_LOADED:
+ case NAME_CHANGED:
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ String name = workflow.getName();
+
+ // Change the name of the tab.
+ updateTabTitle(graphCanvas, workflow);
+
+ // Change the name of the frame.
+ setFrameName(name);
+ }
+
+
+ });
+ break;
+ case NODE_SELECTED:
+ case INPUT_PORT_SELECTED:
+ case OUTPUT_PORT_SELECTED:
+ // Do nothing
+ case WORKFLOW_CHANGED:
+ updateTabTitle(graphCanvas,graphCanvas.getWorkflow());
+ setFrameName(workflow.getName());
+ for (ChangeListener listener:tabChangeListeners){
+ try{
+ listener.stateChanged(null);
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ private void updateTabTitle(
+ final GraphCanvas graphCanvas,
+ final Workflow workflow) {
+ int index = XBayaGUI.this.graphTabbedPane.indexOfComponent(graphCanvas.getSwingComponent());
+ String newTitle = workflow.getName();
+ if (graphCanvas.isWorkflowChanged()){
+ newTitle="*"+newTitle;
+ }
+ XBayaGUI.this.graphTabbedPane.setTitleAt(index, newTitle);
+ }
+ });
+ if (withID){
+ getWorkflowPropertyWindow().show();
+ }
+ return newGraphCanvas;
+ }
+
+ /**
+ * @param graphCanvas
+ */
+ public void setFocus(GraphCanvas graphCanvas) {
+ this.graphTabbedPane.setSelectedComponent(graphCanvas.getSwingComponent());
+ }
+
+ /**
+ * Selects a canvas with a specified workflow if any; otherwise create one.
+ *
+ * This method needs to be called by Swing event thread.
+ *
+ * @param workflow
+ */
+ public void selectOrCreateGraphCanvas(Workflow workflow) {
+ GraphCanvas graphCanvas = null;
+ for (GraphCanvas canvas : this.graphCanvases) {
+ if (workflow == canvas.getWorkflow()) {
+ graphCanvas = canvas;
+ }
+ }
+ if (graphCanvas == null) {
+ graphCanvas = newGraphCanvas(true);
+ graphCanvas.setWorkflow(workflow);
+ } else {
+ setFocus(graphCanvas);
+ }
+ }
+
+ private List<ChangeListener> tabChangeListeners=new ArrayList<ChangeListener>();
+
+ private JCRBrowserPanel jcrBrowserPanel;
+
+ public void addWorkflowTabChangeListener(ChangeListener listener){
+ graphTabbedPane.addChangeListener(listener);
+ tabChangeListeners.add(listener);
+ }
+
+ public void removeWorkflowTabChangeListener(ChangeListener listener){
+ graphTabbedPane.removeChangeListener(listener);
+ tabChangeListeners.remove(listener);
+ }
+ /**
+ * Closes the selected graph canvas.
+ *
+ * This method needs to be called by Swing event thread.
+ */
+ public void closeGraphCanvas() {
+ removeGraphCanvasFromIndex(this.graphTabbedPane.getSelectedIndex());
+ //I dont know why but aparently you have to have atleast one tab present
+// newGraphCanvas(true);
+ }
+
+ public boolean closeAllGraphCanvas(){
+ while (graphTabbedPane.getTabCount()>0){
+ if (!removeGraphCanvasFromIndex(0)){
+ return false;
+ }
+ }
+ return true;
+ //I dont know why but aparently you have to have atleast one tab present
+// newGraphCanvas(true);
+ }
+
+ private boolean removeGraphCanvasFromIndex(int index) {
+ boolean actionSuccess=true;
+ if ((graphTabbedPane.getTabCount()>0) && (index<this.graphTabbedPane.getTabCount())){
+ GraphCanvas graphCanvas = graphCanvases.get(index);
+ if (graphCanvas.isWorkflowChanged()){
+ int result = JOptionPane.showConfirmDialog(frame, "'"+graphCanvas.getWorkflow().getName()+"' has been modified. Save changes?", "Save Workflow", JOptionPane.YES_NO_CANCEL_OPTION);
+ try {
+ if (result==JOptionPane.YES_OPTION){
+ graphFiler.saveWorkflow(graphCanvas);
+ if (graphCanvas.isWorkflowChanged()){
+ //if cancelled while trying to save
+ actionSuccess=false;
+ }
+ }else if (result==JOptionPane.CANCEL_OPTION){
+ actionSuccess=false;
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ if (actionSuccess) {
+ graphCanvases.remove(index);
+ graphTabbedPane.removeTabAt(index);
+ activeTabChanged();
+ }
+ }
+ return actionSuccess;
+ }
+
+ /**
+ * Selects the next graph canvas.
+ *
+ * This method needs to be called by Swing event thread.
+ */
+ public void selectNextGraphCanvas() {
+ int count = this.graphTabbedPane.getTabCount();
+ int index = this.graphTabbedPane.getSelectedIndex();
+ index = (index + 1) % count;
+ this.graphTabbedPane.setSelectedIndex(index);
+ }
+
+ /**
+ * Toggles the maximization of the Graph Panel.
+ */
+ public void toggleMaximizeGraphPanel() {
+ if (XBayaGUI.this.graphPanelMaximized) {
+ unmaximizeGraphPanel();
+ } else {
+ maximizeGraphPanel();
+ }
+ }
+
+ /**
+ * Maximizes the Graph Panel.
+ */
+ public void maximizeGraphPanel() {
+ if (!XBayaGUI.this.graphPanelMaximized) {
+ XBayaGUI.this.graphPanelMaximized = true;
+
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ XBayaGUI.this.previousMainDividerLocation = XBayaGUI.this.mainSplitPane.getDividerLocation();
+ XBayaGUI.this.previousRightDividerLocation = XBayaGUI.this.rightSplitPane.getDividerLocation();
+ XBayaGUI.this.mainSplitPane.setDividerLocation(0.0);
+ XBayaGUI.this.rightSplitPane.setDividerLocation(1.0);
+ }
+ });
+ }
+ }
+
+ /**
+ * Set the size of the graph panel to the original.
+ */
+ public void unmaximizeGraphPanel() {
+ if (XBayaGUI.this.graphPanelMaximized) {
+ XBayaGUI.this.graphPanelMaximized = false;
+
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ XBayaGUI.this.mainSplitPane.setDividerLocation(XBayaGUI.this.previousMainDividerLocation);
+ XBayaGUI.this.rightSplitPane.setDividerLocation(XBayaGUI.this.previousRightDividerLocation);
+ }
+ });
+ }
+ }
+
+ /**
+ * Adds a selected component as a node at random position.
+ */
+ public void addNode() {
+ getGraphCanvas().addNode(this.componentSelector.getSelectedComponent());
+ }
+
+ /**
+ * @see org.apache.airavata.ws.monitor.event.EventListener#eventReceived(org.apache.airavata.ws.monitor.event.Event)
+ */
+ public void eventReceived(Event event) {
+ Type type = event.getType();
+ if (type == Type.MONITOR_STARTED || type == Type.KARMA_STARTED) {
+ // Show the monitor panel.
+ this.rightBottomTabbedPane.setSelectedComponent(this.monitorPane.getSwingComponent());
+ }
+ }
+
+ /**
+ * Initializes
+ */
+ private void init() {
+ createFrame();
+
+ this.menu = new XBayaMenu(this.engine, getToolbar());
+ this.frame.setJMenuBar(this.menu.getSwingComponent());
+
+ initPane();
+
+ // Create an empty graph canvas.
+// newGraphCanvas(true);
+
+ this.frame.setVisible(true);
+ loadDefaultGraph();
+
+ executionModeChanged(this.engine.getConfiguration());
+ }
+
+ /**
+ * Initializes the GUI.
+ */
+ private void initPane() {
+ Container contentPane = this.frame.getContentPane();
+
+ // Error window
+ this.errorWindow = new ErrorWindow(contentPane);
+
+ contentPane.add(getToolbar().getSwingComponent(), BorderLayout.PAGE_START);
+
+ this.portViewer = new PortViewer();
+ this.componentViewer = new ComponentViewer();
+ this.componentSelector = new ComponentSelector(this.engine);
+ this.componentSelector.addComponentSelectorListener(this.componentViewer);
+ this.monitorPane = new MonitorPanel(this,this.engine.getMonitor());
+
+ compTreeXBayapanel = new ScrollPanel(this.componentSelector, ComponentSelector.TITLE);
+ ScrollPanel compViewXBayaPanel = new ScrollPanel(this.componentViewer, ComponentViewer.TITLE);
+
+ this.rightBottomTabbedPane = new JTabbedPane();
+ this.rightBottomTabbedPane.setMinimumSize(SwingUtil.MINIMUM_SIZE);
+ this.rightBottomTabbedPane.setPreferredSize(new Dimension(0, 200));
+ this.rightBottomTabbedPane.addTab(PortViewer.TITLE, this.portViewer.getSwingComponent());
+ this.rightBottomTabbedPane.addTab(MonitorPanel.TITLE, this.monitorPane.getSwingComponent());
+
+ this.graphTabbedPane = new JTabbedPane();
+ this.graphTabbedPane.setMinimumSize(SwingUtil.MINIMUM_SIZE);
+ this.graphTabbedPane.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ if (e.getClickCount() >= 2) {
+ toggleMaximizeGraphPanel();
+ }
+ }
+ });
+ this.graphTabbedPane.addChangeListener(new ChangeListener() {
+ public void stateChanged(ChangeEvent event) {
+ // Called when the active tab changed.
+ // Note that this is not called when a tab is removed.
+ logger.debug(event.toString());
+ XBayaGUI.this.activeTabChanged();
+ }
+ });
+
+ this.leftSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true);
+ this.rightSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true);
+ this.mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, this.leftSplitPane, this.rightSplitPane);
+ contentPane.add(this.mainSplitPane, BorderLayout.CENTER);
+
+ this.leftSplitPane.setOneTouchExpandable(true);
+ this.rightSplitPane.setOneTouchExpandable(true);
+ this.mainSplitPane.setOneTouchExpandable(true);
+
+ // this.leftSplitPane.setTopComponent(compTreeXBayapanel.getSwingComponent());
+ // this.leftSplitPane.setTopComponent(new JCRBrowserPanel(engine));
+
+ this.componentTabbedPane = new JTabbedPane();
+ this.componentTabbedPane.setMinimumSize(SwingUtil.MINIMUM_SIZE);
+ this.leftSplitPane.setTopComponent(this.componentTabbedPane);
+ this.componentTabbedPane.add(this.compTreeXBayapanel.getSwingComponent());
+ this.componentTabbedPane.setTitleAt(0, "Component");
+
+ this.leftSplitPane.setBottomComponent(compViewXBayaPanel.getSwingComponent());
+ this.rightSplitPane.setTopComponent(this.graphTabbedPane);
+ this.rightSplitPane.setBottomComponent(this.rightBottomTabbedPane);
+
+ this.leftSplitPane.setMinimumSize(SwingUtil.MINIMUM_SIZE);
+ this.rightSplitPane.setMinimumSize(SwingUtil.MINIMUM_SIZE);
+
+ //
+ // Adjust sizes
+ //
+
+ // Need to pack the frame first to get the size of each component.
+ this.frame.pack();
+
+ final int leftPanelWidth = 250;
+ final int portViewHight = 200;
+
+ this.mainSplitPane.setDividerLocation(leftPanelWidth);
+ this.leftSplitPane.setDividerLocation(0.5);
+ this.leftSplitPane.setResizeWeight(0.5);
+
+ this.rightSplitPane.setDividerLocation(this.rightSplitPane.getSize().height - portViewHight);
+ // The bottom component to stay the same size
+ this.rightSplitPane.setResizeWeight(1.0);
+
+ }
+
+ public void viewJCRBrowserPanel(){
+ if (jcrBrowserPanel!=null){
+ jcrBrowserPanel=componentTabbedPane.indexOfComponent(jcrBrowserPanel)==-1? null:jcrBrowserPanel;
+ }
+ if (jcrBrowserPanel==null) {
+ jcrBrowserPanel = new JCRBrowserPanel(engine);
+ this.componentTabbedPane.add(jcrBrowserPanel);
+ int index=this.componentTabbedPane.getTabCount()-1;
+ this.componentTabbedPane.setTitleAt(1, "Airavata Registry");
+ TabLabelButton tabLabelButton = new TabLabelButton(componentTabbedPane, "Close JCR Browser");
+ tabLabelButton.setCloseButtonListener(new ActionListener(){
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ componentTabbedPane.remove(jcrBrowserPanel);
+ }
+
+ });
+ this.componentTabbedPane.setTabComponentAt(index, tabLabelButton);
+ }
+ componentTabbedPane.setSelectedComponent(jcrBrowserPanel);
+ }
+
+ public void viewComponentTree(){
+ componentTabbedPane.setSelectedComponent(compTreeXBayapanel.getSwingComponent());
+ }
+
+
+ /**
+ * Creates a frame.
+ */
+ private void createFrame() {
+ try {
+ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+ } catch (Exception e) {
+ // OK. The default will be used.
+ logger.error(e.getMessage(), e);
+ }
+
+ JFrame.setDefaultLookAndFeelDecorated(false);
+ this.frame = new JFrame();
+
+ // Adjust the size
+ XBayaConfiguration config = this.engine.getConfiguration();
+ int width = config.getWidth();
+ int height = config.getHeight();
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ final int inset = 50;
+ this.frame.setLocation(inset, inset);
+ Dimension size = new Dimension(screenSize.width - inset * 2, screenSize.height - inset * 2);
+ if (width != 0) {
+ size.width = width;
+ }
+ if (height != 0) {
+ size.height = height;
+ }
+
+ // This controls the size when you open in a huge screen
+ if(size.width > 1280 && size.height > 800){
+ size.width = 1280;
+ size.height = 800;
+ }
+ this.frame.setPreferredSize(size);
+
+ this.frame.setTitle(XBayaConstants.APPLICATION_NAME);
+
+ this.frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
+ this.frame.addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent event) {
+ int result = JOptionPane.showConfirmDialog(frame, "'Are you sure you want to exit?", "Exit XBaya", JOptionPane.YES_NO_OPTION);
+ if (result==JOptionPane.NO_OPTION || (!closeAllGraphCanvas())){
+ return;
+ }
+ logger.debug(event.toString());
+ XBayaGUI.this.frame.setVisible(false);
+ try {
+ XBayaGUI.this.engine.dispose();
+ } catch (WorkflowException e) {
+ // Ignore the error.
+ logger.error(e.getMessage(), e);
+ } catch (RuntimeException e) {
+ // Ignore the error.
+ logger.error(e.getMessage(), e);
+ }
+ if (XBayaGUI.this.engine.getConfiguration().isCloseOnExit()) {
+ System.exit(0);
+ }
+ }
+
+ @Override
+ public void windowClosed(WindowEvent e) {
+ logger.debug(e.toString());
+
+ try {
+ XBayaGUI.this.engine.getMonitor().stop();
+ } catch (MonitorException e1) {
+ logger.error(e1.getMessage(), e1);
+ }
+ // Make sure to kill all threads.
+ // Dispose only when it can be disposed to prevent infinite loop
+ if (XBayaGUI.this.frame.isDisplayable()) {
+ XBayaGUI.this.frame.dispose();
+ }
+ }
+ });
+ this.frame.setIconImage(SwingUtil.createImage("airavata-2.png"));
+ }
+
+ private void activeTabChanged() {
+ GraphCanvas graphPanel = getGraphCanvas();
+
+ if (graphPanel!=null) {
+ // Reset the port viewers.
+ Port inputPort = graphPanel.getSelectedInputPort();
+ Port outputPort = graphPanel.getSelectedOutputPort();
+ this.portViewer.setInputPort(inputPort);
+ this.portViewer.setOutputPort(outputPort);
+ // Reset component viewer.
+ Node node = graphPanel.getSelectedNode();
+ Component component;
+ if (node != null) {
+ component = node.getComponent();
+ } else {
+ component = this.componentSelector.getSelectedComponent();
+ }
+ this.componentViewer.setComponent(component);
+ String name = graphPanel.getWorkflow().getName();
+ setFrameName(name);
+ }else{
+ //TODO what to do when no tabs are present???
+ }
+ }
+
+ public ComponentViewer getComponentVIewer() {
+ return this.componentViewer;
+ }
+
+ private void setFrameName(String workflowName) {
+ String title = this.engine.getConfiguration().getTitle();
+ this.frame.setTitle(workflowName + " - " + title);
+ }
+
+ @Override
+ public void executionModeChanged(XBayaConfiguration config) {
+ this.leftSplitPane.setVisible(config.getXbayaExecutionMode()==XBayaExecutionMode.IDE);
+ }
+
+
+ /**
+ * @return
+ */
+ public WorkflowPropertyWindow getWorkflowPropertyWindow() {
+ if (this.workflowPropertiesWindow == null) {
+ this.workflowPropertiesWindow = new WorkflowPropertyWindow(this);
+ }
+ return this.workflowPropertiesWindow;
+ }
+
+ /**
+ * Sets the workflow.
+ *
+ * @param workflow
+ * The workflow
+ */
+ public void setWorkflow(Workflow workflow) {
+ this.getGraphCanvas().setWorkflow(workflow);
+ }
+
+ /**
+ * Return the current workflow.
+ *
+ * @return The current workflow
+ */
+ public Workflow getWorkflow() {
+ return this.getGraphCanvas().getWorkflowWithImage();
+ }
+
+ private void loadDefaultGraph() {
+ if (this.engine.getConfiguration().getWorkflow() != null) {
+ this.newGraphCanvas(true, false);
+ try {
+ String xml = this.engine.getConfiguration().getAiravataAPI().getWorkflowManager().getWorkflowAsString(this.engine.getConfiguration().getWorkflow());
+ XmlElement xwf = XMLUtil.stringToXmlElement(xml);
+ Workflow workflow = new Workflow(xwf);
+ setWorkflow(workflow);
+ } catch (AiravataAPIInvocationException e) {
+ getErrorWindow().error(ErrorMessages.REPOSITORY_CONFIGURATION_IS_WRONG_FAILED_TO_LOAD_THE_WORKFLOW, e);
+ } catch (GraphException e) {
+ getErrorWindow().error(ErrorMessages.WORKFLOW_IS_WRONG, e);
+ } catch (ComponentException e) {
+ getErrorWindow().error(ErrorMessages.COMPONENT_FORMAT_ERROR, e);
+ }
+ }
+
+ }
+
+ public XBayaConfiguration getConfiguration() {
+ return engine.getConfiguration();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/actions/AbstractBrowserActionItem.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/actions/AbstractBrowserActionItem.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/actions/AbstractBrowserActionItem.java
new file mode 100644
index 0000000..406e3b7
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/actions/AbstractBrowserActionItem.java
@@ -0,0 +1,90 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.xbaya.ui.actions;
+
+import java.awt.event.ActionListener;
+
+import javax.swing.Icon;
+import javax.swing.JMenuItem;
+
+public abstract class AbstractBrowserActionItem {
+
+ private String caption;
+ private Icon icon;
+ private JMenuItem menuItem;
+ private String description;
+
+ public abstract String getID();
+
+ public void setIcon(Icon icon) {
+ this.icon = icon;
+ getMenuItem().setIcon(getIcon());
+ }
+
+ public Icon getIcon() {
+ return icon;
+ }
+
+ public String getCaption() {
+ return caption;
+ }
+
+ public void setCaption(String caption) {
+ this.caption = caption;
+ getMenuItem().setText(getCaption());
+ }
+
+ public JMenuItem getMenuItem() {
+ if (menuItem == null) {
+ menuItem = new JMenuItem(getCaption());
+ }
+ menuItem.setText(getCaption());
+ return menuItem;
+ }
+
+ public void addActionListener(ActionListener listener) {
+ getMenuItem().addActionListener(listener);
+ }
+
+ public void removeActionListener(ActionListener listener) {
+ getMenuItem().removeActionListener(listener);
+ }
+
+ public void setVisible(boolean visible) {
+ getMenuItem().setVisible(visible);
+ }
+
+ public void setEnabled(boolean enabled) {
+ getMenuItem().setEnabled(enabled);
+ }
+
+ public abstract String getDefaultCaption();
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ getMenuItem().setToolTipText(getDescription());
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/actions/registry/browser/AddAction.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/actions/registry/browser/AddAction.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/actions/registry/browser/AddAction.java
new file mode 100644
index 0000000..625aaf8
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/actions/registry/browser/AddAction.java
@@ -0,0 +1,43 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.xbaya.ui.actions.registry.browser;
+
+import org.apache.airavata.xbaya.ui.actions.AbstractBrowserActionItem;
+
+public class AddAction extends AbstractBrowserActionItem {
+ public static final String ID = "action.add";
+
+ public AddAction() {
+ setCaption(getDefaultCaption());
+ }
+
+ @Override
+ public String getID() {
+ return ID;
+ }
+
+ @Override
+ public String getDefaultCaption() {
+ return "Add";
+ }
+
+}