Merging c-Eclipse code to camf repo. Changes to *.tosca.editor chained changes to *.infosystem.model Change-Id: Ifd2cb20824ae4c52b9c8415fc9e5bd1dff4f531f Signed-off-by: Athanasios Foudoulis <foudoulisathanasios@gmail.com>
diff --git a/plugins/org.eclipse.camf.infosystem.model/model/InfoSystem.genmodel b/plugins/org.eclipse.camf.infosystem.model/model/InfoSystem.genmodel index 83c982e..48dcc10 100644 --- a/plugins/org.eclipse.camf.infosystem.model/model/InfoSystem.genmodel +++ b/plugins/org.eclipse.camf.infosystem.model/model/InfoSystem.genmodel
@@ -4,8 +4,8 @@ modelName="InfoSystem" importerID="org.eclipse.emf.importer.ecore" complianceLevel="6.0" copyrightFields="false" classNamePattern=""> <foreignModel>infosystem.ecore</foreignModel> - <genPackages prefix="InfoSystem" basePackage="org.eclipse.camf.infosystem.model" resource="XML" - disposableProviderFactory="true" ecorePackage="infosystem.ecore#/"> + <genPackages prefix="InfoSystem" basePackage="org.eclipse.camf.infosystem.model" + resource="XML" disposableProviderFactory="true" ecorePackage="infosystem.ecore#/"> <genEnums typeSafeEnumCompatible="false" ecoreEnum="infosystem.ecore#//VirtualMachineImageType"> <genEnumLiterals ecoreEnumLiteral="infosystem.ecore#//VirtualMachineImageType/BaseImage"/> <genEnumLiterals ecoreEnumLiteral="infosystem.ecore#//VirtualMachineImageType/CustomImage"/> @@ -15,7 +15,7 @@ <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//MonitoringProbe/uID"/> <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//MonitoringProbe/name"/> <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//MonitoringProbe/description"/> - <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//MonitoringProbe/uRL"/> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//MonitoringProbe/metrics"/> </genClasses> <genClasses ecoreClass="infosystem.ecore#//ResizingAction"> <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//ResizingAction/uID"/> @@ -44,5 +44,47 @@ <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//UserApplication/uRL"/> <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//UserApplication/type"/> </genClasses> + <genClasses ecoreClass="infosystem.ecore#//KeyPair"> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//KeyPair/uID"/> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//KeyPair/name"/> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//KeyPair/publicKey"/> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//KeyPair/Description"/> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//KeyPair/URL"/> + </genClasses> + <genClasses ecoreClass="infosystem.ecore#//VirtualMachineImageFlavor"> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//VirtualMachineImageFlavor/name"/> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//VirtualMachineImageFlavor/uID"/> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//VirtualMachineImageFlavor/ram"/> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//VirtualMachineImageFlavor/hdd"/> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//VirtualMachineImageFlavor/vCPU"/> + </genClasses> + <genClasses ecoreClass="infosystem.ecore#//VirtualNetwork"> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//VirtualNetwork/uID"/> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//VirtualNetwork/name"/> + </genClasses> + <genClasses ecoreClass="infosystem.ecore#//VirtualInstance"> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//VirtualInstance/uID"/> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//VirtualInstance/name"/> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//VirtualInstance/status"/> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//VirtualInstance/IPs"/> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//VirtualInstance/URI"/> + </genClasses> + <genClasses ecoreClass="infosystem.ecore#//SecurityGroup"> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//SecurityGroup/uID"/> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//SecurityGroup/name"/> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//SecurityGroup/description"/> + </genClasses> + <genClasses ecoreClass="infosystem.ecore#//Deployment"> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//Deployment/depID"/> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//Deployment/deploymentName"/> + <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference infosystem.ecore#//Deployment/modules"/> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//Deployment/Status"/> + </genClasses> + <genClasses ecoreClass="infosystem.ecore#//Module"> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//Module/modID"/> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//Module/moduleName"/> + <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference infosystem.ecore#//Module/instances"/> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute infosystem.ecore#//Module/initInstances"/> + </genClasses> </genPackages> </genmodel:GenModel>
diff --git a/plugins/org.eclipse.camf.infosystem.model/model/infosystem.ecore b/plugins/org.eclipse.camf.infosystem.model/model/infosystem.ecore index 35762f4..6df2058 100644 --- a/plugins/org.eclipse.camf.infosystem.model/model/infosystem.ecore +++ b/plugins/org.eclipse.camf.infosystem.model/model/infosystem.ecore
@@ -28,7 +28,8 @@ <details key="namespace" value="##targetNamespace"/> </eAnnotations> </eStructuralFeatures> - <eStructuralFeatures xsi:type="ecore:EAttribute" name="uRL" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String"> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="metrics" lowerBound="1" + eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String"> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> <details key="kind" value="element"/> <details key="name" value="URL"/>
diff --git a/plugins/org.eclipse.camf.infosystem.model/src/org/eclipse/camf/infosystem/model/base/InfoSystemPackage.java b/plugins/org.eclipse.camf.infosystem.model/src/org/eclipse/camf/infosystem/model/base/InfoSystemPackage.java index ce95b05..d704eef 100644 --- a/plugins/org.eclipse.camf.infosystem.model/src/org/eclipse/camf/infosystem/model/base/InfoSystemPackage.java +++ b/plugins/org.eclipse.camf.infosystem.model/src/org/eclipse/camf/infosystem/model/base/InfoSystemPackage.java
@@ -110,15 +110,15 @@ int MONITORING_PROBE__DESCRIPTION = 2; /** - * The feature id for the '<em><b>URL</b></em>' attribute. + * The feature id for the '<em><b>Metrics</b></em>' attribute. * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * <!-- end-user-doc --> * @generated * @ordered */ - int MONITORING_PROBE__URL = 3; + int MONITORING_PROBE__METRICS = 3; - /** + /** * The number of structural features of the '<em>Monitoring Probe</em>' class. * <!-- begin-user-doc --> * <!-- end-user-doc --> @@ -824,17 +824,17 @@ EAttribute getMonitoringProbe_Description(); /** - * Returns the meta object for the attribute '{@link org.eclipse.camf.infosystem.model.base.MonitoringProbe#getURL <em>URL</em>}'. + * Returns the meta object for the attribute '{@link org.eclipse.camf.infosystem.model.base.MonitoringProbe#getMetrics <em>Metrics</em>}'. * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @return the meta object for the attribute '<em>URL</em>'. - * @see org.eclipse.camf.infosystem.model.base.MonitoringProbe#getURL() + * <!-- end-user-doc --> + * @return the meta object for the attribute '<em>Metrics</em>'. + * @see org.eclipse.camf.infosystem.model.base.MonitoringProbe#getMetrics() * @see #getMonitoringProbe() * @generated */ - EAttribute getMonitoringProbe_URL(); + EAttribute getMonitoringProbe_Metrics(); - /** + /** * Returns the meta object for class '{@link org.eclipse.camf.infosystem.model.base.ResizingAction <em>Resizing Action</em>}'. * <!-- begin-user-doc --> * <!-- end-user-doc --> @@ -1541,14 +1541,14 @@ EAttribute MONITORING_PROBE__DESCRIPTION = eINSTANCE.getMonitoringProbe_Description(); /** - * The meta object literal for the '<em><b>URL</b></em>' attribute feature. + * The meta object literal for the '<em><b>Metrics</b></em>' attribute feature. * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * <!-- end-user-doc --> * @generated */ - EAttribute MONITORING_PROBE__URL = eINSTANCE.getMonitoringProbe_URL(); + EAttribute MONITORING_PROBE__METRICS = eINSTANCE.getMonitoringProbe_Metrics(); - /** + /** * The meta object literal for the '{@link org.eclipse.camf.infosystem.model.base.impl.ResizingActionImpl <em>Resizing Action</em>}' class. * <!-- begin-user-doc --> * <!-- end-user-doc -->
diff --git a/plugins/org.eclipse.camf.infosystem.model/src/org/eclipse/camf/infosystem/model/base/MonitoringProbe.java b/plugins/org.eclipse.camf.infosystem.model/src/org/eclipse/camf/infosystem/model/base/MonitoringProbe.java index ce97813..106c302 100644 --- a/plugins/org.eclipse.camf.infosystem.model/src/org/eclipse/camf/infosystem/model/base/MonitoringProbe.java +++ b/plugins/org.eclipse.camf.infosystem.model/src/org/eclipse/camf/infosystem/model/base/MonitoringProbe.java
@@ -29,7 +29,7 @@ * <li>{@link org.eclipse.camf.infosystem.model.base.MonitoringProbe#getUID <em>UID</em>}</li> * <li>{@link org.eclipse.camf.infosystem.model.base.MonitoringProbe#getName <em>Name</em>}</li> * <li>{@link org.eclipse.camf.infosystem.model.base.MonitoringProbe#getDescription <em>Description</em>}</li> - * <li>{@link org.eclipse.camf.infosystem.model.base.MonitoringProbe#getURL <em>URL</em>}</li> + * <li>{@link org.eclipse.camf.infosystem.model.base.MonitoringProbe#getMetrics <em>Metrics</em>}</li> * </ul> * </p> * @@ -121,30 +121,30 @@ void setDescription(String value); /** - * Returns the value of the '<em><b>URL</b></em>' attribute. + * Returns the value of the '<em><b>Metrics</b></em>' attribute. * <!-- begin-user-doc --> - * <p> - * If the meaning of the '<em>URL</em>' attribute isn't clear, - * there really should be more of a description here... - * </p> - * <!-- end-user-doc --> - * @return the value of the '<em>URL</em>' attribute. - * @see #setURL(String) - * @see org.eclipse.camf.infosystem.model.base.InfoSystemPackage#getMonitoringProbe_URL() + * <p> + * If the meaning of the '<em>Metrics</em>' attribute isn't clear, + * there really should be more of a description here... + * </p> + * <!-- end-user-doc --> + * @return the value of the '<em>Metrics</em>' attribute. + * @see #setMetrics(String) + * @see org.eclipse.camf.infosystem.model.base.InfoSystemPackage#getMonitoringProbe_Metrics() * @model dataType="org.eclipse.emf.ecore.xml.type.String" required="true" * extendedMetaData="kind='element' name='URL' namespace='##targetNamespace'" * @generated */ - String getURL(); + String getMetrics(); - /** - * Sets the value of the '{@link org.eclipse.camf.infosystem.model.base.MonitoringProbe#getURL <em>URL</em>}' attribute. + /** + * Sets the value of the '{@link org.eclipse.camf.infosystem.model.base.MonitoringProbe#getMetrics <em>Metrics</em>}' attribute. * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @param value the new value of the '<em>URL</em>' attribute. - * @see #getURL() + * <!-- end-user-doc --> + * @param value the new value of the '<em>Metrics</em>' attribute. + * @see #getMetrics() * @generated */ - void setURL(String value); + void setMetrics(String value); } // MonitoringProbe
diff --git a/plugins/org.eclipse.camf.infosystem.model/src/org/eclipse/camf/infosystem/model/base/VirtualInstance.java b/plugins/org.eclipse.camf.infosystem.model/src/org/eclipse/camf/infosystem/model/base/VirtualInstance.java index 4735600..71f8acb 100644 --- a/plugins/org.eclipse.camf.infosystem.model/src/org/eclipse/camf/infosystem/model/base/VirtualInstance.java +++ b/plugins/org.eclipse.camf.infosystem.model/src/org/eclipse/camf/infosystem/model/base/VirtualInstance.java
@@ -23,16 +23,11 @@ * <p> * The following features are supported: * <ul> - * <li>{@link org.eclipse.camf.infosystem.model.base.VirtualInstance#getUID <em> - * UID</em>}</li> - * <li>{@link org.eclipse.camf.infosystem.model.base.VirtualInstance#getName - * <em>Name</em>}</li> - * <li>{@link org.eclipse.camf.infosystem.model.base.VirtualInstance#getStatus - * <em>Status</em>}</li> - * <li>{@link org.eclipse.camf.infosystem.model.base.VirtualInstance#getIPs <em> - * IPs</em>}</li> - * <li>{@link org.eclipse.camf.infosystem.model.base.VirtualInstance#getURI <em> - * URI</em>}</li> + * <li>{@link org.eclipse.camf.infosystem.model.base.VirtualInstance#getUID <em>UID</em>}</li> + * <li>{@link org.eclipse.camf.infosystem.model.base.VirtualInstance#getName <em>Name</em>}</li> + * <li>{@link org.eclipse.camf.infosystem.model.base.VirtualInstance#getStatus <em>Status</em>}</li> + * <li>{@link org.eclipse.camf.infosystem.model.base.VirtualInstance#getIPs <em>IPs</em>}</li> + * <li>{@link org.eclipse.camf.infosystem.model.base.VirtualInstance#getURI <em>URI</em>}</li> * </ul> * </p> * @@ -59,12 +54,9 @@ String getUID(); /** - * Sets the value of the ' - * {@link org.eclipse.camf.infosystem.model.base.VirtualInstance#getUID - * <em>UID</em>}' attribute. <!-- begin-user-doc --> <!-- end-user-doc --> - * - * @param value - * the new value of the '<em>UID</em>' attribute. + * Sets the value of the '{@link org.eclipse.camf.infosystem.model.base.VirtualInstance#getUID <em>UID</em>}' attribute. + * <!-- begin-user-doc --> <!-- end-user-doc --> + * @param value the new value of the '<em>UID</em>' attribute. * @see #getUID() * @generated */ @@ -88,12 +80,9 @@ String getName(); /** - * Sets the value of the ' - * {@link org.eclipse.camf.infosystem.model.base.VirtualInstance#getName - * <em>Name</em>}' attribute. <!-- begin-user-doc --> <!-- end-user-doc --> - * - * @param value - * the new value of the '<em>Name</em>' attribute. + * Sets the value of the '{@link org.eclipse.camf.infosystem.model.base.VirtualInstance#getName <em>Name</em>}' attribute. + * <!-- begin-user-doc --> <!-- end-user-doc --> + * @param value the new value of the '<em>Name</em>' attribute. * @see #getName() * @generated */ @@ -147,12 +136,9 @@ String getIPs(); /** - * Sets the value of the ' - * {@link org.eclipse.camf.infosystem.model.base.VirtualInstance#getIPs - * <em>IPs</em>}' attribute. <!-- begin-user-doc --> <!-- end-user-doc --> - * - * @param value - * the new value of the '<em>IPs</em>' attribute. + * Sets the value of the '{@link org.eclipse.camf.infosystem.model.base.VirtualInstance#getIPs <em>IPs</em>}' attribute. + * <!-- begin-user-doc --> <!-- end-user-doc --> + * @param value the new value of the '<em>IPs</em>' attribute. * @see #getIPs() * @generated */ @@ -176,12 +162,9 @@ String getURI(); /** - * Sets the value of the ' - * {@link org.eclipse.camf.infosystem.model.base.VirtualInstance#getURI - * <em>URI</em>}' attribute. <!-- begin-user-doc --> <!-- end-user-doc --> - * - * @param value - * the new value of the '<em>URI</em>' attribute. + * Sets the value of the '{@link org.eclipse.camf.infosystem.model.base.VirtualInstance#getURI <em>URI</em>}' attribute. + * <!-- begin-user-doc --> <!-- end-user-doc --> + * @param value the new value of the '<em>URI</em>' attribute. * @see #getURI() * @generated */
diff --git a/plugins/org.eclipse.camf.infosystem.model/src/org/eclipse/camf/infosystem/model/base/impl/InfoSystemPackageImpl.java b/plugins/org.eclipse.camf.infosystem.model/src/org/eclipse/camf/infosystem/model/base/impl/InfoSystemPackageImpl.java index bdc037c..1aff9bf 100644 --- a/plugins/org.eclipse.camf.infosystem.model/src/org/eclipse/camf/infosystem/model/base/impl/InfoSystemPackageImpl.java +++ b/plugins/org.eclipse.camf.infosystem.model/src/org/eclipse/camf/infosystem/model/base/impl/InfoSystemPackageImpl.java
@@ -254,15 +254,14 @@ /** * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * <!-- end-user-doc --> * @generated */ - public EAttribute getMonitoringProbe_URL() - { + public EAttribute getMonitoringProbe_Metrics() { return (EAttribute)monitoringProbeEClass.getEStructuralFeatures().get(3); } - /** + /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated @@ -870,7 +869,7 @@ createEAttribute(monitoringProbeEClass, MONITORING_PROBE__UID); createEAttribute(monitoringProbeEClass, MONITORING_PROBE__NAME); createEAttribute(monitoringProbeEClass, MONITORING_PROBE__DESCRIPTION); - createEAttribute(monitoringProbeEClass, MONITORING_PROBE__URL); + createEAttribute(monitoringProbeEClass, MONITORING_PROBE__METRICS); resizingActionEClass = createEClass(RESIZING_ACTION); createEAttribute(resizingActionEClass, RESIZING_ACTION__UID); @@ -986,7 +985,7 @@ initEAttribute(getMonitoringProbe_UID(), theXMLTypePackage.getString(), "uID", null, 1, 1, MonitoringProbe.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); initEAttribute(getMonitoringProbe_Name(), theXMLTypePackage.getString(), "name", null, 1, 1, MonitoringProbe.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); initEAttribute(getMonitoringProbe_Description(), theXMLTypePackage.getString(), "description", null, 1, 1, MonitoringProbe.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); - initEAttribute(getMonitoringProbe_URL(), theXMLTypePackage.getString(), "uRL", null, 1, 1, MonitoringProbe.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + initEAttribute(getMonitoringProbe_Metrics(), theXMLTypePackage.getString(), "metrics", null, 1, 1, MonitoringProbe.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); initEClass(resizingActionEClass, ResizingAction.class, "ResizingAction", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); initEAttribute(getResizingAction_UID(), theXMLTypePackage.getString(), "uID", null, 1, 1, ResizingAction.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); @@ -1114,7 +1113,7 @@ "namespace", "##targetNamespace" }); addAnnotation - (getMonitoringProbe_URL(), + (getMonitoringProbe_Metrics(), source, new String[] { "kind", "element",
diff --git a/plugins/org.eclipse.camf.infosystem.model/src/org/eclipse/camf/infosystem/model/base/impl/MonitoringProbeImpl.java b/plugins/org.eclipse.camf.infosystem.model/src/org/eclipse/camf/infosystem/model/base/impl/MonitoringProbeImpl.java index bc941bc..5b50119 100644 --- a/plugins/org.eclipse.camf.infosystem.model/src/org/eclipse/camf/infosystem/model/base/impl/MonitoringProbeImpl.java +++ b/plugins/org.eclipse.camf.infosystem.model/src/org/eclipse/camf/infosystem/model/base/impl/MonitoringProbeImpl.java
@@ -33,7 +33,7 @@ * <li>{@link org.eclipse.camf.infosystem.model.base.impl.MonitoringProbeImpl#getUID <em>UID</em>}</li> * <li>{@link org.eclipse.camf.infosystem.model.base.impl.MonitoringProbeImpl#getName <em>Name</em>}</li> * <li>{@link org.eclipse.camf.infosystem.model.base.impl.MonitoringProbeImpl#getDescription <em>Description</em>}</li> - * <li>{@link org.eclipse.camf.infosystem.model.base.impl.MonitoringProbeImpl#getURL <em>URL</em>}</li> + * <li>{@link org.eclipse.camf.infosystem.model.base.impl.MonitoringProbeImpl#getMetrics <em>Metrics</em>}</li> * </ul> * </p> * @@ -102,26 +102,26 @@ protected String description = DESCRIPTION_EDEFAULT; /** - * The default value of the '{@link #getURL() <em>URL</em>}' attribute. + * The default value of the '{@link #getMetrics() <em>Metrics</em>}' attribute. * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @see #getURL() + * <!-- end-user-doc --> + * @see #getMetrics() * @generated * @ordered */ - protected static final String URL_EDEFAULT = null; + protected static final String METRICS_EDEFAULT = null; - /** - * The cached value of the '{@link #getURL() <em>URL</em>}' attribute. + /** + * The cached value of the '{@link #getMetrics() <em>Metrics</em>}' attribute. * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @see #getURL() + * <!-- end-user-doc --> + * @see #getMetrics() * @generated * @ordered */ - protected String uRL = URL_EDEFAULT; + protected String metrics = METRICS_EDEFAULT; - /** + /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated @@ -213,28 +213,26 @@ /** * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * <!-- end-user-doc --> * @generated */ - public String getURL() - { - return uRL; + public String getMetrics() { + return metrics; } - /** + /** * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * <!-- end-user-doc --> * @generated */ - public void setURL(String newURL) - { - String oldURL = uRL; - uRL = newURL; + public void setMetrics(String newMetrics) { + String oldMetrics = metrics; + metrics = newMetrics; if (eNotificationRequired()) - eNotify(new ENotificationImpl(this, Notification.SET, InfoSystemPackage.MONITORING_PROBE__URL, oldURL, uRL)); + eNotify(new ENotificationImpl(this, Notification.SET, InfoSystemPackage.MONITORING_PROBE__METRICS, oldMetrics, metrics)); } - /** + /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated @@ -249,8 +247,8 @@ return getName(); case InfoSystemPackage.MONITORING_PROBE__DESCRIPTION: return getDescription(); - case InfoSystemPackage.MONITORING_PROBE__URL: - return getURL(); + case InfoSystemPackage.MONITORING_PROBE__METRICS: + return getMetrics(); } return super.eGet(featureID, resolve, coreType); } @@ -273,8 +271,8 @@ case InfoSystemPackage.MONITORING_PROBE__DESCRIPTION: setDescription((String)newValue); return; - case InfoSystemPackage.MONITORING_PROBE__URL: - setURL((String)newValue); + case InfoSystemPackage.MONITORING_PROBE__METRICS: + setMetrics((String)newValue); return; } super.eSet(featureID, newValue); @@ -298,8 +296,8 @@ case InfoSystemPackage.MONITORING_PROBE__DESCRIPTION: setDescription(DESCRIPTION_EDEFAULT); return; - case InfoSystemPackage.MONITORING_PROBE__URL: - setURL(URL_EDEFAULT); + case InfoSystemPackage.MONITORING_PROBE__METRICS: + setMetrics(METRICS_EDEFAULT); return; } super.eUnset(featureID); @@ -320,8 +318,8 @@ return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name); case InfoSystemPackage.MONITORING_PROBE__DESCRIPTION: return DESCRIPTION_EDEFAULT == null ? description != null : !DESCRIPTION_EDEFAULT.equals(description); - case InfoSystemPackage.MONITORING_PROBE__URL: - return URL_EDEFAULT == null ? uRL != null : !URL_EDEFAULT.equals(uRL); + case InfoSystemPackage.MONITORING_PROBE__METRICS: + return METRICS_EDEFAULT == null ? metrics != null : !METRICS_EDEFAULT.equals(metrics); } return super.eIsSet(featureID); } @@ -343,8 +341,8 @@ result.append(name); result.append(", description: "); result.append(description); - result.append(", uRL: "); - result.append(uRL); + result.append(", metrics: "); + result.append(metrics); result.append(')'); return result.toString(); }
diff --git a/plugins/org.eclipse.camf.tosca.editor/META-INF/MANIFEST.MF b/plugins/org.eclipse.camf.tosca.editor/META-INF/MANIFEST.MF index e30e05e..b459cab 100644 --- a/plugins/org.eclipse.camf.tosca.editor/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.camf.tosca.editor/META-INF/MANIFEST.MF
@@ -34,7 +34,8 @@ org.eclipse.camf.infosystem.mockup.info, org.eclipse.core.filesystem, org.eclipse.core.internal.filesystem.local, - org.eclipse.ui.part + org.eclipse.ui.part, + org.json Export-Package: org.eclipse.camf.tosca.editor, org.eclipse.camf.tosca.editor.diagram, org.eclipse.camf.tosca.editor.dialog,
diff --git a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/ToscaDiagramEditor.java b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/ToscaDiagramEditor.java index 565bc92..cd77657 100644 --- a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/ToscaDiagramEditor.java +++ b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/ToscaDiagramEditor.java
@@ -23,6 +23,7 @@ import org.eclipse.camf.tosca.DocumentRoot; import org.eclipse.camf.tosca.ImplementationArtifactType; import org.eclipse.camf.tosca.SourceElementType; +import org.eclipse.camf.tosca.TArtifactTemplate; import org.eclipse.camf.tosca.TDeploymentArtifact; import org.eclipse.camf.tosca.TNodeTemplate; import org.eclipse.camf.tosca.TNodeTypeImplementation; @@ -66,6 +67,7 @@ import org.eclipse.graphiti.mm.pictograms.ContainerShape; import org.eclipse.graphiti.mm.pictograms.Diagram; import org.eclipse.graphiti.mm.pictograms.PictogramElement; +import org.eclipse.graphiti.platform.IDiagramBehavior; //import org.eclipse.graphiti.services.Graphiti; import org.eclipse.graphiti.ui.editor.DiagramEditor; import org.eclipse.graphiti.ui.editor.DiagramEditorInput; @@ -80,527 +82,540 @@ * */ public class ToscaDiagramEditor extends DiagramEditor { - - private static GraphicalViewer gViewer; - - private ToscaModelChangeListener toscaModelChangeListener; - - private TransactionalEditingDomain transactionalEditingDomain; - - private static IProject activeProject = null; - - /** - * The Tosca Diagram Editor Constructor. - */ - public ToscaDiagramEditor () { - super (); - } - - public static IProject getActiveProject(){ - - return activeProject; - - } - - protected void registerBusinessObjectsListener() { - - this.toscaModelChangeListener = new ToscaModelChangeListener(this); + + private static GraphicalViewer gViewer; + + public static IDiagramBehavior db = null; + + private ToscaModelChangeListener toscaModelChangeListener; + + private TransactionalEditingDomain transactionalEditingDomain; + + private static IProject activeProject = null; + + /** + * The Tosca Diagram Editor Constructor. + */ + public ToscaDiagramEditor () { + + super (); + + } + + public static IProject getActiveProject(){ + + return activeProject; + + } + + protected void registerBusinessObjectsListener() { + + this.toscaModelChangeListener = new ToscaModelChangeListener(this); - final TransactionalEditingDomain ted = getEditingDomain(); - ted.addResourceSetListener(this.toscaModelChangeListener); - } + final TransactionalEditingDomain ted = getEditingDomain(); + ted.addResourceSetListener(this.toscaModelChangeListener); + } - /* (non-Javadoc) - * @see org.eclipse.graphiti.ui.editor.DiagramEditor#getEditingDomain() - */ - @Override - public TransactionalEditingDomain getEditingDomain() { - TransactionalEditingDomain ted = super.getEditingDomain(); + /* (non-Javadoc) + * @see org.eclipse.graphiti.ui.editor.DiagramEditor#getEditingDomain() + */ + @Override + public TransactionalEditingDomain getEditingDomain() { + TransactionalEditingDomain ted = super.getEditingDomain(); - if (ted == null) { - ted = this.transactionalEditingDomain; - } + if (ted == null) { + ted = this.transactionalEditingDomain; + } - return ted; - } + return ted; + } - @Override - public void init(final IEditorSite site, final IEditorInput input) throws PartInitException { - - IEditorInput finalInput = null; + @Override + public void init(final IEditorSite site, final IEditorInput input) throws PartInitException { + + IEditorInput finalInput = null; - try { - if (input instanceof ToscaDiagramEditorInput) { - finalInput = input; - } else { - finalInput = createNewDiagramEditorInput(input); - } - } catch (CoreException exception) { - exception.printStackTrace(); - } + try { + if (input instanceof ToscaDiagramEditorInput) { + finalInput = input; + } else { + finalInput = createNewDiagramEditorInput(input); + } + } catch (CoreException exception) { + exception.printStackTrace(); + } - if ( finalInput instanceof ToscaDiagramEditorInput ){ - activeProject = ((ToscaDiagramEditorInput) finalInput).getToscaFile().getProject(); - } + if ( finalInput instanceof ToscaDiagramEditorInput ){ + activeProject = ((ToscaDiagramEditorInput) finalInput).getToscaFile().getProject(); + } - super.init(site, finalInput); - // Refresh Palette Compartments - getDiagramTypeProvider().getFeatureProvider().getDiagramTypeProvider().getDiagramBehavior().refreshPalette(); - - } - + super.init(site, finalInput); + // Refresh Palette Compartments + ToscaDiagramEditor.db = getDiagramTypeProvider().getFeatureProvider().getDiagramTypeProvider().getDiagramBehavior(); + getDiagramTypeProvider().getFeatureProvider().getDiagramTypeProvider().getDiagramBehavior().refreshPalette(); + + } + - private ToscaDiagramEditorInput createNewDiagramEditorInput(final IEditorInput input) throws CoreException { + private ToscaDiagramEditorInput createNewDiagramEditorInput(final IEditorInput input) throws CoreException { - final IFile dataFile = ToscaFileService.getDataFileForInput(input); + final IFile dataFile = ToscaFileService.getDataFileForInput(input); - // now generate the temporary diagram file - final IPath dataFilePath = dataFile.getFullPath(); + // now generate the temporary diagram file + final IPath dataFilePath = dataFile.getFullPath(); - // get or create the corresponding temporary folder - final IFolder tempFolder = ToscaFileService.getOrCreateTempFolder(dataFilePath); + // get or create the corresponding temporary folder + final IFolder tempFolder = ToscaFileService.getOrCreateTempFolder(dataFilePath); - // finally get the diagram file that corresponds to the data file - final IFile diagramFile = ToscaFileService.getTemporaryDiagramFile(dataFilePath, tempFolder); + // finally get the diagram file that corresponds to the data file + final IFile diagramFile = ToscaFileService.getTemporaryDiagramFile(dataFilePath, tempFolder); - // Create new temporary diagram file - ToscaDiagramCreator creator = new ToscaDiagramCreator(); + // Create new temporary diagram file + ToscaDiagramCreator creator = new ToscaDiagramCreator(); - return creator.createToscaDiagram(dataFile, diagramFile, this, false); - } - - @Override - public void doSave(final IProgressMonitor monitor) { - super.doSave(monitor); - -// final ToscaDiagramEditorInput tdei = (ToscaDiagramEditorInput) getEditorInput(); - - ((BasicCommandStack) getEditingDomain().getCommandStack()).saveIsDone(); - updateDirtyState(); - } - - @Override - public boolean isDirty() { - TransactionalEditingDomain editingDomain = getEditingDomain(); - // Check that the editor is not yet disposed - if (editingDomain != null && editingDomain.getCommandStack() != null) { - return ((BasicCommandStack) editingDomain.getCommandStack()).isSaveNeeded(); - } - return false; - } - - @Override - protected void setInput(final IEditorInput input) { - super.setInput(input); + return creator.createToscaDiagram(dataFile, diagramFile, this, false); + } + + @Override + public void doSave(final IProgressMonitor monitor) { + super.doSave(monitor); + +// final ToscaDiagramEditorInput tdei = (ToscaDiagramEditorInput) getEditorInput(); + + ((BasicCommandStack) getEditingDomain().getCommandStack()).saveIsDone(); + updateDirtyState(); + } + + @Override + public boolean isDirty() { + TransactionalEditingDomain editingDomain = getEditingDomain(); + // Check that the editor is not yet disposed + if (editingDomain != null && editingDomain.getCommandStack() != null) { + return ((BasicCommandStack) editingDomain.getCommandStack()).isSaveNeeded(); + } + return false; + } + + @Override + protected void setInput(final IEditorInput input) { + super.setInput(input); - final ToscaDiagramEditorInput tdei = (ToscaDiagramEditorInput) input; - final IFile dataFile = tdei.getToscaFile(); - - final ToscaModelLayer model = new ToscaModelLayer(getDiagramTypeProvider().getFeatureProvider(), dataFile); - ModelHandler.addModel(EcoreUtil.getURI(getDiagramTypeProvider().getDiagram()), model); - - DocumentRoot documentRoot = null; - TOSCAResource toscaResource = null ; - ICloudElement findElement = CloudModel.getRoot().findElement( dataFile ); - if (findElement instanceof TOSCAResource) { - toscaResource = (TOSCAResource) findElement; - } - - URI resourceURI = null; - //IEditorInput eInput = getEditorInput(); - - if( getEditorInput() instanceof ToscaDiagramEditorInput ) { - IFile modelFile = ((ToscaDiagramEditorInput) getEditorInput()).getToscaFile(); - resourceURI = URI.createPlatformResourceURI( modelFile.getFullPath().toString(), false ); - } - - Exception exception = null; - Resource resource = null; - try { - /* Load the resource through the editing domain. */ - resource = getEditingDomain().getResourceSet().getResource( resourceURI, true ); - } catch( Exception e ) { - exception = e; - resource = getEditingDomain().getResourceSet().getResource( resourceURI, false ); - } - Diagnostic diagnostic = analyzeResourceProblems( resource, exception ); - - if( diagnostic.getSeverity() != Diagnostic.OK ) { - //todo - } else { - documentRoot = getDocumentRoot( resource ); -// documentRoot = toscaResource.getTOSCAModel().getDocumentRoot(); - } + final ToscaDiagramEditorInput tdei = (ToscaDiagramEditorInput) input; + final IFile dataFile = tdei.getToscaFile(); + + final ToscaModelLayer model = new ToscaModelLayer(getDiagramTypeProvider().getFeatureProvider(), dataFile); + ModelHandler.addModel(EcoreUtil.getURI(getDiagramTypeProvider().getDiagram()), model); + + DocumentRoot documentRoot = null; + TOSCAResource toscaResource = null ; + ICloudElement findElement = CloudModel.getRoot().findElement( dataFile ); + if (findElement instanceof TOSCAResource) { + toscaResource = (TOSCAResource) findElement; + } + + URI resourceURI = null; + //IEditorInput eInput = getEditorInput(); + + if( getEditorInput() instanceof ToscaDiagramEditorInput ) { + IFile modelFile = ((ToscaDiagramEditorInput) getEditorInput()).getToscaFile(); + resourceURI = URI.createPlatformResourceURI( modelFile.getFullPath().toString(), false ); + } + + Exception exception = null; + Resource resource = null; + try { + /* Load the resource through the editing domain. */ + resource = getEditingDomain().getResourceSet().getResource( resourceURI, true ); + } catch( Exception e ) { + exception = e; + resource = getEditingDomain().getResourceSet().getResource( resourceURI, false ); + } + Diagnostic diagnostic = analyzeResourceProblems( resource, exception ); + + if( diagnostic.getSeverity() != Diagnostic.OK ) { + //todo + } else { + documentRoot = getDocumentRoot( resource ); +// documentRoot = toscaResource.getTOSCAModel().getDocumentRoot(); + } - - if( documentRoot != null ) { - model.setDocumentRoot( documentRoot ); - BasicCommandStack basicCommandStack = ( BasicCommandStack )getEditingDomain().getCommandStack(); - if( input instanceof DiagramEditorInput ) { - basicCommandStack.execute( new RecordingCommand( getEditingDomain() ) { + + if( documentRoot != null ) { + model.setDocumentRoot( documentRoot ); + BasicCommandStack basicCommandStack = ( BasicCommandStack )getEditingDomain().getCommandStack(); + if( input instanceof DiagramEditorInput ) { + basicCommandStack.execute( new RecordingCommand( getEditingDomain() ) { - @Override - protected void doExecute() { - importDiagram( model ); - } - } ); - } - basicCommandStack.saveIsDone(); - basicCommandStack.flush(); - } - } - - private final DocumentRoot getDocumentRoot( final Resource resource ) { - // Get an iterator to iterate through all contents of the resource. - TreeIterator<EObject> iterator = resource.getAllContents(); - DocumentRoot result = null; - while( iterator.hasNext() ) { - EObject testElement = iterator.next(); - /* - * Instance-of checks for each EObject that appears in the resource. We - * want to get the DocumentRoot EObject which is the root Element inside a - * Tosca Document. - */ - if( testElement instanceof DocumentRoot ) { - result = ( DocumentRoot ) testElement; - } - } - return result; - } - - - /** - * @param resource - * @param exception - * @return - */ - private Diagnostic analyzeResourceProblems( final Resource resource, - final Exception exception ) - { - Diagnostic basicDiagnostic = null; - if( !resource.getErrors().isEmpty() || !resource.getWarnings().isEmpty() ) { - basicDiagnostic = new BasicDiagnostic( Diagnostic.ERROR, - Activator.PLUGIN_ID, - 0, - String.format( Messages.getString( "ToscaEditor.CreateModelErrorMessage" ), //$NON-NLS-1$ - resource.getURI() ), - new Object[]{ - exception == null - ? ( Object )resource - : exception - } ); - ( ( BasicDiagnostic )basicDiagnostic ).merge( EcoreUtil.computeDiagnostic( resource, - true ) ); - } else if( exception != null ) { - basicDiagnostic = new BasicDiagnostic( Diagnostic.ERROR, - Activator.PLUGIN_ID, - 0, - Messages.getString( "ToscaEditor.CreateModelErrorMessage" ), //$NON-NLS-1$ - new Object[]{ - exception - } ); - } else { - basicDiagnostic = Diagnostic.OK_INSTANCE; - } - return basicDiagnostic; - } - - - protected void importDiagram( final ToscaModelLayer model ) { - final Diagram diagram = getDiagramTypeProvider().getDiagram(); - diagram.setActive( true ); - getEditingDomain().getCommandStack() - .execute( new RecordingCommand( getEditingDomain() ) { + @Override + protected void doExecute() { + importDiagram( model ); + } + } ); + } + basicCommandStack.saveIsDone(); + basicCommandStack.flush(); + } + } + + private final DocumentRoot getDocumentRoot( final Resource resource ) { + // Get an iterator to iterate through all contents of the resource. + TreeIterator<EObject> iterator = resource.getAllContents(); + DocumentRoot result = null; + while( iterator.hasNext() ) { + EObject testElement = iterator.next(); + /* + * Instance-of checks for each EObject that appears in the resource. We + * want to get the DocumentRoot EObject which is the root Element inside a + * Tosca Document. + */ + if( testElement instanceof DocumentRoot ) { + result = ( DocumentRoot ) testElement; + } + } + return result; + } + + + /** + * @param resource + * @param exception + * @return + */ + private Diagnostic analyzeResourceProblems( final Resource resource, + final Exception exception ) + { + Diagnostic basicDiagnostic = null; + if( !resource.getErrors().isEmpty() || !resource.getWarnings().isEmpty() ) { + basicDiagnostic = new BasicDiagnostic( Diagnostic.ERROR, + Activator.PLUGIN_ID, + 0, + String.format( Messages.getString( "ToscaEditor.CreateModelErrorMessage" ), //$NON-NLS-1$ + resource.getURI() ), + new Object[]{ + exception == null + ? ( Object )resource + : exception + } ); + ( ( BasicDiagnostic )basicDiagnostic ).merge( EcoreUtil.computeDiagnostic( resource, + true ) ); + } else if( exception != null ) { + basicDiagnostic = new BasicDiagnostic( Diagnostic.ERROR, + Activator.PLUGIN_ID, + 0, + Messages.getString( "ToscaEditor.CreateModelErrorMessage" ), //$NON-NLS-1$ + new Object[]{ + exception + } ); + } else { + basicDiagnostic = Diagnostic.OK_INSTANCE; + } + return basicDiagnostic; + } + + + protected void importDiagram( final ToscaModelLayer model ) { + final Diagram diagram = getDiagramTypeProvider().getDiagram(); + diagram.setActive( true ); + getEditingDomain().getCommandStack() + .execute( new RecordingCommand( getEditingDomain() ) { - @Override - protected void doExecute() { - if (model.getDocumentRoot() != null) { - DocumentRoot documentRoot = model.getDocumentRoot(); - DefinitionsType definitionsType = documentRoot.getDefinitions(); - EList<TServiceTemplate> serviceTemplates = definitionsType.getServiceTemplate(); - EList<TNodeTypeImplementation> nodeTypesImplementation = definitionsType.getNodeTypeImplementation(); - - Boolean substitute = false; - ContainerShape containerShapeTST = null; - - for (TServiceTemplate tst : serviceTemplates) { - - if ( tst.getSubstitutableNodeType() != null ){ - //tst is a group component - TServiceTemplateExtension tstG = (TServiceTemplateExtension) tst; - addContainerElement (tst, containerShapeTST, tstG.getX(), tstG.getY(), tstG.getWidth(), tstG.getHeight()); - substitute = true; - } - - else{ - TServiceTemplateExtension tste = (TServiceTemplateExtension) tst; - addContainerElement (tst, diagram, 0, 0, tste.getWidth(), tste.getHeight()); - containerShapeTST = ( ContainerShape )getDiagramTypeProvider().getFeatureProvider() - .getPictogramElementForBusinessObject( tst ); - } - - ContainerShape containerShape = ( ContainerShape )getDiagramTypeProvider().getFeatureProvider() - .getPictogramElementForBusinessObject( tst ); - - TTopologyTemplate topology = tst.getTopologyTemplate(); - - if (topology == null) - break; - - for (TNodeTemplate tnt : topology.getNodeTemplate()) { + @Override + protected void doExecute() { + if (model.getDocumentRoot() != null) { + DocumentRoot documentRoot = model.getDocumentRoot(); + DefinitionsType definitionsType = documentRoot.getDefinitions(); + EList<TServiceTemplate> serviceTemplates = definitionsType.getServiceTemplate(); + EList<TNodeTypeImplementation> nodeTypesImplementation = definitionsType.getNodeTypeImplementation(); + EList<TArtifactTemplate> artifactTemplates = definitionsType.getArtifactTemplate(); + + Boolean substitute = false; + ContainerShape containerShapeTST = null; + + for (TServiceTemplate tst : serviceTemplates) { + + if ( tst.getSubstitutableNodeType() != null ){ + //tst is a group component + TServiceTemplateExtension tstG = (TServiceTemplateExtension) tst; + addContainerElement (tst, containerShapeTST, tstG.getX(), tstG.getY(), tstG.getWidth(), tstG.getHeight()); + substitute = true; + } + + else{ + TServiceTemplateExtension tste = (TServiceTemplateExtension) tst; + addContainerElement (tst, diagram, 0, 0, tste.getWidth(), tste.getHeight()); + containerShapeTST = ( ContainerShape )getDiagramTypeProvider().getFeatureProvider() + .getPictogramElementForBusinessObject( tst ); + } + + ContainerShape containerShape = ( ContainerShape )getDiagramTypeProvider().getFeatureProvider() + .getPictogramElementForBusinessObject( tst ); + + TTopologyTemplate topology = tst.getTopologyTemplate(); + + if (topology == null) + break; + + for (TNodeTemplate tnt : topology.getNodeTemplate()) { - if ( (tnt.getType()!=null) && (tnt.getType().toString().contains( "substituteNode" )) ) {//$NON-NLS-1$ - continue; - } - - TNodeTemplateExtension tnte = (TNodeTemplateExtension) tnt; - addContainerElement( tnt, containerShape, tnte.getX(), tnte.getY(), tnte.getWidth(), tnte.getHeight() ); - - ContainerShape containerShapeTNT = ( ContainerShape )getDiagramTypeProvider().getFeatureProvider() - .getPictogramElementForBusinessObject( tnt ); - - //Add Deployment Artifacts - if ( tnt.getDeploymentArtifacts() != null && tnt.getDeploymentArtifacts().getDeploymentArtifact() != null ){ - for (TDeploymentArtifact tda : tnt.getDeploymentArtifacts().getDeploymentArtifact() ){ + if ( (tnt.getType()!=null) && (tnt.getType().toString().contains( "substituteNode" )) ) {//$NON-NLS-1$ + continue; + } + + TNodeTemplateExtension tnte = (TNodeTemplateExtension) tnt; + addContainerElement( tnt, containerShape, tnte.getX(), tnte.getY(), tnte.getWidth(), tnte.getHeight() ); + + ContainerShape containerShapeTNT = ( ContainerShape )getDiagramTypeProvider().getFeatureProvider() + .getPictogramElementForBusinessObject( tnt ); + + //Add Deployment Artifacts + if ( tnt.getDeploymentArtifacts() != null && tnt.getDeploymentArtifacts().getDeploymentArtifact() != null ){ + for (TDeploymentArtifact tda : tnt.getDeploymentArtifacts().getDeploymentArtifact() ){ - addContainerElement( tda, containerShapeTNT, 0, 0, 0, 0 ); - - } - } - -// //Find NodeTypeImplementation -// TNodeTypeImplementation nodeTypeImplementation = null; -// for (TNodeTypeImplementation tempNodeImplementation : nodeTypesImplementation){ -// if (tnt.getName().equals( tempNodeImplementation.getNodeType().toString())){ -// nodeTypeImplementation = tempNodeImplementation; -// break; -// } -// } -// if (nodeTypeImplementation!=null && nodeTypeImplementation.getImplementationArtifacts()!=null){ -// EList<ImplementationArtifactType> implementationArtifacts = nodeTypeImplementation.getImplementationArtifacts().getImplementationArtifact(); -// for (ImplementationArtifactType tempImplementationArtifact : implementationArtifacts){ -// addContainerElement( tempImplementationArtifact, containerShapeTNT, 0, 0, 0, 0 ); -// } -// } - - } - - if ( substitute ){ - //Composite Component Service Template - //Add deployment artifacts to composite component's service template - - for (TServiceTemplate tempTst : serviceTemplates) { - for (TNodeTemplate tnt : tempTst.getTopologyTemplate().getNodeTemplate()) { - - - if ( tst.getSubstitutableNodeType() != null && (tnt.getType()!=null) && tnt.getType().toString().equals( tst.getSubstitutableNodeType().toString()) ){ - //Found the service template that substitutes the specific node template - - ContainerShape containerShapeTNT = ( ContainerShape )getDiagramTypeProvider().getFeatureProvider() - .getPictogramElementForBusinessObject( tst ); - - //Add Deployment Artifacts - if ( tnt.getDeploymentArtifacts() != null && tnt.getDeploymentArtifacts().getDeploymentArtifact() != null ){ - for (TDeploymentArtifact tda : tnt.getDeploymentArtifacts().getDeploymentArtifact() ){ + addContainerElement( tda, containerShapeTNT, 0, 0, 0, 0 ); + + } + } + + //Find NodeTypeImplementation + TNodeTypeImplementation nodeTypeImplementation = null; + for (TNodeTypeImplementation tempNodeImplementation : nodeTypesImplementation){ + if (tnt.getName().equals( tempNodeImplementation.getNodeType().toString())){ + nodeTypeImplementation = tempNodeImplementation; + break; + } + } + if (nodeTypeImplementation!=null && nodeTypeImplementation.getImplementationArtifacts()!=null){ + EList<ImplementationArtifactType> implementationArtifacts = nodeTypeImplementation.getImplementationArtifacts().getImplementationArtifact(); + for (ImplementationArtifactType tempImplementationArtifact : implementationArtifacts){ + if (tempImplementationArtifact.getOperationName().equals( "execute" )) + { + for (TArtifactTemplate tempArtifactTemplate : artifactTemplates){ + if (tempArtifactTemplate.getId().equals(tempImplementationArtifact.getArtifactRef().toString())) + addContainerElement( tempArtifactTemplate, containerShapeTNT, 0, 0, 0, 0 ); + } + } + + } + } + + } + + if ( substitute ){ + //Composite Component Service Template + //Add deployment artifacts to composite component's service template + + for (TServiceTemplate tempTst : serviceTemplates) { + for (TNodeTemplate tnt : tempTst.getTopologyTemplate().getNodeTemplate()) { + + + if ( tst.getSubstitutableNodeType() != null && (tnt.getType()!=null) && tnt.getType().toString().equals( tst.getSubstitutableNodeType().toString()) ){ + //Found the service template that substitutes the specific node template + + ContainerShape containerShapeTNT = ( ContainerShape )getDiagramTypeProvider().getFeatureProvider() + .getPictogramElementForBusinessObject( tst ); + + //Add Deployment Artifacts + if ( tnt.getDeploymentArtifacts() != null && tnt.getDeploymentArtifacts().getDeploymentArtifact() != null ){ + for (TDeploymentArtifact tda : tnt.getDeploymentArtifacts().getDeploymentArtifact() ){ - addContainerElement( tda, containerShapeTNT, 0, 0, 0, 0 ); - - } - } - break; - } - - - } - } - substitute = false; - } - else{ - //Application Service Template - //Add deployment artifacts to application's service template - - } + addContainerElement( tda, containerShapeTNT, 0, 0, 0, 0 ); + + } + } + break; + } + + + } + } + substitute = false; + } + else{ + //Application Service Template + //Add deployment artifacts to application's service template + + } - } - - //Add Relationships - for (TServiceTemplate tst : serviceTemplates) { - - if ( tst.getTopologyTemplate() == null ) - continue; - - for (TRelationshipTemplate trt : tst.getTopologyTemplate().getRelationshipTemplate()) { - - SourceElementType se = trt.getSourceElement(); - TargetElementType te = trt.getTargetElement(); - String sourceID = se.getRef(); - String targetID = te.getRef(); - Anchor sourceAnchor = null, targetAnchor = null; - for (TServiceTemplate tstTemp : serviceTemplates) { - for (TNodeTemplate tnt : tstTemp.getTopologyTemplate().getNodeTemplate()) { - - ContainerShape containerShapeTNT; - - if ( tnt.getId().equals(sourceID) ){ - if ( (tnt.getType()!=null) && (tnt.getType().toString().contains( "substituteNode" ) == true) ){ - containerShapeTNT = getAnchorContainer(model, tnt); - }else{ - containerShapeTNT = ( ContainerShape )getDiagramTypeProvider().getFeatureProvider() - .getPictogramElementForBusinessObject( tnt ); - } - if ( containerShapeTNT.getAnchors() != null ){ - for ( Anchor anchor : containerShapeTNT.getAnchors() ){ - if (anchor instanceof ChopboxAnchor){ - sourceAnchor = anchor; - break; - } - } - } - - } else if ( tnt.getId().equals(targetID) ){ - if ( ((tnt.getType()!=null)) && (tnt.getType().toString().contains( "substituteNode" ) == true) ){ - containerShapeTNT = getAnchorContainer(model, tnt); - }else{ - containerShapeTNT = ( ContainerShape )getDiagramTypeProvider().getFeatureProvider() - .getPictogramElementForBusinessObject( tnt ); - } - if ( containerShapeTNT.getAnchors() != null ){ - for ( Anchor anchor : containerShapeTNT.getAnchors() ){ - if (anchor instanceof ChopboxAnchor){ - targetAnchor = anchor; - break; - } - } - } - } - } - } - - - addRelationshipContainerElement( trt, sourceAnchor, targetAnchor ); - } - } - } - } + } + + //Add Relationships + for (TServiceTemplate tst : serviceTemplates) { + + if ( tst.getTopologyTemplate() == null ) + continue; + + for (TRelationshipTemplate trt : tst.getTopologyTemplate().getRelationshipTemplate()) { + + SourceElementType se = trt.getSourceElement(); + TargetElementType te = trt.getTargetElement(); + String sourceID = se.getRef(); + String targetID = te.getRef(); + Anchor sourceAnchor = null, targetAnchor = null; + for (TServiceTemplate tstTemp : serviceTemplates) { + for (TNodeTemplate tnt : tstTemp.getTopologyTemplate().getNodeTemplate()) { + + ContainerShape containerShapeTNT; + + if ( tnt.getId().equals(sourceID) ){ + if ( (tnt.getType()!=null) && (tnt.getType().toString().contains( "substituteNode" ) == true) ){ + containerShapeTNT = getAnchorContainer(model, tnt); + }else{ + containerShapeTNT = ( ContainerShape )getDiagramTypeProvider().getFeatureProvider() + .getPictogramElementForBusinessObject( tnt ); + } + if ( containerShapeTNT.getAnchors() != null ){ + for ( Anchor anchor : containerShapeTNT.getAnchors() ){ + if (anchor instanceof ChopboxAnchor){ + sourceAnchor = anchor; + break; + } + } + } + + } else if ( tnt.getId().equals(targetID) ){ + if ( ((tnt.getType()!=null)) && (tnt.getType().toString().contains( "substituteNode" ) == true) ){ + containerShapeTNT = getAnchorContainer(model, tnt); + }else{ + containerShapeTNT = ( ContainerShape )getDiagramTypeProvider().getFeatureProvider() + .getPictogramElementForBusinessObject( tnt ); + } + if ( containerShapeTNT.getAnchors() != null ){ + for ( Anchor anchor : containerShapeTNT.getAnchors() ){ + if (anchor instanceof ChopboxAnchor){ + targetAnchor = anchor; + break; + } + } + } + } + } + } + + + addRelationshipContainerElement( trt, sourceAnchor, targetAnchor ); + } + } + } + } - } ); - } - - - private ContainerShape getAnchorContainer(final ToscaModelLayer model, TNodeTemplate nodeTemplate){ - // Find the substitute TServiceTemplate - TServiceTemplate substituteNode = null; + } ); + } + + + private ContainerShape getAnchorContainer(final ToscaModelLayer model, TNodeTemplate nodeTemplate){ + // Find the substitute TServiceTemplate + TServiceTemplate substituteNode = null; - for (TServiceTemplate tempServiceTemplate : model.getDocumentRoot() - .getDefinitions() - .getServiceTemplate()){ - - if (tempServiceTemplate.getSubstitutableNodeType() != null && - tempServiceTemplate.getId().equals(nodeTemplate.getId())) - { - substituteNode = tempServiceTemplate; - break; - } - } - return ( ContainerShape )getDiagramTypeProvider().getFeatureProvider() - .getPictogramElementForBusinessObject( substituteNode ); - } - - protected PictogramElement addContainerElement( final EObject element, - final ContainerShape parent, int x_axis, int y_axis, int width, int height ) - { - - final IFeatureProvider featureProvider = getDiagramTypeProvider().getFeatureProvider(); - - AddContext context = new AddContext( new AreaContext(), element ); - IAddFeature addFeature = featureProvider.getAddFeature( context ); - context.setNewObject( element ); - context.setTargetContainer( parent ); - context.setLocation(x_axis, y_axis); - context.setSize( width, height ); - PictogramElement pictElement = null; - - boolean canAdd = false; - if (addFeature != null) { - canAdd = addFeature.canAdd( context ) ; - } - - if( canAdd ) { - pictElement = addFeature.add( context ); - - if (element instanceof TDeploymentArtifact && ((TDeploymentArtifact) element).getArtifactType().toString().compareTo( "MonitoringProbe" )==0){ - //There is no pictogram element linked to the monitoring image - return pictElement; - } - else{ - featureProvider.link( pictElement, new Object[]{ element } ); - return pictElement; - } - } - - return null; + for (TServiceTemplate tempServiceTemplate : model.getDocumentRoot() + .getDefinitions() + .getServiceTemplate()){ + + if (tempServiceTemplate.getSubstitutableNodeType() != null && + tempServiceTemplate.getId().equals(nodeTemplate.getId())) + { + substituteNode = tempServiceTemplate; + break; + } + } + return ( ContainerShape )getDiagramTypeProvider().getFeatureProvider() + .getPictogramElementForBusinessObject( substituteNode ); + } + + protected PictogramElement addContainerElement( final EObject element, + final ContainerShape parent, int x_axis, int y_axis, int width, int height ) + { + + final IFeatureProvider featureProvider = getDiagramTypeProvider().getFeatureProvider(); + + AddContext context = new AddContext( new AreaContext(), element ); + IAddFeature addFeature = featureProvider.getAddFeature( context ); + context.setNewObject( element ); + context.setTargetContainer( parent ); + context.setLocation(x_axis, y_axis); + context.setSize( width, height ); + PictogramElement pictElement = null; + + boolean canAdd = false; + if (addFeature != null) { + canAdd = addFeature.canAdd( context ) ; + } + + if( canAdd ) { + pictElement = addFeature.add( context ); + + if (element instanceof TDeploymentArtifact && ((TDeploymentArtifact) element).getArtifactType().toString().compareTo( "MonitoringProbe" )==0){ + //There is no pictogram element linked to the monitoring image + return pictElement; + } + else{ + featureProvider.link( pictElement, new Object[]{ element } ); + return pictElement; + } + } + + return null; - } + } - protected PictogramElement addRelationshipContainerElement( final EObject element, - final Anchor sourceAnchor, final Anchor targetAnchor ){ - - if (sourceAnchor == null) - return null; - - if (targetAnchor == null) - return null; - - AddConnectionContext context = new AddConnectionContext(sourceAnchor, targetAnchor); - context.setNewObject( element ); - - final IFeatureProvider featureProvider = getDiagramTypeProvider().getFeatureProvider(); - IAddFeature addFeature = featureProvider.getAddFeature( context ); - - PictogramElement pictElement = null; - - boolean canAdd = addFeature.canAdd( context ) ; - - if( canAdd ) { - pictElement = addFeature.add( context ); - featureProvider.link( pictElement, new Object[]{ element } ); - } - - return pictElement; + protected PictogramElement addRelationshipContainerElement( final EObject element, + final Anchor sourceAnchor, final Anchor targetAnchor ){ + + if (sourceAnchor == null) + return null; + + if (targetAnchor == null) + return null; + + AddConnectionContext context = new AddConnectionContext(sourceAnchor, targetAnchor); + context.setNewObject( element ); + + final IFeatureProvider featureProvider = getDiagramTypeProvider().getFeatureProvider(); + IAddFeature addFeature = featureProvider.getAddFeature( context ); + + PictogramElement pictElement = null; + + boolean canAdd = addFeature.canAdd( context ) ; + + if( canAdd ) { + pictElement = addFeature.add( context ); + featureProvider.link( pictElement, new Object[]{ element } ); + } + + return pictElement; - } + } - - - @Override - public void createPartControl(Composite parent) { - super.createPartControl(parent); - // hides grid on diagram, but you can reenable it - if (getGraphicalViewer() != null && getGraphicalViewer().getEditPartRegistry() != null) { - ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart) getGraphicalViewer().getEditPartRegistry().get(LayerManager.ID); - IFigure gridFigure = ((LayerManager) rootEditPart).getLayer(LayerConstants.GRID_LAYER); - gridFigure.setVisible(true); - } - // setPartName("MyDiagram2"); - } + + + @Override + public void createPartControl(Composite parent) { + super.createPartControl(parent); + // hides grid on diagram, but you can reenable it + if (getGraphicalViewer() != null && getGraphicalViewer().getEditPartRegistry() != null) { + ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart) getGraphicalViewer().getEditPartRegistry().get(LayerManager.ID); + IFigure gridFigure = ((LayerManager) rootEditPart).getLayer(LayerConstants.GRID_LAYER); + gridFigure.setVisible(true); + } + // setPartName("MyDiagram2"); + } -// @Override -// protected ContextMenuProvider createContextMenuProvider() { -// return new ActivitiEditorContextMenuProvider(getGraphicalViewer(), getActionRegistry(), getDiagramTypeProvider()); -// } + // @Override + // protected ContextMenuProvider createContextMenuProvider() { +// return new ActivitiEditorContextMenuProvider(getGraphicalViewer(), getActionRegistry(), getDiagramTypeProvider()); + // } - public static GraphicalViewer getActiveGraphicalViewer() { - return gViewer; - } + public static GraphicalViewer getActiveGraphicalViewer() { + return gViewer; + } - @Override - public void dispose() { - super.dispose(); + @Override + public void dispose() { + super.dispose(); - final ToscaDiagramEditorInput tdei = (ToscaDiagramEditorInput) getEditorInput(); + final ToscaDiagramEditorInput tdei = (ToscaDiagramEditorInput) getEditorInput(); - ModelHandler.removeModel(EcoreUtil.getURI(getDiagramTypeProvider().getDiagram())); - ToscaDiagramCreator.dispose(tdei.getDiagramFile()); - } - -} + ModelHandler.removeModel(EcoreUtil.getURI(getDiagramTypeProvider().getDiagram())); + ToscaDiagramCreator.dispose(tdei.getDiagramFile()); + } + + }
diff --git a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/diagram/ToscaFeatureProvider.java b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/diagram/ToscaFeatureProvider.java index 108608c..9b87766 100644 --- a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/diagram/ToscaFeatureProvider.java +++ b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/diagram/ToscaFeatureProvider.java
@@ -22,6 +22,7 @@ import org.eclipse.camf.core.model.impl.ResourceCloudElement; import org.eclipse.camf.infosystem.model.base.ResizingAction; +import org.eclipse.camf.tosca.TArtifactTemplate; import org.eclipse.camf.tosca.TDeploymentArtifact; import org.eclipse.camf.tosca.TNodeTemplate; import org.eclipse.camf.tosca.TRelationshipTemplate; @@ -50,6 +51,7 @@ import org.eclipse.camf.tosca.editor.features.CreateUserApplicationFeature; import org.eclipse.camf.tosca.editor.features.CreateVMIFeature; import org.eclipse.camf.tosca.editor.features.DeleteApplicationComponentFeature; +import org.eclipse.camf.tosca.editor.features.DeleteArtifactTemplateFeature; import org.eclipse.camf.tosca.editor.features.DeleteDeploymentArtifactFeature; import org.eclipse.camf.tosca.editor.features.DeleteGroupFeature; import org.eclipse.camf.tosca.editor.features.DirectEditApplicationComponentFeature; @@ -64,6 +66,7 @@ import org.eclipse.camf.tosca.editor.features.ResizeCompositeComponentFeature; import org.eclipse.camf.tosca.editor.features.UpdateApplicationComponentFeature; import org.eclipse.camf.tosca.editor.features.UpdateCompositeComponentFeature; +import org.eclipse.camf.tosca.elasticity.Tosca_Elasticity_ExtensionsPackage; import org.eclipse.core.resources.IFile; import org.eclipse.graphiti.dt.IDiagramTypeProvider; import org.eclipse.graphiti.features.IAddFeature; @@ -94,230 +97,214 @@ import org.eclipse.graphiti.ui.features.DefaultFeatureProvider; public class ToscaFeatureProvider extends DefaultFeatureProvider { + + private String imageType = Tosca_Elasticity_ExtensionsPackage.eINSTANCE.getImageArtifactPropertiesType().getName(); - public ToscaFeatureProvider( final IDiagramTypeProvider dtp ) { - super( dtp ); - } + public ToscaFeatureProvider( final IDiagramTypeProvider dtp ) { + super( dtp ); + } - // Returns the add feature for the context - @Override - public IAddFeature getAddFeature( final IAddContext context ) { - if( context.getNewObject() instanceof TNodeTemplate ) { - return new AddApplicationComponentFeature( this ); - } -// else if( context.getNewObject() instanceof TRelationshipTemplate -// && ( ( TRelationshipTemplate )context.getNewObject() ).getType().toString().compareTo("Bidirected") == 0 ) //$NON-NLS-1$ -// { -// return new AddBidirectionalRelationFeature( this ); -// } - else if( context.getNewObject() instanceof TRelationshipTemplate ) { - return new AddDirectedRelationFeature( this ); - } else if( context.getNewObject() instanceof TDeploymentArtifact ) { - if (((TDeploymentArtifact)context.getNewObject()).getArtifactType().toString().compareTo( "UA" )==0) - return new AddUserApplicationFeature( this ); - else if (((TDeploymentArtifact)context.getNewObject()).getArtifactType().toString().compareTo( "SD" )==0) - return new AddSoftwareDependencyFeature( this ); - else if (((TDeploymentArtifact)context.getNewObject()).getArtifactType().toString().compareTo( "VMI" )==0) - return new AddVirtualMachineFeature( this ); - else if (((TDeploymentArtifact)context.getNewObject()).getArtifactType().toString().compareTo( "KeyPair" )==0) - return new AddKeyPairFeature( this ); - else if (((TDeploymentArtifact)context.getNewObject()).getArtifactType().toString().compareTo( "Network" )==0) - return new AddNetworkFeature( this ); - else if (((TDeploymentArtifact)context.getNewObject()).getArtifactType().toString().compareTo( "MonitoringProbe" )==0) - return new AddMonitorProbeFeature( this ); - - } else if( context.getNewObject() instanceof ResourceCloudElement) { - - return getIFileFeature(context); - } - else if( context.getNewObject() instanceof ResizingAction ) { - return new AddResizingActionFeature( this ); - } - // its a substitutional Service Template - else if( context.getNewObject() instanceof TServiceTemplate - && ( ( TServiceTemplate )context.getNewObject() ).getSubstitutableNodeType() != null ) - { - return new AddGroupFeature( this ); - } else if( context.getNewObject() instanceof TServiceTemplate ) { - return new AddServiceTemplateFeature( this ); - } - return super.getAddFeature( context ); - } + // Returns the add feature for the context + @Override + public IAddFeature getAddFeature( final IAddContext context ) { + if( context.getNewObject() instanceof TNodeTemplate ) { + return new AddApplicationComponentFeature( this ); + } + else if( context.getNewObject() instanceof TRelationshipTemplate ) { + return new AddDirectedRelationFeature( this ); + } else if( context.getNewObject() instanceof TDeploymentArtifact ) { + if (((TDeploymentArtifact)context.getNewObject()).getArtifactType().toString().compareTo( "UA" )==0) + return new AddUserApplicationFeature( this ); + else if (((TDeploymentArtifact)context.getNewObject()).getArtifactType().getLocalPart().compareTo( imageType )==0) + return new AddVirtualMachineFeature( this ); + else if (((TDeploymentArtifact)context.getNewObject()).getArtifactType().toString().compareTo( "KeyPair" )==0) + return new AddKeyPairFeature( this ); + else if (((TDeploymentArtifact)context.getNewObject()).getArtifactType().toString().compareTo( "MonitoringProbe" )==0) + return new AddMonitorProbeFeature( this ); + + }else if (context.getNewObject() instanceof TArtifactTemplate){ + if (((TArtifactTemplate)context.getNewObject()).getName()!=null && ((TArtifactTemplate)context.getNewObject()).getName().contains( "SD" )) + return new AddSoftwareDependencyFeature( this ); + } + + else if( context.getNewObject() instanceof ResourceCloudElement) { + + return getIFileFeature(context); + } + else if( context.getNewObject() instanceof ResizingAction ) { + return new AddResizingActionFeature( this ); + } + // its a substitutional Service Template + else if( context.getNewObject() instanceof TServiceTemplate + && ( ( TServiceTemplate )context.getNewObject() ).getSubstitutableNodeType() != null ) + { + return new AddGroupFeature( this ); + } else if( context.getNewObject() instanceof TServiceTemplate ) { + return new AddServiceTemplateFeature( this ); + } + return super.getAddFeature( context ); + } - /** - * @return - */ - private AbstractAddShapeFeature getIFileFeature(final IAddContext context) { - ResourceCloudElement element = (ResourceCloudElement) context - .getNewObject(); - AbstractAddShapeFeature result = null; + /** + * @return + */ + private AbstractAddShapeFeature getIFileFeature(final IAddContext context) { + ResourceCloudElement element = (ResourceCloudElement) context.getNewObject(); + AbstractAddShapeFeature result = null; + + String extension = element.getResource().getFileExtension(); + System.out.println(extension); - String extension = element.getResource().getFileExtension(); - - TDeploymentArtifact deploymentArtifact = ToscaFactory.eINSTANCE - .createTDeploymentArtifact(); - deploymentArtifact.setName(element.getName()); - CreateContext createContext = new CreateContext(); - createContext.setTargetContainer(context.getTargetContainer()); + if (extension.equals( "pub" )) { //$NON-NLS-1$ + // Call the Create User Application Feature to create a deployment artifact for the deployment script and add it to the artifacts list + CreateKeyPairFeature createKPFeature = new CreateKeyPairFeature( new ToscaFeatureProvider(getDiagramTypeProvider()) ); + + TDeploymentArtifact deploymentArtifact = ToscaFactory.eINSTANCE.createTDeploymentArtifact(); + deploymentArtifact.setName( element.getName() ); + deploymentArtifact.setArtifactType( new QName( "KeyPair" ) ); + + createKPFeature.setContextObject( deploymentArtifact ); + + CreateContext createContext = new CreateContext(); + createContext.setTargetContainer( context.getTargetContainer() ); + + if ( createKPFeature.canCreate( createContext )){ + createKPFeature.create( createContext ); + } + + } + + return result; + } + - if (extension.equals("pub")) { //$NON-NLS-1$ - // Call the Create User Application Feature to create a deployment - // artifact for the deployment script and add it to the artifacts - // list - CreateKeyPairFeature createKPFeature = new CreateKeyPairFeature( - new ToscaFeatureProvider(getDiagramTypeProvider())); + // Initializes all create features + @Override + public ICreateFeature[] getCreateFeatures() { + return new ICreateFeature[]{ + new CreateApplicationComponentFeature( this ), + new CreateVMIFeature( this ), + new CreateSoftwareDependencyFeature( this ), + new CreateMonitorProbeFeature( this ), + new CreateServiceTemplateFeature( this ), + new CreateResizeActionFeature( this ), + new CreateUserApplicationFeature( this ), + new CreateGroupFeature( this ), + new CreateKeyPairFeature( this ) + }; + } - deploymentArtifact.setArtifactType(new QName("KeyPair")); + // Custom delete feature for application components and composite components + @Override + public IDeleteFeature getDeleteFeature(IDeleteContext context){ + PictogramElement pictogramElement = context.getPictogramElement(); + Object bo = getBusinessObjectForPictogramElement( pictogramElement ); + if( bo instanceof TServiceTemplate ) { + //TServiceTemplate representing Composite Component + return new DeleteGroupFeature( this ); + } + else if (bo instanceof TNodeTemplate){ + return new DeleteApplicationComponentFeature( this ); + } + else if ( bo instanceof TDeploymentArtifact){ + return new DeleteDeploymentArtifactFeature( this ); + }else if (bo instanceof TArtifactTemplate){ + if (((TArtifactTemplate)bo).getName()!=null && ((TArtifactTemplate)bo).getName().contains( "SD" )) + return new DeleteArtifactTemplateFeature( this ); + } + + return super.getDeleteFeature( context ); + } + + // Enables direct editing + @Override + public IDirectEditingFeature getDirectEditingFeature( final IDirectEditingContext context ) + { + PictogramElement pe = context.getPictogramElement(); + Object bo = getBusinessObjectForPictogramElement( pe ); + if( bo instanceof TNodeTemplate ) { + return new DirectEditApplicationComponentFeature( this ); + } + else if( bo instanceof TServiceTemplate ) { + return new DirectEditCompositeComponentFeature( this ); + } + return super.getDirectEditingFeature( context ); + } - createKPFeature.setContextObject(deploymentArtifact); + // Returns layout features + @Override + public ILayoutFeature getLayoutFeature( final ILayoutContext context ) { + PictogramElement pictogramElement = context.getPictogramElement(); + Object bo = getBusinessObjectForPictogramElement( pictogramElement ); + if( bo instanceof TNodeTemplate ) { + return new LayoutApplicationComponentFeature( this ); + } + if ( bo instanceof TServiceTemplate ){ + return new LayoutServiceTemplateFeature( this ); + } + return super.getLayoutFeature( context ); + } - if (createKPFeature.canCreate(createContext)) { - createKPFeature.create(createContext); - } + // Enables update features + @Override + public IUpdateFeature getUpdateFeature( final IUpdateContext context ) { + PictogramElement pictogramElement = context.getPictogramElement(); + if( pictogramElement instanceof ContainerShape ) { + Object bo = getBusinessObjectForPictogramElement( pictogramElement ); + if( bo instanceof TNodeTemplate ) { + return new UpdateApplicationComponentFeature( this ); + } + else if( bo instanceof TServiceTemplate ) { + return new UpdateCompositeComponentFeature( this ); + } + } + return super.getUpdateFeature( context ); + } - } else if (extension.equals("sh")) { - CreateSoftwareDependencyFeature createSDFeature = new CreateSoftwareDependencyFeature( - new ToscaFeatureProvider(getDiagramTypeProvider())); + // Enables moving of figures + @Override + public IMoveShapeFeature getMoveShapeFeature( final IMoveShapeContext context ) + { + Shape shape = context.getShape(); + Object bo = getBusinessObjectForPictogramElement( shape ); + if( bo instanceof TNodeTemplate ) { + return new MoveApplicationComponentFeature( this ); + } + if ( bo instanceof TServiceTemplate ){ + return new MoveCompositeComponentFeature( this ); + } + return super.getMoveShapeFeature( context ); + } - deploymentArtifact.setName(element.getName()); - deploymentArtifact.setArtifactType(new QName("SD")); - createSDFeature.setContextObject(deploymentArtifact); - + // Feature for renaming application components + @Override + public ICustomFeature[] getCustomFeatures( ICustomContext context ) { + return new ICustomFeature[]{ + new RenameApplicationComponentFeature( this ), + new RenameCompositeComponentFeature( this ), + }; + } - if (createSDFeature.canCreate(createContext)) { - createSDFeature.create(createContext); - } - } - - return result; + // Initializes relationships' create features + @Override + public ICreateConnectionFeature[] getCreateConnectionFeatures() { + return new ICreateConnectionFeature[]{ + new CreateDirectedRelationFeature( this ) +// , +// new CreateBidirectionalRelationFeature( this ) + }; + } + + @Override + public IResizeShapeFeature getResizeShapeFeature(IResizeShapeContext context) { + Shape shape = context.getShape(); + Object bo = getBusinessObjectForPictogramElement(shape); + if (bo instanceof TNodeTemplate) { + return new ResizeApplicationComponentFeature(this); + } + if (bo instanceof TServiceTemplate){ + return new ResizeCompositeComponentFeature(this); + } + return super.getResizeShapeFeature(context); + } } - - - // Initializes all create features - @Override - public ICreateFeature[] getCreateFeatures() { - return new ICreateFeature[]{ - new CreateApplicationComponentFeature( this ), - new CreateVMIFeature( this ), - new CreateNetworkFeature( this ), - new CreateSoftwareDependencyFeature( this ), - new CreateMonitorProbeFeature( this ), - new CreateServiceTemplateFeature( this ), - new CreateResizeActionFeature( this ), - new CreateUserApplicationFeature( this ), - new CreateGroupFeature( this ), - new CreateKeyPairFeature( this ) - }; - } - - // Custom delete feature for application components and composite components - @Override - public IDeleteFeature getDeleteFeature(IDeleteContext context){ - PictogramElement pictogramElement = context.getPictogramElement(); - Object bo = getBusinessObjectForPictogramElement( pictogramElement ); - if( bo instanceof TServiceTemplate ) { - //TServiceTemplate representing Composite Component - return new DeleteGroupFeature( this ); - } - else if (bo instanceof TNodeTemplate){ - return new DeleteApplicationComponentFeature( this ); - } - else if ( bo instanceof TDeploymentArtifact){ - return new DeleteDeploymentArtifactFeature( this ); - } - - return super.getDeleteFeature( context ); - } - - // Enables direct editing - @Override - public IDirectEditingFeature getDirectEditingFeature( final IDirectEditingContext context ) - { - PictogramElement pe = context.getPictogramElement(); - Object bo = getBusinessObjectForPictogramElement( pe ); - if( bo instanceof TNodeTemplate ) { - return new DirectEditApplicationComponentFeature( this ); - } - else if( bo instanceof TServiceTemplate ) { - return new DirectEditCompositeComponentFeature( this ); - } - return super.getDirectEditingFeature( context ); - } - - // Returns layout features - @Override - public ILayoutFeature getLayoutFeature( final ILayoutContext context ) { - PictogramElement pictogramElement = context.getPictogramElement(); - Object bo = getBusinessObjectForPictogramElement( pictogramElement ); - if( bo instanceof TNodeTemplate ) { - return new LayoutApplicationComponentFeature( this ); - } - if ( bo instanceof TServiceTemplate ){ - return new LayoutServiceTemplateFeature( this ); - } - return super.getLayoutFeature( context ); - } - - // Enables update features - @Override - public IUpdateFeature getUpdateFeature( final IUpdateContext context ) { - PictogramElement pictogramElement = context.getPictogramElement(); - if( pictogramElement instanceof ContainerShape ) { - Object bo = getBusinessObjectForPictogramElement( pictogramElement ); - if( bo instanceof TNodeTemplate ) { - return new UpdateApplicationComponentFeature( this ); - } - else if( bo instanceof TServiceTemplate ) { - return new UpdateCompositeComponentFeature( this ); - } - } - return super.getUpdateFeature( context ); - } - - // Enables moving of figures - @Override - public IMoveShapeFeature getMoveShapeFeature( final IMoveShapeContext context ) - { - Shape shape = context.getShape(); - Object bo = getBusinessObjectForPictogramElement( shape ); - if( bo instanceof TNodeTemplate ) { - return new MoveApplicationComponentFeature( this ); - } - if ( bo instanceof TServiceTemplate ){ - return new MoveCompositeComponentFeature( this ); - } - return super.getMoveShapeFeature( context ); - } - - // Feature for renaming application components - @Override - public ICustomFeature[] getCustomFeatures( ICustomContext context ) { - return new ICustomFeature[]{ - new RenameApplicationComponentFeature( this ), - new RenameCompositeComponentFeature( this ), - }; - } - - // Initializes relationships' create features - @Override - public ICreateConnectionFeature[] getCreateConnectionFeatures() { - return new ICreateConnectionFeature[]{ - new CreateDirectedRelationFeature( this ) -// , -// new CreateBidirectionalRelationFeature( this ) - }; - } - - @Override - public IResizeShapeFeature getResizeShapeFeature(IResizeShapeContext context) { - Shape shape = context.getShape(); - Object bo = getBusinessObjectForPictogramElement(shape); - if (bo instanceof TNodeTemplate) { - return new ResizeApplicationComponentFeature(this); - } - if (bo instanceof TServiceTemplate){ - return new ResizeCompositeComponentFeature(this); - } - return super.getResizeShapeFeature(context); - } -}
diff --git a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/diagram/ToscaToolBehaviorProvider.java b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/diagram/ToscaToolBehaviorProvider.java index a18e15c..6d913d4 100644 --- a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/diagram/ToscaToolBehaviorProvider.java +++ b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/diagram/ToscaToolBehaviorProvider.java
@@ -36,6 +36,7 @@ import org.eclipse.camf.infosystem.model.base.VirtualMachineImage; import org.eclipse.camf.infosystem.model.base.VirtualMachineImageType; import org.eclipse.camf.infosystem.model.base.VirtualNetwork; +import org.eclipse.camf.tosca.TArtifactTemplate; import org.eclipse.camf.tosca.TDeploymentArtifact; import org.eclipse.camf.tosca.TNodeTemplate; import org.eclipse.camf.tosca.ToscaFactory; @@ -54,6 +55,7 @@ import org.eclipse.camf.tosca.elasticity.TNodeTemplateExtension; import org.eclipse.camf.tosca.elasticity.TServiceTemplateExtension; import org.eclipse.camf.tosca.elasticity.Tosca_Elasticity_ExtensionsFactory; +import org.eclipse.camf.tosca.elasticity.Tosca_Elasticity_ExtensionsPackage; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; @@ -95,15 +97,25 @@ import org.eclipse.graphiti.tb.IContextMenuEntry; import org.eclipse.graphiti.tb.IDecorator; import org.eclipse.graphiti.tb.ImageDecorator; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; public class ToscaToolBehaviorProvider extends DefaultToolBehaviorProvider { - MockUpInfoSystem mockUpInfoSystemInstance; - + MockUpInfoSystem mockUpInfoSystemInstance; + + private String typesPrefix = Tosca_Elasticity_ExtensionsPackage.eINSTANCE.getNsPrefix(); - public ToscaToolBehaviorProvider( final IDiagramTypeProvider dtp ) { - super( dtp ); - } + private String typesNamespace = Tosca_Elasticity_ExtensionsPackage.eINSTANCE.getNsURI(); + + private String imageType = Tosca_Elasticity_ExtensionsPackage.eINSTANCE.getImageArtifactPropertiesType().getName(); + + private String scriptArtifactType = Tosca_Elasticity_ExtensionsPackage.eINSTANCE.getScriptArtifactPropertiesType().getName(); + + public ToscaToolBehaviorProvider( final IDiagramTypeProvider dtp ) { + super( dtp ); + } @Override public IContextButtonPadData getContextButtonPad( IPictogramElementContext context ) @@ -142,31 +154,31 @@ /** * */ - private void fetchResources() { - Job job = new Job( "Resource Fetching" ) { //$NON-NLS-1$ - - @Override - protected IStatus run( final IProgressMonitor monitor ) { - monitor.beginTask( "Fetching Resources from Cloud Provider", 100 ); - MockUpInfoSystem.getInstance(); - for( int i = 0; i < 5; i++ ) { - try { - // sleep a second - TimeUnit.SECONDS.sleep( 1 ); - monitor.subTask( "Resource bundle #" + i ); - // report that 20 additional units are done - monitor.worked( 20 ); - } catch( InterruptedException e1 ) { - e1.printStackTrace(); - return Status.CANCEL_STATUS; - } - } - System.out.println( "Called save" ); - return Status.OK_STATUS; - } - }; - job.schedule(); - } +// private void fetchResources() { +// Job job = new Job( "Resource Fetching" ) { //$NON-NLS-1$ +// +// @Override +// protected IStatus run( final IProgressMonitor monitor ) { +// monitor.beginTask( "Fetching Resources from Cloud Provider", 100 ); +// MockUpInfoSystem.getInstance(); +// for( int i = 0; i < 5; i++ ) { +// try { +// // sleep a second +// TimeUnit.SECONDS.sleep( 1 ); +// monitor.subTask( "Resource bundle #" + i ); +// // report that 20 additional units are done +// monitor.worked( 20 ); +// } catch( InterruptedException e1 ) { +// e1.printStackTrace(); +// return Status.CANCEL_STATUS; +// } +// } +// System.out.println( "Called save" ); +// return Status.OK_STATUS; +// } +// }; +// job.schedule(); +// } // Creates the Palette. Palette entries are retrieved from an SQL database. @Override @@ -329,6 +341,7 @@ appCompCF.getCreateLargeImageId(), appCompCF ); stackEntry.addCreationToolEntry( objectCreationToolEntry ); + break; } } } @@ -354,6 +367,7 @@ groupCF.getCreateLargeImageId(), groupCF ); stackEntry.addCreationToolEntry( objectCreationToolEntry ); + break; } } } @@ -399,10 +413,14 @@ if( cf instanceof CreateSoftwareDependencyFeature ) { CreateSoftwareDependencyFeature sdCF = ( CreateSoftwareDependencyFeature )cf; - TDeploymentArtifact deploymentArtifact = ToscaFactory.eINSTANCE.createTDeploymentArtifact(); - deploymentArtifact.setName( script.getName() ); - deploymentArtifact.setArtifactType( new QName( "SD" ) ); - sdCF.setContextObject( deploymentArtifact ); + + TArtifactTemplate artifactTemplate = ToscaFactory.eINSTANCE.createTArtifactTemplate(); + artifactTemplate.setName( "SD"+script.getName() ); + artifactTemplate.setId( script.getName() ); + artifactTemplate.setType( new QName( typesNamespace, scriptArtifactType, typesPrefix ) ); + sdCF.setContextObject( artifactTemplate ); + + // add new stack entry to new compartment IToolEntry entry = new ObjectCreationToolEntry( script.getName(), script.getDescription(), @@ -410,6 +428,7 @@ null, sdCF ); compartmentEntry.addToolEntry( entry ); + break; } } } @@ -511,9 +530,6 @@ } } - // Now check the InfoService for additional KeyPairs - keyPairList.addAll( this.mockUpInfoSystemInstance.getKeyPairs() ); - // add new compartment at the end of the existing compartments PaletteCompartmentEntry compartmentEntry = new PaletteCompartmentEntry( "Key Pairs", null ); //$NON-NLS-1$ ret.add( compartmentEntry ); @@ -537,6 +553,7 @@ null, kpCF ); compartmentEntry.addToolEntry( entry ); + break; } } } @@ -596,9 +613,7 @@ /* ... */ } String imageId = out.toString(); - - ///////////////////////////////////////////////////// - + VirtualMachineImage vmi = InfoSystemFactory.eINSTANCE.createVirtualMachineImage(); vmi.setUID( imageId ); vmi.setName( tempResource.getName() ); @@ -629,7 +644,8 @@ TDeploymentArtifact deploymentArtifact = ToscaFactory.eINSTANCE.createTDeploymentArtifact(); deploymentArtifact.setName( vmi.getUID() ); deploymentArtifact.setArtifactRef( new QName(vmi.getUID()) ); - deploymentArtifact.setArtifactType( new QName( "VMI" ) ); + //deploymentArtifact.setArtifactType( new QName( "VMI" ) ); + deploymentArtifact.setArtifactType( new QName( typesNamespace, imageType, typesPrefix )); vmiCF.setContextObject( deploymentArtifact ); ObjectCreationToolEntry objectCreationToolEntry = new ObjectCreationToolEntry( vmi.getUID(), @@ -638,22 +654,158 @@ vmiCF.getCreateLargeImageId(), vmiCF ); stackEntry.addCreationToolEntry( objectCreationToolEntry ); + break; } } - - // add all create-connection-features to the new stack-entry - ICreateConnectionFeature[] createConnectionFeatures = featureProvider.getCreateConnectionFeatures(); - for( ICreateConnectionFeature connFeat : createConnectionFeatures ) { - ConnectionCreationToolEntry connectionCreationToolEntry = new ConnectionCreationToolEntry( vmi.getName(), - connFeat.getName(), - connFeat.getCreateImageId(), - connFeat.getCreateLargeImageId() ); - connectionCreationToolEntry.addCreateConnectionFeature( connFeat ); - stackEntry.addCreationToolEntry( connectionCreationToolEntry ); - } } } +//Create Palette compartment for Monitoring Probes + private void addJCatascopiaMonitorProbeCompartment( List<IPaletteCompartmentEntry> ret ) + { + + ArrayList<MonitoringProbe> mps = this.mockUpInfoSystemInstance.getMonitoringProbes(); + + @SuppressWarnings("unchecked") + ArrayList<MonitoringProbe> mpsCopy = ( ArrayList<MonitoringProbe> )mps.clone(); + + // Add custom probes from project explorer + + IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); + IProject monitoringProbesProject = workspaceRoot.getProject( "MonitoringProbe" ); + + if( monitoringProbesProject.exists() ) { + IFolder srcFolder = monitoringProbesProject.getFolder( "src" ); + IResource[] artifactsResource = null; + try { + artifactsResource = srcFolder.members(); + } catch( CoreException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if ( artifactsResource != null ){ + for( IResource tempResource : artifactsResource ) { + if( tempResource instanceof IFile ) { + MonitoringProbe mp = InfoSystemFactory.eINSTANCE.createMonitoringProbe(); + mp.setUID( tempResource.getName().replaceFirst( ".java", "" )); + mp.setName( tempResource.getName().replaceFirst( ".java", "" )); + mp.setDescription( "" ); + // add new probe to monitoring list + mpsCopy.add( 0, mp ); + } + } + } + } + + // add new compartment at the end of the existing compartments + PaletteCompartmentEntry compartmentEntry = new PaletteCompartmentEntry( "Monitor Probes", null ); //$NON-NLS-1$ + compartmentEntry.setInitiallyOpen( false ); + ret.add( compartmentEntry ); + + for( MonitoringProbe mp : mpsCopy ) { + + String metricsString = mp.getMetrics(); + if ( metricsString.equals( "" ) == false ){ + // add new Metric Probe entry to probes compartment + StackEntry stackEntry = new StackEntry( mp.getName(), mp.getDescription(), null ); + compartmentEntry.addToolEntry( stackEntry ); + compartmentEntry.setInitiallyOpen( false ); + + IFeatureProvider featureProvider = getFeatureProvider(); + ICreateFeature[] createFeatures = featureProvider.getCreateFeatures(); + for( ICreateFeature cf : createFeatures ) { + if( cf instanceof CreateMonitorProbeFeature ) { + CreateMonitorProbeFeature mpCF = ( CreateMonitorProbeFeature )cf; + + TDeploymentArtifact deploymentArtifact = ToscaFactory.eINSTANCE.createTDeploymentArtifact(); + deploymentArtifact.setName( mp.getName() ); + deploymentArtifact.setArtifactType( new QName( "MonitoringProbe" ) ); + mpCF.setContextObject( deploymentArtifact ); + + ObjectCreationToolEntry objectCreationToolEntry = new ObjectCreationToolEntry( mp.getName(), + mp.getDescription(), + mpCF.getCreateImageId(), + mpCF.getCreateLargeImageId(), + mpCF ); + stackEntry.addCreationToolEntry( objectCreationToolEntry ); + break; + } + } + + String metrics = "{\"metrics\":" + metricsString + "}"; + JSONObject obj = null; + JSONArray metrics_array = null; + try { + obj = new JSONObject( metrics ); + metrics_array = obj.getJSONArray( "metrics" ); + } catch( JSONException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } //$NON-NLS-1$ + + for ( int i=0; i < metrics_array.length(); i++){ + String metricLabel = null; + String metricDescription = null; + try { + metricLabel = metrics_array.getJSONObject( i ).getString( "name" ); + metricDescription = metrics_array.getJSONObject( i ).getString( "desc" ); + } catch( JSONException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + // add all create-features to the new stack-entry + featureProvider = getFeatureProvider(); + createFeatures = featureProvider.getCreateFeatures(); + for( ICreateFeature cf : createFeatures ) { + if( cf instanceof CreateMonitorProbeFeature ) { + CreateMonitorProbeFeature mpCF = ( CreateMonitorProbeFeature )cf; + + TDeploymentArtifact deploymentArtifact = ToscaFactory.eINSTANCE.createTDeploymentArtifact(); + deploymentArtifact.setName( metricLabel ); + deploymentArtifact.setArtifactType( new QName( "MonitoringProbe" ) ); + mpCF.setContextObject( deploymentArtifact ); + + ObjectCreationToolEntry objectCreationToolEntry = new ObjectCreationToolEntry( metricLabel, + metricDescription, + mpCF.getCreateImageId(), + mpCF.getCreateLargeImageId(), + mpCF ); + + stackEntry.addCreationToolEntry( objectCreationToolEntry ); + break; + } + } + + } + } + else{ + // Custom Monitoring Probes + // add all create-features to the new stack-entry + IFeatureProvider featureProvider = getFeatureProvider(); + ICreateFeature[] createFeatures = featureProvider.getCreateFeatures(); + for( ICreateFeature cf : createFeatures ) { + if( cf instanceof CreateMonitorProbeFeature ) { + CreateMonitorProbeFeature mpCF = ( CreateMonitorProbeFeature )cf; + + TDeploymentArtifact deploymentArtifact = ToscaFactory.eINSTANCE.createTDeploymentArtifact(); + deploymentArtifact.setName( mp.getName() ); + deploymentArtifact.setArtifactType( new QName( "MonitoringProbe" ) ); + mpCF.setContextObject( deploymentArtifact ); + + // add new stack entry to new compartment + IToolEntry entry = new ObjectCreationToolEntry( mp.getName(), + mp.getDescription(), + null, + null, + mpCF ); + compartmentEntry.addToolEntry( entry ); + + } + } + } + } + } + // Create Palette compartment for Monitoring Probes private void addMonitorProbeCompartment( List<IPaletteCompartmentEntry> ret ) { @@ -721,6 +873,7 @@ mpCF.getCreateLargeImageId(), mpCF ); stackEntry.addCreationToolEntry( objectCreationToolEntry ); + break; } } @@ -746,7 +899,8 @@ mpCF ); stackEntry.addCreationToolEntry( objectCreationToolEntry ); - } + break; + } } } @@ -772,7 +926,7 @@ null, mpCF ); compartmentEntry.addToolEntry( entry ); - + break; } } } @@ -785,6 +939,7 @@ { ArrayList<ResizingAction> ras = this.mockUpInfoSystemInstance.getResizingActions(); + @SuppressWarnings("unchecked") ArrayList<ResizingAction> rasCopy = ( ArrayList<ResizingAction> )ras.clone(); // Add custom images from project explorer IProject activeProject = ToscaDiagramEditor.getActiveProject(); @@ -831,6 +986,7 @@ raCF.getCreateLargeImageId(), raCF ); stackEntry.addCreationToolEntry( objectCreationToolEntry ); + break; } } } @@ -904,7 +1060,12 @@ public GraphicsAlgorithm[] getClickArea( final PictogramElement pe ) { IFeatureProvider featureProvider = getFeatureProvider(); Object bo = featureProvider.getBusinessObjectForPictogramElement( pe ); - if( bo instanceof TNodeTemplate ) { + + if (bo instanceof TNodeTemplate) + if ( ((TNodeTemplate) bo)==null || ((TNodeTemplate) bo).getType() == null) + return null; + + if( bo instanceof TNodeTemplate && ((TNodeTemplate) bo).getType().toString().contains("substituteNode")==false) { GraphicsAlgorithm invisible = pe.getGraphicsAlgorithm(); GraphicsAlgorithm rectangle = invisible.getGraphicsAlgorithmChildren() .get( 0 );
diff --git a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/dialog/ElasticityConditionDialog.java b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/dialog/ElasticityConditionDialog.java index 422996d..e897783 100644 --- a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/dialog/ElasticityConditionDialog.java +++ b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/dialog/ElasticityConditionDialog.java
@@ -68,394 +68,394 @@ public class ElasticityConditionDialog extends Dialog { - private Label lblCondition; - private CCombo cmbCondition; - private boolean conditionSelected; - private Label lblCondition2; - private CCombo cmbCondition2; - private boolean conditionSelected2; - private ToscaModelLayer model; - private String condition; + private Label lblCondition; + private CCombo cmbCondition; + private boolean conditionSelected; + private Label lblCondition2; + private CCombo cmbCondition2; + private boolean conditionSelected2; + private ToscaModelLayer model; + private String condition; - - protected Text typeText; - protected Text valueText; - protected boolean editMode = false; - protected boolean addMode = false; - protected String newType; - protected String elasticityRequirement; - private CCombo cmbGlobalElasticityReq; - private CCombo cmbOperator; - private String component; - private Label unitLabel; - - private String unit; - - private String strategyName; - private Label strategyLabel; - - private String conditionLeft; - private String conditionRight; - private String conditionOperator; - - /** - * @param parentShell - * @param pe - * @param existingDataStage - */ - public ElasticityConditionDialog( final Shell parentShell, String component, - ToscaModelLayer model, String strategyName - ) - { - super( parentShell ); - this.conditionSelected = false; - this.conditionSelected2 = false; - this.model = model; - this.component = component; - this.strategyName = strategyName; - } - - @Override - protected void configureShell( final Shell shell ) { - super.configureShell( shell ); - shell.setText( "Apply Strategy Under Condition" ); - shell.setSize( 330, 400 ); - - } - - @Override - protected Control createDialogArea( final Composite parent ) { - Composite composite = ( Composite )super.createDialogArea( parent ); - composite.setLayout( new GridLayout( 1, false ) ); - composite.setLayoutData( new GridData( GridData.FILL_BOTH ) ); - - this.strategyLabel = new Label( composite, SWT.NONE ); - this.strategyLabel.setText( this.strategyName ); - - GridData gd = new GridData( GridData.FILL_BOTH ); - gd.verticalIndent = 7; - gd.heightHint = 10; - this.strategyLabel.setLayoutData( gd ); - - - - //////////////////////////////////////////////////////////////////////////////////////////////// - - Group newConstraintGroup = new Group( composite, SWT.NONE ); - newConstraintGroup.setLayout( new GridLayout( 1, false ) ); - newConstraintGroup.setText( "&Specify New Condition" ); - GridData gData = new GridData( SWT.FILL, SWT.FILL, true, true ); - newConstraintGroup.setLayoutData( gData ); - - - - Composite newConstraintComposite = new Composite( newConstraintGroup, SWT.NONE ); - newConstraintComposite.setLayout( new GridLayout( 1, false ) ); - //GridLayout gLayout = new GridLayout( 2, false ); - newConstraintComposite.setLayout( new GridLayout( 1, false ) ); - gData = new GridData( GridData.FILL_BOTH ); - //gData.grabExcessHorizontalSpace = true; - //gData.grabExcessVerticalSpace = true; - newConstraintComposite.setLayoutData( gData ); - - Composite typeComposite = new Composite( newConstraintComposite, SWT.NONE ); - GridLayout gLayout = new GridLayout( 2, false ); - typeComposite.setLayout( gLayout ); - gData = new GridData( GridData.FILL_HORIZONTAL ); - typeComposite.setLayoutData( gData ); - - Label typeLabel = new Label( typeComposite, SWT.LEAD ); - typeLabel.setText( "Type" ); //$NON-NLS-1$ - gd = new GridData( 50, 20 ); - typeLabel.setLayoutData( gd ); - // Combo - GlobalElasticityReq - this.cmbGlobalElasticityReq = new CCombo( typeComposite, SWT.BORDER ); - this.cmbGlobalElasticityReq.setEnabled( true ); - gd = new GridData( 212, 20 ); - this.cmbGlobalElasticityReq.setLayoutData( gd ); - - ArrayList<MonitoringProbe> mps = getMetrics(); - for (MonitoringProbe mp : mps){ - String metricsString = mp.getDescription(); - if (metricsString.equals( "" )==false){ - metricsString = metricsString.substring( 2, metricsString.length()-2 ); - metricsString = metricsString.replace( "\"", "" ); - String[] metrics = metricsString.split( "," ); - for (String metric : metrics) - this.cmbGlobalElasticityReq.add(metric); - } - else{ - this.cmbGlobalElasticityReq.add(mp.getName()); - } - } - - Composite valueComposite = new Composite( newConstraintComposite, SWT.NONE ); - gLayout = new GridLayout( 3, false ); - valueComposite.setLayout( gLayout ); - gData = new GridData( GridData.FILL_HORIZONTAL ); - valueComposite.setLayoutData( gData ); - - Label valueLabel = new Label( valueComposite, SWT.LEAD ); - valueLabel.setText( "Value" ); //$NON-NLS-1$ - gd = new GridData( 50, 20 ); - valueLabel.setLayoutData( gd ); - - // Combo - Operator - this.cmbOperator = new CCombo( valueComposite, SWT.BORDER ); - this.cmbOperator.setEnabled( true ); - gd = new GridData( 40, 20 ); - this.cmbOperator.setLayoutData( gd ); - this.cmbOperator.add( "=" ); //$NON-NLS-1$ - this.cmbOperator.add( "<" ); //$NON-NLS-1$ - this.cmbOperator.add( ">" ); //$NON-NLS-1$ - this.cmbOperator.setText( this.cmbOperator.getItem( 0 ) ); - - this.valueText = new Text( valueComposite, SWT.BORDER ); - gd = new GridData( 154, 20 ); - this.valueText.setLayoutData( gd ); - - this.cmbGlobalElasticityReq.setEditable( false ); - this.cmbGlobalElasticityReq.addModifyListener( new ModifyListener() { - - public void modifyText( final ModifyEvent e ) { - - ElasticityConditionDialog.this.cmbCondition.setEnabled( true ); - ElasticityConditionDialog.this.cmbCondition2.setEnabled( true ); - - ElasticityConditionDialog.this.newType = ElasticityConditionDialog.this.cmbGlobalElasticityReq.getText(); - - - } - } ); - - ////////////////////////////////////////////////////////////////////////////////////////////////////////////// - Group constraintGroup = new Group( composite, SWT.NONE ); - constraintGroup.setLayout( new GridLayout( 1, false ) ); - constraintGroup.setText( "&Select Constraint" ); - gData = new GridData( SWT.FILL, SWT.FILL, true, true ); - constraintGroup.setLayoutData( gData ); - - Composite constraintComposite = new Composite( constraintGroup, SWT.NONE ); - constraintComposite.setLayout( new GridLayout( 1, false ) ); - gData = new GridData( GridData.GRAB_HORIZONTAL ); - //gData.grabExcessHorizontalSpace = true; - //gData.grabExcessVerticalSpace = true; - constraintComposite.setLayoutData( gData ); - - - // Condition label - this.lblCondition = new Label( constraintComposite, SWT.NONE ); - this.lblCondition.setText( "When fulfilled Constraint:" ); - gd = new GridData( GridData.FILL_HORIZONTAL ); - gd.widthHint = 280; - this.lblCondition.setLayoutData( gd ); - - // Combo - Condition - this.cmbCondition = new CCombo( constraintComposite, SWT.BORDER ); - this.cmbCondition.setEnabled( true ); - gd = new GridData( GridData.FILL_HORIZONTAL ); - gd.widthHint = 280; - this.cmbCondition.setLayoutData( gd ); - this.cmbCondition.setEnabled( false ); - - - ArrayList<String> elasticityConstraints = getAllConstraints(); - - if ( elasticityConstraints.size() > 0 ){ - for ( String constraint : elasticityConstraints ){ - this.cmbCondition.add(constraint); - } - } - - this.cmbCondition.setText( "" ); - - this.cmbCondition.addModifyListener( new ModifyListener() { - - @Override - public void modifyText( ModifyEvent e ) { - if (ElasticityConditionDialog.this.cmbCondition.getText() != ""){ - ElasticityConditionDialog.this.conditionSelected = true; - } - - } - - }); - - // Condition label - this.lblCondition2 = new Label( constraintComposite, SWT.NONE ); - this.lblCondition2.setText( "When violated Constraint:" ); - gd = new GridData( GridData.FILL_HORIZONTAL ); - gd.widthHint = 280; - this.lblCondition2.setLayoutData( gd ); - - // Combo - Condition - this.cmbCondition2 = new CCombo( constraintComposite, SWT.BORDER ); - this.cmbCondition2.setEnabled( true ); - gd.widthHint = 280; - gd = new GridData( GridData.FILL_HORIZONTAL ); - this.cmbCondition2.setLayoutData( gd ); - - if ( elasticityConstraints.size() > 0 ){ - for ( String constraint : elasticityConstraints ){ - this.cmbCondition2.add(constraint); - } - } - - this.cmbCondition2.setText( "" ); - - this.cmbCondition2.addModifyListener( new ModifyListener() { - - @Override - public void modifyText( ModifyEvent e ) { - if (ElasticityConditionDialog.this.cmbCondition2.getText() != ""){ - ElasticityConditionDialog.this.conditionSelected2 = true; - } - - } - - }); - - return composite; - } - - public ArrayList<MonitoringProbe> getMetrics(){ - - ArrayList<MonitoringProbe> mps = MockUpInfoSystem.getInstance() - .getMonitoringProbes(); - - ArrayList<MonitoringProbe> mpsCopy = ( ArrayList<MonitoringProbe> )mps.clone(); - - IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); - IProject monitoringProbesProject = workspaceRoot.getProject( "MonitoringProbe" ); - - if( monitoringProbesProject.exists() ) { - IFolder srcFolder = monitoringProbesProject.getFolder( "src" ); - IResource[] artifactsResource = null; - try { - artifactsResource = srcFolder.members(); - } catch( CoreException e ) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - for( IResource tempResource : artifactsResource ) { - if( tempResource instanceof IFile ) { - MonitoringProbe mp = InfoSystemFactory.eINSTANCE.createMonitoringProbe(); - mp.setUID( tempResource.getName().replaceFirst( ".java", "" )); - mp.setName( tempResource.getName().replaceFirst( ".java", "" )); - mp.setDescription( "" ); - mp.setURL( "" ); - // add new probe to monitoring list - mpsCopy.add( 0, mp ); - } - } - } - - return mpsCopy; - } - - // Returns all global, composite and component level elasticity constraints; - private ArrayList<String> getAllConstraints(){ - ArrayList<String> constraints = new ArrayList<String>(); + protected Text typeText; + protected Text valueText; + protected boolean editMode = false; + protected boolean addMode = false; + protected String newType; + protected String elasticityRequirement; + private CCombo cmbGlobalElasticityReq; + private CCombo cmbOperator; + private String component; + private Label unitLabel; + + private String unit; + + private String strategyName; + private Label strategyLabel; - DocumentRoot toscaRoot = this.model.getDocumentRoot(); - EList<TServiceTemplate> toscaServiceTemplates = toscaRoot.getDefinitions().getServiceTemplate(); - EList<TNodeTemplate> tempNodeTemplates; - for ( TServiceTemplate tempServiceTemplate : toscaServiceTemplates ){ - - //TBoundaryDefinitionsExtension boundaryDef = ( TBoundaryDefinitionsExtension ) tempServiceTemplate.getBoundaryDefinitions(); - - TBoundaryDefinitions boundaryDef = ( TBoundaryDefinitions ) tempServiceTemplate.getBoundaryDefinitions(); + private String conditionLeft; + private String conditionRight; + private String conditionOperator; + + /** + * @param parentShell + * @param pe + * @param existingDataStage + */ + public ElasticityConditionDialog( final Shell parentShell, String component, + ToscaModelLayer model, String strategyName + ) + { + super( parentShell ); + this.conditionSelected = false; + this.conditionSelected2 = false; + this.model = model; + this.component = component; + this.strategyName = strategyName; + } + + @Override + protected void configureShell( final Shell shell ) { + super.configureShell( shell ); + shell.setText( "Apply Strategy Under Condition" ); + shell.setSize( 330, 400 ); + + } + + @Override + protected Control createDialogArea( final Composite parent ) { + Composite composite = ( Composite )super.createDialogArea( parent ); + composite.setLayout( new GridLayout( 1, false ) ); + composite.setLayoutData( new GridData( GridData.FILL_BOTH ) ); + + this.strategyLabel = new Label( composite, SWT.NONE ); + this.strategyLabel.setText( this.strategyName ); - if ( boundaryDef != null ){ - - PoliciesType1 globalPolicies = boundaryDef.getPolicies(); - - if ( globalPolicies != null ){ - - for ( int k=0; k<globalPolicies.getPolicy().size(); k++){ - - if ( globalPolicies.getPolicy().get(k).getPolicyType().toString().contains( "Constraint" ) ){ - constraints.add(globalPolicies.getPolicy().get(k).getName()); - } - } + GridData gd = new GridData( GridData.FILL_BOTH ); + gd.verticalIndent = 7; + gd.heightHint = 10; + this.strategyLabel.setLayoutData( gd ); + - } - } + + //////////////////////////////////////////////////////////////////////////////////////////////// + + Group newConstraintGroup = new Group( composite, SWT.NONE ); + newConstraintGroup.setLayout( new GridLayout( 1, false ) ); + newConstraintGroup.setText( "&Specify New Condition" ); + GridData gData = new GridData( SWT.FILL, SWT.FILL, true, true ); + newConstraintGroup.setLayoutData( gData ); + + + + Composite newConstraintComposite = new Composite( newConstraintGroup, SWT.NONE ); + newConstraintComposite.setLayout( new GridLayout( 1, false ) ); + //GridLayout gLayout = new GridLayout( 2, false ); + newConstraintComposite.setLayout( new GridLayout( 1, false ) ); + gData = new GridData( GridData.FILL_BOTH ); + //gData.grabExcessHorizontalSpace = true; + //gData.grabExcessVerticalSpace = true; + newConstraintComposite.setLayoutData( gData ); + + Composite typeComposite = new Composite( newConstraintComposite, SWT.NONE ); + GridLayout gLayout = new GridLayout( 2, false ); + typeComposite.setLayout( gLayout ); + gData = new GridData( GridData.FILL_HORIZONTAL ); + typeComposite.setLayoutData( gData ); + + Label typeLabel = new Label( typeComposite, SWT.LEAD ); + typeLabel.setText( "Type" ); //$NON-NLS-1$ + gd = new GridData( 50, 20 ); + typeLabel.setLayoutData( gd ); + // Combo - GlobalElasticityReq + this.cmbGlobalElasticityReq = new CCombo( typeComposite, SWT.BORDER ); + this.cmbGlobalElasticityReq.setEnabled( true ); + gd = new GridData( 212, 20 ); + this.cmbGlobalElasticityReq.setLayoutData( gd ); + + ArrayList<MonitoringProbe> mps = getMetrics(); + for (MonitoringProbe mp : mps){ + String metricsString = mp.getDescription(); + if (metricsString.equals( "" )==false){ + metricsString = metricsString.substring( 2, metricsString.length()-2 ); + metricsString = metricsString.replace( "\"", "" ); + String[] metrics = metricsString.split( "," ); + for (String metric : metrics) + this.cmbGlobalElasticityReq.add(metric); + } + else{ + this.cmbGlobalElasticityReq.add(mp.getName()); + } + } + this.cmbGlobalElasticityReq.add("Cost"); + + Composite valueComposite = new Composite( newConstraintComposite, SWT.NONE ); + gLayout = new GridLayout( 3, false ); + valueComposite.setLayout( gLayout ); + gData = new GridData( GridData.FILL_HORIZONTAL ); + valueComposite.setLayoutData( gData ); + + Label valueLabel = new Label( valueComposite, SWT.LEAD ); + valueLabel.setText( "Value" ); //$NON-NLS-1$ + gd = new GridData( 50, 20 ); + valueLabel.setLayoutData( gd ); + + // Combo - Operator + this.cmbOperator = new CCombo( valueComposite, SWT.BORDER ); + this.cmbOperator.setEnabled( true ); + gd = new GridData( 40, 20 ); + this.cmbOperator.setLayoutData( gd ); + this.cmbOperator.add( "=" ); //$NON-NLS-1$ + this.cmbOperator.add( "<" ); //$NON-NLS-1$ + this.cmbOperator.add( ">" ); //$NON-NLS-1$ + this.cmbOperator.setText( this.cmbOperator.getItem( 0 ) ); + + this.valueText = new Text( valueComposite, SWT.BORDER ); + gd = new GridData( 154, 20 ); + this.valueText.setLayoutData( gd ); + + this.cmbGlobalElasticityReq.setEditable( false ); + this.cmbGlobalElasticityReq.addModifyListener( new ModifyListener() { + + public void modifyText( final ModifyEvent e ) { + + ElasticityConditionDialog.this.cmbCondition.setEnabled( true ); + ElasticityConditionDialog.this.cmbCondition2.setEnabled( true ); + + ElasticityConditionDialog.this.newType = ElasticityConditionDialog.this.cmbGlobalElasticityReq.getText(); + + + } + } ); + + ////////////////////////////////////////////////////////////////////////////////////////////////////////////// + Group constraintGroup = new Group( composite, SWT.NONE ); + constraintGroup.setLayout( new GridLayout( 1, false ) ); + constraintGroup.setText( "&Select Constraint" ); + gData = new GridData( SWT.FILL, SWT.FILL, true, true ); + constraintGroup.setLayoutData( gData ); + + Composite constraintComposite = new Composite( constraintGroup, SWT.NONE ); + constraintComposite.setLayout( new GridLayout( 1, false ) ); + gData = new GridData( GridData.GRAB_HORIZONTAL ); + //gData.grabExcessHorizontalSpace = true; + //gData.grabExcessVerticalSpace = true; + constraintComposite.setLayoutData( gData ); + + + // Condition label + this.lblCondition = new Label( constraintComposite, SWT.NONE ); + this.lblCondition.setText( "When fulfilled Constraint:" ); + gd = new GridData( GridData.FILL_HORIZONTAL ); + gd.widthHint = 280; + this.lblCondition.setLayoutData( gd ); + + // Combo - Condition + this.cmbCondition = new CCombo( constraintComposite, SWT.BORDER ); + this.cmbCondition.setEnabled( true ); + gd = new GridData( GridData.FILL_HORIZONTAL ); + gd.widthHint = 280; + this.cmbCondition.setLayoutData( gd ); + this.cmbCondition.setEnabled( false ); + + + ArrayList<String> elasticityConstraints = getAllConstraints(); + + if ( elasticityConstraints.size() > 0 ){ + for ( String constraint : elasticityConstraints ){ + this.cmbCondition.add(constraint); + } + } + + this.cmbCondition.setText( "" ); + + this.cmbCondition.addModifyListener( new ModifyListener() { + + @Override + public void modifyText( ModifyEvent e ) { + if (ElasticityConditionDialog.this.cmbCondition.getText() != ""){ + ElasticityConditionDialog.this.conditionSelected = true; + } + + } + + }); + + // Condition label + this.lblCondition2 = new Label( constraintComposite, SWT.NONE ); + this.lblCondition2.setText( "When violated Constraint:" ); + gd = new GridData( GridData.FILL_HORIZONTAL ); + gd.widthHint = 280; + this.lblCondition2.setLayoutData( gd ); + + // Combo - Condition + this.cmbCondition2 = new CCombo( constraintComposite, SWT.BORDER ); + this.cmbCondition2.setEnabled( true ); + gd.widthHint = 280; + gd = new GridData( GridData.FILL_HORIZONTAL ); + this.cmbCondition2.setLayoutData( gd ); + + if ( elasticityConstraints.size() > 0 ){ + for ( String constraint : elasticityConstraints ){ + this.cmbCondition2.add(constraint); + } + } + + this.cmbCondition2.setText( "" ); + + this.cmbCondition2.addModifyListener( new ModifyListener() { + + @Override + public void modifyText( ModifyEvent e ) { + if (ElasticityConditionDialog.this.cmbCondition2.getText() != ""){ + ElasticityConditionDialog.this.conditionSelected2 = true; + } + + } + + }); + + return composite; + } + + public ArrayList<MonitoringProbe> getMetrics(){ + + ArrayList<MonitoringProbe> mps = MockUpInfoSystem.getInstance() + .getMonitoringProbes(); + + ArrayList<MonitoringProbe> mpsCopy = ( ArrayList<MonitoringProbe> )mps.clone(); + + IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); + IProject monitoringProbesProject = workspaceRoot.getProject( "MonitoringProbe" ); + + if( monitoringProbesProject.exists() ) { + IFolder srcFolder = monitoringProbesProject.getFolder( "src" ); + IResource[] artifactsResource = null; + try { + artifactsResource = srcFolder.members(); + } catch( CoreException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + for( IResource tempResource : artifactsResource ) { + if( tempResource instanceof IFile ) { + MonitoringProbe mp = InfoSystemFactory.eINSTANCE.createMonitoringProbe(); + mp.setUID( tempResource.getName().replaceFirst( ".java", "" )); + mp.setName( tempResource.getName().replaceFirst( ".java", "" )); + mp.setDescription( "" ); + // add new probe to monitoring list + mpsCopy.add( 0, mp ); + } + } + } + + return mpsCopy; + } + + // Returns all global, composite and component level elasticity constraints; + private ArrayList<String> getAllConstraints(){ - if ( tempServiceTemplate.getTopologyTemplate() != null && tempServiceTemplate.getTopologyTemplate().getNodeTemplate() != null ){ + ArrayList<String> constraints = new ArrayList<String>(); + + DocumentRoot toscaRoot = this.model.getDocumentRoot(); + EList<TServiceTemplate> toscaServiceTemplates = toscaRoot.getDefinitions().getServiceTemplate(); + EList<TNodeTemplate> tempNodeTemplates; + for ( TServiceTemplate tempServiceTemplate : toscaServiceTemplates ){ - tempNodeTemplates = tempServiceTemplate.getTopologyTemplate().getNodeTemplate(); - - for ( final TNodeTemplate tempNodeTemplate : tempNodeTemplates ){ + //TBoundaryDefinitionsExtension boundaryDef = ( TBoundaryDefinitionsExtension ) tempServiceTemplate.getBoundaryDefinitions(); + + TBoundaryDefinitions boundaryDef = ( TBoundaryDefinitions ) tempServiceTemplate.getBoundaryDefinitions(); + + if ( boundaryDef != null ){ + + PoliciesType1 globalPolicies = boundaryDef.getPolicies(); - if ( tempNodeTemplate.getPolicies() != null && tempNodeTemplate.getPolicies().getPolicy() != null ){ - for ( int j=0; j<tempNodeTemplate.getPolicies().getPolicy().size(); j++){ - - if (tempNodeTemplate.getPolicies().getPolicy().get(j).getPolicyType().toString().contains( "Constraint" ) ){ - constraints.add(tempNodeTemplate.getPolicies().getPolicy().get(j).getName()); + if ( globalPolicies != null ){ + + for ( int k=0; k<globalPolicies.getPolicy().size(); k++){ + + if ( globalPolicies.getPolicy().get(k).getPolicyType().toString().contains( "Constraint" ) ){ + constraints.add(globalPolicies.getPolicy().get(k).getName()); + } + } + + } + } + + if ( tempServiceTemplate.getTopologyTemplate() != null && tempServiceTemplate.getTopologyTemplate().getNodeTemplate() != null ){ + + tempNodeTemplates = tempServiceTemplate.getTopologyTemplate().getNodeTemplate(); + + for ( final TNodeTemplate tempNodeTemplate : tempNodeTemplates ){ + + if ( tempNodeTemplate.getPolicies() != null && tempNodeTemplate.getPolicies().getPolicy() != null ){ + for ( int j=0; j<tempNodeTemplate.getPolicies().getPolicy().size(); j++){ + + if (tempNodeTemplate.getPolicies().getPolicy().get(j).getPolicyType().toString().contains( "Constraint" ) ){ + constraints.add(tempNodeTemplate.getPolicies().getPolicy().get(j).getName()); + } } } } + + } - } + + return constraints; } + - return constraints; + /** + * Access to the List of Data Stage-In elements. + * + * @return DataStage-In list set by the user. + */ + public String getSelectedCondition() { + return ElasticityConditionDialog.this.condition; + } + + public ConditionType getSYBLCondition() { + + ConditionType strategyCondition = SyblFactory.eINSTANCE.createConditionType(); + BinaryRestriction br = SyblFactory.eINSTANCE.createBinaryRestriction(); + br.setType( this.conditionOperator ); + LeftHandSideType conditionLeft = SyblFactory.eINSTANCE.createLeftHandSideType(); + conditionLeft.setMetric( this.conditionLeft ); + br.setLeftHandSide( conditionLeft ); + RightHandSideType conditionRight = SyblFactory.eINSTANCE.createRightHandSideType(); + conditionRight.setNumber( this.conditionRight ); + br.setRightHandSide( conditionRight ); + UnaryRestriction ur = SyblFactory.eINSTANCE.createUnaryRestriction(); + ur.setType( "hi4" ); + strategyCondition.getBinaryRestrictionsConjunction().add( br ); + strategyCondition.getUnaryRestrictionsConjunction().add( ur ); + + return strategyCondition; - } + } - - /** - * Access to the List of Data Stage-In elements. - * - * @return DataStage-In list set by the user. - */ - public String getSelectedCondition() { - return ElasticityConditionDialog.this.condition; - } - - public ConditionType getSYBLCondition() { - - ConditionType strategyCondition = SyblFactory.eINSTANCE.createConditionType(); - BinaryRestriction br = SyblFactory.eINSTANCE.createBinaryRestriction(); - br.setType( this.conditionOperator ); - LeftHandSideType conditionLeft = SyblFactory.eINSTANCE.createLeftHandSideType(); - conditionLeft.setMetric( this.conditionLeft ); - br.setLeftHandSide( conditionLeft ); - RightHandSideType conditionRight = SyblFactory.eINSTANCE.createRightHandSideType(); - conditionRight.setNumber( this.conditionRight ); - br.setRightHandSide( conditionRight ); - UnaryRestriction ur = SyblFactory.eINSTANCE.createUnaryRestriction(); - ur.setType( "hi4" ); - strategyCondition.getBinaryRestrictionsConjunction().add( br ); - strategyCondition.getUnaryRestrictionsConjunction().add( ur ); - - return strategyCondition; - - } - - @SuppressWarnings("boxing") - @Override - protected void okPressed() { - - ElasticityConditionDialog.this.conditionLeft = this.cmbGlobalElasticityReq.getText(); - ElasticityConditionDialog.this.conditionRight = this.valueText.getText(); - ElasticityConditionDialog.this.conditionOperator = this.cmbOperator.getText(); - if ( this.conditionSelected ){ - ElasticityConditionDialog.this.condition = "CASE fulfilled(" + this.cmbCondition.getText().split( ":" )[0] + "):"; - } - else if ( this.conditionSelected2 ){ - ElasticityConditionDialog.this.condition = "CASE violated(" + this.cmbCondition2.getText().split( ":" )[0] + "):"; - } - else { - ElasticityConditionDialog.this.condition = "CASE " + this.cmbGlobalElasticityReq.getText() + this.cmbOperator.getText() + this.valueText.getText(); - } - - super.okPressed(); - } -} + @SuppressWarnings("boxing") + @Override + protected void okPressed() { + + ElasticityConditionDialog.this.conditionLeft = this.cmbGlobalElasticityReq.getText(); + ElasticityConditionDialog.this.conditionRight = this.valueText.getText(); + ElasticityConditionDialog.this.conditionOperator = this.cmbOperator.getText(); + if ( this.conditionSelected ){ + ElasticityConditionDialog.this.condition = "CASE fulfilled(" + this.cmbCondition.getText().split( ":" )[0] + "):"; + } + else if ( this.conditionSelected2 ){ + ElasticityConditionDialog.this.condition = "CASE violated(" + this.cmbCondition2.getText().split( ":" )[0] + "):"; + } + else { + ElasticityConditionDialog.this.condition = "CASE " + this.cmbGlobalElasticityReq.getText() + this.cmbOperator.getText() + this.valueText.getText(); + } + + super.okPressed(); + } + }
diff --git a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/dialog/ElasticityConstraintDialog.java b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/dialog/ElasticityConstraintDialog.java index fc252ef..b808e32 100644 --- a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/dialog/ElasticityConstraintDialog.java +++ b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/dialog/ElasticityConstraintDialog.java
@@ -52,19 +52,14 @@ public class ElasticityConstraintDialog extends Dialog { - protected Text typeText; - protected Text valueText; - protected boolean editMode = false; - protected boolean addMode = false; - protected String newType; - protected String elasticityRequirement; - private CCombo cmbGlobalElasticityReq; - private CCombo cmbOperator; - private String component; - private String constraintLeft; - private String constraintRight; - private String constraintOperator; - + protected Text typeText; + protected Text valueText; + protected boolean editMode = false; + protected boolean addMode = false; + protected String newType; + protected String elasticityRequirement; + private CCombo cmbGlobalElasticityReq; + private CCombo cmbOperator; /** * @param parentShell @@ -74,7 +69,6 @@ super( parentShell ); this.elasticityRequirement = null; this.addMode = true; - this.component = component; } @Override @@ -101,33 +95,28 @@ this.cmbGlobalElasticityReq.setEnabled( true ); gd = new GridData( 212, 20 ); this.cmbGlobalElasticityReq.setLayoutData( gd ); - ArrayList<MonitoringProbe> mps = getMetrics(); - - for (MonitoringProbe mp : mps){ + for( MonitoringProbe mp : mps ) { String metricsString = mp.getDescription(); - if (metricsString.equals( "" )==false){ - metricsString = metricsString.substring( 2, metricsString.length()-2 ); + if( metricsString.equals( "" ) == false ) { + metricsString = metricsString.substring( 2, metricsString.length() - 2 ); metricsString = metricsString.replace( "\"", "" ); - String[] metrics = metricsString.split( "," ); - for (String metric : metrics) - this.cmbGlobalElasticityReq.add(metric); - } - else{ - this.cmbGlobalElasticityReq.add(mp.getName()); + String[] metrics = metricsString.split( "," ); + for( String metric : metrics ) + this.cmbGlobalElasticityReq.add( metric ); + } else { + this.cmbGlobalElasticityReq.add( mp.getName() ); } } this.cmbGlobalElasticityReq.add( "CostPerHour ($)" ); - + this.cmbGlobalElasticityReq.add( "Response Time" ); Composite valueComposite = new Composite( composite, SWT.NONE ); gLayout = new GridLayout( 3, false ); valueComposite.setLayout( gLayout ); - Label valueLabel = new Label( valueComposite, SWT.LEAD ); valueLabel.setText( "Value" ); //$NON-NLS-1$ gd = new GridData( 50, 20 ); valueLabel.setLayoutData( gd ); - // Combo - Operator this.cmbOperator = new CCombo( valueComposite, SWT.BORDER ); this.cmbOperator.setEnabled( true ); @@ -135,92 +124,55 @@ this.cmbOperator.setLayoutData( gd ); this.cmbOperator.add( "=" ); //$NON-NLS-1$ this.cmbOperator.add( "<" ); //$NON-NLS-1$ - this.cmbOperator.add( ">" ); //$NON-NLS-1$ - this.cmbOperator.setText( this.cmbOperator.getItem( 0 ) ); - + this.cmbOperator.add( ">" ); //$NON-NLS-1$ + this.cmbOperator.setText( this.cmbOperator.getItem( 0 ) ); this.valueText = new Text( valueComposite, SWT.BORDER ); gd = new GridData( 154, 20 ); - this.valueText.setLayoutData( gd ); - + this.valueText.setLayoutData( gd ); return composite; } - public ArrayList<MonitoringProbe> getMetrics(){ - - ArrayList<MonitoringProbe> mps = MockUpInfoSystem.getInstance() - .getMonitoringProbes(); - - ArrayList<MonitoringProbe> mpsCopy = ( ArrayList<MonitoringProbe> )mps.clone(); - - IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); - IProject monitoringProbesProject = workspaceRoot.getProject( "MonitoringProbe" ); + public ArrayList<MonitoringProbe> getMetrics() { + ArrayList<MonitoringProbe> mps = MockUpInfoSystem.getInstance() + .getMonitoringProbes(); + @SuppressWarnings("unchecked") + ArrayList<MonitoringProbe> mpsCopy = ( ArrayList<MonitoringProbe> )mps.clone(); + IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); + IProject monitoringProbesProject = workspaceRoot.getProject( "MonitoringProbe" ); + if( monitoringProbesProject.exists() ) { + IFolder srcFolder = monitoringProbesProject.getFolder( "src" ); + IResource[] artifactsResource = null; + try { + artifactsResource = srcFolder.members(); + } catch( CoreException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + for( IResource tempResource : artifactsResource ) { + if( tempResource instanceof IFile ) { + MonitoringProbe mp = InfoSystemFactory.eINSTANCE.createMonitoringProbe(); + mp.setUID( tempResource.getName().replaceFirst( ".java", "" ) ); + mp.setName( tempResource.getName().replaceFirst( ".java", "" ) ); + mp.setDescription( "" ); + // add new probe to monitoring list + mpsCopy.add( 0, mp ); + } + } + } + return mpsCopy; + } - if( monitoringProbesProject.exists() ) { - IFolder srcFolder = monitoringProbesProject.getFolder( "src" ); - IResource[] artifactsResource = null; - try { - artifactsResource = srcFolder.members(); - } catch( CoreException e ) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - for( IResource tempResource : artifactsResource ) { - if( tempResource instanceof IFile ) { - MonitoringProbe mp = InfoSystemFactory.eINSTANCE.createMonitoringProbe(); - mp.setUID( tempResource.getName().replaceFirst( ".java", "" )); - mp.setName( tempResource.getName().replaceFirst( ".java", "" )); - mp.setDescription( "" ); - mp.setURL( "" ); - // add new probe to monitoring list - mpsCopy.add( 0, mp ); - } - } - } - - return mpsCopy; - } - - public String getElasticityConstraint() { - return ElasticityConstraintDialog.this.elasticityRequirement; - } - - public SyblElasticityRequirementsDescription getSYBLConstraint(){ + public String getElasticityConstraint() { + return ElasticityConstraintDialog.this.elasticityRequirement; + } - SyblElasticityRequirementsDescription serd = SyblFactory.eINSTANCE.createSyblElasticityRequirementsDescription(); - - Constraint propertiesConstraint = SyblFactory.eINSTANCE.createConstraint(); - ToEnforceType1 constraintToEnforce = SyblFactory.eINSTANCE.createToEnforceType1(); - propertiesConstraint.setId( "hi" ); - propertiesConstraint.setToEnforce( constraintToEnforce ); - - BinaryRestriction br = SyblFactory.eINSTANCE.createBinaryRestriction(); - br.setType( this.constraintOperator ); - LeftHandSideType constraintLeft = SyblFactory.eINSTANCE.createLeftHandSideType(); - constraintLeft.setMetric( this.constraintLeft ); - br.setLeftHandSide( constraintLeft ); - RightHandSideType constraintRight = SyblFactory.eINSTANCE.createRightHandSideType(); - constraintRight.setNumber( this.constraintRight ); - br.setRightHandSide( constraintRight ); - constraintToEnforce.getBinaryRestrictionsConjunction().add( br ); - - SYBLSpecificationType sst = SyblFactory.eINSTANCE.createSYBLSpecificationType(); - sst.getConstraint().add( propertiesConstraint ); - serd.getSYBLSpecification().add( sst ); - - return serd; - } - - @SuppressWarnings("boxing") - @Override - protected void okPressed() { - - ElasticityConstraintDialog.this.constraintLeft = this.cmbGlobalElasticityReq.getText(); - ElasticityConstraintDialog.this.constraintRight = this.valueText.getText(); - ElasticityConstraintDialog.this.constraintOperator = this.cmbOperator.getText(); - - ElasticityConstraintDialog.this.elasticityRequirement = this.cmbGlobalElasticityReq.getText() + this.cmbOperator.getText() + this.valueText.getText(); - - super.okPressed(); - } + @SuppressWarnings("boxing") + @Override + protected void okPressed() { + ElasticityConstraintDialog.this.elasticityRequirement = this.cmbGlobalElasticityReq.getText() + + this.cmbOperator.getText() + + this.valueText.getText(); + super.okPressed(); + } }
diff --git a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/dialog/ElasticityStrategyDialog.java b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/dialog/ElasticityStrategyDialog.java index bd46d88..31332f5 100644 --- a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/dialog/ElasticityStrategyDialog.java +++ b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/dialog/ElasticityStrategyDialog.java
@@ -39,7 +39,7 @@ public class ElasticityStrategyDialog extends Dialog { - protected Text typeText; + protected Text typeText; protected Text valueText; protected boolean editMode = false; protected boolean addMode = false; @@ -48,19 +48,17 @@ private CCombo cmbStrategy; private CCombo cmbMetric; private CCombo cmbElasticityAction; - private String component; - + private String nodeName; + /** * @param parentShell */ - public ElasticityStrategyDialog( final Shell parentShell, String component ) - { + public ElasticityStrategyDialog( final Shell parentShell, String component, String nodeName ) { super( parentShell ); this.addMode = true; - this.component = component; + this.nodeName = nodeName; } - @Override protected void configureShell( final Shell shell ) { super.configureShell( shell ); @@ -73,69 +71,47 @@ Composite composite = ( Composite )super.createDialogArea( parent ); composite.setLayout( new GridLayout( 1, false ) ); composite.setLayoutData( new GridData( GridData.FILL_BOTH ) ); - // Choose from Supported Elasticity Actions Group Group elasticityActionsGroup = new Group( composite, SWT.NONE ); elasticityActionsGroup.setLayout( new GridLayout( 1, false ) ); elasticityActionsGroup.setText( "&Select Strategy" ); GridData gData = new GridData( SWT.FILL, SWT.FILL, true, true ); elasticityActionsGroup.setLayoutData( gData ); - // Combo - GlobalElasticityReq this.cmbElasticityAction = new CCombo( elasticityActionsGroup, SWT.BORDER ); this.cmbElasticityAction.setEnabled( true ); GridData gd = new GridData( GridData.FILL_HORIZONTAL ); this.cmbElasticityAction.setLayoutData( gd ); - - this.cmbElasticityAction.add( "AddVM" ); - this.cmbElasticityAction.add( "RemoveVM" ); - this.cmbElasticityAction.setText( this.cmbElasticityAction.getItem( 0 ) ); - +// this.cmbElasticityAction.add( "AddVM" ); +// this.cmbElasticityAction.add( "RemoveVM" ); + this.cmbElasticityAction.add( "scaleIn" ); + this.cmbElasticityAction.add( "scaleOut" ); + this.cmbElasticityAction.setText( this.cmbElasticityAction.getItem( 0 ) ); this.cmbElasticityAction.setEditable( false ); - - //Create New Strategy Group + // Create New Strategy Group Group customStrategyGroup = new Group( composite, SWT.NONE ); customStrategyGroup.setLayout( new GridLayout( 1, false ) ); customStrategyGroup.setText( "&Specify New Strategy" ); gData = new GridData( SWT.FILL, SWT.FILL, true, true ); customStrategyGroup.setLayoutData( gData ); - // Combo - GlobalElasticityReq this.cmbStrategy = new CCombo( customStrategyGroup, SWT.BORDER ); this.cmbStrategy.setEnabled( true ); gd = new GridData( GridData.FILL_HORIZONTAL ); this.cmbStrategy.setLayoutData( gd ); - this.cmbStrategy.add( "Maximize" ); this.cmbStrategy.add( "Minimize" ); - this.cmbStrategy.setText( this.cmbStrategy.getItem( 0 ) ); - + this.cmbStrategy.setText( this.cmbStrategy.getItem( 0 ) ); this.cmbStrategy.setEditable( false ); - // Combo - Metric - this.cmbMetric = new CCombo( customStrategyGroup, SWT.BORDER ); this.cmbMetric.setEnabled( true ); this.cmbMetric.setEditable( false ); GridData gdMetric = new GridData( GridData.FILL_HORIZONTAL ); this.cmbMetric.setLayoutData( gdMetric ); - -// if( this.component.compareTo( "Application" ) == 0 ) { -// List<ElasticityRequirementCategory> categories = ElasticityRequirementCategory.VALUES; -// for( ElasticityRequirementCategory tempCat : categories ) { -// this.cmbMetric.add( tempCat.toString() ); -// } -// } -// else if( this.component.compareTo( "Application Component" ) == 0 ) { -// List<ApplicationComponentElasticityRequirementCategory> categories = ApplicationComponentElasticityRequirementCategory.VALUES; -// for( ApplicationComponentElasticityRequirementCategory tempCat : categories ) -// { -// this.cmbMetric.add( tempCat.toString() ); -// } -// this.cmbMetric.add( "Latency" ); -// } - - this.cmbMetric.add( "Latency" ); + this.cmbMetric.add( "Cost" ); + this.cmbMetric.add( "Throughput" ); + this.cmbMetric.add( "Response Time" ); return composite; } @@ -147,35 +123,22 @@ public String getElasticityStrategy() { return ElasticityStrategyDialog.this.elasticityStrategy; } - - public SyblElasticityRequirementsDescription getSYBLStrategy(){ - - SyblElasticityRequirementsDescription serd = SyblFactory.eINSTANCE.createSyblElasticityRequirementsDescription(); - - Strategy propertiesStrategy = SyblFactory.eINSTANCE.createStrategy(); - ToEnforceType strategyToEnforce = SyblFactory.eINSTANCE.createToEnforceType(); - propertiesStrategy.setId( "hi" ); - propertiesStrategy.setToEnforce( strategyToEnforce ); - strategyToEnforce.setActionName( this.elasticityStrategy ); - strategyToEnforce.setParameter( "hi2" ); - SYBLSpecificationType sst = SyblFactory.eINSTANCE.createSYBLSpecificationType(); - sst.getStrategy().add( propertiesStrategy ); - serd.getSYBLSpecification().add( sst ); - - return serd; - } @SuppressWarnings("boxing") @Override protected void okPressed() { - - if ( !(this.cmbMetric.getText().equals( "" )) ){ - ElasticityStrategyDialog.this.elasticityStrategy = this.cmbStrategy.getText() + " (" + this.cmbMetric.getText() + ")"; - } - else{ - ElasticityStrategyDialog.this.elasticityStrategy = this.cmbElasticityAction.getText(); + if( !( this.cmbMetric.getText().equals( "" ) ) ) { + ElasticityStrategyDialog.this.elasticityStrategy = this.cmbStrategy.getText() + + " (" + + this.cmbMetric.getText() + + ")"; + } else { + //ElasticityStrategyDialog.this.elasticityStrategy = this.cmbElasticityAction.getText(); + ElasticityStrategyDialog.this.elasticityStrategy = this.cmbElasticityAction.getText() + + " (" + + this.nodeName + + ")"; } - super.okPressed(); } }
diff --git a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/AddSoftwareDependencyFeature.java b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/AddSoftwareDependencyFeature.java index 65097d2..2b59eb5 100644 --- a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/AddSoftwareDependencyFeature.java +++ b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/AddSoftwareDependencyFeature.java
@@ -16,12 +16,14 @@ *******************************************************************************/ package org.eclipse.camf.tosca.editor.features; +import org.eclipse.camf.tosca.TArtifactTemplate; import org.eclipse.camf.tosca.TDeploymentArtifact; import org.eclipse.camf.tosca.editor.StyleUtil; import org.eclipse.graphiti.features.IAddFeature; import org.eclipse.graphiti.features.IFeatureProvider; import org.eclipse.graphiti.features.context.IAddContext; import org.eclipse.graphiti.features.context.IContext; +import org.eclipse.graphiti.features.impl.AbstractAddShapeFeature; import org.eclipse.graphiti.features.impl.AbstractFeature; import org.eclipse.graphiti.mm.algorithms.Polyline; import org.eclipse.graphiti.mm.algorithms.Rectangle; @@ -38,8 +40,7 @@ import org.eclipse.graphiti.util.ColorConstant; import org.eclipse.graphiti.util.IColorConstant; -public class AddSoftwareDependencyFeature extends AbstractFeature - implements IAddFeature +public class AddSoftwareDependencyFeature extends AbstractAddShapeFeature { private static final IColorConstant E_CLASS_TEXT_FOREGROUND = IColorConstant.BLACK; @@ -59,14 +60,16 @@ public boolean canAdd( final IAddContext context ) { boolean result = false; - boolean diagraminstance = context.getTargetContainer() instanceof Diagram; - - if( context.getNewObject() instanceof TDeploymentArtifact - && !diagraminstance ) - { - if (((TDeploymentArtifact)context.getNewObject()).getArtifactType().toString().compareTo( "SD" )==0) - result = true; - } + boolean diagraminstance = context.getTargetContainer() instanceof Diagram; + + if( context.getNewObject() instanceof TArtifactTemplate + && !diagraminstance ) + { + if (((TArtifactTemplate)context.getNewObject()).getName().contains( "SD" )) + result = true; + } + + return result; } @@ -75,7 +78,7 @@ @Override public PictogramElement add( final IAddContext context ) { - TDeploymentArtifact addedClass = ( TDeploymentArtifact )context.getNewObject(); + TArtifactTemplate addedClass = ( TArtifactTemplate )context.getNewObject(); ContainerShape targetDiagram = context.getTargetContainer(); Object[] targetDiagrams = targetDiagram.getChildren().toArray(); @@ -135,7 +138,9 @@ // create shape for text Shape shape = peCreateService.createShape( containerShape, false ); // create and set text graphics algorithm - Text text = gaService.createText( shape, addedClass.getName() ); + // 2 is the size of "SD" + Text text = gaService.createText( shape, addedClass.getName().substring( 2 ) ); + //Text text = gaService.createText( shape, findImplementationArtifactName(addedClass.getId()) ); text.setForeground( manageColor( E_CLASS_TEXT_FOREGROUND ) ); text.setHorizontalAlignment( Orientation.ALIGNMENT_CENTER ); // vertical alignment has as default value "center" @@ -151,13 +156,23 @@ return containerShape; } - @Override - public boolean canExecute( final IContext context ) { - return false; - } - - @Override - public void execute( final IContext context ) { - // TODO Auto-generated method stub - } + +// private String findImplementationArtifactName(String artifactId){ +// ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); +// DocumentRoot dr = model.getDocumentRoot(); +// DefinitionsType dt = dr.getDefinitions(); +// EList<TArtifactTemplate> artifactTemplates = +// dt.getArtifactTemplate(); +// +// for (TArtifactTemplate tempArtifactTemplate : artifactTemplates){ +// if (tempArtifactTemplate.getId().equals( artifactId )){ +// TArtifactReference artifactRef = tempArtifactTemplate.getArtifactReferences().getArtifactReference().get( 0 ); +// String artifactReference = artifactRef.getReference(); +// String artifactName = artifactReference.substring( artifactReference.indexOf( "\\" ) +1); +// return artifactName; +// } +// } +// +// return null; +// } }
diff --git a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/AddVirtualMachineFeature.java b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/AddVirtualMachineFeature.java index 66c4650..428f20e 100644 --- a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/AddVirtualMachineFeature.java +++ b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/AddVirtualMachineFeature.java
@@ -18,6 +18,7 @@ import org.eclipse.camf.tosca.TDeploymentArtifact; import org.eclipse.camf.tosca.editor.StyleUtil; +import org.eclipse.camf.tosca.elasticity.Tosca_Elasticity_ExtensionsPackage; import org.eclipse.graphiti.features.IFeatureProvider; import org.eclipse.graphiti.features.context.IAddContext; import org.eclipse.graphiti.features.impl.AbstractAddShapeFeature; @@ -37,100 +38,102 @@ public class AddVirtualMachineFeature extends AbstractAddShapeFeature { - private static final IColorConstant E_CLASS_TEXT_FOREGROUND = IColorConstant.BLACK; - private static final IColorConstant E_CLASS_FOREGROUND = new ColorConstant( 98, - 131, - 167 ); - private static final IColorConstant E_CLASS_BACKGROUND = new ColorConstant( 32, - 178, - 170 ); + private static final IColorConstant E_CLASS_TEXT_FOREGROUND = IColorConstant.BLACK; + private static final IColorConstant E_CLASS_FOREGROUND = new ColorConstant( 98, + 131, + 167 ); + private static final IColorConstant E_CLASS_BACKGROUND = new ColorConstant( 32, + 178, + 170 ); + private String imageType = Tosca_Elasticity_ExtensionsPackage.eINSTANCE.getImageArtifactPropertiesType().getName(); + + public AddVirtualMachineFeature( final IFeatureProvider fp ) { + super( fp ); + } - public AddVirtualMachineFeature( final IFeatureProvider fp ) { - super( fp ); - } + // Checks whether a VM Image can be added to the target object + @Override + public boolean canAdd( final IAddContext context ) { + boolean result = false; + boolean diagraminstance = context.getTargetContainer() instanceof Diagram; +// if( context.getNewObject() instanceof VirtualMachineImage +// && !diagraminstance ) +// { +// result = true; +// } + if( context.getNewObject() instanceof TDeploymentArtifact + && !diagraminstance ) + { + //if (((TDeploymentArtifact)context.getNewObject()).getArtifactType().toString().compareTo( "VMI" )==0) + if (((TDeploymentArtifact)context.getNewObject()).getArtifactType().getLocalPart().compareTo( imageType )==0) + result = true; + } + return result; + } - // Checks whether a VM Image can be added to the target object - @Override - public boolean canAdd( final IAddContext context ) { - boolean result = false; - boolean diagraminstance = context.getTargetContainer() instanceof Diagram; -// if( context.getNewObject() instanceof VirtualMachineImage -// && !diagraminstance ) -// { -// result = true; -// } - if( context.getNewObject() instanceof TDeploymentArtifact - && !diagraminstance ) - { - if (((TDeploymentArtifact)context.getNewObject()).getArtifactType().toString().compareTo( "VMI" )==0) - result = true; - } - return result; - } + // Adds a VM Image figure to the target object + @Override + public PictogramElement add( final IAddContext context ) { - // Adds a VM Image figure to the target object - @Override - public PictogramElement add( final IAddContext context ) { - - TDeploymentArtifact addedClass = ( TDeploymentArtifact )context.getNewObject(); - - - ContainerShape targetDiagram = ( ContainerShape )context.getTargetContainer(); - int targetContainerHeight = targetDiagram.getGraphicsAlgorithm().getHeight(); - int targetContainerWidth = targetDiagram.getGraphicsAlgorithm().getWidth(); - - // CONTAINER SHAPE WITH ROUNDED RECTANGLE - IPeCreateService peCreateService = Graphiti.getPeCreateService(); - ContainerShape containerShape = peCreateService.createContainerShape( targetDiagram, - true ); - final int width = targetContainerWidth; - final int height = 20; - IGaService gaService = Graphiti.getGaService(); - RoundedRectangle roundedRectangle; - { - // create and set graphics algorithm - roundedRectangle = gaService.createRoundedRectangle( containerShape, 5, 5 ); - roundedRectangle.setForeground( manageColor( E_CLASS_FOREGROUND ) ); - roundedRectangle.setBackground( manageColor( E_CLASS_BACKGROUND ) ); - roundedRectangle.setLineWidth( 2 ); - gaService.setLocationAndSize( roundedRectangle, - 0, - targetContainerHeight - 20, - width, - height ); - if( addedClass.eResource() == null ) { - getDiagram().eResource().getContents().add( addedClass ); - } - // create link and wire it - link( containerShape, addedClass ); - } - // SHAPE WITH LINE - { - // create shape for line - Shape shape = peCreateService.createShape( containerShape, false ); - // create and set graphics algorithm - Polyline polyline = gaService.createPolyline( shape, new int[]{ - 0, 20, width, 20 - } ); - polyline.setForeground( manageColor( E_CLASS_FOREGROUND ) ); - polyline.setLineWidth( 2 ); - } - // SHAPE WITH TEXT - { - // create shape for text - Shape shape = peCreateService.createShape( containerShape, false ); - // create and set text graphics algorithm - Text text = gaService.createText( shape, addedClass.getName() ); - text.setForeground( manageColor( E_CLASS_TEXT_FOREGROUND ) ); - text.setHorizontalAlignment( Orientation.ALIGNMENT_CENTER ); - // vertical alignment has as default value "center" - text.setFont( gaService.manageDefaultFont( getDiagram(), false, true ) ); - gaService.setLocationAndSize( text, 0, 0, width, 20 ); - // create link and wire it - link( shape, addedClass ); - } - // call the layout feature - layoutPictogramElement( containerShape ); - return containerShape; - } -} + TDeploymentArtifact addedClass = ( TDeploymentArtifact )context.getNewObject(); + + + ContainerShape targetDiagram = ( ContainerShape )context.getTargetContainer(); + int targetContainerHeight = targetDiagram.getGraphicsAlgorithm().getHeight(); + int targetContainerWidth = targetDiagram.getGraphicsAlgorithm().getWidth(); + + // CONTAINER SHAPE WITH ROUNDED RECTANGLE + IPeCreateService peCreateService = Graphiti.getPeCreateService(); + ContainerShape containerShape = peCreateService.createContainerShape( targetDiagram, + true ); + final int width = targetContainerWidth; + final int height = 20; + IGaService gaService = Graphiti.getGaService(); + RoundedRectangle roundedRectangle; + { + // create and set graphics algorithm + roundedRectangle = gaService.createRoundedRectangle( containerShape, 5, 5 ); + roundedRectangle.setForeground( manageColor( E_CLASS_FOREGROUND ) ); + roundedRectangle.setBackground( manageColor( E_CLASS_BACKGROUND ) ); + roundedRectangle.setLineWidth( 2 ); + gaService.setLocationAndSize( roundedRectangle, + 0, + targetContainerHeight - 20, + width, + height ); + if( addedClass.eResource() == null ) { + getDiagram().eResource().getContents().add( addedClass ); + } + // create link and wire it + link( containerShape, addedClass ); + } + // SHAPE WITH LINE + { + // create shape for line + Shape shape = peCreateService.createShape( containerShape, false ); + // create and set graphics algorithm + Polyline polyline = gaService.createPolyline( shape, new int[]{ + 0, 20, width, 20 + } ); + polyline.setForeground( manageColor( E_CLASS_FOREGROUND ) ); + polyline.setLineWidth( 2 ); + } + // SHAPE WITH TEXT + { + // create shape for text + Shape shape = peCreateService.createShape( containerShape, false ); + // create and set text graphics algorithm + Text text = gaService.createText( shape, addedClass.getName() ); + text.setForeground( manageColor( E_CLASS_TEXT_FOREGROUND ) ); + text.setHorizontalAlignment( Orientation.ALIGNMENT_CENTER ); + // vertical alignment has as default value "center" + text.setFont( gaService.manageDefaultFont( getDiagram(), false, true ) ); + gaService.setLocationAndSize( text, 0, 0, width, 20 ); + // create link and wire it + link( shape, addedClass ); + } + // call the layout feature + layoutPictogramElement( containerShape ); + return containerShape; + } + }
diff --git a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/CreateApplicationComponentFeature.java b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/CreateApplicationComponentFeature.java index 520101f..688cdcb 100644 --- a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/CreateApplicationComponentFeature.java +++ b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/CreateApplicationComponentFeature.java
@@ -44,7 +44,6 @@ //-1 means not specified by user private static int DEFAULT_MAX_INSTANCES = -1; - private static int DEFAULT_INIT_INSTANCES = 1; private Object contextObject = null; @@ -73,64 +72,63 @@ // Creates the business object for the application component @Override public Object[] create( final ICreateContext context ) { - - if (this.contextObject == null) { - return null; - } - // create Application Component - TNodeTemplateExtension newClass = Tosca_Elasticity_ExtensionsFactory.eINSTANCE.createTNodeTemplateExtension(); - - //newClass.setYcsbmulti( 1 ); - //newClass.setCasmulti( 1 ); - - // initialize Application Component - // Max or Min instances == 0 => nothing specified by user - newClass.setInitInstances( DEFAULT_INIT_INSTANCES ); - newClass.setMinInstances( DEFAULT_MIN_INSTANCES ); - newClass.setMaxInstances( BigInteger.valueOf( DEFAULT_MAX_INSTANCES ) ); - newClass.setId( ( "C" + ( Integer )newClass.hashCode() ).toString() ); - //newClass.setType(((TNodeTemplateExtension) this.contextObject ).getType()); - - //Set X and Y required for reloading tosca model in tosca editor - newClass.setX(context.getX()); - newClass.setY(context.getY()); - // create the node template - ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - model.getDocumentRoot() - .getDefinitions() - .getServiceTemplate() - .get( 0 ) - .getTopologyTemplate() - .getNodeTemplate() - .add( newClass ); - Object parentObject = getFeatureProvider().getBusinessObjectForPictogramElement( context.getTargetContainer() ); - TServiceTemplate serviceTemplate = null; - if( parentObject == null ) - return null; - if( parentObject instanceof TServiceTemplate ) { - serviceTemplate = ( TServiceTemplate )parentObject; - } - TTopologyTemplate topology = null; - if( serviceTemplate.getTopologyTemplate() == null ) { - topology = ToscaFactory.eINSTANCE.createTTopologyTemplate(); - serviceTemplate.setTopologyTemplate( topology ); - } else { - topology = serviceTemplate.getTopologyTemplate(); - } - - // Add object to domain model - topology.getNodeTemplate().add( newClass ); - - // Add object to diagram model - //getDiagram().eResource().getContents().add(newClass); - - // do the add - addGraphicalRepresentation( context, newClass ); - // activate direct editing after object creation - getFeatureProvider().getDirectEditingInfo().setActive( true ); - // return newly created business object(s) - return new Object[]{ - newClass - }; - } + + if (this.contextObject == null) { + return null; + } + // create Application Component + TNodeTemplateExtension newClass = Tosca_Elasticity_ExtensionsFactory.eINSTANCE.createTNodeTemplateExtension(); + + //newClass.setYcsbmulti( 1 ); + //newClass.setCasmulti( 1 ); + + // initialize Application Component + // Max or Min instances == 0 => nothing specified by user + newClass.setMinInstances( DEFAULT_MIN_INSTANCES ); + newClass.setMaxInstances( BigInteger.valueOf( DEFAULT_MAX_INSTANCES ) ); + newClass.setId( ( "C" + ( Integer )newClass.hashCode() ).toString() ); + //newClass.setType(((TNodeTemplateExtension) this.contextObject ).getType()); + + //Set X and Y required for reloading tosca model in tosca editor + newClass.setX(context.getX()); + newClass.setY(context.getY()); + // create the node template + ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); + model.getDocumentRoot() + .getDefinitions() + .getServiceTemplate() + .get( 0 ) + .getTopologyTemplate() + .getNodeTemplate() + .add( newClass ); + Object parentObject = getFeatureProvider().getBusinessObjectForPictogramElement( context.getTargetContainer() ); + TServiceTemplate serviceTemplate = null; + if( parentObject == null ) + return null; + if( parentObject instanceof TServiceTemplate ) { + serviceTemplate = ( TServiceTemplate )parentObject; + } + TTopologyTemplate topology = null; + if( serviceTemplate.getTopologyTemplate() == null ) { + topology = ToscaFactory.eINSTANCE.createTTopologyTemplate(); + serviceTemplate.setTopologyTemplate( topology ); + } else { + topology = serviceTemplate.getTopologyTemplate(); + } + + // Add object to domain model + topology.getNodeTemplate().add( newClass ); + + // Add object to diagram model + //getDiagram().eResource().getContents().add(newClass); + + // do the add + addGraphicalRepresentation( context, newClass ); + // activate direct editing after object creation + getFeatureProvider().getDirectEditingInfo().setActive( true ); + // return newly created business object(s) + return new Object[]{ + newClass + }; + } }
diff --git a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/CreateResizeActionFeature.java b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/CreateResizeActionFeature.java index cc27002..222ecc3 100644 --- a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/CreateResizeActionFeature.java +++ b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/CreateResizeActionFeature.java
@@ -30,6 +30,7 @@ import org.eclipse.camf.tosca.editor.ModelHandler; import org.eclipse.camf.tosca.editor.ToscaModelLayer; import org.eclipse.camf.tosca.elasticity.TBoundaryDefinitionsExtension; +import org.eclipse.camf.tosca.elementCreators.CreateArtifactTemplate; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.transaction.RecordingCommand; @@ -46,257 +47,245 @@ public class CreateResizeActionFeature extends AbstractCreateFeature { - private Object contextObject = null; + private Object contextObject = null; - public CreateResizeActionFeature( final IFeatureProvider fp ) { - // set name and description of the creation feature - super( fp, "Resizing Action", "Resizing Action" ); //$NON-NLS-1$ //$NON-NLS-2$ - } + public CreateResizeActionFeature( final IFeatureProvider fp ) { + // set name and description of the creation feature + super( fp, "Resizing Action", "Resizing Action" ); //$NON-NLS-1$ //$NON-NLS-2$ + } - public void setContextObject( final Object obj ) { - this.contextObject = obj; - } + public void setContextObject( final Object obj ) { + this.contextObject = obj; + } - // Checks if user can create an elasticity action object in the target - // business object - @Override - public boolean canCreate( final ICreateContext context ) { - Object parentBo = getFeatureProvider().getBusinessObjectForPictogramElement( context.getTargetContainer() ); - if( parentBo instanceof TNodeTemplate || parentBo instanceof TServiceTemplate ) { - return true; - } - return false; - } + // Checks if user can create an elasticity action object in the target + // business object + @Override + public boolean canCreate( final ICreateContext context ) { + Object parentBo = getFeatureProvider().getBusinessObjectForPictogramElement( context.getTargetContainer() ); + if( parentBo instanceof TNodeTemplate || parentBo instanceof TServiceTemplate ) { + return true; + } + return false; + } - // Creates the business object for the elasticity action - @Override - public Object[] create( final ICreateContext context ) { - // MessageConsole myConsole = findConsole("MyConsole"); - // MessageConsoleStream out = myConsole.newMessageStream(); - if( this.contextObject == null ) - return null; - - String level = null; - - ResizingAction ra = ( ResizingAction )this.contextObject; - - Object parentObject = getFeatureProvider().getBusinessObjectForPictogramElement( context.getTargetContainer() ); + // Creates the business object for the elasticity action + @Override + public Object[] create( final ICreateContext context ) { + // MessageConsole myConsole = findConsole("MyConsole"); + // MessageConsoleStream out = myConsole.newMessageStream(); + if( this.contextObject == null ) + return null; + + String level = null; + + ResizingAction ra = ( ResizingAction )this.contextObject; + + CreateArtifactTemplate artTempl = new CreateArtifactTemplate(ra.getName(), new QName("RA"), ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) )); + + Object parentObject = getFeatureProvider().getBusinessObjectForPictogramElement( context.getTargetContainer() ); - if( parentObject == null ) - return null; - - TNodeTemplate tNode = null; - TServiceTemplate tService = null; - - // Application Component - if( parentObject instanceof TNodeTemplate ) { - level = "C"; - tNode = ( TNodeTemplate )parentObject; - - if (tNode.getName()==null){ - MessageDialog.openError(null, "Error", "Give a Name to the selected Component and try again."); - return null; - } - } - - else if ( parentObject instanceof TServiceTemplate ){ - level = "G"; - tService = ( TServiceTemplate )parentObject; - if (tService.getSubstitutableNodeType() != null){ - // Composite Application Component - - // Find the substitute TNodeTemplate - TNodeTemplate substituteNode = null; - ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - for (TNodeTemplate tempNodeTemplate : model.getDocumentRoot() - .getDefinitions() - .getServiceTemplate() - .get( 0 ) - .getTopologyTemplate() - .getNodeTemplate()){ - - if ( tempNodeTemplate.getId().toString().equals( tService.getId().toString()) ) - { - substituteNode = tempNodeTemplate; - break; - } - - } - - tNode = substituteNode; - + if( parentObject == null ) + return null; + + TNodeTemplate tNode = null; + TServiceTemplate tService = null; + + // Application Component + if( parentObject instanceof TNodeTemplate ) { + level = "C"; + tNode = ( TNodeTemplate )parentObject; + + if (tNode.getName()==null){ + MessageDialog.openError(null, "Error", "Give a Name to the selected Component and try again."); + return null; + } + } + + else if ( parentObject instanceof TServiceTemplate ){ + level = "G"; + tService = ( TServiceTemplate )parentObject; + if (tService.getSubstitutableNodeType() != null){ + // Composite Application Component + + // Find the substitute TNodeTemplate + TNodeTemplate substituteNode = null; + ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); + for (TNodeTemplate tempNodeTemplate : model.getDocumentRoot() + .getDefinitions() + .getServiceTemplate() + .get( 0 ) + .getTopologyTemplate() + .getNodeTemplate()){ + + if ( tempNodeTemplate.getId().toString().equals( tService.getId().toString()) ) + { + substituteNode = tempNodeTemplate; + break; + } + + } + + tNode = substituteNode; + - - } - else{ - // Application - - level = "A"; - final TBoundaryDefinitionsExtension boundaryDef = ( TBoundaryDefinitionsExtension )( ( ( TServiceTemplate )parentObject ).getBoundaryDefinitions() ); - - - if ( boundaryDef.getPolicies() == null ){ - - final PoliciesType1 boundaryPolicies = ToscaFactory.eINSTANCE.createPoliciesType1(); - - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( parentObject ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { + + } + else{ + // Application + + level = "A"; + final TBoundaryDefinitionsExtension boundaryDef = ( TBoundaryDefinitionsExtension )( ( ( TServiceTemplate )parentObject ).getBoundaryDefinitions() ); + + + if ( boundaryDef.getPolicies() == null ){ + + final PoliciesType1 boundaryPolicies = ToscaFactory.eINSTANCE.createPoliciesType1(); + + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( parentObject ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { - @Override - protected void doExecute() { - boundaryDef.setPolicies( boundaryPolicies ); - } - } ); - - - } - - PoliciesType1 nodePolicyList = boundaryDef.getPolicies(); - - final EList<TPolicy> policy = nodePolicyList.getPolicy(); - - final TPolicy newPolicy = createNewPolicy(level, ra.getName()); - -// final TPolicy newPolicy = ToscaFactory.eINSTANCE.createTPolicy(); -// -// final String policyUniqueName = "G" + policy.size(); -// -// newPolicy.setPolicyType( new QName("SYBLStrategy") ); -// -//// newPolicy.setName( "S" + policyUniqueName + ":STRATEGY " + ra.getName() ); -// -// newPolicy.setName( "STRATEGY " + ra.getName() ); - - - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( parentObject ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { + @Override + protected void doExecute() { + boundaryDef.setPolicies( boundaryPolicies ); + } + } ); + + + } + + PoliciesType1 nodePolicyList = boundaryDef.getPolicies(); + + final EList<TPolicy> policy = nodePolicyList.getPolicy(); + + final TPolicy newPolicy = createNewPolicy(level, ra.getName()); + +// final TPolicy newPolicy = ToscaFactory.eINSTANCE.createTPolicy(); +// +// final String policyUniqueName = "G" + policy.size(); +// +// newPolicy.setPolicyType( new QName("SYBLStrategy") ); +// +//// newPolicy.setName( "S" + policyUniqueName + ":STRATEGY " + ra.getName() ); + // +// newPolicy.setName( "STRATEGY " + ra.getName() ); + + + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( parentObject ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { - @Override - protected void doExecute() { - policy.add( newPolicy ); - } - } ); - - return new Object[]{ - newPolicy - }; - } - - } + @Override + protected void doExecute() { + policy.add( newPolicy ); + } + } ); + + return new Object[]{ + newPolicy + }; + } + + } - - final TNodeTemplate nodeTemplate = tNode; - - if ( nodeTemplate.getPolicies() == null ){ - final PoliciesType nodePolicyList = ToscaFactory.eINSTANCE.createPoliciesType(); - - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( parentObject ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { + + final TNodeTemplate nodeTemplate = tNode; + + if ( nodeTemplate.getPolicies() == null ){ + final PoliciesType nodePolicyList = ToscaFactory.eINSTANCE.createPoliciesType(); + + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( parentObject ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { - @Override - protected void doExecute() { - nodeTemplate.setPolicies( nodePolicyList ); - } - } ); - - - } - - final EList<TPolicy> policy = nodeTemplate.getPolicies().getPolicy(); - - final TPolicy newPolicy = createNewPolicy(level, ra.getName()); - -// final TPolicy newPolicy = ToscaFactory.eINSTANCE.createTPolicy(); -// -// final String policyUniqueName = nodeTemplate.getId() + policy.size(); -// -// newPolicy.setPolicyType( new QName("SYBLStrategy") ); -// -//// newPolicy.setName( "S" + policyUniqueName + ":STRATEGY " + ra.getName() ); -// newPolicy.setName( "STRATEGY " + ra.getName() ); - - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( parentObject ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { + @Override + protected void doExecute() { + nodeTemplate.setPolicies( nodePolicyList ); + } + } ); + + + } + + final EList<TPolicy> policy = nodeTemplate.getPolicies().getPolicy(); + + final TPolicy newPolicy = createNewPolicy(level, ra.getName()); + +// final TPolicy newPolicy = ToscaFactory.eINSTANCE.createTPolicy(); + // +// final String policyUniqueName = nodeTemplate.getId() + policy.size(); + // +// newPolicy.setPolicyType( new QName("SYBLStrategy") ); + // +//// newPolicy.setName( "S" + policyUniqueName + ":STRATEGY " + ra.getName() ); +// newPolicy.setName( "STRATEGY " + ra.getName() ); + + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( parentObject ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { - @Override - protected void doExecute() { - policy.add( newPolicy ); - } - } ); - - - // do the add - addGraphicalRepresentation( context, ra ); - // activate direct editing after object creation - getFeatureProvider().getDirectEditingInfo().setActive( true ); - // return newly created business object(s) - return new Object[]{ - newPolicy - }; - } + @Override + protected void doExecute() { + policy.add( newPolicy ); + } + } ); + + + // do the add + addGraphicalRepresentation( context, ra ); + // activate direct editing after object creation + getFeatureProvider().getDirectEditingInfo().setActive( true ); + // return newly created business object(s) + return new Object[]{ + newPolicy + }; + } - //level can be "C" for Application Component, "G" for Composite Component, "A" for Application - TPolicy createNewPolicy(String level, String policyName){ + //level can be "C" for Application Component, "G" for Composite Component, "A" for Application + TPolicy createNewPolicy(String level, String policyName){ - // Create Policy Template - - final TPolicyTemplate newPolicyTemplate = ToscaFactory.eINSTANCE.createTPolicyTemplate(); - - QName policyTypeName = new QName( "http://www.example.org/SYBL", "Strategy" ); - - newPolicyTemplate.setType( policyTypeName ); - - String id = level + ( ( Integer )newPolicyTemplate.hashCode() ).toString(); - - newPolicyTemplate.setId( id ); - - // Add the new Policy Template to the TOSCA Definitions element - - final ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - - DefinitionsType definitions = model.getDocumentRoot().getDefinitions(); - - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( definitions ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { + // Create Policy Template + + final TPolicyTemplate newPolicyTemplate = ToscaFactory.eINSTANCE.createTPolicyTemplate(); + + QName policyTypeName = new QName( "http://www.example.org/SYBL", "Strategy" ); + + newPolicyTemplate.setType( policyTypeName ); + + String id = level + ( ( Integer )newPolicyTemplate.hashCode() ).toString(); + + newPolicyTemplate.setId( id ); + + // Add the new Policy Template to the TOSCA Definitions element + + final ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); + + DefinitionsType definitions = model.getDocumentRoot().getDefinitions(); + + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( definitions ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { - @Override - protected void doExecute() { - model.getDocumentRoot().getDefinitions().getPolicyTemplate().add( newPolicyTemplate ); - } - } ); - - // Assign the created Policy Template to the new Policy - - TPolicy newPolicy = ToscaFactory.eINSTANCE.createTPolicy(); - - QName qnamePolicyTemplate = new QName( newPolicyTemplate.getId() ); - - newPolicy.setPolicyType( policyTypeName ); - - newPolicy.setPolicyRef( qnamePolicyTemplate ); - - newPolicy.setName( "STRATEGY " + policyName ); - - return newPolicy; - } - - private MessageConsole findConsole( String name ) { - ConsolePlugin plugin = ConsolePlugin.getDefault(); - IConsoleManager conMan = plugin.getConsoleManager(); - IConsole[] existing = conMan.getConsoles(); - for( int i = 0; i < existing.length; i++ ) - if( name.equals( existing[ i ].getName() ) ) - return ( MessageConsole )existing[ i ]; - // no console found, so create a new one - MessageConsole myConsole = new MessageConsole( name, null ); - conMan.addConsoles( new IConsole[]{ - myConsole - } ); - return myConsole; - } -} + @Override + protected void doExecute() { + model.getDocumentRoot().getDefinitions().getPolicyTemplate().add( newPolicyTemplate ); + } + } ); + + // Assign the created Policy Template to the new Policy + + TPolicy newPolicy = ToscaFactory.eINSTANCE.createTPolicy(); + + QName qnamePolicyTemplate = new QName( newPolicyTemplate.getId() ); + + newPolicy.setPolicyType( policyTypeName ); + + newPolicy.setPolicyRef( qnamePolicyTemplate ); + + newPolicy.setName( "STRATEGY " + policyName ); + + return newPolicy; + } + + } \ No newline at end of file
diff --git a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/CreateSoftwareDependencyFeature.java b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/CreateSoftwareDependencyFeature.java index 5043b93..f0db42b 100644 --- a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/CreateSoftwareDependencyFeature.java +++ b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/CreateSoftwareDependencyFeature.java
@@ -37,6 +37,7 @@ import org.eclipse.camf.tosca.elasticity.ScriptArtifactPropertiesType; import org.eclipse.camf.tosca.elasticity.Tosca_Elasticity_ExtensionsFactory; import org.eclipse.camf.tosca.elasticity.Tosca_Elasticity_ExtensionsPackage; +import org.eclipse.camf.tosca.elementCreators.CreateArtifactTemplate; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.ecore.util.FeatureMapUtil; import org.eclipse.emf.ecore.util.FeatureMap.Entry; @@ -52,221 +53,121 @@ public class CreateSoftwareDependencyFeature extends AbstractCreateFeature { - private Object contextObject = null; + private Object contextObject = null; - public CreateSoftwareDependencyFeature( final IFeatureProvider fp ) { - // set name and description of the creation feature - super( fp, "Software Dependency", "Software Dependency" ); //$NON-NLS-1$ //$NON-NLS-2$ - } + public CreateSoftwareDependencyFeature( final IFeatureProvider fp ) { + // set name and description of the creation feature + super( fp, "Software Dependency", "Software Dependency" ); //$NON-NLS-1$ //$NON-NLS-2$ + } - public void setContextObject( final Object obj ) { - this.contextObject = obj; - } + public void setContextObject( final Object obj ) { + this.contextObject = obj; + } - // Checks if user can create a software dependency object in the target - // business object - @Override - public boolean canCreate( final ICreateContext context ) { - return !( context.getTargetContainer() instanceof Diagram ); - } + // Checks if user can create a software dependency object in the target + // business object + @Override + public boolean canCreate( final ICreateContext context ) { + return !( context.getTargetContainer() instanceof Diagram ); + } - // Creates the business object for the software dependency - @Override - public Object[] create( final ICreateContext context ) { - + // Creates the business object for the software dependency + @Override + public Object[] create( final ICreateContext context ) { if( this.contextObject == null ) - return null; - - Object parentObject = getFeatureProvider().getBusinessObjectForPictogramElement( context.getTargetContainer() ); - TNodeTemplate tNode = null; - if( parentObject == null ) - return null; - if( parentObject instanceof TNodeTemplate ) { - tNode = ( TNodeTemplate )parentObject; - } - - if (tNode.getName()==null){ - MessageDialog.openError(null, "Error", "Give a Name to the selected Component and try again."); - return null; - } - - - if( tNode.getDeploymentArtifacts() == null ) { - - final TNodeTemplate node = tNode; - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( parentObject ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { - - protected void doExecute() { - node.setDeploymentArtifacts( ToscaFactory.eINSTANCE.createTDeploymentArtifacts() ); - } - } ); - - } + return null; + Object parentObject = getFeatureProvider().getBusinessObjectForPictogramElement( context.getTargetContainer() ); + TNodeTemplate tNode = null; + if( parentObject == null ) + return null; + if( parentObject instanceof TNodeTemplate ) { + tNode = ( TNodeTemplate )parentObject; + } + if( tNode.getName() == null ) { + MessageDialog.openError( null, + "Error", + "Give a Name to the selected Component and try again." ); + return null; + } + TArtifactTemplate artifactTemplate = ( TArtifactTemplate )this.contextObject; + // Create Script Artifact Template + CreateArtifactTemplate artTempl = new CreateArtifactTemplate(artifactTemplate.getId(), artifactTemplate.getType(), ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) )); + TArtifactTemplate newArtifactTemplate = artTempl.getNewArtifactTemplate(); + + // Create Implementation Artifact + createImplementationArtifact( new QName( tNode.getName() ), artifactTemplate.getType(), + new QName( artifactTemplate.getId()) ); + //addGraphicalRepresentation( context, artifactTemplate ); + addGraphicalRepresentation( context, newArtifactTemplate ); + + // activate direct editing after object creation + getFeatureProvider().getDirectEditingInfo().setActive( true ); + // return newly created business object(s) + return new Object[]{ + newArtifactTemplate + }; + } + + // Creates the install implementation artifact + private void createImplementationArtifact( QName nodeType, QName artifactType, + QName artifactID ) + { + + final ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); + DefinitionsType definitions = model.getDocumentRoot().getDefinitions(); + + TNodeTypeImplementation nodeTypeImplementation = null; + // Test if NodeTypeImplementation for nodeType already exists + for( TNodeTypeImplementation tempNodeTypeImplementation : definitions.getNodeTypeImplementation() ) + { + if( tempNodeTypeImplementation.getNodeType() + .toString() + .equals( nodeType.toString() ) ) + { + // NodeTypeImplementation already exists + // We are going to add the artifact to the existing implementation + nodeTypeImplementation = tempNodeTypeImplementation; + } + } + if( nodeTypeImplementation == null ) { + // NodeTypeImplementation does not exists + final TNodeTypeImplementation newNodeTypeImplementation = ToscaFactory.eINSTANCE.createTNodeTypeImplementation(); + newNodeTypeImplementation.setNodeType( nodeType ); + newNodeTypeImplementation.setName( "name" ); + TImplementationArtifacts implementationArtifacts = ToscaFactory.eINSTANCE.createTImplementationArtifacts(); + newNodeTypeImplementation.setImplementationArtifacts( implementationArtifacts ); - // Add the new deployment artifact to the list - final TDeploymentArtifacts deploymentArtifacts = tNode.getDeploymentArtifacts(); - TDeploymentArtifact tempDeploymentArtifact = ( TDeploymentArtifact )this.contextObject; - - TDeploymentArtifact deploymentArtifact = ToscaFactory.eINSTANCE.createTDeploymentArtifact(); - deploymentArtifact.setName( tempDeploymentArtifact.getName() ); - deploymentArtifact.setArtifactType( tempDeploymentArtifact.getArtifactType() ); - deploymentArtifact.setArtifactRef( new QName (tNode.getName() + "Script" )); - - final TDeploymentArtifact tempArtifact = deploymentArtifact; - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( parentObject ); + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( definitions ); editingDomain.getCommandStack() .execute( new RecordingCommand( editingDomain ) { + @Override protected void doExecute() { - deploymentArtifacts.getDeploymentArtifact().add( tempArtifact ); + model.getDocumentRoot().getDefinitions().getNodeTypeImplementation() + .add( newNodeTypeImplementation ); } } ); -// ImplementationArtifactType tempImplementationArtifact = (ImplementationArtifactType) this.contextObject; -// -// //Create Image Artifact Template -// createArtifactTemplate(tNode.getName(), tempImplementationArtifact.getArtifactType().toString()); -// -// //Create Implementation Artifact -// ImplementationArtifactType implementationArtifact = createImplementationArtifact( tNode.getName()+"Script", tempImplementationArtifact.getArtifactType(), new QName(tNode.getName()+"Script")); -// -// addGraphicalRepresentation( context, implementationArtifact ); -// -// -// // activate direct editing after object creation -// getFeatureProvider().getDirectEditingInfo().setActive( true ); -// // return newly created business object(s) -// return new Object[]{ -// implementationArtifact -// }; - - addGraphicalRepresentation( context, deploymentArtifact ); + nodeTypeImplementation = newNodeTypeImplementation; + } + // Create Implementation Artifact + final ImplementationArtifactType installArtifactType = ToscaFactory.eINSTANCE.createImplementationArtifactType(); + installArtifactType.setArtifactType( artifactType ); + installArtifactType.setArtifactRef( artifactID ); + installArtifactType.setInterfaceName( "Lifecycle" ); + installArtifactType.setOperationName( "execute" ); + final TNodeTypeImplementation nodeImplementation = nodeTypeImplementation; + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( nodeTypeImplementation ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { - //Create Image Artifact Template - createArtifactTemplate(tNode.getName(), tempDeploymentArtifact.getName()); - - //Create Implementation Artifact - createImplementationArtifact( tempDeploymentArtifact.getName(), new QName(tNode.getName()), new QName(tNode.getName()+"Script")); - - // activate direct editing after object creation - getFeatureProvider().getDirectEditingInfo().setActive( true ); - // return newly created business object(s) - return new Object[]{ - deploymentArtifact - }; - - } - - private void createArtifactTemplate(String nodeName, String artifactName){ - - //Create Artifact Template - final TArtifactTemplate artifactTemplate = ToscaFactory.eINSTANCE.createTArtifactTemplate(); - - //Create Script Artifact Properties - ScriptArtifactPropertiesType scriptProperties = Tosca_Elasticity_ExtensionsFactory.eINSTANCE.createScriptArtifactPropertiesType(); - scriptProperties.setLanguage( "Shell" ); - - // Set the Properties of the Policy Template - PropertiesType properties = ToscaFactory.eINSTANCE.createPropertiesType(); - - // Add the SYBL Policy to the FeatureMap of the Policy's Properties element - Entry e = FeatureMapUtil.createEntry( Tosca_Elasticity_ExtensionsPackage.eINSTANCE.getDocumentRoot_ScriptArtifactProperties(), scriptProperties ); - properties.getAny().add( e ); - - artifactTemplate.setProperties( properties ); - - artifactTemplate.setId( nodeName + "Script" ); - - - // Set artifact ref - TArtifactReference artifactRef = ToscaFactory.eINSTANCE.createTArtifactReference(); - artifactRef.setReference( "Scripts"+ File.separator + artifactName); - - ArtifactReferencesType artifactRefType = ToscaFactory.eINSTANCE.createArtifactReferencesType(); - artifactRefType.getArtifactReference().add( artifactRef ); - - artifactTemplate.setArtifactReferences( artifactRefType ); - - // Add the new Artifact Template to the TOSCA Definitions element - - final ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - - DefinitionsType definitions = model.getDocumentRoot().getDefinitions(); - - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( definitions ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { - - @Override - protected void doExecute() { - model.getDocumentRoot().getDefinitions().getArtifactTemplate().add( artifactTemplate ); - - } - } ); - - } - - - //Creates the install implementation artifact - private ImplementationArtifactType createImplementationArtifact(String artifactName, QName nodeType, QName artifactID){ - - final ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - - final DefinitionsType definitions = model.getDocumentRoot().getDefinitions(); - - TNodeTypeImplementation nodeTypeImplementation = null; - - //Test if NodeTypeImplementation for nodeType already exists - for ( TNodeTypeImplementation tempNodeTypeImplementation : definitions.getNodeTypeImplementation() ){ - if ( tempNodeTypeImplementation.getNodeType().toString().equals(nodeType.toString()) ){ - //NodeTypeImplementation already exists - //We are going to add the artifact to the existing implementation - nodeTypeImplementation = tempNodeTypeImplementation; - } - } - - if ( nodeTypeImplementation == null ){ - //NodeTypeImplementation does not exists - final TNodeTypeImplementation newNodeTypeImplementation = ToscaFactory.eINSTANCE.createTNodeTypeImplementation(); - newNodeTypeImplementation.setNodeType( nodeType ); - TImplementationArtifacts implementationArtifacts = ToscaFactory.eINSTANCE.createTImplementationArtifacts(); - newNodeTypeImplementation.setImplementationArtifacts( implementationArtifacts ); - - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( definitions ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { - - @Override - protected void doExecute() { - definitions.getNodeTypeImplementation().add( newNodeTypeImplementation ); - - } - } ); - nodeTypeImplementation = newNodeTypeImplementation; - } - - //Create Implementation Artifact - final ImplementationArtifactType installArtifactType = ToscaFactory.eINSTANCE.createImplementationArtifactType(); - installArtifactType.setArtifactType( new QName("ScriptArtifact") ); - installArtifactType.setArtifactRef( artifactID ); - installArtifactType.setInterfaceName( "Lifecycle" ); - installArtifactType.setOperationName( "execute" ); - - final TNodeTypeImplementation nodeImplementation = nodeTypeImplementation; - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( nodeTypeImplementation ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { - - @Override - protected void doExecute() { - nodeImplementation.getImplementationArtifacts().getImplementationArtifact().add( installArtifactType ); - - } - } ); - - return installArtifactType; - } -} + @Override + protected void doExecute() { + nodeImplementation.getImplementationArtifacts() + .getImplementationArtifact() + .add( installArtifactType ); + } + } ); + } + }
diff --git a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/CreateVMIFeature.java b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/CreateVMIFeature.java index 3ca02ec..3083843 100644 --- a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/CreateVMIFeature.java +++ b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/CreateVMIFeature.java
@@ -157,46 +157,54 @@ }; } - private void createArtifactTemplate(String nodeName, String description, String imageId){ - - //Create Artifact Template - final TArtifactTemplate artifactTemplate = ToscaFactory.eINSTANCE.createTArtifactTemplate(); - - //Create Image Artifact Properties - ImageArtifactPropertiesType imageProperties = Tosca_Elasticity_ExtensionsFactory.eINSTANCE.createImageArtifactPropertiesType(); - imageProperties.setDescription( description ); - - if (imageId!=null){ - imageProperties.setId( imageId ); - } - - // Set the Properties of the Policy Template - PropertiesType properties = ToscaFactory.eINSTANCE.createPropertiesType(); - - // Add the SYBL Policy to the FeatureMap of the Policy's Properties element - Entry e = FeatureMapUtil.createEntry( Tosca_Elasticity_ExtensionsPackage.eINSTANCE.getDocumentRoot_ImageArtifactProperties(), imageProperties ); - properties.getAny().add( e ); - - artifactTemplate.setProperties( properties ); - - artifactTemplate.setId( nodeName + "Image" ); - - // Add the new Artifact Template to the TOSCA Definitions element - - final ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - - DefinitionsType definitions = model.getDocumentRoot().getDefinitions(); - - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( definitions ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { + private void createArtifactTemplate(String description, String artifactRef, String imageId){ + + final ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); + + for (TArtifactTemplate tempArtifactTemplate : model.getDocumentRoot() + .getDefinitions() + .getArtifactTemplate()){ + if (tempArtifactTemplate.getId().equals( imageId )) + return; + } + + //Create Artifact Template + final TArtifactTemplate artifactTemplate = ToscaFactory.eINSTANCE.createTArtifactTemplate(); + + //Create Image Artifact Properties + ImageArtifactPropertiesType imageProperties = Tosca_Elasticity_ExtensionsFactory.eINSTANCE.createImageArtifactPropertiesType(); + imageProperties.setDescription( description ); + + if (imageId!=null){ + imageProperties.setId( imageId ); + } + + // Set the Properties of the Policy Template + PropertiesType properties = ToscaFactory.eINSTANCE.createPropertiesType(); + + // Add the SYBL Policy to the FeatureMap of the Policy's Properties element + Entry e = FeatureMapUtil.createEntry( Tosca_Elasticity_ExtensionsPackage.eINSTANCE.getDocumentRoot_ImageArtifactProperties(), imageProperties ); + properties.getAny().add( e ); + + artifactTemplate.setProperties( properties ); + + //artifactTemplate.setId( imageId ); + artifactTemplate.setId( artifactRef ); + + // Add the new Artifact Template to the TOSCA Definitions element + + DefinitionsType definitions = model.getDocumentRoot().getDefinitions(); + + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( definitions ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { - @Override - protected void doExecute() { - model.getDocumentRoot().getDefinitions().getArtifactTemplate().add( artifactTemplate ); - - } - } ); + @Override + protected void doExecute() { + model.getDocumentRoot().getDefinitions().getArtifactTemplate().add( artifactTemplate ); + + } + } ); - } + } }
diff --git a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/DeleteApplicationComponentFeature.java b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/DeleteApplicationComponentFeature.java index 7c189e5..b678806 100644 --- a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/DeleteApplicationComponentFeature.java +++ b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/DeleteApplicationComponentFeature.java
@@ -19,6 +19,7 @@ import javax.xml.namespace.QName; import org.eclipse.camf.tosca.TArtifactTemplate; +import org.eclipse.camf.tosca.TDeploymentArtifact; import org.eclipse.camf.tosca.TImplementationArtifact; import org.eclipse.camf.tosca.TNodeTemplate; import org.eclipse.camf.tosca.TNodeTypeImplementation; @@ -35,102 +36,109 @@ public class DeleteApplicationComponentFeature extends DefaultDeleteFeature { - public DeleteApplicationComponentFeature( IFeatureProvider fp ) { - super( fp ); - // TODO Auto-generated constructor stub - } + public DeleteApplicationComponentFeature( IFeatureProvider fp ) { + super( fp ); + // TODO Auto-generated constructor stub + } - @Override - public void preDelete( IDeleteContext context ) { - // Removes the relationships related to the deleted application component - Object deletedObject = getFeatureProvider().getBusinessObjectForPictogramElement( context.getPictogramElement() ); - - - TNodeTemplate deletedNodeTemplate = ( TNodeTemplate )deletedObject; - ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - // Delete Policy Templates - if ( deletedNodeTemplate.getPolicies() != null ) - { - for( TPolicy tempPolicy : deletedNodeTemplate.getPolicies().getPolicy() ) - for( TPolicyTemplate tempPolicyTemplate : model.getDocumentRoot() - .getDefinitions() - .getPolicyTemplate() ) - { - if( tempPolicy.getPolicyRef() - .toString() - .compareTo( tempPolicyTemplate.getId() ) == 0 ) - { - model.getDocumentRoot() - .getDefinitions() - .getPolicyTemplate() - .remove( tempPolicyTemplate ); - } - } - } - // Delete Relationships - for( TServiceTemplate tempServiceTemplate : model.getDocumentRoot() - .getDefinitions() - .getServiceTemplate() ) - { - if ( tempServiceTemplate.getTopologyTemplate() != null ){ - for( TRelationshipTemplate tempRelationshipTemplate : tempServiceTemplate.getTopologyTemplate() - .getRelationshipTemplate() ) - { - if( tempRelationshipTemplate.getSourceElement() - .getRef() - .compareTo( deletedNodeTemplate.getId() ) == 0 - || tempRelationshipTemplate.getTargetElement() - .getRef() - .compareTo( deletedNodeTemplate.getId() ) == 0 ) - { - tempServiceTemplate.getTopologyTemplate() - .getRelationshipTemplate() - .remove( tempRelationshipTemplate ); - } - } - } - } - //Delete NodeTypeImplementations - if (model.getDocumentRoot() - .getDefinitions() - .getNodeTypeImplementation() != null){ - QName[] artifactTemplatesIDs = new QName[1]; - for( TNodeTypeImplementation tempNodeTypeImplementation : model.getDocumentRoot() - .getDefinitions() - .getNodeTypeImplementation() ) - { - if ( tempNodeTypeImplementation.getNodeType().toString().equals( deletedNodeTemplate.getName()) ){ - //Find Artifact Templates to be Deleted - { - for (TImplementationArtifact tempImplementationArtifact: tempNodeTypeImplementation.getImplementationArtifacts().getImplementationArtifact()){ - artifactTemplatesIDs[artifactTemplatesIDs.length-1]=tempImplementationArtifact.getArtifactRef(); - } - } - //Delete NodeTypeImplementation - { - model.getDocumentRoot() - .getDefinitions() - .getNodeTypeImplementation() - .remove( tempNodeTypeImplementation ); - } - } - } - - //Delete ArtifactTemplates - for( TArtifactTemplate tempArtifactTemplate : model.getDocumentRoot() - .getDefinitions().getArtifactTemplate()){ - for (QName tempArtifactTemplateID : artifactTemplatesIDs){ - if (tempArtifactTemplate.getId().equals( tempArtifactTemplateID.toString() )){ - //Delete Artifact Template - { - model.getDocumentRoot() - .getDefinitions() - .getArtifactTemplate() - .remove( tempArtifactTemplate ); - } - } - } - } - } - } -} + @Override + public void preDelete( IDeleteContext context ) { + // Removes the relationships related to the deleted application component + Object deletedObject = getFeatureProvider().getBusinessObjectForPictogramElement( context.getPictogramElement() ); + + + TNodeTemplate deletedNodeTemplate = ( TNodeTemplate )deletedObject; + ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); + // Delete Policy Templates + if ( deletedNodeTemplate.getPolicies() != null ) + { + for( TPolicy tempPolicy : deletedNodeTemplate.getPolicies().getPolicy() ) + for( TPolicyTemplate tempPolicyTemplate : model.getDocumentRoot() + .getDefinitions() + .getPolicyTemplate() ) + { + if( tempPolicy.getPolicyRef() + .toString() + .compareTo( tempPolicyTemplate.getId() ) == 0 ) + { + model.getDocumentRoot() + .getDefinitions() + .getPolicyTemplate() + .remove( tempPolicyTemplate ); + } + } + } + // Delete Relationships + for( TServiceTemplate tempServiceTemplate : model.getDocumentRoot() + .getDefinitions() + .getServiceTemplate() ) + { + if ( tempServiceTemplate.getTopologyTemplate() != null ){ + for( TRelationshipTemplate tempRelationshipTemplate : tempServiceTemplate.getTopologyTemplate() + .getRelationshipTemplate() ) + { + if( tempRelationshipTemplate.getSourceElement() + .getRef() + .compareTo( deletedNodeTemplate.getId() ) == 0 + || tempRelationshipTemplate.getTargetElement() + .getRef() + .compareTo( deletedNodeTemplate.getId() ) == 0 ) + { + tempServiceTemplate.getTopologyTemplate() + .getRelationshipTemplate() + .remove( tempRelationshipTemplate ); + } + } + } + } + //Delete NodeTypeImplementations + if (model.getDocumentRoot() + .getDefinitions() + .getNodeTypeImplementation() != null){ + QName[] artifactTemplatesIDs = new QName[1]; + for( TNodeTypeImplementation tempNodeTypeImplementation : model.getDocumentRoot() + .getDefinitions() + .getNodeTypeImplementation() ) + { + if ( tempNodeTypeImplementation.getNodeType().toString().equals( deletedNodeTemplate.getName()) ){ + //Find Artifact Templates to be Deleted + { + for (TImplementationArtifact tempImplementationArtifact: tempNodeTypeImplementation.getImplementationArtifacts().getImplementationArtifact()){ + artifactTemplatesIDs[artifactTemplatesIDs.length-1]=tempImplementationArtifact.getArtifactRef(); + } + } + //Delete NodeTypeImplementation + { + model.getDocumentRoot() + .getDefinitions() + .getNodeTypeImplementation() + .remove( tempNodeTypeImplementation ); + } + } + } + + //Find DeploymentArtifacts to be deleted + if (deletedNodeTemplate.getDeploymentArtifacts() != null){ + for (TDeploymentArtifact tempDeploymentArtifact: deletedNodeTemplate.getDeploymentArtifacts().getDeploymentArtifact()){ + artifactTemplatesIDs[artifactTemplatesIDs.length-1]=tempDeploymentArtifact.getArtifactRef(); + } + } + + //Delete ArtifactTemplates + for( TArtifactTemplate tempArtifactTemplate : model.getDocumentRoot() + .getDefinitions().getArtifactTemplate()){ + for (QName tempArtifactTemplateID : artifactTemplatesIDs){ + if (tempArtifactTemplateID != null && tempArtifactTemplate.getId().equals( tempArtifactTemplateID.toString() )){ + //Delete Artifact Template + { + model.getDocumentRoot() + .getDefinitions() + .getArtifactTemplate() + .remove( tempArtifactTemplate ); + } + } + } + } + } + } + }
diff --git a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/DeleteArtifactTemplateFeature.java b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/DeleteArtifactTemplateFeature.java new file mode 100644 index 0000000..cc95589 --- /dev/null +++ b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/DeleteArtifactTemplateFeature.java
@@ -0,0 +1,86 @@ +package org.eclipse.camf.tosca.editor.features; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.emf.transaction.util.TransactionUtil; +import org.eclipse.graphiti.features.IFeatureProvider; +import org.eclipse.graphiti.features.context.IDeleteContext; +import org.eclipse.graphiti.mm.pictograms.PictogramElement; +import org.eclipse.graphiti.services.Graphiti; +import org.eclipse.graphiti.ui.features.DefaultDeleteFeature; + +import org.eclipse.camf.tosca.TArtifactTemplate; +import org.eclipse.camf.tosca.TImplementationArtifact; +import org.eclipse.camf.tosca.TNodeTemplate; +import org.eclipse.camf.tosca.TNodeTypeImplementation; +import org.eclipse.camf.tosca.editor.ModelHandler; +import org.eclipse.camf.tosca.editor.ToscaModelLayer; + + +public class DeleteArtifactTemplateFeature extends DefaultDeleteFeature{ + + private TNodeTypeImplementation parentNodeTypeImplementation; + + public DeleteArtifactTemplateFeature( IFeatureProvider fp ) { + super( fp ); + } + + @Override + public void preDelete(IDeleteContext context) { + + //TArtifactTemplate + Object deletedObject = getFeatureProvider().getBusinessObjectForPictogramElement( context.getPictogramElement() ); + + TArtifactTemplate deletedArtifactTemplate = (TArtifactTemplate) deletedObject; + + String deletedArtifactTemplateId = deletedArtifactTemplate.getId(); + + //TNodeTemplate parent of TArtifactTemplate + PictogramElement parentPE = Graphiti.getPeService().getPictogramElementParent( context.getPictogramElement() ); + + TNodeTemplate parentNodeTemplate = ( TNodeTemplate ) getFeatureProvider().getBusinessObjectForPictogramElement( parentPE ); + + final ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); + + final EList<TNodeTypeImplementation> nodeTypeImplementations = model.getDocumentRoot().getDefinitions().getNodeTypeImplementation(); + + this.parentNodeTypeImplementation = null; + for (final TNodeTypeImplementation tempNodeTypeImplementation : nodeTypeImplementations){ + if (tempNodeTypeImplementation.getNodeType().toString().compareTo( parentNodeTemplate.getName() )==0){ + this.parentNodeTypeImplementation = tempNodeTypeImplementation; + break; + } + } + + if (this.parentNodeTypeImplementation == null) + return; + + final TNodeTypeImplementation nodeTypeImplementation = parentNodeTypeImplementation; + //for (final TImplementationArtifact tempImplementationArtifact : nodeTypeImplementation.getImplementationArtifacts().getImplementationArtifact()){ + for (int i=0; i<nodeTypeImplementation.getImplementationArtifacts().getImplementationArtifact().size(); i++){ + final TImplementationArtifact tempImplementationArtifact = nodeTypeImplementation.getImplementationArtifacts().getImplementationArtifact().get( i ); + if (tempImplementationArtifact.getArtifactRef().toString().compareTo( deletedArtifactTemplateId )==0){ + //Implementation artifact refers to the TArtifactTemplate to be deleted + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( nodeTypeImplementation ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { + + @Override + protected void doExecute() { + nodeTypeImplementation.getImplementationArtifacts().getImplementationArtifact().remove( tempImplementationArtifact ); + } + } ); + + } + } + + //if there are no more implementation artifacts, delete implementation artifacts element + if (nodeTypeImplementation.getImplementationArtifacts().getImplementationArtifact().size()==0){ + nodeTypeImplementations.remove( nodeTypeImplementation ); + } + + } + +}
diff --git a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/DeleteDeploymentArtifactFeature.java b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/DeleteDeploymentArtifactFeature.java index 9454fe2..c04a4cd 100644 --- a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/DeleteDeploymentArtifactFeature.java +++ b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/DeleteDeploymentArtifactFeature.java
@@ -16,7 +16,12 @@ *******************************************************************************/ package org.eclipse.camf.tosca.editor.features; +import org.eclipse.camf.tosca.TArtifactTemplate; +import org.eclipse.camf.tosca.TDeploymentArtifact; import org.eclipse.camf.tosca.TNodeTemplate; +import org.eclipse.camf.tosca.editor.ModelHandler; +import org.eclipse.camf.tosca.editor.ToscaModelLayer; +import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.graphiti.features.IFeatureProvider; import org.eclipse.graphiti.features.context.IDeleteContext; import org.eclipse.graphiti.mm.pictograms.PictogramElement; @@ -24,35 +29,47 @@ import org.eclipse.graphiti.ui.features.DefaultDeleteFeature; public class DeleteDeploymentArtifactFeature extends DefaultDeleteFeature{ - - private boolean deleteDeploymentArtifact = false; - private TNodeTemplate parentNodeTemplate; + + private boolean deleteDeploymentArtifact = false; + private TNodeTemplate parentNodeTemplate; - public DeleteDeploymentArtifactFeature( IFeatureProvider fp ) { - super( fp ); - // TODO Auto-generated constructor stub - } - - @Override - public void preDelete(IDeleteContext context) { - // Checks whether the node template contained only the deleted deployment artifact - - PictogramElement parentPE = Graphiti.getPeService().getPictogramElementParent( context.getPictogramElement() ); - - TNodeTemplate parentNodeTemplate = ( TNodeTemplate ) getFeatureProvider().getBusinessObjectForPictogramElement( parentPE ); - - if ( parentNodeTemplate.getDeploymentArtifacts().getDeploymentArtifact().size() == 1 ){ - this.deleteDeploymentArtifact = true; - this.parentNodeTemplate = parentNodeTemplate; - } - } - - @Override - public void postDelete(IDeleteContext context) { - // Removes the deployment artifacts element if no more artifacts left - - if ( this.deleteDeploymentArtifact == true ) - this.parentNodeTemplate.setDeploymentArtifacts( null ); - } + public DeleteDeploymentArtifactFeature( IFeatureProvider fp ) { + super( fp ); + } + + @Override + public void preDelete(IDeleteContext context) { + // Checks whether the node template contained only the deleted deployment artifact + + PictogramElement parentPE = Graphiti.getPeService().getPictogramElementParent( context.getPictogramElement() ); + + TNodeTemplate parentNodeTemplate = ( TNodeTemplate ) getFeatureProvider().getBusinessObjectForPictogramElement( parentPE ); + + if ( parentNodeTemplate.getDeploymentArtifacts().getDeploymentArtifact().size() == 1 ){ + this.deleteDeploymentArtifact = true; + this.parentNodeTemplate = parentNodeTemplate; + } + + //Delete corresponding TArtifactTemplate + Object deletedObject = getFeatureProvider().getBusinessObjectForPictogramElement( context.getPictogramElement() ); + TDeploymentArtifact deletedDeploymentArtifact = (TDeploymentArtifact) deletedObject; + String deletedDeploymentArtifactId = deletedDeploymentArtifact.getArtifactRef().toString(); + + final ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); + + for ( TArtifactTemplate tempArtifactTemplate : model.getDocumentRoot().getDefinitions().getArtifactTemplate() ){ + if (tempArtifactTemplate.getId().compareTo( deletedDeploymentArtifactId )==0){ + model.getDocumentRoot().getDefinitions().getArtifactTemplate().remove( tempArtifactTemplate ); + } + } + } + + @Override + public void postDelete(IDeleteContext context) { + // Removes the deployment artifacts element if no more artifacts left + + if ( this.deleteDeploymentArtifact == true ) + this.parentNodeTemplate.setDeploymentArtifacts( null ); + } -} + } \ No newline at end of file
diff --git a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/RenameCompositeComponentFeature.java b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/RenameCompositeComponentFeature.java index d3d2bc0..37ba308 100644 --- a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/RenameCompositeComponentFeature.java +++ b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/features/RenameCompositeComponentFeature.java
@@ -91,7 +91,6 @@ this.hasDoneChanges = true; tServiceTemplate.setName( newName ); - ///////////////////////////////////////////////////////////////////////////////////////////////////// tServiceTemplate.setSubstitutableNodeType(new QName("substituteNode_"+newName)); // Find the substitute TNodeTemplate
diff --git a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/property/ApplicationComponentElasticityRequirementsSection.java b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/property/ApplicationComponentElasticityRequirementsSection.java index 0fb3a93..3b7683d 100644 --- a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/property/ApplicationComponentElasticityRequirementsSection.java +++ b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/property/ApplicationComponentElasticityRequirementsSection.java
@@ -58,6 +58,7 @@ import org.eclipse.camf.tosca.elasticity.TNodeTemplateExtension; import org.eclipse.camf.tosca.elasticity.Tosca_Elasticity_ExtensionsFactory; import org.eclipse.camf.tosca.elasticity.Tosca_Elasticity_ExtensionsPackage; +import org.eclipse.camf.tosca.elementCreators.CreateArtifactTemplate; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; @@ -106,613 +107,625 @@ * Application Component Properties - Elasticity Tab */ public class ApplicationComponentElasticityRequirementsSection - extends GFPropertySection implements ITabbedPropertyConstants +extends GFPropertySection implements ITabbedPropertyConstants { - Composite client; - Section section; - private Table table; - private Button addButton; - private Button removeButton; - private Button addExecutableButton; - TableViewer tableViewer; - List<TPolicy> appComponentElasticityRequirements = new ArrayList<TPolicy>(); - Section sectionRA; - private Table tableResizingActions; - private Button removeButtonRA; - private Button addButtonRA; - private Button conditionButtonRA; - TableViewer tableResizingActionsViewer; - List<TPolicy> appComponentResizingActions = new ArrayList<TPolicy>(); - protected Tosca_Elasticity_ExtensionsFactory elasticityFactory = Tosca_Elasticity_ExtensionsFactory.eINSTANCE; +Composite client; +Section section; +private Table table; +private Button addButton; +private Button removeButton; +private Button addExecutableButton; +TableViewer tableViewer; +List<TPolicy> appComponentElasticityRequirements = new ArrayList<TPolicy>(); +Section sectionRA; +private Table tableResizingActions; +private Button removeButtonRA; +private Button addButtonRA; +private Button conditionButtonRA; +TableViewer tableResizingActionsViewer; +List<TPolicy> appComponentResizingActions = new ArrayList<TPolicy>(); +protected Tosca_Elasticity_ExtensionsFactory elasticityFactory = Tosca_Elasticity_ExtensionsFactory.eINSTANCE; - @Override - public void createControls( final Composite parent, - TabbedPropertySheetPage tabbedPropertySheetPage ) - { - super.createControls( parent, tabbedPropertySheetPage ); - FormToolkit toolkit = new FormToolkit( parent.getDisplay() ); - // Application Component Elasticity Requirements Section - this.section = toolkit.createSection( parent, Section.TITLE_BAR ); - this.section.setText( "Application Component Elasticity Constraints" ); //$NON-NLS-1$ - Composite client = toolkit.createComposite( this.section, SWT.WRAP ); - Composite client1 = toolkit.createComposite( client, SWT.WRAP ); - Composite client2 = toolkit.createComposite( client, SWT.WRAP ); - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - layout.marginTop = 15; - layout.verticalSpacing = 15; - layout.marginWidth = 2; - layout.marginHeight = 2; - client.setLayout( layout ); - layout = new GridLayout(); - layout.numColumns = 1; - client1.setLayout( layout ); - layout = new GridLayout(); - layout.numColumns = 1; - client2.setLayout( layout ); - GridData gd; - this.table = new Table( client1, SWT.BORDER - | SWT.VIRTUAL - | SWT.MULTI - | SWT.FULL_SELECTION ); - this.table.setHeaderVisible( true ); - this.table.setLinesVisible( false ); - this.table.getHorizontalBar().setEnabled( false ); - gd = new GridData( 300, this.table.getItemHeight() * 4 ); - gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; - this.table.setLayoutData( gd ); - TableLayout tableLayout = new TableLayout(); - this.table.setLayout( tableLayout ); - TableColumn nameColumn = new TableColumn( this.table, SWT.CENTER ); - ColumnLayoutData data = new ColumnWeightData( 100 ); - tableLayout.addColumnData( data ); - data = new ColumnWeightData( 100 ); - tableLayout.addColumnData( data ); - data = new ColumnWeightData( 150 ); - tableLayout.addColumnData( data ); - nameColumn.setText( "Constraint" ); //$NON-NLS-1$ - this.tableViewer = new TableViewer( this.table ); - ElasticityConstraintsProvider ERProvider = new ElasticityConstraintsProvider(); - IStructuredContentProvider contentProvider = ERProvider.ERContentProvider; - this.tableViewer.setContentProvider( contentProvider ); - this.tableViewer.setLabelProvider( ERProvider.ERContentLabelProvider ); - this.tableViewer.setInput( this.appComponentElasticityRequirements ); - this.addButton = new Button( client2, SWT.PUSH ); - this.addButton.setText( "Add" ); //$NON-NLS-1$ - gd = new GridData(); - gd.widthHint = 60; - gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - this.addButton.setLayoutData( gd ); - // Listener for Add button - this.addButton.addSelectionListener( new SelectionListener() { +@Override +public void createControls( final Composite parent, + TabbedPropertySheetPage tabbedPropertySheetPage ) +{ + super.createControls( parent, tabbedPropertySheetPage ); + FormToolkit toolkit = new FormToolkit( parent.getDisplay() ); + // Application Component Elasticity Requirements Section + this.section = toolkit.createSection( parent, Section.TITLE_BAR ); + this.section.setText( "Application Component Elasticity Constraints" ); //$NON-NLS-1$ + Composite client = toolkit.createComposite( this.section, SWT.WRAP ); + Composite client1 = toolkit.createComposite( client, SWT.WRAP ); + Composite client2 = toolkit.createComposite( client, SWT.WRAP ); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + layout.marginTop = 15; + layout.verticalSpacing = 15; + layout.marginWidth = 2; + layout.marginHeight = 2; + client.setLayout( layout ); + layout = new GridLayout(); + layout.numColumns = 1; + client1.setLayout( layout ); + layout = new GridLayout(); + layout.numColumns = 1; + client2.setLayout( layout ); + GridData gd; + this.table = new Table( client1, SWT.BORDER + | SWT.VIRTUAL + | SWT.MULTI + | SWT.FULL_SELECTION ); + this.table.setHeaderVisible( true ); + this.table.setLinesVisible( false ); + this.table.getHorizontalBar().setEnabled( false ); + gd = new GridData( 300, this.table.getItemHeight() * 4 ); + gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; + this.table.setLayoutData( gd ); + TableLayout tableLayout = new TableLayout(); + this.table.setLayout( tableLayout ); + TableColumn nameColumn = new TableColumn( this.table, SWT.CENTER ); + ColumnLayoutData data = new ColumnWeightData( 100 ); + tableLayout.addColumnData( data ); + data = new ColumnWeightData( 100 ); + tableLayout.addColumnData( data ); + data = new ColumnWeightData( 150 ); + tableLayout.addColumnData( data ); + nameColumn.setText( "Constraint" ); //$NON-NLS-1$ + this.tableViewer = new TableViewer( this.table ); + ElasticityConstraintsProvider ERProvider = new ElasticityConstraintsProvider(); + IStructuredContentProvider contentProvider = ERProvider.ERContentProvider; + this.tableViewer.setContentProvider( contentProvider ); + this.tableViewer.setLabelProvider( ERProvider.ERContentLabelProvider ); + this.tableViewer.setInput( this.appComponentElasticityRequirements ); + this.addButton = new Button( client2, SWT.PUSH ); + this.addButton.setText( "Add" ); //$NON-NLS-1$ + gd = new GridData(); + gd.widthHint = 60; + gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + this.addButton.setLayoutData( gd ); + // Listener for Add button + this.addButton.addSelectionListener( new SelectionListener() { - @Override - public void widgetSelected( SelectionEvent e ) { - editDataStagingEntry( null ); - } + @Override + public void widgetSelected( SelectionEvent e ) { + editDataStagingEntry( null ); + } - @Override - public void widgetDefaultSelected( final SelectionEvent e ) { - // TODO Auto-generated method stub - } - } ); - - this.removeButton = new Button( client2, SWT.PUSH ); - this.removeButton.setText( "Remove" ); //$NON-NLS-1$ - gd = new GridData(); - gd.widthHint = 60; - gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - this.removeButton.setLayoutData( gd ); - // Listener for Remove button - this.removeButton.addSelectionListener( new SelectionListener() { + @Override + public void widgetDefaultSelected( final SelectionEvent e ) { + // TODO Auto-generated method stub + } + } ); + this.removeButton = new Button( client2, SWT.PUSH ); + this.removeButton.setText( "Remove" ); //$NON-NLS-1$ + gd = new GridData(); + gd.widthHint = 60; + gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + this.removeButton.setLayoutData( gd ); + // Listener for Remove button + this.removeButton.addSelectionListener( new SelectionListener() { - @Override - public void widgetSelected( final SelectionEvent e ) { - removeApplicationComponentElasticityRequirement( getSelectedObject() ); - } + @Override + public void widgetSelected( final SelectionEvent e ) { + removeApplicationComponentElasticityRequirement( getSelectedObject() ); + } - @Override - public void widgetDefaultSelected( final SelectionEvent e ) { - // TODO Auto-generated method stub - } - } ); - // Add section components to the toolkit - toolkit.adapt( this.table, true, true ); - toolkit.adapt( this.addButton, true, true ); - toolkit.adapt( this.removeButton, true, true ); - this.section.setClient( client ); - // Application Component Elasticity Actions Section - this.sectionRA = toolkit.createSection( parent, Section.TITLE_BAR ); - this.sectionRA.setText( "Elasticity Strategies" ); //$NON-NLS-1$ - Composite clientRA = toolkit.createComposite( this.sectionRA, SWT.WRAP ); - Composite clientRA1 = toolkit.createComposite( clientRA, SWT.WRAP ); - Composite clientRA2 = toolkit.createComposite( clientRA, SWT.WRAP ); - GridLayout layoutRA; - layoutRA = new GridLayout(); - layoutRA.numColumns = 2; - layoutRA.marginTop = 15; - layoutRA.verticalSpacing = 15; - layoutRA.marginWidth = 2; - layoutRA.marginHeight = 2; - clientRA.setLayout( layoutRA ); - layoutRA = new GridLayout(); - layoutRA.numColumns = 1; - clientRA1.setLayout( layoutRA ); - layoutRA = new GridLayout(); - layoutRA.numColumns = 1; - clientRA2.setLayout( layoutRA ); - this.tableResizingActions = new Table( clientRA1, SWT.BORDER - | SWT.VIRTUAL - | SWT.MULTI - | SWT.FULL_SELECTION ); - this.tableResizingActions.setHeaderVisible( true ); - this.tableResizingActions.setLinesVisible( false ); - this.tableResizingActions.getHorizontalBar().setEnabled( false ); - GridData gdRA; - gdRA = new GridData( 300, this.tableResizingActions.getItemHeight() * 4 ); - gdRA.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - gdRA.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; - this.tableResizingActions.setLayoutData( gdRA ); - TableLayout tableLayoutRA = new TableLayout(); - this.tableResizingActions.setLayout( tableLayoutRA ); - TableColumn nameColumnRA = new TableColumn( this.tableResizingActions, - SWT.CENTER ); - nameColumnRA.setText( "Strategy" ); //$NON-NLS-1$ - nameColumnRA.setWidth( 100 ); - ColumnWeightData dataRA = new ColumnWeightData( 100 ); - tableLayoutRA.addColumnData( dataRA ); - // Set the Elasticity Actions table viewer - ResizingActionsProvider RAProvider = new ResizingActionsProvider(); - this.tableResizingActionsViewer = new TableViewer( this.tableResizingActions ); - IStructuredContentProvider contentProviderRA = RAProvider.RAContentProvider; - this.tableResizingActionsViewer.setContentProvider( contentProviderRA ); - this.tableResizingActionsViewer.setLabelProvider( RAProvider.RAContentLabelProvider ); - this.tableResizingActionsViewer.setInput( this.appComponentResizingActions ); - // Add Elasticity Strategy button - this.addButtonRA = new Button( clientRA2, SWT.PUSH ); - this.addButtonRA.setText( "Add" ); //$NON-NLS-1$ - // Listener for Adding Elasticity Strategy button - this.addButtonRA.addSelectionListener( new SelectionListener() { + @Override + public void widgetDefaultSelected( final SelectionEvent e ) { + // TODO Auto-generated method stub + } + } ); + // Add section components to the toolkit + toolkit.adapt( this.table, true, true ); + toolkit.adapt( this.addButton, true, true ); + toolkit.adapt( this.removeButton, true, true ); + this.section.setClient( client ); + // Application Component Elasticity Actions Section + this.sectionRA = toolkit.createSection( parent, Section.TITLE_BAR ); + this.sectionRA.setText( "Elasticity Strategies" ); //$NON-NLS-1$ + Composite clientRA = toolkit.createComposite( this.sectionRA, SWT.WRAP ); + Composite clientRA1 = toolkit.createComposite( clientRA, SWT.WRAP ); + Composite clientRA2 = toolkit.createComposite( clientRA, SWT.WRAP ); + GridLayout layoutRA; + layoutRA = new GridLayout(); + layoutRA.numColumns = 2; + layoutRA.marginTop = 15; + layoutRA.verticalSpacing = 15; + layoutRA.marginWidth = 2; + layoutRA.marginHeight = 2; + clientRA.setLayout( layoutRA ); + layoutRA = new GridLayout(); + layoutRA.numColumns = 1; + clientRA1.setLayout( layoutRA ); + layoutRA = new GridLayout(); + layoutRA.numColumns = 1; + clientRA2.setLayout( layoutRA ); + this.tableResizingActions = new Table( clientRA1, SWT.BORDER + | SWT.VIRTUAL + | SWT.MULTI + | SWT.FULL_SELECTION ); + this.tableResizingActions.setHeaderVisible( true ); + this.tableResizingActions.setLinesVisible( false ); + this.tableResizingActions.getHorizontalBar().setEnabled( false ); + GridData gdRA; + gdRA = new GridData( 300, this.tableResizingActions.getItemHeight() * 4 ); + gdRA.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + gdRA.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; + this.tableResizingActions.setLayoutData( gdRA ); + TableLayout tableLayoutRA = new TableLayout(); + this.tableResizingActions.setLayout( tableLayoutRA ); + TableColumn nameColumnRA = new TableColumn( this.tableResizingActions, + SWT.CENTER ); + nameColumnRA.setText( "Strategy" ); //$NON-NLS-1$ + nameColumnRA.setWidth( 100 ); + ColumnWeightData dataRA = new ColumnWeightData( 100 ); + tableLayoutRA.addColumnData( dataRA ); + // Set the Elasticity Actions table viewer + ResizingActionsProvider RAProvider = new ResizingActionsProvider(); + this.tableResizingActionsViewer = new TableViewer( this.tableResizingActions ); + IStructuredContentProvider contentProviderRA = RAProvider.RAContentProvider; + this.tableResizingActionsViewer.setContentProvider( contentProviderRA ); + this.tableResizingActionsViewer.setLabelProvider( RAProvider.RAContentLabelProvider ); + this.tableResizingActionsViewer.setInput( this.appComponentResizingActions ); + // Add Elasticity Strategy button + this.addButtonRA = new Button( clientRA2, SWT.PUSH ); + this.addButtonRA.setText( "Add" ); //$NON-NLS-1$ + // Listener for Adding Elasticity Strategy button + this.addButtonRA.addSelectionListener( new SelectionListener() { - @Override - public void widgetSelected( final SelectionEvent e ) { - editDataStagingEntryRA( getSelectedObject() ); - } + @Override + public void widgetSelected( final SelectionEvent e ) { + editDataStagingEntryRA( getSelectedObject() ); + } - @Override - public void widgetDefaultSelected( final SelectionEvent e ) { - // TODO Auto-generated method stub - } - } ); - gdRA = new GridData(); - gdRA.widthHint = 80; - gdRA.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - this.addButtonRA.setLayoutData( gdRA ); - - //////////////////////////////////////////////////////////////////// - - // Add Elasticity Strategy Executable button - this.addExecutableButton = new Button( clientRA2, SWT.PUSH ); - this.addExecutableButton.setText( "Exectutable" ); //$NON-NLS-1$ - // Listener for Adding Elasticity Strategy button - this.addExecutableButton.addSelectionListener( new SelectionListener() { + @Override + public void widgetDefaultSelected( final SelectionEvent e ) { + // TODO Auto-generated method stub + } + } ); + gdRA = new GridData(); + gdRA.widthHint = 80; + gdRA.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + this.addButtonRA.setLayoutData( gdRA ); + // ////////////////////////////////////////////////////////////////// + // Add Elasticity Strategy Executable button + this.addExecutableButton = new Button( clientRA2, SWT.PUSH ); + this.addExecutableButton.setText( "Exectutable" ); //$NON-NLS-1$ + // Listener for Adding Elasticity Strategy button + this.addExecutableButton.addSelectionListener( new SelectionListener() { - @Override - public void widgetSelected( final SelectionEvent e ) { - addResizingActionExecutable( parent, getSelectedElasticityStrategy() ); - } + @Override + public void widgetSelected( final SelectionEvent e ) { + addResizingActionExecutable( parent, getSelectedElasticityStrategy() ); + } - @Override - public void widgetDefaultSelected( final SelectionEvent e ) { - // TODO Auto-generated method stub - } - } ); - gdRA = new GridData(); - gdRA.widthHint = 80; - gdRA.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - this.addExecutableButton.setLayoutData( gdRA ); - + @Override + public void widgetDefaultSelected( final SelectionEvent e ) { + // TODO Auto-generated method stub + } + } ); + gdRA = new GridData(); + gdRA.widthHint = 80; + gdRA.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + this.addExecutableButton.setLayoutData( gdRA ); + // ///////////////////////////////////////////////////////////////// + this.removeButtonRA = new Button( clientRA2, SWT.PUSH ); + this.removeButtonRA.setText( "Remove" ); //$NON-NLS-1$ + // Listener for Remove Elasticity Strategy button + this.removeButtonRA.addSelectionListener( new SelectionListener() { - /////////////////////////////////////////////////////////////////// - - - this.removeButtonRA = new Button( clientRA2, SWT.PUSH ); - this.removeButtonRA.setText( "Remove" ); //$NON-NLS-1$ - // Listener for Remove Elasticity Strategy button - this.removeButtonRA.addSelectionListener( new SelectionListener() { + @Override + public void widgetSelected( final SelectionEvent e ) { + removeApplicationComponentResizingAction( getSelectedElasticityStrategy() ); + } - @Override - public void widgetSelected( final SelectionEvent e ) { - removeApplicationComponentResizingAction( getSelectedElasticityStrategy() ); - } + @Override + public void widgetDefaultSelected( final SelectionEvent e ) { + // TODO Auto-generated method stub + } + } ); + gdRA = new GridData(); + gdRA.widthHint = 80; + gdRA.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + this.removeButtonRA.setLayoutData( gdRA ); + this.conditionButtonRA = new Button( clientRA2, SWT.PUSH ); + this.conditionButtonRA.setText( "Condition" ); //$NON-NLS-1$ + // Listener for Remove Elasticity Strategy button + this.conditionButtonRA.addSelectionListener( new SelectionListener() { - @Override - public void widgetDefaultSelected( final SelectionEvent e ) { - // TODO Auto-generated method stub - } - } ); - gdRA = new GridData(); - gdRA.widthHint = 80; - gdRA.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - this.removeButtonRA.setLayoutData( gdRA ); - this.conditionButtonRA = new Button( clientRA2, SWT.PUSH ); - this.conditionButtonRA.setText( "Condition" ); //$NON-NLS-1$ - // Listener for Remove Elasticity Strategy button - this.conditionButtonRA.addSelectionListener( new SelectionListener() { + @Override + public void widgetSelected( final SelectionEvent e ) { + addStrategyCondition( getSelectedElasticityStrategy() ); + } - @Override - public void widgetSelected( final SelectionEvent e ) { - addStrategyCondition( getSelectedElasticityStrategy() ); - } + @Override + public void widgetDefaultSelected( final SelectionEvent e ) { + // TODO Auto-generated method stub + } + } ); + gdRA = new GridData(); + gdRA.widthHint = 80; + gdRA.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + this.conditionButtonRA.setLayoutData( gdRA ); + // Add section components to the toolkit + toolkit.adapt( this.tableResizingActions, true, true ); + toolkit.adapt( this.removeButtonRA, true, true ); + toolkit.adapt( this.addButtonRA, true, true ); + // toolkit.adapt( this.uploadButtonRA, true, true ); + toolkit.adapt( this.conditionButtonRA, true, true ); + toolkit.adapt( this.addExecutableButton, true, true ); + this.sectionRA.setClient( clientRA ); +} - @Override - public void widgetDefaultSelected( final SelectionEvent e ) { - // TODO Auto-generated method stub - } - } ); - gdRA = new GridData(); - gdRA.widthHint = 80; - gdRA.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - this.conditionButtonRA.setLayoutData( gdRA ); - // Add section components to the toolkit - toolkit.adapt( this.tableResizingActions, true, true ); - toolkit.adapt( this.removeButtonRA, true, true ); - toolkit.adapt( this.addButtonRA, true, true ); - // toolkit.adapt( this.uploadButtonRA, true, true ); - toolkit.adapt( this.conditionButtonRA, true, true ); - - toolkit.adapt( this.addExecutableButton, true, true); - this.sectionRA.setClient( clientRA ); - } +// Add Application Component Elasticity Requirement +void editDataStagingEntry( final TPolicy selectedObject ) { + ElasticityConstraintDialog dialog; + if( selectedObject == null ) { + // Add button is pressed + dialog = new ElasticityConstraintDialog( this.section.getShell(), + "Application Component" ); //$NON-NLS-1$ + if( dialog.open() == Window.OK ) { + String newElasticityConstraint = dialog.getElasticityConstraint(); - // Add Application Component Elasticity Requirement - void editDataStagingEntry( final TPolicy selectedObject ) { - ElasticityConstraintDialog dialog; - if( selectedObject == null ) { - // Add button is pressed - dialog = new ElasticityConstraintDialog( this.section.getShell(), - "Application Component" ); //$NON-NLS-1$ - if( dialog.open() == Window.OK ) { - String newElasticityConstraint = dialog.getElasticityConstraint(); - + if( newElasticityConstraint != null ) { - if (newElasticityConstraint.contains( "<" )){ + if( newElasticityConstraint.contains( "<" ) ) { String[] cond = newElasticityConstraint.split( "<" ); - newElasticityConstraint = cond[0] + "<" + cond[1]; - } - else if (newElasticityConstraint.contains( ">" )){ + newElasticityConstraint = cond[ 0 ] + "<" + cond[ 1 ]; + } else if( newElasticityConstraint.contains( ">" ) ) { String[] cond = newElasticityConstraint.split( ">" ); - newElasticityConstraint = cond[0] + ">" + cond[1]; + newElasticityConstraint = cond[ 0 ] + ">" + cond[ 1 ]; } - - SyblElasticityRequirementsDescription newSYBLConstraint = dialog.getSYBLConstraint(); - if( newElasticityConstraint != null ) { - // Add Application Component Elasticity Requirement to TOSCA - PictogramElement pe = getSelectedPictogramElement(); - Object bo = null; - if( pe != null ) { - bo = Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( pe ); - } - final TNodeTemplateExtension nodeTemplate; - if( bo instanceof TDeploymentArtifact ) { - PictogramElement parentPE = Graphiti.getPeService() - .getPictogramElementParent( pe ); - nodeTemplate = ( TNodeTemplateExtension )Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( parentPE ); - } else { // bo instanceof TNodeTemplate - nodeTemplate = ( TNodeTemplateExtension )bo; - } - if( nodeTemplate.getPolicies() == null ) { - final PoliciesType nodePolicyList = ToscaFactory.eINSTANCE.createPoliciesType(); - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( nodeTemplate ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { - - @Override - protected void doExecute() { - nodeTemplate.setPolicies( nodePolicyList ); - } - } ); - } - PoliciesType nodePolicyList = nodeTemplate.getPolicies(); - final EList<TPolicy> policy = nodePolicyList.getPolicy(); - final TPolicy newPolicy = createNewPolicy( "Constraint", - newElasticityConstraint, newSYBLConstraint ); + // Add Application Component Elasticity Requirement to TOSCA + PictogramElement pe = getSelectedPictogramElement(); + Object bo = null; + if( pe != null ) { + bo = Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( pe ); + } + final TNodeTemplateExtension nodeTemplate; + if( bo instanceof TDeploymentArtifact ) { + PictogramElement parentPE = Graphiti.getPeService() + .getPictogramElementParent( pe ); + nodeTemplate = ( TNodeTemplateExtension )Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( parentPE ); + } else { // bo instanceof TNodeTemplate + nodeTemplate = ( TNodeTemplateExtension )bo; + } + if( nodeTemplate.getPolicies() == null ) { + final PoliciesType nodePolicyList = ToscaFactory.eINSTANCE.createPoliciesType(); TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( nodeTemplate ); editingDomain.getCommandStack() .execute( new RecordingCommand( editingDomain ) { @Override protected void doExecute() { - policy.add( newPolicy ); + nodeTemplate.setPolicies( nodePolicyList ); } } ); - // Add Application Component Elasticity Requirement to temp list - this.appComponentElasticityRequirements.add( newPolicy ); - this.tableViewer.refresh(); - } else { } + PoliciesType nodePolicyList = nodeTemplate.getPolicies(); + final EList<TPolicy> policy = nodePolicyList.getPolicy(); + final TPolicy newPolicy = ToscaFactory.eINSTANCE.createTPolicy(); + String type = "Constraint"; + QName policyTypeName = new QName( "http://www.example.org/SYBL", + type, + null ); + newPolicy.setPolicyType( policyTypeName ); + newPolicy.setName( type.toUpperCase() + " " + newElasticityConstraint ); + + String id = "C" + ( ( Integer )nodeTemplate.hashCode() ).toString() + nodePolicyList.getPolicy().size(); + QName qnamePolicyTemplate = new QName( id ); + newPolicy.setPolicyRef( qnamePolicyTemplate ); + + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( nodeTemplate ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { + + @Override + protected void doExecute() { + policy.add( newPolicy ); + } + } ); + // Add Application Component Elasticity Requirement to temp list + this.appComponentElasticityRequirements.add( newPolicy ); + this.tableViewer.refresh(); } } } +} - void editDataStagingEntryRA( final TPolicy selectedObject ) { - ElasticityStrategyDialog dialog; - if( selectedObject == null ) { - // Add button is pressed - dialog = new ElasticityStrategyDialog( this.section.getShell(), - "Application Component" ); //$NON-NLS-1$ - if( dialog.open() == Window.OK ) { - String newElasticityStrategy = dialog.getElasticityStrategy(); - SyblElasticityRequirementsDescription newSYBLStrategy = dialog.getSYBLStrategy(); - if( newElasticityStrategy != null ) { - // Add Application Component Elasticity Strategy to TOSCA - PictogramElement pe = getSelectedPictogramElement(); - Object bo = null; - if( pe != null ) { - bo = Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( pe ); - } - final TNodeTemplateExtension nodeTemplate; - if( bo instanceof TDeploymentArtifact ) { - PictogramElement parentPE = Graphiti.getPeService() - .getPictogramElementParent( pe ); - nodeTemplate = ( TNodeTemplateExtension )Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( parentPE ); - } else { // bo instanceof TNodeTemplate - nodeTemplate = ( TNodeTemplateExtension )bo; - } - if( nodeTemplate.getPolicies() == null ) { - final PoliciesType nodePolicyList = ToscaFactory.eINSTANCE.createPoliciesType(); - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { +void editDataStagingEntryRA( final TPolicy selectedObject ) { + ElasticityStrategyDialog dialog; + if( selectedObject == null ) { + // Add button is pressed + + PictogramElement pe = getSelectedPictogramElement(); + Object bo = null; + if( pe != null ) { + bo = Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( pe ); + } + final TNodeTemplateExtension nodeTemplate; + if( bo instanceof TDeploymentArtifact ) { + PictogramElement parentPE = Graphiti.getPeService() + .getPictogramElementParent( pe ); + nodeTemplate = ( TNodeTemplateExtension )Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( parentPE ); + } else { // bo instanceof TNodeTemplate + nodeTemplate = ( TNodeTemplateExtension )bo; + } + + dialog = new ElasticityStrategyDialog( this.section.getShell(), + "Application Component", nodeTemplate.getName() ); //$NON-NLS-1$ + if( dialog.open() == Window.OK ) { + String newElasticityStrategy = dialog.getElasticityStrategy(); + if( newElasticityStrategy != null ) { + // Add Application Component Elasticity Strategy to TOSCA - @Override - protected void doExecute() { - nodeTemplate.setPolicies( nodePolicyList ); - } - } ); - } - PoliciesType nodePolicyList = nodeTemplate.getPolicies(); - final EList<TPolicy> policy = nodePolicyList.getPolicy(); - final TPolicy newPolicy = createNewPolicy( "Strategy", - newElasticityStrategy, newSYBLStrategy ); + if( nodeTemplate.getPolicies() == null ) { + final PoliciesType nodePolicyList = ToscaFactory.eINSTANCE.createPoliciesType(); TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); editingDomain.getCommandStack() .execute( new RecordingCommand( editingDomain ) { @Override protected void doExecute() { - policy.add( newPolicy ); + nodeTemplate.setPolicies( nodePolicyList ); } } ); - this.appComponentResizingActions.add( newPolicy ); - this.tableResizingActionsViewer.refresh(); - } else { - // Edit } + PoliciesType nodePolicyList = nodeTemplate.getPolicies(); + final EList<TPolicy> policy = nodePolicyList.getPolicy(); + final TPolicy newPolicy = ToscaFactory.eINSTANCE.createTPolicy(); + String type = "Strategy"; + QName policyTypeName = new QName( "http://www.example.org/SYBL", + type, + null ); + newPolicy.setPolicyType( policyTypeName ); + newPolicy.setName( type.toUpperCase() + " " + newElasticityStrategy ); + + String id = "C" + ( ( Integer )nodeTemplate.hashCode() ).toString() + nodePolicyList.getPolicy().size(); + QName qnamePolicyTemplate = new QName( id ); + newPolicy.setPolicyRef( qnamePolicyTemplate ); + + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { + + @Override + protected void doExecute() { + policy.add( newPolicy ); + } + } ); + this.appComponentResizingActions.add( newPolicy ); + this.tableResizingActionsViewer.refresh(); + } else { + // Edit } } } +} +void addStrategyCondition( final TPolicy selectedObject ) { + if( selectedObject == null ) + return; + TNodeTemplate nodeTemplate = null; + if( getSelectedPictogramElement() != null ) + nodeTemplate = ( TNodeTemplate )Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( getSelectedPictogramElement() ); + ElasticityConditionDialog dialog; + ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); + dialog = new ElasticityConditionDialog( this.section.getShell(), + "Application Component", + model, + selectedObject.getName() ); //$NON-NLS-1$ + String newElasticityCondition = null; + if( dialog.open() == Window.OK ) { + newElasticityCondition = dialog.getSelectedCondition(); + } + if( newElasticityCondition == null ) + return; + // final String condition = newElasticityCondition; + String newCond = newElasticityCondition; + if( newCond.contains( "<" ) ) { + String[] cond = newCond.split( "<" ); + newCond = cond[ 0 ] + "<" + cond[ 1 ]; + } else if( newCond.contains( ">" ) ) { + String[] cond = newCond.split( ">" ); + newCond = cond[ 0 ] + ">" + cond[ 1 ]; + } + final String condition = newCond; + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( nodeTemplate ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { - // type is either "Constraint" or "Strategy" - TPolicy createNewPolicy(String type, String policyName, SyblElasticityRequirementsDescription syblPolicy){ + @Override + protected void doExecute() { + String[] strategy = selectedObject.getName().split( "STRATEGY" ); + selectedObject.setName( strategy[ 0 ] + + "STRATEGY " + + condition + + " :" + + strategy[ 1 ] ); + } + } ); + this.tableResizingActionsViewer.refresh(); +} - // Create Policy Template - - final TPolicyTemplate newPolicyTemplate = ToscaFactory.eINSTANCE.createTPolicyTemplate(); - - QName policyTypeName = new QName( "http://www.example.org/SYBL", type, null ); - - newPolicyTemplate.setType( policyTypeName ); - - String id = "C" + ( ( Integer )newPolicyTemplate.hashCode() ).toString(); - - newPolicyTemplate.setId( id ); +// Remove the selected Application Component Elasticity Requirement from TOSCA +void removeApplicationComponentElasticityRequirement( final TPolicy selectedObject ) +{ + PictogramElement pe = getSelectedPictogramElement(); + Object bo = null; + if( pe != null ) { + bo = Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( pe ); + } + final TNodeTemplateExtension nodeTemplate; + if( bo instanceof TDeploymentArtifact ) { + PictogramElement parentPE = Graphiti.getPeService() + .getPictogramElementParent( pe ); + nodeTemplate = ( TNodeTemplateExtension )Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( parentPE ); + } else { // bo instanceof TNodeTemplate + nodeTemplate = ( TNodeTemplateExtension )bo; + } + PoliciesType nodePolicyList = nodeTemplate.getPolicies(); + final EList<TPolicy> policy = nodePolicyList.getPolicy(); + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { - - // Set the Properties of the Policy Template - - PropertiesType properties = ToscaFactory.eINSTANCE.createPropertiesType(); - - // Add the SYBL Policy to the FeatureMap of the Policy's Properties element - Entry e = FeatureMapUtil.createEntry( SyblPackage.eINSTANCE.getDocumentRoot_SYBLElasticityRequirementsDescription(), syblPolicy ); - properties.getAny().add( e ); - - newPolicyTemplate.setProperties( properties ); - - // Add the new Policy Template to the TOSCA Definitions element - - final ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - - DefinitionsType definitions = model.getDocumentRoot().getDefinitions(); - - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( definitions ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { - - @Override - protected void doExecute() { - model.getDocumentRoot().getDefinitions().getPolicyTemplate().add( newPolicyTemplate ); - + @Override + protected void doExecute() { + for( TPolicy tempPolicy : policy ) { + if( tempPolicy.getPolicyType().toString().contains( "Constraint" ) ) //$NON-NLS-1$ + if( tempPolicy.getName().compareTo( selectedObject.getName() ) == 0 ) + { + policy.remove( tempPolicy ); + if( policy.size() == 0 ) + nodeTemplate.setPolicies( null ); + break; + } } - } ); - - // Assign the created Policy Template to the new Policy - - TPolicy newPolicy = ToscaFactory.eINSTANCE.createTPolicy(); - - QName qnamePolicyTemplate = new QName( newPolicyTemplate.getId() ); - - newPolicy.setPolicyType( policyTypeName ); - - newPolicy.setPolicyRef( qnamePolicyTemplate ); - - newPolicy.setName( type.toUpperCase() + " " + policyName ); - - return newPolicy; - } - - void addStrategyCondition( final TPolicy selectedObject ) { - if( selectedObject == null ) - return; - TNodeTemplate nodeTemplate = null; - if( getSelectedPictogramElement() != null ) - nodeTemplate = ( TNodeTemplate )Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( getSelectedPictogramElement() ); - ElasticityConditionDialog dialog; - ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - dialog = new ElasticityConditionDialog( this.section.getShell(), - "Application Component", - model, - selectedObject.getName() ); //$NON-NLS-1$ - String newElasticityCondition = null; - ConditionType policyCondition = null; - if( dialog.open() == Window.OK ) { - newElasticityCondition = dialog.getSelectedCondition(); - policyCondition = dialog.getSYBLCondition(); - } - if( newElasticityCondition == null ) - return; - - //final String condition = newElasticityCondition; - - String newCond = newElasticityCondition; - - if (newCond.contains( "<" )){ - String[] cond = newCond.split( "<" ); - newCond = cond[0] + "<" + cond[1]; - } - else if (newCond.contains( ">" )){ - String[] cond = newCond.split( ">" ); - newCond = cond[0] + ">" + cond[1]; - } - - final String condition = newCond; - - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( nodeTemplate ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { + } + } ); + this.appComponentElasticityRequirements.remove( selectedObject ); + this.tableViewer.refresh(); +} - @Override - protected void doExecute() { - String[] strategy = selectedObject.getName().split( "STRATEGY" ); - selectedObject.setName( strategy[ 0 ] - + "STRATEGY " - + condition - + " :" + strategy[ 1 ] ); +// Return the selected Elasticity Requirement +TPolicy getSelectedObject() { + TPolicy result = null; + IStructuredSelection selection = ( IStructuredSelection )this.tableViewer.getSelection(); + Object obj = selection.getFirstElement(); + result = ( TPolicy )obj; + return result; +} + +// Return the selected Elasticity Action +TPolicy getSelectedElasticityStrategy() { + TPolicy result = null; + IStructuredSelection selection = ( IStructuredSelection )this.tableResizingActionsViewer.getSelection(); + Object obj = selection.getFirstElement(); + result = ( TPolicy )obj; + return result; +} + +/** + * Get Application Component Elasticity Actions + */ +public void getResizingActions() { + PictogramElement pe = getSelectedPictogramElement(); + Object bo = null; + if( pe != null ) { + bo = Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( pe ); + } + final TNodeTemplateExtension appComponent; + if( bo instanceof TDeploymentArtifact ) { + PictogramElement parentPE = Graphiti.getPeService() + .getPictogramElementParent( pe ); + appComponent = ( TNodeTemplateExtension )Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( parentPE ); + } else { // bo instanceof TNodeTemplate + appComponent = ( TNodeTemplateExtension )bo; + } + + if( appComponent == null || appComponent.getPolicies() == null ) + return; + PoliciesType nodePolicyList = appComponent.getPolicies(); + for( TPolicy tempPolicy : nodePolicyList.getPolicy() ) { + if( tempPolicy.getPolicyType().toString().contains( "Strategy" ) ) //$NON-NLS-1$ + this.appComponentResizingActions.add( tempPolicy ); + } +} + +/** + * Get Application Component Elasticity Constraints + */ +public void getElasticityConstraints() { + PictogramElement pe = getSelectedPictogramElement(); + Object bo = null; + if( pe != null ) { + bo = Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( pe ); + } + final TNodeTemplateExtension appComponent; + if( bo instanceof TDeploymentArtifact ) { + PictogramElement parentPE = Graphiti.getPeService() + .getPictogramElementParent( pe ); + appComponent = ( TNodeTemplateExtension )Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( parentPE ); + } else { // bo instanceof TNodeTemplate + appComponent = ( TNodeTemplateExtension )bo; + } + + if( appComponent == null || appComponent.getPolicies() == null ) + return; + PoliciesType nodePolicyList = appComponent.getPolicies(); + for( TPolicy tempPolicy : nodePolicyList.getPolicy() ) { + if( tempPolicy.getPolicyType().toString().contains( "Constraint" ) ) //$NON-NLS-1$ + this.appComponentElasticityRequirements.add( tempPolicy ); + } +} + +// Remove Application Component Elasticity Action +void removeApplicationComponentResizingAction( final TPolicy selectedObject ) +{ + PictogramElement pe = getSelectedPictogramElement(); + Object bo = null; + if( pe != null ) { + bo = Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( pe ); + } + final TNodeTemplateExtension nodeTemplate; + if( bo instanceof TDeploymentArtifact ) { + PictogramElement parentPE = Graphiti.getPeService() + .getPictogramElementParent( pe ); + nodeTemplate = ( TNodeTemplateExtension )Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( parentPE ); + } else { // bo instanceof TNodeTemplate + nodeTemplate = ( TNodeTemplateExtension )bo; + } + PoliciesType nodePolicyList = nodeTemplate.getPolicies(); + final EList<TPolicy> policy = nodePolicyList.getPolicy(); + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { + + @Override + protected void doExecute() { + for( TPolicy tempPolicy : policy ) { + if( tempPolicy.getPolicyType().toString().contains( "Strategy" ) ) //$NON-NLS-1$ + if( tempPolicy.getName().compareTo( selectedObject.getName() ) == 0 ) + { + policy.remove( tempPolicy ); + if( policy.size() == 0 ) + nodeTemplate.setPolicies( null ); + break; + } } - } ); - this.tableResizingActionsViewer.refresh(); - - //addPolicyCondition( selectedObject, policyCondition); - } - -// void addPolicyCondition(final TPolicy selectedPolicy, final ConditionType policyCondition){ -// -// ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); -// EList<TPolicyTemplate> policyTemplates = model.getDocumentRoot().getDefinitions().getPolicyTemplate(); -// TPolicyTemplate policyTemplate = null; -// for ( TPolicyTemplate tempPolicyTemplate : policyTemplates ){ -// if (tempPolicyTemplate.getId().toString().equals(selectedPolicy.getPolicyRef().toString())){ -// policyTemplate = tempPolicyTemplate; -// break; -// } -// } -// -// final SyblElasticityRequirementsDescription syblPolicy = (SyblElasticityRequirementsDescription) policyTemplate.getProperties().getAny().get(0).getValue(); -// TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( policyTemplate ); -// editingDomain.getCommandStack() -// .execute( new RecordingCommand( editingDomain ) { -// -// @Override -// protected void doExecute() { -// syblPolicy.getSYBLSpecification().get( 0 ).getStrategy().get( 0 ).setCondition( policyCondition ); -// } -// } ); -// } + } + } ); + this.appComponentResizingActions.remove( selectedObject ); + this.tableResizingActionsViewer.refresh(); +} - // Remove the selected Application Component Elasticity Requirement from TOSCA - void removeApplicationComponentElasticityRequirement( final TPolicy selectedObject ) - { - PictogramElement pe = getSelectedPictogramElement(); - Object bo = null; - if( pe != null ) { - bo = Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( pe ); - } - final TNodeTemplateExtension nodeTemplate; - if( bo instanceof TDeploymentArtifact ) { - PictogramElement parentPE = Graphiti.getPeService() - .getPictogramElementParent( pe ); - nodeTemplate = ( TNodeTemplateExtension )Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( parentPE ); - } else { // bo instanceof TNodeTemplate - nodeTemplate = ( TNodeTemplateExtension )bo; - } - PoliciesType nodePolicyList = nodeTemplate.getPolicies(); - final EList<TPolicy> policy = nodePolicyList.getPolicy(); - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { - - @Override - protected void doExecute() { - for( TPolicy tempPolicy : policy ) { - if( tempPolicy.getPolicyType().toString().contains( "Constraint" ) ) //$NON-NLS-1$ - if( tempPolicy.getName().compareTo( selectedObject.getName() ) == 0 ) - { - policy.remove( tempPolicy ); - if( policy.size() == 0 ) - nodeTemplate.setPolicies( null ); - // remove corresponding Policy Template - String removedPolicyId = tempPolicy.getPolicyRef().toString(); - ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - DefinitionsType toscaDefinitions = model.getDocumentRoot() - .getDefinitions(); - final EList<TPolicyTemplate> policyTemplate = toscaDefinitions.getPolicyTemplate(); - for( TPolicyTemplate tempPolicyTemplate : policyTemplate ) { - if( tempPolicyTemplate.getId().equals( removedPolicyId ) ) { - policyTemplate.remove( tempPolicyTemplate ); - } - } - break; - } - } - } - } ); - this.appComponentElasticityRequirements.remove( selectedObject ); - this.tableViewer.refresh(); - } - - // Return the selected Elasticity Requirement - TPolicy getSelectedObject() { - TPolicy result = null; - IStructuredSelection selection = ( IStructuredSelection )this.tableViewer.getSelection(); - Object obj = selection.getFirstElement(); - result = ( TPolicy )obj; - return result; - } - - // Return the selected Elasticity Action - TPolicy getSelectedElasticityStrategy() { - TPolicy result = null; - IStructuredSelection selection = ( IStructuredSelection )this.tableResizingActionsViewer.getSelection(); - Object obj = selection.getFirstElement(); - result = ( TPolicy )obj; - return result; - } - - /** - * Get Application Component Elasticity Actions - */ - public void getResizingActions() { +void addResizingActionExecutable( final Composite parent, + final TPolicy selectedObject ) +{ + if( selectedObject == null ) + return; + FileDialog dialog = new FileDialog( parent.getShell(), SWT.OPEN ); + dialog.setText( "Select Executable File" ); //$NON-NLS-1$ + String result = dialog.open(); + if( result != null ) { PictogramElement pe = getSelectedPictogramElement(); Object bo = null; if( pe != null ) { @@ -728,331 +741,205 @@ } else { // bo instanceof TNodeTemplate appComponent = ( TNodeTemplateExtension )bo; } - PoliciesType nodePolicyList = appComponent.getPolicies(); - if( nodePolicyList == null ) - return; - for( TPolicy tempPolicy : nodePolicyList.getPolicy() ) { - if( tempPolicy.getPolicyType().toString().contains( "Strategy" ) ) //$NON-NLS-1$ - this.appComponentResizingActions.add( tempPolicy ); - } - } - - /** - * Get Application Component Elasticity Constraints - */ - public void getElasticityConstraints() { - PictogramElement pe = getSelectedPictogramElement(); - Object bo = null; - if( pe != null ) { - bo = Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( pe ); - } - final TNodeTemplateExtension appComponent; - if( bo instanceof TDeploymentArtifact ) { - PictogramElement parentPE = Graphiti.getPeService() - .getPictogramElementParent( pe ); - appComponent = ( TNodeTemplateExtension )Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( parentPE ); - } else { // bo instanceof TNodeTemplate - appComponent = ( TNodeTemplateExtension )bo; - } - PoliciesType nodePolicyList = appComponent.getPolicies(); - if( nodePolicyList == null ) - return; - for( TPolicy tempPolicy : nodePolicyList.getPolicy() ) { - if( tempPolicy.getPolicyType().toString().contains( "Constraint" ) ) //$NON-NLS-1$ - this.appComponentElasticityRequirements.add( tempPolicy ); - } - } - - // Remove Application Component Elasticity Action - void removeApplicationComponentResizingAction( final TPolicy selectedObject ) - { - PictogramElement pe = getSelectedPictogramElement(); - Object bo = null; - if( pe != null ) { - bo = Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( pe ); - } - final TNodeTemplateExtension nodeTemplate; - if( bo instanceof TDeploymentArtifact ) { - PictogramElement parentPE = Graphiti.getPeService() - .getPictogramElementParent( pe ); - nodeTemplate = ( TNodeTemplateExtension )Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( parentPE ); - } else { // bo instanceof TNodeTemplate - nodeTemplate = ( TNodeTemplateExtension )bo; - } - PoliciesType nodePolicyList = nodeTemplate.getPolicies(); - final EList<TPolicy> policy = nodePolicyList.getPolicy(); - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { - - @Override - protected void doExecute() { - for( TPolicy tempPolicy : policy ) { - if( tempPolicy.getPolicyType().toString().contains( "Strategy" ) ) //$NON-NLS-1$ - if( tempPolicy.getName().compareTo( selectedObject.getName() ) == 0 ) - { - policy.remove( tempPolicy ); - if( policy.size() == 0 ) - nodeTemplate.setPolicies( null ); - // remove corresponding Policy Template - String removedPolicyId = tempPolicy.getPolicyRef().toString(); - ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - DefinitionsType toscaDefinitions = model.getDocumentRoot() - .getDefinitions(); - final EList<TPolicyTemplate> policyTemplate = toscaDefinitions.getPolicyTemplate(); - for( TPolicyTemplate tempPolicyTemplate : policyTemplate ) { - if( tempPolicyTemplate.getId().equals( removedPolicyId ) ) { - policyTemplate.remove( tempPolicyTemplate ); - } - } - break; - } - } - } - } ); - this.appComponentResizingActions.remove( selectedObject ); - this.tableResizingActionsViewer.refresh(); - } - - void addResizingActionExecutable( final Composite parent, final TPolicy selectedObject ) { + // Create Resizing Artifact Template - if (selectedObject == null) - return; + CreateArtifactTemplate artTempl = new CreateArtifactTemplate(dialog.getFileName(), new QName("RA"), ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) )); - FileDialog dialog = new FileDialog( parent.getShell(), SWT.OPEN ); - dialog.setText( "Select Executable File" ); //$NON-NLS-1$ + // Create Implementation Artifact + String operationName = selectedObject.getName(); + // String operationName = ""; + createImplementationArtifact( operationName, + dialog.getFileName(), + new QName( appComponent.getName() ), + new QName( dialog.getFileName() ) ); - String result = dialog.open(); - - if( result != null ) { - - PictogramElement pe = getSelectedPictogramElement(); - Object bo = null; - if( pe != null ) { - bo = Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( pe ); - } - final TNodeTemplateExtension appComponent; - if( bo instanceof TDeploymentArtifact ) { - PictogramElement parentPE = Graphiti.getPeService() - .getPictogramElementParent( pe ); - appComponent = ( TNodeTemplateExtension )Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( parentPE ); - } else { // bo instanceof TNodeTemplate - appComponent = ( TNodeTemplateExtension )bo; - } - //Create Resizing Artifact Template - createArtifactTemplate(appComponent.getName(), dialog.getFileName()); - - //Create Implementation Artifact - String operationName = selectedObject.getName(); - //String operationName = ""; - createImplementationArtifact( operationName, dialog.getFileName(), new QName(appComponent.getName()), new QName(appComponent.getName()+"_"+ dialog.getFileName() +"_"+"Script")); - - // Add uploaded resizing scripts to Project Artifacts folder - - IWorkbenchPage activePage = PlatformUI.getWorkbench() - .getActiveWorkbenchWindow() - .getActivePage(); - IEditorInput input = activePage.getActiveEditor().getEditorInput(); - IFile file = null; - if( input instanceof ToscaDiagramEditorInput ) { - file = ( ( ToscaDiagramEditorInput )input ).getToscaFile(); - } - IProject project = file.getProject(); - String targetPath = Platform.getLocation() - + File.separator + project.getName() + File.separator + "Artifacts" + File.separator + "Reconfiguration Scripts" + File.separator + dialog.getFileName(); //$NON-NLS-1$ //$NON-NLS-2$ - - File tmp = new File( targetPath ); - try { - tmp.createNewFile(); - } catch( IOException e1 ) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - - copySelectedFileToCloudProject( new File(result), tmp ); - - IProgressMonitor monitor = null; - try { - CloudModel.getRoot().refresh( monitor ); - } catch( ProblemException e2 ) { - e2.printStackTrace(); - } - // Refresh Palette Compartments - getDiagramTypeProvider().getFeatureProvider() - .getDiagramTypeProvider() - .getDiagramBehavior() - .refreshPalette(); + // Add uploaded resizing scripts to Project Artifacts folder + IWorkbenchPage activePage = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow() + .getActivePage(); + IEditorInput input = activePage.getActiveEditor().getEditorInput(); + IFile file = null; + if( input instanceof ToscaDiagramEditorInput ) { + file = ( ( ToscaDiagramEditorInput )input ).getToscaFile(); } - } - - private void copySelectedFileToCloudProject(File source, File destination){ - - InputStream selection = null; - OutputStream output = null; + IProject project = file.getProject(); + String targetPath = Platform.getLocation() + + System.getProperty( "file.separator" ) + + project.getName() + + System.getProperty( "file.separator" ) + + "Artifacts" + System.getProperty( "file.separator" ) + "Reconfiguration Scripts" + System.getProperty( "file.separator" ) + dialog.getFileName(); //$NON-NLS-1$ //$NON-NLS-2$ + File tmp = new File( targetPath ); try { - try { - selection = new FileInputStream(source); - } catch( FileNotFoundException e ) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + tmp.createNewFile(); + } catch( IOException e1 ) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + copySelectedFileToCloudProject( new File( result ), tmp ); + IProgressMonitor monitor = null; try { - output = new FileOutputStream(destination); + CloudModel.getRoot().refresh( monitor ); + } catch( ProblemException e2 ) { + e2.printStackTrace(); + } +// // Refresh Palette Compartments +// getDiagramTypeProvider().getFeatureProvider() +// .getDiagramTypeProvider() +// .getDiagramBehavior() +// .refreshPalette(); + } +} + +private void copySelectedFileToCloudProject( File source, File destination ) { + InputStream selection = null; + OutputStream output = null; + try { + try { + selection = new FileInputStream( source ); } catch( FileNotFoundException e ) { // TODO Auto-generated catch block e.printStackTrace(); } - byte[] buf = new byte[1024]; + try { + output = new FileOutputStream( destination ); + } catch( FileNotFoundException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + byte[] buf = new byte[ 1024 ]; int bytesRead; - try { - while ((bytesRead = selection.read(buf)) > 0) { - output.write(buf, 0, bytesRead); + try { + while( ( bytesRead = selection.read( buf ) ) > 0 ) { + output.write( buf, 0, bytesRead ); } } catch( IOException e ) { // TODO Auto-generated catch block e.printStackTrace(); } - } finally { - try { - selection.close(); - output.close(); - } catch( IOException e ) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - + } finally { + try { + selection.close(); + output.close(); + } catch( IOException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); } } - - private void createArtifactTemplate(String nodeName, String artifactName){ - - //Create Artifact Template - final TArtifactTemplate artifactTemplate = ToscaFactory.eINSTANCE.createTArtifactTemplate(); - - //Create Script Artifact Properties - ScriptArtifactPropertiesType scriptProperties = Tosca_Elasticity_ExtensionsFactory.eINSTANCE.createScriptArtifactPropertiesType(); - scriptProperties.setLanguage( "Shell" ); - - // Set the Properties of the Policy Template - PropertiesType properties = ToscaFactory.eINSTANCE.createPropertiesType(); - - // Add the SYBL Policy to the FeatureMap of the Policy's Properties element - Entry e = FeatureMapUtil.createEntry( Tosca_Elasticity_ExtensionsPackage.eINSTANCE.getDocumentRoot_ScriptArtifactProperties(), scriptProperties ); - properties.getAny().add( e ); - - artifactTemplate.setProperties( properties ); - - artifactTemplate.setId( nodeName + "_" + artifactName + "_" + "Script" ); - - - // Set artifact ref - TArtifactReference artifactRef = ToscaFactory.eINSTANCE.createTArtifactReference(); - artifactRef.setReference( "Scripts"+ File.separator + artifactName); +} - ArtifactReferencesType artifactRefType = ToscaFactory.eINSTANCE.createArtifactReferencesType(); - artifactRefType.getArtifactReference().add( artifactRef ); - - artifactTemplate.setArtifactReferences( artifactRefType ); - - // Add the new Artifact Template to the TOSCA Definitions element - - final ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - - DefinitionsType definitions = model.getDocumentRoot().getDefinitions(); - +private void createArtifactTemplate( String nodeName, String artifactName ) { + // Create Artifact Template + final TArtifactTemplate artifactTemplate = ToscaFactory.eINSTANCE.createTArtifactTemplate(); + // Create Script Artifact Properties + ScriptArtifactPropertiesType scriptProperties = Tosca_Elasticity_ExtensionsFactory.eINSTANCE.createScriptArtifactPropertiesType(); + scriptProperties.setLanguage( "Shell" ); + // Set the Properties of the Policy Template + PropertiesType properties = ToscaFactory.eINSTANCE.createPropertiesType(); + // Add the SYBL Policy to the FeatureMap of the Policy's Properties element + Entry e = FeatureMapUtil.createEntry( Tosca_Elasticity_ExtensionsPackage.eINSTANCE.getDocumentRoot_ScriptArtifactProperties(), + scriptProperties ); + properties.getAny().add( e ); + artifactTemplate.setProperties( properties ); + artifactTemplate.setId( nodeName + "_" + artifactName + "_" + "Script" ); + artifactTemplate.setType( new QName( "ScriptArtifact" ) ); + // Set artifact ref + TArtifactReference artifactRef = ToscaFactory.eINSTANCE.createTArtifactReference(); + artifactRef.setReference( "Scripts" + System.getProperty( "file.separator" ) + artifactName ); + ArtifactReferencesType artifactRefType = ToscaFactory.eINSTANCE.createArtifactReferencesType(); + artifactRefType.getArtifactReference().add( artifactRef ); + artifactTemplate.setArtifactReferences( artifactRefType ); + // Add the new Artifact Template to the TOSCA Definitions element + final ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); + DefinitionsType definitions = model.getDocumentRoot().getDefinitions(); + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( definitions ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { + + @Override + protected void doExecute() { + model.getDocumentRoot() + .getDefinitions() + .getArtifactTemplate() + .add( artifactTemplate ); + } + } ); +} + +// Creates the install implementation artifact +private ImplementationArtifactType createImplementationArtifact( String resizingActionName, + String artifactName, + QName nodeType, + QName artifactID ) +{ + final ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); + final DefinitionsType definitions = model.getDocumentRoot() + .getDefinitions(); + TNodeTypeImplementation nodeTypeImplementation = null; + // Test if NodeTypeImplementation for nodeType already exists + for( TNodeTypeImplementation tempNodeTypeImplementation : definitions.getNodeTypeImplementation() ) + { + if( tempNodeTypeImplementation.getNodeType() + .toString() + .equals( nodeType.toString() ) ) + { + // NodeTypeImplementation already exists + // We are going to add the artifact to the existing implementation + nodeTypeImplementation = tempNodeTypeImplementation; + } + } + if( nodeTypeImplementation == null ) { + // NodeTypeImplementation does not exists + final TNodeTypeImplementation newNodeTypeImplementation = ToscaFactory.eINSTANCE.createTNodeTypeImplementation(); + newNodeTypeImplementation.setNodeType( nodeType ); + TImplementationArtifacts implementationArtifacts = ToscaFactory.eINSTANCE.createTImplementationArtifacts(); + newNodeTypeImplementation.setImplementationArtifacts( implementationArtifacts ); TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( definitions ); editingDomain.getCommandStack() .execute( new RecordingCommand( editingDomain ) { @Override protected void doExecute() { - model.getDocumentRoot().getDefinitions().getArtifactTemplate().add( artifactTemplate ); - + definitions.getNodeTypeImplementation() + .add( newNodeTypeImplementation ); } } ); - + nodeTypeImplementation = newNodeTypeImplementation; } - - - //Creates the install implementation artifact - private ImplementationArtifactType createImplementationArtifact(String resizingActionName, String artifactName, QName nodeType, QName artifactID){ - - final ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - - final DefinitionsType definitions = model.getDocumentRoot().getDefinitions(); - - TNodeTypeImplementation nodeTypeImplementation = null; - - //Test if NodeTypeImplementation for nodeType already exists - for ( TNodeTypeImplementation tempNodeTypeImplementation : definitions.getNodeTypeImplementation() ){ - if ( tempNodeTypeImplementation.getNodeType().toString().equals(nodeType.toString()) ){ - //NodeTypeImplementation already exists - //We are going to add the artifact to the existing implementation - nodeTypeImplementation = tempNodeTypeImplementation; + // Create Implementation Artifact + final ImplementationArtifactType installArtifactType = ToscaFactory.eINSTANCE.createImplementationArtifactType(); + installArtifactType.setArtifactType( new QName( "ScriptArtifact" ) ); + installArtifactType.setArtifactRef( artifactID ); + installArtifactType.setInterfaceName( "Lifecycle" ); + installArtifactType.setOperationName( resizingActionName ); + final TNodeTypeImplementation nodeImplementation = nodeTypeImplementation; + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( nodeTypeImplementation ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { + + @Override + protected void doExecute() { + nodeImplementation.getImplementationArtifacts() + .getImplementationArtifact() + .add( installArtifactType ); } - } - - if ( nodeTypeImplementation == null ){ - //NodeTypeImplementation does not exists - final TNodeTypeImplementation newNodeTypeImplementation = ToscaFactory.eINSTANCE.createTNodeTypeImplementation(); - newNodeTypeImplementation.setNodeType( nodeType ); - TImplementationArtifacts implementationArtifacts = ToscaFactory.eINSTANCE.createTImplementationArtifacts(); - newNodeTypeImplementation.setImplementationArtifacts( implementationArtifacts ); - - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( definitions ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { + } ); + return installArtifactType; +} - @Override - protected void doExecute() { - definitions.getNodeTypeImplementation().add( newNodeTypeImplementation ); - - } - } ); - nodeTypeImplementation = newNodeTypeImplementation; - } - - //Create Implementation Artifact - final ImplementationArtifactType installArtifactType = ToscaFactory.eINSTANCE.createImplementationArtifactType(); - installArtifactType.setArtifactType( new QName("ScriptArtifact") ); - installArtifactType.setArtifactRef( artifactID ); - installArtifactType.setInterfaceName( "Lifecycle" ); - installArtifactType.setOperationName( resizingActionName ); - - final TNodeTypeImplementation nodeImplementation = nodeTypeImplementation; - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( nodeTypeImplementation ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { - - @Override - protected void doExecute() { - nodeImplementation.getImplementationArtifacts().getImplementationArtifact().add( installArtifactType ); - - } - } ); - - return installArtifactType; - } - /* - * Refresh Elasticity Tab(non-Javadoc) - * @see - * org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#refresh() - */ - @Override - public void refresh() { - // Refresh Elasticity Constraints - this.appComponentElasticityRequirements.clear(); - getElasticityConstraints(); - this.tableViewer.refresh(); - // Refresh Elasticity Actions - this.appComponentResizingActions.clear(); - getResizingActions(); - this.tableResizingActionsViewer.refresh(); - } +/* + * Refresh Elasticity Tab(non-Javadoc) + * @see + * org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#refresh() + */ +@Override +public void refresh() { + // Refresh Elasticity Constraints + this.appComponentElasticityRequirements.clear(); + getElasticityConstraints(); + this.tableViewer.refresh(); + // Refresh Elasticity Actions + this.appComponentResizingActions.clear(); + getResizingActions(); + this.tableResizingActionsViewer.refresh(); +} }
diff --git a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/property/ApplicationComponentNameSection.java b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/property/ApplicationComponentNameSection.java index 2059b42..d22d4b2 100644 --- a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/property/ApplicationComponentNameSection.java +++ b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/property/ApplicationComponentNameSection.java
@@ -89,587 +89,728 @@ * Application Component Properties - Main Tab */ public class ApplicationComponentNameSection extends GFPropertySection - implements ITabbedPropertyConstants, ModifyListener, SelectionListener +implements ITabbedPropertyConstants, ModifyListener, SelectionListener { - private Text nameText; - private Text descrText; - private Text imageText; - private Text keypairText; - private Text initialInstancesText; - private Text minInstancesText; - private Text maxInstancesText; - private CCombo cmbImageSize; - private Button uploadImage; - private Button keypairSelect; +private Text nameText; +private Text imageText; +private Text keypairText; +private Text minInstancesText; +private Text maxInstancesText; +private CCombo cmbImageSize; +private Button uploadImage; +private Button keypairSelect; - @Override - public void createControls( final Composite parent, - TabbedPropertySheetPage tabbedPropertySheetPage ) - { - super.createControls( parent, tabbedPropertySheetPage ); - TabbedPropertySheetWidgetFactory factory = getWidgetFactory(); - FormToolkit toolkit = new FormToolkit( parent.getDisplay() ); - // Application Component Properties Section\ - // Application Name label - Section section = toolkit.createSection( parent, Section.TITLE_BAR ); - section.setText( "Application Component Properties" ); //$NON-NLS-1$ - Composite client = toolkit.createComposite( section, SWT.WRAP ); - GridLayout layout = new GridLayout(); - layout.numColumns = 3; - layout.marginTop = 15; - layout.verticalSpacing = 15; - layout.marginWidth = 2; - layout.marginHeight = 2; - client.setLayout( layout ); - GridData gd; - CLabel valueLabel = factory.createCLabel( client, "Name:" ); //$NON-NLS-1$ - gd = new GridData(); - gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - gd.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; - gd.widthHint = 80; - // gd.widthHint=STANDARD_LABEL_WIDTH; - valueLabel.setLayoutData( gd ); - // Application Name text - this.nameText = factory.createText( client, "" ); //$NON-NLS-1$ - this.nameText.setEditable( true ); - gd = new GridData(); - gd.horizontalSpan = 2; - gd.widthHint = 160; - gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; - this.nameText.setLayoutData( gd ); - // Application VM label - CLabel imageLabel = factory.createCLabel( client, "VM Image:" ); //$NON-NLS-1$ - gd = new GridData(); - gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - gd.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; - gd.widthHint = 80; - // gd.widthHint=STANDARD_LABEL_WIDTH; - imageLabel.setLayoutData( gd ); - this.imageText = factory.createText( client, "" ); //$NON-NLS-1$ - this.imageText.setEditable( true ); - gd = new GridData(); - gd.widthHint = 160; - gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; - // Application VM text - this.imageText.setLayoutData( gd ); - this.imageText.addModifyListener( this ); - // VM Upload Image Button - this.uploadImage = new Button( client, SWT.PUSH ); - this.uploadImage.setText( " Add Image... " ); //$NON-NLS-1$ - gd = new GridData(); - gd.widthHint = 80; - gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - this.uploadImage.setLayoutData( gd ); - // Listener for Add button - this.uploadImage.addSelectionListener( new SelectionListener() { +private String typesPrefix = Tosca_Elasticity_ExtensionsPackage.eINSTANCE.getNsPrefix(); - @Override - public void widgetSelected( SelectionEvent e ) { - FileDialog dialog = new FileDialog( parent.getShell(), SWT.OPEN ); - dialog.setText( "Select Image File" ); //$NON-NLS-1$ - // dialog.setFilterExtensions(new String [] {"*.html"}); - // dialog.setFilterPath("c:\\temp"); - String result = dialog.open(); - if( result != null ) { - // Add uploaded image to Project Artifacts folder - IWorkbenchPage activePage = PlatformUI.getWorkbench() - .getActiveWorkbenchWindow() - .getActivePage(); - IEditorInput input = activePage.getActiveEditor().getEditorInput(); - IFile file = null; - if( input instanceof ToscaDiagramEditorInput ) { - file = ( ( ToscaDiagramEditorInput )input ).getToscaFile(); +private String typesNamespace = Tosca_Elasticity_ExtensionsPackage.eINSTANCE.getNsURI(); + +private String imageType = Tosca_Elasticity_ExtensionsPackage.eINSTANCE.getImageArtifactPropertiesType().getName(); + +@Override +public void createControls( final Composite parent, + TabbedPropertySheetPage tabbedPropertySheetPage ) +{ + super.createControls( parent, tabbedPropertySheetPage ); + TabbedPropertySheetWidgetFactory factory = getWidgetFactory(); + FormToolkit toolkit = new FormToolkit( parent.getDisplay() ); + // Application Component Properties Section\ + // Application Name label + Section section = toolkit.createSection( parent, Section.TITLE_BAR ); + section.setText( "Application Component Properties" ); //$NON-NLS-1$ + Composite client = toolkit.createComposite( section, SWT.WRAP ); + GridLayout layout = new GridLayout(); + layout.numColumns = 3; + layout.marginTop = 15; + layout.verticalSpacing = 15; + layout.marginWidth = 2; + layout.marginHeight = 2; + client.setLayout( layout ); + GridData gd; + CLabel valueLabel = factory.createCLabel( client, "Name:" ); //$NON-NLS-1$ + gd = new GridData(); + gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + gd.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; + gd.widthHint = 80; + // gd.widthHint=STANDARD_LABEL_WIDTH; + valueLabel.setLayoutData( gd ); + // Application Name text + this.nameText = factory.createText( client, "" ); //$NON-NLS-1$ + this.nameText.setEditable( true ); + gd = new GridData(); + gd.horizontalSpan = 2; + gd.widthHint = 160; + gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; + this.nameText.setLayoutData( gd ); + // Application VM label + CLabel imageLabel = factory.createCLabel( client, "VM Image:" ); //$NON-NLS-1$ + gd = new GridData(); + gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + gd.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; + gd.widthHint = 80; + // gd.widthHint=STANDARD_LABEL_WIDTH; + imageLabel.setLayoutData( gd ); + this.imageText = factory.createText( client, "" ); //$NON-NLS-1$ + this.imageText.setEditable( true ); + gd = new GridData(); + gd.widthHint = 160; + gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; + // Application VM text + this.imageText.setLayoutData( gd ); + this.imageText.addModifyListener( this ); + // VM Upload Image Button + this.uploadImage = new Button( client, SWT.PUSH ); + this.uploadImage.setText( " Add Image... " ); //$NON-NLS-1$ + gd = new GridData(); + gd.widthHint = 80; + gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + this.uploadImage.setLayoutData( gd ); + // Listener for Add button + this.uploadImage.addSelectionListener( new SelectionListener() { + + @Override + public void widgetSelected( SelectionEvent e ) { + FileDialog dialog = new FileDialog( parent.getShell(), SWT.OPEN ); + dialog.setText( "Select Image File" ); //$NON-NLS-1$ + // dialog.setFilterExtensions(new String [] {"*.html"}); + // dialog.setFilterPath("c:\\temp"); + String result = dialog.open(); + if( result != null ) { + // Add uploaded image to Project Artifacts folder + IWorkbenchPage activePage = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow() + .getActivePage(); + IEditorInput input = activePage.getActiveEditor().getEditorInput(); + IFile file = null; + if( input instanceof ToscaDiagramEditorInput ) { + file = ( ( ToscaDiagramEditorInput )input ).getToscaFile(); + } + IProject project = file.getProject(); + + String targetPath = Platform.getLocation() + + System.getProperty( "file.separator" ) + project.getName() + System.getProperty( "file.separator" ) + "Artifacts"+ System.getProperty( "file.separator" ) + "Virtual Machine Images" + System.getProperty( "file.separator" ) + dialog.getFileName(); //$NON-NLS-1$ //$NON-NLS-2$ + File tmp = new File( targetPath ); + try { + tmp.createNewFile(); + } catch( IOException e1 ) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + // Get image Id + BufferedReader reader = null; + try { + reader = new BufferedReader( new FileReader (new File(result))); + } catch( FileNotFoundException e3 ) { + // TODO Auto-generated catch block + e3.printStackTrace(); + } + String line = null; + StringBuilder stringBuilder = new StringBuilder(); + + try { + while( ( line = reader.readLine() ) != null ) { + stringBuilder.append( line ); } - IProject project = file.getProject(); - String targetPath = Platform.getLocation() - + File.separator + project.getName() + File.separator + "Artifacts"+ File.separator + "Virtual Machine Images" + File.separator + dialog.getFileName(); //$NON-NLS-1$ //$NON-NLS-2$ - File tmp = new File( targetPath ); + } catch( IOException e1 ) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + String imageId = stringBuilder.toString(); + + copySelectedFileToCloudProject( new File(result), tmp ); + + IProgressMonitor monitor = null; + try { + CloudModel.getRoot().refresh( monitor ); + } catch( ProblemException e2 ) { + e2.printStackTrace(); + } +// // Refresh Palette Compartments +// getDiagramTypeProvider().getFeatureProvider() +// .getDiagramTypeProvider() +// .getDiagramBehavior() +// .refreshPalette(); + + + CreateVMIFeature createImageFeature = new CreateVMIFeature( new ToscaFeatureProvider( getDiagramTypeProvider() ) ); + TDeploymentArtifact deploymentArtifact = ToscaFactory.eINSTANCE.createTDeploymentArtifact(); + deploymentArtifact.setName( dialog.getFileName()); + deploymentArtifact.setArtifactRef( new QName (imageId) ); + deploymentArtifact.setArtifactType( new QName( typesNamespace, imageType, typesPrefix ) ); //$NON-NLS-1$ + createImageFeature.setContextObject( deploymentArtifact ); + CreateContext createContext = new CreateContext(); + createContext.setTargetContainer( ( ContainerShape )getSelectedPictogramElement() ); + if( createImageFeature.canCreate( createContext ) ) + createImageFeature.create( createContext ); + refresh(); + + } + } + + @Override + public void widgetDefaultSelected( final SelectionEvent e ) { + // TODO Auto-generated method stub + } + } ); + + // VM Image Flavor label + CLabel vmImageLabel = factory.createCLabel( client, "VM Type:" ); //$NON-NLS-1$ + gd = new GridData(); + gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + gd.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; + gd.widthHint = 80; + vmImageLabel.setLayoutData( gd ); + // Combo - VM Image Flavor + this.cmbImageSize = new CCombo( client, SWT.BORDER ); + this.cmbImageSize.setEnabled( true ); + +// ArrayList<VirtualMachineImageFlavor> instanceTypes = +// MockUpInfoSystem.getInstance().getInstanceTypes(); +// for (VirtualMachineImageFlavor type : instanceTypes ) +// this.cmbImageSize.add(type.getName()); + /////////////////////////////////////////////////////// + this.cmbImageSize.add( "vcpus:1 ram:1024 disk:20" ); + this.cmbImageSize.add( "vcpus:1 ram:1024 disk:40" ); + this.cmbImageSize.add( "vcpus:1 ram:2048 disk:20" ); + this.cmbImageSize.add( "vcpus:1 ram:2048 disk:40" ); + this.cmbImageSize.add( "vcpus:1 ram:4096 disk:20" ); + this.cmbImageSize.add( "vcpus:1 ram:4096 disk:40" ); + this.cmbImageSize.add( "vcpus:2 ram:1024 disk:20" ); + this.cmbImageSize.add( "vcpus:2 ram:1024 disk:40" ); + this.cmbImageSize.add( "vcpus:2 ram:2048 disk:20" ); + this.cmbImageSize.add( "vcpus:2 ram:2048 disk:40" ); + this.cmbImageSize.add( "vcpus:2 ram:4096 disk:20" ); + this.cmbImageSize.add( "vcpus:2 ram:4096 disk:40" ); + this.cmbImageSize.add( "vcpus:4 ram:1024 disk:20" ); + this.cmbImageSize.add( "vcpus:4 ram:1024 disk:40" ); + this.cmbImageSize.add( "vcpus:4 ram:2048 disk:20" ); + this.cmbImageSize.add( "vcpus:4 ram:2048 disk:40" ); + this.cmbImageSize.add( "vcpus:4 ram:4096 disk:20" ); + this.cmbImageSize.add( "vcpus:4 ram:4096 disk:40" ); + this.cmbImageSize.add( "vcpus:1 ram:1024 disk:5" ); + this.cmbImageSize.add( "vcpus:1 ram:1024 disk:10" ); + this.cmbImageSize.add( "vcpus:1 ram:2048 disk:5" ); + this.cmbImageSize.add( "vcpus:1 ram:2048 disk:10" ); + this.cmbImageSize.add( "vcpus:1 ram:4096 disk:5" ); + this.cmbImageSize.add( "vcpus:1 ram:4096 disk:10" ); + this.cmbImageSize.add( "vcpus:2 ram:1024 disk:5" ); + this.cmbImageSize.add( "vcpus:2 ram:1024 disk:10" ); + this.cmbImageSize.add( "vcpus:2 ram:2048 disk:5" ); + this.cmbImageSize.add( "vcpus:2 ram:2048 disk:10" ); + this.cmbImageSize.add( "vcpus:2 ram:4096 disk:5" ); + this.cmbImageSize.add( "vcpus:2 ram:4096 disk:10" ); + this.cmbImageSize.add( "vcpus:4 ram:1024 disk:5" ); + this.cmbImageSize.add( "vcpus:4 ram:1024 disk:10" ); + this.cmbImageSize.add( "vcpus:4 ram:2048 disk:5" ); + this.cmbImageSize.add( "vcpus:4 ram:2048 disk:10" ); + this.cmbImageSize.add( "vcpus:4 ram:4096 disk:5" ); + this.cmbImageSize.add( "vcpus:4 ram:4096 disk:10" ); + this.cmbImageSize.add( "vcpus:1 ram:512 disk:5" ); + this.cmbImageSize.add( "vcpus:1 ram:512 disk:10" ); + this.cmbImageSize.add( "vcpus:1 ram:512 disk:20" ); + this.cmbImageSize.add( "vcpus:1 ram:512 disk:40" ); + this.cmbImageSize.add( "vcpus:1 ram:512 disk:60" ); + this.cmbImageSize.add( "vcpus:1 ram:512 disk:80" ); + this.cmbImageSize.add( "vcpus:1 ram:512 disk:100" ); + this.cmbImageSize.add( "vcpus:1 ram:1024 disk:60" ); + this.cmbImageSize.add( "vcpus:1 ram:1024 disk:80" ); + this.cmbImageSize.add( "vcpus:1 ram:1024 disk:100" ); + this.cmbImageSize.add( "vcpus:1 ram:2048 disk:60" ); + this.cmbImageSize.add( "vcpus:1 ram:2048 disk:80" ); + this.cmbImageSize.add( "vcpus:1 ram:2048 disk:100" ); + this.cmbImageSize.add( "vcpus:1 ram:4096 disk:60" ); + this.cmbImageSize.add( "vcpus:1 ram:4096 disk:80" ); + this.cmbImageSize.add( "vcpus:1 ram:4096 disk:100" ); + this.cmbImageSize.add( "vcpus:1 ram:8192 disk:5" ); + this.cmbImageSize.add( "vcpus:1 ram:8192 disk:10" ); + this.cmbImageSize.add( "vcpus:1 ram:8192 disk:20" ); + this.cmbImageSize.add( "vcpus:1 ram:8192 disk:40" ); + this.cmbImageSize.add( "vcpus:1 ram:8192 disk:60" ); + this.cmbImageSize.add( "vcpus:1 ram:8192 disk:80" ); + this.cmbImageSize.add( "vcpus:1 ram:8192 disk:100" ); + this.cmbImageSize.add( "vcpus:2 ram:512 disk:5" ); + this.cmbImageSize.add( "vcpus:2 ram:512 disk:10" ); + this.cmbImageSize.add( "vcpus:2 ram:512 disk:20" ); + this.cmbImageSize.add( "vcpus:2 ram:512 disk:40" ); + this.cmbImageSize.add( "vcpus:2 ram:512 disk:60" ); + this.cmbImageSize.add( "vcpus:2 ram:512 disk:80" ); + this.cmbImageSize.add( "vcpus:2 ram:512 disk:100" ); + this.cmbImageSize.add( "vcpus:2 ram:1024 disk:60" ); + this.cmbImageSize.add( "vcpus:2 ram:1024 disk:80" ); + this.cmbImageSize.add( "vcpus:2 ram:1024 disk:100" ); + this.cmbImageSize.add( "vcpus:2 ram:2048 disk:60" ); + this.cmbImageSize.add( "vcpus:2 ram:2048 disk:80" ); + this.cmbImageSize.add( "vcpus:2 ram:2048 disk:100" ); + this.cmbImageSize.add( "vcpus:2 ram:4096 disk:60" ); + this.cmbImageSize.add( "vcpus:2 ram:4096 disk:80" ); + this.cmbImageSize.add( "vcpus:2 ram:4096 disk:100" ); + this.cmbImageSize.add( "vcpus:2 ram:8192 disk:5" ); + this.cmbImageSize.add( "vcpus:2 ram:8192 disk:10" ); + this.cmbImageSize.add( "vcpus:2 ram:8192 disk:20" ); + this.cmbImageSize.add( "vcpus:2 ram:8192 disk:40" ); + this.cmbImageSize.add( "vcpus:2 ram:8192 disk:60" ); + this.cmbImageSize.add( "vcpus:2 ram:8192 disk:80" ); + this.cmbImageSize.add( "vcpus:2 ram:8192 disk:100" ); + this.cmbImageSize.add( "vcpus:4 ram:512 disk:5" ); + this.cmbImageSize.add( "vcpus:4 ram:512 disk:10" ); + this.cmbImageSize.add( "vcpus:4 ram:512 disk:20" ); + this.cmbImageSize.add( "vcpus:4 ram:512 disk:40" ); + this.cmbImageSize.add( "vcpus:4 ram:512 disk:60" ); + this.cmbImageSize.add( "vcpus:4 ram:512 disk:80" ); + this.cmbImageSize.add( "vcpus:4 ram:512 disk:100" ); + this.cmbImageSize.add( "vcpus:4 ram:1024 disk:60" ); + this.cmbImageSize.add( "vcpus:4 ram:1024 disk:80" ); + this.cmbImageSize.add( "vcpus:4 ram:1024 disk:100" ); + this.cmbImageSize.add( "vcpus:4 ram:2048 disk:60" ); + this.cmbImageSize.add( "vcpus:4 ram:2048 disk:80" ); + this.cmbImageSize.add( "vcpus:4 ram:2048 disk:100" ); + this.cmbImageSize.add( "vcpus:4 ram:4096 disk:60" ); + this.cmbImageSize.add( "vcpus:4 ram:4096 disk:80" ); + this.cmbImageSize.add( "vcpus:4 ram:4096 disk:100" ); + this.cmbImageSize.add( "vcpus:4 ram:8192 disk:5" ); + this.cmbImageSize.add( "vcpus:4 ram:8192 disk:10" ); + this.cmbImageSize.add( "vcpus:4 ram:8192 disk:20" ); + this.cmbImageSize.add( "vcpus:4 ram:8192 disk:40" ); + this.cmbImageSize.add( "vcpus:4 ram:8192 disk:60" ); + this.cmbImageSize.add( "vcpus:4 ram:8192 disk:80" ); + this.cmbImageSize.add( "vcpus:4 ram:8192 disk:100" ); + this.cmbImageSize.add( "vcpus:8 ram:512 disk:5" ); + this.cmbImageSize.add( "vcpus:8 ram:512 disk:10" ); + this.cmbImageSize.add( "vcpus:8 ram:512 disk:20" ); + this.cmbImageSize.add( "vcpus:8 ram:512 disk:40" ); + this.cmbImageSize.add( "vcpus:8 ram:512 disk:60" ); + this.cmbImageSize.add( "vcpus:8 ram:512 disk:80" ); + this.cmbImageSize.add( "vcpus:8 ram:512 disk:100" ); + this.cmbImageSize.add( "vcpus:8 ram:1024 disk:5" ); + this.cmbImageSize.add( "vcpus:8 ram:1024 disk:10" ); + this.cmbImageSize.add( "vcpus:8 ram:1024 disk:20" ); + this.cmbImageSize.add( "vcpus:8 ram:1024 disk:40" ); + this.cmbImageSize.add( "vcpus:8 ram:1024 disk:60" ); + this.cmbImageSize.add( "vcpus:8 ram:1024 disk:80" ); + this.cmbImageSize.add( "vcpus:8 ram:1024 disk:100" ); + this.cmbImageSize.add( "vcpus:8 ram:2048 disk:5" ); + this.cmbImageSize.add( "vcpus:8 ram:2048 disk:10" ); + this.cmbImageSize.add( "vcpus:8 ram:2048 disk:20" ); + this.cmbImageSize.add( "vcpus:8 ram:2048 disk:40" ); + this.cmbImageSize.add( "vcpus:8 ram:2048 disk:60" ); + this.cmbImageSize.add( "vcpus:8 ram:2048 disk:80" ); + this.cmbImageSize.add( "vcpus:8 ram:2048 disk:100" ); + this.cmbImageSize.add( "vcpus:8 ram:4096 disk:5" ); + this.cmbImageSize.add( "vcpus:8 ram:4096 disk:10" ); + this.cmbImageSize.add( "vcpus:8 ram:4096 disk:20" ); + this.cmbImageSize.add( "vcpus:8 ram:4096 disk:40" ); + this.cmbImageSize.add( "vcpus:8 ram:4096 disk:60" ); + this.cmbImageSize.add( "vcpus:8 ram:4096 disk:80" ); + this.cmbImageSize.add( "vcpus:8 ram:4096 disk:100" ); + this.cmbImageSize.add( "vcpus:8 ram:8192 disk:5" ); + this.cmbImageSize.add( "vcpus:8 ram:8192 disk:10" ); + this.cmbImageSize.add( "vcpus:8 ram:8192 disk:20" ); + this.cmbImageSize.add( "vcpus:8 ram:8192 disk:40" ); + this.cmbImageSize.add( "vcpus:8 ram:8192 disk:60" ); + this.cmbImageSize.add( "vcpus:8 ram:8192 disk:80" ); + this.cmbImageSize.add( "vcpus:8 ram:8192 disk:100" ); + this.cmbImageSize.add( "vcpus:1 ram:512 disk:5" ); + this.cmbImageSize.add( "vcpus:1 ram:512 disk:10" ); + this.cmbImageSize.add( "vcpus:1 ram:512 disk:20" ); + this.cmbImageSize.add( "vcpus:1 ram:512 disk:40" ); + this.cmbImageSize.add( "vcpus:1 ram:512 disk:60" ); + this.cmbImageSize.add( "vcpus:1 ram:512 disk:80" ); + this.cmbImageSize.add( "vcpus:1 ram:512 disk:100" ); + this.cmbImageSize.add( "vcpus:1 ram:1024 disk:5" ); + this.cmbImageSize.add( "vcpus:1 ram:1024 disk:10" ); + this.cmbImageSize.add( "vcpus:1 ram:1024 disk:20" ); + this.cmbImageSize.add( "vcpus:1 ram:1024 disk:40" ); + this.cmbImageSize.add( "vcpus:1 ram:1024 disk:60" ); + this.cmbImageSize.add( "vcpus:1 ram:1024 disk:80" ); + this.cmbImageSize.add( "vcpus:1 ram:1024 disk:100" ); + this.cmbImageSize.add( "vcpus:1 ram:2048 disk:5" ); + this.cmbImageSize.add( "vcpus:1 ram:2048 disk:10" ); + this.cmbImageSize.add( "vcpus:1 ram:2048 disk:20" ); + this.cmbImageSize.add( "vcpus:1 ram:2048 disk:40" ); + this.cmbImageSize.add( "vcpus:1 ram:2048 disk:60" ); + this.cmbImageSize.add( "vcpus:1 ram:2048 disk:80" ); + this.cmbImageSize.add( "vcpus:1 ram:2048 disk:100" ); + this.cmbImageSize.add( "vcpus:1 ram:4096 disk:5" ); + this.cmbImageSize.add( "vcpus:1 ram:4096 disk:10" ); + this.cmbImageSize.add( "vcpus:1 ram:4096 disk:20" ); + this.cmbImageSize.add( "vcpus:1 ram:4096 disk:40" ); + this.cmbImageSize.add( "vcpus:1 ram:4096 disk:60" ); + this.cmbImageSize.add( "vcpus:1 ram:4096 disk:80" ); + this.cmbImageSize.add( "vcpus:1 ram:4096 disk:100" ); + this.cmbImageSize.add( "vcpus:1 ram:8192 disk:5" ); + this.cmbImageSize.add( "vcpus:1 ram:8192 disk:10" ); + this.cmbImageSize.add( "vcpus:1 ram:8192 disk:20" ); + this.cmbImageSize.add( "vcpus:1 ram:8192 disk:40" ); + this.cmbImageSize.add( "vcpus:1 ram:8192 disk:60" ); + this.cmbImageSize.add( "vcpus:1 ram:8192 disk:80" ); + this.cmbImageSize.add( "vcpus:1 ram:8192 disk:100" ); + this.cmbImageSize.add( "vcpus:2 ram:512 disk:5" ); + this.cmbImageSize.add( "vcpus:2 ram:512 disk:10" ); + this.cmbImageSize.add( "vcpus:2 ram:512 disk:20" ); + this.cmbImageSize.add( "vcpus:2 ram:512 disk:40" ); + this.cmbImageSize.add( "vcpus:2 ram:512 disk:60" ); + this.cmbImageSize.add( "vcpus:2 ram:512 disk:80" ); + this.cmbImageSize.add( "vcpus:2 ram:512 disk:100" ); + this.cmbImageSize.add( "vcpus:2 ram:1024 disk:5" ); + this.cmbImageSize.add( "vcpus:2 ram:1024 disk:10" ); + this.cmbImageSize.add( "vcpus:2 ram:1024 disk:20" ); + this.cmbImageSize.add( "vcpus:2 ram:1024 disk:40" ); + this.cmbImageSize.add( "vcpus:2 ram:1024 disk:60" ); + this.cmbImageSize.add( "vcpus:2 ram:1024 disk:80" ); + this.cmbImageSize.add( "vcpus:2 ram:1024 disk:100" ); + this.cmbImageSize.add( "vcpus:2 ram:2048 disk:5" ); + this.cmbImageSize.add( "vcpus:2 ram:2048 disk:10" ); + this.cmbImageSize.add( "vcpus:2 ram:2048 disk:20" ); + this.cmbImageSize.add( "vcpus:2 ram:2048 disk:40" ); + this.cmbImageSize.add( "vcpus:2 ram:2048 disk:60" ); + this.cmbImageSize.add( "vcpus:2 ram:2048 disk:80" ); + this.cmbImageSize.add( "vcpus:2 ram:2048 disk:100" ); + this.cmbImageSize.add( "vcpus:2 ram:4096 disk:5" ); + this.cmbImageSize.add( "vcpus:2 ram:4096 disk:10" ); + this.cmbImageSize.add( "vcpus:2 ram:4096 disk:20" ); + this.cmbImageSize.add( "vcpus:2 ram:4096 disk:40" ); + this.cmbImageSize.add( "vcpus:2 ram:4096 disk:60" ); + this.cmbImageSize.add( "vcpus:2 ram:4096 disk:80" ); + this.cmbImageSize.add( "vcpus:2 ram:4096 disk:100" ); + this.cmbImageSize.add( "vcpus:2 ram:8192 disk:5" ); + this.cmbImageSize.add( "vcpus:2 ram:8192 disk:10" ); + this.cmbImageSize.add( "vcpus:2 ram:8192 disk:20" ); + this.cmbImageSize.add( "vcpus:2 ram:8192 disk:40" ); + this.cmbImageSize.add( "vcpus:2 ram:8192 disk:60" ); + this.cmbImageSize.add( "vcpus:2 ram:8192 disk:80" ); + this.cmbImageSize.add( "vcpus:2 ram:8192 disk:100" ); + this.cmbImageSize.add( "vcpus:4 ram:512 disk:5" ); + this.cmbImageSize.add( "vcpus:4 ram:512 disk:10" ); + this.cmbImageSize.add( "vcpus:4 ram:512 disk:20" ); + this.cmbImageSize.add( "vcpus:4 ram:512 disk:40" ); + this.cmbImageSize.add( "vcpus:4 ram:512 disk:60" ); + this.cmbImageSize.add( "vcpus:4 ram:512 disk:80" ); + this.cmbImageSize.add( "vcpus:4 ram:512 disk:100" ); + this.cmbImageSize.add( "vcpus:4 ram:1024 disk:5" ); + this.cmbImageSize.add( "vcpus:4 ram:1024 disk:10" ); + this.cmbImageSize.add( "vcpus:4 ram:1024 disk:20" ); + this.cmbImageSize.add( "vcpus:4 ram:1024 disk:40" ); + this.cmbImageSize.add( "vcpus:4 ram:1024 disk:60" ); + this.cmbImageSize.add( "vcpus:4 ram:1024 disk:80" ); + this.cmbImageSize.add( "vcpus:4 ram:1024 disk:100" ); + this.cmbImageSize.add( "vcpus:4 ram:2048 disk:5" ); + this.cmbImageSize.add( "vcpus:4 ram:2048 disk:10" ); + this.cmbImageSize.add( "vcpus:4 ram:2048 disk:20" ); + this.cmbImageSize.add( "vcpus:4 ram:2048 disk:40" ); + this.cmbImageSize.add( "vcpus:4 ram:2048 disk:60" ); + this.cmbImageSize.add( "vcpus:4 ram:2048 disk:80" ); + this.cmbImageSize.add( "vcpus:4 ram:2048 disk:100" ); + this.cmbImageSize.add( "vcpus:4 ram:4096 disk:5" ); + this.cmbImageSize.add( "vcpus:4 ram:4096 disk:10" ); + this.cmbImageSize.add( "vcpus:4 ram:4096 disk:20" ); + this.cmbImageSize.add( "vcpus:4 ram:4096 disk:40" ); + this.cmbImageSize.add( "vcpus:4 ram:4096 disk:60" ); + this.cmbImageSize.add( "vcpus:4 ram:4096 disk:80" ); + this.cmbImageSize.add( "vcpus:4 ram:4096 disk:100" ); + this.cmbImageSize.add( "vcpus:4 ram:8192 disk:5" ); + this.cmbImageSize.add( "vcpus:4 ram:8192 disk:10" ); + this.cmbImageSize.add( "vcpus:4 ram:8192 disk:20" ); + this.cmbImageSize.add( "vcpus:4 ram:8192 disk:40" ); + this.cmbImageSize.add( "vcpus:4 ram:8192 disk:60" ); + this.cmbImageSize.add( "vcpus:4 ram:8192 disk:80" ); + this.cmbImageSize.add( "vcpus:4 ram:8192 disk:100" ); + this.cmbImageSize.add( "vcpus:8 ram:512 disk:5" ); + this.cmbImageSize.add( "vcpus:8 ram:512 disk:10" ); + this.cmbImageSize.add( "vcpus:8 ram:512 disk:20" ); + this.cmbImageSize.add( "vcpus:8 ram:512 disk:40" ); + this.cmbImageSize.add( "vcpus:8 ram:512 disk:60" ); + this.cmbImageSize.add( "vcpus:8 ram:512 disk:80" ); + this.cmbImageSize.add( "vcpus:8 ram:512 disk:100" ); + this.cmbImageSize.add( "vcpus:8 ram:1024 disk:5" ); + this.cmbImageSize.add( "vcpus:8 ram:1024 disk:10" ); + this.cmbImageSize.add( "vcpus:8 ram:1024 disk:20" ); + this.cmbImageSize.add( "vcpus:8 ram:1024 disk:40" ); + this.cmbImageSize.add( "vcpus:8 ram:1024 disk:60" ); + this.cmbImageSize.add( "vcpus:8 ram:1024 disk:80" ); + this.cmbImageSize.add( "vcpus:8 ram:1024 disk:100" ); + this.cmbImageSize.add( "vcpus:8 ram:2048 disk:5" ); + this.cmbImageSize.add( "vcpus:8 ram:2048 disk:10" ); + this.cmbImageSize.add( "vcpus:8 ram:2048 disk:20" ); + this.cmbImageSize.add( "vcpus:8 ram:2048 disk:40" ); + this.cmbImageSize.add( "vcpus:8 ram:2048 disk:60" ); + this.cmbImageSize.add( "vcpus:8 ram:2048 disk:80" ); + this.cmbImageSize.add( "vcpus:8 ram:2048 disk:100" ); + this.cmbImageSize.add( "vcpus:8 ram:4096 disk:5" ); + this.cmbImageSize.add( "vcpus:8 ram:4096 disk:10" ); + this.cmbImageSize.add( "vcpus:8 ram:4096 disk:20" ); + this.cmbImageSize.add( "vcpus:8 ram:4096 disk:40" ); + this.cmbImageSize.add( "vcpus:8 ram:4096 disk:60" ); + this.cmbImageSize.add( "vcpus:8 ram:4096 disk:80" ); + this.cmbImageSize.add( "vcpus:8 ram:4096 disk:100" ); + this.cmbImageSize.add( "vcpus:8 ram:8192 disk:5" ); + this.cmbImageSize.add( "vcpus:8 ram:8192 disk:10" ); + this.cmbImageSize.add( "vcpus:8 ram:8192 disk:20" ); + this.cmbImageSize.add( "vcpus:8 ram:8192 disk:40" ); + this.cmbImageSize.add( "vcpus:8 ram:8192 disk:60" ); + this.cmbImageSize.add( "vcpus:8 ram:8192 disk:80" ); + this.cmbImageSize.add( "vcpus:8 ram:8192 disk:100" ); + this.cmbImageSize.add( "vcpus:1 ram:6144 disk:100" ); + this.cmbImageSize.add( "vcpus:1 ram:6144 disk:100" ); + this.cmbImageSize.add( "vcpus:2 ram:6144 disk:100" ); + this.cmbImageSize.add( "vcpus:2 ram:6144 disk:100" ); + this.cmbImageSize.add( "vcpus:2 ram:6144 disk:80" ); + this.cmbImageSize.add( "vcpus:2 ram:6144 disk:60" ); + this.cmbImageSize.add( "vcpus:2 ram:6144 disk:40" ); + this.cmbImageSize.add( "vcpus:2 ram:6144 disk:40" ); + this.cmbImageSize.add( "vcpus:2 ram:6144 disk:60" ); + this.cmbImageSize.add( "vcpus:2 ram:6144 disk:80" ); + this.cmbImageSize.add( "vcpus:1 ram:6144 disk:5" ); + this.cmbImageSize.add( "vcpus:1 ram:6144 disk:10" ); + this.cmbImageSize.add( "vcpus:1 ram:6144 disk:20" ); + this.cmbImageSize.add( "vcpus:1 ram:6144 disk:40" ); + this.cmbImageSize.add( "vcpus:1 ram:6144 disk:60" ); + this.cmbImageSize.add( "vcpus:1 ram:6144 disk:80" ); + this.cmbImageSize.add( "vcpus:1 ram:6144 disk:5" ); + this.cmbImageSize.add( "vcpus:1 ram:6144 disk:10" ); + this.cmbImageSize.add( "vcpus:1 ram:6144 disk:20" ); + this.cmbImageSize.add( "vcpus:1 ram:6144 disk:40" ); + this.cmbImageSize.add( "vcpus:1 ram:6144 disk:60" ); + this.cmbImageSize.add( "vcpus:1 ram:6144 disk:80" ); + this.cmbImageSize.add( "vcpus:2 ram:6144 disk:5" ); + this.cmbImageSize.add( "vcpus:2 ram:6144 disk:10" ); + this.cmbImageSize.add( "vcpus:2 ram:6144 disk:20" ); + this.cmbImageSize.add( "vcpus:2 ram:6144 disk:5" ); + this.cmbImageSize.add( "vcpus:2 ram:6144 disk:10" ); + this.cmbImageSize.add( "vcpus:2 ram:6144 disk:20" ); + this.cmbImageSize.add( "vcpus:4 ram:6144 disk:5" ); + this.cmbImageSize.add( "vcpus:4 ram:6144 disk:10" ); + this.cmbImageSize.add( "vcpus:4 ram:6144 disk:20" ); + this.cmbImageSize.add( "vcpus:4 ram:6144 disk:40" ); + this.cmbImageSize.add( "vcpus:4 ram:6144 disk:60" ); + this.cmbImageSize.add( "vcpus:4 ram:6144 disk:80" ); + this.cmbImageSize.add( "vcpus:4 ram:6144 disk:100" ); + this.cmbImageSize.add( "vcpus:4 ram:6144 disk:5" ); + this.cmbImageSize.add( "vcpus:4 ram:6144 disk:10" ); + this.cmbImageSize.add( "vcpus:4 ram:6144 disk:20" ); + this.cmbImageSize.add( "vcpus:4 ram:6144 disk:40" ); + this.cmbImageSize.add( "vcpus:4 ram:6144 disk:60" ); + this.cmbImageSize.add( "vcpus:4 ram:6144 disk:80" ); + this.cmbImageSize.add( "vcpus:4 ram:6144 disk:100" ); + this.cmbImageSize.add( "vcpus:8 ram:6144 disk:5" ); + this.cmbImageSize.add( "vcpus:8 ram:6144 disk:10" ); + this.cmbImageSize.add( "vcpus:8 ram:6144 disk:20" ); + this.cmbImageSize.add( "vcpus:8 ram:6144 disk:40" ); + this.cmbImageSize.add( "vcpus:8 ram:6144 disk:60" ); + this.cmbImageSize.add( "vcpus:8 ram:6144 disk:80" ); + this.cmbImageSize.add( "vcpus:8 ram:6144 disk:100" ); + this.cmbImageSize.add( "vcpus:8 ram:6144 disk:5" ); + this.cmbImageSize.add( "vcpus:8 ram:6144 disk:10" ); + this.cmbImageSize.add( "vcpus:8 ram:6144 disk:20" ); + this.cmbImageSize.add( "vcpus:8 ram:6144 disk:40" ); + this.cmbImageSize.add( "vcpus:8 ram:6144 disk:60" ); + this.cmbImageSize.add( "vcpus:8 ram:6144 disk:80" ); + this.cmbImageSize.add( "vcpus:8 ram:6144 disk:100" ); + this.cmbImageSize.add( "vcpus:8 ram:6144 disk:diskdump" ); + this.cmbImageSize.add( "vcpus:8 ram:6144 disk:diskdump" ); + this.cmbImageSize.add( "vcpus:8 ram:6144 disk:diskdump" ); + this.cmbImageSize.add( "vcpus:8 ram:6144 disk:diskdump" ); + this.cmbImageSize.add( "vcpus:8 ram:6144 disk:diskdump" ); + this.cmbImageSize.add( "vcpus:8 ram:6144 disk:diskdump" ); + /////////////////////////////////////////////////////// + this.cmbImageSize.setEditable( false ); + gd = new GridData(); + gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; + gd.horizontalSpan = 2; + gd.widthHint = 200; + this.cmbImageSize.setLayoutData( gd ); + // Listener for Flavor + this.cmbImageSize.addSelectionListener( new SelectionListener() { + + @Override + public void widgetSelected( final SelectionEvent e ) { + createNodeFlavorProperties( ApplicationComponentNameSection.this.cmbImageSize.getText() ); + } + + @Override + public void widgetDefaultSelected( final SelectionEvent e ) { + // TODO Auto-generated method stub + } + } ); + // KeyPair Label + CLabel keypairLabel = factory.createCLabel( client, "Keypair:" ); //$NON-NLS-1$ + gd = new GridData(); + gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + gd.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; + gd.widthHint = 80; + keypairLabel.setLayoutData( gd ); + // KeyPair text + this.keypairText = factory.createText( client, "" ); //$NON-NLS-1$ + this.keypairText.setEditable( true ); + gd = new GridData(); + gd.widthHint = 160; + gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; + this.keypairText.setLayoutData( gd ); + this.keypairText.addModifyListener( this ); + // Select KeyPair Button + this.keypairSelect = new Button( client, SWT.PUSH ); + this.keypairSelect.setText( " Select... " ); //$NON-NLS-1$ + gd = new GridData(); + gd.widthHint = 80; + gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + this.keypairSelect.setLayoutData( gd ); + // Listener for Add button + this.keypairSelect.addSelectionListener( new SelectionListener() { + + @Override + public void widgetSelected( final SelectionEvent e ) { + FileDialog dialog = new FileDialog( parent.getShell(), SWT.OPEN ); + dialog.setText( "Select Keypair " ); //$NON-NLS-1$ + dialog.setFilterExtensions( new String[]{ + "*.pub"} ); // filter only pub keys //$NON-NLS-1$ + // dialog.setFilterPath("c:\\temp"); + String result = dialog.open(); + if( result != null ) { + CreateVMIFeature createImageFeature = new CreateVMIFeature( new ToscaFeatureProvider( getDiagramTypeProvider() ) ); + TDeploymentArtifact deploymentArtifact = ToscaFactory.eINSTANCE.createTDeploymentArtifact(); + deploymentArtifact.setName( dialog.getFileName() ); + deploymentArtifact.setArtifactType( new QName( "KeyPair" ) ); //$NON-NLS-1$ + createImageFeature.setContextObject( deploymentArtifact ); + CreateContext createContext = new CreateContext(); + createContext.setTargetContainer( ( ContainerShape )getSelectedPictogramElement() ); + if( createImageFeature.canCreate( createContext ) ) + createImageFeature.create( createContext ); + refresh(); + // Add uploaded image to Project Artifacts folder + IWorkbenchPage activePage = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow() + .getActivePage(); + IEditorInput input = activePage.getActiveEditor().getEditorInput(); + IFile file = null; + if( input instanceof ToscaDiagramEditorInput ) { + file = ( ( ToscaDiagramEditorInput )input ).getToscaFile(); + } + IProject project = file.getProject(); + String target = Platform.getLocation() + + System.getProperty( "file.separator" ) + project.getName() + System.getProperty( "file.separator" ) + "Artifacts" +System.getProperty( "file.separator" )+"Deployment Scripts"+System.getProperty( "file.separator" ) + dialog.getFileName(); //$NON-NLS-1$ //$NON-NLS-2$ + String source = dialog.getFilterPath() + + System.getProperty( "file.separator" ) + dialog.getFileName(); //$NON-NLS-1$ + File targetFile = new File( target ); + if( !targetFile.exists() ) { try { - tmp.createNewFile(); - } catch( IOException e1 ) { - // TODO Auto-generated catch block + new LocalFile( new File( source ) ).copy( new LocalFile( new File( target ) ), + EFS.NONE, + null ); + } catch( CoreException e1 ) { e1.printStackTrace(); } - - // Get image Id - BufferedReader reader = null; - try { - reader = new BufferedReader( new FileReader (new File(result))); - } catch( FileNotFoundException e3 ) { - // TODO Auto-generated catch block - e3.printStackTrace(); - } - String line = null; - StringBuilder stringBuilder = new StringBuilder(); - - try { - while( ( line = reader.readLine() ) != null ) { - stringBuilder.append( line ); - } - } catch( IOException e1 ) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - - String imageId = stringBuilder.toString(); - - - - copySelectedFileToCloudProject( new File(result), tmp ); - - IProgressMonitor monitor = null; - try { - CloudModel.getRoot().refresh( monitor ); - } catch( ProblemException e2 ) { - e2.printStackTrace(); - } - // Refresh Palette Compartments - getDiagramTypeProvider().getFeatureProvider() - .getDiagramTypeProvider() - .getDiagramBehavior() - .refreshPalette(); - - - CreateVMIFeature createImageFeature = new CreateVMIFeature( new ToscaFeatureProvider( getDiagramTypeProvider() ) ); - TDeploymentArtifact deploymentArtifact = ToscaFactory.eINSTANCE.createTDeploymentArtifact(); - deploymentArtifact.setName( dialog.getFileName()); - deploymentArtifact.setArtifactRef( new QName (imageId) ); - deploymentArtifact.setArtifactType( new QName( "VMI" ) ); //$NON-NLS-1$ - createImageFeature.setContextObject( deploymentArtifact ); - CreateContext createContext = new CreateContext(); - createContext.setTargetContainer( ( ContainerShape )getSelectedPictogramElement() ); - if( createImageFeature.canCreate( createContext ) ) - createImageFeature.create( createContext ); - refresh(); - } - } - - @Override - public void widgetDefaultSelected( final SelectionEvent e ) { - // TODO Auto-generated method stub - } - } ); - // VM Description Label - CLabel vmDecsrLabel = factory.createCLabel( client, "VM Description:" ); //$NON-NLS-1$ - gd = new GridData(); - gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - gd.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; - gd.widthHint = 80; - // gd.widthHint=STANDARD_LABEL_WIDTH; - // VM Description text - vmDecsrLabel.setLayoutData( gd ); - this.descrText = factory.createText( client, "" ); //$NON-NLS-1$ - this.descrText.setEditable( false ); - gd = new GridData(); - gd.horizontalSpan = 2; - gd.widthHint = 160; - gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; - this.descrText.setLayoutData( gd ); - // VM Image Flavor label - CLabel vmImageLabel = factory.createCLabel( client, "VM Type:" ); //$NON-NLS-1$ - gd = new GridData(); - gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - gd.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; - gd.widthHint = 80; - vmImageLabel.setLayoutData( gd ); - // Combo - VM Image Flavor - this.cmbImageSize = new CCombo( client, SWT.BORDER ); - this.cmbImageSize.setEnabled( true ); - - // // TODO - nickl For now use Amazon Flavors - get them from IS - ArrayList<VirtualMachineImageFlavor> flavors = MockUpInfoSystem - .getInstance().getFlavors(); - - for (VirtualMachineImageFlavor f : flavors) { - this.cmbImageSize.add(f.getName()); - } - - - this.cmbImageSize.setEditable( false ); - gd = new GridData(); - gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; - gd.horizontalSpan = 2; - gd.widthHint = 200; - this.cmbImageSize.setLayoutData( gd ); - // Listener for Flavor - this.cmbImageSize.addSelectionListener( new SelectionListener() { - - @Override - public void widgetSelected( final SelectionEvent e ) { - createNodeFlavorProperties( ApplicationComponentNameSection.this.cmbImageSize.getText() ); - } - - @Override - public void widgetDefaultSelected( final SelectionEvent e ) { - // TODO Auto-generated method stub - } - } ); - // KeyPair Label - CLabel keypairLabel = factory.createCLabel( client, "Keypair:" ); //$NON-NLS-1$ - gd = new GridData(); - gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - gd.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; - gd.widthHint = 80; - keypairLabel.setLayoutData( gd ); - // KeyPair text - this.keypairText = factory.createText( client, "" ); //$NON-NLS-1$ - this.keypairText.setEditable( true ); - gd = new GridData(); - gd.widthHint = 160; - gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; - this.keypairText.setLayoutData( gd ); - this.keypairText.addModifyListener( this ); - // Select KeyPair Button - this.keypairSelect = new Button( client, SWT.PUSH ); - this.keypairSelect.setText( " Select... " ); //$NON-NLS-1$ - gd = new GridData(); - gd.widthHint = 80; - gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - this.keypairSelect.setLayoutData( gd ); - // Listener for Add button - this.keypairSelect.addSelectionListener( new SelectionListener() { - - @Override - public void widgetSelected( final SelectionEvent e ) { - FileDialog dialog = new FileDialog( parent.getShell(), SWT.OPEN ); - dialog.setText( "Select Keypair " ); //$NON-NLS-1$ - dialog.setFilterExtensions( new String[]{ - "*.pub"} ); // filter only pub keys //$NON-NLS-1$ - // dialog.setFilterPath("c:\\temp"); - String result = dialog.open(); - if( result != null ) { - CreateVMIFeature createImageFeature = new CreateVMIFeature( new ToscaFeatureProvider( getDiagramTypeProvider() ) ); - TDeploymentArtifact deploymentArtifact = ToscaFactory.eINSTANCE.createTDeploymentArtifact(); - deploymentArtifact.setName( dialog.getFileName() ); - deploymentArtifact.setArtifactType( new QName( "KeyPair" ) ); //$NON-NLS-1$ - createImageFeature.setContextObject( deploymentArtifact ); - CreateContext createContext = new CreateContext(); - createContext.setTargetContainer( ( ContainerShape )getSelectedPictogramElement() ); - if( createImageFeature.canCreate( createContext ) ) - createImageFeature.create( createContext ); - refresh(); - // Add uploaded image to Project Artifacts folder - IWorkbenchPage activePage = PlatformUI.getWorkbench() - .getActiveWorkbenchWindow() - .getActivePage(); - IEditorInput input = activePage.getActiveEditor().getEditorInput(); - IFile file = null; - if( input instanceof ToscaDiagramEditorInput ) { - file = ( ( ToscaDiagramEditorInput )input ).getToscaFile(); - } - IProject project = file.getProject(); - String target = Platform.getLocation() - + "/" + project.getName() + "/Artifacts/Deployment Scripts/" + dialog.getFileName(); //$NON-NLS-1$ //$NON-NLS-2$ - String source = dialog.getFilterPath() - + System.getProperty( "file.separator" ) + dialog.getFileName(); //$NON-NLS-1$ - File targetFile = new File( target ); - if( !targetFile.exists() ) { - try { - new LocalFile( new File( source ) ).copy( new LocalFile( new File( target ) ), - EFS.NONE, - null ); - } catch( CoreException e1 ) { - e1.printStackTrace(); - } - } - // File tmp = new File( targetPath ); - // try { - // tmp.createNewFile(); - // tmp. - // } catch( IOException e1 ) { - // // TODO Auto-generated catch block - // e1.printStackTrace(); - // } - IProgressMonitor monitor = null; - try { - CloudModel.getRoot().refresh( monitor ); - } catch( ProblemException e2 ) { - e2.printStackTrace(); - } - // Refresh Palette Compartments - getDiagramTypeProvider().getFeatureProvider() - .getDiagramTypeProvider() - .getDiagramBehavior() - .refreshPalette(); - ApplicationComponentNameSection.this.keypairText.setText( dialog.getFileName() ); + // File tmp = new File( targetPath ); + // try { + // tmp.createNewFile(); + // tmp. + // } catch( IOException e1 ) { + // // TODO Auto-generated catch block + // e1.printStackTrace(); + // } + IProgressMonitor monitor = null; + try { + CloudModel.getRoot().refresh( monitor ); + } catch( ProblemException e2 ) { + e2.printStackTrace(); } - } - - @Override - public void widgetDefaultSelected( final SelectionEvent e ) { - // TODO Auto-generated method stub - } - } ); - // Add section components to the toolkit - toolkit.adapt( vmImageLabel, true, true ); - toolkit.adapt( this.cmbImageSize, true, true ); - toolkit.adapt( valueLabel, true, true ); - toolkit.adapt( this.nameText, true, true ); - toolkit.adapt( imageLabel, true, true ); - toolkit.adapt( this.imageText, true, true ); - toolkit.adapt( keypairLabel, true, true ); - toolkit.adapt( this.keypairText, true, true ); - toolkit.adapt( vmDecsrLabel, true, true ); - toolkit.adapt( this.descrText, true, true); - section.setClient( client ); - // Application Component Instances Section - Section sectionInstances = toolkit.createSection( parent, Section.TITLE_BAR ); - sectionInstances.setText( "Number of Instances" ); //$NON-NLS-1$ - Composite clientInstances = toolkit.createComposite( sectionInstances, - SWT.WRAP ); - GridLayout layoutInstances = new GridLayout(); - layoutInstances.numColumns = 2; - layoutInstances.marginTop = 15; - layoutInstances.verticalSpacing = 15; - layoutInstances.marginWidth = 2; - layoutInstances.marginHeight = 2; - clientInstances.setLayout( layoutInstances ); - GridData gdInstances; - CLabel initialInstancesLabel = factory.createCLabel( clientInstances, - "Initial:" ); //$NON-NLS-1$ - gdInstances = new GridData(); - gdInstances.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - gdInstances.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; - // gd.widthHint=STANDARD_LABEL_WIDTH; - initialInstancesLabel.setLayoutData( gdInstances ); - this.initialInstancesText = factory.createText( clientInstances, "1" ); //$NON-NLS-1$ - this.initialInstancesText.setEditable( true ); - gdInstances = new GridData(); - gdInstances.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - gdInstances.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; - gdInstances.widthHint = 160; - this.initialInstancesText.setLayoutData( gdInstances ); - this.initialInstancesText.addModifyListener( this ); - CLabel minInstancesLabel = factory.createCLabel( clientInstances, "Min:" ); //$NON-NLS-1$ - gdInstances = new GridData(); - gdInstances.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - gdInstances.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; - // gd.widthHint=STANDARD_LABEL_WIDTH; - minInstancesLabel.setLayoutData( gdInstances ); - this.minInstancesText = factory.createText( clientInstances, "" ); //$NON-NLS-1$ - this.minInstancesText.setEditable( true ); - gdInstances = new GridData(); - gdInstances.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - gdInstances.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; - gdInstances.widthHint = 160; - this.minInstancesText.setLayoutData( gdInstances ); - this.minInstancesText.addModifyListener( this ); - CLabel maxInstancesLabel = factory.createCLabel( clientInstances, "Max:" ); //$NON-NLS-1$ - gdInstances = new GridData(); - gdInstances.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - gdInstances.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; - // gd.widthHint=STANDARD_LABEL_WIDTH; - maxInstancesLabel.setLayoutData( gdInstances ); - this.maxInstancesText = factory.createText( clientInstances, "" ); //$NON-NLS-1$ - this.maxInstancesText.setEditable( true ); - gdInstances = new GridData(); - gdInstances.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - gdInstances.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; - gdInstances.widthHint = 160; - this.maxInstancesText.setLayoutData( gdInstances ); - this.maxInstancesText.addModifyListener( this ); - // Add section components to the toolkit - toolkit.adapt( valueLabel, true, true ); - toolkit.adapt( this.nameText, true, true ); - toolkit.adapt( imageLabel, true, true ); - toolkit.adapt( this.imageText, true, true ); - section.setClient( client ); - toolkit.adapt( minInstancesLabel, true, true ); - toolkit.adapt( maxInstancesLabel, true, true ); - toolkit.adapt( this.minInstancesText, true, true ); - toolkit.adapt( this.maxInstancesText, true, true ); - sectionInstances.setClient( clientInstances ); - } - - /* - * Refresh values of max and min instances - */ - void refreshInstances() { - PictogramElement pe = getSelectedPictogramElement(); - if( pe != null ) { - Object bo = Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( pe ); - if( bo == null ) - return; - TNodeTemplateExtension appComponent; - if( bo instanceof TDeploymentArtifact ) { - PictogramElement parentPE = Graphiti.getPeService() - .getPictogramElementParent( pe ); - appComponent = ( TNodeTemplateExtension )Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( parentPE ); - } else { // bo instanceof TNodeTemplate - appComponent = ( TNodeTemplateExtension )bo; - } - String initInstances = Integer.toString( appComponent.getInitInstances() ); - this.initialInstancesText.setText( initInstances ); - String minInstances = Integer.toString( appComponent.getMinInstances() ); - String maxInstances = ( ( BigInteger )appComponent.getMaxInstances() ).toString(); - if( minInstances.compareTo( "-1" ) == 0 ) //$NON-NLS-1$ - minInstances = ""; //$NON-NLS-1$ - if( maxInstances.compareTo( "-1" ) == 0 ) //$NON-NLS-1$ - maxInstances = ""; //$NON-NLS-1$ - this.minInstancesText.setText( minInstances ); - this.maxInstancesText.setText( maxInstances ); - } - } - - // Refresh Tab - @Override - public void refresh() { - PictogramElement pe = getSelectedPictogramElement(); - if( pe != null ) { - final Object bo = Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( pe ); - if( bo == null ) - return; - TNodeTemplate appComponent; - if( bo instanceof TDeploymentArtifact ) { - PictogramElement parentPE = Graphiti.getPeService() - .getPictogramElementParent( pe ); - appComponent = ( TNodeTemplate )Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( parentPE ); - } else { // bo instanceof TNodeTemplate - appComponent = ( TNodeTemplate )bo; - } - String name = appComponent.getName(); - this.nameText.setText( name == null - ? "" : name ); //$NON-NLS-1$ - // set Image Artifact - String imageName = null; - TDeploymentArtifacts deploymentArtifacts = appComponent.getDeploymentArtifacts(); - if( deploymentArtifacts != null ) { - for( TDeploymentArtifact artifact : deploymentArtifacts.getDeploymentArtifact() ) - { - if( artifact.getArtifactType().toString().equals( "VMI" ) ) { //$NON-NLS-1$ - imageName = artifact.getName(); - break; - } - } - } - this.imageText.setText( imageName == null - ? "" : imageName ); //$NON-NLS-1$ - - // set VM Flavor - if ( appComponent.getProperties() != null ){ - NodePropertiesType nodeProperties = (NodePropertiesType) appComponent.getProperties().getAny().get( 0 ).getValue(); - String flavor = nodeProperties.getFlavor(); - this.cmbImageSize.setText( flavor == null - ? "" : flavor ); //$NON-NLS-1$ - } - else{ - this.cmbImageSize.setText( "" ); - } - - if( !( bo instanceof TDeploymentArtifact ) ) - refreshInstances(); - } - } - - // Updates Application name or number of instances according the triggered - // listener - @Override - public void modifyText( final ModifyEvent e ) { - PictogramElement pe = getSelectedPictogramElement(); - if( pe != null ) { - final Object bo = Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( pe ); - // the filter assured, that it is a TNodeTemplate - if( bo == null ) - return; - final TNodeTemplateExtension nodeTemplate; - if( bo instanceof TDeploymentArtifact ) { - PictogramElement parentPE = Graphiti.getPeService() - .getPictogramElementParent( pe ); - nodeTemplate = ( TNodeTemplateExtension )Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( parentPE ); - } else { // bo instanceof TNodeTemplate - nodeTemplate = ( TNodeTemplateExtension )bo; - } - // nameText Listener - if( e.widget == this.nameText ) { - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { - - protected void doExecute() { - nodeTemplate.setName( ApplicationComponentNameSection.this.nameText.getText() ); - } - } ); - } - // minInstancesText Listener - else if( e.widget == this.minInstancesText ) { - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { - - protected void doExecute() { - if( nodeTemplate != null ) { - if( ApplicationComponentNameSection.this.minInstancesText.getText() - .equals( "" ) ) { //$NON-NLS-1$ - // nodeTemplate.setMinInstances( -1 ); - } else - nodeTemplate.setMinInstances( Integer.parseInt( ApplicationComponentNameSection.this.minInstancesText.getText() ) ); - } - } - } ); - } - // maxInstancesText Listener - else if( e.widget == this.maxInstancesText ) { - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { - - protected void doExecute() { - if( ApplicationComponentNameSection.this.maxInstancesText.getText() - .compareTo( "" ) == 0 ) { //$NON-NLS-1$ - // nodeTemplate.setMaxInstances( ( BigInteger - // )BigInteger.valueOf(-1) ); - } else - nodeTemplate.setMaxInstances( ( BigInteger )BigInteger.valueOf( Integer.parseInt( ApplicationComponentNameSection.this.maxInstancesText.getText() ) ) ); - } - } ); - } - // initialInstancesText Listener - else if( e.widget == this.initialInstancesText ) { - if( ApplicationComponentNameSection.this.initialInstancesText.getText() - .compareTo( "" ) == 0 ) { //$NON-NLS-1$ - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { - - protected void doExecute() { - nodeTemplate.setInitInstances( 1 ); - } - } ); - } else if( nodeTemplate.getInitInstances() != Integer.parseInt( ApplicationComponentNameSection.this.initialInstancesText.getText() ) ) - { - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { - - protected void doExecute() { - nodeTemplate.setInitInstances( Integer.parseInt( ApplicationComponentNameSection.this.initialInstancesText.getText() ) ); - } - } ); - } +// // Refresh Palette Compartments +// getDiagramTypeProvider().getFeatureProvider() +// .getDiagramTypeProvider() +// .getDiagramBehavior() +// .refreshPalette(); + ApplicationComponentNameSection.this.keypairText.setText( dialog.getFileName() ); } } - } - private void createNodeFlavorProperties( String flavor ) { - PictogramElement pe = getSelectedPictogramElement(); - final TNodeTemplateExtension appComponent; + @Override + public void widgetDefaultSelected( final SelectionEvent e ) { + // TODO Auto-generated method stub + } + } ); + // Add section components to the toolkit + toolkit.adapt( vmImageLabel, true, true ); + toolkit.adapt( this.cmbImageSize, true, true ); + toolkit.adapt( valueLabel, true, true ); + toolkit.adapt( this.nameText, true, true ); + toolkit.adapt( imageLabel, true, true ); + toolkit.adapt( this.imageText, true, true ); + toolkit.adapt( keypairLabel, true, true ); + toolkit.adapt( this.keypairText, true, true ); +// toolkit.adapt( vmDecsrLabel, true, true ); +// toolkit.adapt( this.descrText, true, true); + section.setClient( client ); + // Application Component Instances Section + Section sectionInstances = toolkit.createSection( parent, Section.TITLE_BAR ); + sectionInstances.setText( "Number of Instances" ); //$NON-NLS-1$ + Composite clientInstances = toolkit.createComposite( sectionInstances, + SWT.WRAP ); + GridLayout layoutInstances = new GridLayout(); + layoutInstances.numColumns = 2; + layoutInstances.marginTop = 15; + layoutInstances.verticalSpacing = 15; + layoutInstances.marginWidth = 2; + layoutInstances.marginHeight = 2; + clientInstances.setLayout( layoutInstances ); + GridData gdInstances; + + CLabel minInstancesLabel = factory.createCLabel( clientInstances, "Min:" ); //$NON-NLS-1$ + gdInstances = new GridData(); + gdInstances.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + gdInstances.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; + // gd.widthHint=STANDARD_LABEL_WIDTH; + minInstancesLabel.setLayoutData( gdInstances ); + this.minInstancesText = factory.createText( clientInstances, "" ); //$NON-NLS-1$ + this.minInstancesText.setEditable( true ); + gdInstances = new GridData(); + gdInstances.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + gdInstances.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; + gdInstances.widthHint = 160; + this.minInstancesText.setLayoutData( gdInstances ); + this.minInstancesText.addModifyListener( this ); + CLabel maxInstancesLabel = factory.createCLabel( clientInstances, "Max:" ); //$NON-NLS-1$ + gdInstances = new GridData(); + gdInstances.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + gdInstances.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; + // gd.widthHint=STANDARD_LABEL_WIDTH; + maxInstancesLabel.setLayoutData( gdInstances ); + this.maxInstancesText = factory.createText( clientInstances, "" ); //$NON-NLS-1$ + this.maxInstancesText.setEditable( true ); + gdInstances = new GridData(); + gdInstances.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + gdInstances.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; + gdInstances.widthHint = 160; + this.maxInstancesText.setLayoutData( gdInstances ); + this.maxInstancesText.addModifyListener( this ); + // Add section components to the toolkit + toolkit.adapt( valueLabel, true, true ); + toolkit.adapt( this.nameText, true, true ); + toolkit.adapt( imageLabel, true, true ); + toolkit.adapt( this.imageText, true, true ); + section.setClient( client ); + toolkit.adapt( minInstancesLabel, true, true ); + toolkit.adapt( maxInstancesLabel, true, true ); + toolkit.adapt( this.minInstancesText, true, true ); + toolkit.adapt( this.maxInstancesText, true, true ); + sectionInstances.setClient( clientInstances ); +} + +/* + * Refresh values of max and min instances + */ +void refreshInstances() { + PictogramElement pe = getSelectedPictogramElement(); + if( pe != null ) { Object bo = Graphiti.getLinkService() .getBusinessObjectForLinkedPictogramElement( pe ); if( bo == null ) return; + TNodeTemplateExtension appComponent; if( bo instanceof TDeploymentArtifact ) { PictogramElement parentPE = Graphiti.getPeService() .getPictogramElementParent( pe ); @@ -678,75 +819,221 @@ } else { // bo instanceof TNodeTemplate appComponent = ( TNodeTemplateExtension )bo; } - // Create Flavor Properties - NodePropertiesType nodeProperties = Tosca_Elasticity_ExtensionsFactory.eINSTANCE.createNodePropertiesType(); - nodeProperties.setFlavor( flavor ); - // Set the Properties of the Policy Template - final PropertiesType properties = ToscaFactory.eINSTANCE.createPropertiesType(); - // Add the SYBL Policy to the FeatureMap of the Policy's Properties element - Entry e = FeatureMapUtil.createEntry( Tosca_Elasticity_ExtensionsPackage.eINSTANCE.getDocumentRoot_NodeProperties(), - nodeProperties ); - properties.getAny().add( e ); - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( appComponent ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { - @Override - protected void doExecute() { - appComponent.setProperties( properties ); + String minInstances = Integer.toString( appComponent.getMinInstances() ); + String maxInstances = ( ( BigInteger )appComponent.getMaxInstances() ).toString(); + if( minInstances.compareTo( "-1" ) == 0 ) //$NON-NLS-1$ + minInstances = ""; //$NON-NLS-1$ + if( maxInstances.compareTo( "-1" ) == 0 ) //$NON-NLS-1$ + maxInstances = ""; //$NON-NLS-1$ + this.minInstancesText.setText( minInstances ); + this.maxInstancesText.setText( maxInstances ); + } +} + +// Refresh Tab +@Override +public void refresh() { + PictogramElement pe = getSelectedPictogramElement(); + if( pe != null ) { + final Object bo = Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( pe ); + if( bo == null ) + return; + TNodeTemplate appComponent; + if( bo instanceof TDeploymentArtifact ) { + PictogramElement parentPE = Graphiti.getPeService() + .getPictogramElementParent( pe ); + appComponent = ( TNodeTemplate )Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( parentPE ); + } else { // bo instanceof TNodeTemplate + appComponent = ( TNodeTemplate )bo; + } + String name = appComponent.getName(); + this.nameText.setText( name == null + ? "" : name ); //$NON-NLS-1$ + // set Image Artifact + String imageName = null; + TDeploymentArtifacts deploymentArtifacts = appComponent.getDeploymentArtifacts(); + if( deploymentArtifacts != null ) { + for( TDeploymentArtifact artifact : deploymentArtifacts.getDeploymentArtifact() ) + { + if( artifact.getArtifactType().getLocalPart().equals( imageType ) ) { //$NON-NLS-1$ + imageName = artifact.getName(); + break; } - } ); - } - - @Override - public void widgetSelected( SelectionEvent e ) { - // TODO Auto-generated method stub - - } - - @Override - public void widgetDefaultSelected( SelectionEvent e ) { - // TODO Auto-generated method stub - - } - - private void copySelectedFileToCloudProject(File source, File destination){ - - InputStream selection = null; - OutputStream output = null; - try { - try { - selection = new FileInputStream(source); - } catch( FileNotFoundException e ) { - // TODO Auto-generated catch block - e.printStackTrace(); } + } + this.imageText.setText( imageName == null + ? "" : imageName ); //$NON-NLS-1$ + + // set VM Flavor + if ( appComponent.getProperties() != null ){ + NodePropertiesType nodeProperties = (NodePropertiesType) appComponent.getProperties().getAny().get( 0 ).getValue(); + String flavor = nodeProperties.getFlavor(); + this.cmbImageSize.setText( flavor == null + ? "" : flavor ); //$NON-NLS-1$ + } + else{ + this.cmbImageSize.setText( "" ); + } + + if( !( bo instanceof TDeploymentArtifact ) ) + refreshInstances(); + } +} + +// Updates Application name or number of instances according the triggered +// listener +@Override +public void modifyText( final ModifyEvent e ) { + PictogramElement pe = getSelectedPictogramElement(); + if( pe != null ) { + final Object bo = Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( pe ); + // the filter assured, that it is a TNodeTemplate + if( bo == null ) + return; + final TNodeTemplateExtension nodeTemplate; + if( bo instanceof TDeploymentArtifact ) { + PictogramElement parentPE = Graphiti.getPeService() + .getPictogramElementParent( pe ); + nodeTemplate = ( TNodeTemplateExtension )Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( parentPE ); + } else { // bo instanceof TNodeTemplate + nodeTemplate = ( TNodeTemplateExtension )bo; + } + // nameText Listener + if( e.widget == this.nameText ) { + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { + + protected void doExecute() { + nodeTemplate.setName( ApplicationComponentNameSection.this.nameText.getText() ); + } + } ); + } + // minInstancesText Listener + else if( e.widget == this.minInstancesText ) { + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { + + protected void doExecute() { + if( nodeTemplate != null ) { + if( ApplicationComponentNameSection.this.minInstancesText.getText() + .equals( "" ) ) { //$NON-NLS-1$ + // nodeTemplate.setMinInstances( -1 ); + } else + nodeTemplate.setMinInstances( Integer.parseInt( ApplicationComponentNameSection.this.minInstancesText.getText() ) ); + } + } + } ); + } + // maxInstancesText Listener + else if( e.widget == this.maxInstancesText ) { + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { + + protected void doExecute() { + if( ApplicationComponentNameSection.this.maxInstancesText.getText() + .compareTo( "" ) == 0 ) { //$NON-NLS-1$ + // nodeTemplate.setMaxInstances( ( BigInteger + // )BigInteger.valueOf(-1) ); + } else + nodeTemplate.setMaxInstances( ( BigInteger )BigInteger.valueOf( Integer.parseInt( ApplicationComponentNameSection.this.maxInstancesText.getText() ) ) ); + } + } ); + } + } +} + +private void createNodeFlavorProperties( String flavor ) { + PictogramElement pe = getSelectedPictogramElement(); + final TNodeTemplateExtension appComponent; + Object bo = Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( pe ); + if( bo == null ) + return; + if( bo instanceof TDeploymentArtifact ) { + PictogramElement parentPE = Graphiti.getPeService() + .getPictogramElementParent( pe ); + appComponent = ( TNodeTemplateExtension )Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( parentPE ); + } else { // bo instanceof TNodeTemplate + appComponent = ( TNodeTemplateExtension )bo; + } + // Create Flavor Properties + NodePropertiesType nodeProperties = Tosca_Elasticity_ExtensionsFactory.eINSTANCE.createNodePropertiesType(); + nodeProperties.setFlavor( flavor ); + // Set the Properties of the Policy Template + final PropertiesType properties = ToscaFactory.eINSTANCE.createPropertiesType(); + // Add the SYBL Policy to the FeatureMap of the Policy's Properties element + Entry e = FeatureMapUtil.createEntry( Tosca_Elasticity_ExtensionsPackage.eINSTANCE.getDocumentRoot_NodeProperties(), + nodeProperties ); + properties.getAny().add( e ); + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( appComponent ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { + + @Override + protected void doExecute() { + appComponent.setProperties( properties ); + } + } ); +} + +@Override +public void widgetSelected( SelectionEvent e ) { + // TODO Auto-generated method stub + +} + +@Override +public void widgetDefaultSelected( SelectionEvent e ) { + // TODO Auto-generated method stub + +} + +private void copySelectedFileToCloudProject(File source, File destination){ + + InputStream selection = null; + OutputStream output = null; + try { try { - output = new FileOutputStream(destination); + selection = new FileInputStream(source); } catch( FileNotFoundException e ) { // TODO Auto-generated catch block e.printStackTrace(); } - byte[] buf = new byte[1024]; - int bytesRead; - try { - while ((bytesRead = selection.read(buf)) > 0) { - output.write(buf, 0, bytesRead); - } + try { + output = new FileOutputStream(destination); + } catch( FileNotFoundException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + byte[] buf = new byte[1024]; + int bytesRead; + try { + while ((bytesRead = selection.read(buf)) > 0) { + output.write(buf, 0, bytesRead); + } + } catch( IOException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } finally { + try { + selection.close(); + output.close(); } catch( IOException e ) { // TODO Auto-generated catch block e.printStackTrace(); } - } finally { - try { - selection.close(); - output.close(); - } catch( IOException e ) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - + } + +} }
diff --git a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/property/ApplicationComponentScriptSection.java b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/property/ApplicationComponentScriptSection.java index b912bd4..66946d6 100644 --- a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/property/ApplicationComponentScriptSection.java +++ b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/property/ApplicationComponentScriptSection.java
@@ -25,18 +25,28 @@ import org.eclipse.camf.core.model.CloudModel; import org.eclipse.camf.core.reporting.ProblemException; +import org.eclipse.camf.tosca.DefinitionsType; +import org.eclipse.camf.tosca.DocumentRoot; +import org.eclipse.camf.tosca.TArtifactReference; +import org.eclipse.camf.tosca.TArtifactTemplate; import org.eclipse.camf.tosca.TDeploymentArtifact; import org.eclipse.camf.tosca.TDeploymentArtifacts; import org.eclipse.camf.tosca.ToscaFactory; +import org.eclipse.camf.tosca.editor.ModelHandler; import org.eclipse.camf.tosca.editor.ToscaDiagramEditor; +import org.eclipse.camf.tosca.editor.ToscaModelLayer; import org.eclipse.camf.tosca.editor.diagram.ToscaFeatureProvider; import org.eclipse.camf.tosca.editor.features.CreateSoftwareDependencyFeature; import org.eclipse.camf.tosca.elasticity.TNodeTemplateExtension; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.graphiti.features.context.impl.CreateContext; import org.eclipse.graphiti.mm.pictograms.ContainerShape; import org.eclipse.graphiti.mm.pictograms.PictogramElement; @@ -60,240 +70,240 @@ * Application Component Properties - Custom Scripts Tab */ public class ApplicationComponentScriptSection extends GFPropertySection - implements ITabbedPropertyConstants, ModifyListener +implements ITabbedPropertyConstants, ModifyListener { - Section section; - private Text deploymentScriptText; +Section section; +private Text deploymentScriptText; - @Override - public void createControls( Composite parent, - TabbedPropertySheetPage tabbedPropertySheetPage ) - { - super.createControls( parent, tabbedPropertySheetPage ); - // TabbedPropertySheetWidgetFactory factory = getWidgetFactory(); - FormToolkit toolkit = new FormToolkit( parent.getDisplay() ); - this.section = toolkit.createSection( parent, Section.TITLE_BAR ); - this.section.setText( "Deployment Script" ); //$NON-NLS-1$ - Composite client = toolkit.createComposite( this.section, SWT.WRAP ); +@Override +public void createControls( Composite parent, + TabbedPropertySheetPage tabbedPropertySheetPage ) +{ + super.createControls( parent, tabbedPropertySheetPage ); + // TabbedPropertySheetWidgetFactory factory = getWidgetFactory(); + FormToolkit toolkit = new FormToolkit( parent.getDisplay() ); + this.section = toolkit.createSection( parent, Section.TITLE_BAR ); + this.section.setText( "Deployment Script" ); //$NON-NLS-1$ + Composite client = toolkit.createComposite( this.section, SWT.WRAP ); + GridLayout layout = new GridLayout(); + layout.numColumns = 1; + layout.marginTop = 15; + layout.marginWidth = 2; + layout.marginHeight = 2; + client.setLayout( layout ); + TabbedPropertySheetWidgetFactory factory = getWidgetFactory(); + deploymentScriptText = factory.createText( client, + "", SWT.V_SCROLL | SWT.H_SCROLL ); //$NON-NLS-1$ + GridData gd = new GridData(); + gd.widthHint = 1100; + gd.heightHint = 150; + gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; + this.deploymentScriptText.setLayoutData( gd ); + deploymentScriptText.addModifyListener( this ); + // Add section components to the toolkit + toolkit.adapt( this.deploymentScriptText, true, true ); + this.section.setClient( client ); +} - GridLayout layout = new GridLayout(); - layout.numColumns = 1; - layout.marginTop = 15; - layout.marginWidth = 2; - layout.marginHeight = 2; - client.setLayout( layout ); - - TabbedPropertySheetWidgetFactory factory = getWidgetFactory(); - - deploymentScriptText = factory.createText(client, "", SWT.V_SCROLL | SWT.H_SCROLL ); //$NON-NLS-1$ - - GridData gd = new GridData(); - gd.widthHint = 1100; - gd.heightHint = 150; - gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; - - this.deploymentScriptText.setLayoutData( gd ); - - - deploymentScriptText.addModifyListener( this ); - - // Add section components to the toolkit - toolkit.adapt( this.deploymentScriptText, true, true ); - this.section.setClient( client ); - } - - - - /* - * Refresh Tab(non-Javadoc) - * @see org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#refresh() - */ - @Override - public void refresh() { - - - PictogramElement pe = getSelectedPictogramElement(); - TNodeTemplateExtension appComponent = null; - if( pe != null ) { - Object bo = Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( pe ); - if( bo == null ) - return; - - if ( bo instanceof TDeploymentArtifact ){ - PictogramElement parentPE = Graphiti.getPeService().getPictogramElementParent( pe ); - - appComponent = ( TNodeTemplateExtension ) Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement( parentPE ); - } - else { // bo instanceof TNodeTemplate - appComponent = ( TNodeTemplateExtension )bo; - } - } - - String fileName = null; - TDeploymentArtifacts deploymentArtifacts = appComponent.getDeploymentArtifacts(); - if ( deploymentArtifacts != null ){ - for ( TDeploymentArtifact artifact : deploymentArtifacts.getDeploymentArtifact() ){ - if ( artifact.getArtifactType().toString().equals( "UA" )){ - fileName = artifact.getName(); - break; - } - } - } - - IProject activeProject = ToscaDiagramEditor.getActiveProject(); - - if ( activeProject != null ){ - - IFile file = activeProject.getFile( new Path("/Artifacts/Deployment Scripts/" + fileName)); - - if ( file.exists() == true ){ - //Convert deployment script file to String - BufferedReader br = null; - StringBuilder sb = new StringBuilder(); - String line; - - try { - br = new BufferedReader(new InputStreamReader(file.getContents())); - } catch( CoreException e1 ) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - - try { - while ((line = br.readLine()) != null) { - sb.append(line + "\n"); - } - } catch( IOException e1 ) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - - this.deploymentScriptText.setText(sb.toString()); - } - else{ - this.deploymentScriptText.setText( "" ); - } - } - - } - - @Override - public void modifyText( ModifyEvent e ) { - - if ( this.deploymentScriptText.getText().equals("") ){ - // this is also the case where the Deployment Script tab is preopened +/* + * Refresh Tab(non-Javadoc) + * @see + * org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#refresh() + */ +@Override +public void refresh() { + PictogramElement pe = getSelectedPictogramElement(); + PictogramElement parentPE = Graphiti.getPeService() + .getPictogramElementParent( pe ); + TNodeTemplateExtension appComponent = null; + if( pe != null ) { + Object bo = Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( pe ); + if( bo == null ) return; + if( bo instanceof TArtifactTemplate ) { + appComponent = ( TNodeTemplateExtension )Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( parentPE ); + } else { // bo instanceof TNodeTemplate + appComponent = ( TNodeTemplateExtension )bo; } - - PictogramElement pe = getSelectedPictogramElement(); - TNodeTemplateExtension appComponent = null; - if( pe != null ) { - Object bo = Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( pe ); - if( bo == null ) - return; - - if ( bo instanceof TDeploymentArtifact ){ - PictogramElement parentPE = Graphiti.getPeService().getPictogramElementParent( pe ); - - appComponent = ( TNodeTemplateExtension ) Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement( parentPE ); - } - else { // bo instanceof TNodeTemplate - appComponent = ( TNodeTemplateExtension )bo; - } - } - - IProject activeProject = ToscaDiagramEditor.getActiveProject(); - - if ( activeProject != null ){ - - String fileName = appComponent.getName() + " Deployment.sh"; - - IFile file = activeProject.getFile( new Path("/Artifacts/Deployment Scripts/" + fileName)); - - if ( !file.exists() ){ - file = createDeploymentScript(activeProject); - } - else{ - try { - file.setContents( new ByteArrayInputStream(this.deploymentScriptText.getText().getBytes()), false, false, null ); - } catch( CoreException e1 ) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - } - - - } - } - // Creates the Application Deployment file - public IFile createDeploymentScript(IProject activeProject) { - - IFile file = null; - - PictogramElement pe = getSelectedPictogramElement(); - TNodeTemplateExtension appComponent = null; - if( pe != null ) { - Object bo = Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( pe ); - if( bo == null ) - return null; - - if ( bo instanceof TDeploymentArtifact ){ - PictogramElement parentPE = Graphiti.getPeService().getPictogramElementParent( pe ); - pe = parentPE; - appComponent = ( TNodeTemplateExtension ) Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement( parentPE ); - - } - else { // bo instanceof TNodeTemplate - appComponent = ( TNodeTemplateExtension )bo; - } - } - - String fileName = appComponent.getName() + "Deployment"; - - file = activeProject.getFile( new Path("/Artifacts/Deployment Scripts/" + fileName)); - try { - file.create(new ByteArrayInputStream(this.deploymentScriptText.getText().getBytes()), false, null); - } catch (CoreException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - return null; - } - - - IProgressMonitor monitor = null; + String fileName = findImplementationArtifactName(appComponent.getName()+"Script"); +// String fileName = null; +// // Find NodeTypeImplementation +// ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( +// getDiagram() ) ); +// DocumentRoot dr = model.getDocumentRoot(); +// DefinitionsType dt = dr.getDefinitions(); +// EList<TNodeTypeImplementation> nodeTypesImplementation = +// dt.getNodeTypeImplementation(); +// EList<TArtifactTemplate> artifactTemplates = dt.getArtifactTemplate(); +// TNodeTypeImplementation nodeTypeImplementation = null; +// for (TNodeTypeImplementation tempNodeImplementation : +// nodeTypesImplementation){ +// if (appComponent.getName().equals( +// tempNodeImplementation.getNodeType().toString())){ +// nodeTypeImplementation = tempNodeImplementation; +// break; +// } +// } +// if (nodeTypeImplementation!=null && +// nodeTypeImplementation.getImplementationArtifacts()!=null){ +// EList<ImplementationArtifactType> implementationArtifacts = +// nodeTypeImplementation.getImplementationArtifacts().getImplementationArtifact(); +// for (ImplementationArtifactType tempImplementationArtifact : +// implementationArtifacts){ +// for (TArtifactTemplate tempArtifactTemplate : artifactTemplates){ +// if +// (tempArtifactTemplate.getId().equals(tempImplementationArtifact.getArtifactRef().toString())){ +// fileName=tempArtifactTemplate.getId(); +// break; +// } +// } +// +// } +// } + //fileName = appComponent.getName() + "Deployment.sh"; + IProject activeProject = ToscaDiagramEditor.getActiveProject(); + if( activeProject != null ) { + IFile file = activeProject.getFile( new Path( "/Artifacts/Deployment Scripts/" + + fileName ) ); + if( file.exists() == true ) { + // if ( file.exists() == true ){ + // Convert deployment script file to String + BufferedReader br = null; + StringBuilder sb = new StringBuilder(); + String line; try { - CloudModel.getRoot().refresh( monitor ); - } catch( ProblemException e ) { - e.printStackTrace(); + br = new BufferedReader( new InputStreamReader( file.getContents() ) ); + } catch( CoreException e1 ) { + // TODO Auto-generated catch block + e1.printStackTrace(); } - - // Refresh Palette Compartments - getDiagramTypeProvider().getFeatureProvider().getDiagramTypeProvider().getDiagramBehavior().refreshPalette(); - - // Call the Create User Application Feature to create a deployment artifact for the deployment script and add it to the artifacts list - CreateSoftwareDependencyFeature createSDFeature = new CreateSoftwareDependencyFeature( new ToscaFeatureProvider(getDiagramTypeProvider()) ); - - TDeploymentArtifact deploymentArtifact = ToscaFactory.eINSTANCE.createTDeploymentArtifact(); - deploymentArtifact.setName( fileName ); - deploymentArtifact.setArtifactType( new QName( "SD" ) ); - - createSDFeature.setContextObject( deploymentArtifact ); - - CreateContext createContext = new CreateContext(); - createContext.setTargetContainer( (ContainerShape) pe ); - - if ( createSDFeature.canCreate( createContext )) - createSDFeature.create( createContext ); - - return file; - + try { + while( ( line = br.readLine() ) != null ) { + sb.append( line + "\n" ); + } + } catch( IOException e1 ) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + this.deploymentScriptText.setText( sb.toString() ); + } else { + this.deploymentScriptText.setText( "" ); + } + } +} + +@Override +public void modifyText( ModifyEvent e ) { + if( this.deploymentScriptText.getText().equals( "" ) ) { + // this is also the case where the Deployment Script tab is preopened + return; + } + IProject activeProject = ToscaDiagramEditor.getActiveProject(); + if( activeProject != null ) { + createDeploymentScript( activeProject ); + } +} + +// Creates the Application Deployment file +public IFile createDeploymentScript( IProject activeProject ) { + IFile file = null; + PictogramElement pe = getSelectedPictogramElement(); + TNodeTemplateExtension appComponent = null; + if( pe != null ) { + Object bo = Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( pe ); + if( bo == null ) + return null; + if( bo instanceof TDeploymentArtifact ) { + PictogramElement parentPE = Graphiti.getPeService() + .getPictogramElementParent( pe ); + pe = parentPE; + appComponent = ( TNodeTemplateExtension )Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( parentPE ); + } else { // bo instanceof TNodeTemplate + appComponent = ( TNodeTemplateExtension )bo; + } + } + String fileName = appComponent.getName() + "Deployment.sh"; + file = activeProject.getFile( new Path( "/Artifacts/Deployment Scripts/" + + fileName ) ); + if( file.exists() ) { + // Deployment file exists, update its contents + try { + file.setContents( new ByteArrayInputStream( this.deploymentScriptText.getText() + .getBytes() ), + false, + false, + null ); + } catch( CoreException e1 ) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + return null; + } + // Deployment file does not exists, create one + try { + file.create( new ByteArrayInputStream( this.deploymentScriptText.getText() + .getBytes() ), + false, + null ); + } catch( CoreException e1 ) { + // TODO Auto-generated catch block + e1.printStackTrace(); + return null; + } + try { + activeProject.refreshLocal( IResource.DEPTH_INFINITE, + new NullProgressMonitor() ); + } catch( CoreException e1 ) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + IProgressMonitor monitor = null; + try { + CloudModel.getRoot().refresh( monitor ); + } catch( ProblemException e ) { + e.printStackTrace(); + } + // Refresh Palette Compartments + // getDiagramTypeProvider().getFeatureProvider().getDiagramTypeProvider().getDiagramBehavior().refreshPalette(); + // Call the Create User Application Feature to create a deployment artifact + // for the deployment script and add it to the artifacts list + CreateSoftwareDependencyFeature createSDFeature = new CreateSoftwareDependencyFeature( new ToscaFeatureProvider( getDiagramTypeProvider() ) ); + TArtifactTemplate artifactTemplate = ToscaFactory.eINSTANCE.createTArtifactTemplate(); + artifactTemplate.setName( "SD"+fileName ); + artifactTemplate.setId( fileName ); + artifactTemplate.setType( new QName( "ScriptArtifact" ) ); + createSDFeature.setContextObject( artifactTemplate ); + CreateContext createContext = new CreateContext(); + createContext.setTargetContainer( ( ContainerShape )pe ); + if( createSDFeature.canCreate( createContext ) ) + createSDFeature.create( createContext ); + return file; +} + +private String findImplementationArtifactName(String artifactId){ + ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); + DocumentRoot dr = model.getDocumentRoot(); + DefinitionsType dt = dr.getDefinitions(); + EList<TArtifactTemplate> artifactTemplates = + dt.getArtifactTemplate(); + + for (TArtifactTemplate tempArtifactTemplate : artifactTemplates){ + if (tempArtifactTemplate.getId().equals( artifactId )){ + TArtifactReference artifactRef = tempArtifactTemplate.getArtifactReferences().getArtifactReference().get( 0 ); + String artifactReference = artifactRef.getReference(); + String artifactName = artifactReference.substring( artifactReference.indexOf( "\\" ) +1); + return artifactName; + } } + return null; +} }
diff --git a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/property/ApplicationGlobalElasticityReqSection.java b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/property/ApplicationGlobalElasticityReqSection.java index 5f73157..aad7be9 100644 --- a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/property/ApplicationGlobalElasticityReqSection.java +++ b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/property/ApplicationGlobalElasticityReqSection.java
@@ -76,685 +76,564 @@ /** * Application Properties - Elasticity Tab */ -public class ApplicationGlobalElasticityReqSection - extends GFPropertySection implements ITabbedPropertyConstants +public class ApplicationGlobalElasticityReqSection extends GFPropertySection +implements ITabbedPropertyConstants { - Composite client; - Section section; - private Table table; - private Button addButton; - private Button removeButton; - TableViewer tableViewer; - List<TPolicy> appComponentElasticityRequirements = new ArrayList<TPolicy>(); - Section sectionRA; - private Table tableResizingActions; - private Button removeButtonRA; - private Button addButtonRA; - private Button conditionButtonRA; - TableViewer tableResizingActionsViewer; - List<TPolicy> appComponentResizingActions = new ArrayList<TPolicy>(); - protected Tosca_Elasticity_ExtensionsFactory elasticityFactory = Tosca_Elasticity_ExtensionsFactory.eINSTANCE; +Composite client; +Section section; +private Table table; +private Button addButton; +private Button removeButton; +TableViewer tableViewer; +List<TPolicy> appComponentElasticityRequirements = new ArrayList<TPolicy>(); +Section sectionRA; +private Table tableResizingActions; +private Button removeButtonRA; +private Button addButtonRA; +private Button conditionButtonRA; +TableViewer tableResizingActionsViewer; +List<TPolicy> appComponentResizingActions = new ArrayList<TPolicy>(); +protected Tosca_Elasticity_ExtensionsFactory elasticityFactory = Tosca_Elasticity_ExtensionsFactory.eINSTANCE; - @Override - public void createControls( final Composite parent, - TabbedPropertySheetPage tabbedPropertySheetPage ) - { - super.createControls( parent, tabbedPropertySheetPage ); - FormToolkit toolkit = new FormToolkit( parent.getDisplay() ); - // Application Component Elasticity Requirements Section - this.section = toolkit.createSection( parent, Section.TITLE_BAR ); - this.section.setText( "Application Component Elasticity Constraints" ); //$NON-NLS-1$ - Composite client = toolkit.createComposite( this.section, SWT.WRAP ); - Composite client1 = toolkit.createComposite( client, SWT.WRAP ); - Composite client2 = toolkit.createComposite( client, SWT.WRAP ); - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - layout.marginTop = 15; - layout.verticalSpacing = 15; - layout.marginWidth = 2; - layout.marginHeight = 2; - client.setLayout( layout ); - layout = new GridLayout(); - layout.numColumns = 1; - client1.setLayout( layout ); - layout = new GridLayout(); - layout.numColumns = 1; - client2.setLayout( layout ); - GridData gd; - this.table = new Table( client1, SWT.BORDER - | SWT.VIRTUAL - | SWT.MULTI - | SWT.FULL_SELECTION ); - this.table.setHeaderVisible( true ); - this.table.setLinesVisible( false ); - this.table.getHorizontalBar().setEnabled( false ); - gd = new GridData( 300, this.table.getItemHeight() * 4 ); - gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; - this.table.setLayoutData( gd ); - TableLayout tableLayout = new TableLayout(); - this.table.setLayout( tableLayout ); - TableColumn nameColumn = new TableColumn( this.table, SWT.CENTER ); - ColumnLayoutData data = new ColumnWeightData( 100 ); - tableLayout.addColumnData( data ); - data = new ColumnWeightData( 100 ); - tableLayout.addColumnData( data ); - data = new ColumnWeightData( 150 ); - tableLayout.addColumnData( data ); - nameColumn.setText( "Constraint" ); //$NON-NLS-1$ - this.tableViewer = new TableViewer( this.table ); - ElasticityConstraintsProvider ERProvider = new ElasticityConstraintsProvider(); - IStructuredContentProvider contentProvider = ERProvider.ERContentProvider; - this.tableViewer.setContentProvider( contentProvider ); - this.tableViewer.setLabelProvider( ERProvider.ERContentLabelProvider ); - this.tableViewer.setInput( this.appComponentElasticityRequirements ); - this.addButton = new Button( client2, SWT.PUSH ); - this.addButton.setText( "Add" ); //$NON-NLS-1$ - gd = new GridData(); - gd.widthHint = 60; - gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - this.addButton.setLayoutData( gd ); - // Listener for Add button - this.addButton.addSelectionListener( new SelectionListener() { +@Override +public void createControls( final Composite parent, + TabbedPropertySheetPage tabbedPropertySheetPage ) +{ + super.createControls( parent, tabbedPropertySheetPage ); + FormToolkit toolkit = new FormToolkit( parent.getDisplay() ); + // Application Component Elasticity Requirements Section + this.section = toolkit.createSection( parent, Section.TITLE_BAR ); + this.section.setText( "Application Component Elasticity Constraints" ); //$NON-NLS-1$ + Composite client = toolkit.createComposite( this.section, SWT.WRAP ); + Composite client1 = toolkit.createComposite( client, SWT.WRAP ); + Composite client2 = toolkit.createComposite( client, SWT.WRAP ); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + layout.marginTop = 15; + layout.verticalSpacing = 15; + layout.marginWidth = 2; + layout.marginHeight = 2; + client.setLayout( layout ); + layout = new GridLayout(); + layout.numColumns = 1; + client1.setLayout( layout ); + layout = new GridLayout(); + layout.numColumns = 1; + client2.setLayout( layout ); + GridData gd; + this.table = new Table( client1, SWT.BORDER + | SWT.VIRTUAL + | SWT.MULTI + | SWT.FULL_SELECTION ); + this.table.setHeaderVisible( true ); + this.table.setLinesVisible( false ); + this.table.getHorizontalBar().setEnabled( false ); + gd = new GridData( 300, this.table.getItemHeight() * 4 ); + gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; + this.table.setLayoutData( gd ); + TableLayout tableLayout = new TableLayout(); + this.table.setLayout( tableLayout ); + TableColumn nameColumn = new TableColumn( this.table, SWT.CENTER ); + ColumnLayoutData data = new ColumnWeightData( 100 ); + tableLayout.addColumnData( data ); + data = new ColumnWeightData( 100 ); + tableLayout.addColumnData( data ); + data = new ColumnWeightData( 150 ); + tableLayout.addColumnData( data ); + nameColumn.setText( "Constraint" ); //$NON-NLS-1$ + this.tableViewer = new TableViewer( this.table ); + ElasticityConstraintsProvider ERProvider = new ElasticityConstraintsProvider(); + IStructuredContentProvider contentProvider = ERProvider.ERContentProvider; + this.tableViewer.setContentProvider( contentProvider ); + this.tableViewer.setLabelProvider( ERProvider.ERContentLabelProvider ); + this.tableViewer.setInput( this.appComponentElasticityRequirements ); + this.addButton = new Button( client2, SWT.PUSH ); + this.addButton.setText( "Add" ); //$NON-NLS-1$ + gd = new GridData(); + gd.widthHint = 60; + gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + this.addButton.setLayoutData( gd ); + // Listener for Add button + this.addButton.addSelectionListener( new SelectionListener() { - @Override - public void widgetSelected( SelectionEvent e ) { - editDataStagingEntry( null ); - } - - @Override - public void widgetDefaultSelected( final SelectionEvent e ) { - // TODO Auto-generated method stub - } - } ); - this.removeButton = new Button( client2, SWT.PUSH ); - this.removeButton.setText( "Remove" ); //$NON-NLS-1$ - gd = new GridData(); - gd.widthHint = 60; - gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - this.removeButton.setLayoutData( gd ); - // Listener for Remove button - this.removeButton.addSelectionListener( new SelectionListener() { - - @Override - public void widgetSelected( final SelectionEvent e ) { - removeApplicationComponentElasticityRequirement( getSelectedObject() ); - } - - @Override - public void widgetDefaultSelected( final SelectionEvent e ) { - // TODO Auto-generated method stub - } - } ); - // Add section components to the toolkit - toolkit.adapt( this.table, true, true ); - toolkit.adapt( this.addButton, true, true ); - toolkit.adapt( this.removeButton, true, true ); - this.section.setClient( client ); - // Application Component Elasticity Actions Section - this.sectionRA = toolkit.createSection( parent, Section.TITLE_BAR ); - this.sectionRA.setText( "Elasticity Strategies" ); //$NON-NLS-1$ - Composite clientRA = toolkit.createComposite( this.sectionRA, SWT.WRAP ); - Composite clientRA1 = toolkit.createComposite( clientRA, SWT.WRAP ); - Composite clientRA2 = toolkit.createComposite( clientRA, SWT.WRAP ); - GridLayout layoutRA; - layoutRA = new GridLayout(); - layoutRA.numColumns = 2; - layoutRA.marginTop = 15; - layoutRA.verticalSpacing = 15; - layoutRA.marginWidth = 2; - layoutRA.marginHeight = 2; - clientRA.setLayout( layoutRA ); - layoutRA = new GridLayout(); - layoutRA.numColumns = 1; - clientRA1.setLayout( layoutRA ); - layoutRA = new GridLayout(); - layoutRA.numColumns = 1; - clientRA2.setLayout( layoutRA ); - this.tableResizingActions = new Table( clientRA1, SWT.BORDER - | SWT.VIRTUAL - | SWT.MULTI - | SWT.FULL_SELECTION ); - this.tableResizingActions.setHeaderVisible( true ); - this.tableResizingActions.setLinesVisible( false ); - this.tableResizingActions.getHorizontalBar().setEnabled( false ); - GridData gdRA; - gdRA = new GridData( 300, this.tableResizingActions.getItemHeight() * 4 ); - gdRA.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - gdRA.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; - this.tableResizingActions.setLayoutData( gdRA ); - TableLayout tableLayoutRA = new TableLayout(); - this.tableResizingActions.setLayout( tableLayoutRA ); - TableColumn nameColumnRA = new TableColumn( this.tableResizingActions, - SWT.CENTER ); - nameColumnRA.setText( "Strategy" ); //$NON-NLS-1$ - nameColumnRA.setWidth( 100 ); - ColumnWeightData dataRA = new ColumnWeightData( 100 ); - tableLayoutRA.addColumnData( dataRA ); - // Set the Elasticity Actions table viewer - ResizingActionsProvider RAProvider = new ResizingActionsProvider(); - this.tableResizingActionsViewer = new TableViewer( this.tableResizingActions ); - IStructuredContentProvider contentProviderRA = RAProvider.RAContentProvider; - this.tableResizingActionsViewer.setContentProvider( contentProviderRA ); - this.tableResizingActionsViewer.setLabelProvider( RAProvider.RAContentLabelProvider ); - this.tableResizingActionsViewer.setInput( this.appComponentResizingActions ); - // Add Elasticity Strategy button - this.addButtonRA = new Button( clientRA2, SWT.PUSH ); - this.addButtonRA.setText( "Add" ); //$NON-NLS-1$ - // Listener for Adding Elasticity Strategy button - this.addButtonRA.addSelectionListener( new SelectionListener() { - - @Override - public void widgetSelected( final SelectionEvent e ) { - editDataStagingEntryRA( getSelectedObject() ); - } - - @Override - public void widgetDefaultSelected( final SelectionEvent e ) { - // TODO Auto-generated method stub - } - } ); - gdRA = new GridData(); - gdRA.widthHint = 60; - gdRA.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - this.addButtonRA.setLayoutData( gdRA ); - this.removeButtonRA = new Button( clientRA2, SWT.PUSH ); - this.removeButtonRA.setText( "Remove" ); //$NON-NLS-1$ - // Listener for Remove Elasticity Strategy button - this.removeButtonRA.addSelectionListener( new SelectionListener() { - - @Override - public void widgetSelected( final SelectionEvent e ) { - removeApplicationComponentResizingAction( getSelectedElasticityStrategy() ); - } - - @Override - public void widgetDefaultSelected( final SelectionEvent e ) { - // TODO Auto-generated method stub - } - } ); - gdRA = new GridData(); - gdRA.widthHint = 60; - gdRA.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - this.removeButtonRA.setLayoutData( gdRA ); - this.conditionButtonRA = new Button( clientRA2, SWT.PUSH ); - this.conditionButtonRA.setText( "Condition" ); //$NON-NLS-1$ - // Listener for Remove Elasticity Strategy button - this.conditionButtonRA.addSelectionListener( new SelectionListener() { - - @Override - public void widgetSelected( final SelectionEvent e ) { - addStrategyCondition( getSelectedElasticityStrategy() ); - } - - @Override - public void widgetDefaultSelected( final SelectionEvent e ) { - // TODO Auto-generated method stub - } - } ); - gdRA = new GridData(); - gdRA.widthHint = 60; - gdRA.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - this.conditionButtonRA.setLayoutData( gdRA ); - // Add section components to the toolkit - toolkit.adapt( this.tableResizingActions, true, true ); - toolkit.adapt( this.removeButtonRA, true, true ); - toolkit.adapt( this.addButtonRA, true, true ); - // toolkit.adapt( this.uploadButtonRA, true, true ); - toolkit.adapt( this.conditionButtonRA, true, true ); - this.sectionRA.setClient( clientRA ); - } - - // Add Application Component Elasticity Requirement - void editDataStagingEntry( final TPolicy selectedObject ) { - ElasticityConstraintDialog dialog; - if( selectedObject == null ) { - // Add button is pressed - dialog = new ElasticityConstraintDialog( this.section.getShell(), - "Application" ); //$NON-NLS-1$ - if( dialog.open() == Window.OK ) { - String newElasticityConstraint = dialog.getElasticityConstraint(); - - if (newElasticityConstraint.contains( "<" )){ - String[] cond = newElasticityConstraint.split( "<" ); - newElasticityConstraint = cond[0] + "<" + cond[1]; - } - else if (newElasticityConstraint.contains( ">" )){ - String[] cond = newElasticityConstraint.split( ">" ); - newElasticityConstraint = cond[0] + ">" + cond[1]; - } - - - SyblElasticityRequirementsDescription newSYBLConstraint = dialog.getSYBLConstraint(); - if( newElasticityConstraint != null ) { - // Add Application Component Elasticity Requirement to TOSCA - PictogramElement pe = getSelectedPictogramElement(); - Object bo = null; - if( pe != null ) { - bo = Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( pe ); - } - final TBoundaryDefinitionsExtension boundaryDef = ( TBoundaryDefinitionsExtension )( ( ( TServiceTemplate )bo ).getBoundaryDefinitions() ); - - - if ( boundaryDef.getPolicies() == null ){ - - final PoliciesType1 boundaryPolicies = ToscaFactory.eINSTANCE.createPoliciesType1(); - - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { - - @Override - protected void doExecute() { - boundaryDef.setPolicies( boundaryPolicies ); - } - } ); - - - } - - PoliciesType1 nodePolicyList = boundaryDef.getPolicies(); - - final EList<TPolicy> policy = nodePolicyList.getPolicy(); - final TPolicy newPolicy = createNewPolicy( "Constraint", - newElasticityConstraint, newSYBLConstraint ); - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { - - @Override - protected void doExecute() { - policy.add( newPolicy ); - } - } ); - // Add Application Component Elasticity Requirement to temp list - this.appComponentElasticityRequirements.add( newPolicy ); - this.tableViewer.refresh(); - } else { - } - } + @Override + public void widgetSelected( SelectionEvent e ) { + editDataStagingEntry( null ); } - } - void editDataStagingEntryRA( final TPolicy selectedObject ) { - ElasticityStrategyDialog dialog; - if( selectedObject == null ) { - // Add button is pressed - dialog = new ElasticityStrategyDialog( this.section.getShell(), + @Override + public void widgetDefaultSelected( final SelectionEvent e ) { + // TODO Auto-generated method stub + } + } ); + this.removeButton = new Button( client2, SWT.PUSH ); + this.removeButton.setText( "Remove" ); //$NON-NLS-1$ + gd = new GridData(); + gd.widthHint = 60; + gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + this.removeButton.setLayoutData( gd ); + // Listener for Remove button + this.removeButton.addSelectionListener( new SelectionListener() { + + @Override + public void widgetSelected( final SelectionEvent e ) { + removeApplicationComponentElasticityRequirement( getSelectedObject() ); + } + + @Override + public void widgetDefaultSelected( final SelectionEvent e ) { + // TODO Auto-generated method stub + } + } ); + // Add section components to the toolkit + toolkit.adapt( this.table, true, true ); + toolkit.adapt( this.addButton, true, true ); + toolkit.adapt( this.removeButton, true, true ); + this.section.setClient( client ); + // Application Component Elasticity Actions Section + this.sectionRA = toolkit.createSection( parent, Section.TITLE_BAR ); + this.sectionRA.setText( "Elasticity Strategies" ); //$NON-NLS-1$ + Composite clientRA = toolkit.createComposite( this.sectionRA, SWT.WRAP ); + Composite clientRA1 = toolkit.createComposite( clientRA, SWT.WRAP ); + Composite clientRA2 = toolkit.createComposite( clientRA, SWT.WRAP ); + GridLayout layoutRA; + layoutRA = new GridLayout(); + layoutRA.numColumns = 2; + layoutRA.marginTop = 15; + layoutRA.verticalSpacing = 15; + layoutRA.marginWidth = 2; + layoutRA.marginHeight = 2; + clientRA.setLayout( layoutRA ); + layoutRA = new GridLayout(); + layoutRA.numColumns = 1; + clientRA1.setLayout( layoutRA ); + layoutRA = new GridLayout(); + layoutRA.numColumns = 1; + clientRA2.setLayout( layoutRA ); + this.tableResizingActions = new Table( clientRA1, SWT.BORDER + | SWT.VIRTUAL + | SWT.MULTI + | SWT.FULL_SELECTION ); + this.tableResizingActions.setHeaderVisible( true ); + this.tableResizingActions.setLinesVisible( false ); + this.tableResizingActions.getHorizontalBar().setEnabled( false ); + GridData gdRA; + gdRA = new GridData( 300, this.tableResizingActions.getItemHeight() * 4 ); + gdRA.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + gdRA.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; + this.tableResizingActions.setLayoutData( gdRA ); + TableLayout tableLayoutRA = new TableLayout(); + this.tableResizingActions.setLayout( tableLayoutRA ); + TableColumn nameColumnRA = new TableColumn( this.tableResizingActions, + SWT.CENTER ); + nameColumnRA.setText( "Strategy" ); //$NON-NLS-1$ + nameColumnRA.setWidth( 100 ); + ColumnWeightData dataRA = new ColumnWeightData( 100 ); + tableLayoutRA.addColumnData( dataRA ); + // Set the Elasticity Actions table viewer + ResizingActionsProvider RAProvider = new ResizingActionsProvider(); + this.tableResizingActionsViewer = new TableViewer( this.tableResizingActions ); + IStructuredContentProvider contentProviderRA = RAProvider.RAContentProvider; + this.tableResizingActionsViewer.setContentProvider( contentProviderRA ); + this.tableResizingActionsViewer.setLabelProvider( RAProvider.RAContentLabelProvider ); + this.tableResizingActionsViewer.setInput( this.appComponentResizingActions ); + // Add Elasticity Strategy button + this.addButtonRA = new Button( clientRA2, SWT.PUSH ); + this.addButtonRA.setText( "Add" ); //$NON-NLS-1$ + // Listener for Adding Elasticity Strategy button + this.addButtonRA.addSelectionListener( new SelectionListener() { + + @Override + public void widgetSelected( final SelectionEvent e ) { + editDataStagingEntryRA( getSelectedObject() ); + } + + @Override + public void widgetDefaultSelected( final SelectionEvent e ) { + // TODO Auto-generated method stub + } + } ); + gdRA = new GridData(); + gdRA.widthHint = 60; + gdRA.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + this.addButtonRA.setLayoutData( gdRA ); + this.removeButtonRA = new Button( clientRA2, SWT.PUSH ); + this.removeButtonRA.setText( "Remove" ); //$NON-NLS-1$ + // Listener for Remove Elasticity Strategy button + this.removeButtonRA.addSelectionListener( new SelectionListener() { + + @Override + public void widgetSelected( final SelectionEvent e ) { + removeApplicationComponentResizingAction( getSelectedElasticityStrategy() ); + } + + @Override + public void widgetDefaultSelected( final SelectionEvent e ) { + // TODO Auto-generated method stub + } + } ); + gdRA = new GridData(); + gdRA.widthHint = 60; + gdRA.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + this.removeButtonRA.setLayoutData( gdRA ); + this.conditionButtonRA = new Button( clientRA2, SWT.PUSH ); + this.conditionButtonRA.setText( "Condition" ); //$NON-NLS-1$ + // Listener for Remove Elasticity Strategy button + this.conditionButtonRA.addSelectionListener( new SelectionListener() { + + @Override + public void widgetSelected( final SelectionEvent e ) { + addStrategyCondition( getSelectedElasticityStrategy() ); + } + + @Override + public void widgetDefaultSelected( final SelectionEvent e ) { + // TODO Auto-generated method stub + } + } ); + gdRA = new GridData(); + gdRA.widthHint = 60; + gdRA.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + this.conditionButtonRA.setLayoutData( gdRA ); + // Add section components to the toolkit + toolkit.adapt( this.tableResizingActions, true, true ); + toolkit.adapt( this.removeButtonRA, true, true ); + toolkit.adapt( this.addButtonRA, true, true ); + // toolkit.adapt( this.uploadButtonRA, true, true ); + toolkit.adapt( this.conditionButtonRA, true, true ); + this.sectionRA.setClient( clientRA ); +} + +// Add Application Component Elasticity Requirement +void editDataStagingEntry( final TPolicy selectedObject ) { + ElasticityConstraintDialog dialog; + if( selectedObject == null ) { + // Add button is pressed + dialog = new ElasticityConstraintDialog( this.section.getShell(), "Application" ); //$NON-NLS-1$ - if( dialog.open() == Window.OK ) { - String newElasticityStrategy = dialog.getElasticityStrategy(); - SyblElasticityRequirementsDescription newSYBLStrategy = dialog.getSYBLStrategy(); - if( newElasticityStrategy != null ) { - // Add Application Component Elasticity Strategy to TOSCA - PictogramElement pe = getSelectedPictogramElement(); - Object bo = null; - if( pe != null ) { - bo = Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( pe ); - } - final TBoundaryDefinitionsExtension boundaryDef = ( TBoundaryDefinitionsExtension )( ( ( TServiceTemplate )bo ).getBoundaryDefinitions() ); - - if ( boundaryDef.getPolicies() == null ){ - - final PoliciesType1 boundaryPolicies = ToscaFactory.eINSTANCE.createPoliciesType1(); - - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { - - @Override - protected void doExecute() { - boundaryDef.setPolicies( boundaryPolicies ); - } - } ); - } - - PoliciesType1 nodePolicyList = boundaryDef.getPolicies(); - final EList<TPolicy> policy = nodePolicyList.getPolicy(); - final TPolicy newPolicy = createNewPolicy( "Strategy", - newElasticityStrategy, newSYBLStrategy ); + if( dialog.open() == Window.OK ) { + String newElasticityConstraint = dialog.getElasticityConstraint(); + + if( newElasticityConstraint != null ) { + + if( newElasticityConstraint.contains( "<" ) ) { + String[] cond = newElasticityConstraint.split( "<" ); + newElasticityConstraint = cond[ 0 ] + "<" + cond[ 1 ]; + } else if( newElasticityConstraint.contains( ">" ) ) { + String[] cond = newElasticityConstraint.split( ">" ); + newElasticityConstraint = cond[ 0 ] + ">" + cond[ 1 ]; + } + + // Add Application Component Elasticity Requirement to TOSCA + PictogramElement pe = getSelectedPictogramElement(); + Object bo = null; + if( pe != null ) { + bo = Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( pe ); + } + final TBoundaryDefinitionsExtension boundaryDef = ( TBoundaryDefinitionsExtension )( ( ( TServiceTemplate )bo ).getBoundaryDefinitions() ); + if( boundaryDef.getPolicies() == null ) { + final PoliciesType1 boundaryPolicies = ToscaFactory.eINSTANCE.createPoliciesType1(); TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); editingDomain.getCommandStack() .execute( new RecordingCommand( editingDomain ) { @Override protected void doExecute() { - policy.add( newPolicy ); + boundaryDef.setPolicies( boundaryPolicies ); } } ); - this.appComponentResizingActions.add( newPolicy ); - this.tableResizingActionsViewer.refresh(); - } else { - // Edit } + PoliciesType1 nodePolicyList = boundaryDef.getPolicies(); + final EList<TPolicy> policy = nodePolicyList.getPolicy(); + final TPolicy newPolicy = ToscaFactory.eINSTANCE.createTPolicy(); + String type = "Constraint"; + QName policyTypeName = new QName( "http://www.example.org/SYBL", + type, + null ); + newPolicy.setPolicyType( policyTypeName ); + newPolicy.setName( type.toUpperCase() + " " + newElasticityConstraint ); + + String id = "A" + ( ( Integer )boundaryDef.hashCode() ).toString() + nodePolicyList.getPolicy().size(); + QName qnamePolicyTemplate = new QName( id ); + newPolicy.setPolicyRef( qnamePolicyTemplate ); + + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { + + @Override + protected void doExecute() { + policy.add( newPolicy ); + } + } ); + // Add Application Component Elasticity Requirement to temp list + this.appComponentElasticityRequirements.add( newPolicy ); + this.tableViewer.refresh(); } } } +} - - // type is either "Constraint" or "Strategy" - TPolicy createNewPolicy(String type, String policyName, SyblElasticityRequirementsDescription syblPolicy){ - - // Create Policy Template +void editDataStagingEntryRA( final TPolicy selectedObject ) { + ElasticityStrategyDialog dialog; + if( selectedObject == null ) { + // Add button is pressed + PictogramElement pe = getSelectedPictogramElement(); + Object bo = null; + if( pe != null ) { + bo = Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( pe ); + } + TServiceTemplate application = (TServiceTemplate) bo; - final TPolicyTemplate newPolicyTemplate = ToscaFactory.eINSTANCE.createTPolicyTemplate(); - - QName policyTypeName = new QName( "http://www.example.org/SYBL", type, null ); - - newPolicyTemplate.setType( policyTypeName ); - - String id = "A" + ( ( Integer )newPolicyTemplate.hashCode() ).toString(); - - newPolicyTemplate.setId( id ); - - - // Set the Properties of the Policy Template - - PropertiesType properties = ToscaFactory.eINSTANCE.createPropertiesType(); - - // Add the SYBL Policy to the FeatureMap of the Policy's Properties element - Entry e = FeatureMapUtil.createEntry( SyblPackage.eINSTANCE.getDocumentRoot_SYBLElasticityRequirementsDescription(), syblPolicy ); - properties.getAny().add( e ); - - newPolicyTemplate.setProperties( properties ); - - // Add the new Policy Template to the TOSCA Definitions element - - final ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - - DefinitionsType definitions = model.getDocumentRoot().getDefinitions(); - - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( definitions ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { - - @Override - protected void doExecute() { - model.getDocumentRoot().getDefinitions().getPolicyTemplate().add( newPolicyTemplate ); - - } - } ); - - // Assign the created Policy Template to the new Policy - - TPolicy newPolicy = ToscaFactory.eINSTANCE.createTPolicy(); - - QName qnamePolicyTemplate = new QName( newPolicyTemplate.getId() ); - - newPolicy.setPolicyType( policyTypeName ); - - newPolicy.setPolicyRef( qnamePolicyTemplate ); - - newPolicy.setName( type.toUpperCase() + " " + policyName ); - - return newPolicy; - } - - void addStrategyCondition( final TPolicy selectedObject ) { - if( selectedObject == null ) - return; - - TServiceTemplate serviceTemplate = null; - - if (getSelectedPictogramElement() != null) - serviceTemplate = (TServiceTemplate) Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(getSelectedPictogramElement()); - - ElasticityConditionDialog dialog; - ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - dialog = new ElasticityConditionDialog( this.section.getShell(), - "Application Component", - model, - selectedObject.getName() ); //$NON-NLS-1$ - String newElasticityCondition = null; - ConditionType policyCondition = null; + dialog = new ElasticityStrategyDialog( this.section.getShell(), + "Application", application.getName() ); //$NON-NLS-1$ if( dialog.open() == Window.OK ) { - newElasticityCondition = dialog.getSelectedCondition(); - policyCondition = dialog.getSYBLCondition(); - } - if( newElasticityCondition == null ) - return; + String newElasticityStrategy = dialog.getElasticityStrategy(); + if( newElasticityStrategy != null ) { + // Add Application Component Elasticity Strategy to TOSCA - String newCond = newElasticityCondition; - - if (newCond.contains( "<" )){ - String[] cond = newCond.split( "<" ); - newCond = cond[0] + "<" + cond[1]; - } - else if (newCond.contains( ">" )){ - String[] cond = newCond.split( ">" ); - newCond = cond[0] + ">" + cond[1]; - } - - final String condition = newCond; - - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( serviceTemplate ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { + final TBoundaryDefinitionsExtension boundaryDef = ( TBoundaryDefinitionsExtension )( application.getBoundaryDefinitions() ); + if( boundaryDef.getPolicies() == null ) { + final PoliciesType1 boundaryPolicies = ToscaFactory.eINSTANCE.createPoliciesType1(); + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { - @Override - protected void doExecute() { - String[] strategy = selectedObject.getName().split( "STRATEGY" ); - selectedObject.setName( strategy[ 0 ] - + "STRATEGY " - + condition + " :" - + strategy[ 1 ] ); - } - } ); - this.tableResizingActionsViewer.refresh(); - - //addPolicyCondition( selectedObject, policyCondition); - } - -// void addPolicyCondition(final TPolicy selectedPolicy, final ConditionType policyCondition){ -// -// ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); -// EList<TPolicyTemplate> policyTemplates = model.getDocumentRoot().getDefinitions().getPolicyTemplate(); -// TPolicyTemplate policyTemplate = null; -// for ( TPolicyTemplate tempPolicyTemplate : policyTemplates ){ -// if (tempPolicyTemplate.getId().toString().equals(selectedPolicy.getPolicyRef().toString())){ -// policyTemplate = tempPolicyTemplate; -// break; -// } -// } -// -// final SyblElasticityRequirementsDescription syblPolicy = (SyblElasticityRequirementsDescription) policyTemplate.getProperties().getAny().get(0).getValue(); -// TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( policyTemplate ); -// editingDomain.getCommandStack() -// .execute( new RecordingCommand( editingDomain ) { -// -// @Override -// protected void doExecute() { -// syblPolicy.getSYBLSpecification().get( 0 ).getStrategy().get( 0 ).setCondition( policyCondition ); -// } -// } ); -// } - - // Remove the selected Application Component Elasticity Requirement from TOSCA - void removeApplicationComponentElasticityRequirement( final TPolicy selectedObject ) - { - PictogramElement pe = getSelectedPictogramElement(); - Object bo = null; - if( pe != null ) { - bo = Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( pe ); - } - - final TBoundaryDefinitionsExtension boundaryDef = ( TBoundaryDefinitionsExtension )( ( ( TServiceTemplate )bo ).getBoundaryDefinitions() ); - - PoliciesType1 nodePolicyList = boundaryDef.getPolicies(); - - final EList<TPolicy> policy = nodePolicyList.getPolicy(); - - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { - - @Override - protected void doExecute() { - for( TPolicy tempPolicy : policy ) { - if( tempPolicy.getPolicyType().toString().contains( "Constraint" ) ) //$NON-NLS-1$ - if( tempPolicy.getName().compareTo( selectedObject.getName() ) == 0 ) - { - policy.remove( tempPolicy ); - if( policy.size() == 0 ) - boundaryDef.setPolicies( null ); - // remove corresponding Policy Template - String removedPolicyId = tempPolicy.getPolicyRef().toString(); - ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - DefinitionsType toscaDefinitions = model.getDocumentRoot() - .getDefinitions(); - final EList<TPolicyTemplate> policyTemplate = toscaDefinitions.getPolicyTemplate(); - for( TPolicyTemplate tempPolicyTemplate : policyTemplate ) { - if( tempPolicyTemplate.getId().equals( removedPolicyId ) ) { - policyTemplate.remove( tempPolicyTemplate ); - } - } - break; + @Override + protected void doExecute() { + boundaryDef.setPolicies( boundaryPolicies ); } - } + } ); } - } ); - this.appComponentElasticityRequirements.remove( selectedObject ); - this.tableViewer.refresh(); - } + PoliciesType1 nodePolicyList = boundaryDef.getPolicies(); + final EList<TPolicy> policy = nodePolicyList.getPolicy(); + final TPolicy newPolicy = ToscaFactory.eINSTANCE.createTPolicy(); + String type = "Strategy"; + QName policyTypeName = new QName( "http://www.example.org/SYBL", + type, + null ); + newPolicy.setPolicyType( policyTypeName ); + newPolicy.setName( type.toUpperCase() + " " + newElasticityStrategy ); + + String id = "A" + ( ( Integer )boundaryDef.hashCode() ).toString() + nodePolicyList.getPolicy().size(); + QName qnamePolicyTemplate = new QName( id ); + newPolicy.setPolicyRef( qnamePolicyTemplate ); + + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { - // Return the selected Elasticity Requirement - TPolicy getSelectedObject() { - TPolicy result = null; - IStructuredSelection selection = ( IStructuredSelection )this.tableViewer.getSelection(); - Object obj = selection.getFirstElement(); - result = ( TPolicy )obj; - return result; - } - - // Return the selected Elasticity Action - TPolicy getSelectedElasticityStrategy() { - TPolicy result = null; - IStructuredSelection selection = ( IStructuredSelection )this.tableResizingActionsViewer.getSelection(); - Object obj = selection.getFirstElement(); - result = ( TPolicy )obj; - return result; - } - - /** - * Get Application Elasticity Actions - */ - public void getResizingActions() { - // initiate global elasticity requirement list with requirements from - // description wizard - PictogramElement pe = getSelectedPictogramElement(); - Object bo = null; - if( pe != null ) { - bo = Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( pe ); + @Override + protected void doExecute() { + policy.add( newPolicy ); + } + } ); + this.appComponentResizingActions.add( newPolicy ); + this.tableResizingActionsViewer.refresh(); + } } - TBoundaryDefinitionsExtension boundaryDef = ( TBoundaryDefinitionsExtension )( ( ( TServiceTemplate )bo ).getBoundaryDefinitions() ); - - PoliciesType1 nodePolicyList = boundaryDef.getPolicies(); - - if( nodePolicyList == null ) - return; - - for( TPolicy tempPolicy : nodePolicyList.getPolicy() ) - { - if( tempPolicy.getPolicyType().toString().contains( "Strategy" ) ) //$NON-NLS-1$ - this.appComponentResizingActions.add( tempPolicy ); - } - } +} +void addStrategyCondition( final TPolicy selectedObject ) { + if( selectedObject == null ) + return; + TServiceTemplate serviceTemplate = null; + if( getSelectedPictogramElement() != null ) + serviceTemplate = ( TServiceTemplate )Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( getSelectedPictogramElement() ); + ElasticityConditionDialog dialog; + ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); + dialog = new ElasticityConditionDialog( this.section.getShell(), + "Application Component", + model, + selectedObject.getName() ); //$NON-NLS-1$ + String newElasticityCondition = null; + if( dialog.open() == Window.OK ) { + newElasticityCondition = dialog.getSelectedCondition(); + } + if( newElasticityCondition == null ) + return; + String newCond = newElasticityCondition; + if( newCond.contains( "<" ) ) { + String[] cond = newCond.split( "<" ); + newCond = cond[ 0 ] + "<" + cond[ 1 ]; + } else if( newCond.contains( ">" ) ) { + String[] cond = newCond.split( ">" ); + newCond = cond[ 0 ] + ">" + cond[ 1 ]; + } + final String condition = newCond; + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( serviceTemplate ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { + + @Override + protected void doExecute() { + String[] strategy = selectedObject.getName().split( "STRATEGY" ); + selectedObject.setName( strategy[ 0 ] + + "STRATEGY " + + condition + + " :" + + strategy[ 1 ] ); + } + } ); + this.tableResizingActionsViewer.refresh(); +} + +// Remove the selected Application Component Elasticity Requirement from TOSCA +void removeApplicationComponentElasticityRequirement( final TPolicy selectedObject ) +{ + PictogramElement pe = getSelectedPictogramElement(); + Object bo = null; + if( pe != null ) { + bo = Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( pe ); + } + final TBoundaryDefinitionsExtension boundaryDef = ( TBoundaryDefinitionsExtension )( ( ( TServiceTemplate )bo ).getBoundaryDefinitions() ); + PoliciesType1 nodePolicyList = boundaryDef.getPolicies(); + final EList<TPolicy> policy = nodePolicyList.getPolicy(); + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { + + @Override + protected void doExecute() { + for( TPolicy tempPolicy : policy ) { + if( tempPolicy.getPolicyType().toString().contains( "Constraint" ) ) //$NON-NLS-1$ + if( tempPolicy.getName().compareTo( selectedObject.getName() ) == 0 ) + { + policy.remove( tempPolicy ); + if( policy.size() == 0 ) + boundaryDef.setPolicies( null ); + break; + } + } + } + } ); + this.appComponentElasticityRequirements.remove( selectedObject ); + this.tableViewer.refresh(); +} + +// Return the selected Elasticity Requirement +TPolicy getSelectedObject() { + TPolicy result = null; + IStructuredSelection selection = ( IStructuredSelection )this.tableViewer.getSelection(); + Object obj = selection.getFirstElement(); + result = ( TPolicy )obj; + return result; +} + +// Return the selected Elasticity Action +TPolicy getSelectedElasticityStrategy() { + TPolicy result = null; + IStructuredSelection selection = ( IStructuredSelection )this.tableResizingActionsViewer.getSelection(); + Object obj = selection.getFirstElement(); + result = ( TPolicy )obj; + return result; +} + +/** + * Get Application Elasticity Actions + */ +public void getResizingActions() { + // initiate global elasticity requirement list with requirements from + // description wizard + PictogramElement pe = getSelectedPictogramElement(); + Object bo = null; + if( pe != null ) { + bo = Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( pe ); + } + if (bo == null) + return; - /** - * Get Application Elasticity Constraints - */ - public void getElasticityConstraints() { - // initiate global elasticity requirement list with requirements from - // description wizard - PictogramElement pe = getSelectedPictogramElement(); - Object bo = null; - if( pe != null ) { - bo = Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( pe ); - } - TBoundaryDefinitionsExtension boundaryDef = ( TBoundaryDefinitionsExtension )( ( ( TServiceTemplate )bo ).getBoundaryDefinitions() ); - - PoliciesType1 nodePolicyList = boundaryDef.getPolicies(); - - if( nodePolicyList == null ) - return; - - for( TPolicy tempPolicy : nodePolicyList.getPolicy() ) - { - if( tempPolicy.getPolicyType().toString().contains( "Constraint" ) ) //$NON-NLS-1$ - this.appComponentElasticityRequirements.add( tempPolicy ); - } - + TBoundaryDefinitionsExtension boundaryDef = ( TBoundaryDefinitionsExtension )( ( ( TServiceTemplate )bo ).getBoundaryDefinitions() ); + PoliciesType1 nodePolicyList = boundaryDef.getPolicies(); + if( nodePolicyList == null ) + return; + for( TPolicy tempPolicy : nodePolicyList.getPolicy() ) { + if( tempPolicy.getPolicyType().toString().contains( "Strategy" ) ) //$NON-NLS-1$ + this.appComponentResizingActions.add( tempPolicy ); } +} - // Remove Application Component Elasticity Action - void removeApplicationComponentResizingAction( final TPolicy selectedObject ) - { - PictogramElement pe = getSelectedPictogramElement(); - Object bo = null; - if( pe != null ) { - bo = Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( pe ); - } - final TBoundaryDefinitionsExtension boundaryDef = ( TBoundaryDefinitionsExtension )( ( ( TServiceTemplate )bo ).getBoundaryDefinitions() ); - - PoliciesType1 nodePolicyList = boundaryDef.getPolicies(); - - final EList<TPolicy> policy = nodePolicyList.getPolicy(); - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { +/** + * Get Application Elasticity Constraints + */ +public void getElasticityConstraints() { + // initiate global elasticity requirement list with requirements from + // description wizard + PictogramElement pe = getSelectedPictogramElement(); + Object bo = null; + if( pe != null ) { + bo = Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( pe ); + } + if (bo == null) + return; + + TBoundaryDefinitionsExtension boundaryDef = ( TBoundaryDefinitionsExtension )( ( ( TServiceTemplate )bo ).getBoundaryDefinitions() ); + PoliciesType1 nodePolicyList = boundaryDef.getPolicies(); + if( nodePolicyList == null ) + return; + for( TPolicy tempPolicy : nodePolicyList.getPolicy() ) { + if( tempPolicy.getPolicyType().toString().contains( "Constraint" ) ) //$NON-NLS-1$ + this.appComponentElasticityRequirements.add( tempPolicy ); + } +} - @Override - protected void doExecute() { - for( TPolicy tempPolicy : policy ) { - if( tempPolicy.getPolicyType().toString().contains( "Strategy" ) ) //$NON-NLS-1$ - if( tempPolicy.getName().compareTo( selectedObject.getName() ) == 0 ) - { - policy.remove( tempPolicy ); - if( policy.size() == 0 ) - boundaryDef.setPolicies( null ); - // remove corresponding Policy Template - String removedPolicyId = tempPolicy.getPolicyRef().toString(); - ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - DefinitionsType toscaDefinitions = model.getDocumentRoot() - .getDefinitions(); - final EList<TPolicyTemplate> policyTemplate = toscaDefinitions.getPolicyTemplate(); - for( TPolicyTemplate tempPolicyTemplate : policyTemplate ) { - if( tempPolicyTemplate.getId().equals( removedPolicyId ) ) { - policyTemplate.remove( tempPolicyTemplate ); - } - } - break; - } - } +// Remove Application Component Elasticity Action +void removeApplicationComponentResizingAction( final TPolicy selectedObject ) +{ + PictogramElement pe = getSelectedPictogramElement(); + Object bo = null; + if( pe != null ) { + bo = Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( pe ); + } + final TBoundaryDefinitionsExtension boundaryDef = ( TBoundaryDefinitionsExtension )( ( ( TServiceTemplate )bo ).getBoundaryDefinitions() ); + PoliciesType1 nodePolicyList = boundaryDef.getPolicies(); + final EList<TPolicy> policy = nodePolicyList.getPolicy(); + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { + + @Override + protected void doExecute() { + for( TPolicy tempPolicy : policy ) { + if( tempPolicy.getPolicyType().toString().contains( "Strategy" ) ) //$NON-NLS-1$ + if( tempPolicy.getName().compareTo( selectedObject.getName() ) == 0 ) + { + policy.remove( tempPolicy ); + if( policy.size() == 0 ) + boundaryDef.setPolicies( null ); + break; + } } - } ); - this.appComponentResizingActions.remove( selectedObject ); - this.tableResizingActionsViewer.refresh(); - } + } + } ); + this.appComponentResizingActions.remove( selectedObject ); + this.tableResizingActionsViewer.refresh(); +} - /* - * Refresh Elasticity Tab(non-Javadoc) - * @see - * org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#refresh() - */ - @Override - public void refresh() { - // Refresh Elasticity Constraints - this.appComponentElasticityRequirements.clear(); - getElasticityConstraints(); - this.tableViewer.refresh(); - // Refresh Elasticity Actions - this.appComponentResizingActions.clear(); - getResizingActions(); - this.tableResizingActionsViewer.refresh(); - } +/* + * Refresh Elasticity Tab(non-Javadoc) + * @see + * org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#refresh() + */ +@Override +public void refresh() { + // Refresh Elasticity Constraints + this.appComponentElasticityRequirements.clear(); + getElasticityConstraints(); + this.tableViewer.refresh(); + // Refresh Elasticity Actions + this.appComponentResizingActions.clear(); + getResizingActions(); + this.tableResizingActionsViewer.refresh(); +} }
diff --git a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/property/CompositeElasticity.java b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/property/CompositeElasticity.java index d90d5d4..1d6b7ce 100644 --- a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/property/CompositeElasticity.java +++ b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/editor/property/CompositeElasticity.java
@@ -74,796 +74,691 @@ /** * Composite Component Properties - Elasticity Tab */ -public class CompositeElasticity - extends GFPropertySection implements ITabbedPropertyConstants +public class CompositeElasticity extends GFPropertySection +implements ITabbedPropertyConstants { - Composite client; - Section section; - private Table table; - private Button addButton; - private Button removeButton; - TableViewer tableViewer; - List<TPolicy> appComponentElasticityRequirements = new ArrayList<TPolicy>(); - Section sectionRA; - private Table tableResizingActions; - private Button removeButtonRA; - private Button addButtonRA; - private Button conditionButtonRA; - TableViewer tableResizingActionsViewer; - List<TPolicy> appComponentResizingActions = new ArrayList<TPolicy>(); - protected Tosca_Elasticity_ExtensionsFactory elasticityFactory = Tosca_Elasticity_ExtensionsFactory.eINSTANCE; +Composite client; +Section section; +private Table table; +private Button addButton; +private Button removeButton; +TableViewer tableViewer; +List<TPolicy> appComponentElasticityRequirements = new ArrayList<TPolicy>(); +Section sectionRA; +private Table tableResizingActions; +private Button removeButtonRA; +private Button addButtonRA; +private Button conditionButtonRA; +TableViewer tableResizingActionsViewer; +List<TPolicy> appComponentResizingActions = new ArrayList<TPolicy>(); +protected Tosca_Elasticity_ExtensionsFactory elasticityFactory = Tosca_Elasticity_ExtensionsFactory.eINSTANCE; - @Override - public void createControls( final Composite parent, - TabbedPropertySheetPage tabbedPropertySheetPage ) - { - super.createControls( parent, tabbedPropertySheetPage ); - FormToolkit toolkit = new FormToolkit( parent.getDisplay() ); - // Application Component Elasticity Requirements Section - this.section = toolkit.createSection( parent, Section.TITLE_BAR ); - this.section.setText( "Application Component Elasticity Constraints" ); //$NON-NLS-1$ - Composite client = toolkit.createComposite( this.section, SWT.WRAP ); - Composite client1 = toolkit.createComposite( client, SWT.WRAP ); - Composite client2 = toolkit.createComposite( client, SWT.WRAP ); - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - layout.marginTop = 15; - layout.verticalSpacing = 15; - layout.marginWidth = 2; - layout.marginHeight = 2; - client.setLayout( layout ); - layout = new GridLayout(); - layout.numColumns = 1; - client1.setLayout( layout ); - layout = new GridLayout(); - layout.numColumns = 1; - client2.setLayout( layout ); - GridData gd; - this.table = new Table( client1, SWT.BORDER - | SWT.VIRTUAL - | SWT.MULTI - | SWT.FULL_SELECTION ); - this.table.setHeaderVisible( true ); - this.table.setLinesVisible( false ); - this.table.getHorizontalBar().setEnabled( false ); - gd = new GridData( 300, this.table.getItemHeight() * 4 ); - gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; - this.table.setLayoutData( gd ); - TableLayout tableLayout = new TableLayout(); - this.table.setLayout( tableLayout ); - TableColumn nameColumn = new TableColumn( this.table, SWT.CENTER ); - ColumnLayoutData data = new ColumnWeightData( 100 ); - tableLayout.addColumnData( data ); - data = new ColumnWeightData( 100 ); - tableLayout.addColumnData( data ); - data = new ColumnWeightData( 150 ); - tableLayout.addColumnData( data ); - nameColumn.setText( "Constraint" ); //$NON-NLS-1$ - this.tableViewer = new TableViewer( this.table ); - ElasticityConstraintsProvider ERProvider = new ElasticityConstraintsProvider(); - IStructuredContentProvider contentProvider = ERProvider.ERContentProvider; - this.tableViewer.setContentProvider( contentProvider ); - this.tableViewer.setLabelProvider( ERProvider.ERContentLabelProvider ); - this.tableViewer.setInput( this.appComponentElasticityRequirements ); - this.addButton = new Button( client2, SWT.PUSH ); - this.addButton.setText( "Add" ); //$NON-NLS-1$ - gd = new GridData(); - gd.widthHint = 60; - gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - this.addButton.setLayoutData( gd ); - // Listener for Add button - this.addButton.addSelectionListener( new SelectionListener() { +@Override +public void createControls( final Composite parent, + TabbedPropertySheetPage tabbedPropertySheetPage ) +{ + super.createControls( parent, tabbedPropertySheetPage ); + FormToolkit toolkit = new FormToolkit( parent.getDisplay() ); + // Application Component Elasticity Requirements Section + this.section = toolkit.createSection( parent, Section.TITLE_BAR ); + this.section.setText( "Application Component Elasticity Constraints" ); //$NON-NLS-1$ + Composite client = toolkit.createComposite( this.section, SWT.WRAP ); + Composite client1 = toolkit.createComposite( client, SWT.WRAP ); + Composite client2 = toolkit.createComposite( client, SWT.WRAP ); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + layout.marginTop = 15; + layout.verticalSpacing = 15; + layout.marginWidth = 2; + layout.marginHeight = 2; + client.setLayout( layout ); + layout = new GridLayout(); + layout.numColumns = 1; + client1.setLayout( layout ); + layout = new GridLayout(); + layout.numColumns = 1; + client2.setLayout( layout ); + GridData gd; + this.table = new Table( client1, SWT.BORDER + | SWT.VIRTUAL + | SWT.MULTI + | SWT.FULL_SELECTION ); + this.table.setHeaderVisible( true ); + this.table.setLinesVisible( false ); + this.table.getHorizontalBar().setEnabled( false ); + gd = new GridData( 300, this.table.getItemHeight() * 4 ); + gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; + this.table.setLayoutData( gd ); + TableLayout tableLayout = new TableLayout(); + this.table.setLayout( tableLayout ); + TableColumn nameColumn = new TableColumn( this.table, SWT.CENTER ); + ColumnLayoutData data = new ColumnWeightData( 100 ); + tableLayout.addColumnData( data ); + data = new ColumnWeightData( 100 ); + tableLayout.addColumnData( data ); + data = new ColumnWeightData( 150 ); + tableLayout.addColumnData( data ); + nameColumn.setText( "Constraint" ); //$NON-NLS-1$ + this.tableViewer = new TableViewer( this.table ); + ElasticityConstraintsProvider ERProvider = new ElasticityConstraintsProvider(); + IStructuredContentProvider contentProvider = ERProvider.ERContentProvider; + this.tableViewer.setContentProvider( contentProvider ); + this.tableViewer.setLabelProvider( ERProvider.ERContentLabelProvider ); + this.tableViewer.setInput( this.appComponentElasticityRequirements ); + this.addButton = new Button( client2, SWT.PUSH ); + this.addButton.setText( "Add" ); //$NON-NLS-1$ + gd = new GridData(); + gd.widthHint = 60; + gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + this.addButton.setLayoutData( gd ); + // Listener for Add button + this.addButton.addSelectionListener( new SelectionListener() { - @Override - public void widgetSelected( SelectionEvent e ) { - editDataStagingEntry( null ); - } + @Override + public void widgetSelected( SelectionEvent e ) { + editDataStagingEntry( null ); + } - @Override - public void widgetDefaultSelected( final SelectionEvent e ) { - // TODO Auto-generated method stub - } - } ); - this.removeButton = new Button( client2, SWT.PUSH ); - this.removeButton.setText( "Remove" ); //$NON-NLS-1$ - gd = new GridData(); - gd.widthHint = 60; - gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - this.removeButton.setLayoutData( gd ); - // Listener for Remove button - this.removeButton.addSelectionListener( new SelectionListener() { + @Override + public void widgetDefaultSelected( final SelectionEvent e ) { + // TODO Auto-generated method stub + } + } ); + this.removeButton = new Button( client2, SWT.PUSH ); + this.removeButton.setText( "Remove" ); //$NON-NLS-1$ + gd = new GridData(); + gd.widthHint = 60; + gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + this.removeButton.setLayoutData( gd ); + // Listener for Remove button + this.removeButton.addSelectionListener( new SelectionListener() { - @Override - public void widgetSelected( final SelectionEvent e ) { - removeApplicationComponentElasticityRequirement( getSelectedObject() ); - } + @Override + public void widgetSelected( final SelectionEvent e ) { + removeApplicationComponentElasticityRequirement( getSelectedObject() ); + } - @Override - public void widgetDefaultSelected( final SelectionEvent e ) { - // TODO Auto-generated method stub - } - } ); - // Add section components to the toolkit - toolkit.adapt( this.table, true, true ); - toolkit.adapt( this.addButton, true, true ); - toolkit.adapt( this.removeButton, true, true ); - this.section.setClient( client ); - // Application Component Elasticity Actions Section - this.sectionRA = toolkit.createSection( parent, Section.TITLE_BAR ); - this.sectionRA.setText( "Elasticity Strategies" ); //$NON-NLS-1$ - Composite clientRA = toolkit.createComposite( this.sectionRA, SWT.WRAP ); - Composite clientRA1 = toolkit.createComposite( clientRA, SWT.WRAP ); - Composite clientRA2 = toolkit.createComposite( clientRA, SWT.WRAP ); - GridLayout layoutRA; - layoutRA = new GridLayout(); - layoutRA.numColumns = 2; - layoutRA.marginTop = 15; - layoutRA.verticalSpacing = 15; - layoutRA.marginWidth = 2; - layoutRA.marginHeight = 2; - clientRA.setLayout( layoutRA ); - layoutRA = new GridLayout(); - layoutRA.numColumns = 1; - clientRA1.setLayout( layoutRA ); - layoutRA = new GridLayout(); - layoutRA.numColumns = 1; - clientRA2.setLayout( layoutRA ); - this.tableResizingActions = new Table( clientRA1, SWT.BORDER - | SWT.VIRTUAL - | SWT.MULTI - | SWT.FULL_SELECTION ); - this.tableResizingActions.setHeaderVisible( true ); - this.tableResizingActions.setLinesVisible( false ); - this.tableResizingActions.getHorizontalBar().setEnabled( false ); - GridData gdRA; - gdRA = new GridData( 300, this.tableResizingActions.getItemHeight() * 4 ); - gdRA.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - gdRA.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; - this.tableResizingActions.setLayoutData( gdRA ); - TableLayout tableLayoutRA = new TableLayout(); - this.tableResizingActions.setLayout( tableLayoutRA ); - TableColumn nameColumnRA = new TableColumn( this.tableResizingActions, - SWT.CENTER ); - nameColumnRA.setText( "Strategy" ); //$NON-NLS-1$ - nameColumnRA.setWidth( 100 ); - ColumnWeightData dataRA = new ColumnWeightData( 100 ); - tableLayoutRA.addColumnData( dataRA ); - // Set the Elasticity Actions table viewer - ResizingActionsProvider RAProvider = new ResizingActionsProvider(); - this.tableResizingActionsViewer = new TableViewer( this.tableResizingActions ); - IStructuredContentProvider contentProviderRA = RAProvider.RAContentProvider; - this.tableResizingActionsViewer.setContentProvider( contentProviderRA ); - this.tableResizingActionsViewer.setLabelProvider( RAProvider.RAContentLabelProvider ); - this.tableResizingActionsViewer.setInput( this.appComponentResizingActions ); - // Add Elasticity Strategy button - this.addButtonRA = new Button( clientRA2, SWT.PUSH ); - this.addButtonRA.setText( "Add" ); //$NON-NLS-1$ - // Listener for Adding Elasticity Strategy button - this.addButtonRA.addSelectionListener( new SelectionListener() { + @Override + public void widgetDefaultSelected( final SelectionEvent e ) { + // TODO Auto-generated method stub + } + } ); + // Add section components to the toolkit + toolkit.adapt( this.table, true, true ); + toolkit.adapt( this.addButton, true, true ); + toolkit.adapt( this.removeButton, true, true ); + this.section.setClient( client ); + // Application Component Elasticity Actions Section + this.sectionRA = toolkit.createSection( parent, Section.TITLE_BAR ); + this.sectionRA.setText( "Elasticity Strategies" ); //$NON-NLS-1$ + Composite clientRA = toolkit.createComposite( this.sectionRA, SWT.WRAP ); + Composite clientRA1 = toolkit.createComposite( clientRA, SWT.WRAP ); + Composite clientRA2 = toolkit.createComposite( clientRA, SWT.WRAP ); + GridLayout layoutRA; + layoutRA = new GridLayout(); + layoutRA.numColumns = 2; + layoutRA.marginTop = 15; + layoutRA.verticalSpacing = 15; + layoutRA.marginWidth = 2; + layoutRA.marginHeight = 2; + clientRA.setLayout( layoutRA ); + layoutRA = new GridLayout(); + layoutRA.numColumns = 1; + clientRA1.setLayout( layoutRA ); + layoutRA = new GridLayout(); + layoutRA.numColumns = 1; + clientRA2.setLayout( layoutRA ); + this.tableResizingActions = new Table( clientRA1, SWT.BORDER + | SWT.VIRTUAL + | SWT.MULTI + | SWT.FULL_SELECTION ); + this.tableResizingActions.setHeaderVisible( true ); + this.tableResizingActions.setLinesVisible( false ); + this.tableResizingActions.getHorizontalBar().setEnabled( false ); + GridData gdRA; + gdRA = new GridData( 300, this.tableResizingActions.getItemHeight() * 4 ); + gdRA.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + gdRA.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; + this.tableResizingActions.setLayoutData( gdRA ); + TableLayout tableLayoutRA = new TableLayout(); + this.tableResizingActions.setLayout( tableLayoutRA ); + TableColumn nameColumnRA = new TableColumn( this.tableResizingActions, + SWT.CENTER ); + nameColumnRA.setText( "Strategy" ); //$NON-NLS-1$ + nameColumnRA.setWidth( 100 ); + ColumnWeightData dataRA = new ColumnWeightData( 100 ); + tableLayoutRA.addColumnData( dataRA ); + // Set the Elasticity Actions table viewer + ResizingActionsProvider RAProvider = new ResizingActionsProvider(); + this.tableResizingActionsViewer = new TableViewer( this.tableResizingActions ); + IStructuredContentProvider contentProviderRA = RAProvider.RAContentProvider; + this.tableResizingActionsViewer.setContentProvider( contentProviderRA ); + this.tableResizingActionsViewer.setLabelProvider( RAProvider.RAContentLabelProvider ); + this.tableResizingActionsViewer.setInput( this.appComponentResizingActions ); + // Add Elasticity Strategy button + this.addButtonRA = new Button( clientRA2, SWT.PUSH ); + this.addButtonRA.setText( "Add" ); //$NON-NLS-1$ + // Listener for Adding Elasticity Strategy button + this.addButtonRA.addSelectionListener( new SelectionListener() { - @Override - public void widgetSelected( final SelectionEvent e ) { - editDataStagingEntryRA( getSelectedObject() ); - } + @Override + public void widgetSelected( final SelectionEvent e ) { + editDataStagingEntryRA( getSelectedObject() ); + } - @Override - public void widgetDefaultSelected( final SelectionEvent e ) { - // TODO Auto-generated method stub - } - } ); - gdRA = new GridData(); - gdRA.widthHint = 60; - gdRA.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - this.addButtonRA.setLayoutData( gdRA ); - this.removeButtonRA = new Button( clientRA2, SWT.PUSH ); - this.removeButtonRA.setText( "Remove" ); //$NON-NLS-1$ - // Listener for Remove Elasticity Strategy button - this.removeButtonRA.addSelectionListener( new SelectionListener() { + @Override + public void widgetDefaultSelected( final SelectionEvent e ) { + // TODO Auto-generated method stub + } + } ); + gdRA = new GridData(); + gdRA.widthHint = 60; + gdRA.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + this.addButtonRA.setLayoutData( gdRA ); + this.removeButtonRA = new Button( clientRA2, SWT.PUSH ); + this.removeButtonRA.setText( "Remove" ); //$NON-NLS-1$ + // Listener for Remove Elasticity Strategy button + this.removeButtonRA.addSelectionListener( new SelectionListener() { - @Override - public void widgetSelected( final SelectionEvent e ) { - removeApplicationComponentResizingAction( getSelectedElasticityStrategy() ); - } + @Override + public void widgetSelected( final SelectionEvent e ) { + removeApplicationComponentResizingAction( getSelectedElasticityStrategy() ); + } - @Override - public void widgetDefaultSelected( final SelectionEvent e ) { - // TODO Auto-generated method stub - } - } ); - gdRA = new GridData(); - gdRA.widthHint = 60; - gdRA.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - this.removeButtonRA.setLayoutData( gdRA ); - this.conditionButtonRA = new Button( clientRA2, SWT.PUSH ); - this.conditionButtonRA.setText( "Condition" ); //$NON-NLS-1$ - // Listener for Remove Elasticity Strategy button - this.conditionButtonRA.addSelectionListener( new SelectionListener() { + @Override + public void widgetDefaultSelected( final SelectionEvent e ) { + // TODO Auto-generated method stub + } + } ); + gdRA = new GridData(); + gdRA.widthHint = 60; + gdRA.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + this.removeButtonRA.setLayoutData( gdRA ); + this.conditionButtonRA = new Button( clientRA2, SWT.PUSH ); + this.conditionButtonRA.setText( "Condition" ); //$NON-NLS-1$ + // Listener for Remove Elasticity Strategy button + this.conditionButtonRA.addSelectionListener( new SelectionListener() { - @Override - public void widgetSelected( final SelectionEvent e ) { - addStrategyCondition( getSelectedElasticityStrategy() ); - } + @Override + public void widgetSelected( final SelectionEvent e ) { + addStrategyCondition( getSelectedElasticityStrategy() ); + } - @Override - public void widgetDefaultSelected( final SelectionEvent e ) { - // TODO Auto-generated method stub - } - } ); - gdRA = new GridData(); - gdRA.widthHint = 60; - gdRA.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - this.conditionButtonRA.setLayoutData( gdRA ); - // Add section components to the toolkit - toolkit.adapt( this.tableResizingActions, true, true ); - toolkit.adapt( this.removeButtonRA, true, true ); - toolkit.adapt( this.addButtonRA, true, true ); - // toolkit.adapt( this.uploadButtonRA, true, true ); - toolkit.adapt( this.conditionButtonRA, true, true ); - this.sectionRA.setClient( clientRA ); - } + @Override + public void widgetDefaultSelected( final SelectionEvent e ) { + // TODO Auto-generated method stub + } + } ); + gdRA = new GridData(); + gdRA.widthHint = 60; + gdRA.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; + this.conditionButtonRA.setLayoutData( gdRA ); + // Add section components to the toolkit + toolkit.adapt( this.tableResizingActions, true, true ); + toolkit.adapt( this.removeButtonRA, true, true ); + toolkit.adapt( this.addButtonRA, true, true ); + // toolkit.adapt( this.uploadButtonRA, true, true ); + toolkit.adapt( this.conditionButtonRA, true, true ); + this.sectionRA.setClient( clientRA ); +} - // Add Application Component Elasticity Requirement - void editDataStagingEntry( final TPolicy selectedObject ) { - ElasticityConstraintDialog dialog; - if( selectedObject == null ) { - // Add button is pressed - dialog = new ElasticityConstraintDialog( this.section.getShell(), - "Application Component" ); //$NON-NLS-1$ - if( dialog.open() == Window.OK ) { - String newElasticityConstraint = dialog.getElasticityConstraint(); +// Add Application Component Elasticity Requirement +void editDataStagingEntry( final TPolicy selectedObject ) { + ElasticityConstraintDialog dialog; + if( selectedObject == null ) { + // Add button is pressed + dialog = new ElasticityConstraintDialog( this.section.getShell(), + "Application Component" ); //$NON-NLS-1$ + if( dialog.open() == Window.OK ) { + String newElasticityConstraint = dialog.getElasticityConstraint(); + + if( newElasticityConstraint != null ) { - if (newElasticityConstraint.contains( "<" )){ + if( newElasticityConstraint.contains( "<" ) ) { String[] cond = newElasticityConstraint.split( "<" ); - newElasticityConstraint = cond[0] + "<" + cond[1]; - } - else if (newElasticityConstraint.contains( ">" )){ + newElasticityConstraint = cond[ 0 ] + "<" + cond[ 1 ]; + } else if( newElasticityConstraint.contains( ">" ) ) { String[] cond = newElasticityConstraint.split( ">" ); - newElasticityConstraint = cond[0] + ">" + cond[1]; - } + newElasticityConstraint = cond[ 0 ] + ">" + cond[ 1 ]; + } - - SyblElasticityRequirementsDescription newSYBLConstraint = dialog.getSYBLConstraint(); - if( newElasticityConstraint != null ) { - // Add Application Component Elasticity Requirement to TOSCA - PictogramElement pe = getSelectedPictogramElement(); - Object bo = null; - if( pe != null ) { - bo = Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( pe ); + // Add Application Component Elasticity Requirement to TOSCA + PictogramElement pe = getSelectedPictogramElement(); + Object bo = null; + if( pe != null ) { + bo = Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( pe ); + } + // Find the substitute TNodeTemplate + TServiceTemplate serviceTemplate = ( TServiceTemplate )bo; + TNodeTemplate substituteNode = null; + ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); + for( TNodeTemplate tempNodeTemplate : model.getDocumentRoot() + .getDefinitions() + .getServiceTemplate() + .get( 0 ) + .getTopologyTemplate() + .getNodeTemplate() ) + { + if( tempNodeTemplate.getId() + .toString() + .compareTo( serviceTemplate.getId().toString() ) == 0 ) + { + substituteNode = tempNodeTemplate; + break; } - - - // Find the substitute TNodeTemplate - TServiceTemplate serviceTemplate = (TServiceTemplate) bo; - TNodeTemplate substituteNode = null; - ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - for (TNodeTemplate tempNodeTemplate : model.getDocumentRoot() - .getDefinitions() - .getServiceTemplate() - .get( 0 ) - .getTopologyTemplate() - .getNodeTemplate()){ - - if ( tempNodeTemplate.getId().toString().compareTo( serviceTemplate.getId().toString()) == 0 ) - { - substituteNode = tempNodeTemplate; - break; - } - - } - - if ( substituteNode == null) - return; - - final TNodeTemplateExtension nodeTemplate = (TNodeTemplateExtension) substituteNode; - if( nodeTemplate.getPolicies() == null ) { - final PoliciesType nodePolicyList = ToscaFactory.eINSTANCE.createPoliciesType(); - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( nodeTemplate ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { - - @Override - protected void doExecute() { - nodeTemplate.setPolicies( nodePolicyList ); - } - } ); - } - PoliciesType nodePolicyList = nodeTemplate.getPolicies(); - final EList<TPolicy> policy = nodePolicyList.getPolicy(); - final TPolicy newPolicy = createNewPolicy( "Constraint", - newElasticityConstraint, newSYBLConstraint ); + } + if( substituteNode == null ) + return; + final TNodeTemplateExtension nodeTemplate = ( TNodeTemplateExtension )substituteNode; + if( nodeTemplate.getPolicies() == null ) { + final PoliciesType nodePolicyList = ToscaFactory.eINSTANCE.createPoliciesType(); TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( nodeTemplate ); editingDomain.getCommandStack() .execute( new RecordingCommand( editingDomain ) { @Override protected void doExecute() { - policy.add( newPolicy ); + nodeTemplate.setPolicies( nodePolicyList ); } } ); - // Add Application Component Elasticity Requirement to temp list - this.appComponentElasticityRequirements.add( newPolicy ); - this.tableViewer.refresh(); - } else { } + PoliciesType nodePolicyList = nodeTemplate.getPolicies(); + final EList<TPolicy> policy = nodePolicyList.getPolicy(); + final TPolicy newPolicy = ToscaFactory.eINSTANCE.createTPolicy(); + String type = "Constraint"; + QName policyTypeName = new QName( "http://www.example.org/SYBL", + type, + null ); + newPolicy.setPolicyType( policyTypeName ); + newPolicy.setName( type.toUpperCase() + " " + newElasticityConstraint ); + + String id = "G" + ( ( Integer )nodeTemplate.hashCode() ).toString() + nodePolicyList.getPolicy().size(); + QName qnamePolicyTemplate = new QName( id ); + newPolicy.setPolicyRef( qnamePolicyTemplate ); + + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( nodeTemplate ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { + + @Override + protected void doExecute() { + policy.add( newPolicy ); + } + } ); + // Add Application Component Elasticity Requirement to temp list + this.appComponentElasticityRequirements.add( newPolicy ); + this.tableViewer.refresh(); } } } +} - void editDataStagingEntryRA( final TPolicy selectedObject ) { - ElasticityStrategyDialog dialog; - if( selectedObject == null ) { - // Add button is pressed - dialog = new ElasticityStrategyDialog( this.section.getShell(), - "Application Component" ); //$NON-NLS-1$ - if( dialog.open() == Window.OK ) { - String newElasticityStrategy = dialog.getElasticityStrategy(); - SyblElasticityRequirementsDescription newSYBLStrategy = dialog.getSYBLStrategy(); - if( newElasticityStrategy != null ) { - // Add Application Component Elasticity Strategy to TOSCA - PictogramElement pe = getSelectedPictogramElement(); - Object bo = null; - if( pe != null ) { - bo = Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( pe ); - } - // Find the substitute TNodeTemplate - TServiceTemplate serviceTemplate = (TServiceTemplate) bo; - TNodeTemplate substituteNode = null; - ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - for (TNodeTemplate tempNodeTemplate : model.getDocumentRoot() - .getDefinitions() - .getServiceTemplate() - .get( 0 ) - .getTopologyTemplate() - .getNodeTemplate()){ - - if ( tempNodeTemplate.getId().toString().compareTo( serviceTemplate.getId().toString()) == 0 ) - { - substituteNode = tempNodeTemplate; - break; - } - - } - - if ( substituteNode == null) - return; - - final TNodeTemplateExtension nodeTemplate = (TNodeTemplateExtension) substituteNode; - if( nodeTemplate.getPolicies() == null ) { - final PoliciesType nodePolicyList = ToscaFactory.eINSTANCE.createPoliciesType(); - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { +void editDataStagingEntryRA( final TPolicy selectedObject ) { + ElasticityStrategyDialog dialog; + if( selectedObject == null ) { + // Add button is pressed + PictogramElement pe = getSelectedPictogramElement(); + Object bo = null; + if( pe != null ) { + bo = Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( pe ); + } + // Find the substitute TNodeTemplate + TServiceTemplate serviceTemplate = ( TServiceTemplate )bo; + + dialog = new ElasticityStrategyDialog( this.section.getShell(), + "Application Component", serviceTemplate.getName() ); //$NON-NLS-1$ + if( dialog.open() == Window.OK ) { + String newElasticityStrategy = dialog.getElasticityStrategy(); + if( newElasticityStrategy != null ) { + // Add Application Component Elasticity Strategy to TOSCA - @Override - protected void doExecute() { - nodeTemplate.setPolicies( nodePolicyList ); - } - } ); + TNodeTemplate substituteNode = null; + ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); + for( TNodeTemplate tempNodeTemplate : model.getDocumentRoot() + .getDefinitions() + .getServiceTemplate() + .get( 0 ) + .getTopologyTemplate() + .getNodeTemplate() ) + { + if( tempNodeTemplate.getId() + .toString() + .compareTo( serviceTemplate.getId().toString() ) == 0 ) + { + substituteNode = tempNodeTemplate; + break; } - PoliciesType nodePolicyList = nodeTemplate.getPolicies(); - final EList<TPolicy> policy = nodePolicyList.getPolicy(); - final TPolicy newPolicy = createNewPolicy( "Strategy", - newElasticityStrategy, newSYBLStrategy ); + } + if( substituteNode == null ) + return; + final TNodeTemplateExtension nodeTemplate = ( TNodeTemplateExtension )substituteNode; + if( nodeTemplate.getPolicies() == null ) { + final PoliciesType nodePolicyList = ToscaFactory.eINSTANCE.createPoliciesType(); TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); editingDomain.getCommandStack() .execute( new RecordingCommand( editingDomain ) { @Override protected void doExecute() { - policy.add( newPolicy ); + nodeTemplate.setPolicies( nodePolicyList ); } } ); - this.appComponentResizingActions.add( newPolicy ); - this.tableResizingActionsViewer.refresh(); - } else { - // Edit } - } - } - } - - - // type is either "Constraint" or "Strategy" - TPolicy createNewPolicy(String type, String policyName, SyblElasticityRequirementsDescription syblPolicy){ - - // Create Policy Template - - final TPolicyTemplate newPolicyTemplate = ToscaFactory.eINSTANCE.createTPolicyTemplate(); - - QName policyTypeName = new QName( "http://www.example.org/SYBL", type, null ); - - newPolicyTemplate.setType( policyTypeName ); - - String id = "G" + ( ( Integer )newPolicyTemplate.hashCode() ).toString(); - - newPolicyTemplate.setId( id ); - - - // Set the Properties of the Policy Template - - PropertiesType properties = ToscaFactory.eINSTANCE.createPropertiesType(); - - // Add the SYBL Policy to the FeatureMap of the Policy's Properties element - Entry e = FeatureMapUtil.createEntry( SyblPackage.eINSTANCE.getDocumentRoot_SYBLElasticityRequirementsDescription(), syblPolicy ); - properties.getAny().add( e ); - - newPolicyTemplate.setProperties( properties ); + PoliciesType nodePolicyList = nodeTemplate.getPolicies(); + final EList<TPolicy> policy = nodePolicyList.getPolicy(); + final TPolicy newPolicy = ToscaFactory.eINSTANCE.createTPolicy(); + String type = "Strategy"; + QName policyTypeName = new QName( "http://www.example.org/SYBL", + type, + null ); + newPolicy.setPolicyType( policyTypeName ); + newPolicy.setName( type.toUpperCase() + " " + newElasticityStrategy ); - // Add the new Policy Template to the TOSCA Definitions element - - final ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - - DefinitionsType definitions = model.getDocumentRoot().getDefinitions(); - - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( definitions ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { + String id = "G" + ( ( Integer )nodeTemplate.hashCode() ).toString() + nodePolicyList.getPolicy().size(); + QName qnamePolicyTemplate = new QName( id ); + newPolicy.setPolicyRef( qnamePolicyTemplate ); + + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { - @Override - protected void doExecute() { - model.getDocumentRoot().getDefinitions().getPolicyTemplate().add( newPolicyTemplate ); - - } - } ); - - // Assign the created Policy Template to the new Policy - - TPolicy newPolicy = ToscaFactory.eINSTANCE.createTPolicy(); - - QName qnamePolicyTemplate = new QName( newPolicyTemplate.getId() ); - - newPolicy.setPolicyType( policyTypeName ); - - newPolicy.setPolicyRef( qnamePolicyTemplate ); - - newPolicy.setName( type.toUpperCase() + " " + policyName ); - - return newPolicy; + @Override + protected void doExecute() { + policy.add( newPolicy ); + } + } ); + this.appComponentResizingActions.add( newPolicy ); + this.tableResizingActionsViewer.refresh(); + } else { + // Edit + } + } } - - void addStrategyCondition( final TPolicy selectedObject ) { - if( selectedObject == null ) - return; - - // Find the substitute TNodeTemplate +} - PictogramElement pe = getSelectedPictogramElement(); - Object bo = null; - if( pe != null ) { - bo = Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( pe ); - } - - ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - - - ElasticityConditionDialog dialog; - - dialog = new ElasticityConditionDialog( this.section.getShell(), - "Composite Component", - model, - selectedObject.getName() ); //$NON-NLS-1$ - String newElasticityCondition = null; - ConditionType policyCondition = null; - if( dialog.open() == Window.OK ) { - newElasticityCondition = dialog.getSelectedCondition(); - policyCondition = dialog.getSYBLCondition(); - } - if( newElasticityCondition == null ) - return; - - String newCond = newElasticityCondition; - - if (newCond.contains( "<" )){ - String[] cond = newCond.split( "<" ); - newCond = cond[0] + "<" + cond[1]; - } - else if (newCond.contains( ">" )){ - String[] cond = newCond.split( ">" ); - newCond = cond[0] + ">" + cond[1]; - } - - final String condition = newCond; - - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { - - @Override - protected void doExecute() { - String[] strategy = selectedObject.getName().split( "STRATEGY" ); - selectedObject.setName( strategy[ 0 ] - + "STRATEGY " - + condition + " :" - + strategy[ 1 ] ); - } - } ); - this.tableResizingActionsViewer.refresh(); - - //addPolicyCondition( selectedObject, policyCondition); +void addStrategyCondition( final TPolicy selectedObject ) { + if( selectedObject == null ) + return; + // Find the substitute TNodeTemplate + PictogramElement pe = getSelectedPictogramElement(); + Object bo = null; + if( pe != null ) { + bo = Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( pe ); } - -// void addPolicyCondition(final TPolicy selectedPolicy, final ConditionType policyCondition){ -// -// ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); -// EList<TPolicyTemplate> policyTemplates = model.getDocumentRoot().getDefinitions().getPolicyTemplate(); -// TPolicyTemplate policyTemplate = null; -// for ( TPolicyTemplate tempPolicyTemplate : policyTemplates ){ -// if (tempPolicyTemplate.getId().toString().equals(selectedPolicy.getPolicyRef().toString())){ -// policyTemplate = tempPolicyTemplate; -// break; -// } -// } -// -// final SyblElasticityRequirementsDescription syblPolicy = (SyblElasticityRequirementsDescription) policyTemplate.getProperties().getAny().get(0).getValue(); -// TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( policyTemplate ); -// editingDomain.getCommandStack() -// .execute( new RecordingCommand( editingDomain ) { -// -// @Override -// protected void doExecute() { -// syblPolicy.getSYBLSpecification().get( 0 ).getStrategy().get( 0 ).setCondition( policyCondition ); -// } -// } ); -// } + ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); + ElasticityConditionDialog dialog; + dialog = new ElasticityConditionDialog( this.section.getShell(), + "Composite Component", + model, + selectedObject.getName() ); //$NON-NLS-1$ + String newElasticityCondition = null; + if( dialog.open() == Window.OK ) { + newElasticityCondition = dialog.getSelectedCondition(); + } + if( newElasticityCondition == null ) + return; + String newCond = newElasticityCondition; + if( newCond.contains( "<" ) ) { + String[] cond = newCond.split( "<" ); + newCond = cond[ 0 ] + "<" + cond[ 1 ]; + } else if( newCond.contains( ">" ) ) { + String[] cond = newCond.split( ">" ); + newCond = cond[ 0 ] + ">" + cond[ 1 ]; + } + final String condition = newCond; + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { - // Remove the selected Application Component Elasticity Requirement from TOSCA - void removeApplicationComponentElasticityRequirement( final TPolicy selectedObject ) + @Override + protected void doExecute() { + String[] strategy = selectedObject.getName().split( "STRATEGY" ); + selectedObject.setName( strategy[ 0 ] + + "STRATEGY " + + condition + + " :" + + strategy[ 1 ] ); + } + } ); + this.tableResizingActionsViewer.refresh(); +} + +// Remove the selected Application Component Elasticity Requirement from TOSCA +void removeApplicationComponentElasticityRequirement( final TPolicy selectedObject ) +{ + PictogramElement pe = getSelectedPictogramElement(); + Object bo = null; + if( pe != null ) { + bo = Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( pe ); + } + // Find the substitute TNodeTemplate + TServiceTemplate serviceTemplate = ( TServiceTemplate )bo; + TNodeTemplate substituteNode = null; + ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); + for( TNodeTemplate tempNodeTemplate : model.getDocumentRoot() + .getDefinitions() + .getServiceTemplate() + .get( 0 ) + .getTopologyTemplate() + .getNodeTemplate() ) { - PictogramElement pe = getSelectedPictogramElement(); - Object bo = null; - if( pe != null ) { - bo = Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( pe ); + if( tempNodeTemplate.getId() + .toString() + .compareTo( serviceTemplate.getId().toString() ) == 0 ) + { + substituteNode = tempNodeTemplate; + break; } + } + if( substituteNode == null ) + return; + final TNodeTemplateExtension nodeTemplate = ( TNodeTemplateExtension )substituteNode; + PoliciesType nodePolicyList = nodeTemplate.getPolicies(); + final EList<TPolicy> policy = nodePolicyList.getPolicy(); + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { - // Find the substitute TNodeTemplate - TServiceTemplate serviceTemplate = (TServiceTemplate) bo; - TNodeTemplate substituteNode = null; - ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - for (TNodeTemplate tempNodeTemplate : model.getDocumentRoot() - .getDefinitions() - .getServiceTemplate() - .get( 0 ) - .getTopologyTemplate() - .getNodeTemplate()){ - - if (tempNodeTemplate.getId().toString().compareTo( serviceTemplate.getId().toString()) == 0 ) - { - substituteNode = tempNodeTemplate; - break; - } - - } - - if ( substituteNode == null) - return; - - final TNodeTemplateExtension nodeTemplate = (TNodeTemplateExtension) substituteNode; - - PoliciesType nodePolicyList = nodeTemplate.getPolicies(); - final EList<TPolicy> policy = nodePolicyList.getPolicy(); - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { - - @Override - protected void doExecute() { - for( TPolicy tempPolicy : policy ) { - if( tempPolicy.getPolicyType().toString().contains( "Constraint" ) ) //$NON-NLS-1$ - if( tempPolicy.getName().compareTo( selectedObject.getName() ) == 0 ) - { - policy.remove( tempPolicy ); - if( policy.size() == 0 ) - nodeTemplate.setPolicies( null ); - // remove corresponding Policy Template - String removedPolicyId = tempPolicy.getPolicyRef().toString(); - ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - DefinitionsType toscaDefinitions = model.getDocumentRoot() - .getDefinitions(); - final EList<TPolicyTemplate> policyTemplate = toscaDefinitions.getPolicyTemplate(); - for( TPolicyTemplate tempPolicyTemplate : policyTemplate ) { - if( tempPolicyTemplate.getId().equals( removedPolicyId ) ) { - policyTemplate.remove( tempPolicyTemplate ); - } - } - break; - } - } + @Override + protected void doExecute() { + for( TPolicy tempPolicy : policy ) { + if( tempPolicy.getPolicyType().toString().contains( "Constraint" ) ) //$NON-NLS-1$ + if( tempPolicy.getName().compareTo( selectedObject.getName() ) == 0 ) + { + policy.remove( tempPolicy ); + if( policy.size() == 0 ) + nodeTemplate.setPolicies( null ); + break; + } } - } ); - this.appComponentElasticityRequirements.remove( selectedObject ); - this.tableViewer.refresh(); - } - - // Return the selected Elasticity Requirement - TPolicy getSelectedObject() { - TPolicy result = null; - IStructuredSelection selection = ( IStructuredSelection )this.tableViewer.getSelection(); - Object obj = selection.getFirstElement(); - result = ( TPolicy )obj; - return result; - } - - // Return the selected Elasticity Action - TPolicy getSelectedElasticityStrategy() { - TPolicy result = null; - IStructuredSelection selection = ( IStructuredSelection )this.tableResizingActionsViewer.getSelection(); - Object obj = selection.getFirstElement(); - result = ( TPolicy )obj; - return result; - } - - /** - * Get Application Component Elasticity Actions - */ - public void getResizingActions() { - PictogramElement pe = getSelectedPictogramElement(); - Object bo = null; - if( pe != null ) { - bo = Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( pe ); - } - // Find the substitute TNodeTemplate - TServiceTemplate serviceTemplate = (TServiceTemplate) bo; - TNodeTemplate substituteNode = null; - ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - for (TNodeTemplate tempNodeTemplate : model.getDocumentRoot() - .getDefinitions() - .getServiceTemplate() - .get( 0 ) - .getTopologyTemplate() - .getNodeTemplate()){ - - if ( tempNodeTemplate.getId().toString().compareTo( serviceTemplate.getId().toString()) == 0 ) - { - substituteNode = tempNodeTemplate; - break; } - - } - - if ( substituteNode == null) - return; - - TNodeTemplateExtension appComponent = (TNodeTemplateExtension) substituteNode; - - PoliciesType nodePolicyList = appComponent.getPolicies(); - if( nodePolicyList == null ) - return; - for( TPolicy tempPolicy : nodePolicyList.getPolicy() ) { - if( tempPolicy.getPolicyType().toString().contains( "Strategy" ) ) //$NON-NLS-1$ - this.appComponentResizingActions.add( tempPolicy ); - } - } + } ); + this.appComponentElasticityRequirements.remove( selectedObject ); + this.tableViewer.refresh(); +} - /** - * Get Application Component Elasticity Constraints - */ - public void getElasticityConstraints() { - PictogramElement pe = getSelectedPictogramElement(); - Object bo = null; - if( pe != null ) { - bo = Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( pe ); - } - // Find the substitute TNodeTemplate - TServiceTemplate serviceTemplate = (TServiceTemplate) bo; - TNodeTemplate substituteNode = null; - ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - for (TNodeTemplate tempNodeTemplate : model.getDocumentRoot() - .getDefinitions() - .getServiceTemplate() - .get( 0 ) - .getTopologyTemplate() - .getNodeTemplate()){ - - if ( tempNodeTemplate.getId().toString().compareTo( serviceTemplate.getId().toString()) == 0 ) - { - substituteNode = tempNodeTemplate; - break; - } - - } - - if ( substituteNode == null) - return; - - TNodeTemplateExtension appComponent = (TNodeTemplateExtension) substituteNode; - PoliciesType nodePolicyList = appComponent.getPolicies(); - if( nodePolicyList == null ) - return; - for( TPolicy tempPolicy : nodePolicyList.getPolicy() ) { - if( tempPolicy.getPolicyType().toString().contains( "Constraint" ) ) //$NON-NLS-1$ - this.appComponentElasticityRequirements.add( tempPolicy ); - } - } +// Return the selected Elasticity Requirement +TPolicy getSelectedObject() { + TPolicy result = null; + IStructuredSelection selection = ( IStructuredSelection )this.tableViewer.getSelection(); + Object obj = selection.getFirstElement(); + result = ( TPolicy )obj; + return result; +} - // Remove Application Component Elasticity Action - void removeApplicationComponentResizingAction( final TPolicy selectedObject ) +// Return the selected Elasticity Action +TPolicy getSelectedElasticityStrategy() { + TPolicy result = null; + IStructuredSelection selection = ( IStructuredSelection )this.tableResizingActionsViewer.getSelection(); + Object obj = selection.getFirstElement(); + result = ( TPolicy )obj; + return result; +} + +/** + * Get Application Component Elasticity Actions + */ +public void getResizingActions() { + PictogramElement pe = getSelectedPictogramElement(); + Object bo = null; + if( pe != null ) { + bo = Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( pe ); + } + // Find the substitute TNodeTemplate + TServiceTemplate serviceTemplate = ( TServiceTemplate )bo; + if (serviceTemplate == null) + return; + TNodeTemplate substituteNode = null; + ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); + for( TNodeTemplate tempNodeTemplate : model.getDocumentRoot() + .getDefinitions() + .getServiceTemplate() + .get( 0 ) + .getTopologyTemplate() + .getNodeTemplate() ) { - PictogramElement pe = getSelectedPictogramElement(); - Object bo = null; - if( pe != null ) { - bo = Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement( pe ); + if( tempNodeTemplate.getId() + .toString() + .compareTo( serviceTemplate.getId().toString() ) == 0 ) + { + substituteNode = tempNodeTemplate; + break; } - // Find the substitute TNodeTemplate - TServiceTemplate serviceTemplate = (TServiceTemplate) bo; - TNodeTemplate substituteNode = null; - ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - for (TNodeTemplate tempNodeTemplate : model.getDocumentRoot() - .getDefinitions() - .getServiceTemplate() - .get( 0 ) - .getTopologyTemplate() - .getNodeTemplate()){ - - if ( tempNodeTemplate.getId().toString().compareTo( serviceTemplate.getId().toString()) == 0 ) - { - substituteNode = tempNodeTemplate; - break; - } - - } - - if ( substituteNode == null) - return; - - final TNodeTemplateExtension nodeTemplate = (TNodeTemplateExtension) substituteNode; - PoliciesType nodePolicyList = nodeTemplate.getPolicies(); - final EList<TPolicy> policy = nodePolicyList.getPolicy(); - TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); - editingDomain.getCommandStack() - .execute( new RecordingCommand( editingDomain ) { + } + if( substituteNode == null ) + return; + TNodeTemplateExtension appComponent = ( TNodeTemplateExtension )substituteNode; + PoliciesType nodePolicyList = appComponent.getPolicies(); + if( nodePolicyList == null ) + return; + for( TPolicy tempPolicy : nodePolicyList.getPolicy() ) { + if( tempPolicy.getPolicyType().toString().contains( "Strategy" ) ) //$NON-NLS-1$ + this.appComponentResizingActions.add( tempPolicy ); + } +} - @Override - protected void doExecute() { - for( TPolicy tempPolicy : policy ) { - if( tempPolicy.getPolicyType().toString().contains( "Strategy" ) ) //$NON-NLS-1$ - if( tempPolicy.getName().compareTo( selectedObject.getName() ) == 0 ) - { - policy.remove( tempPolicy ); - if( policy.size() == 0 ) - nodeTemplate.setPolicies( null ); - // remove corresponding Policy Template - String removedPolicyId = tempPolicy.getPolicyRef().toString(); - ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); - DefinitionsType toscaDefinitions = model.getDocumentRoot() - .getDefinitions(); - final EList<TPolicyTemplate> policyTemplate = toscaDefinitions.getPolicyTemplate(); - for( TPolicyTemplate tempPolicyTemplate : policyTemplate ) { - if( tempPolicyTemplate.getId().equals( removedPolicyId ) ) { - policyTemplate.remove( tempPolicyTemplate ); - } - } - break; - } - } +/** + * Get Application Component Elasticity Constraints + */ +public void getElasticityConstraints() { + PictogramElement pe = getSelectedPictogramElement(); + Object bo = null; + if( pe != null ) { + bo = Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( pe ); + } + // Find the substitute TNodeTemplate + TServiceTemplate serviceTemplate = ( TServiceTemplate )bo; + + if (serviceTemplate == null) + return; + + TNodeTemplate substituteNode = null; + ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); + + for( TNodeTemplate tempNodeTemplate : model.getDocumentRoot() + .getDefinitions() + .getServiceTemplate() + .get( 0 ) + .getTopologyTemplate() + .getNodeTemplate() ) + { + if( tempNodeTemplate.getId() + .toString() + .compareTo( serviceTemplate.getId().toString() ) == 0 ) + { + substituteNode = tempNodeTemplate; + break; + } + } + if( substituteNode == null ) + return; + TNodeTemplateExtension appComponent = ( TNodeTemplateExtension )substituteNode; + PoliciesType nodePolicyList = appComponent.getPolicies(); + if( nodePolicyList == null ) + return; + for( TPolicy tempPolicy : nodePolicyList.getPolicy() ) { + if( tempPolicy.getPolicyType().toString().contains( "Constraint" ) ) //$NON-NLS-1$ + this.appComponentElasticityRequirements.add( tempPolicy ); + } +} + +// Remove Application Component Elasticity Action +void removeApplicationComponentResizingAction( final TPolicy selectedObject ) +{ + PictogramElement pe = getSelectedPictogramElement(); + Object bo = null; + if( pe != null ) { + bo = Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement( pe ); + } + // Find the substitute TNodeTemplate + TServiceTemplate serviceTemplate = ( TServiceTemplate )bo; + TNodeTemplate substituteNode = null; + ToscaModelLayer model = ModelHandler.getModel( EcoreUtil.getURI( getDiagram() ) ); + for( TNodeTemplate tempNodeTemplate : model.getDocumentRoot() + .getDefinitions() + .getServiceTemplate() + .get( 0 ) + .getTopologyTemplate() + .getNodeTemplate() ) + { + if( tempNodeTemplate.getId() + .toString() + .compareTo( serviceTemplate.getId().toString() ) == 0 ) + { + substituteNode = tempNodeTemplate; + break; + } + } + if( substituteNode == null ) + return; + final TNodeTemplateExtension nodeTemplate = ( TNodeTemplateExtension )substituteNode; + PoliciesType nodePolicyList = nodeTemplate.getPolicies(); + final EList<TPolicy> policy = nodePolicyList.getPolicy(); + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( bo ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { + + @Override + protected void doExecute() { + for( TPolicy tempPolicy : policy ) { + if( tempPolicy.getPolicyType().toString().contains( "Strategy" ) ) //$NON-NLS-1$ + if( tempPolicy.getName().compareTo( selectedObject.getName() ) == 0 ) + { + policy.remove( tempPolicy ); + if( policy.size() == 0 ) + nodeTemplate.setPolicies( null ); + break; + } } - } ); - this.appComponentResizingActions.remove( selectedObject ); - this.tableResizingActionsViewer.refresh(); - } + } + } ); + this.appComponentResizingActions.remove( selectedObject ); + this.tableResizingActionsViewer.refresh(); +} - /* - * Refresh Elasticity Tab(non-Javadoc) - * @see - * org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#refresh() - */ - @Override - public void refresh() { - // Refresh Elasticity Constraints - this.appComponentElasticityRequirements.clear(); - getElasticityConstraints(); - this.tableViewer.refresh(); - // Refresh Elasticity Actions - this.appComponentResizingActions.clear(); - getResizingActions(); - this.tableResizingActionsViewer.refresh(); - } +/* + * Refresh Elasticity Tab(non-Javadoc) + * @see + * org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#refresh() + */ +@Override +public void refresh() { + // Refresh Elasticity Constraints + this.appComponentElasticityRequirements.clear(); + getElasticityConstraints(); + this.tableViewer.refresh(); + // Refresh Elasticity Actions + this.appComponentResizingActions.clear(); + getResizingActions(); + this.tableResizingActionsViewer.refresh(); +} }
diff --git a/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/elementCreators/CreateArtifactTemplate.java b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/elementCreators/CreateArtifactTemplate.java new file mode 100644 index 0000000..7b77352 --- /dev/null +++ b/plugins/org.eclipse.camf.tosca.editor/src/org/eclipse/camf/tosca/elementCreators/CreateArtifactTemplate.java
@@ -0,0 +1,91 @@ +package org.eclipse.camf.tosca.elementCreators; + +import java.io.File; + +import javax.xml.namespace.QName; + +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.emf.ecore.util.FeatureMapUtil; +import org.eclipse.emf.ecore.util.FeatureMap.Entry; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.emf.transaction.util.TransactionUtil; + +import org.eclipse.camf.tosca.ArtifactReferencesType; +import org.eclipse.camf.tosca.DefinitionsType; +import org.eclipse.camf.tosca.PropertiesType; +import org.eclipse.camf.tosca.TArtifactReference; +import org.eclipse.camf.tosca.TArtifactTemplate; +import org.eclipse.camf.tosca.ToscaFactory; +import org.eclipse.camf.tosca.editor.ToscaModelLayer; +import org.eclipse.camf.tosca.elasticity.ScriptArtifactPropertiesType; +import org.eclipse.camf.tosca.elasticity.Tosca_Elasticity_ExtensionsFactory; +import org.eclipse.camf.tosca.elasticity.Tosca_Elasticity_ExtensionsPackage; + + +public class CreateArtifactTemplate { + + TArtifactTemplate newArtifactTemplate = null; + + public CreateArtifactTemplate(String artifactName, QName artifactType, final ToscaModelLayer model){ + if (templateExists(model, artifactName)){ + return; + } + + // Create Artifact Template + final TArtifactTemplate artifactTemplate = ToscaFactory.eINSTANCE.createTArtifactTemplate(); + // Create Script Artifact Properties + ScriptArtifactPropertiesType scriptProperties = Tosca_Elasticity_ExtensionsFactory.eINSTANCE.createScriptArtifactPropertiesType(); + scriptProperties.setLanguage( "Shell" ); + // Set the Properties of the Policy Template + PropertiesType properties = ToscaFactory.eINSTANCE.createPropertiesType(); + // Add the SYBL Policy to the FeatureMap of the Policy's Properties element + Entry e = FeatureMapUtil.createEntry( Tosca_Elasticity_ExtensionsPackage.eINSTANCE.getDocumentRoot_ScriptArtifactProperties(), + scriptProperties ); + properties.getAny().add( e ); + artifactTemplate.setProperties( properties ); + artifactTemplate.setId( artifactName ); + artifactTemplate.setName( "SD"+artifactName ); + artifactTemplate.setType( artifactType ); + // Set artifact ref + TArtifactReference artifactRef = ToscaFactory.eINSTANCE.createTArtifactReference(); + artifactRef.setReference( "Scripts" + System.getProperty( "file.separator" ) + artifactName ); + ArtifactReferencesType artifactRefType = ToscaFactory.eINSTANCE.createArtifactReferencesType(); + artifactRefType.getArtifactReference().add( artifactRef ); + artifactTemplate.setArtifactReferences( artifactRefType ); + + // Add the new Artifact Template to the TOSCA Definitions element + DefinitionsType definitions = model.getDocumentRoot().getDefinitions(); + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain( definitions ); + editingDomain.getCommandStack() + .execute( new RecordingCommand( editingDomain ) { + + @Override + protected void doExecute() { + model.getDocumentRoot() + .getDefinitions() + .getArtifactTemplate() + .add( artifactTemplate ); + } + } ); + + this.newArtifactTemplate = artifactTemplate; + + } + + private boolean templateExists(final ToscaModelLayer model, String artifactName){ + + for (TArtifactTemplate tempArtifactTemplate : model.getDocumentRoot() + .getDefinitions() + .getArtifactTemplate()){ + if (tempArtifactTemplate.getId().equals( artifactName )) + return true; + } + + return false; + } + + public TArtifactTemplate getNewArtifactTemplate(){ + return this.newArtifactTemplate; + } +}