Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.etrice.ui.structure')
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/.classpath14
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/.gitignore2
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/.project56
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/.settings/org.eclipse.jdt.core.prefs16
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/META-INF/MANIFEST.MF50
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/about.html54
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/build.properties12
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/plugin.xml130
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/Activator.java154
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramAccess.java130
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramTypeProvider.java174
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/ImageProvider.java76
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/ProviderDispatcher.java980
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/commands/PopulateDiagramCommand.java236
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/ActorContainerRefPropertyDialog.java448
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/PortPropertyDialog.java706
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/SPPPropertyDialog.java262
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/SubProtocolSelectionDialog.java422
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureEditor.java98
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureExporter.java60
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/link/ExecutableExtensionFactory.java58
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/link/ResourceModule.java72
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/ActorContainerRefSupport.java2238
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/BindingSupport.java1190
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/Constants.java52
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/DecorationProvider.java102
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/InterfaceItemSupport.java1632
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/LayerConnectionSupport.java842
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/PortSupport.java1116
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/SPPSupport.java964
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassSupport.java1378
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/SupportUtil.java654
32 files changed, 7189 insertions, 7189 deletions
diff --git a/plugins/org.eclipse.etrice.ui.structure/.classpath b/plugins/org.eclipse.etrice.ui.structure/.classpath
index 8a8f1668c..ad32c83a7 100644
--- a/plugins/org.eclipse.etrice.ui.structure/.classpath
+++ b/plugins/org.eclipse.etrice.ui.structure/.classpath
@@ -1,7 +1,7 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/org.eclipse.etrice.ui.structure/.gitignore b/plugins/org.eclipse.etrice.ui.structure/.gitignore
index 092357e47..ba077a403 100644
--- a/plugins/org.eclipse.etrice.ui.structure/.gitignore
+++ b/plugins/org.eclipse.etrice.ui.structure/.gitignore
@@ -1 +1 @@
-bin
+bin
diff --git a/plugins/org.eclipse.etrice.ui.structure/.project b/plugins/org.eclipse.etrice.ui.structure/.project
index 93e38c39b..27837f35e 100644
--- a/plugins/org.eclipse.etrice.ui.structure/.project
+++ b/plugins/org.eclipse.etrice.ui.structure/.project
@@ -1,28 +1,28 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.eclipse.etrice.ui.structure</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.ManifestBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.SchemaBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.pde.PluginNature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.etrice.ui.structure</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/org.eclipse.etrice.ui.structure/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.etrice.ui.structure/.settings/org.eclipse.jdt.core.prefs
index 244bc70d5..1e3f3dd1f 100644
--- a/plugins/org.eclipse.etrice.ui.structure/.settings/org.eclipse.jdt.core.prefs
+++ b/plugins/org.eclipse.etrice.ui.structure/.settings/org.eclipse.jdt.core.prefs
@@ -1,8 +1,8 @@
-#Thu Oct 14 15:48:59 CEST 2010
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
-org.eclipse.jdt.core.compiler.compliance=1.6
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.6
+#Thu Oct 14 15:48:59 CEST 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/plugins/org.eclipse.etrice.ui.structure/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.ui.structure/META-INF/MANIFEST.MF
index e9cba2610..e1062ef15 100644
--- a/plugins/org.eclipse.etrice.ui.structure/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.etrice.ui.structure/META-INF/MANIFEST.MF
@@ -1,25 +1,25 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: Actor Structure Diagram Editor
-Bundle-SymbolicName: org.eclipse.etrice.ui.structure;singleton:=true
-Bundle-Version: 0.3.0.qualifier
-Bundle-Activator: org.eclipse.etrice.ui.structure.Activator
-Bundle-Vendor: Eclipse eTrice (Incubation)
-Require-Bundle: org.eclipse.etrice.core.room.ui;bundle-version="0.3.0",
- org.eclipse.etrice.ui.common;bundle-version="0.3.0",
- org.eclipse.etrice.ui.behavior;bundle-version="0.3.0",
- org.eclipse.graphiti;bundle-version="0.8.0",
- org.eclipse.graphiti.ui;bundle-version="0.8.0",
- org.eclipse.ui.views.properties.tabbed;bundle-version="3.5.100",
- org.eclipse.core.databinding;bundle-version="1.3.100",
- org.eclipse.gef;bundle-version="3.6.1",
- org.eclipse.emf.transaction;bundle-version="1.4.0",
- org.eclipse.xtext.ui;bundle-version="2.1.1",
- org.eclipse.xtext.ui.shared;bundle-version="2.1.1",
- org.eclipse.jface.databinding;bundle-version="1.5.0",
- org.eclipse.core.databinding.beans;bundle-version="1.2.100"
-Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Bundle-ActivationPolicy: lazy
-Export-Package: org.eclipse.etrice.ui.structure,
- org.eclipse.etrice.ui.structure.editor,
- org.eclipse.etrice.ui.structure.support
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Actor Structure Diagram Editor
+Bundle-SymbolicName: org.eclipse.etrice.ui.structure;singleton:=true
+Bundle-Version: 0.3.0.qualifier
+Bundle-Activator: org.eclipse.etrice.ui.structure.Activator
+Bundle-Vendor: Eclipse eTrice (Incubation)
+Require-Bundle: org.eclipse.etrice.core.room.ui;bundle-version="0.3.0",
+ org.eclipse.etrice.ui.common;bundle-version="0.3.0",
+ org.eclipse.etrice.ui.behavior;bundle-version="0.3.0",
+ org.eclipse.graphiti;bundle-version="0.8.0",
+ org.eclipse.graphiti.ui;bundle-version="0.8.0",
+ org.eclipse.ui.views.properties.tabbed;bundle-version="3.5.100",
+ org.eclipse.core.databinding;bundle-version="1.3.100",
+ org.eclipse.gef;bundle-version="3.6.1",
+ org.eclipse.emf.transaction;bundle-version="1.4.0",
+ org.eclipse.xtext.ui;bundle-version="2.1.1",
+ org.eclipse.xtext.ui.shared;bundle-version="2.1.1",
+ org.eclipse.jface.databinding;bundle-version="1.5.0",
+ org.eclipse.core.databinding.beans;bundle-version="1.2.100"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-ActivationPolicy: lazy
+Export-Package: org.eclipse.etrice.ui.structure,
+ org.eclipse.etrice.ui.structure.editor,
+ org.eclipse.etrice.ui.structure.support
diff --git a/plugins/org.eclipse.etrice.ui.structure/about.html b/plugins/org.eclipse.etrice.ui.structure/about.html
index f47dbddbb..c258ef55d 100644
--- a/plugins/org.eclipse.etrice.ui.structure/about.html
+++ b/plugins/org.eclipse.etrice.ui.structure/about.html
@@ -1,28 +1,28 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
-<title>About</title>
-</head>
-<body lang="EN-US">
-<h2>About This Content</h2>
-
-<p>June 5, 2006</p>
-<h3>License</h3>
-
-<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
-indicated below, the Content is provided to you under the terms and conditions of the
-Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
-at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
-For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
-
-<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
-being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
-apply to your use of any object code in the Content. Check the Redistributor's license that was
-provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
-indicated below, the terms and conditions of the EPL still apply to any source code in the Content
-and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 5, 2006</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body>
</html> \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.structure/build.properties b/plugins/org.eclipse.etrice.ui.structure/build.properties
index 285b8bf47..6c480f39f 100644
--- a/plugins/org.eclipse.etrice.ui.structure/build.properties
+++ b/plugins/org.eclipse.etrice.ui.structure/build.properties
@@ -1,6 +1,6 @@
-source.. = src/
-output.. = bin/
-bin.includes = META-INF/,\
- .,\
- plugin.xml,\
- icons/
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ icons/
diff --git a/plugins/org.eclipse.etrice.ui.structure/plugin.xml b/plugins/org.eclipse.etrice.ui.structure/plugin.xml
index 04177e711..c52439167 100644
--- a/plugins/org.eclipse.etrice.ui.structure/plugin.xml
+++ b/plugins/org.eclipse.etrice.ui.structure/plugin.xml
@@ -1,65 +1,65 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.4"?>
-<plugin>
- <extension
- point="org.eclipse.graphiti.ui.diagramTypes">
- <diagramType
- id="org.eclipse.etrice.ui.structure.diagramType"
- name="ROOM Structure Diagram Type"
- type="room.structure">
- </diagramType>
- </extension>
- <extension
- point="org.eclipse.graphiti.ui.diagramTypeProviders">
- <diagramTypeProvider
- class="org.eclipse.etrice.ui.structure.DiagramTypeProvider"
- id="org.eclipse.etrice.ui.structure.diagramTypeProvider"
- name="ROOM Structure Editor">
- <diagramType
- id="org.eclipse.etrice.ui.structure.diagramType">
- </diagramType>
- <imageProvider
- id="org.eclipse.etrice.ui.structure.ImageProvider">
- </imageProvider>
- </diagramTypeProvider>
- </extension>
- <extension
- point="org.eclipse.ui.editors">
- <editor
- class="org.eclipse.etrice.ui.structure.editor.StructureEditor"
- contributorClass="org.eclipse.graphiti.ui.editor.DiagramEditorActionBarContributor"
- default="true"
- extensions="structure"
- icon="icons/Structure.gif"
- id="org.eclipse.etrice.ui.structure.editor.StructureEditor"
- matchingStrategy="org.eclipse.graphiti.ui.editor.DiagramEditorMatchingStrategy"
- name="ROOM Structure Editor">
- <contentTypeBinding
- contentTypeId="org.eclipse.graphiti.content.diagram">
- </contentTypeBinding>
- </editor>
- </extension>
-
- <extension
- point="org.eclipse.graphiti.ui.imageProviders">
- <imageProvider
- class="org.eclipse.etrice.ui.structure.ImageProvider"
- id="org.eclipse.etrice.ui.structure.ImageProvider">
- </imageProvider>
- </extension>
-
- <extension
- point="org.eclipse.emf.ecore.extension_parser">
- <parser
- class="org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl"
- type="structure">
- </parser>
- </extension>
- <extension point="org.eclipse.xtext.extension_resourceServiceProvider">
- <resourceServiceProvider
- class="org.eclipse.etrice.ui.structure.link.ExecutableExtensionFactory:org.eclipse.xtext.ui.resource.IResourceUIServiceProvider"
- uriExtension="structure">
- </resourceServiceProvider>
- </extension>
-
-</plugin>
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.graphiti.ui.diagramTypes">
+ <diagramType
+ id="org.eclipse.etrice.ui.structure.diagramType"
+ name="ROOM Structure Diagram Type"
+ type="room.structure">
+ </diagramType>
+ </extension>
+ <extension
+ point="org.eclipse.graphiti.ui.diagramTypeProviders">
+ <diagramTypeProvider
+ class="org.eclipse.etrice.ui.structure.DiagramTypeProvider"
+ id="org.eclipse.etrice.ui.structure.diagramTypeProvider"
+ name="ROOM Structure Editor">
+ <diagramType
+ id="org.eclipse.etrice.ui.structure.diagramType">
+ </diagramType>
+ <imageProvider
+ id="org.eclipse.etrice.ui.structure.ImageProvider">
+ </imageProvider>
+ </diagramTypeProvider>
+ </extension>
+ <extension
+ point="org.eclipse.ui.editors">
+ <editor
+ class="org.eclipse.etrice.ui.structure.editor.StructureEditor"
+ contributorClass="org.eclipse.graphiti.ui.editor.DiagramEditorActionBarContributor"
+ default="true"
+ extensions="structure"
+ icon="icons/Structure.gif"
+ id="org.eclipse.etrice.ui.structure.editor.StructureEditor"
+ matchingStrategy="org.eclipse.graphiti.ui.editor.DiagramEditorMatchingStrategy"
+ name="ROOM Structure Editor">
+ <contentTypeBinding
+ contentTypeId="org.eclipse.graphiti.content.diagram">
+ </contentTypeBinding>
+ </editor>
+ </extension>
+
+ <extension
+ point="org.eclipse.graphiti.ui.imageProviders">
+ <imageProvider
+ class="org.eclipse.etrice.ui.structure.ImageProvider"
+ id="org.eclipse.etrice.ui.structure.ImageProvider">
+ </imageProvider>
+ </extension>
+
+ <extension
+ point="org.eclipse.emf.ecore.extension_parser">
+ <parser
+ class="org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl"
+ type="structure">
+ </parser>
+ </extension>
+ <extension point="org.eclipse.xtext.extension_resourceServiceProvider">
+ <resourceServiceProvider
+ class="org.eclipse.etrice.ui.structure.link.ExecutableExtensionFactory:org.eclipse.xtext.ui.resource.IResourceUIServiceProvider"
+ uriExtension="structure">
+ </resourceServiceProvider>
+ </extension>
+
+</plugin>
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/Activator.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/Activator.java
index 6b6ed7577..b17b5f104 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/Activator.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/Activator.java
@@ -1,77 +1,77 @@
-/*******************************************************************************
- * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.structure;
-
-import org.osgi.framework.BundleContext;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-
-public class Activator extends AbstractUIPlugin {
-
- // The shared instance
- private static Activator plugin;
-
- // The plug-in ID
- public static final String PLUGIN_ID = "org.eclipse.etrice.ui.structure";
-
- /*
- * (non-Javadoc)
- * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
- */
- public void start(BundleContext context) throws Exception {
- super.start(context);
- plugin = this;
- }
-
- /*
- * (non-Javadoc)
- * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
- */
- public void stop(BundleContext context) throws Exception {
- plugin = null;
- super.stop(context);
- }
-
- /**
- * Returns the shared instance
- *
- * @return the shared instance
- */
- public static Activator getDefault() {
- return plugin;
- }
-
- /**
- * Returns an image descriptor for the image file at the given
- * plug-in relative path
- *
- * @param path
- * the path
- * @return the image descriptor
- */
- public static Image getImage(String path) {
- Image img = getDefault().getImageRegistry().get(path);
- if (img==null) {
- ImageDescriptor desc = imageDescriptorFromPlugin(PLUGIN_ID, path);
- if (desc==null)
- System.err.println("image not found: "+path);
- else {
- getDefault().getImageRegistry().put(path, desc);
- getDefault().getImageRegistry().get(path);
- }
- }
- return img;
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure;
+
+import org.osgi.framework.BundleContext;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+public class Activator extends AbstractUIPlugin {
+
+ // The shared instance
+ private static Activator plugin;
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.etrice.ui.structure";
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Returns an image descriptor for the image file at the given
+ * plug-in relative path
+ *
+ * @param path
+ * the path
+ * @return the image descriptor
+ */
+ public static Image getImage(String path) {
+ Image img = getDefault().getImageRegistry().get(path);
+ if (img==null) {
+ ImageDescriptor desc = imageDescriptorFromPlugin(PLUGIN_ID, path);
+ if (desc==null)
+ System.err.println("image not found: "+path);
+ else {
+ getDefault().getImageRegistry().put(path, desc);
+ getDefault().getImageRegistry().get(path);
+ }
+ }
+ return img;
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramAccess.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramAccess.java
index c1e230736..c395e88f9 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramAccess.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramAccess.java
@@ -1,65 +1,65 @@
-/*******************************************************************************
- * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.structure;
-
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.etrice.ui.common.DiagramAccessBase;
-import org.eclipse.etrice.ui.common.commands.UpdateCommand;
-import org.eclipse.etrice.ui.common.support.AutoUpdateFeature;
-import org.eclipse.etrice.ui.structure.commands.PopulateDiagramCommand;
-import org.eclipse.etrice.ui.structure.editor.StructureEditor;
-import org.eclipse.graphiti.dt.IDiagramTypeProvider;
-import org.eclipse.graphiti.features.IFeatureProvider;
-import org.eclipse.graphiti.mm.pictograms.Diagram;
-import org.eclipse.graphiti.ui.services.GraphitiUi;
-
-import org.eclipse.etrice.core.room.StructureClass;
-
-public class DiagramAccess extends DiagramAccessBase {
-
- protected String getDiagramName(StructureClass sc) {
- return "Structure of "+sc.getName();
- }
-
- protected String getDiagramTypeId() {
- return "room.structure";
- }
-
- protected String getEditorId() {
- return StructureEditor.STRUCTURE_EDITOR_ID;
- }
-
- protected String getFileExtension() {
- return ".structure";
- }
-
- protected Command getInitialCommand(StructureClass ac, Diagram diagram, TransactionalEditingDomain editingDomain) {
- return new PopulateDiagramCommand(diagram, ac, editingDomain);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.etrice.ui.common.DiagramAccessBase#getUpdateCommand(org.eclipse.graphiti.mm.pictograms.Diagram, org.eclipse.emf.transaction.TransactionalEditingDomain)
- */
- @Override
- protected Command getUpdateCommand(Diagram diagram, TransactionalEditingDomain editingDomain) {
- IDiagramTypeProvider dtp = GraphitiUi.getExtensionManager().createDiagramTypeProvider(diagram, DiagramTypeProvider.PROVIDER_ID); //$NON-NLS-1$
- IFeatureProvider featureProvider = dtp.getFeatureProvider();
- UpdateCommand cmd = new UpdateCommand(diagram, editingDomain, new AutoUpdateFeature(featureProvider));
- if (cmd.updateNeeded())
- return cmd;
-
- return null;
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure;
+
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.etrice.ui.common.DiagramAccessBase;
+import org.eclipse.etrice.ui.common.commands.UpdateCommand;
+import org.eclipse.etrice.ui.common.support.AutoUpdateFeature;
+import org.eclipse.etrice.ui.structure.commands.PopulateDiagramCommand;
+import org.eclipse.etrice.ui.structure.editor.StructureEditor;
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.ui.services.GraphitiUi;
+
+import org.eclipse.etrice.core.room.StructureClass;
+
+public class DiagramAccess extends DiagramAccessBase {
+
+ protected String getDiagramName(StructureClass sc) {
+ return "Structure of "+sc.getName();
+ }
+
+ protected String getDiagramTypeId() {
+ return "room.structure";
+ }
+
+ protected String getEditorId() {
+ return StructureEditor.STRUCTURE_EDITOR_ID;
+ }
+
+ protected String getFileExtension() {
+ return ".structure";
+ }
+
+ protected Command getInitialCommand(StructureClass ac, Diagram diagram, TransactionalEditingDomain editingDomain) {
+ return new PopulateDiagramCommand(diagram, ac, editingDomain);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.ui.common.DiagramAccessBase#getUpdateCommand(org.eclipse.graphiti.mm.pictograms.Diagram, org.eclipse.emf.transaction.TransactionalEditingDomain)
+ */
+ @Override
+ protected Command getUpdateCommand(Diagram diagram, TransactionalEditingDomain editingDomain) {
+ IDiagramTypeProvider dtp = GraphitiUi.getExtensionManager().createDiagramTypeProvider(diagram, DiagramTypeProvider.PROVIDER_ID); //$NON-NLS-1$
+ IFeatureProvider featureProvider = dtp.getFeatureProvider();
+ UpdateCommand cmd = new UpdateCommand(diagram, editingDomain, new AutoUpdateFeature(featureProvider));
+ if (cmd.updateNeeded())
+ return cmd;
+
+ return null;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramTypeProvider.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramTypeProvider.java
index 5f414d141..7ac6fb5ee 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramTypeProvider.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramTypeProvider.java
@@ -1,87 +1,87 @@
-/*******************************************************************************
- * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.structure;
-
-import org.eclipse.etrice.core.ui.RoomUiModule;
-import org.eclipse.graphiti.dt.AbstractDiagramTypeProvider;
-import org.eclipse.graphiti.tb.IToolBehaviorProvider;
-import org.eclipse.xtext.scoping.IScopeProvider;
-
-import com.google.inject.Inject;
-import com.google.inject.Injector;
-
-//@SuppressWarnings("restriction")
-public class DiagramTypeProvider extends AbstractDiagramTypeProvider {
-
- private static final boolean USE_AUTO_UPDATE = true;
-
- public static final String PROVIDER_ID = "org.eclipse.etrice.ui.structure.diagramTypeProvider";
-
- private IToolBehaviorProvider[] toolBehaviorProviders;
- private ProviderDispatcher dispatcher;
-
- @Inject
- private IScopeProvider scopeProvider;
-
- public DiagramTypeProvider() {
- super();
-
- Injector injector = RoomUiModule.getInjector();
- injector.injectMembers(this);
-
- dispatcher = new ProviderDispatcher(this);
- setFeatureProvider(dispatcher.getFeatureProvider());
-
-// IEclipsePreferences node = new DefaultScope().getNode(GraphitiPlugin.PLUGIN_ID);
-// if (node!=null)
-// node.putBoolean(GFPreferences.RECURSIVE_CHECK_FOR_UPDATE_ACTIVE, true);
- }
-
- @Override
- public IToolBehaviorProvider[] getAvailableToolBehaviorProviders() {
- if (toolBehaviorProviders == null) {
- toolBehaviorProviders =
- new IToolBehaviorProvider[] {
- dispatcher.getToolBehaviorProvider() };
- }
- return toolBehaviorProviders;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.graphiti.dt.AbstractDiagramTypeProvider#isAutoUpdateAtStartup()
- */
- @Override
- public boolean isAutoUpdateAtStartup() {
- return USE_AUTO_UPDATE;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.graphiti.dt.AbstractDiagramTypeProvider#isAutoUpdateAtReset()
- */
- @Override
- public boolean isAutoUpdateAtReset() {
- return USE_AUTO_UPDATE;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.graphiti.dt.AbstractDiagramTypeProvider#isAutoUpdateAtRuntime()
- */
- @Override
- public boolean isAutoUpdateAtRuntime() {
- return USE_AUTO_UPDATE;
- }
-
- public IScopeProvider getScopeProvider() {
- return scopeProvider;
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure;
+
+import org.eclipse.etrice.core.ui.RoomUiModule;
+import org.eclipse.graphiti.dt.AbstractDiagramTypeProvider;
+import org.eclipse.graphiti.tb.IToolBehaviorProvider;
+import org.eclipse.xtext.scoping.IScopeProvider;
+
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+
+//@SuppressWarnings("restriction")
+public class DiagramTypeProvider extends AbstractDiagramTypeProvider {
+
+ private static final boolean USE_AUTO_UPDATE = true;
+
+ public static final String PROVIDER_ID = "org.eclipse.etrice.ui.structure.diagramTypeProvider";
+
+ private IToolBehaviorProvider[] toolBehaviorProviders;
+ private ProviderDispatcher dispatcher;
+
+ @Inject
+ private IScopeProvider scopeProvider;
+
+ public DiagramTypeProvider() {
+ super();
+
+ Injector injector = RoomUiModule.getInjector();
+ injector.injectMembers(this);
+
+ dispatcher = new ProviderDispatcher(this);
+ setFeatureProvider(dispatcher.getFeatureProvider());
+
+// IEclipsePreferences node = new DefaultScope().getNode(GraphitiPlugin.PLUGIN_ID);
+// if (node!=null)
+// node.putBoolean(GFPreferences.RECURSIVE_CHECK_FOR_UPDATE_ACTIVE, true);
+ }
+
+ @Override
+ public IToolBehaviorProvider[] getAvailableToolBehaviorProviders() {
+ if (toolBehaviorProviders == null) {
+ toolBehaviorProviders =
+ new IToolBehaviorProvider[] {
+ dispatcher.getToolBehaviorProvider() };
+ }
+ return toolBehaviorProviders;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.graphiti.dt.AbstractDiagramTypeProvider#isAutoUpdateAtStartup()
+ */
+ @Override
+ public boolean isAutoUpdateAtStartup() {
+ return USE_AUTO_UPDATE;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.graphiti.dt.AbstractDiagramTypeProvider#isAutoUpdateAtReset()
+ */
+ @Override
+ public boolean isAutoUpdateAtReset() {
+ return USE_AUTO_UPDATE;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.graphiti.dt.AbstractDiagramTypeProvider#isAutoUpdateAtRuntime()
+ */
+ @Override
+ public boolean isAutoUpdateAtRuntime() {
+ return USE_AUTO_UPDATE;
+ }
+
+ public IScopeProvider getScopeProvider() {
+ return scopeProvider;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/ImageProvider.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/ImageProvider.java
index b4dd0c63a..32fd5e47d 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/ImageProvider.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/ImageProvider.java
@@ -1,38 +1,38 @@
-/*******************************************************************************
- * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.structure;
-
-import org.eclipse.graphiti.ui.platform.AbstractImageProvider;
-
-public class ImageProvider extends AbstractImageProvider {
-
- // The prefix for all identifiers of this image provider
- protected static final String PREFIX = "org.eclipse.etrice.ui.structure.";
-
- // The image identifier for an EReference.
- public static final String IMG_PORT = PREFIX + "port";
- public static final String IMG_SPP = PREFIX + "spp";
- public static final String IMG_REF = PREFIX + "ref";
- public static final String IMG_BINDING = PREFIX + "binding";
- public static final String IMG_LAYER_CONNECTION = PREFIX + "layer_connection";
-
- @Override
- protected void addAvailableImages() {
- addImageFilePath(IMG_PORT, "icons/Port.gif");
- addImageFilePath(IMG_SPP, "icons/SPP.gif");
- addImageFilePath(IMG_REF, "icons/ActorRef.gif");
- addImageFilePath(IMG_BINDING, "icons/Binding.gif");
- addImageFilePath(IMG_LAYER_CONNECTION, "icons/LayerConnection.gif");
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure;
+
+import org.eclipse.graphiti.ui.platform.AbstractImageProvider;
+
+public class ImageProvider extends AbstractImageProvider {
+
+ // The prefix for all identifiers of this image provider
+ protected static final String PREFIX = "org.eclipse.etrice.ui.structure.";
+
+ // The image identifier for an EReference.
+ public static final String IMG_PORT = PREFIX + "port";
+ public static final String IMG_SPP = PREFIX + "spp";
+ public static final String IMG_REF = PREFIX + "ref";
+ public static final String IMG_BINDING = PREFIX + "binding";
+ public static final String IMG_LAYER_CONNECTION = PREFIX + "layer_connection";
+
+ @Override
+ protected void addAvailableImages() {
+ addImageFilePath(IMG_PORT, "icons/Port.gif");
+ addImageFilePath(IMG_SPP, "icons/SPP.gif");
+ addImageFilePath(IMG_REF, "icons/ActorRef.gif");
+ addImageFilePath(IMG_BINDING, "icons/Binding.gif");
+ addImageFilePath(IMG_LAYER_CONNECTION, "icons/LayerConnection.gif");
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/ProviderDispatcher.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/ProviderDispatcher.java
index d62f20ed4..863d04f1b 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/ProviderDispatcher.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/ProviderDispatcher.java
@@ -1,490 +1,490 @@
-/*******************************************************************************
- * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.structure;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.etrice.core.naming.RoomFragmentProvider;
-import org.eclipse.etrice.core.room.ActorContainerRef;
-import org.eclipse.etrice.core.room.Binding;
-import org.eclipse.etrice.core.room.LayerConnection;
-import org.eclipse.etrice.core.room.Port;
-import org.eclipse.etrice.core.room.SPPRef;
-import org.eclipse.etrice.core.room.StructureClass;
-import org.eclipse.etrice.core.room.util.RoomSwitch;
-import org.eclipse.etrice.ui.common.support.AutoUpdateFeature;
-import org.eclipse.etrice.ui.common.support.RemoveBendpointsFeature;
-import org.eclipse.etrice.ui.structure.support.ActorContainerRefSupport;
-import org.eclipse.etrice.ui.structure.support.BindingSupport;
-import org.eclipse.etrice.ui.structure.support.DecorationProvider;
-import org.eclipse.etrice.ui.structure.support.LayerConnectionSupport;
-import org.eclipse.etrice.ui.structure.support.PortSupport;
-import org.eclipse.etrice.ui.structure.support.SPPSupport;
-import org.eclipse.etrice.ui.structure.support.StructureClassSupport;
-import org.eclipse.graphiti.dt.IDiagramTypeProvider;
-import org.eclipse.graphiti.features.IAddFeature;
-import org.eclipse.graphiti.features.ICreateConnectionFeature;
-import org.eclipse.graphiti.features.ICreateFeature;
-import org.eclipse.graphiti.features.IDeleteFeature;
-import org.eclipse.graphiti.features.IFeatureProvider;
-import org.eclipse.graphiti.features.ILayoutFeature;
-import org.eclipse.graphiti.features.IMoveShapeFeature;
-import org.eclipse.graphiti.features.IReconnectionFeature;
-import org.eclipse.graphiti.features.IRemoveFeature;
-import org.eclipse.graphiti.features.IResizeShapeFeature;
-import org.eclipse.graphiti.features.IUpdateFeature;
-import org.eclipse.graphiti.features.context.IAddContext;
-import org.eclipse.graphiti.features.context.ICustomContext;
-import org.eclipse.graphiti.features.context.IDeleteContext;
-import org.eclipse.graphiti.features.context.IDoubleClickContext;
-import org.eclipse.graphiti.features.context.ILayoutContext;
-import org.eclipse.graphiti.features.context.IMoveShapeContext;
-import org.eclipse.graphiti.features.context.IPictogramElementContext;
-import org.eclipse.graphiti.features.context.IReconnectionContext;
-import org.eclipse.graphiti.features.context.IRemoveContext;
-import org.eclipse.graphiti.features.context.IResizeShapeContext;
-import org.eclipse.graphiti.features.context.IUpdateContext;
-import org.eclipse.graphiti.features.custom.ICustomFeature;
-import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
-import org.eclipse.graphiti.mm.algorithms.styles.LineStyle;
-import org.eclipse.graphiti.mm.pictograms.Diagram;
-import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
-import org.eclipse.graphiti.mm.pictograms.PictogramElement;
-import org.eclipse.graphiti.mm.pictograms.Shape;
-import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider;
-import org.eclipse.graphiti.tb.IContextButtonPadData;
-import org.eclipse.graphiti.tb.IDecorator;
-import org.eclipse.graphiti.tb.IShapeSelectionInfo;
-import org.eclipse.graphiti.tb.IToolBehaviorProvider;
-import org.eclipse.graphiti.tb.ShapeSelectionInfoImpl;
-import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;
-import org.eclipse.graphiti.util.IColorConstant;
-
-public class ProviderDispatcher {
-
- private class FeatureProviderSwitch extends RoomSwitch<IFeatureProvider> {
- @Override
- public IFeatureProvider doSwitch(EObject theEObject) {
-
- if (theEObject==null)
- return null;
-
- if (theEObject.eIsProxy()) {
- if (RoomFragmentProvider.isPort(theEObject))
- return portSupport.getFeatureProvider();
- if (RoomFragmentProvider.isSPP(theEObject))
- return sppSupport.getFeatureProvider();
- if (RoomFragmentProvider.isStructureClass(theEObject))
- return structureClassSupport.getFeatureProvider();
- if (RoomFragmentProvider.isBinding(theEObject))
- return bindingSupport.getFeatureProvider();
- if (RoomFragmentProvider.isLayerConnection(theEObject))
- return layerConnectionSupport.getFeatureProvider();
- if (RoomFragmentProvider.isRef(theEObject))
- return actorContainerRefSupport.getFeatureProvider();
- }
- return super.doSwitch(theEObject);
- }
-
- @Override
- public IFeatureProvider caseStructureClass(StructureClass object) {
- return structureClassSupport.getFeatureProvider();
- }
-
- @Override
- public IFeatureProvider casePort(Port port) {
- return portSupport.getFeatureProvider();
- }
-
- @Override
- public IFeatureProvider caseSPPRef(SPPRef object) {
- return sppSupport.getFeatureProvider();
- }
- @Override
- public IFeatureProvider caseActorContainerRef(ActorContainerRef object) {
- return actorContainerRefSupport.getFeatureProvider();
- }
-
- @Override
- public IFeatureProvider caseBinding(Binding object) {
- return bindingSupport.getFeatureProvider();
- }
-
- @Override
- public IFeatureProvider caseLayerConnection(LayerConnection object) {
- return layerConnectionSupport.getFeatureProvider();
- }
-
- @Override
- public IFeatureProvider defaultCase(EObject object) {
- return null;
- }
-
- public ICreateFeature[] getCreateFeatures() {
- return concatAll(
- structureClassSupport.getFeatureProvider().getCreateFeatures(),
- portSupport.getFeatureProvider().getCreateFeatures(),
- sppSupport.getFeatureProvider().getCreateFeatures(),
- actorContainerRefSupport.getFeatureProvider().getCreateFeatures()
- );
- }
-
- public ICreateConnectionFeature[] getCreateConnectionFeatures() {
- return concatAll(
- bindingSupport.getFeatureProvider().getCreateConnectionFeatures(),
- layerConnectionSupport.getFeatureProvider().getCreateConnectionFeatures()
- );
- }
- }
-
- private class ToolBehaviorProviderSwitch extends RoomSwitch<IToolBehaviorProvider> {
- @Override
- public IToolBehaviorProvider doSwitch(EObject theEObject) {
-
- if (theEObject==null)
- return null;
-
- if (theEObject.eIsProxy()) {
- if (RoomFragmentProvider.isPort(theEObject))
- return portSupport.getToolBehaviorProvider();
- if (RoomFragmentProvider.isSPP(theEObject))
- return sppSupport.getToolBehaviorProvider();
- if (RoomFragmentProvider.isStructureClass(theEObject))
- return structureClassSupport.getToolBehaviorProvider();
- if (RoomFragmentProvider.isBinding(theEObject))
- return bindingSupport.getToolBehaviorProvider();
- if (RoomFragmentProvider.isLayerConnection(theEObject))
- return layerConnectionSupport.getToolBehaviorProvider();
- if (RoomFragmentProvider.isRef(theEObject))
- return actorContainerRefSupport.getToolBehaviorProvider();
- }
-
- return super.doSwitch(theEObject);
- }
-
- @Override
- public IToolBehaviorProvider caseStructureClass(StructureClass object) {
- return structureClassSupport.getToolBehaviorProvider();
- }
-
- @Override
- public IToolBehaviorProvider casePort(Port port) {
- return portSupport.getToolBehaviorProvider();
- }
-
- @Override
- public IToolBehaviorProvider caseSPPRef(SPPRef object) {
- return sppSupport.getToolBehaviorProvider();
- }
-
- @Override
- public IToolBehaviorProvider caseActorContainerRef(ActorContainerRef object) {
- return actorContainerRefSupport.getToolBehaviorProvider();
- }
-
- @Override
- public IToolBehaviorProvider caseBinding(Binding object) {
- return bindingSupport.getToolBehaviorProvider();
- }
-
- @Override
- public IToolBehaviorProvider caseLayerConnection(LayerConnection object) {
- return layerConnectionSupport.getToolBehaviorProvider();
- }
-
- @Override
- public IToolBehaviorProvider defaultCase(EObject object) {
- return null;
- }
-
- }
-
- private class DispatchingFeatureProvider extends DefaultFeatureProvider {
-
- public DispatchingFeatureProvider(IDiagramTypeProvider dtp) {
- super(dtp);
- }
-
- @Override
- public ICreateFeature[] getCreateFeatures() {
- return getAllCreateFeatures();
- }
-
- @Override
- public ICreateConnectionFeature[] getCreateConnectionFeatures() {
- return getAllCreateConnectionFeatures();
- }
-
- @Override
- public IAddFeature getAddFeature(IAddContext context) {
- IFeatureProvider fp = featureSwitch.doSwitch(((EObject) context.getNewObject()));
- if (fp==null)
- return super.getAddFeature(context);
- else
- return fp.getAddFeature(context);
- }
-
- @Override
- public ILayoutFeature getLayoutFeature(ILayoutContext context) {
- IFeatureProvider fp = featureSwitch.doSwitch(getBusinessObject(context));
- if (fp==null)
- return super.getLayoutFeature(context);
- else
- return fp.getLayoutFeature(context);
- }
-
- @Override
- public IMoveShapeFeature getMoveShapeFeature(IMoveShapeContext context) {
- IFeatureProvider fp = featureSwitch.doSwitch(getBusinessObject(context));
- if (fp==null)
- return super.getMoveShapeFeature(context);
- else
- return fp.getMoveShapeFeature(context);
- }
-
- @Override
- public IResizeShapeFeature getResizeShapeFeature(IResizeShapeContext context) {
- IFeatureProvider fp = featureSwitch.doSwitch(getBusinessObject(context));
- if (fp==null)
- return super.getResizeShapeFeature(context);
- else
- return fp.getResizeShapeFeature(context);
- }
-
- @Override
- public IUpdateFeature getUpdateFeature(IUpdateContext context) {
- if (context.getPictogramElement() instanceof Diagram)
- return new AutoUpdateFeature(this);
-
- IFeatureProvider fp = featureSwitch.doSwitch(getBusinessObject(context));
- if (fp!=null)
- return fp.getUpdateFeature(context);
- else
- return super.getUpdateFeature(context);
- }
-
- @Override
- public IReconnectionFeature getReconnectionFeature(IReconnectionContext context) {
- IFeatureProvider fp = getFeatureProvider(context);
- if (fp!=null)
- return fp.getReconnectionFeature(context);
- else
- return super.getReconnectionFeature(context);
- }
-
- @Override
- public IDeleteFeature getDeleteFeature(IDeleteContext context) {
- IFeatureProvider fp = featureSwitch.doSwitch(getBusinessObject(context));
- if (fp!=null)
- return fp.getDeleteFeature(context);
- else
- return super.getDeleteFeature(context);
- }
-
- @Override
- public IRemoveFeature getRemoveFeature(IRemoveContext context) {
- IFeatureProvider fp = featureSwitch.doSwitch(getBusinessObject(context));
- if (fp!=null)
- return fp.getRemoveFeature(context);
- else
- return super.getRemoveFeature(context);
- }
-
- @Override
- public ICustomFeature[] getCustomFeatures(ICustomContext context) {
- ArrayList<ICustomFeature> result = new ArrayList<ICustomFeature>();
-
- ICustomFeature[] custom;
- IFeatureProvider fp = featureSwitch.doSwitch(getBusinessObject(context));
- if (fp!=null)
- custom = fp.getCustomFeatures(context);
- else
- custom = super.getCustomFeatures(context);
-
- for (ICustomFeature cust : custom) {
- result.add(cust);
- }
-
- boolean allFreeForm = true;
- PictogramElement[] pes = context.getPictogramElements();
- for (PictogramElement pe : pes) {
- if (!(pe instanceof FreeFormConnection))
- allFreeForm = false;
- }
- if (allFreeForm)
- result.add(new RemoveBendpointsFeature(fp));
-
- ICustomFeature features[] = new ICustomFeature[result.size()];
- return result.toArray(features);
- }
-
- private EObject getBusinessObject(IPictogramElementContext context) {
- PictogramElement pictogramElement = context.getPictogramElement();
- EObject bo = (EObject) getBusinessObjectForPictogramElement(pictogramElement);
- return bo;
- }
-
- private EObject getBusinessObject(ICustomContext context) {
- PictogramElement[] pes = context.getPictogramElements();
- if (pes.length>0) {
- EObject bo = (EObject) getBusinessObjectForPictogramElement(pes[0]);
- return bo;
- }
- return null;
- }
-
- private IFeatureProvider getFeatureProvider(IReconnectionContext context) {
- return featureSwitch.doSwitch((EObject) getBusinessObjectForPictogramElement(context.getConnection()));
- }
- }
-
- private class DispatchingToolBehaviorProvider extends DefaultToolBehaviorProvider {
-
- public DispatchingToolBehaviorProvider(IDiagramTypeProvider diagramTypeProvider) {
- super(diagramTypeProvider);
- }
-
- @Override
- public IDecorator[] getDecorators(PictogramElement pe) {
- return DecorationProvider.getDecorators(pe);
- }
-
- @Override
- public GraphicsAlgorithm[] getClickArea(PictogramElement pe) {
- IToolBehaviorProvider bp = getToolBehaviorProvider(pe);
- if (bp==null)
- return super.getClickArea(pe);
- else
- return bp.getClickArea(pe);
- }
-
- @Override
- public GraphicsAlgorithm getSelectionBorder(PictogramElement pe) {
- IToolBehaviorProvider bp = getToolBehaviorProvider(pe);
- if (bp==null)
- return super.getSelectionBorder(pe);
- else
- return bp.getSelectionBorder(pe);
- }
-
- @Override
- public ICustomFeature getDoubleClickFeature(IDoubleClickContext context) {
- IToolBehaviorProvider bp = getToolBehaviorProvider(context.getPictogramElements()[0]);
- if (bp==null)
- return super.getDoubleClickFeature(context);
- else
- return bp.getDoubleClickFeature(context);
- }
-
- protected IToolBehaviorProvider getToolBehaviorProvider(PictogramElement pe) {
- IFeatureProvider fp = getFeatureProvider();
- EObject bo = (EObject) fp.getBusinessObjectForPictogramElement(pe);
- if (bo==null)
- return null;
-
- IToolBehaviorProvider bp = behaviorSwitch.doSwitch(bo);
- return bp;
- }
-
- @Override
- public IContextButtonPadData getContextButtonPad(IPictogramElementContext context) {
- IToolBehaviorProvider bp = getToolBehaviorProvider(context.getPictogramElement());
- if (bp==null)
- return super.getContextButtonPad(context);
- else
- return bp.getContextButtonPad(context);
- }
-
- @Override
- public Object getToolTip(GraphicsAlgorithm context) {
- IToolBehaviorProvider bp = getToolBehaviorProvider(context.getPictogramElement());
- if (bp==null)
- return super.getToolTip(context);
- else
- return bp.getToolTip(context);
- }
-
- public IShapeSelectionInfo getSelectionInfoForShape(Shape shape) {
- IShapeSelectionInfo ssi = new ShapeSelectionInfoImpl();
- ssi.setColor(IColorConstant.SHAPE_SELECTION_FG);
- ssi.setPrimarySelectionHandleForegroundColor(IColorConstant.HANDLE_FG);
- ssi.setPrimarySelectionHandleBackgroundColor(IColorConstant.HANDLE_BG);
- ssi.setLineStyle(LineStyle.DASH);
- ssi.setPrimarySelectionBackgroundColor(IColorConstant.LIGHT_ORANGE);
- ssi.setSecondarySelectionBackgroundColor(IColorConstant.LIGHT_ORANGE);
- return ssi;
- }
- }
-
- private StructureClassSupport structureClassSupport;
- private PortSupport portSupport;
- private SPPSupport sppSupport;
- private ActorContainerRefSupport actorContainerRefSupport;
- private BindingSupport bindingSupport;
- private LayerConnectionSupport layerConnectionSupport;
-
- private FeatureProviderSwitch featureSwitch;
- private ToolBehaviorProviderSwitch behaviorSwitch;
-
- private DispatchingFeatureProvider dispatchingFP;
- private DispatchingToolBehaviorProvider dispatchingBP;
-
-
- public ProviderDispatcher(IDiagramTypeProvider dtp) {
- // create those first before using them
- dispatchingFP = new DispatchingFeatureProvider(dtp);
- dispatchingBP = new DispatchingToolBehaviorProvider(dtp);
-
- structureClassSupport = new StructureClassSupport(dtp, dispatchingFP);
- portSupport = new PortSupport(dtp, dispatchingFP);
- sppSupport = new SPPSupport(dtp, dispatchingFP);
- actorContainerRefSupport = new ActorContainerRefSupport(dtp, dispatchingFP);
- bindingSupport = new BindingSupport(dtp, dispatchingFP);
- layerConnectionSupport = new LayerConnectionSupport(dtp, dispatchingFP);
-
- featureSwitch = new FeatureProviderSwitch();
- behaviorSwitch = new ToolBehaviorProviderSwitch();
- }
-
- public IFeatureProvider getFeatureProvider() {
- return dispatchingFP;
- }
-
- public IToolBehaviorProvider getToolBehaviorProvider() {
- return dispatchingBP;
- }
-
- private ICreateFeature[] getAllCreateFeatures() {
- return featureSwitch.getCreateFeatures();
- }
-
- private ICreateConnectionFeature[] getAllCreateConnectionFeatures() {
- return featureSwitch.getCreateConnectionFeatures();
- }
-
- private static <T> T[] concatAll(T[] first, T[]... rest) {
- int totalLength = first.length;
- for (T[] array : rest) {
- totalLength += array.length;
- }
- T[] result = Arrays.copyOf(first, totalLength);
- int offset = first.length;
- for (T[] array : rest) {
- System.arraycopy(array, 0, result, offset, array.length);
- offset += array.length;
- }
- return result;
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.naming.RoomFragmentProvider;
+import org.eclipse.etrice.core.room.ActorContainerRef;
+import org.eclipse.etrice.core.room.Binding;
+import org.eclipse.etrice.core.room.LayerConnection;
+import org.eclipse.etrice.core.room.Port;
+import org.eclipse.etrice.core.room.SPPRef;
+import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.core.room.util.RoomSwitch;
+import org.eclipse.etrice.ui.common.support.AutoUpdateFeature;
+import org.eclipse.etrice.ui.common.support.RemoveBendpointsFeature;
+import org.eclipse.etrice.ui.structure.support.ActorContainerRefSupport;
+import org.eclipse.etrice.ui.structure.support.BindingSupport;
+import org.eclipse.etrice.ui.structure.support.DecorationProvider;
+import org.eclipse.etrice.ui.structure.support.LayerConnectionSupport;
+import org.eclipse.etrice.ui.structure.support.PortSupport;
+import org.eclipse.etrice.ui.structure.support.SPPSupport;
+import org.eclipse.etrice.ui.structure.support.StructureClassSupport;
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.features.IAddFeature;
+import org.eclipse.graphiti.features.ICreateConnectionFeature;
+import org.eclipse.graphiti.features.ICreateFeature;
+import org.eclipse.graphiti.features.IDeleteFeature;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.ILayoutFeature;
+import org.eclipse.graphiti.features.IMoveShapeFeature;
+import org.eclipse.graphiti.features.IReconnectionFeature;
+import org.eclipse.graphiti.features.IRemoveFeature;
+import org.eclipse.graphiti.features.IResizeShapeFeature;
+import org.eclipse.graphiti.features.IUpdateFeature;
+import org.eclipse.graphiti.features.context.IAddContext;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.context.IDeleteContext;
+import org.eclipse.graphiti.features.context.IDoubleClickContext;
+import org.eclipse.graphiti.features.context.ILayoutContext;
+import org.eclipse.graphiti.features.context.IMoveShapeContext;
+import org.eclipse.graphiti.features.context.IPictogramElementContext;
+import org.eclipse.graphiti.features.context.IReconnectionContext;
+import org.eclipse.graphiti.features.context.IRemoveContext;
+import org.eclipse.graphiti.features.context.IResizeShapeContext;
+import org.eclipse.graphiti.features.context.IUpdateContext;
+import org.eclipse.graphiti.features.custom.ICustomFeature;
+import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.algorithms.styles.LineStyle;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider;
+import org.eclipse.graphiti.tb.IContextButtonPadData;
+import org.eclipse.graphiti.tb.IDecorator;
+import org.eclipse.graphiti.tb.IShapeSelectionInfo;
+import org.eclipse.graphiti.tb.IToolBehaviorProvider;
+import org.eclipse.graphiti.tb.ShapeSelectionInfoImpl;
+import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;
+import org.eclipse.graphiti.util.IColorConstant;
+
+public class ProviderDispatcher {
+
+ private class FeatureProviderSwitch extends RoomSwitch<IFeatureProvider> {
+ @Override
+ public IFeatureProvider doSwitch(EObject theEObject) {
+
+ if (theEObject==null)
+ return null;
+
+ if (theEObject.eIsProxy()) {
+ if (RoomFragmentProvider.isPort(theEObject))
+ return portSupport.getFeatureProvider();
+ if (RoomFragmentProvider.isSPP(theEObject))
+ return sppSupport.getFeatureProvider();
+ if (RoomFragmentProvider.isStructureClass(theEObject))
+ return structureClassSupport.getFeatureProvider();
+ if (RoomFragmentProvider.isBinding(theEObject))
+ return bindingSupport.getFeatureProvider();
+ if (RoomFragmentProvider.isLayerConnection(theEObject))
+ return layerConnectionSupport.getFeatureProvider();
+ if (RoomFragmentProvider.isRef(theEObject))
+ return actorContainerRefSupport.getFeatureProvider();
+ }
+ return super.doSwitch(theEObject);
+ }
+
+ @Override
+ public IFeatureProvider caseStructureClass(StructureClass object) {
+ return structureClassSupport.getFeatureProvider();
+ }
+
+ @Override
+ public IFeatureProvider casePort(Port port) {
+ return portSupport.getFeatureProvider();
+ }
+
+ @Override
+ public IFeatureProvider caseSPPRef(SPPRef object) {
+ return sppSupport.getFeatureProvider();
+ }
+ @Override
+ public IFeatureProvider caseActorContainerRef(ActorContainerRef object) {
+ return actorContainerRefSupport.getFeatureProvider();
+ }
+
+ @Override
+ public IFeatureProvider caseBinding(Binding object) {
+ return bindingSupport.getFeatureProvider();
+ }
+
+ @Override
+ public IFeatureProvider caseLayerConnection(LayerConnection object) {
+ return layerConnectionSupport.getFeatureProvider();
+ }
+
+ @Override
+ public IFeatureProvider defaultCase(EObject object) {
+ return null;
+ }
+
+ public ICreateFeature[] getCreateFeatures() {
+ return concatAll(
+ structureClassSupport.getFeatureProvider().getCreateFeatures(),
+ portSupport.getFeatureProvider().getCreateFeatures(),
+ sppSupport.getFeatureProvider().getCreateFeatures(),
+ actorContainerRefSupport.getFeatureProvider().getCreateFeatures()
+ );
+ }
+
+ public ICreateConnectionFeature[] getCreateConnectionFeatures() {
+ return concatAll(
+ bindingSupport.getFeatureProvider().getCreateConnectionFeatures(),
+ layerConnectionSupport.getFeatureProvider().getCreateConnectionFeatures()
+ );
+ }
+ }
+
+ private class ToolBehaviorProviderSwitch extends RoomSwitch<IToolBehaviorProvider> {
+ @Override
+ public IToolBehaviorProvider doSwitch(EObject theEObject) {
+
+ if (theEObject==null)
+ return null;
+
+ if (theEObject.eIsProxy()) {
+ if (RoomFragmentProvider.isPort(theEObject))
+ return portSupport.getToolBehaviorProvider();
+ if (RoomFragmentProvider.isSPP(theEObject))
+ return sppSupport.getToolBehaviorProvider();
+ if (RoomFragmentProvider.isStructureClass(theEObject))
+ return structureClassSupport.getToolBehaviorProvider();
+ if (RoomFragmentProvider.isBinding(theEObject))
+ return bindingSupport.getToolBehaviorProvider();
+ if (RoomFragmentProvider.isLayerConnection(theEObject))
+ return layerConnectionSupport.getToolBehaviorProvider();
+ if (RoomFragmentProvider.isRef(theEObject))
+ return actorContainerRefSupport.getToolBehaviorProvider();
+ }
+
+ return super.doSwitch(theEObject);
+ }
+
+ @Override
+ public IToolBehaviorProvider caseStructureClass(StructureClass object) {
+ return structureClassSupport.getToolBehaviorProvider();
+ }
+
+ @Override
+ public IToolBehaviorProvider casePort(Port port) {
+ return portSupport.getToolBehaviorProvider();
+ }
+
+ @Override
+ public IToolBehaviorProvider caseSPPRef(SPPRef object) {
+ return sppSupport.getToolBehaviorProvider();
+ }
+
+ @Override
+ public IToolBehaviorProvider caseActorContainerRef(ActorContainerRef object) {
+ return actorContainerRefSupport.getToolBehaviorProvider();
+ }
+
+ @Override
+ public IToolBehaviorProvider caseBinding(Binding object) {
+ return bindingSupport.getToolBehaviorProvider();
+ }
+
+ @Override
+ public IToolBehaviorProvider caseLayerConnection(LayerConnection object) {
+ return layerConnectionSupport.getToolBehaviorProvider();
+ }
+
+ @Override
+ public IToolBehaviorProvider defaultCase(EObject object) {
+ return null;
+ }
+
+ }
+
+ private class DispatchingFeatureProvider extends DefaultFeatureProvider {
+
+ public DispatchingFeatureProvider(IDiagramTypeProvider dtp) {
+ super(dtp);
+ }
+
+ @Override
+ public ICreateFeature[] getCreateFeatures() {
+ return getAllCreateFeatures();
+ }
+
+ @Override
+ public ICreateConnectionFeature[] getCreateConnectionFeatures() {
+ return getAllCreateConnectionFeatures();
+ }
+
+ @Override
+ public IAddFeature getAddFeature(IAddContext context) {
+ IFeatureProvider fp = featureSwitch.doSwitch(((EObject) context.getNewObject()));
+ if (fp==null)
+ return super.getAddFeature(context);
+ else
+ return fp.getAddFeature(context);
+ }
+
+ @Override
+ public ILayoutFeature getLayoutFeature(ILayoutContext context) {
+ IFeatureProvider fp = featureSwitch.doSwitch(getBusinessObject(context));
+ if (fp==null)
+ return super.getLayoutFeature(context);
+ else
+ return fp.getLayoutFeature(context);
+ }
+
+ @Override
+ public IMoveShapeFeature getMoveShapeFeature(IMoveShapeContext context) {
+ IFeatureProvider fp = featureSwitch.doSwitch(getBusinessObject(context));
+ if (fp==null)
+ return super.getMoveShapeFeature(context);
+ else
+ return fp.getMoveShapeFeature(context);
+ }
+
+ @Override
+ public IResizeShapeFeature getResizeShapeFeature(IResizeShapeContext context) {
+ IFeatureProvider fp = featureSwitch.doSwitch(getBusinessObject(context));
+ if (fp==null)
+ return super.getResizeShapeFeature(context);
+ else
+ return fp.getResizeShapeFeature(context);
+ }
+
+ @Override
+ public IUpdateFeature getUpdateFeature(IUpdateContext context) {
+ if (context.getPictogramElement() instanceof Diagram)
+ return new AutoUpdateFeature(this);
+
+ IFeatureProvider fp = featureSwitch.doSwitch(getBusinessObject(context));
+ if (fp!=null)
+ return fp.getUpdateFeature(context);
+ else
+ return super.getUpdateFeature(context);
+ }
+
+ @Override
+ public IReconnectionFeature getReconnectionFeature(IReconnectionContext context) {
+ IFeatureProvider fp = getFeatureProvider(context);
+ if (fp!=null)
+ return fp.getReconnectionFeature(context);
+ else
+ return super.getReconnectionFeature(context);
+ }
+
+ @Override
+ public IDeleteFeature getDeleteFeature(IDeleteContext context) {
+ IFeatureProvider fp = featureSwitch.doSwitch(getBusinessObject(context));
+ if (fp!=null)
+ return fp.getDeleteFeature(context);
+ else
+ return super.getDeleteFeature(context);
+ }
+
+ @Override
+ public IRemoveFeature getRemoveFeature(IRemoveContext context) {
+ IFeatureProvider fp = featureSwitch.doSwitch(getBusinessObject(context));
+ if (fp!=null)
+ return fp.getRemoveFeature(context);
+ else
+ return super.getRemoveFeature(context);
+ }
+
+ @Override
+ public ICustomFeature[] getCustomFeatures(ICustomContext context) {
+ ArrayList<ICustomFeature> result = new ArrayList<ICustomFeature>();
+
+ ICustomFeature[] custom;
+ IFeatureProvider fp = featureSwitch.doSwitch(getBusinessObject(context));
+ if (fp!=null)
+ custom = fp.getCustomFeatures(context);
+ else
+ custom = super.getCustomFeatures(context);
+
+ for (ICustomFeature cust : custom) {
+ result.add(cust);
+ }
+
+ boolean allFreeForm = true;
+ PictogramElement[] pes = context.getPictogramElements();
+ for (PictogramElement pe : pes) {
+ if (!(pe instanceof FreeFormConnection))
+ allFreeForm = false;
+ }
+ if (allFreeForm)
+ result.add(new RemoveBendpointsFeature(fp));
+
+ ICustomFeature features[] = new ICustomFeature[result.size()];
+ return result.toArray(features);
+ }
+
+ private EObject getBusinessObject(IPictogramElementContext context) {
+ PictogramElement pictogramElement = context.getPictogramElement();
+ EObject bo = (EObject) getBusinessObjectForPictogramElement(pictogramElement);
+ return bo;
+ }
+
+ private EObject getBusinessObject(ICustomContext context) {
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes.length>0) {
+ EObject bo = (EObject) getBusinessObjectForPictogramElement(pes[0]);
+ return bo;
+ }
+ return null;
+ }
+
+ private IFeatureProvider getFeatureProvider(IReconnectionContext context) {
+ return featureSwitch.doSwitch((EObject) getBusinessObjectForPictogramElement(context.getConnection()));
+ }
+ }
+
+ private class DispatchingToolBehaviorProvider extends DefaultToolBehaviorProvider {
+
+ public DispatchingToolBehaviorProvider(IDiagramTypeProvider diagramTypeProvider) {
+ super(diagramTypeProvider);
+ }
+
+ @Override
+ public IDecorator[] getDecorators(PictogramElement pe) {
+ return DecorationProvider.getDecorators(pe);
+ }
+
+ @Override
+ public GraphicsAlgorithm[] getClickArea(PictogramElement pe) {
+ IToolBehaviorProvider bp = getToolBehaviorProvider(pe);
+ if (bp==null)
+ return super.getClickArea(pe);
+ else
+ return bp.getClickArea(pe);
+ }
+
+ @Override
+ public GraphicsAlgorithm getSelectionBorder(PictogramElement pe) {
+ IToolBehaviorProvider bp = getToolBehaviorProvider(pe);
+ if (bp==null)
+ return super.getSelectionBorder(pe);
+ else
+ return bp.getSelectionBorder(pe);
+ }
+
+ @Override
+ public ICustomFeature getDoubleClickFeature(IDoubleClickContext context) {
+ IToolBehaviorProvider bp = getToolBehaviorProvider(context.getPictogramElements()[0]);
+ if (bp==null)
+ return super.getDoubleClickFeature(context);
+ else
+ return bp.getDoubleClickFeature(context);
+ }
+
+ protected IToolBehaviorProvider getToolBehaviorProvider(PictogramElement pe) {
+ IFeatureProvider fp = getFeatureProvider();
+ EObject bo = (EObject) fp.getBusinessObjectForPictogramElement(pe);
+ if (bo==null)
+ return null;
+
+ IToolBehaviorProvider bp = behaviorSwitch.doSwitch(bo);
+ return bp;
+ }
+
+ @Override
+ public IContextButtonPadData getContextButtonPad(IPictogramElementContext context) {
+ IToolBehaviorProvider bp = getToolBehaviorProvider(context.getPictogramElement());
+ if (bp==null)
+ return super.getContextButtonPad(context);
+ else
+ return bp.getContextButtonPad(context);
+ }
+
+ @Override
+ public Object getToolTip(GraphicsAlgorithm context) {
+ IToolBehaviorProvider bp = getToolBehaviorProvider(context.getPictogramElement());
+ if (bp==null)
+ return super.getToolTip(context);
+ else
+ return bp.getToolTip(context);
+ }
+
+ public IShapeSelectionInfo getSelectionInfoForShape(Shape shape) {
+ IShapeSelectionInfo ssi = new ShapeSelectionInfoImpl();
+ ssi.setColor(IColorConstant.SHAPE_SELECTION_FG);
+ ssi.setPrimarySelectionHandleForegroundColor(IColorConstant.HANDLE_FG);
+ ssi.setPrimarySelectionHandleBackgroundColor(IColorConstant.HANDLE_BG);
+ ssi.setLineStyle(LineStyle.DASH);
+ ssi.setPrimarySelectionBackgroundColor(IColorConstant.LIGHT_ORANGE);
+ ssi.setSecondarySelectionBackgroundColor(IColorConstant.LIGHT_ORANGE);
+ return ssi;
+ }
+ }
+
+ private StructureClassSupport structureClassSupport;
+ private PortSupport portSupport;
+ private SPPSupport sppSupport;
+ private ActorContainerRefSupport actorContainerRefSupport;
+ private BindingSupport bindingSupport;
+ private LayerConnectionSupport layerConnectionSupport;
+
+ private FeatureProviderSwitch featureSwitch;
+ private ToolBehaviorProviderSwitch behaviorSwitch;
+
+ private DispatchingFeatureProvider dispatchingFP;
+ private DispatchingToolBehaviorProvider dispatchingBP;
+
+
+ public ProviderDispatcher(IDiagramTypeProvider dtp) {
+ // create those first before using them
+ dispatchingFP = new DispatchingFeatureProvider(dtp);
+ dispatchingBP = new DispatchingToolBehaviorProvider(dtp);
+
+ structureClassSupport = new StructureClassSupport(dtp, dispatchingFP);
+ portSupport = new PortSupport(dtp, dispatchingFP);
+ sppSupport = new SPPSupport(dtp, dispatchingFP);
+ actorContainerRefSupport = new ActorContainerRefSupport(dtp, dispatchingFP);
+ bindingSupport = new BindingSupport(dtp, dispatchingFP);
+ layerConnectionSupport = new LayerConnectionSupport(dtp, dispatchingFP);
+
+ featureSwitch = new FeatureProviderSwitch();
+ behaviorSwitch = new ToolBehaviorProviderSwitch();
+ }
+
+ public IFeatureProvider getFeatureProvider() {
+ return dispatchingFP;
+ }
+
+ public IToolBehaviorProvider getToolBehaviorProvider() {
+ return dispatchingBP;
+ }
+
+ private ICreateFeature[] getAllCreateFeatures() {
+ return featureSwitch.getCreateFeatures();
+ }
+
+ private ICreateConnectionFeature[] getAllCreateConnectionFeatures() {
+ return featureSwitch.getCreateConnectionFeatures();
+ }
+
+ private static <T> T[] concatAll(T[] first, T[]... rest) {
+ int totalLength = first.length;
+ for (T[] array : rest) {
+ totalLength += array.length;
+ }
+ T[] result = Arrays.copyOf(first, totalLength);
+ int offset = first.length;
+ for (T[] array : rest) {
+ System.arraycopy(array, 0, result, offset, array.length);
+ offset += array.length;
+ }
+ return result;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/commands/PopulateDiagramCommand.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/commands/PopulateDiagramCommand.java
index 0e80b8788..8c7dc82d5 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/commands/PopulateDiagramCommand.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/commands/PopulateDiagramCommand.java
@@ -1,118 +1,118 @@
-/*******************************************************************************
- * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.structure.commands;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.etrice.core.room.ActorClass;
-import org.eclipse.etrice.core.room.ActorContainerClass;
-import org.eclipse.etrice.core.room.Binding;
-import org.eclipse.etrice.core.room.InterfaceItem;
-import org.eclipse.etrice.core.room.LayerConnection;
-import org.eclipse.etrice.core.room.LogicalSystem;
-import org.eclipse.etrice.core.room.StructureClass;
-import org.eclipse.etrice.core.room.SubSystemClass;
-import org.eclipse.etrice.ui.structure.DiagramTypeProvider;
-import org.eclipse.etrice.ui.structure.support.StructureClassSupport;
-import org.eclipse.etrice.ui.structure.support.SupportUtil;
-import org.eclipse.graphiti.dt.IDiagramTypeProvider;
-import org.eclipse.graphiti.features.IAddFeature;
-import org.eclipse.graphiti.features.IFeatureProvider;
-import org.eclipse.graphiti.features.context.impl.AddContext;
-import org.eclipse.graphiti.mm.pictograms.Anchor;
-import org.eclipse.graphiti.mm.pictograms.ContainerShape;
-import org.eclipse.graphiti.mm.pictograms.Diagram;
-import org.eclipse.graphiti.ui.services.GraphitiUi;
-
-public class PopulateDiagramCommand extends RecordingCommand {
-
- private StructureClass sc;
- private Diagram diagram;
-
- public PopulateDiagramCommand(Diagram diag, StructureClass sc, TransactionalEditingDomain domain) {
- super(domain);
- this.diagram = diag;
- this.sc = sc;
- }
-
- @Override
- protected void doExecute() {
- IDiagramTypeProvider dtp = GraphitiUi.getExtensionManager().createDiagramTypeProvider(diagram, DiagramTypeProvider.PROVIDER_ID); //$NON-NLS-1$
- IFeatureProvider featureProvider = dtp.getFeatureProvider();
-
- AddContext addContext = new AddContext();
- addContext.setNewObject(sc);
- addContext.setTargetContainer(diagram);
- addContext.setX(StructureClassSupport.MARGIN);
- addContext.setY(StructureClassSupport.MARGIN);
-
- HashMap<String, Anchor> ifitem2anchor = new HashMap<String, Anchor>();
-
- IAddFeature addFeature = featureProvider.getAddFeature(addContext);
- if (addFeature!=null && addFeature.canAdd(addContext)) {
- ContainerShape acShape = (ContainerShape) addFeature.add(addContext);
-
- int width = acShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0).getWidth();
-
- if (sc instanceof ActorClass) {
- List<InterfaceItem> items = new ArrayList<InterfaceItem>();
- items.addAll(((ActorClass) sc).getIfPorts());
- items.addAll(((ActorClass) sc).getIfSPPs());
- SupportUtil.addInterfaceItems(items, 0, acShape, width, featureProvider, ifitem2anchor);
-
- SupportUtil.addInterfaceItems(((ActorClass)sc).getIntPorts(), 3*StructureClassSupport.MARGIN, acShape, width, featureProvider, ifitem2anchor);
- }
- else if (sc instanceof SubSystemClass) {
- List<InterfaceItem> items = new ArrayList<InterfaceItem>();
- items.addAll(((SubSystemClass) sc).getRelayPorts());
- items.addAll(((SubSystemClass) sc).getIfSPPs());
- SupportUtil.addInterfaceItems(items, 0, acShape, width, featureProvider, ifitem2anchor);
- }
-
- // actor container references
- if (sc instanceof ActorContainerClass) {
- ActorContainerClass acc = (ActorContainerClass) sc;
- SupportUtil.addRefItems(acc.getActorRefs(), acShape, width, featureProvider, ifitem2anchor);
- }
- else if (sc instanceof LogicalSystem) {
- LogicalSystem sys = (LogicalSystem) sc;
- SupportUtil.addRefItems(sys.getSubSystems(), acShape, width, featureProvider, ifitem2anchor);
- }
-
- // base class items
- if (sc instanceof ActorClass) {
- ActorClass base = ((ActorClass) sc).getBase();
-
- // add inherited ports and refs and bindings (and preserve layout)
- if (base!=null)
- StructureClassSupport.addInheritedItems(base, acShape, ifitem2anchor, featureProvider);
- }
-
- // layer connections
- for (LayerConnection lc : sc.getConnections()) {
- SupportUtil.addLayerConnection(lc, featureProvider, ifitem2anchor);
- }
-
- // bindings
- for (Binding bind : sc.getBindings()) {
- SupportUtil.addBinding(bind, featureProvider, ifitem2anchor);
- }
- }
-
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.commands;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.ActorContainerClass;
+import org.eclipse.etrice.core.room.Binding;
+import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.etrice.core.room.LayerConnection;
+import org.eclipse.etrice.core.room.LogicalSystem;
+import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.core.room.SubSystemClass;
+import org.eclipse.etrice.ui.structure.DiagramTypeProvider;
+import org.eclipse.etrice.ui.structure.support.StructureClassSupport;
+import org.eclipse.etrice.ui.structure.support.SupportUtil;
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.features.IAddFeature;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.impl.AddContext;
+import org.eclipse.graphiti.mm.pictograms.Anchor;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.ui.services.GraphitiUi;
+
+public class PopulateDiagramCommand extends RecordingCommand {
+
+ private StructureClass sc;
+ private Diagram diagram;
+
+ public PopulateDiagramCommand(Diagram diag, StructureClass sc, TransactionalEditingDomain domain) {
+ super(domain);
+ this.diagram = diag;
+ this.sc = sc;
+ }
+
+ @Override
+ protected void doExecute() {
+ IDiagramTypeProvider dtp = GraphitiUi.getExtensionManager().createDiagramTypeProvider(diagram, DiagramTypeProvider.PROVIDER_ID); //$NON-NLS-1$
+ IFeatureProvider featureProvider = dtp.getFeatureProvider();
+
+ AddContext addContext = new AddContext();
+ addContext.setNewObject(sc);
+ addContext.setTargetContainer(diagram);
+ addContext.setX(StructureClassSupport.MARGIN);
+ addContext.setY(StructureClassSupport.MARGIN);
+
+ HashMap<String, Anchor> ifitem2anchor = new HashMap<String, Anchor>();
+
+ IAddFeature addFeature = featureProvider.getAddFeature(addContext);
+ if (addFeature!=null && addFeature.canAdd(addContext)) {
+ ContainerShape acShape = (ContainerShape) addFeature.add(addContext);
+
+ int width = acShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0).getWidth();
+
+ if (sc instanceof ActorClass) {
+ List<InterfaceItem> items = new ArrayList<InterfaceItem>();
+ items.addAll(((ActorClass) sc).getIfPorts());
+ items.addAll(((ActorClass) sc).getIfSPPs());
+ SupportUtil.addInterfaceItems(items, 0, acShape, width, featureProvider, ifitem2anchor);
+
+ SupportUtil.addInterfaceItems(((ActorClass)sc).getIntPorts(), 3*StructureClassSupport.MARGIN, acShape, width, featureProvider, ifitem2anchor);
+ }
+ else if (sc instanceof SubSystemClass) {
+ List<InterfaceItem> items = new ArrayList<InterfaceItem>();
+ items.addAll(((SubSystemClass) sc).getRelayPorts());
+ items.addAll(((SubSystemClass) sc).getIfSPPs());
+ SupportUtil.addInterfaceItems(items, 0, acShape, width, featureProvider, ifitem2anchor);
+ }
+
+ // actor container references
+ if (sc instanceof ActorContainerClass) {
+ ActorContainerClass acc = (ActorContainerClass) sc;
+ SupportUtil.addRefItems(acc.getActorRefs(), acShape, width, featureProvider, ifitem2anchor);
+ }
+ else if (sc instanceof LogicalSystem) {
+ LogicalSystem sys = (LogicalSystem) sc;
+ SupportUtil.addRefItems(sys.getSubSystems(), acShape, width, featureProvider, ifitem2anchor);
+ }
+
+ // base class items
+ if (sc instanceof ActorClass) {
+ ActorClass base = ((ActorClass) sc).getBase();
+
+ // add inherited ports and refs and bindings (and preserve layout)
+ if (base!=null)
+ StructureClassSupport.addInheritedItems(base, acShape, ifitem2anchor, featureProvider);
+ }
+
+ // layer connections
+ for (LayerConnection lc : sc.getConnections()) {
+ SupportUtil.addLayerConnection(lc, featureProvider, ifitem2anchor);
+ }
+
+ // bindings
+ for (Binding bind : sc.getBindings()) {
+ SupportUtil.addBinding(bind, featureProvider, ifitem2anchor);
+ }
+ }
+
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/ActorContainerRefPropertyDialog.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/ActorContainerRefPropertyDialog.java
index 4fe506547..c6025fbbe 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/ActorContainerRefPropertyDialog.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/ActorContainerRefPropertyDialog.java
@@ -1,224 +1,224 @@
-/*******************************************************************************
- * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.structure.dialogs;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-
-import org.eclipse.core.databinding.DataBindingContext;
-import org.eclipse.core.databinding.validation.IValidator;
-import org.eclipse.core.databinding.validation.ValidationStatus;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.etrice.core.room.ActorClass;
-import org.eclipse.etrice.core.room.ActorContainerClass;
-import org.eclipse.etrice.core.room.ActorContainerRef;
-import org.eclipse.etrice.core.room.ActorRef;
-import org.eclipse.etrice.core.room.LogicalSystem;
-import org.eclipse.etrice.core.room.Port;
-import org.eclipse.etrice.core.room.RoomPackage;
-import org.eclipse.etrice.core.room.StructureClass;
-import org.eclipse.etrice.core.room.SubSystemClass;
-import org.eclipse.etrice.core.room.SubSystemRef;
-import org.eclipse.etrice.core.validation.ValidationUtil;
-import org.eclipse.etrice.ui.common.dialogs.AbstractPropertyDialog;
-import org.eclipse.etrice.ui.structure.Activator;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.forms.IManagedForm;
-import org.eclipse.xtext.resource.IEObjectDescription;
-import org.eclipse.xtext.scoping.IScope;
-
-public class ActorContainerRefPropertyDialog extends AbstractPropertyDialog {
-
- class NameValidator implements IValidator {
-
- @Override
- public IStatus validate(Object value) {
- if (value instanceof String) {
- String name = (String) value;
-
- if (name.isEmpty())
- return ValidationStatus.error("name must not be empty");
-
- // TODOHRR: check valid identifier
- // TODOHRR: use ValidationUtil
-
- if (sc instanceof ActorClass) {
- if (nameExists((ActorClass) sc, name))
- return ValidationStatus.error("name already exists");
- }
- else if (sc instanceof SubSystemClass) {
- SubSystemClass ssc = (SubSystemClass) sc;
- for (ActorRef ar : ssc.getActorRefs()) {
- if (ar!=ref && ar.getName().equals(name))
- return ValidationStatus.error("name already exists");
- }
- }
- else if (sc instanceof LogicalSystem) {
- LogicalSystem ssc = (LogicalSystem) sc;
- for (SubSystemRef ssr : ssc.getSubSystems()) {
- if (ssr!=ref && ssr.getName().equals(name))
- return ValidationStatus.error("name already exists");
- }
- }
- else {
- assert(false): "unexpected type";
- }
- return Status.OK_STATUS;
- }
- return Status.OK_STATUS;
- }
-
- private boolean nameExists(ActorClass ac, String name) {
- for (ActorRef ar : ac.getActorRefs()) {
- if (ar!=ref && ar.getName().equals(name))
- return true;
- }
- if (ac.getBase()!=null)
- return nameExists(ac.getBase(), name);
-
- return false;
- }
- }
-
- class ProtocolValidator implements IValidator {
-
- @Override
- public IStatus validate(Object value) {
- if (value==null)
- return ValidationStatus.error("select a class");
-
- return Status.OK_STATUS;
- }
- }
-
- class SizeValidator implements IValidator {
-
- public SizeValidator() {
- }
-
- @Override
- public IStatus validate(Object value) {
- if (value instanceof Integer) {
- int m = (Integer) value;
- if (m<=0)
- return ValidationStatus.error("multiplicity must not be positive");
- }
- return Status.OK_STATUS;
- }
- }
-
- private ActorContainerRef ref;
- private IScope scope;
- private StructureClass sc;
- private boolean newRef;
-
- public ActorContainerRefPropertyDialog(Shell shell, ActorContainerRef ref, IScope scope, StructureClass sc, boolean newRef) {
- super(shell, "Edit Reference");
- this.ref = ref;
- this.scope = scope;
- this.sc = sc;
- this.newRef = newRef;
- }
-
- @Override
- protected void initializeBounds() {
- super.initializeBounds();
- Point size = getShell().getSize();
- getShell().setSize((int)(size.x*1.2), size.y);
- }
-
- @Override
- protected void createContent(IManagedForm mform, Composite body,
- DataBindingContext bindingContext) {
-
- NameValidator nv = new NameValidator();
- ProtocolValidator pv = new ProtocolValidator();
-
- boolean refIsActor = sc instanceof ActorContainerClass;
- boolean containerIsActor = sc instanceof ActorClass;
-
- ArrayList<IEObjectDescription> actors = new ArrayList<IEObjectDescription>();
- Iterator<IEObjectDescription> it = scope.getAllElements().iterator();
- while (it.hasNext()) {
- IEObjectDescription desc = it.next();
- EObject obj = desc.getEObjectOrProxy();
- if (refIsActor && obj instanceof ActorClass) {
- if (containerIsActor) {
- if (!ValidationUtil.isReferencing((ActorClass)obj, (ActorClass)sc))
- actors.add(desc);
- }
- else
- actors.add(desc);
- }
- else if (!refIsActor && obj instanceof SubSystemClass) {
- if (obj!=sc)
- actors.add(desc);
- }
- }
-
- Text name = createText(body, "&Name:", ref, RoomPackage.eINSTANCE.getActorContainerRef_Name(), nv);
- Combo refClass = refIsActor?
- createComboUsingDesc(body, "Actor &Class:", ref, ActorClass.class, RoomPackage.eINSTANCE.getActorRef_Type(), actors, RoomPackage.eINSTANCE.getRoomClass_Name(), pv)
- : createComboUsingDesc(body, "SubSystem &Class:", ref, SubSystemClass.class, RoomPackage.eINSTANCE.getSubSystemRef_Type(), actors, RoomPackage.eINSTANCE.getRoomClass_Name(), pv);
-
- createDecorator(name, "invalid name");
- createDecorator(refClass, "no class selected");
-
- if (!newRef) {
- refClass.setEnabled(false);
- createInfoDecorator(refClass, "class fixed for exisiting ref");
- }
-
- if (ref instanceof ActorRef) {
- Text size = createText(body, "&Multiplicity", ref, RoomPackage.eINSTANCE.getActorRef_Size(), new SizeValidator());
- if (hasInterfacePortWithMultiplicityAny(((ActorRef) ref).getType())) {
- size.setEnabled(false);
- createInfoDecorator(size, "size fixed since actor has interface ports with multiplicity *");
- }
- else {
- createDecorator(size, "multiplicity");
- }
- }
-
- name.selectAll();
- name.setFocus();
- }
-
- /**
- * @param ac
- * @return
- */
- private boolean hasInterfacePortWithMultiplicityAny(ActorClass ac) {
- if (ac==null)
- return false;
-
- for (Port p : ac.getIfPorts()) {
- if (p.getMultiplicity()<0)
- return true;
- }
- return false;
- }
-
- @Override
- protected Image getImage() {
- return Activator.getImage("icons/Structure.gif");
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.dialogs;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.core.databinding.validation.ValidationStatus;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.ActorContainerClass;
+import org.eclipse.etrice.core.room.ActorContainerRef;
+import org.eclipse.etrice.core.room.ActorRef;
+import org.eclipse.etrice.core.room.LogicalSystem;
+import org.eclipse.etrice.core.room.Port;
+import org.eclipse.etrice.core.room.RoomPackage;
+import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.core.room.SubSystemClass;
+import org.eclipse.etrice.core.room.SubSystemRef;
+import org.eclipse.etrice.core.validation.ValidationUtil;
+import org.eclipse.etrice.ui.common.dialogs.AbstractPropertyDialog;
+import org.eclipse.etrice.ui.structure.Activator;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.xtext.resource.IEObjectDescription;
+import org.eclipse.xtext.scoping.IScope;
+
+public class ActorContainerRefPropertyDialog extends AbstractPropertyDialog {
+
+ class NameValidator implements IValidator {
+
+ @Override
+ public IStatus validate(Object value) {
+ if (value instanceof String) {
+ String name = (String) value;
+
+ if (name.isEmpty())
+ return ValidationStatus.error("name must not be empty");
+
+ // TODOHRR: check valid identifier
+ // TODOHRR: use ValidationUtil
+
+ if (sc instanceof ActorClass) {
+ if (nameExists((ActorClass) sc, name))
+ return ValidationStatus.error("name already exists");
+ }
+ else if (sc instanceof SubSystemClass) {
+ SubSystemClass ssc = (SubSystemClass) sc;
+ for (ActorRef ar : ssc.getActorRefs()) {
+ if (ar!=ref && ar.getName().equals(name))
+ return ValidationStatus.error("name already exists");
+ }
+ }
+ else if (sc instanceof LogicalSystem) {
+ LogicalSystem ssc = (LogicalSystem) sc;
+ for (SubSystemRef ssr : ssc.getSubSystems()) {
+ if (ssr!=ref && ssr.getName().equals(name))
+ return ValidationStatus.error("name already exists");
+ }
+ }
+ else {
+ assert(false): "unexpected type";
+ }
+ return Status.OK_STATUS;
+ }
+ return Status.OK_STATUS;
+ }
+
+ private boolean nameExists(ActorClass ac, String name) {
+ for (ActorRef ar : ac.getActorRefs()) {
+ if (ar!=ref && ar.getName().equals(name))
+ return true;
+ }
+ if (ac.getBase()!=null)
+ return nameExists(ac.getBase(), name);
+
+ return false;
+ }
+ }
+
+ class ProtocolValidator implements IValidator {
+
+ @Override
+ public IStatus validate(Object value) {
+ if (value==null)
+ return ValidationStatus.error("select a class");
+
+ return Status.OK_STATUS;
+ }
+ }
+
+ class SizeValidator implements IValidator {
+
+ public SizeValidator() {
+ }
+
+ @Override
+ public IStatus validate(Object value) {
+ if (value instanceof Integer) {
+ int m = (Integer) value;
+ if (m<=0)
+ return ValidationStatus.error("multiplicity must not be positive");
+ }
+ return Status.OK_STATUS;
+ }
+ }
+
+ private ActorContainerRef ref;
+ private IScope scope;
+ private StructureClass sc;
+ private boolean newRef;
+
+ public ActorContainerRefPropertyDialog(Shell shell, ActorContainerRef ref, IScope scope, StructureClass sc, boolean newRef) {
+ super(shell, "Edit Reference");
+ this.ref = ref;
+ this.scope = scope;
+ this.sc = sc;
+ this.newRef = newRef;
+ }
+
+ @Override
+ protected void initializeBounds() {
+ super.initializeBounds();
+ Point size = getShell().getSize();
+ getShell().setSize((int)(size.x*1.2), size.y);
+ }
+
+ @Override
+ protected void createContent(IManagedForm mform, Composite body,
+ DataBindingContext bindingContext) {
+
+ NameValidator nv = new NameValidator();
+ ProtocolValidator pv = new ProtocolValidator();
+
+ boolean refIsActor = sc instanceof ActorContainerClass;
+ boolean containerIsActor = sc instanceof ActorClass;
+
+ ArrayList<IEObjectDescription> actors = new ArrayList<IEObjectDescription>();
+ Iterator<IEObjectDescription> it = scope.getAllElements().iterator();
+ while (it.hasNext()) {
+ IEObjectDescription desc = it.next();
+ EObject obj = desc.getEObjectOrProxy();
+ if (refIsActor && obj instanceof ActorClass) {
+ if (containerIsActor) {
+ if (!ValidationUtil.isReferencing((ActorClass)obj, (ActorClass)sc))
+ actors.add(desc);
+ }
+ else
+ actors.add(desc);
+ }
+ else if (!refIsActor && obj instanceof SubSystemClass) {
+ if (obj!=sc)
+ actors.add(desc);
+ }
+ }
+
+ Text name = createText(body, "&Name:", ref, RoomPackage.eINSTANCE.getActorContainerRef_Name(), nv);
+ Combo refClass = refIsActor?
+ createComboUsingDesc(body, "Actor &Class:", ref, ActorClass.class, RoomPackage.eINSTANCE.getActorRef_Type(), actors, RoomPackage.eINSTANCE.getRoomClass_Name(), pv)
+ : createComboUsingDesc(body, "SubSystem &Class:", ref, SubSystemClass.class, RoomPackage.eINSTANCE.getSubSystemRef_Type(), actors, RoomPackage.eINSTANCE.getRoomClass_Name(), pv);
+
+ createDecorator(name, "invalid name");
+ createDecorator(refClass, "no class selected");
+
+ if (!newRef) {
+ refClass.setEnabled(false);
+ createInfoDecorator(refClass, "class fixed for exisiting ref");
+ }
+
+ if (ref instanceof ActorRef) {
+ Text size = createText(body, "&Multiplicity", ref, RoomPackage.eINSTANCE.getActorRef_Size(), new SizeValidator());
+ if (hasInterfacePortWithMultiplicityAny(((ActorRef) ref).getType())) {
+ size.setEnabled(false);
+ createInfoDecorator(size, "size fixed since actor has interface ports with multiplicity *");
+ }
+ else {
+ createDecorator(size, "multiplicity");
+ }
+ }
+
+ name.selectAll();
+ name.setFocus();
+ }
+
+ /**
+ * @param ac
+ * @return
+ */
+ private boolean hasInterfacePortWithMultiplicityAny(ActorClass ac) {
+ if (ac==null)
+ return false;
+
+ for (Port p : ac.getIfPorts()) {
+ if (p.getMultiplicity()<0)
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ protected Image getImage() {
+ return Activator.getImage("icons/Structure.gif");
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/PortPropertyDialog.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/PortPropertyDialog.java
index 3c19fa37b..818776844 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/PortPropertyDialog.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/PortPropertyDialog.java
@@ -1,353 +1,353 @@
-/*******************************************************************************
- * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.structure.dialogs;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-
-import org.eclipse.core.databinding.DataBindingContext;
-import org.eclipse.core.databinding.UpdateValueStrategy;
-import org.eclipse.core.databinding.beans.PojoObservables;
-import org.eclipse.core.databinding.conversion.Converter;
-import org.eclipse.core.databinding.validation.IValidator;
-import org.eclipse.core.databinding.validation.ValidationStatus;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.etrice.core.validation.ValidationUtil;
-import org.eclipse.etrice.core.validation.ValidationUtil.Result;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.forms.IManagedForm;
-import org.eclipse.ui.forms.widgets.FormToolkit;
-import org.eclipse.xtext.resource.IEObjectDescription;
-import org.eclipse.xtext.scoping.IScope;
-
-import org.eclipse.etrice.core.room.ActorClass;
-import org.eclipse.etrice.core.room.ActorContainerClass;
-import org.eclipse.etrice.core.room.CommunicationType;
-import org.eclipse.etrice.core.room.CompoundProtocolClass;
-import org.eclipse.etrice.core.room.ExternalPort;
-import org.eclipse.etrice.core.room.GeneralProtocolClass;
-import org.eclipse.etrice.core.room.Port;
-import org.eclipse.etrice.core.room.ProtocolClass;
-import org.eclipse.etrice.core.room.RoomFactory;
-import org.eclipse.etrice.core.room.RoomPackage;
-import org.eclipse.etrice.core.room.SubSystemClass;
-import org.eclipse.etrice.ui.common.dialogs.AbstractPropertyDialog;
-import org.eclipse.etrice.ui.structure.Activator;
-import org.eclipse.jface.databinding.swt.SWTObservables;
-
-public class PortPropertyDialog extends AbstractPropertyDialog {
-
- class NameValidator implements IValidator {
-
- @Override
- public IStatus validate(Object value) {
- if (value instanceof String) {
- String name = (String) value;
-
- Result result = ValidationUtil.isUniqueName(port, name);
- if (!result.isOk())
- return ValidationStatus.error(result.getMsg());
- }
- return Status.OK_STATUS;
- }
- }
-
- class ProtocolValidator implements IValidator {
-
- @Override
- public IStatus validate(Object value) {
- if (value==null)
- return ValidationStatus.error("select a protocol");
-
- if (value instanceof CompoundProtocolClass)
- if (!relay)
- return ValidationStatus.error("compound protocol only possible for relay port");
-
- return Status.OK_STATUS;
- }
- }
-
- class MultiplicityValidator implements IValidator {
-
- private boolean mayChange;
- private int old;
- private boolean multAnyAllowed;
-
- public MultiplicityValidator(boolean mayChange, int old, boolean multAnyAllowed) {
- this.mayChange = mayChange;
- this.old = old;
- this.multAnyAllowed = multAnyAllowed;
- }
-
- @Override
- public IStatus validate(Object value) {
- if (value instanceof Integer) {
- int m = (Integer) value;
- if (m==0)
- return ValidationStatus.error("multiplicity must not be 0");
- if (m<-1)
- return ValidationStatus.error("multiplicity must be -1 or positive");
- if (!mayChange) {
- if (old==1 && (m>1 || m==-1))
- return ValidationStatus.error("cannot change connected port to replicated");
- if ((old>1 || old==-1) && m==1)
- return ValidationStatus.error("cannot change connected port to not replicated");
- }
- if (m==-1 && !multAnyAllowed)
- return ValidationStatus.error("multiplicity * not allowed (actor used replicated)");
-
- if (port.getProtocol()!=null)
- if (port.getProtocol() instanceof ProtocolClass && ((ProtocolClass)port.getProtocol()).getCommType()==CommunicationType.DATA_DRIVEN) {
- if (m!=1)
- return ValidationStatus.error("data driven ports can not be replicated");
- }
- }
- return Status.OK_STATUS;
- }
- }
-
- class RelayValidator implements IValidator {
-
- /* (non-Javadoc)
- * @see org.eclipse.core.databinding.validation.IValidator#validate(java.lang.Object)
- */
- @Override
- public IStatus validate(Object value) {
- if (!((Boolean)value).booleanValue())
- if (port.getProtocol() instanceof CompoundProtocolClass)
- return ValidationStatus.error("external end port must not have compound protocol");
-
- return Status.OK_STATUS;
- }
-
- }
-
- static class Multiplicity2StringConverter extends Converter {
-
- public Multiplicity2StringConverter() {
- super(Integer.class, String.class);
- }
-
- @Override
- public Object convert(Object fromObject) {
- if (fromObject instanceof Integer) {
- int val = (Integer) fromObject;
- if (val==-1)
- return "*";
- else
- return fromObject.toString();
- }
- return fromObject;
- }
-
- }
-
- static class String2MultiplicityConverter extends Converter {
- String2MultiplicityConverter() {
- super(String.class, Integer.class);
- }
-
- @Override
- public Object convert(Object fromObject) {
- if (fromObject.equals("*"))
- return -1;
- else
- return Integer.parseInt((String) fromObject);
- }
- }
-
- private Port port;
- private IScope scope;
- private ActorContainerClass acc;
- private boolean newPort;
- private boolean refitem;
- private boolean internal;
- private Button relayCheck = null;
- private boolean relay;
- private boolean oldRelay;
-
- public PortPropertyDialog(Shell shell, Port port, IScope scope, ActorContainerClass acc, boolean newPort, boolean refitem, boolean internal) {
- super(shell, "Edit Port");
- this.port = port;
- this.scope = scope;
- this.acc = acc;
- this.newPort = newPort;
- this.refitem = refitem;
- this.internal = internal;
-
- relay = isPortRelay();
- oldRelay = relay;
- }
-
- private boolean isPortRelay() {
- if (internal)
- return false;
-
- if (acc instanceof SubSystemClass)
- return true;
- else if (acc instanceof ActorClass) {
- for (ExternalPort xp : ((ActorClass) acc).getExtPorts()) {
- if (xp.getIfport()==port)
- return false;
- }
- return true;
- }
-
- return false;
- }
-
- @Override
- protected void initializeBounds() {
- super.initializeBounds();
- Point size = getShell().getSize();
- getShell().setSize((int)(size.x*1.2), size.y);
- }
-
- @Override
- protected void createContent(IManagedForm mform, Composite body, DataBindingContext bindingContext) {
- Result notReferenced = ValidationUtil.isFreeOfReferences(port);
- boolean multiplicityAnyAllowed = true;
- ActorContainerClass parent = (ActorContainerClass) port.eContainer();
- if (parent instanceof ActorClass) {
- if (ValidationUtil.isReferencedAsReplicatedInModel((ActorClass) parent))
- multiplicityAnyAllowed = false;
- }
- NameValidator nv = new NameValidator();
- ProtocolValidator pv = new ProtocolValidator();
- MultiplicityValidator mv = new MultiplicityValidator(newPort || notReferenced.isOk(), port.getMultiplicity(), multiplicityAnyAllowed);
-
- ArrayList<IEObjectDescription> protocols = new ArrayList<IEObjectDescription>();
- Iterator<IEObjectDescription> it = scope.getAllElements().iterator();
- while (it.hasNext()) {
- IEObjectDescription desc = it.next();
- EObject obj = desc.getEObjectOrProxy();
- if (obj instanceof GeneralProtocolClass)
- protocols.add(desc);
- }
-
- Text name = createText(body, "&Name:", port, RoomPackage.eINSTANCE.getInterfaceItem_Name(), nv);
- Combo protocol = createComboUsingDesc(body, "&Protocol:", port, GeneralProtocolClass.class, RoomPackage.eINSTANCE.getPort_Protocol(), protocols, RoomPackage.eINSTANCE.getRoomClass_Name(), pv);
- Button conj = createCheck(body, "&Conjugated:", port, RoomPackage.eINSTANCE.getPort_Conjugated());
- if (!internal && !refitem && (acc instanceof ActorClass))
- createRelayCheck(body, notReferenced, mform.getToolkit());
-
- Multiplicity2StringConverter m2s = new Multiplicity2StringConverter();
- String2MultiplicityConverter s2m = new String2MultiplicityConverter();
- Text multi = createText(body, "&Multiplicity:", port, RoomPackage.eINSTANCE.getPort_Multiplicity(), mv, s2m, m2s, false);
-
- if (!newPort) {
- if (!notReferenced.isOk()) {
- protocol.setEnabled(false);
- createInfoDecorator(protocol, notReferenced.getMsg());
- conj.setEnabled(false);
- createInfoDecorator(conj, notReferenced.getMsg());
- if (port.getMultiplicity()==1) {
- multi.setEnabled(false);
- createInfoDecorator(multi, notReferenced.getMsg());
- }
- }
-
- if (refitem) {
- name.setEnabled(false);
- createInfoDecorator(name, "inherited");
- protocol.setEnabled(false);
- createInfoDecorator(protocol, "inherited");
- conj.setEnabled(false);
- createInfoDecorator(conj, "inherited");
- multi.setEnabled(false);
- createInfoDecorator(multi, "inherited");
- }
- }
-
- createDecorator(name, "invalid name");
- createDecorator(protocol, "no protocol selected");
- createDecorator(multi, "multiplicity must be greater 1");
-
- name.selectAll();
- name.setFocus();
- }
-
- private void createRelayCheck(Composite parent, Result notReferenced, FormToolkit toolkit) {
- Label l = toolkit.createLabel(parent, "Is Relay Port:", SWT.NONE);
- l.setLayoutData(new GridData(SWT.NONE));
-
- relayCheck = toolkit.createButton(parent, "", SWT.CHECK);
- relayCheck.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- relayCheck.setSelection(relay);
- relayCheck.setEnabled(notReferenced.isOk());
-
- RelayValidator validator = new RelayValidator();
- UpdateValueStrategy t2m = new UpdateValueStrategy();
- t2m.setAfterConvertValidator(validator);
- t2m.setBeforeSetValidator(validator);
- UpdateValueStrategy m2t = new UpdateValueStrategy();
- m2t.setAfterConvertValidator(validator);
- m2t.setBeforeSetValidator(validator);
-
- getBindingContext().bindValue(SWTObservables.observeSelection(relayCheck), PojoObservables.observeValue(
- this, "relay"), t2m, m2t);
-
- if (notReferenced.isOk())
- createDecorator(relayCheck, "");
- else
- createInfoDecorator(relayCheck, notReferenced.getMsg());
- }
-
- @Override
- protected void okPressed() {
- if (relay!=oldRelay) {
- // we know it's an ActorClass (else the flag couldn't have changed)
- ActorClass ac = (ActorClass) acc;
-
- if (relay) {
- for (ExternalPort xp : ac.getExtPorts()) {
- if (xp.getIfport()==port) {
- ac.getExtPorts().remove(xp);
- break;
- }
- }
- }
- else {
- ExternalPort xp = RoomFactory.eINSTANCE.createExternalPort();
- xp.setIfport(port);
- ac.getExtPorts().add(xp);
- }
- }
-
- super.okPressed();
- }
-
- @Override
- protected Image getImage() {
- return Activator.getImage("icons/Structure.gif");
- }
-
- public boolean isRelay() {
- return relay;
- }
-
- public void setRelay(boolean relay) {
- this.relay = relay;
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.dialogs;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.databinding.UpdateValueStrategy;
+import org.eclipse.core.databinding.beans.PojoObservables;
+import org.eclipse.core.databinding.conversion.Converter;
+import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.core.databinding.validation.ValidationStatus;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.validation.ValidationUtil;
+import org.eclipse.etrice.core.validation.ValidationUtil.Result;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.xtext.resource.IEObjectDescription;
+import org.eclipse.xtext.scoping.IScope;
+
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.ActorContainerClass;
+import org.eclipse.etrice.core.room.CommunicationType;
+import org.eclipse.etrice.core.room.CompoundProtocolClass;
+import org.eclipse.etrice.core.room.ExternalPort;
+import org.eclipse.etrice.core.room.GeneralProtocolClass;
+import org.eclipse.etrice.core.room.Port;
+import org.eclipse.etrice.core.room.ProtocolClass;
+import org.eclipse.etrice.core.room.RoomFactory;
+import org.eclipse.etrice.core.room.RoomPackage;
+import org.eclipse.etrice.core.room.SubSystemClass;
+import org.eclipse.etrice.ui.common.dialogs.AbstractPropertyDialog;
+import org.eclipse.etrice.ui.structure.Activator;
+import org.eclipse.jface.databinding.swt.SWTObservables;
+
+public class PortPropertyDialog extends AbstractPropertyDialog {
+
+ class NameValidator implements IValidator {
+
+ @Override
+ public IStatus validate(Object value) {
+ if (value instanceof String) {
+ String name = (String) value;
+
+ Result result = ValidationUtil.isUniqueName(port, name);
+ if (!result.isOk())
+ return ValidationStatus.error(result.getMsg());
+ }
+ return Status.OK_STATUS;
+ }
+ }
+
+ class ProtocolValidator implements IValidator {
+
+ @Override
+ public IStatus validate(Object value) {
+ if (value==null)
+ return ValidationStatus.error("select a protocol");
+
+ if (value instanceof CompoundProtocolClass)
+ if (!relay)
+ return ValidationStatus.error("compound protocol only possible for relay port");
+
+ return Status.OK_STATUS;
+ }
+ }
+
+ class MultiplicityValidator implements IValidator {
+
+ private boolean mayChange;
+ private int old;
+ private boolean multAnyAllowed;
+
+ public MultiplicityValidator(boolean mayChange, int old, boolean multAnyAllowed) {
+ this.mayChange = mayChange;
+ this.old = old;
+ this.multAnyAllowed = multAnyAllowed;
+ }
+
+ @Override
+ public IStatus validate(Object value) {
+ if (value instanceof Integer) {
+ int m = (Integer) value;
+ if (m==0)
+ return ValidationStatus.error("multiplicity must not be 0");
+ if (m<-1)
+ return ValidationStatus.error("multiplicity must be -1 or positive");
+ if (!mayChange) {
+ if (old==1 && (m>1 || m==-1))
+ return ValidationStatus.error("cannot change connected port to replicated");
+ if ((old>1 || old==-1) && m==1)
+ return ValidationStatus.error("cannot change connected port to not replicated");
+ }
+ if (m==-1 && !multAnyAllowed)
+ return ValidationStatus.error("multiplicity * not allowed (actor used replicated)");
+
+ if (port.getProtocol()!=null)
+ if (port.getProtocol() instanceof ProtocolClass && ((ProtocolClass)port.getProtocol()).getCommType()==CommunicationType.DATA_DRIVEN) {
+ if (m!=1)
+ return ValidationStatus.error("data driven ports can not be replicated");
+ }
+ }
+ return Status.OK_STATUS;
+ }
+ }
+
+ class RelayValidator implements IValidator {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.databinding.validation.IValidator#validate(java.lang.Object)
+ */
+ @Override
+ public IStatus validate(Object value) {
+ if (!((Boolean)value).booleanValue())
+ if (port.getProtocol() instanceof CompoundProtocolClass)
+ return ValidationStatus.error("external end port must not have compound protocol");
+
+ return Status.OK_STATUS;
+ }
+
+ }
+
+ static class Multiplicity2StringConverter extends Converter {
+
+ public Multiplicity2StringConverter() {
+ super(Integer.class, String.class);
+ }
+
+ @Override
+ public Object convert(Object fromObject) {
+ if (fromObject instanceof Integer) {
+ int val = (Integer) fromObject;
+ if (val==-1)
+ return "*";
+ else
+ return fromObject.toString();
+ }
+ return fromObject;
+ }
+
+ }
+
+ static class String2MultiplicityConverter extends Converter {
+ String2MultiplicityConverter() {
+ super(String.class, Integer.class);
+ }
+
+ @Override
+ public Object convert(Object fromObject) {
+ if (fromObject.equals("*"))
+ return -1;
+ else
+ return Integer.parseInt((String) fromObject);
+ }
+ }
+
+ private Port port;
+ private IScope scope;
+ private ActorContainerClass acc;
+ private boolean newPort;
+ private boolean refitem;
+ private boolean internal;
+ private Button relayCheck = null;
+ private boolean relay;
+ private boolean oldRelay;
+
+ public PortPropertyDialog(Shell shell, Port port, IScope scope, ActorContainerClass acc, boolean newPort, boolean refitem, boolean internal) {
+ super(shell, "Edit Port");
+ this.port = port;
+ this.scope = scope;
+ this.acc = acc;
+ this.newPort = newPort;
+ this.refitem = refitem;
+ this.internal = internal;
+
+ relay = isPortRelay();
+ oldRelay = relay;
+ }
+
+ private boolean isPortRelay() {
+ if (internal)
+ return false;
+
+ if (acc instanceof SubSystemClass)
+ return true;
+ else if (acc instanceof ActorClass) {
+ for (ExternalPort xp : ((ActorClass) acc).getExtPorts()) {
+ if (xp.getIfport()==port)
+ return false;
+ }
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ protected void initializeBounds() {
+ super.initializeBounds();
+ Point size = getShell().getSize();
+ getShell().setSize((int)(size.x*1.2), size.y);
+ }
+
+ @Override
+ protected void createContent(IManagedForm mform, Composite body, DataBindingContext bindingContext) {
+ Result notReferenced = ValidationUtil.isFreeOfReferences(port);
+ boolean multiplicityAnyAllowed = true;
+ ActorContainerClass parent = (ActorContainerClass) port.eContainer();
+ if (parent instanceof ActorClass) {
+ if (ValidationUtil.isReferencedAsReplicatedInModel((ActorClass) parent))
+ multiplicityAnyAllowed = false;
+ }
+ NameValidator nv = new NameValidator();
+ ProtocolValidator pv = new ProtocolValidator();
+ MultiplicityValidator mv = new MultiplicityValidator(newPort || notReferenced.isOk(), port.getMultiplicity(), multiplicityAnyAllowed);
+
+ ArrayList<IEObjectDescription> protocols = new ArrayList<IEObjectDescription>();
+ Iterator<IEObjectDescription> it = scope.getAllElements().iterator();
+ while (it.hasNext()) {
+ IEObjectDescription desc = it.next();
+ EObject obj = desc.getEObjectOrProxy();
+ if (obj instanceof GeneralProtocolClass)
+ protocols.add(desc);
+ }
+
+ Text name = createText(body, "&Name:", port, RoomPackage.eINSTANCE.getInterfaceItem_Name(), nv);
+ Combo protocol = createComboUsingDesc(body, "&Protocol:", port, GeneralProtocolClass.class, RoomPackage.eINSTANCE.getPort_Protocol(), protocols, RoomPackage.eINSTANCE.getRoomClass_Name(), pv);
+ Button conj = createCheck(body, "&Conjugated:", port, RoomPackage.eINSTANCE.getPort_Conjugated());
+ if (!internal && !refitem && (acc instanceof ActorClass))
+ createRelayCheck(body, notReferenced, mform.getToolkit());
+
+ Multiplicity2StringConverter m2s = new Multiplicity2StringConverter();
+ String2MultiplicityConverter s2m = new String2MultiplicityConverter();
+ Text multi = createText(body, "&Multiplicity:", port, RoomPackage.eINSTANCE.getPort_Multiplicity(), mv, s2m, m2s, false);
+
+ if (!newPort) {
+ if (!notReferenced.isOk()) {
+ protocol.setEnabled(false);
+ createInfoDecorator(protocol, notReferenced.getMsg());
+ conj.setEnabled(false);
+ createInfoDecorator(conj, notReferenced.getMsg());
+ if (port.getMultiplicity()==1) {
+ multi.setEnabled(false);
+ createInfoDecorator(multi, notReferenced.getMsg());
+ }
+ }
+
+ if (refitem) {
+ name.setEnabled(false);
+ createInfoDecorator(name, "inherited");
+ protocol.setEnabled(false);
+ createInfoDecorator(protocol, "inherited");
+ conj.setEnabled(false);
+ createInfoDecorator(conj, "inherited");
+ multi.setEnabled(false);
+ createInfoDecorator(multi, "inherited");
+ }
+ }
+
+ createDecorator(name, "invalid name");
+ createDecorator(protocol, "no protocol selected");
+ createDecorator(multi, "multiplicity must be greater 1");
+
+ name.selectAll();
+ name.setFocus();
+ }
+
+ private void createRelayCheck(Composite parent, Result notReferenced, FormToolkit toolkit) {
+ Label l = toolkit.createLabel(parent, "Is Relay Port:", SWT.NONE);
+ l.setLayoutData(new GridData(SWT.NONE));
+
+ relayCheck = toolkit.createButton(parent, "", SWT.CHECK);
+ relayCheck.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ relayCheck.setSelection(relay);
+ relayCheck.setEnabled(notReferenced.isOk());
+
+ RelayValidator validator = new RelayValidator();
+ UpdateValueStrategy t2m = new UpdateValueStrategy();
+ t2m.setAfterConvertValidator(validator);
+ t2m.setBeforeSetValidator(validator);
+ UpdateValueStrategy m2t = new UpdateValueStrategy();
+ m2t.setAfterConvertValidator(validator);
+ m2t.setBeforeSetValidator(validator);
+
+ getBindingContext().bindValue(SWTObservables.observeSelection(relayCheck), PojoObservables.observeValue(
+ this, "relay"), t2m, m2t);
+
+ if (notReferenced.isOk())
+ createDecorator(relayCheck, "");
+ else
+ createInfoDecorator(relayCheck, notReferenced.getMsg());
+ }
+
+ @Override
+ protected void okPressed() {
+ if (relay!=oldRelay) {
+ // we know it's an ActorClass (else the flag couldn't have changed)
+ ActorClass ac = (ActorClass) acc;
+
+ if (relay) {
+ for (ExternalPort xp : ac.getExtPorts()) {
+ if (xp.getIfport()==port) {
+ ac.getExtPorts().remove(xp);
+ break;
+ }
+ }
+ }
+ else {
+ ExternalPort xp = RoomFactory.eINSTANCE.createExternalPort();
+ xp.setIfport(port);
+ ac.getExtPorts().add(xp);
+ }
+ }
+
+ super.okPressed();
+ }
+
+ @Override
+ protected Image getImage() {
+ return Activator.getImage("icons/Structure.gif");
+ }
+
+ public boolean isRelay() {
+ return relay;
+ }
+
+ public void setRelay(boolean relay) {
+ this.relay = relay;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/SPPPropertyDialog.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/SPPPropertyDialog.java
index a6a1f2b4e..efe88fea8 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/SPPPropertyDialog.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/SPPPropertyDialog.java
@@ -1,131 +1,131 @@
-/*******************************************************************************
- * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.structure.dialogs;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-
-import org.eclipse.core.databinding.DataBindingContext;
-import org.eclipse.core.databinding.validation.IValidator;
-import org.eclipse.core.databinding.validation.ValidationStatus;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.etrice.core.room.ProtocolClass;
-import org.eclipse.etrice.core.room.RoomPackage;
-import org.eclipse.etrice.core.room.SPPRef;
-import org.eclipse.etrice.core.validation.ValidationUtil;
-import org.eclipse.etrice.core.validation.ValidationUtil.Result;
-import org.eclipse.etrice.ui.common.dialogs.AbstractPropertyDialog;
-import org.eclipse.etrice.ui.structure.Activator;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.forms.IManagedForm;
-import org.eclipse.xtext.resource.IEObjectDescription;
-import org.eclipse.xtext.scoping.IScope;
-
-public class SPPPropertyDialog extends AbstractPropertyDialog {
-
- class NameValidator implements IValidator {
-
- @Override
- public IStatus validate(Object value) {
- if (value instanceof String) {
- String name = (String) value;
-
- Result result = ValidationUtil.isUniqueName(spp, name);
- if (!result.isOk())
- return ValidationStatus.error(result.getMsg());
-
- return Status.OK_STATUS;
- }
- return Status.OK_STATUS;
- }
- }
-
- class ProtocolValidator implements IValidator {
-
- @Override
- public IStatus validate(Object value) {
- if (value==null)
- return ValidationStatus.error("select a protocol");
-
- return Status.OK_STATUS;
- }
- }
-
- private SPPRef spp;
- private IScope scope;
- private boolean newSPP;
- private boolean refitem;
-
- public SPPPropertyDialog(Shell shell, SPPRef spp, IScope scope, boolean newSPP, boolean refitem) {
- super(shell, "Edit SPP");
- this.spp = spp;
- this.scope = scope;
- this.newSPP = newSPP;
- this.refitem = refitem;
- }
-
- @Override
- protected void initializeBounds() {
- super.initializeBounds();
- Point size = getShell().getSize();
- getShell().setSize((int)(size.x*1.2), size.y);
- }
-
- @Override
- protected void createContent(IManagedForm mform, Composite body, DataBindingContext bindingContext) {
- boolean connected = ValidationUtil.isReferencedInModel(spp);
- NameValidator nv = new NameValidator();
- ProtocolValidator pv = new ProtocolValidator();
-
- ArrayList<IEObjectDescription> protocols = new ArrayList<IEObjectDescription>();
- Iterator<IEObjectDescription> it = scope.getAllElements().iterator();
- while (it.hasNext()) {
- IEObjectDescription desc = it.next();
- EObject obj = desc.getEObjectOrProxy();
- if (obj instanceof ProtocolClass)
- protocols.add(desc);
- }
-
- Text name = createText(body, "Name:", spp, RoomPackage.eINSTANCE.getInterfaceItem_Name(), nv);
- Combo protocol = createComboUsingDesc(body, "Protocol:", spp, ProtocolClass.class, RoomPackage.eINSTANCE.getSPPRef_Protocol(), protocols, RoomPackage.eINSTANCE.getRoomClass_Name(), pv);
-
- if (!newSPP) {
- // TODOHRR: check whether spp is used externally?
- if (connected) {
- protocol.setEnabled(false);
- }
- if (refitem) {
- name.setEnabled(false);
- protocol.setEnabled(false);
- }
- }
-
- createDecorator(name, "invalid name");
- createDecorator(protocol, "no protocol selected");
-
- name.selectAll();
- name.setFocus();
- }
-
- @Override
- protected Image getImage() {
- return Activator.getImage("icons/Structure.gif");
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.dialogs;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.core.databinding.validation.ValidationStatus;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.room.ProtocolClass;
+import org.eclipse.etrice.core.room.RoomPackage;
+import org.eclipse.etrice.core.room.SPPRef;
+import org.eclipse.etrice.core.validation.ValidationUtil;
+import org.eclipse.etrice.core.validation.ValidationUtil.Result;
+import org.eclipse.etrice.ui.common.dialogs.AbstractPropertyDialog;
+import org.eclipse.etrice.ui.structure.Activator;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.xtext.resource.IEObjectDescription;
+import org.eclipse.xtext.scoping.IScope;
+
+public class SPPPropertyDialog extends AbstractPropertyDialog {
+
+ class NameValidator implements IValidator {
+
+ @Override
+ public IStatus validate(Object value) {
+ if (value instanceof String) {
+ String name = (String) value;
+
+ Result result = ValidationUtil.isUniqueName(spp, name);
+ if (!result.isOk())
+ return ValidationStatus.error(result.getMsg());
+
+ return Status.OK_STATUS;
+ }
+ return Status.OK_STATUS;
+ }
+ }
+
+ class ProtocolValidator implements IValidator {
+
+ @Override
+ public IStatus validate(Object value) {
+ if (value==null)
+ return ValidationStatus.error("select a protocol");
+
+ return Status.OK_STATUS;
+ }
+ }
+
+ private SPPRef spp;
+ private IScope scope;
+ private boolean newSPP;
+ private boolean refitem;
+
+ public SPPPropertyDialog(Shell shell, SPPRef spp, IScope scope, boolean newSPP, boolean refitem) {
+ super(shell, "Edit SPP");
+ this.spp = spp;
+ this.scope = scope;
+ this.newSPP = newSPP;
+ this.refitem = refitem;
+ }
+
+ @Override
+ protected void initializeBounds() {
+ super.initializeBounds();
+ Point size = getShell().getSize();
+ getShell().setSize((int)(size.x*1.2), size.y);
+ }
+
+ @Override
+ protected void createContent(IManagedForm mform, Composite body, DataBindingContext bindingContext) {
+ boolean connected = ValidationUtil.isReferencedInModel(spp);
+ NameValidator nv = new NameValidator();
+ ProtocolValidator pv = new ProtocolValidator();
+
+ ArrayList<IEObjectDescription> protocols = new ArrayList<IEObjectDescription>();
+ Iterator<IEObjectDescription> it = scope.getAllElements().iterator();
+ while (it.hasNext()) {
+ IEObjectDescription desc = it.next();
+ EObject obj = desc.getEObjectOrProxy();
+ if (obj instanceof ProtocolClass)
+ protocols.add(desc);
+ }
+
+ Text name = createText(body, "Name:", spp, RoomPackage.eINSTANCE.getInterfaceItem_Name(), nv);
+ Combo protocol = createComboUsingDesc(body, "Protocol:", spp, ProtocolClass.class, RoomPackage.eINSTANCE.getSPPRef_Protocol(), protocols, RoomPackage.eINSTANCE.getRoomClass_Name(), pv);
+
+ if (!newSPP) {
+ // TODOHRR: check whether spp is used externally?
+ if (connected) {
+ protocol.setEnabled(false);
+ }
+ if (refitem) {
+ name.setEnabled(false);
+ protocol.setEnabled(false);
+ }
+ }
+
+ createDecorator(name, "invalid name");
+ createDecorator(protocol, "no protocol selected");
+
+ name.selectAll();
+ name.setFocus();
+ }
+
+ @Override
+ protected Image getImage() {
+ return Activator.getImage("icons/Structure.gif");
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/SubProtocolSelectionDialog.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/SubProtocolSelectionDialog.java
index 76b6b43d3..94140a2f6 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/SubProtocolSelectionDialog.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/SubProtocolSelectionDialog.java
@@ -1,211 +1,211 @@
-/*******************************************************************************
- * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.structure.dialogs;
-
-import java.util.List;
-
-import org.eclipse.etrice.core.room.ActorContainerRef;
-import org.eclipse.etrice.core.room.Binding;
-import org.eclipse.etrice.core.room.Port;
-import org.eclipse.etrice.core.room.StructureClass;
-import org.eclipse.etrice.core.room.SubProtocol;
-import org.eclipse.etrice.core.room.util.CompoundProtocolHelpers;
-import org.eclipse.etrice.core.room.util.CompoundProtocolHelpers.Match;
-import org.eclipse.etrice.ui.structure.Activator;
-import org.eclipse.jface.layout.TableColumnLayout;
-import org.eclipse.jface.viewers.ColumnWeightData;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITableLabelProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.ui.forms.FormDialog;
-import org.eclipse.ui.forms.IManagedForm;
-import org.eclipse.ui.forms.widgets.Form;
-
-/**
- * @author Henrik Rentz-Reichert
- *
- */
-public class SubProtocolSelectionDialog extends FormDialog {
-
- private class MatchContentProvider implements IStructuredContentProvider {
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- */
- @Override
- public void dispose() {
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
- */
- @Override
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- */
- @Override
- public Object[] getElements(Object inputElement) {
- return matches.toArray();
- }
-
- }
-
- private class MatchLabelProvider extends LabelProvider implements ITableLabelProvider {
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
- */
- @Override
- public Image getColumnImage(Object element, int columnIndex) {
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
- */
- @Override
- public String getColumnText(Object element, int columnIndex) {
- if (element instanceof Match) {
- SubProtocol sub = (columnIndex==0)?
- ((Match) element).getLeft() : ((Match) element).getRight();
-
- if (sub==null)
- return "-/"+((columnIndex==0)? src.getProtocol().getName() : dst.getProtocol().getName());
- else
- return sub.getName()+"/"+sub.getProtocol().getName();
- }
- return null;
- }
-
- }
-
- private Port src;
- private Port dst;
- private TableViewer viewer;
- private List<Match> matches;
- private Match selected;
-
- public SubProtocolSelectionDialog(Shell shell, Port src, ActorContainerRef srcRef, Port dst, ActorContainerRef dstRef, Binding bind, StructureClass sc) {
- super(shell);
-
- this.src = src;
- this.dst = dst;
-
- matches = CompoundProtocolHelpers.getMatches(src, srcRef, dst, dstRef, sc, bind);
-
- // find match to select
- if (bind!=null) {
- for (Match match : matches) {
- if (match.getLeft()==bind.getEndpoint1().getSub() && match.getRight()==bind.getEndpoint2().getSub())
- selected = match;
- }
- }
- else
- selected = matches.get(0);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.forms.FormDialog#createFormContent(org.eclipse.ui.forms.IManagedForm)
- */
- @Override
- protected void createFormContent(IManagedForm mform) {
- super.createFormContent(mform);
-
- Form form = mform.getForm().getForm();
- form.setText("Connect SubProtocol(s)");
- mform.getToolkit().decorateFormHeading(form);
- form.setImage(Activator.getImage("icons/Structure.gif"));
-
- Composite body = form.getBody();
-
- Table matchTable = mform.getToolkit().createTable(body, SWT.NONE | SWT.SINGLE | SWT.FULL_SELECTION);
- viewer = new TableViewer(matchTable);
-
- TableColumn col0 = new TableColumn(viewer.getTable(), SWT.NONE);
- col0.setText("Port "+src.getName());
- TableColumn col1 = new TableColumn(viewer.getTable(), SWT.NONE);
- col1.setText("Port "+dst.getName());
- viewer.getTable().setHeaderVisible(true);
-
- viewer.setContentProvider(new MatchContentProvider());
- viewer.setLabelProvider(new MatchLabelProvider());
-
- viewer.setInput(matches);
-
- TableColumnLayout layout = new TableColumnLayout();
- body.setLayout(layout);
-
- layout.setColumnData(col0, new ColumnWeightData(50));
- layout.setColumnData(col1, new ColumnWeightData(50));
-
- viewer.setSelection(new StructuredSelection(selected));
-
- viewer.addSelectionChangedListener(new ISelectionChangedListener() {
- @Override
- public void selectionChanged(SelectionChangedEvent event) {
- Button ok = getButton(OK);
- if (ok!=null) {
- if (event.getSelection() instanceof IStructuredSelection) {
- Object element = ((IStructuredSelection) event.getSelection()).getFirstElement();
- ok.setEnabled(element instanceof Match);
- }
- else
- ok.setEnabled(false);
- }
- }
- });
-
- viewer.addDoubleClickListener(new IDoubleClickListener() {
-
- @Override
- public void doubleClick(DoubleClickEvent event) {
- okPressed();
- }
- });
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.dialogs.Dialog#okPressed()
- */
- @Override
- protected void okPressed() {
- ISelection selection = viewer.getSelection();
- if (selection instanceof IStructuredSelection) {
- selected = (Match) ((IStructuredSelection) selection).getFirstElement();
- }
- super.okPressed();
- }
-
- public Match getSelected() {
- return selected;
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.dialogs;
+
+import java.util.List;
+
+import org.eclipse.etrice.core.room.ActorContainerRef;
+import org.eclipse.etrice.core.room.Binding;
+import org.eclipse.etrice.core.room.Port;
+import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.core.room.SubProtocol;
+import org.eclipse.etrice.core.room.util.CompoundProtocolHelpers;
+import org.eclipse.etrice.core.room.util.CompoundProtocolHelpers.Match;
+import org.eclipse.etrice.ui.structure.Activator;
+import org.eclipse.jface.layout.TableColumnLayout;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.ui.forms.FormDialog;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.widgets.Form;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public class SubProtocolSelectionDialog extends FormDialog {
+
+ private class MatchContentProvider implements IStructuredContentProvider {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+ */
+ @Override
+ public void dispose() {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
+ */
+ @Override
+ public Object[] getElements(Object inputElement) {
+ return matches.toArray();
+ }
+
+ }
+
+ private class MatchLabelProvider extends LabelProvider implements ITableLabelProvider {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
+ */
+ @Override
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
+ */
+ @Override
+ public String getColumnText(Object element, int columnIndex) {
+ if (element instanceof Match) {
+ SubProtocol sub = (columnIndex==0)?
+ ((Match) element).getLeft() : ((Match) element).getRight();
+
+ if (sub==null)
+ return "-/"+((columnIndex==0)? src.getProtocol().getName() : dst.getProtocol().getName());
+ else
+ return sub.getName()+"/"+sub.getProtocol().getName();
+ }
+ return null;
+ }
+
+ }
+
+ private Port src;
+ private Port dst;
+ private TableViewer viewer;
+ private List<Match> matches;
+ private Match selected;
+
+ public SubProtocolSelectionDialog(Shell shell, Port src, ActorContainerRef srcRef, Port dst, ActorContainerRef dstRef, Binding bind, StructureClass sc) {
+ super(shell);
+
+ this.src = src;
+ this.dst = dst;
+
+ matches = CompoundProtocolHelpers.getMatches(src, srcRef, dst, dstRef, sc, bind);
+
+ // find match to select
+ if (bind!=null) {
+ for (Match match : matches) {
+ if (match.getLeft()==bind.getEndpoint1().getSub() && match.getRight()==bind.getEndpoint2().getSub())
+ selected = match;
+ }
+ }
+ else
+ selected = matches.get(0);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.FormDialog#createFormContent(org.eclipse.ui.forms.IManagedForm)
+ */
+ @Override
+ protected void createFormContent(IManagedForm mform) {
+ super.createFormContent(mform);
+
+ Form form = mform.getForm().getForm();
+ form.setText("Connect SubProtocol(s)");
+ mform.getToolkit().decorateFormHeading(form);
+ form.setImage(Activator.getImage("icons/Structure.gif"));
+
+ Composite body = form.getBody();
+
+ Table matchTable = mform.getToolkit().createTable(body, SWT.NONE | SWT.SINGLE | SWT.FULL_SELECTION);
+ viewer = new TableViewer(matchTable);
+
+ TableColumn col0 = new TableColumn(viewer.getTable(), SWT.NONE);
+ col0.setText("Port "+src.getName());
+ TableColumn col1 = new TableColumn(viewer.getTable(), SWT.NONE);
+ col1.setText("Port "+dst.getName());
+ viewer.getTable().setHeaderVisible(true);
+
+ viewer.setContentProvider(new MatchContentProvider());
+ viewer.setLabelProvider(new MatchLabelProvider());
+
+ viewer.setInput(matches);
+
+ TableColumnLayout layout = new TableColumnLayout();
+ body.setLayout(layout);
+
+ layout.setColumnData(col0, new ColumnWeightData(50));
+ layout.setColumnData(col1, new ColumnWeightData(50));
+
+ viewer.setSelection(new StructuredSelection(selected));
+
+ viewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ Button ok = getButton(OK);
+ if (ok!=null) {
+ if (event.getSelection() instanceof IStructuredSelection) {
+ Object element = ((IStructuredSelection) event.getSelection()).getFirstElement();
+ ok.setEnabled(element instanceof Match);
+ }
+ else
+ ok.setEnabled(false);
+ }
+ }
+ });
+
+ viewer.addDoubleClickListener(new IDoubleClickListener() {
+
+ @Override
+ public void doubleClick(DoubleClickEvent event) {
+ okPressed();
+ }
+ });
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#okPressed()
+ */
+ @Override
+ protected void okPressed() {
+ ISelection selection = viewer.getSelection();
+ if (selection instanceof IStructuredSelection) {
+ selected = (Match) ((IStructuredSelection) selection).getFirstElement();
+ }
+ super.okPressed();
+ }
+
+ public Match getSelected() {
+ return selected;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureEditor.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureEditor.java
index 8eddbc69e..9b6704ddb 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureEditor.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureEditor.java
@@ -1,49 +1,49 @@
-/*******************************************************************************
- * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.structure.editor;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.etrice.core.room.StructureClass;
-import org.eclipse.etrice.ui.common.editor.RoomDiagramEditor;
-import org.eclipse.etrice.ui.structure.Activator;
-import org.eclipse.graphiti.mm.pictograms.Diagram;
-import org.eclipse.graphiti.services.Graphiti;
-import org.eclipse.swt.graphics.Image;
-
-
-public class StructureEditor extends RoomDiagramEditor {
-
- public static final String STRUCTURE_EDITOR_ID = "org.eclipse.etrice.ui.structure.editor.StructureEditor";
-
- public StructureEditor() {
- super();
- }
-
- @Override
- public Image getDefaultImage() {
- return Activator.getImage("icons/Structure.gif");
- }
-
- /**
- * @return the actor class of this editor
- */
- public StructureClass getStructureClass() {
- Diagram diagram = getDiagramTypeProvider().getDiagram();
- EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(diagram);
- if (bo instanceof StructureClass)
- return (StructureClass) bo;
-
- return null;
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.editor;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.ui.common.editor.RoomDiagramEditor;
+import org.eclipse.etrice.ui.structure.Activator;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.swt.graphics.Image;
+
+
+public class StructureEditor extends RoomDiagramEditor {
+
+ public static final String STRUCTURE_EDITOR_ID = "org.eclipse.etrice.ui.structure.editor.StructureEditor";
+
+ public StructureEditor() {
+ super();
+ }
+
+ @Override
+ public Image getDefaultImage() {
+ return Activator.getImage("icons/Structure.gif");
+ }
+
+ /**
+ * @return the actor class of this editor
+ */
+ public StructureClass getStructureClass() {
+ Diagram diagram = getDiagramTypeProvider().getDiagram();
+ EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(diagram);
+ if (bo instanceof StructureClass)
+ return (StructureClass) bo;
+
+ return null;
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureExporter.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureExporter.java
index b2f9f779e..ccc024f22 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureExporter.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureExporter.java
@@ -1,30 +1,30 @@
-/*******************************************************************************
- * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.structure.editor;
-
-import java.io.File;
-
-import org.eclipse.etrice.core.room.StructureClass;
-import org.eclipse.etrice.ui.common.editor.DiagramExporter;
-import org.eclipse.etrice.ui.structure.DiagramAccess;
-
-public class StructureExporter {
-
- private static final String SUFFIX = "_structure";
-
- public static void export(StructureClass ac, String folder) {
- DiagramAccess da = new DiagramAccess();
- DiagramExporter.export(ac, da, folder+File.separatorChar+ac.getName()+SUFFIX);
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.editor;
+
+import java.io.File;
+
+import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.ui.common.editor.DiagramExporter;
+import org.eclipse.etrice.ui.structure.DiagramAccess;
+
+public class StructureExporter {
+
+ private static final String SUFFIX = "_structure";
+
+ public static void export(StructureClass ac, String folder) {
+ DiagramAccess da = new DiagramAccess();
+ DiagramExporter.export(ac, da, folder+File.separatorChar+ac.getName()+SUFFIX);
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/link/ExecutableExtensionFactory.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/link/ExecutableExtensionFactory.java
index d5db24c02..2a643ed66 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/link/ExecutableExtensionFactory.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/link/ExecutableExtensionFactory.java
@@ -1,29 +1,29 @@
-package org.eclipse.etrice.ui.structure.link;
-
-import static com.google.inject.Guice.createInjector;
-import static com.google.inject.util.Modules.override;
-
-import org.eclipse.etrice.ui.structure.Activator;
-import org.eclipse.xtext.ui.guice.AbstractGuiceAwareExecutableExtensionFactory;
-import org.eclipse.xtext.ui.resource.generic.EmfUiModule;
-import org.eclipse.xtext.ui.shared.SharedStateModule;
-import org.osgi.framework.Bundle;
-
-import com.google.inject.Injector;
-
-public class ExecutableExtensionFactory extends
- AbstractGuiceAwareExecutableExtensionFactory {
-
- @Override
- protected Bundle getBundle() {
- return Activator.getDefault().getBundle();
- }
-
- @Override
- protected Injector getInjector() {
- return createInjector(override(
- override(new ResourceModule()).with(new SharedStateModule()))
- .with(new EmfUiModule(Activator.getDefault())));
- }
-
-}
+package org.eclipse.etrice.ui.structure.link;
+
+import static com.google.inject.Guice.createInjector;
+import static com.google.inject.util.Modules.override;
+
+import org.eclipse.etrice.ui.structure.Activator;
+import org.eclipse.xtext.ui.guice.AbstractGuiceAwareExecutableExtensionFactory;
+import org.eclipse.xtext.ui.resource.generic.EmfUiModule;
+import org.eclipse.xtext.ui.shared.SharedStateModule;
+import org.osgi.framework.Bundle;
+
+import com.google.inject.Injector;
+
+public class ExecutableExtensionFactory extends
+ AbstractGuiceAwareExecutableExtensionFactory {
+
+ @Override
+ protected Bundle getBundle() {
+ return Activator.getDefault().getBundle();
+ }
+
+ @Override
+ protected Injector getInjector() {
+ return createInjector(override(
+ override(new ResourceModule()).with(new SharedStateModule()))
+ .with(new EmfUiModule(Activator.getDefault())));
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/link/ResourceModule.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/link/ResourceModule.java
index a34c32166..813748f2d 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/link/ResourceModule.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/link/ResourceModule.java
@@ -1,36 +1,36 @@
-/*******************************************************************************
- * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.structure.link;
-
-import org.eclipse.xtext.resource.generic.AbstractGenericResourceRuntimeModule;
-
-/**
- * @author Henrik Rentz-Reichert - initial contribution and API
- *
- */
-public class ResourceModule extends
- AbstractGenericResourceRuntimeModule {
-
- /* (non-Javadoc)
- * @see org.eclipse.xtext.resource.generic.AbstractGenericResourceRuntimeModule#getLanguageName()
- */
- @Override
- protected String getLanguageName() {
- return "org.eclipse.etrice.structure.diagrams";
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.xtext.resource.generic.AbstractGenericResourceRuntimeModule#getFileExtensions()
- */
- @Override
- protected String getFileExtensions() {
- return "structure";
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.link;
+
+import org.eclipse.xtext.resource.generic.AbstractGenericResourceRuntimeModule;
+
+/**
+ * @author Henrik Rentz-Reichert - initial contribution and API
+ *
+ */
+public class ResourceModule extends
+ AbstractGenericResourceRuntimeModule {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.xtext.resource.generic.AbstractGenericResourceRuntimeModule#getLanguageName()
+ */
+ @Override
+ protected String getLanguageName() {
+ return "org.eclipse.etrice.structure.diagrams";
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.xtext.resource.generic.AbstractGenericResourceRuntimeModule#getFileExtensions()
+ */
+ @Override
+ protected String getFileExtensions() {
+ return "structure";
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/ActorContainerRefSupport.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/ActorContainerRefSupport.java
index 3ecbaf42f..30b96ebab 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/ActorContainerRefSupport.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/ActorContainerRefSupport.java
@@ -1,1119 +1,1119 @@
-/*******************************************************************************
- * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.structure.support;
-
-import java.util.List;
-
-import org.eclipse.core.runtime.preferences.InstanceScope;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.etrice.core.naming.RoomNameProvider;
-import org.eclipse.etrice.core.room.ActorClass;
-import org.eclipse.etrice.core.room.ActorContainerClass;
-import org.eclipse.etrice.core.room.ActorContainerRef;
-import org.eclipse.etrice.core.room.ActorRef;
-import org.eclipse.etrice.core.room.InterfaceItem;
-import org.eclipse.etrice.core.room.LogicalSystem;
-import org.eclipse.etrice.core.room.RoomFactory;
-import org.eclipse.etrice.core.room.RoomPackage;
-import org.eclipse.etrice.core.room.StructureClass;
-import org.eclipse.etrice.core.room.SubSystemRef;
-import org.eclipse.etrice.core.room.util.RoomHelpers;
-import org.eclipse.etrice.ui.common.preferences.PreferenceConstants;
-import org.eclipse.etrice.ui.common.support.CommonSupportUtil;
-import org.eclipse.etrice.ui.common.support.DeleteWithoutConfirmFeature;
-import org.eclipse.etrice.ui.structure.DiagramAccess;
-import org.eclipse.etrice.ui.structure.DiagramTypeProvider;
-import org.eclipse.etrice.ui.structure.ImageProvider;
-import org.eclipse.etrice.ui.structure.dialogs.ActorContainerRefPropertyDialog;
-import org.eclipse.graphiti.dt.IDiagramTypeProvider;
-import org.eclipse.graphiti.features.IAddFeature;
-import org.eclipse.graphiti.features.ICreateConnectionFeature;
-import org.eclipse.graphiti.features.ICreateFeature;
-import org.eclipse.graphiti.features.IDeleteFeature;
-import org.eclipse.graphiti.features.IFeatureProvider;
-import org.eclipse.graphiti.features.ILayoutFeature;
-import org.eclipse.graphiti.features.IMoveShapeFeature;
-import org.eclipse.graphiti.features.IReason;
-import org.eclipse.graphiti.features.IRemoveFeature;
-import org.eclipse.graphiti.features.IResizeShapeFeature;
-import org.eclipse.graphiti.features.IUpdateFeature;
-import org.eclipse.graphiti.features.context.IAddContext;
-import org.eclipse.graphiti.features.context.ICreateContext;
-import org.eclipse.graphiti.features.context.ICustomContext;
-import org.eclipse.graphiti.features.context.IDeleteContext;
-import org.eclipse.graphiti.features.context.IDoubleClickContext;
-import org.eclipse.graphiti.features.context.ILayoutContext;
-import org.eclipse.graphiti.features.context.IMoveShapeContext;
-import org.eclipse.graphiti.features.context.IPictogramElementContext;
-import org.eclipse.graphiti.features.context.IRemoveContext;
-import org.eclipse.graphiti.features.context.IResizeShapeContext;
-import org.eclipse.graphiti.features.context.IUpdateContext;
-import org.eclipse.graphiti.features.context.impl.CreateConnectionContext;
-import org.eclipse.graphiti.features.context.impl.RemoveContext;
-import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
-import org.eclipse.graphiti.features.custom.ICustomFeature;
-import org.eclipse.graphiti.features.impl.AbstractAddFeature;
-import org.eclipse.graphiti.features.impl.AbstractCreateFeature;
-import org.eclipse.graphiti.features.impl.AbstractLayoutFeature;
-import org.eclipse.graphiti.features.impl.AbstractUpdateFeature;
-import org.eclipse.graphiti.features.impl.DefaultMoveShapeFeature;
-import org.eclipse.graphiti.features.impl.DefaultRemoveFeature;
-import org.eclipse.graphiti.features.impl.DefaultResizeShapeFeature;
-import org.eclipse.graphiti.features.impl.Reason;
-import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
-import org.eclipse.graphiti.mm.algorithms.Rectangle;
-import org.eclipse.graphiti.mm.algorithms.Text;
-import org.eclipse.graphiti.mm.algorithms.styles.Color;
-import org.eclipse.graphiti.mm.algorithms.styles.Orientation;
-import org.eclipse.graphiti.mm.pictograms.Anchor;
-import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
-import org.eclipse.graphiti.mm.pictograms.ChopboxAnchor;
-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.mm.pictograms.Shape;
-import org.eclipse.graphiti.services.Graphiti;
-import org.eclipse.graphiti.services.IGaService;
-import org.eclipse.graphiti.services.IPeCreateService;
-import org.eclipse.graphiti.tb.ContextButtonEntry;
-import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider;
-import org.eclipse.graphiti.tb.IContextButtonPadData;
-import org.eclipse.graphiti.tb.IToolBehaviorProvider;
-import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;
-import org.eclipse.graphiti.util.ColorConstant;
-import org.eclipse.graphiti.util.IColorConstant;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.preferences.ScopedPreferenceStore;
-import org.eclipse.xtext.scoping.IScope;
-import org.eclipse.xtext.scoping.IScopeProvider;
-
-public class ActorContainerRefSupport {
-
- private static final int LINE_WIDTH = 1;
- public static final int DEFAULT_SIZE_X = 120;
- public static final int DEFAULT_SIZE_Y = 80;
- public static final int MIN_SIZE_X = 100;
- public static final int MIN_SIZE_Y = 60;
- public static final int MARGIN = 30;
- private static final int SIZE_FRAME_SIZE = 25;
- private static final int REPLICATED_RECT_OFFSET = 3;
-
- public static final IColorConstant LINE_COLOR = new ColorConstant(0, 0, 0);
- public static final IColorConstant INHERITED_COLOR = new ColorConstant(100, 100, 100);
- public static final IColorConstant BACKGROUND = new ColorConstant(200, 200, 200);
-
- private static class FeatureProvider extends DefaultFeatureProvider {
-
- private class CreateFeature extends AbstractCreateFeature {
-
- private boolean actorRef;
- private boolean doneChanges = false;
-
- public CreateFeature(IFeatureProvider fp, boolean actorRef) {
- super(fp, actorRef?"ActorRef":"SubSystemRef", "create "+(actorRef?"ActorRef":"SubSystemRef"));
- this.actorRef = actorRef;
- }
-
- @Override
- public String getCreateImageId() {
- return ImageProvider.IMG_REF;
- }
-
- @Override
- public boolean canCreate(ICreateContext context) {
- if (context.getTargetContainer().getLink()!=null)
- if (context.getTargetContainer().getLink().getBusinessObjects().size()==1) {
- EObject obj = context.getTargetContainer().getLink().getBusinessObjects().get(0);
- if (obj instanceof ActorContainerClass) {
- return actorRef;
- }
- if (obj instanceof LogicalSystem) {
- return !actorRef;
- }
- }
- return false;
- }
-
- @Override
- public Object[] create(ICreateContext context) {
-
- StructureClass sc = (StructureClass) context.getTargetContainer().getLink().getBusinessObjects().get(0);
-
- ActorContainerRef newRef = null;
- if (sc instanceof ActorContainerClass) {
- ActorContainerClass acc = (ActorContainerClass) sc;
-
- // create ActorRef
- ActorRef ar = RoomFactory.eINSTANCE.createActorRef();
-
- acc.getActorRefs().add(ar);
- newRef = ar;
-
- }
- else if (sc instanceof LogicalSystem) {
- LogicalSystem sys = (LogicalSystem) sc;
-
- // create ActorRef
- SubSystemRef ssr = RoomFactory.eINSTANCE.createSubSystemRef();
-
- sys.getSubSystems().add(ssr);
- newRef = ssr;
- }
-
- newRef.setName(RoomNameProvider.getUniqueActorContainerRefName(sc));
-
- IScopeProvider scopeProvider = ((DiagramTypeProvider)getFeatureProvider().getDiagramTypeProvider()).getScopeProvider();
- EReference reference = (newRef instanceof ActorRef)?RoomPackage.eINSTANCE.getActorRef_Type():RoomPackage.eINSTANCE.getSubSystemRef_Type();
- IScope scope = scopeProvider.getScope(newRef.eContainer().eContainer(), reference);
- Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- ActorContainerRefPropertyDialog dlg = new ActorContainerRefPropertyDialog(shell, newRef, scope, sc, true);
- if (dlg.open()!=Window.OK) {
- if (sc instanceof ActorContainerClass)
- ((ActorContainerClass)sc).getActorRefs().remove(newRef);
- else if (sc instanceof LogicalSystem)
- ((LogicalSystem) sc).getSubSystems().remove(newRef);
- return EMPTY;
- }
-
- addGraphicalRepresentation(context, newRef);
- doneChanges = true;
-
- // return newly created business object(s)
- return new Object[] { newRef };
- }
-
- @Override
- public boolean hasDoneChanges() {
- return doneChanges;
- }
- }
-
- private class AddFeature extends AbstractAddFeature {
-
- public AddFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canAdd(IAddContext context) {
- if (context.getNewObject() instanceof ActorContainerRef) {
- if (context.getTargetContainer().getLink().getBusinessObjects().size()==1) {
- EObject obj = context.getTargetContainer().getLink().getBusinessObjects().get(0);
- if (obj instanceof StructureClass) {
- return true;
- }
- }
- }
- return false;
- }
-
- @Override
- public PictogramElement add(IAddContext context) {
- ActorContainerRef ar = (ActorContainerRef) context.getNewObject();
- ContainerShape acShape = context.getTargetContainer();
-
- // CONTAINER SHAPE WITH RECTANGLE
- ContainerShape containerShape =
- Graphiti.getPeCreateService().createContainerShape(acShape, true);
-
- Graphiti.getPeService().setPropertyValue(containerShape, Constants.TYPE_KEY, Constants.REF_TYPE);
-
- EObject parent = (EObject) getBusinessObjectForPictogramElement(acShape);
- boolean inherited = isInherited(ar, parent);
-
- Color lineColor = manageColor(inherited?INHERITED_COLOR:LINE_COLOR);
- {
- int width = context.getWidth() <= 0 ? DEFAULT_SIZE_X : context.getWidth();
- int height = context.getHeight() <= 0 ? DEFAULT_SIZE_Y : context.getHeight();
- final Rectangle invisibleRectangle = Graphiti.getGaService().createInvisibleRectangle(containerShape);
- Graphiti.getGaService().setLocationAndSize(invisibleRectangle,
- context.getX()-(width/2+MARGIN), context.getY()-(height/2+MARGIN), width + 2*MARGIN, height + 2*MARGIN);
-
- createRefFigure(ar, getDiagram(), containerShape, invisibleRectangle, lineColor, manageColor(BACKGROUND));
- }
-
- // create link and wire it
- link(containerShape, ar);
-
- // other child shapes may follow
- if (inherited) {
- InterfaceItemSupport.createInheritedRefItems(ar, containerShape, fp);
- }
- else {
- InterfaceItemSupport.createRefItems(ar, containerShape, fp);
- }
-
- // call the layout feature
- layoutPictogramElement(containerShape);
-
- return containerShape;
- }
-
- }
-
- private class LayoutFeature extends AbstractLayoutFeature {
-
- public LayoutFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canLayout(ILayoutContext context) {
- // return true, if pictogram element is linked to an ActorContainerRef
- PictogramElement pe = context.getPictogramElement();
- if (!(pe instanceof ContainerShape))
- return false;
-
- EList<EObject> businessObjects = pe.getLink().getBusinessObjects();
- return businessObjects.size() == 1
- && businessObjects.get(0) instanceof ActorContainerRef;
- }
-
- @Override
- public boolean layout(ILayoutContext context) {
- boolean anythingChanged = false;
- ContainerShape containerShape = (ContainerShape) context
- .getPictogramElement();
-
- // our invisible rectangle
- GraphicsAlgorithm containerGa = containerShape.getGraphicsAlgorithm();
-
- int w = containerGa.getWidth();
- int h = containerGa.getHeight();
- int nw = w-2*MARGIN;
- int nh = h-2*MARGIN;
-
- /**
- * TODO: (Keplar) use Ids to identify GraphicsAlgorithm children
- * see Graphiti example "filesystem"
- * (org.eclipse.graphiti.examples.filesystem.patterns.FolderPattern)
- */
- if(containerGa.getGraphicsAlgorithmChildren().size()>=1){
- GraphicsAlgorithm borderRect = null;
- Object obj = getBusinessObjectForPictogramElement(containerShape);
- if(obj instanceof ActorRef && ((ActorRef)obj).getSize()>1){
- GraphicsAlgorithm replBorder = containerGa.getGraphicsAlgorithmChildren().get(0);
- replBorder.setWidth(nw);
- replBorder.setHeight(nh);
- borderRect = containerGa.getGraphicsAlgorithmChildren().get(1);
- GraphicsAlgorithm replFrame = containerGa.getGraphicsAlgorithmChildren().get(2);
- replFrame.setX(MARGIN+nw-SIZE_FRAME_SIZE);
- } else
- borderRect = containerGa.getGraphicsAlgorithmChildren().get(0);
-
- borderRect.setWidth(nw);
- borderRect.setHeight(nh);
- Object bo = getBusinessObjectForPictogramElement(containerShape);
- if (bo instanceof ActorContainerRef) {
- ActorContainerRef acr = (ActorContainerRef) bo;
- EObject parent = containerShape.getContainer().getLink().getBusinessObjects().get(0);
- Color lineColor = manageColor(isInherited(acr, parent)?INHERITED_COLOR:LINE_COLOR);
- // remove and recreate substructure hint
- while (!borderRect.getGraphicsAlgorithmChildren().isEmpty()) {
- EcoreUtil.delete(borderRect.getGraphicsAlgorithmChildren().get(0), true);
- }
- addSubStructureHint(acr, (Rectangle) borderRect, lineColor);
- }
-
- if (!containerShape.getChildren().isEmpty()) {
- GraphicsAlgorithm childGA = containerShape.getChildren().get(0).getGraphicsAlgorithm();
- assert(childGA instanceof Text): "label expected";
- childGA.setWidth(nw);
- childGA.setHeight(nh);
-
- if(obj instanceof ActorRef && ((ActorRef)obj).getSize()>1){
- GraphicsAlgorithm replLabel = containerShape.getChildren().get(1).getGraphicsAlgorithm();
- replLabel.setX(MARGIN+nw-SIZE_FRAME_SIZE);
- }
- }
-
- anythingChanged = true;
- }
-
- return anythingChanged;
- }
- }
-
- private static class PropertyFeature extends AbstractCustomFeature {
-
- private boolean doneChanges = false;
-
- public PropertyFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public String getName() {
- return "Edit Reference...";
- }
-
- @Override
- public String getDescription() {
- return "Edit Reference Properties";
- }
-
- @Override
- public boolean canExecute(ICustomContext context) {
- PictogramElement[] pes = context.getPictogramElements();
- if (pes != null && pes.length == 1) {
- Object bo = getBusinessObjectForPictogramElement(pes[0]);
- if (bo instanceof ActorContainerRef) {
- EObject parent = (EObject) getBusinessObjectForPictogramElement((PictogramElement) pes[0].eContainer());
- return !isInherited((ActorContainerRef)bo, parent);
- }
- }
- return false;
- }
-
- @Override
- public void execute(ICustomContext context) {
- ContainerShape containerShape = (ContainerShape) context.getPictogramElements()[0];
- ActorContainerRef acr = (ActorContainerRef) getBusinessObjectForPictogramElement(containerShape);
- StructureClass sc = (StructureClass)acr.eContainer();
-
- IScopeProvider scopeProvider = ((DiagramTypeProvider)getFeatureProvider().getDiagramTypeProvider()).getScopeProvider();
- EReference reference = (acr instanceof ActorRef)?RoomPackage.eINSTANCE.getActorRef_Type():RoomPackage.eINSTANCE.getSubSystemRef_Type();
- IScope scope = scopeProvider.getScope(acr.eContainer().eContainer(), reference);
- Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- ActorContainerRefPropertyDialog dlg = new ActorContainerRefPropertyDialog(shell, acr, scope, sc, false);
- if (dlg.open()!=Window.OK)
- return;
-
- doneChanges = true;
- //updateLabel(acr, context.getPictogramElements()[0]);
-
- EObject parent = (EObject) getBusinessObjectForPictogramElement(containerShape.getContainer());
- boolean inherited = isInherited(acr, parent);
- Color lineColor = manageColor(inherited?INHERITED_COLOR:LINE_COLOR);
- createRefFigure(acr, getDiagram(), containerShape, (Rectangle)containerShape.getGraphicsAlgorithm(), lineColor, manageColor(BACKGROUND));
- }
-
- @Override
- public boolean hasDoneChanges() {
- return doneChanges;
- }
-
- }
-
- private static class OpenRefStructureDiagram extends AbstractCustomFeature {
-
- public OpenRefStructureDiagram(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public String getName() {
- return "Open Ref Structure";
- }
-
- @Override
- public boolean canExecute(ICustomContext context) {
- PictogramElement[] pes = context.getPictogramElements();
- if (pes != null && pes.length == 1) {
- Object bo = getBusinessObjectForPictogramElement(pes[0]);
- if (bo instanceof ActorContainerRef) {
- return true;
- }
- }
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.graphiti.features.custom.ICustomFeature#execute(org.eclipse.graphiti.features.context.ICustomContext)
- */
- @Override
- public void execute(ICustomContext context) {
- PictogramElement[] pes = context.getPictogramElements();
- if (pes != null && pes.length == 1) {
- Object bo = getBusinessObjectForPictogramElement(pes[0]);
- if (bo instanceof ActorContainerRef) {
- final ActorContainerRef ref = (ActorContainerRef) bo;
- Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- shell.getDisplay().asyncExec(new Runnable() {
- @Override
- public void run() {
- DiagramAccess diagramAccess = new DiagramAccess();
- if (ref instanceof ActorRef) {
- diagramAccess.openDiagramEditor(((ActorRef) ref).getType());
- }
- else if (ref instanceof SubSystemRef) {
- diagramAccess.openDiagramEditor(((SubSystemRef) ref).getType());
- }
- }
- });
- }
- }
- }
-
- @Override
- public boolean hasDoneChanges() {
- return false;
- }
- }
-
- private static class OpenRefBehaviorDiagram extends AbstractCustomFeature {
-
- public OpenRefBehaviorDiagram(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public String getName() {
- return "Open Ref Behavior";
- }
-
- @Override
- public boolean canExecute(ICustomContext context) {
- PictogramElement[] pes = context.getPictogramElements();
- if (pes != null && pes.length == 1) {
- Object bo = getBusinessObjectForPictogramElement(pes[0]);
- if (bo instanceof ActorRef) {
- return true;
- }
- }
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.graphiti.features.custom.ICustomFeature#execute(org.eclipse.graphiti.features.context.ICustomContext)
- */
- @Override
- public void execute(ICustomContext context) {
- PictogramElement[] pes = context.getPictogramElements();
- if (pes != null && pes.length == 1) {
- Object bo = getBusinessObjectForPictogramElement(pes[0]);
- if (bo instanceof ActorContainerRef) {
- final ActorContainerRef ref = (ActorContainerRef) bo;
- Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- shell.getDisplay().asyncExec(new Runnable() {
- @Override
- public void run() {
- org.eclipse.etrice.ui.behavior.DiagramAccess diagramAccess = new org.eclipse.etrice.ui.behavior.DiagramAccess();
- if (ref instanceof ActorRef) {
- diagramAccess.openDiagramEditor(((ActorRef) ref).getType());
- }
- }
- });
- }
- }
- }
-
- @Override
- public boolean hasDoneChanges() {
- ScopedPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, "org.eclipse.etrice.ui.common");
- boolean autoSave = store.getBoolean(PreferenceConstants.SAVE_DIAG_ON_FOCUS_LOST);
- if (autoSave)
- return true; // this is needed to trigger the save via a CommandStackListener after this command is completed
- else
- return false;
- }
- }
-
- private class UpdateFeature extends AbstractUpdateFeature {
-
- public UpdateFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canUpdate(IUpdateContext context) {
- Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
- if (bo instanceof EObject && ((EObject)bo).eIsProxy())
- return true;
-
- return bo instanceof ActorContainerRef;
- }
-
- @Override
- public IReason updateNeeded(IUpdateContext context) {
- Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
- if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
- return Reason.createTrueReason("Ref deleted from model");
- }
- ActorContainerRef acr = (ActorContainerRef) bo;
- ContainerShape containerShape = (ContainerShape)context.getPictogramElement();
- GraphicsAlgorithm invisibleRect = containerShape.getGraphicsAlgorithm();
- int borderShapeId = 0;
-
- String reason = "";
-
- // check replicated
- if(acr instanceof ActorRef){
- if(((ActorRef)acr).getSize()>1){
- if(invisibleRect.getGraphicsAlgorithmChildren().size() < 3)
- reason += "ActorRef got replicated";
- else
- borderShapeId = 1;
- } else {
- if(invisibleRect.getGraphicsAlgorithmChildren().size() > 2){
- reason += "ActorRef is not replicated anymore";
- borderShapeId = 1;
- }
- }
- }
-
- // check if ref still owned/inherited anymore
- bo = getBusinessObjectForPictogramElement(containerShape);
- if (bo instanceof ActorClass) {
- ActorClass ac = (ActorClass) bo;
- boolean found = false;
- do {
- if (ac==acr.eContainer())
- found = true;
- ac = ac.getBase();
- }
- while (!found && ac!=null);
-
- if (!found)
- reason += "Ref not inherited anymore\n";
- }
-
- // check sub structure hint
- {
- boolean hasSubStruct = hasSubStructure(acr);
- if (!invisibleRect.getGraphicsAlgorithmChildren().isEmpty()) {
- GraphicsAlgorithm borderRect = invisibleRect.getGraphicsAlgorithmChildren().get(borderShapeId);
- if (!borderRect.getGraphicsAlgorithmChildren().isEmpty()) {
- GraphicsAlgorithm hint = borderRect.getGraphicsAlgorithmChildren().get(0);
- if (hasSubStruct && !hint.getLineVisible())
- reason += "state has sub structure now\n";
- if (!hasSubStruct && hint.getLineVisible())
- reason += "state has no sub structure anymore\n";
- }
- }
- }
-
- // check class name
- if (!containerShape.getChildren().isEmpty()) {
- GraphicsAlgorithm ga = containerShape.getChildren().get(0).getGraphicsAlgorithm();
- if (ga instanceof Text) {
- if (bo instanceof ActorContainerRef) {
- String label = RoomNameProvider.getRefLabelName((ActorContainerRef) bo);
- if (!((Text)ga).getValue().equals(label))
- reason += "Class name is out of date\n";
- }
- }
- }
-
- // check replicated label
- if(acr instanceof ActorRef && ((ActorRef)acr).getSize()>1){
- if(containerShape.getChildren().size() >= 2){
- GraphicsAlgorithm ga = containerShape.getChildren().get(1).getGraphicsAlgorithm();
- if (ga instanceof Text) {
- if(!((Text)ga).getValue().equals(((ActorRef)acr).getSize()+""))
- reason += "multiciply changed";
- }
- }
- }
-
- // check interface ports and spps added to model not present in diagram
- {
- ActorContainerClass acc = (acr instanceof ActorRef)?((ActorRef)acr).getType():((SubSystemRef)acr).getType();
- List<InterfaceItem> interfaceItems = RoomHelpers.getInterfaceItems(acc, true);
- List<InterfaceItem> presentItems = SupportUtil.getInterfaceItems(containerShape, fp);
- int missing = 0;
- for (InterfaceItem interfaceItem : interfaceItems) {
- if (!presentItems.contains(interfaceItem))
- ++missing;
- }
- if (missing>0)
- reason += missing+" interface item(s) missing\n";
- }
-
- if (!reason.isEmpty())
- return Reason.createTrueReason(reason.substring(0, reason.length()-1));
-
- return Reason.createFalseReason();
- }
-
- @Override
- public boolean update(IUpdateContext context) {
- ContainerShape containerShape = (ContainerShape)context.getPictogramElement();
- Object bo = getBusinessObjectForPictogramElement(containerShape);
- if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
- IRemoveContext rc = new RemoveContext(containerShape);
- IFeatureProvider featureProvider = getFeatureProvider();
- IRemoveFeature removeFeature = featureProvider.getRemoveFeature(rc);
- if (removeFeature != null) {
- removeFeature.remove(rc);
- }
- EcoreUtil.delete((EObject) bo);
- return true;
- }
-
- GraphicsAlgorithm invisibleRect = containerShape.getGraphicsAlgorithm();
- ActorContainerRef acr = (ActorContainerRef) bo;
- int borderRectId = 0;
-
- // check replicated
- if(acr instanceof ActorRef){
- if(((ActorRef)acr).getSize()>1){
- if(invisibleRect.getGraphicsAlgorithmChildren().size() < 3){
-
- IGaService gaService = Graphiti.getGaService();
- int width = invisibleRect.getWidth()-2*MARGIN;
- int height = invisibleRect.getHeight()-2*MARGIN;
- EObject parent = (EObject) getBusinessObjectForPictogramElement(containerShape.getContainer());
- Color lineColor = manageColor(isInherited(acr, parent)?INHERITED_COLOR:LINE_COLOR);
-
- Rectangle replRect = gaService.createRectangle(invisibleRect);
- replRect.setForeground(lineColor);
- replRect.setBackground(manageColor(BACKGROUND));
- replRect.setLineWidth(LINE_WIDTH);
- gaService.setLocationAndSize(replRect, MARGIN+REPLICATED_RECT_OFFSET, MARGIN-REPLICATED_RECT_OFFSET, width, height);
- invisibleRect.getGraphicsAlgorithmChildren().move(0, replRect);
-
- Rectangle sizeFrame = gaService.createRectangle(invisibleRect);
- sizeFrame.setForeground(lineColor);
- sizeFrame.setBackground(manageColor(BACKGROUND));
- sizeFrame.setLineWidth(LINE_WIDTH);
- gaService.setLocationAndSize(sizeFrame, MARGIN+width-SIZE_FRAME_SIZE, MARGIN, SIZE_FRAME_SIZE, SIZE_FRAME_SIZE);
- invisibleRect.getGraphicsAlgorithmChildren().move(2, sizeFrame);
-
- Shape labelShape = Graphiti.getPeCreateService().createShape(containerShape, false);
- Integer size = ((ActorRef)acr).getSize();
- Text label = gaService.createDefaultText(getDiagram(), labelShape, size.toString());
- label.setForeground(lineColor);
- label.setBackground(lineColor);
- label.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
- label.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
- gaService.setLocationAndSize(label, MARGIN+width-SIZE_FRAME_SIZE, MARGIN, SIZE_FRAME_SIZE, SIZE_FRAME_SIZE);
- containerShape.getChildren().move(1, labelShape);
- }
- borderRectId = 1;
- } else {
- if(invisibleRect.getGraphicsAlgorithmChildren().size() > 2){
- EcoreUtil.delete(invisibleRect.getGraphicsAlgorithmChildren().get(2), true);
- EcoreUtil.delete(invisibleRect.getGraphicsAlgorithmChildren().get(0), true);
- EcoreUtil.delete(containerShape.getChildren().get(1), true);
- }
- }
- }
- {
- if (!invisibleRect.getGraphicsAlgorithmChildren().isEmpty()) {
- GraphicsAlgorithm borderRect = invisibleRect.getGraphicsAlgorithmChildren().get(borderRectId);
- updateSubStructureHint(acr, (Rectangle) borderRect);
- }
- }
-
- updateLabel(acr, context.getPictogramElement());
-
- InterfaceItemSupport.createRefItems(acr, containerShape, fp);
-
- return true;
- }
- }
-
- private class RemoveFeature extends DefaultRemoveFeature {
-
- public RemoveFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canRemove(IRemoveContext context) {
- return false;
- }
- }
-
- private class DeleteFeature extends DeleteWithoutConfirmFeature {
-
- public DeleteFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canDelete(IDeleteContext context) {
- Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
-
- if (bo instanceof ActorContainerRef) {
- ActorContainerRef ar = (ActorContainerRef) bo;
- ContainerShape acShape = (ContainerShape) context.getPictogramElement().eContainer();
- EObject parent = acShape.getLink().getBusinessObjects().get(0);
- return !isInherited(ar, parent);
- }
-
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.graphiti.ui.features.DefaultDeleteFeature#preDelete(org.eclipse.graphiti.features.context.IDeleteContext)
- */
- @Override
- public void preDelete(IDeleteContext context) {
- super.preDelete(context);
-
- if (!(context.getPictogramElement() instanceof ContainerShape))
- return;
-
- ContainerShape container = (ContainerShape) context.getPictogramElement();
- CommonSupportUtil.deleteConnectionsRecursive(container, getFeatureProvider());
- }
- }
-
- private class MoveShapeFeature extends DefaultMoveShapeFeature {
-
- public MoveShapeFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canMoveShape(IMoveShapeContext context) {
- boolean canMove = super.canMoveShape(context);
-
- if (canMove) {
- Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
-
- if (bo instanceof ActorContainerRef) {
- ActorContainerRef ar = (ActorContainerRef) bo;
- ContainerShape acShape = context.getTargetContainer();
- EObject parent = acShape.getLink().getBusinessObjects().get(0);
-
- // TODOHRR: also check coordinates (no overlap with actor boundaries)
-
- return !isInherited(ar, parent);
- }
- }
-
- return canMove;
- }
- }
-
- private class ResizeFeature extends DefaultResizeShapeFeature {
-
- public ResizeFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canResizeShape(IResizeShapeContext context) {
- if (!super.canResizeShape(context))
- return false;
-
- int width = context.getWidth()-MARGIN;
- int height = context.getHeight()-MARGIN;
- if (width>0 && height>0)
- if (width < MIN_SIZE_X+MARGIN || height < MIN_SIZE_Y+MARGIN)
- return false;
-
- return true;
- }
-
- @Override
- public void resizeShape(IResizeShapeContext context) {
- Shape shape = context.getShape();
-
- if (shape.getGraphicsAlgorithm()!=null) {
- GraphicsAlgorithm containerGa = shape.getGraphicsAlgorithm();
- double sx = (context.getWidth()-2*MARGIN)/(double)(containerGa.getWidth()-2*MARGIN);
- double sy = (context.getHeight()-2*MARGIN)/(double)(containerGa.getHeight()-2*MARGIN);
-
- GraphicsAlgorithm ga;
- for (Shape childShape : ((ContainerShape)context.getShape()).getChildren()) {
- Object childBo = getBusinessObjectForPictogramElement(childShape);
- if (childBo instanceof InterfaceItem) {
- ga = childShape.getGraphicsAlgorithm();
- ga.setX((int) (ga.getX()*sx));
- ga.setY((int) (ga.getY()*sy));
- }
-
- }
- }
- super.resizeShape(context);
- }
- }
-
- private IFeatureProvider fp;
-
- public FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp) {
- super(dtp);
- this.fp = fp;
- }
-
- @Override
- public ICreateFeature[] getCreateFeatures() {
- return new ICreateFeature[] { new CreateFeature(fp, true), new CreateFeature(fp, false) };
- }
-
- @Override
- public IAddFeature getAddFeature(IAddContext context) {
- return new AddFeature(fp);
- }
-
- @Override
- public ILayoutFeature getLayoutFeature(ILayoutContext context) {
- return new LayoutFeature(fp);
- }
-
- @Override
- public IUpdateFeature getUpdateFeature(IUpdateContext context) {
- return new UpdateFeature(fp);
- }
-
- @Override
- public IMoveShapeFeature getMoveShapeFeature(IMoveShapeContext context) {
- return new MoveShapeFeature(fp);
- }
-
- @Override
- public IResizeShapeFeature getResizeShapeFeature(
- IResizeShapeContext context) {
- return new ResizeFeature(fp);
- }
-
- @Override
- public IRemoveFeature getRemoveFeature(IRemoveContext context) {
- return new RemoveFeature(fp);
- }
-
- @Override
- public IDeleteFeature getDeleteFeature(IDeleteContext context) {
- return new DeleteFeature(fp);
- }
-
- @Override
- public ICustomFeature[] getCustomFeatures(ICustomContext context) {
- return new ICustomFeature[] {
- new PropertyFeature(fp),
- new OpenRefStructureDiagram(fp),
- new OpenRefBehaviorDiagram(fp)};
- }
-
- protected static boolean isInherited(ActorContainerRef ar, EObject parent) {
- return ar.eContainer()!=parent;
- }
-
- protected static void updateSubStructureHint(ActorContainerRef acr, GraphicsAlgorithm borderRect) {
-
- boolean hasSubStructure = hasSubStructure(acr);
- GraphicsAlgorithm hint = borderRect.getGraphicsAlgorithmChildren().get(0);
- hint.setLineVisible(hasSubStructure);
- hint = borderRect.getGraphicsAlgorithmChildren().get(1);
- hint.setLineVisible(hasSubStructure);
- }
-
- private static void updateLabel(ActorContainerRef acr, PictogramElement pe) {
- ContainerShape container = (ContainerShape)pe;
-
- // TODO: identify children properly
- if (!container.getChildren().isEmpty()) {
- GraphicsAlgorithm actorLabel = container.getChildren().get(0).getGraphicsAlgorithm();
- if (actorLabel instanceof Text)
- ((Text)actorLabel).setValue(RoomNameProvider.getRefLabelName(acr));
-
- if(acr instanceof ActorRef && ((ActorRef)acr).getSize()>1){
- if(container.getChildren().size()>1){
- GraphicsAlgorithm replLabel = container.getChildren().get(1).getGraphicsAlgorithm();
- if (replLabel instanceof Text)
- ((Text)replLabel).setValue(((ActorRef)acr).getSize()+"");
- }
- }
- }
- }
- }
-
- private class BehaviorProvider extends DefaultToolBehaviorProvider {
-
- public BehaviorProvider(IDiagramTypeProvider dtp) {
- super(dtp);
- }
-
- @Override
- public GraphicsAlgorithm[] getClickArea(PictogramElement pe) {
- GraphicsAlgorithm invisible = pe.getGraphicsAlgorithm();
- GraphicsAlgorithm rectangle =
- invisible.getGraphicsAlgorithmChildren().get(0);
- return new GraphicsAlgorithm[] { rectangle };
- }
-
- @Override
- public GraphicsAlgorithm getSelectionBorder(PictogramElement pe) {
- GraphicsAlgorithm invisible = pe.getGraphicsAlgorithm();
-
- GraphicsAlgorithm rectangle =
- invisible.getGraphicsAlgorithmChildren().get(0);
- return rectangle;
- }
-
- @Override
- public ICustomFeature getDoubleClickFeature(IDoubleClickContext context) {
- return new FeatureProvider.OpenRefStructureDiagram(getDiagramTypeProvider().getFeatureProvider());
- }
-
- @Override
- public IContextButtonPadData getContextButtonPad(
- IPictogramElementContext context) {
-
- IContextButtonPadData data = super.getContextButtonPad(context);
- PictogramElement pe = context.getPictogramElement();
-
- CreateConnectionContext ccc = new CreateConnectionContext();
- ccc.setSourcePictogramElement(pe);
- Anchor anchor = null;
- if (pe instanceof AnchorContainer) {
- // our spp has four fixed point anchor - we choose the first one
- anchor = ((ContainerShape)pe).getAnchors().get(0);
- }
- ccc.setSourceAnchor(anchor);
-
- ContextButtonEntry button = new ContextButtonEntry(null, context);
- button.setText("Create Layer Connection");
- button.setIconId(ImageProvider.IMG_LAYER_CONNECTION);
- ICreateConnectionFeature[] features = getFeatureProvider().getCreateConnectionFeatures();
- for (ICreateConnectionFeature feature : features) {
- if (feature.isAvailable(ccc) && feature.canStartConnection(ccc))
- button.addDragAndDropFeature(feature);
- }
-
- if (button.getDragAndDropFeatures().size() > 0) {
- data.getDomainSpecificContextButtons().add(button);
- }
-
- return data;
- }
- }
-
- private static void createRefFigure(ActorContainerRef ar,
- Diagram diagram, ContainerShape containerShape, final Rectangle invisibleRectangle,
- Color lineColor, Color bgColor) {
-
- invisibleRectangle.getGraphicsAlgorithmChildren().clear();
- if (!containerShape.getChildren().isEmpty()) {
- // potentially there are two text labels which we remove before re-creating
- Shape shape = containerShape.getChildren().get(0);
- if (shape.getGraphicsAlgorithm() instanceof Text)
- containerShape.getChildren().remove(0);
- shape = containerShape.getChildren().get(0);
- if (shape.getGraphicsAlgorithm() instanceof Text)
- containerShape.getChildren().remove(0);
- }
-
- int width = invisibleRectangle.getWidth()-2*MARGIN;
- int height = invisibleRectangle.getHeight()-2*MARGIN;
-
- IGaService gaService = Graphiti.getGaService();
- if (ar instanceof ActorRef && ((ActorRef)ar).getSize()>1) {
- Rectangle rect = gaService.createRectangle(invisibleRectangle);
- rect.setForeground(lineColor);
- rect.setBackground(bgColor);
- rect.setLineWidth(LINE_WIDTH);
- gaService.setLocationAndSize(rect, MARGIN+REPLICATED_RECT_OFFSET, MARGIN-REPLICATED_RECT_OFFSET, width, height);
- }
-
- Rectangle borderRect = gaService.createRectangle(invisibleRectangle);
- borderRect.setForeground(lineColor);
- borderRect.setBackground(bgColor);
- borderRect.setLineWidth(LINE_WIDTH);
- gaService.setLocationAndSize(borderRect, MARGIN, MARGIN, width, height);
-
- if (ar instanceof ActorRef && ((ActorRef)ar).getSize()>1) {
- Rectangle sizeFrame = gaService.createRectangle(invisibleRectangle);
- sizeFrame.setForeground(lineColor);
- sizeFrame.setBackground(bgColor);
- sizeFrame.setLineWidth(LINE_WIDTH);
- gaService.setLocationAndSize(sizeFrame, MARGIN+width-SIZE_FRAME_SIZE, MARGIN, SIZE_FRAME_SIZE, SIZE_FRAME_SIZE);
- }
-
- addSubStructureHint(ar, borderRect, lineColor);
-
- IPeCreateService peCreateService = Graphiti.getPeCreateService();
-
- // anchor for layer connections
- if (containerShape.getAnchors().isEmpty()) {
- ChopboxAnchor anchor = peCreateService.createChopboxAnchor(containerShape);
- anchor.setReferencedGraphicsAlgorithm(borderRect);
- }
- else {
- // we just set the referenced GA
- containerShape.getAnchors().get(0).setReferencedGraphicsAlgorithm(borderRect);
- }
-
- // the first child shape is the label
- {
- Shape labelShape = peCreateService.createShape(containerShape, false);
- Text label = gaService.createDefaultText(diagram, labelShape, RoomNameProvider.getRefLabelName(ar));
- label.setForeground(lineColor);
- label.setBackground(lineColor);
- label.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
- label.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
- gaService.setLocationAndSize(label, MARGIN, MARGIN, width, height);
- }
-
- if (ar instanceof ActorRef && ((ActorRef)ar).getSize()>1) {
- Shape labelShape = peCreateService.createShape(containerShape, false);
- Integer size = ((ActorRef)ar).getSize();
- Text label = gaService.createDefaultText(diagram, labelShape, size.toString());
- label.setForeground(lineColor);
- label.setBackground(lineColor);
- label.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
- label.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
- gaService.setLocationAndSize(label, MARGIN+width-SIZE_FRAME_SIZE, MARGIN, SIZE_FRAME_SIZE, SIZE_FRAME_SIZE);
- }
- }
-
- private static void addSubStructureHint(ActorContainerRef acr,
- Rectangle borderRect, Color lineColor) {
-
- int x = borderRect.getWidth()-35;
- int y = borderRect.getHeight()-30;
- IGaService gaService = Graphiti.getGaService();
- Rectangle hint1 = gaService.createRectangle(borderRect);
- hint1.setForeground(lineColor);
- hint1.setFilled(false);
- hint1.setLineWidth(LINE_WIDTH);
- gaService.setLocationAndSize(hint1, x+5, y, 20, 10);
- Rectangle hint2 = gaService.createRectangle(borderRect);
- hint2.setForeground(lineColor);
- hint2.setFilled(false);
- hint2.setLineWidth(LINE_WIDTH);
- gaService.setLocationAndSize(hint2, x, y+15, 20, 10);
-
- if (!hasSubStructure(acr)) {
- hint1.setLineVisible(false);
- hint2.setLineVisible(false);
- }
- }
-
- private static boolean hasSubStructure(ActorContainerRef acr) {
- if (acr instanceof ActorRef) {
- if (!((ActorRef) acr).getType().getActorRefs().isEmpty())
- return true;
- }
- else if (acr instanceof SubSystemRef) {
- if (!((SubSystemRef)acr).getType().getActorRefs().isEmpty())
- return true;
- }
- return false;
- }
-
- private FeatureProvider pfp;
- private BehaviorProvider tbp;
-
- public ActorContainerRefSupport(IDiagramTypeProvider dtp, IFeatureProvider fp) {
- pfp = new FeatureProvider(dtp,fp);
- tbp = new BehaviorProvider(dtp);
- }
-
- public IFeatureProvider getFeatureProvider() {
- return pfp;
- }
-
- public IToolBehaviorProvider getToolBehaviorProvider() {
- return tbp;
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.support;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.etrice.core.naming.RoomNameProvider;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.ActorContainerClass;
+import org.eclipse.etrice.core.room.ActorContainerRef;
+import org.eclipse.etrice.core.room.ActorRef;
+import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.etrice.core.room.LogicalSystem;
+import org.eclipse.etrice.core.room.RoomFactory;
+import org.eclipse.etrice.core.room.RoomPackage;
+import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.core.room.SubSystemRef;
+import org.eclipse.etrice.core.room.util.RoomHelpers;
+import org.eclipse.etrice.ui.common.preferences.PreferenceConstants;
+import org.eclipse.etrice.ui.common.support.CommonSupportUtil;
+import org.eclipse.etrice.ui.common.support.DeleteWithoutConfirmFeature;
+import org.eclipse.etrice.ui.structure.DiagramAccess;
+import org.eclipse.etrice.ui.structure.DiagramTypeProvider;
+import org.eclipse.etrice.ui.structure.ImageProvider;
+import org.eclipse.etrice.ui.structure.dialogs.ActorContainerRefPropertyDialog;
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.features.IAddFeature;
+import org.eclipse.graphiti.features.ICreateConnectionFeature;
+import org.eclipse.graphiti.features.ICreateFeature;
+import org.eclipse.graphiti.features.IDeleteFeature;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.ILayoutFeature;
+import org.eclipse.graphiti.features.IMoveShapeFeature;
+import org.eclipse.graphiti.features.IReason;
+import org.eclipse.graphiti.features.IRemoveFeature;
+import org.eclipse.graphiti.features.IResizeShapeFeature;
+import org.eclipse.graphiti.features.IUpdateFeature;
+import org.eclipse.graphiti.features.context.IAddContext;
+import org.eclipse.graphiti.features.context.ICreateContext;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.context.IDeleteContext;
+import org.eclipse.graphiti.features.context.IDoubleClickContext;
+import org.eclipse.graphiti.features.context.ILayoutContext;
+import org.eclipse.graphiti.features.context.IMoveShapeContext;
+import org.eclipse.graphiti.features.context.IPictogramElementContext;
+import org.eclipse.graphiti.features.context.IRemoveContext;
+import org.eclipse.graphiti.features.context.IResizeShapeContext;
+import org.eclipse.graphiti.features.context.IUpdateContext;
+import org.eclipse.graphiti.features.context.impl.CreateConnectionContext;
+import org.eclipse.graphiti.features.context.impl.RemoveContext;
+import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
+import org.eclipse.graphiti.features.custom.ICustomFeature;
+import org.eclipse.graphiti.features.impl.AbstractAddFeature;
+import org.eclipse.graphiti.features.impl.AbstractCreateFeature;
+import org.eclipse.graphiti.features.impl.AbstractLayoutFeature;
+import org.eclipse.graphiti.features.impl.AbstractUpdateFeature;
+import org.eclipse.graphiti.features.impl.DefaultMoveShapeFeature;
+import org.eclipse.graphiti.features.impl.DefaultRemoveFeature;
+import org.eclipse.graphiti.features.impl.DefaultResizeShapeFeature;
+import org.eclipse.graphiti.features.impl.Reason;
+import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.algorithms.Rectangle;
+import org.eclipse.graphiti.mm.algorithms.Text;
+import org.eclipse.graphiti.mm.algorithms.styles.Color;
+import org.eclipse.graphiti.mm.algorithms.styles.Orientation;
+import org.eclipse.graphiti.mm.pictograms.Anchor;
+import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
+import org.eclipse.graphiti.mm.pictograms.ChopboxAnchor;
+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.mm.pictograms.Shape;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.IGaService;
+import org.eclipse.graphiti.services.IPeCreateService;
+import org.eclipse.graphiti.tb.ContextButtonEntry;
+import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider;
+import org.eclipse.graphiti.tb.IContextButtonPadData;
+import org.eclipse.graphiti.tb.IToolBehaviorProvider;
+import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;
+import org.eclipse.graphiti.util.ColorConstant;
+import org.eclipse.graphiti.util.IColorConstant;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.preferences.ScopedPreferenceStore;
+import org.eclipse.xtext.scoping.IScope;
+import org.eclipse.xtext.scoping.IScopeProvider;
+
+public class ActorContainerRefSupport {
+
+ private static final int LINE_WIDTH = 1;
+ public static final int DEFAULT_SIZE_X = 120;
+ public static final int DEFAULT_SIZE_Y = 80;
+ public static final int MIN_SIZE_X = 100;
+ public static final int MIN_SIZE_Y = 60;
+ public static final int MARGIN = 30;
+ private static final int SIZE_FRAME_SIZE = 25;
+ private static final int REPLICATED_RECT_OFFSET = 3;
+
+ public static final IColorConstant LINE_COLOR = new ColorConstant(0, 0, 0);
+ public static final IColorConstant INHERITED_COLOR = new ColorConstant(100, 100, 100);
+ public static final IColorConstant BACKGROUND = new ColorConstant(200, 200, 200);
+
+ private static class FeatureProvider extends DefaultFeatureProvider {
+
+ private class CreateFeature extends AbstractCreateFeature {
+
+ private boolean actorRef;
+ private boolean doneChanges = false;
+
+ public CreateFeature(IFeatureProvider fp, boolean actorRef) {
+ super(fp, actorRef?"ActorRef":"SubSystemRef", "create "+(actorRef?"ActorRef":"SubSystemRef"));
+ this.actorRef = actorRef;
+ }
+
+ @Override
+ public String getCreateImageId() {
+ return ImageProvider.IMG_REF;
+ }
+
+ @Override
+ public boolean canCreate(ICreateContext context) {
+ if (context.getTargetContainer().getLink()!=null)
+ if (context.getTargetContainer().getLink().getBusinessObjects().size()==1) {
+ EObject obj = context.getTargetContainer().getLink().getBusinessObjects().get(0);
+ if (obj instanceof ActorContainerClass) {
+ return actorRef;
+ }
+ if (obj instanceof LogicalSystem) {
+ return !actorRef;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public Object[] create(ICreateContext context) {
+
+ StructureClass sc = (StructureClass) context.getTargetContainer().getLink().getBusinessObjects().get(0);
+
+ ActorContainerRef newRef = null;
+ if (sc instanceof ActorContainerClass) {
+ ActorContainerClass acc = (ActorContainerClass) sc;
+
+ // create ActorRef
+ ActorRef ar = RoomFactory.eINSTANCE.createActorRef();
+
+ acc.getActorRefs().add(ar);
+ newRef = ar;
+
+ }
+ else if (sc instanceof LogicalSystem) {
+ LogicalSystem sys = (LogicalSystem) sc;
+
+ // create ActorRef
+ SubSystemRef ssr = RoomFactory.eINSTANCE.createSubSystemRef();
+
+ sys.getSubSystems().add(ssr);
+ newRef = ssr;
+ }
+
+ newRef.setName(RoomNameProvider.getUniqueActorContainerRefName(sc));
+
+ IScopeProvider scopeProvider = ((DiagramTypeProvider)getFeatureProvider().getDiagramTypeProvider()).getScopeProvider();
+ EReference reference = (newRef instanceof ActorRef)?RoomPackage.eINSTANCE.getActorRef_Type():RoomPackage.eINSTANCE.getSubSystemRef_Type();
+ IScope scope = scopeProvider.getScope(newRef.eContainer().eContainer(), reference);
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ ActorContainerRefPropertyDialog dlg = new ActorContainerRefPropertyDialog(shell, newRef, scope, sc, true);
+ if (dlg.open()!=Window.OK) {
+ if (sc instanceof ActorContainerClass)
+ ((ActorContainerClass)sc).getActorRefs().remove(newRef);
+ else if (sc instanceof LogicalSystem)
+ ((LogicalSystem) sc).getSubSystems().remove(newRef);
+ return EMPTY;
+ }
+
+ addGraphicalRepresentation(context, newRef);
+ doneChanges = true;
+
+ // return newly created business object(s)
+ return new Object[] { newRef };
+ }
+
+ @Override
+ public boolean hasDoneChanges() {
+ return doneChanges;
+ }
+ }
+
+ private class AddFeature extends AbstractAddFeature {
+
+ public AddFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canAdd(IAddContext context) {
+ if (context.getNewObject() instanceof ActorContainerRef) {
+ if (context.getTargetContainer().getLink().getBusinessObjects().size()==1) {
+ EObject obj = context.getTargetContainer().getLink().getBusinessObjects().get(0);
+ if (obj instanceof StructureClass) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public PictogramElement add(IAddContext context) {
+ ActorContainerRef ar = (ActorContainerRef) context.getNewObject();
+ ContainerShape acShape = context.getTargetContainer();
+
+ // CONTAINER SHAPE WITH RECTANGLE
+ ContainerShape containerShape =
+ Graphiti.getPeCreateService().createContainerShape(acShape, true);
+
+ Graphiti.getPeService().setPropertyValue(containerShape, Constants.TYPE_KEY, Constants.REF_TYPE);
+
+ EObject parent = (EObject) getBusinessObjectForPictogramElement(acShape);
+ boolean inherited = isInherited(ar, parent);
+
+ Color lineColor = manageColor(inherited?INHERITED_COLOR:LINE_COLOR);
+ {
+ int width = context.getWidth() <= 0 ? DEFAULT_SIZE_X : context.getWidth();
+ int height = context.getHeight() <= 0 ? DEFAULT_SIZE_Y : context.getHeight();
+ final Rectangle invisibleRectangle = Graphiti.getGaService().createInvisibleRectangle(containerShape);
+ Graphiti.getGaService().setLocationAndSize(invisibleRectangle,
+ context.getX()-(width/2+MARGIN), context.getY()-(height/2+MARGIN), width + 2*MARGIN, height + 2*MARGIN);
+
+ createRefFigure(ar, getDiagram(), containerShape, invisibleRectangle, lineColor, manageColor(BACKGROUND));
+ }
+
+ // create link and wire it
+ link(containerShape, ar);
+
+ // other child shapes may follow
+ if (inherited) {
+ InterfaceItemSupport.createInheritedRefItems(ar, containerShape, fp);
+ }
+ else {
+ InterfaceItemSupport.createRefItems(ar, containerShape, fp);
+ }
+
+ // call the layout feature
+ layoutPictogramElement(containerShape);
+
+ return containerShape;
+ }
+
+ }
+
+ private class LayoutFeature extends AbstractLayoutFeature {
+
+ public LayoutFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canLayout(ILayoutContext context) {
+ // return true, if pictogram element is linked to an ActorContainerRef
+ PictogramElement pe = context.getPictogramElement();
+ if (!(pe instanceof ContainerShape))
+ return false;
+
+ EList<EObject> businessObjects = pe.getLink().getBusinessObjects();
+ return businessObjects.size() == 1
+ && businessObjects.get(0) instanceof ActorContainerRef;
+ }
+
+ @Override
+ public boolean layout(ILayoutContext context) {
+ boolean anythingChanged = false;
+ ContainerShape containerShape = (ContainerShape) context
+ .getPictogramElement();
+
+ // our invisible rectangle
+ GraphicsAlgorithm containerGa = containerShape.getGraphicsAlgorithm();
+
+ int w = containerGa.getWidth();
+ int h = containerGa.getHeight();
+ int nw = w-2*MARGIN;
+ int nh = h-2*MARGIN;
+
+ /**
+ * TODO: (Keplar) use Ids to identify GraphicsAlgorithm children
+ * see Graphiti example "filesystem"
+ * (org.eclipse.graphiti.examples.filesystem.patterns.FolderPattern)
+ */
+ if(containerGa.getGraphicsAlgorithmChildren().size()>=1){
+ GraphicsAlgorithm borderRect = null;
+ Object obj = getBusinessObjectForPictogramElement(containerShape);
+ if(obj instanceof ActorRef && ((ActorRef)obj).getSize()>1){
+ GraphicsAlgorithm replBorder = containerGa.getGraphicsAlgorithmChildren().get(0);
+ replBorder.setWidth(nw);
+ replBorder.setHeight(nh);
+ borderRect = containerGa.getGraphicsAlgorithmChildren().get(1);
+ GraphicsAlgorithm replFrame = containerGa.getGraphicsAlgorithmChildren().get(2);
+ replFrame.setX(MARGIN+nw-SIZE_FRAME_SIZE);
+ } else
+ borderRect = containerGa.getGraphicsAlgorithmChildren().get(0);
+
+ borderRect.setWidth(nw);
+ borderRect.setHeight(nh);
+ Object bo = getBusinessObjectForPictogramElement(containerShape);
+ if (bo instanceof ActorContainerRef) {
+ ActorContainerRef acr = (ActorContainerRef) bo;
+ EObject parent = containerShape.getContainer().getLink().getBusinessObjects().get(0);
+ Color lineColor = manageColor(isInherited(acr, parent)?INHERITED_COLOR:LINE_COLOR);
+ // remove and recreate substructure hint
+ while (!borderRect.getGraphicsAlgorithmChildren().isEmpty()) {
+ EcoreUtil.delete(borderRect.getGraphicsAlgorithmChildren().get(0), true);
+ }
+ addSubStructureHint(acr, (Rectangle) borderRect, lineColor);
+ }
+
+ if (!containerShape.getChildren().isEmpty()) {
+ GraphicsAlgorithm childGA = containerShape.getChildren().get(0).getGraphicsAlgorithm();
+ assert(childGA instanceof Text): "label expected";
+ childGA.setWidth(nw);
+ childGA.setHeight(nh);
+
+ if(obj instanceof ActorRef && ((ActorRef)obj).getSize()>1){
+ GraphicsAlgorithm replLabel = containerShape.getChildren().get(1).getGraphicsAlgorithm();
+ replLabel.setX(MARGIN+nw-SIZE_FRAME_SIZE);
+ }
+ }
+
+ anythingChanged = true;
+ }
+
+ return anythingChanged;
+ }
+ }
+
+ private static class PropertyFeature extends AbstractCustomFeature {
+
+ private boolean doneChanges = false;
+
+ public PropertyFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public String getName() {
+ return "Edit Reference...";
+ }
+
+ @Override
+ public String getDescription() {
+ return "Edit Reference Properties";
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes != null && pes.length == 1) {
+ Object bo = getBusinessObjectForPictogramElement(pes[0]);
+ if (bo instanceof ActorContainerRef) {
+ EObject parent = (EObject) getBusinessObjectForPictogramElement((PictogramElement) pes[0].eContainer());
+ return !isInherited((ActorContainerRef)bo, parent);
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public void execute(ICustomContext context) {
+ ContainerShape containerShape = (ContainerShape) context.getPictogramElements()[0];
+ ActorContainerRef acr = (ActorContainerRef) getBusinessObjectForPictogramElement(containerShape);
+ StructureClass sc = (StructureClass)acr.eContainer();
+
+ IScopeProvider scopeProvider = ((DiagramTypeProvider)getFeatureProvider().getDiagramTypeProvider()).getScopeProvider();
+ EReference reference = (acr instanceof ActorRef)?RoomPackage.eINSTANCE.getActorRef_Type():RoomPackage.eINSTANCE.getSubSystemRef_Type();
+ IScope scope = scopeProvider.getScope(acr.eContainer().eContainer(), reference);
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ ActorContainerRefPropertyDialog dlg = new ActorContainerRefPropertyDialog(shell, acr, scope, sc, false);
+ if (dlg.open()!=Window.OK)
+ return;
+
+ doneChanges = true;
+ //updateLabel(acr, context.getPictogramElements()[0]);
+
+ EObject parent = (EObject) getBusinessObjectForPictogramElement(containerShape.getContainer());
+ boolean inherited = isInherited(acr, parent);
+ Color lineColor = manageColor(inherited?INHERITED_COLOR:LINE_COLOR);
+ createRefFigure(acr, getDiagram(), containerShape, (Rectangle)containerShape.getGraphicsAlgorithm(), lineColor, manageColor(BACKGROUND));
+ }
+
+ @Override
+ public boolean hasDoneChanges() {
+ return doneChanges;
+ }
+
+ }
+
+ private static class OpenRefStructureDiagram extends AbstractCustomFeature {
+
+ public OpenRefStructureDiagram(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public String getName() {
+ return "Open Ref Structure";
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes != null && pes.length == 1) {
+ Object bo = getBusinessObjectForPictogramElement(pes[0]);
+ if (bo instanceof ActorContainerRef) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.graphiti.features.custom.ICustomFeature#execute(org.eclipse.graphiti.features.context.ICustomContext)
+ */
+ @Override
+ public void execute(ICustomContext context) {
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes != null && pes.length == 1) {
+ Object bo = getBusinessObjectForPictogramElement(pes[0]);
+ if (bo instanceof ActorContainerRef) {
+ final ActorContainerRef ref = (ActorContainerRef) bo;
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ shell.getDisplay().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ DiagramAccess diagramAccess = new DiagramAccess();
+ if (ref instanceof ActorRef) {
+ diagramAccess.openDiagramEditor(((ActorRef) ref).getType());
+ }
+ else if (ref instanceof SubSystemRef) {
+ diagramAccess.openDiagramEditor(((SubSystemRef) ref).getType());
+ }
+ }
+ });
+ }
+ }
+ }
+
+ @Override
+ public boolean hasDoneChanges() {
+ return false;
+ }
+ }
+
+ private static class OpenRefBehaviorDiagram extends AbstractCustomFeature {
+
+ public OpenRefBehaviorDiagram(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public String getName() {
+ return "Open Ref Behavior";
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes != null && pes.length == 1) {
+ Object bo = getBusinessObjectForPictogramElement(pes[0]);
+ if (bo instanceof ActorRef) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.graphiti.features.custom.ICustomFeature#execute(org.eclipse.graphiti.features.context.ICustomContext)
+ */
+ @Override
+ public void execute(ICustomContext context) {
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes != null && pes.length == 1) {
+ Object bo = getBusinessObjectForPictogramElement(pes[0]);
+ if (bo instanceof ActorContainerRef) {
+ final ActorContainerRef ref = (ActorContainerRef) bo;
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ shell.getDisplay().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ org.eclipse.etrice.ui.behavior.DiagramAccess diagramAccess = new org.eclipse.etrice.ui.behavior.DiagramAccess();
+ if (ref instanceof ActorRef) {
+ diagramAccess.openDiagramEditor(((ActorRef) ref).getType());
+ }
+ }
+ });
+ }
+ }
+ }
+
+ @Override
+ public boolean hasDoneChanges() {
+ ScopedPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, "org.eclipse.etrice.ui.common");
+ boolean autoSave = store.getBoolean(PreferenceConstants.SAVE_DIAG_ON_FOCUS_LOST);
+ if (autoSave)
+ return true; // this is needed to trigger the save via a CommandStackListener after this command is completed
+ else
+ return false;
+ }
+ }
+
+ private class UpdateFeature extends AbstractUpdateFeature {
+
+ public UpdateFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canUpdate(IUpdateContext context) {
+ Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
+ if (bo instanceof EObject && ((EObject)bo).eIsProxy())
+ return true;
+
+ return bo instanceof ActorContainerRef;
+ }
+
+ @Override
+ public IReason updateNeeded(IUpdateContext context) {
+ Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
+ if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
+ return Reason.createTrueReason("Ref deleted from model");
+ }
+ ActorContainerRef acr = (ActorContainerRef) bo;
+ ContainerShape containerShape = (ContainerShape)context.getPictogramElement();
+ GraphicsAlgorithm invisibleRect = containerShape.getGraphicsAlgorithm();
+ int borderShapeId = 0;
+
+ String reason = "";
+
+ // check replicated
+ if(acr instanceof ActorRef){
+ if(((ActorRef)acr).getSize()>1){
+ if(invisibleRect.getGraphicsAlgorithmChildren().size() < 3)
+ reason += "ActorRef got replicated";
+ else
+ borderShapeId = 1;
+ } else {
+ if(invisibleRect.getGraphicsAlgorithmChildren().size() > 2){
+ reason += "ActorRef is not replicated anymore";
+ borderShapeId = 1;
+ }
+ }
+ }
+
+ // check if ref still owned/inherited anymore
+ bo = getBusinessObjectForPictogramElement(containerShape);
+ if (bo instanceof ActorClass) {
+ ActorClass ac = (ActorClass) bo;
+ boolean found = false;
+ do {
+ if (ac==acr.eContainer())
+ found = true;
+ ac = ac.getBase();
+ }
+ while (!found && ac!=null);
+
+ if (!found)
+ reason += "Ref not inherited anymore\n";
+ }
+
+ // check sub structure hint
+ {
+ boolean hasSubStruct = hasSubStructure(acr);
+ if (!invisibleRect.getGraphicsAlgorithmChildren().isEmpty()) {
+ GraphicsAlgorithm borderRect = invisibleRect.getGraphicsAlgorithmChildren().get(borderShapeId);
+ if (!borderRect.getGraphicsAlgorithmChildren().isEmpty()) {
+ GraphicsAlgorithm hint = borderRect.getGraphicsAlgorithmChildren().get(0);
+ if (hasSubStruct && !hint.getLineVisible())
+ reason += "state has sub structure now\n";
+ if (!hasSubStruct && hint.getLineVisible())
+ reason += "state has no sub structure anymore\n";
+ }
+ }
+ }
+
+ // check class name
+ if (!containerShape.getChildren().isEmpty()) {
+ GraphicsAlgorithm ga = containerShape.getChildren().get(0).getGraphicsAlgorithm();
+ if (ga instanceof Text) {
+ if (bo instanceof ActorContainerRef) {
+ String label = RoomNameProvider.getRefLabelName((ActorContainerRef) bo);
+ if (!((Text)ga).getValue().equals(label))
+ reason += "Class name is out of date\n";
+ }
+ }
+ }
+
+ // check replicated label
+ if(acr instanceof ActorRef && ((ActorRef)acr).getSize()>1){
+ if(containerShape.getChildren().size() >= 2){
+ GraphicsAlgorithm ga = containerShape.getChildren().get(1).getGraphicsAlgorithm();
+ if (ga instanceof Text) {
+ if(!((Text)ga).getValue().equals(((ActorRef)acr).getSize()+""))
+ reason += "multiciply changed";
+ }
+ }
+ }
+
+ // check interface ports and spps added to model not present in diagram
+ {
+ ActorContainerClass acc = (acr instanceof ActorRef)?((ActorRef)acr).getType():((SubSystemRef)acr).getType();
+ List<InterfaceItem> interfaceItems = RoomHelpers.getInterfaceItems(acc, true);
+ List<InterfaceItem> presentItems = SupportUtil.getInterfaceItems(containerShape, fp);
+ int missing = 0;
+ for (InterfaceItem interfaceItem : interfaceItems) {
+ if (!presentItems.contains(interfaceItem))
+ ++missing;
+ }
+ if (missing>0)
+ reason += missing+" interface item(s) missing\n";
+ }
+
+ if (!reason.isEmpty())
+ return Reason.createTrueReason(reason.substring(0, reason.length()-1));
+
+ return Reason.createFalseReason();
+ }
+
+ @Override
+ public boolean update(IUpdateContext context) {
+ ContainerShape containerShape = (ContainerShape)context.getPictogramElement();
+ Object bo = getBusinessObjectForPictogramElement(containerShape);
+ if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
+ IRemoveContext rc = new RemoveContext(containerShape);
+ IFeatureProvider featureProvider = getFeatureProvider();
+ IRemoveFeature removeFeature = featureProvider.getRemoveFeature(rc);
+ if (removeFeature != null) {
+ removeFeature.remove(rc);
+ }
+ EcoreUtil.delete((EObject) bo);
+ return true;
+ }
+
+ GraphicsAlgorithm invisibleRect = containerShape.getGraphicsAlgorithm();
+ ActorContainerRef acr = (ActorContainerRef) bo;
+ int borderRectId = 0;
+
+ // check replicated
+ if(acr instanceof ActorRef){
+ if(((ActorRef)acr).getSize()>1){
+ if(invisibleRect.getGraphicsAlgorithmChildren().size() < 3){
+
+ IGaService gaService = Graphiti.getGaService();
+ int width = invisibleRect.getWidth()-2*MARGIN;
+ int height = invisibleRect.getHeight()-2*MARGIN;
+ EObject parent = (EObject) getBusinessObjectForPictogramElement(containerShape.getContainer());
+ Color lineColor = manageColor(isInherited(acr, parent)?INHERITED_COLOR:LINE_COLOR);
+
+ Rectangle replRect = gaService.createRectangle(invisibleRect);
+ replRect.setForeground(lineColor);
+ replRect.setBackground(manageColor(BACKGROUND));
+ replRect.setLineWidth(LINE_WIDTH);
+ gaService.setLocationAndSize(replRect, MARGIN+REPLICATED_RECT_OFFSET, MARGIN-REPLICATED_RECT_OFFSET, width, height);
+ invisibleRect.getGraphicsAlgorithmChildren().move(0, replRect);
+
+ Rectangle sizeFrame = gaService.createRectangle(invisibleRect);
+ sizeFrame.setForeground(lineColor);
+ sizeFrame.setBackground(manageColor(BACKGROUND));
+ sizeFrame.setLineWidth(LINE_WIDTH);
+ gaService.setLocationAndSize(sizeFrame, MARGIN+width-SIZE_FRAME_SIZE, MARGIN, SIZE_FRAME_SIZE, SIZE_FRAME_SIZE);
+ invisibleRect.getGraphicsAlgorithmChildren().move(2, sizeFrame);
+
+ Shape labelShape = Graphiti.getPeCreateService().createShape(containerShape, false);
+ Integer size = ((ActorRef)acr).getSize();
+ Text label = gaService.createDefaultText(getDiagram(), labelShape, size.toString());
+ label.setForeground(lineColor);
+ label.setBackground(lineColor);
+ label.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
+ label.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
+ gaService.setLocationAndSize(label, MARGIN+width-SIZE_FRAME_SIZE, MARGIN, SIZE_FRAME_SIZE, SIZE_FRAME_SIZE);
+ containerShape.getChildren().move(1, labelShape);
+ }
+ borderRectId = 1;
+ } else {
+ if(invisibleRect.getGraphicsAlgorithmChildren().size() > 2){
+ EcoreUtil.delete(invisibleRect.getGraphicsAlgorithmChildren().get(2), true);
+ EcoreUtil.delete(invisibleRect.getGraphicsAlgorithmChildren().get(0), true);
+ EcoreUtil.delete(containerShape.getChildren().get(1), true);
+ }
+ }
+ }
+ {
+ if (!invisibleRect.getGraphicsAlgorithmChildren().isEmpty()) {
+ GraphicsAlgorithm borderRect = invisibleRect.getGraphicsAlgorithmChildren().get(borderRectId);
+ updateSubStructureHint(acr, (Rectangle) borderRect);
+ }
+ }
+
+ updateLabel(acr, context.getPictogramElement());
+
+ InterfaceItemSupport.createRefItems(acr, containerShape, fp);
+
+ return true;
+ }
+ }
+
+ private class RemoveFeature extends DefaultRemoveFeature {
+
+ public RemoveFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canRemove(IRemoveContext context) {
+ return false;
+ }
+ }
+
+ private class DeleteFeature extends DeleteWithoutConfirmFeature {
+
+ public DeleteFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canDelete(IDeleteContext context) {
+ Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
+
+ if (bo instanceof ActorContainerRef) {
+ ActorContainerRef ar = (ActorContainerRef) bo;
+ ContainerShape acShape = (ContainerShape) context.getPictogramElement().eContainer();
+ EObject parent = acShape.getLink().getBusinessObjects().get(0);
+ return !isInherited(ar, parent);
+ }
+
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.graphiti.ui.features.DefaultDeleteFeature#preDelete(org.eclipse.graphiti.features.context.IDeleteContext)
+ */
+ @Override
+ public void preDelete(IDeleteContext context) {
+ super.preDelete(context);
+
+ if (!(context.getPictogramElement() instanceof ContainerShape))
+ return;
+
+ ContainerShape container = (ContainerShape) context.getPictogramElement();
+ CommonSupportUtil.deleteConnectionsRecursive(container, getFeatureProvider());
+ }
+ }
+
+ private class MoveShapeFeature extends DefaultMoveShapeFeature {
+
+ public MoveShapeFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canMoveShape(IMoveShapeContext context) {
+ boolean canMove = super.canMoveShape(context);
+
+ if (canMove) {
+ Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
+
+ if (bo instanceof ActorContainerRef) {
+ ActorContainerRef ar = (ActorContainerRef) bo;
+ ContainerShape acShape = context.getTargetContainer();
+ EObject parent = acShape.getLink().getBusinessObjects().get(0);
+
+ // TODOHRR: also check coordinates (no overlap with actor boundaries)
+
+ return !isInherited(ar, parent);
+ }
+ }
+
+ return canMove;
+ }
+ }
+
+ private class ResizeFeature extends DefaultResizeShapeFeature {
+
+ public ResizeFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canResizeShape(IResizeShapeContext context) {
+ if (!super.canResizeShape(context))
+ return false;
+
+ int width = context.getWidth()-MARGIN;
+ int height = context.getHeight()-MARGIN;
+ if (width>0 && height>0)
+ if (width < MIN_SIZE_X+MARGIN || height < MIN_SIZE_Y+MARGIN)
+ return false;
+
+ return true;
+ }
+
+ @Override
+ public void resizeShape(IResizeShapeContext context) {
+ Shape shape = context.getShape();
+
+ if (shape.getGraphicsAlgorithm()!=null) {
+ GraphicsAlgorithm containerGa = shape.getGraphicsAlgorithm();
+ double sx = (context.getWidth()-2*MARGIN)/(double)(containerGa.getWidth()-2*MARGIN);
+ double sy = (context.getHeight()-2*MARGIN)/(double)(containerGa.getHeight()-2*MARGIN);
+
+ GraphicsAlgorithm ga;
+ for (Shape childShape : ((ContainerShape)context.getShape()).getChildren()) {
+ Object childBo = getBusinessObjectForPictogramElement(childShape);
+ if (childBo instanceof InterfaceItem) {
+ ga = childShape.getGraphicsAlgorithm();
+ ga.setX((int) (ga.getX()*sx));
+ ga.setY((int) (ga.getY()*sy));
+ }
+
+ }
+ }
+ super.resizeShape(context);
+ }
+ }
+
+ private IFeatureProvider fp;
+
+ public FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp) {
+ super(dtp);
+ this.fp = fp;
+ }
+
+ @Override
+ public ICreateFeature[] getCreateFeatures() {
+ return new ICreateFeature[] { new CreateFeature(fp, true), new CreateFeature(fp, false) };
+ }
+
+ @Override
+ public IAddFeature getAddFeature(IAddContext context) {
+ return new AddFeature(fp);
+ }
+
+ @Override
+ public ILayoutFeature getLayoutFeature(ILayoutContext context) {
+ return new LayoutFeature(fp);
+ }
+
+ @Override
+ public IUpdateFeature getUpdateFeature(IUpdateContext context) {
+ return new UpdateFeature(fp);
+ }
+
+ @Override
+ public IMoveShapeFeature getMoveShapeFeature(IMoveShapeContext context) {
+ return new MoveShapeFeature(fp);
+ }
+
+ @Override
+ public IResizeShapeFeature getResizeShapeFeature(
+ IResizeShapeContext context) {
+ return new ResizeFeature(fp);
+ }
+
+ @Override
+ public IRemoveFeature getRemoveFeature(IRemoveContext context) {
+ return new RemoveFeature(fp);
+ }
+
+ @Override
+ public IDeleteFeature getDeleteFeature(IDeleteContext context) {
+ return new DeleteFeature(fp);
+ }
+
+ @Override
+ public ICustomFeature[] getCustomFeatures(ICustomContext context) {
+ return new ICustomFeature[] {
+ new PropertyFeature(fp),
+ new OpenRefStructureDiagram(fp),
+ new OpenRefBehaviorDiagram(fp)};
+ }
+
+ protected static boolean isInherited(ActorContainerRef ar, EObject parent) {
+ return ar.eContainer()!=parent;
+ }
+
+ protected static void updateSubStructureHint(ActorContainerRef acr, GraphicsAlgorithm borderRect) {
+
+ boolean hasSubStructure = hasSubStructure(acr);
+ GraphicsAlgorithm hint = borderRect.getGraphicsAlgorithmChildren().get(0);
+ hint.setLineVisible(hasSubStructure);
+ hint = borderRect.getGraphicsAlgorithmChildren().get(1);
+ hint.setLineVisible(hasSubStructure);
+ }
+
+ private static void updateLabel(ActorContainerRef acr, PictogramElement pe) {
+ ContainerShape container = (ContainerShape)pe;
+
+ // TODO: identify children properly
+ if (!container.getChildren().isEmpty()) {
+ GraphicsAlgorithm actorLabel = container.getChildren().get(0).getGraphicsAlgorithm();
+ if (actorLabel instanceof Text)
+ ((Text)actorLabel).setValue(RoomNameProvider.getRefLabelName(acr));
+
+ if(acr instanceof ActorRef && ((ActorRef)acr).getSize()>1){
+ if(container.getChildren().size()>1){
+ GraphicsAlgorithm replLabel = container.getChildren().get(1).getGraphicsAlgorithm();
+ if (replLabel instanceof Text)
+ ((Text)replLabel).setValue(((ActorRef)acr).getSize()+"");
+ }
+ }
+ }
+ }
+ }
+
+ private class BehaviorProvider extends DefaultToolBehaviorProvider {
+
+ public BehaviorProvider(IDiagramTypeProvider dtp) {
+ super(dtp);
+ }
+
+ @Override
+ public GraphicsAlgorithm[] getClickArea(PictogramElement pe) {
+ GraphicsAlgorithm invisible = pe.getGraphicsAlgorithm();
+ GraphicsAlgorithm rectangle =
+ invisible.getGraphicsAlgorithmChildren().get(0);
+ return new GraphicsAlgorithm[] { rectangle };
+ }
+
+ @Override
+ public GraphicsAlgorithm getSelectionBorder(PictogramElement pe) {
+ GraphicsAlgorithm invisible = pe.getGraphicsAlgorithm();
+
+ GraphicsAlgorithm rectangle =
+ invisible.getGraphicsAlgorithmChildren().get(0);
+ return rectangle;
+ }
+
+ @Override
+ public ICustomFeature getDoubleClickFeature(IDoubleClickContext context) {
+ return new FeatureProvider.OpenRefStructureDiagram(getDiagramTypeProvider().getFeatureProvider());
+ }
+
+ @Override
+ public IContextButtonPadData getContextButtonPad(
+ IPictogramElementContext context) {
+
+ IContextButtonPadData data = super.getContextButtonPad(context);
+ PictogramElement pe = context.getPictogramElement();
+
+ CreateConnectionContext ccc = new CreateConnectionContext();
+ ccc.setSourcePictogramElement(pe);
+ Anchor anchor = null;
+ if (pe instanceof AnchorContainer) {
+ // our spp has four fixed point anchor - we choose the first one
+ anchor = ((ContainerShape)pe).getAnchors().get(0);
+ }
+ ccc.setSourceAnchor(anchor);
+
+ ContextButtonEntry button = new ContextButtonEntry(null, context);
+ button.setText("Create Layer Connection");
+ button.setIconId(ImageProvider.IMG_LAYER_CONNECTION);
+ ICreateConnectionFeature[] features = getFeatureProvider().getCreateConnectionFeatures();
+ for (ICreateConnectionFeature feature : features) {
+ if (feature.isAvailable(ccc) && feature.canStartConnection(ccc))
+ button.addDragAndDropFeature(feature);
+ }
+
+ if (button.getDragAndDropFeatures().size() > 0) {
+ data.getDomainSpecificContextButtons().add(button);
+ }
+
+ return data;
+ }
+ }
+
+ private static void createRefFigure(ActorContainerRef ar,
+ Diagram diagram, ContainerShape containerShape, final Rectangle invisibleRectangle,
+ Color lineColor, Color bgColor) {
+
+ invisibleRectangle.getGraphicsAlgorithmChildren().clear();
+ if (!containerShape.getChildren().isEmpty()) {
+ // potentially there are two text labels which we remove before re-creating
+ Shape shape = containerShape.getChildren().get(0);
+ if (shape.getGraphicsAlgorithm() instanceof Text)
+ containerShape.getChildren().remove(0);
+ shape = containerShape.getChildren().get(0);
+ if (shape.getGraphicsAlgorithm() instanceof Text)
+ containerShape.getChildren().remove(0);
+ }
+
+ int width = invisibleRectangle.getWidth()-2*MARGIN;
+ int height = invisibleRectangle.getHeight()-2*MARGIN;
+
+ IGaService gaService = Graphiti.getGaService();
+ if (ar instanceof ActorRef && ((ActorRef)ar).getSize()>1) {
+ Rectangle rect = gaService.createRectangle(invisibleRectangle);
+ rect.setForeground(lineColor);
+ rect.setBackground(bgColor);
+ rect.setLineWidth(LINE_WIDTH);
+ gaService.setLocationAndSize(rect, MARGIN+REPLICATED_RECT_OFFSET, MARGIN-REPLICATED_RECT_OFFSET, width, height);
+ }
+
+ Rectangle borderRect = gaService.createRectangle(invisibleRectangle);
+ borderRect.setForeground(lineColor);
+ borderRect.setBackground(bgColor);
+ borderRect.setLineWidth(LINE_WIDTH);
+ gaService.setLocationAndSize(borderRect, MARGIN, MARGIN, width, height);
+
+ if (ar instanceof ActorRef && ((ActorRef)ar).getSize()>1) {
+ Rectangle sizeFrame = gaService.createRectangle(invisibleRectangle);
+ sizeFrame.setForeground(lineColor);
+ sizeFrame.setBackground(bgColor);
+ sizeFrame.setLineWidth(LINE_WIDTH);
+ gaService.setLocationAndSize(sizeFrame, MARGIN+width-SIZE_FRAME_SIZE, MARGIN, SIZE_FRAME_SIZE, SIZE_FRAME_SIZE);
+ }
+
+ addSubStructureHint(ar, borderRect, lineColor);
+
+ IPeCreateService peCreateService = Graphiti.getPeCreateService();
+
+ // anchor for layer connections
+ if (containerShape.getAnchors().isEmpty()) {
+ ChopboxAnchor anchor = peCreateService.createChopboxAnchor(containerShape);
+ anchor.setReferencedGraphicsAlgorithm(borderRect);
+ }
+ else {
+ // we just set the referenced GA
+ containerShape.getAnchors().get(0).setReferencedGraphicsAlgorithm(borderRect);
+ }
+
+ // the first child shape is the label
+ {
+ Shape labelShape = peCreateService.createShape(containerShape, false);
+ Text label = gaService.createDefaultText(diagram, labelShape, RoomNameProvider.getRefLabelName(ar));
+ label.setForeground(lineColor);
+ label.setBackground(lineColor);
+ label.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
+ label.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
+ gaService.setLocationAndSize(label, MARGIN, MARGIN, width, height);
+ }
+
+ if (ar instanceof ActorRef && ((ActorRef)ar).getSize()>1) {
+ Shape labelShape = peCreateService.createShape(containerShape, false);
+ Integer size = ((ActorRef)ar).getSize();
+ Text label = gaService.createDefaultText(diagram, labelShape, size.toString());
+ label.setForeground(lineColor);
+ label.setBackground(lineColor);
+ label.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
+ label.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
+ gaService.setLocationAndSize(label, MARGIN+width-SIZE_FRAME_SIZE, MARGIN, SIZE_FRAME_SIZE, SIZE_FRAME_SIZE);
+ }
+ }
+
+ private static void addSubStructureHint(ActorContainerRef acr,
+ Rectangle borderRect, Color lineColor) {
+
+ int x = borderRect.getWidth()-35;
+ int y = borderRect.getHeight()-30;
+ IGaService gaService = Graphiti.getGaService();
+ Rectangle hint1 = gaService.createRectangle(borderRect);
+ hint1.setForeground(lineColor);
+ hint1.setFilled(false);
+ hint1.setLineWidth(LINE_WIDTH);
+ gaService.setLocationAndSize(hint1, x+5, y, 20, 10);
+ Rectangle hint2 = gaService.createRectangle(borderRect);
+ hint2.setForeground(lineColor);
+ hint2.setFilled(false);
+ hint2.setLineWidth(LINE_WIDTH);
+ gaService.setLocationAndSize(hint2, x, y+15, 20, 10);
+
+ if (!hasSubStructure(acr)) {
+ hint1.setLineVisible(false);
+ hint2.setLineVisible(false);
+ }
+ }
+
+ private static boolean hasSubStructure(ActorContainerRef acr) {
+ if (acr instanceof ActorRef) {
+ if (!((ActorRef) acr).getType().getActorRefs().isEmpty())
+ return true;
+ }
+ else if (acr instanceof SubSystemRef) {
+ if (!((SubSystemRef)acr).getType().getActorRefs().isEmpty())
+ return true;
+ }
+ return false;
+ }
+
+ private FeatureProvider pfp;
+ private BehaviorProvider tbp;
+
+ public ActorContainerRefSupport(IDiagramTypeProvider dtp, IFeatureProvider fp) {
+ pfp = new FeatureProvider(dtp,fp);
+ tbp = new BehaviorProvider(dtp);
+ }
+
+ public IFeatureProvider getFeatureProvider() {
+ return pfp;
+ }
+
+ public IToolBehaviorProvider getToolBehaviorProvider() {
+ return tbp;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/BindingSupport.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/BindingSupport.java
index daf37a691..0b7bdc681 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/BindingSupport.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/BindingSupport.java
@@ -1,595 +1,595 @@
-/*******************************************************************************
- * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.structure.support;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.etrice.core.naming.RoomNameProvider;
-import org.eclipse.etrice.core.room.ActorContainerClass;
-import org.eclipse.etrice.core.room.ActorContainerRef;
-import org.eclipse.etrice.core.room.Binding;
-import org.eclipse.etrice.core.room.BindingEndPoint;
-import org.eclipse.etrice.core.room.CompoundProtocolClass;
-import org.eclipse.etrice.core.room.GeneralProtocolClass;
-import org.eclipse.etrice.core.room.Port;
-import org.eclipse.etrice.core.room.RoomFactory;
-import org.eclipse.etrice.core.room.StructureClass;
-import org.eclipse.etrice.core.validation.ValidationUtil;
-import org.eclipse.etrice.ui.common.support.DeleteWithoutConfirmFeature;
-import org.eclipse.etrice.ui.structure.ImageProvider;
-import org.eclipse.etrice.ui.structure.dialogs.SubProtocolSelectionDialog;
-import org.eclipse.graphiti.dt.IDiagramTypeProvider;
-import org.eclipse.graphiti.features.IAddFeature;
-import org.eclipse.graphiti.features.ICreateConnectionFeature;
-import org.eclipse.graphiti.features.IDeleteFeature;
-import org.eclipse.graphiti.features.IFeatureProvider;
-import org.eclipse.graphiti.features.IReason;
-import org.eclipse.graphiti.features.IReconnectionFeature;
-import org.eclipse.graphiti.features.IRemoveFeature;
-import org.eclipse.graphiti.features.IUpdateFeature;
-import org.eclipse.graphiti.features.context.IAddConnectionContext;
-import org.eclipse.graphiti.features.context.IAddContext;
-import org.eclipse.graphiti.features.context.ICreateConnectionContext;
-import org.eclipse.graphiti.features.context.ICustomContext;
-import org.eclipse.graphiti.features.context.IDeleteContext;
-import org.eclipse.graphiti.features.context.IDoubleClickContext;
-import org.eclipse.graphiti.features.context.IReconnectionContext;
-import org.eclipse.graphiti.features.context.IRemoveContext;
-import org.eclipse.graphiti.features.context.IUpdateContext;
-import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
-import org.eclipse.graphiti.features.context.impl.ReconnectionContext;
-import org.eclipse.graphiti.features.context.impl.RemoveContext;
-import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
-import org.eclipse.graphiti.features.custom.ICustomFeature;
-import org.eclipse.graphiti.features.impl.AbstractAddFeature;
-import org.eclipse.graphiti.features.impl.AbstractCreateConnectionFeature;
-import org.eclipse.graphiti.features.impl.AbstractUpdateFeature;
-import org.eclipse.graphiti.features.impl.DefaultReconnectionFeature;
-import org.eclipse.graphiti.features.impl.DefaultRemoveFeature;
-import org.eclipse.graphiti.features.impl.Reason;
-import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
-import org.eclipse.graphiti.mm.algorithms.Polyline;
-import org.eclipse.graphiti.mm.pictograms.Anchor;
-import org.eclipse.graphiti.mm.pictograms.Connection;
-import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
-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.mm.pictograms.Shape;
-import org.eclipse.graphiti.services.Graphiti;
-import org.eclipse.graphiti.services.IGaService;
-import org.eclipse.graphiti.services.IPeCreateService;
-import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider;
-import org.eclipse.graphiti.tb.IToolBehaviorProvider;
-import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;
-import org.eclipse.graphiti.util.ColorConstant;
-import org.eclipse.graphiti.util.IColorConstant;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.PlatformUI;
-
-public class BindingSupport {
-
- public static final IColorConstant LINE_COLOR = new ColorConstant(0, 0, 0);
- public static final IColorConstant INHERITED_COLOR = new ColorConstant(100, 100, 100);
-
- static class FeatureProvider extends DefaultFeatureProvider {
-
- private class CreateFeature extends AbstractCreateConnectionFeature {
-
- private boolean doneChanges = false;
-
- public CreateFeature(IFeatureProvider fp) {
- super(fp, "Binding", "create Binding");
- }
-
- @Override
- public String getCreateImageId() {
- return ImageProvider.IMG_BINDING;
- }
-
- @Override
- public boolean canCreate(ICreateConnectionContext context) {
- IFeatureProvider featureProvider = getFeatureProvider();
- Port src = SupportUtil.getPort(context.getSourceAnchor(), featureProvider);
- Port tgt = SupportUtil.getPort(context.getTargetAnchor(), featureProvider);
- ActorContainerRef srcRef = SupportUtil.getRef(context.getSourceAnchor(), featureProvider);
-
- if (src==null || tgt==null) {
- return false;
- }
-
- StructureClass ac = SupportUtil.getParent(context, featureProvider);
- if (ac==null) {
- return false;
- }
-
- ActorContainerRef tgtRef = SupportUtil.getRef(context.getTargetAnchor(), featureProvider);
-
- return ValidationUtil.isConnectable(src, srcRef, null, tgt, tgtRef, null, ac, null, false).isOk();
- }
-
- public boolean canStartConnection(ICreateConnectionContext context) {
- Port src = SupportUtil.getPort(context.getSourceAnchor(), getFeatureProvider());
- boolean canStart = src!=null;
- if (canStart) {
- ActorContainerRef ref = SupportUtil.getRef(context.getSourceAnchor(), getFeatureProvider());
- if (ref==null) {
- // this port is local, i.e. owned by the parent itself
- ActorContainerClass acc = (ActorContainerClass) src.eContainer();
- if (!ValidationUtil.isConnectable(src, null, acc).isOk())
- canStart = false;
- }
- else {
- ActorContainerClass acc = (ActorContainerClass) ref.eContainer();
- if (!ValidationUtil.isConnectable(src, ref, acc).isOk())
- canStart = false;
- }
- }
-
- return canStart;
- }
-
- @Override
- public Connection create(ICreateConnectionContext context) {
- Connection newConnection = null;
-
- endHighLightMatches();
-
- IFeatureProvider featureProvider = getFeatureProvider();
- Port src = SupportUtil.getPort(context.getSourceAnchor(), featureProvider);
- Port dst = SupportUtil.getPort(context.getTargetAnchor(), featureProvider);
- StructureClass sc = SupportUtil.getParent(context, featureProvider);
- if (src!=null && dst!=null && sc!=null) {
- Binding bind = RoomFactory.eINSTANCE.createBinding();
- BindingEndPoint ep1 = RoomFactory.eINSTANCE.createBindingEndPoint();
- ActorContainerRef ar1 = SupportUtil.getRef(context.getSourceAnchor(), featureProvider);
- ep1.setPort(src);
- ep1.setActorRef(ar1);
- BindingEndPoint ep2 = RoomFactory.eINSTANCE.createBindingEndPoint();
- ActorContainerRef ar2 = SupportUtil.getRef(context.getTargetAnchor(), featureProvider);
- ep2.setPort(dst);
- ep2.setActorRef(ar2);
- bind.setEndpoint1(ep1);
- bind.setEndpoint2(ep2);
-
- GeneralProtocolClass srcGPC = src.getProtocol();
- GeneralProtocolClass dstGPC = dst.getProtocol();
- if (srcGPC instanceof CompoundProtocolClass || dstGPC instanceof CompoundProtocolClass) {
- Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- SubProtocolSelectionDialog dlg = new SubProtocolSelectionDialog(shell, src, ar1, dst, ar2, null, sc);
- if (dlg.open()!=Window.OK)
- return null;
-
- ep1.setSub(dlg.getSelected().getLeft());
- ep2.setSub(dlg.getSelected().getRight());
- }
-
- sc.getBindings().add(bind);
-
- AddConnectionContext addContext = new AddConnectionContext(context.getSourceAnchor(), context.getTargetAnchor());
- addContext.setNewObject(bind);
- newConnection = (Connection) featureProvider.addIfPossible(addContext);
- doneChanges = true;
- }
-
- return newConnection;
- }
-
- @Override
- public void attachedToSource(ICreateConnectionContext context) {
- Port src = SupportUtil.getPort(context.getSourceAnchor(), getFeatureProvider());
- ActorContainerRef ref = SupportUtil.getRef(context.getSourceAnchor(), getFeatureProvider());
- StructureClass sc = SupportUtil.getParent(context, getFeatureProvider());
-
- beginHighLightMatches(sc, src, ref);
- }
-
- @Override
- public void canceledAttaching(ICreateConnectionContext context) {
- endHighLightMatches();
- }
-
- @Override
- public void endConnecting() {
- endHighLightMatches();
- }
-
- private void beginHighLightMatches(StructureClass sc, Port src, ActorContainerRef srcRef) {
- if (src==null)
- return;
-
- ContainerShape scContainer = (ContainerShape) getDiagram().getChildren().get(0);
- for (Shape subShape : scContainer.getChildren()) {
- Object bo = getBusinessObjectForPictogramElement(subShape);
- if (bo instanceof Port) {
- if (ValidationUtil.isConnectable(src, srcRef, null, (Port) bo, null, null, sc, null, false).isOk()) {
- DecorationProvider.addAllowedPortShape(subShape);
- getDiagramBehavior().refreshRenderingDecorators(subShape);
- }
- }
- else if (bo instanceof ActorContainerRef) {
- ActorContainerRef tgtRef = (ActorContainerRef) bo;
- for (Shape subSubShape : ((ContainerShape)subShape).getChildren()) {
- bo = getBusinessObjectForPictogramElement(subSubShape);
- if (bo instanceof Port) {
- if (ValidationUtil.isConnectable(src, srcRef, null, (Port) bo, tgtRef, null, sc, null, false).isOk()) {
- DecorationProvider.addAllowedPortShape(subSubShape);
- getDiagramBehavior().refreshRenderingDecorators(subSubShape);
- }
- }
- }
- }
-
- }
- }
-
- private void endHighLightMatches() {
- DecorationProvider.clearAllowedPortShapes();
- getDiagramBehavior().refresh();
- }
-
- @Override
- public boolean hasDoneChanges() {
- return doneChanges;
- }
- }
-
- private class AddFeature extends AbstractAddFeature {
-
- public AddFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canAdd(IAddContext context) {
- if (context instanceof IAddConnectionContext && context.getNewObject() instanceof Binding) {
- return true;
- }
- return false;
- }
-
- @Override
- public PictogramElement add(IAddContext context) {
- IAddConnectionContext addConContext = (IAddConnectionContext) context;
- Binding bind = (Binding) context.getNewObject();
-
- boolean inherited = isInherited(getDiagram(), bind);
-
- IPeCreateService peCreateService = Graphiti.getPeCreateService();
- // CONNECTION WITH POLYLINE
- Connection connection = peCreateService.createFreeFormConnection(getDiagram());
- connection.setStart(addConContext.getSourceAnchor());
- connection.setEnd(addConContext.getTargetAnchor());
-
- Graphiti.getPeService().setPropertyValue(connection, Constants.TYPE_KEY, Constants.BIND_TYPE);
-
- IGaService gaService = Graphiti.getGaService();
- Polyline polyline = gaService.createPolyline(connection);
- polyline.setForeground(manageColor(inherited?INHERITED_COLOR:LINE_COLOR));
-
- // create link and wire it
- link(connection, bind);
-
- return connection;
- }
-
- }
-
- private class ReconnectionFeature extends DefaultReconnectionFeature {
-
- private boolean doneChanges = false;
-
- public ReconnectionFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canReconnect(IReconnectionContext context) {
- if (!super.canReconnect(context))
- return false;
-
- Binding bind = (Binding) getBusinessObjectForPictogramElement(context.getConnection());
- if (isInherited(getDiagram(), bind))
- return false;
-
- Anchor asrc = context.getConnection().getStart();
- Anchor atgt = context.getConnection().getEnd();
- if (context.getReconnectType().equals(ReconnectionContext.RECONNECT_SOURCE))
- asrc = context.getNewAnchor();
- else
- atgt = context.getNewAnchor();
-
- IFeatureProvider featureProvider = getFeatureProvider();
- Port src = SupportUtil.getPort(asrc, featureProvider);
- Port tgt = SupportUtil.getPort(atgt, featureProvider);
- ActorContainerRef srcRef = SupportUtil.getRef(asrc, featureProvider);
-
- if (src==null || tgt==null) {
- return false;
- }
-
- StructureClass ac = SupportUtil.getParent(getDiagram(), featureProvider);
- if (ac==null) {
- return false;
- }
-
- ActorContainerRef tgtRef = SupportUtil.getRef(atgt, featureProvider);
-
- return ValidationUtil.isConnectable(
- src, srcRef, bind.getEndpoint1().getSub(),
- tgt, tgtRef, bind.getEndpoint2().getSub(),
- ac, bind, true).isOk();
- }
-
- @Override
- public void postReconnect(IReconnectionContext context) {
- super.postReconnect(context);
-
- IFeatureProvider featureProvider = getFeatureProvider();
- Port src = SupportUtil.getPort(context.getConnection().getStart(), featureProvider);
- Port dst = SupportUtil.getPort(context.getConnection().getEnd(), featureProvider);
- StructureClass sc = SupportUtil.getParent(getDiagram(), featureProvider);
- if (src!=null && dst!=null && sc!=null) {
- Binding bind = (Binding) getBusinessObjectForPictogramElement(context.getConnection());
- BindingEndPoint ep1 = RoomFactory.eINSTANCE.createBindingEndPoint();
- ActorContainerRef ar1 = SupportUtil.getRef(context.getConnection().getStart(), featureProvider);
- ep1.setPort(src);
- ep1.setActorRef(ar1);
- BindingEndPoint ep2 = RoomFactory.eINSTANCE.createBindingEndPoint();
- ActorContainerRef ar2 = SupportUtil.getRef(context.getConnection().getEnd(), featureProvider);
- ep2.setPort(dst);
- ep2.setActorRef(ar2);
-
- GeneralProtocolClass srcGPC = src.getProtocol();
- GeneralProtocolClass dstGPC = dst.getProtocol();
- if (srcGPC instanceof GeneralProtocolClass || dstGPC instanceof GeneralProtocolClass) {
- Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- SubProtocolSelectionDialog dlg = new SubProtocolSelectionDialog(shell, src, ar1, dst, ar2, bind, sc);
- if (dlg.open()!=Window.OK)
- return;
-
- ep1.setSub(dlg.getSelected().getLeft());
- ep2.setSub(dlg.getSelected().getRight());
- }
-
- bind.setEndpoint1(ep1);
- bind.setEndpoint2(ep2);
-
- doneChanges = true;
- }
- }
-
- @Override
- public boolean hasDoneChanges() {
- return doneChanges ;
- }
- }
-
- private class UpdateFeature extends AbstractUpdateFeature {
-
- public UpdateFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canUpdate(IUpdateContext context) {
- Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
- if (bo instanceof EObject && ((EObject)bo).eIsProxy())
- return true;
-
- return false;
- }
-
- @Override
- public IReason updateNeeded(IUpdateContext context) {
- Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
- if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
- return Reason.createTrueReason("Binding deleted from model");
- }
- return Reason.createFalseReason();
- }
-
- @Override
- public boolean update(IUpdateContext context) {
- PictogramElement pe = context.getPictogramElement();
- Object bo = getBusinessObjectForPictogramElement(pe);
- if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
- IRemoveContext rc = new RemoveContext(pe);
- IFeatureProvider featureProvider = getFeatureProvider();
- IRemoveFeature removeFeature = featureProvider.getRemoveFeature(rc);
- if (removeFeature != null) {
- removeFeature.remove(rc);
- }
- EcoreUtil.delete((EObject) bo);
- return true;
- }
- return false;
- }
- }
-
- private class RemoveFeature extends DefaultRemoveFeature {
-
- public RemoveFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canRemove(IRemoveContext context) {
- return false;
- }
- }
-
- private class DeleteFeature extends DeleteWithoutConfirmFeature {
-
- public DeleteFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canDelete(IDeleteContext context) {
- EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(context.getPictogramElement());
- if (bo instanceof Binding) {
- Binding b = (Binding) bo;
- if (isInherited(getDiagram(), b))
- return false;
- }
-
- return true;
- }
- }
-
- private static class PropertyFeature extends AbstractCustomFeature {
-
- private boolean doneChanges;
-
- public PropertyFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public String getName() {
- return "Edit Binding...";
- }
-
- @Override
- public String getDescription() {
- return "Edit Binding Properties";
- }
-
- public boolean canExecute(ICustomContext context) {
- return getBusinessObjectForPictogramElement(context.getPictogramElements()[0]) instanceof Binding;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.graphiti.features.custom.ICustomFeature#execute(org.eclipse.graphiti.features.context.ICustomContext)
- */
- @Override
- public void execute(ICustomContext context) {
- doneChanges = false;
- Binding bind = (Binding) getBusinessObjectForPictogramElement(context.getPictogramElements()[0]);
- StructureClass sc = (StructureClass) bind.eContainer();
-
- Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- SubProtocolSelectionDialog dlg = new SubProtocolSelectionDialog(
- shell,
- bind.getEndpoint1().getPort(), bind.getEndpoint1().getActorRef(),
- bind.getEndpoint2().getPort(), bind.getEndpoint2().getActorRef(),
- bind, sc);
- if (dlg.open()!=Window.OK)
- return;
-
- bind.getEndpoint1().setSub(dlg.getSelected().getLeft());
- bind.getEndpoint2().setSub(dlg.getSelected().getRight());
-
- doneChanges = true;
- }
-
- @Override
- public boolean hasDoneChanges() {
- return doneChanges;
- }
- }
-
- private IFeatureProvider fp;
-
- public FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp) {
- super(dtp);
- this.fp = fp;
- }
-
- private boolean isInherited(Diagram diag, Binding b) {
- ActorContainerClass ac = (ActorContainerClass) Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(diag.getChildren().get(0));
- return (b.eContainer()!=ac);
- }
-
- @Override
- public ICreateConnectionFeature[] getCreateConnectionFeatures() {
- return new ICreateConnectionFeature[] { new CreateFeature(fp) };
- }
-
- @Override
- public IAddFeature getAddFeature(IAddContext context) {
- return new AddFeature(fp);
- }
-
- @Override
- public IUpdateFeature getUpdateFeature(IUpdateContext context) {
- return new UpdateFeature(fp);
- }
-
- @Override
- public IReconnectionFeature getReconnectionFeature(IReconnectionContext context) {
- return new ReconnectionFeature(fp);
- }
-
- @Override
- public IRemoveFeature getRemoveFeature(IRemoveContext context) {
- return new RemoveFeature(fp);
- }
-
- @Override
- public IDeleteFeature getDeleteFeature(IDeleteContext context) {
- return new DeleteFeature(fp);
- }
-
- @Override
- public ICustomFeature[] getCustomFeatures(ICustomContext context) {
- return new ICustomFeature[] { new PropertyFeature(fp) };
- }
- }
-
- class BehaviorProvider extends DefaultToolBehaviorProvider {
-
- @Override
- public Object getToolTip(GraphicsAlgorithm ga) {
- // if this is called we know there is a business object!=null
- PictogramElement pe = ga.getPictogramElement();
- if (pe instanceof ConnectionDecorator)
- pe = (PictogramElement) pe.eContainer();
-
- EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe);
- if (bo instanceof Binding) {
- Binding bind = (Binding) bo;
- return RoomNameProvider.getDisplayName(bind);
- }
-
- return super.getToolTip(ga);
- }
-
- @Override
- public ICustomFeature getDoubleClickFeature(IDoubleClickContext context) {
- return new FeatureProvider.PropertyFeature(getDiagramTypeProvider().getFeatureProvider());
- }
-
- public BehaviorProvider(IDiagramTypeProvider dtp) {
- super(dtp);
- }
- }
-
- private FeatureProvider pfp;
- private BehaviorProvider tbp;
-
- public BindingSupport(IDiagramTypeProvider dtp, IFeatureProvider fp) {
- pfp = new FeatureProvider(dtp,fp);
- tbp = new BehaviorProvider(dtp);
- }
-
- public IFeatureProvider getFeatureProvider() {
- return pfp;
- }
-
- public IToolBehaviorProvider getToolBehaviorProvider() {
- return tbp;
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.support;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.etrice.core.naming.RoomNameProvider;
+import org.eclipse.etrice.core.room.ActorContainerClass;
+import org.eclipse.etrice.core.room.ActorContainerRef;
+import org.eclipse.etrice.core.room.Binding;
+import org.eclipse.etrice.core.room.BindingEndPoint;
+import org.eclipse.etrice.core.room.CompoundProtocolClass;
+import org.eclipse.etrice.core.room.GeneralProtocolClass;
+import org.eclipse.etrice.core.room.Port;
+import org.eclipse.etrice.core.room.RoomFactory;
+import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.core.validation.ValidationUtil;
+import org.eclipse.etrice.ui.common.support.DeleteWithoutConfirmFeature;
+import org.eclipse.etrice.ui.structure.ImageProvider;
+import org.eclipse.etrice.ui.structure.dialogs.SubProtocolSelectionDialog;
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.features.IAddFeature;
+import org.eclipse.graphiti.features.ICreateConnectionFeature;
+import org.eclipse.graphiti.features.IDeleteFeature;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.IReason;
+import org.eclipse.graphiti.features.IReconnectionFeature;
+import org.eclipse.graphiti.features.IRemoveFeature;
+import org.eclipse.graphiti.features.IUpdateFeature;
+import org.eclipse.graphiti.features.context.IAddConnectionContext;
+import org.eclipse.graphiti.features.context.IAddContext;
+import org.eclipse.graphiti.features.context.ICreateConnectionContext;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.context.IDeleteContext;
+import org.eclipse.graphiti.features.context.IDoubleClickContext;
+import org.eclipse.graphiti.features.context.IReconnectionContext;
+import org.eclipse.graphiti.features.context.IRemoveContext;
+import org.eclipse.graphiti.features.context.IUpdateContext;
+import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
+import org.eclipse.graphiti.features.context.impl.ReconnectionContext;
+import org.eclipse.graphiti.features.context.impl.RemoveContext;
+import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
+import org.eclipse.graphiti.features.custom.ICustomFeature;
+import org.eclipse.graphiti.features.impl.AbstractAddFeature;
+import org.eclipse.graphiti.features.impl.AbstractCreateConnectionFeature;
+import org.eclipse.graphiti.features.impl.AbstractUpdateFeature;
+import org.eclipse.graphiti.features.impl.DefaultReconnectionFeature;
+import org.eclipse.graphiti.features.impl.DefaultRemoveFeature;
+import org.eclipse.graphiti.features.impl.Reason;
+import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.algorithms.Polyline;
+import org.eclipse.graphiti.mm.pictograms.Anchor;
+import org.eclipse.graphiti.mm.pictograms.Connection;
+import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
+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.mm.pictograms.Shape;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.IGaService;
+import org.eclipse.graphiti.services.IPeCreateService;
+import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider;
+import org.eclipse.graphiti.tb.IToolBehaviorProvider;
+import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;
+import org.eclipse.graphiti.util.ColorConstant;
+import org.eclipse.graphiti.util.IColorConstant;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+
+public class BindingSupport {
+
+ public static final IColorConstant LINE_COLOR = new ColorConstant(0, 0, 0);
+ public static final IColorConstant INHERITED_COLOR = new ColorConstant(100, 100, 100);
+
+ static class FeatureProvider extends DefaultFeatureProvider {
+
+ private class CreateFeature extends AbstractCreateConnectionFeature {
+
+ private boolean doneChanges = false;
+
+ public CreateFeature(IFeatureProvider fp) {
+ super(fp, "Binding", "create Binding");
+ }
+
+ @Override
+ public String getCreateImageId() {
+ return ImageProvider.IMG_BINDING;
+ }
+
+ @Override
+ public boolean canCreate(ICreateConnectionContext context) {
+ IFeatureProvider featureProvider = getFeatureProvider();
+ Port src = SupportUtil.getPort(context.getSourceAnchor(), featureProvider);
+ Port tgt = SupportUtil.getPort(context.getTargetAnchor(), featureProvider);
+ ActorContainerRef srcRef = SupportUtil.getRef(context.getSourceAnchor(), featureProvider);
+
+ if (src==null || tgt==null) {
+ return false;
+ }
+
+ StructureClass ac = SupportUtil.getParent(context, featureProvider);
+ if (ac==null) {
+ return false;
+ }
+
+ ActorContainerRef tgtRef = SupportUtil.getRef(context.getTargetAnchor(), featureProvider);
+
+ return ValidationUtil.isConnectable(src, srcRef, null, tgt, tgtRef, null, ac, null, false).isOk();
+ }
+
+ public boolean canStartConnection(ICreateConnectionContext context) {
+ Port src = SupportUtil.getPort(context.getSourceAnchor(), getFeatureProvider());
+ boolean canStart = src!=null;
+ if (canStart) {
+ ActorContainerRef ref = SupportUtil.getRef(context.getSourceAnchor(), getFeatureProvider());
+ if (ref==null) {
+ // this port is local, i.e. owned by the parent itself
+ ActorContainerClass acc = (ActorContainerClass) src.eContainer();
+ if (!ValidationUtil.isConnectable(src, null, acc).isOk())
+ canStart = false;
+ }
+ else {
+ ActorContainerClass acc = (ActorContainerClass) ref.eContainer();
+ if (!ValidationUtil.isConnectable(src, ref, acc).isOk())
+ canStart = false;
+ }
+ }
+
+ return canStart;
+ }
+
+ @Override
+ public Connection create(ICreateConnectionContext context) {
+ Connection newConnection = null;
+
+ endHighLightMatches();
+
+ IFeatureProvider featureProvider = getFeatureProvider();
+ Port src = SupportUtil.getPort(context.getSourceAnchor(), featureProvider);
+ Port dst = SupportUtil.getPort(context.getTargetAnchor(), featureProvider);
+ StructureClass sc = SupportUtil.getParent(context, featureProvider);
+ if (src!=null && dst!=null && sc!=null) {
+ Binding bind = RoomFactory.eINSTANCE.createBinding();
+ BindingEndPoint ep1 = RoomFactory.eINSTANCE.createBindingEndPoint();
+ ActorContainerRef ar1 = SupportUtil.getRef(context.getSourceAnchor(), featureProvider);
+ ep1.setPort(src);
+ ep1.setActorRef(ar1);
+ BindingEndPoint ep2 = RoomFactory.eINSTANCE.createBindingEndPoint();
+ ActorContainerRef ar2 = SupportUtil.getRef(context.getTargetAnchor(), featureProvider);
+ ep2.setPort(dst);
+ ep2.setActorRef(ar2);
+ bind.setEndpoint1(ep1);
+ bind.setEndpoint2(ep2);
+
+ GeneralProtocolClass srcGPC = src.getProtocol();
+ GeneralProtocolClass dstGPC = dst.getProtocol();
+ if (srcGPC instanceof CompoundProtocolClass || dstGPC instanceof CompoundProtocolClass) {
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ SubProtocolSelectionDialog dlg = new SubProtocolSelectionDialog(shell, src, ar1, dst, ar2, null, sc);
+ if (dlg.open()!=Window.OK)
+ return null;
+
+ ep1.setSub(dlg.getSelected().getLeft());
+ ep2.setSub(dlg.getSelected().getRight());
+ }
+
+ sc.getBindings().add(bind);
+
+ AddConnectionContext addContext = new AddConnectionContext(context.getSourceAnchor(), context.getTargetAnchor());
+ addContext.setNewObject(bind);
+ newConnection = (Connection) featureProvider.addIfPossible(addContext);
+ doneChanges = true;
+ }
+
+ return newConnection;
+ }
+
+ @Override
+ public void attachedToSource(ICreateConnectionContext context) {
+ Port src = SupportUtil.getPort(context.getSourceAnchor(), getFeatureProvider());
+ ActorContainerRef ref = SupportUtil.getRef(context.getSourceAnchor(), getFeatureProvider());
+ StructureClass sc = SupportUtil.getParent(context, getFeatureProvider());
+
+ beginHighLightMatches(sc, src, ref);
+ }
+
+ @Override
+ public void canceledAttaching(ICreateConnectionContext context) {
+ endHighLightMatches();
+ }
+
+ @Override
+ public void endConnecting() {
+ endHighLightMatches();
+ }
+
+ private void beginHighLightMatches(StructureClass sc, Port src, ActorContainerRef srcRef) {
+ if (src==null)
+ return;
+
+ ContainerShape scContainer = (ContainerShape) getDiagram().getChildren().get(0);
+ for (Shape subShape : scContainer.getChildren()) {
+ Object bo = getBusinessObjectForPictogramElement(subShape);
+ if (bo instanceof Port) {
+ if (ValidationUtil.isConnectable(src, srcRef, null, (Port) bo, null, null, sc, null, false).isOk()) {
+ DecorationProvider.addAllowedPortShape(subShape);
+ getDiagramBehavior().refreshRenderingDecorators(subShape);
+ }
+ }
+ else if (bo instanceof ActorContainerRef) {
+ ActorContainerRef tgtRef = (ActorContainerRef) bo;
+ for (Shape subSubShape : ((ContainerShape)subShape).getChildren()) {
+ bo = getBusinessObjectForPictogramElement(subSubShape);
+ if (bo instanceof Port) {
+ if (ValidationUtil.isConnectable(src, srcRef, null, (Port) bo, tgtRef, null, sc, null, false).isOk()) {
+ DecorationProvider.addAllowedPortShape(subSubShape);
+ getDiagramBehavior().refreshRenderingDecorators(subSubShape);
+ }
+ }
+ }
+ }
+
+ }
+ }
+
+ private void endHighLightMatches() {
+ DecorationProvider.clearAllowedPortShapes();
+ getDiagramBehavior().refresh();
+ }
+
+ @Override
+ public boolean hasDoneChanges() {
+ return doneChanges;
+ }
+ }
+
+ private class AddFeature extends AbstractAddFeature {
+
+ public AddFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canAdd(IAddContext context) {
+ if (context instanceof IAddConnectionContext && context.getNewObject() instanceof Binding) {
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public PictogramElement add(IAddContext context) {
+ IAddConnectionContext addConContext = (IAddConnectionContext) context;
+ Binding bind = (Binding) context.getNewObject();
+
+ boolean inherited = isInherited(getDiagram(), bind);
+
+ IPeCreateService peCreateService = Graphiti.getPeCreateService();
+ // CONNECTION WITH POLYLINE
+ Connection connection = peCreateService.createFreeFormConnection(getDiagram());
+ connection.setStart(addConContext.getSourceAnchor());
+ connection.setEnd(addConContext.getTargetAnchor());
+
+ Graphiti.getPeService().setPropertyValue(connection, Constants.TYPE_KEY, Constants.BIND_TYPE);
+
+ IGaService gaService = Graphiti.getGaService();
+ Polyline polyline = gaService.createPolyline(connection);
+ polyline.setForeground(manageColor(inherited?INHERITED_COLOR:LINE_COLOR));
+
+ // create link and wire it
+ link(connection, bind);
+
+ return connection;
+ }
+
+ }
+
+ private class ReconnectionFeature extends DefaultReconnectionFeature {
+
+ private boolean doneChanges = false;
+
+ public ReconnectionFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canReconnect(IReconnectionContext context) {
+ if (!super.canReconnect(context))
+ return false;
+
+ Binding bind = (Binding) getBusinessObjectForPictogramElement(context.getConnection());
+ if (isInherited(getDiagram(), bind))
+ return false;
+
+ Anchor asrc = context.getConnection().getStart();
+ Anchor atgt = context.getConnection().getEnd();
+ if (context.getReconnectType().equals(ReconnectionContext.RECONNECT_SOURCE))
+ asrc = context.getNewAnchor();
+ else
+ atgt = context.getNewAnchor();
+
+ IFeatureProvider featureProvider = getFeatureProvider();
+ Port src = SupportUtil.getPort(asrc, featureProvider);
+ Port tgt = SupportUtil.getPort(atgt, featureProvider);
+ ActorContainerRef srcRef = SupportUtil.getRef(asrc, featureProvider);
+
+ if (src==null || tgt==null) {
+ return false;
+ }
+
+ StructureClass ac = SupportUtil.getParent(getDiagram(), featureProvider);
+ if (ac==null) {
+ return false;
+ }
+
+ ActorContainerRef tgtRef = SupportUtil.getRef(atgt, featureProvider);
+
+ return ValidationUtil.isConnectable(
+ src, srcRef, bind.getEndpoint1().getSub(),
+ tgt, tgtRef, bind.getEndpoint2().getSub(),
+ ac, bind, true).isOk();
+ }
+
+ @Override
+ public void postReconnect(IReconnectionContext context) {
+ super.postReconnect(context);
+
+ IFeatureProvider featureProvider = getFeatureProvider();
+ Port src = SupportUtil.getPort(context.getConnection().getStart(), featureProvider);
+ Port dst = SupportUtil.getPort(context.getConnection().getEnd(), featureProvider);
+ StructureClass sc = SupportUtil.getParent(getDiagram(), featureProvider);
+ if (src!=null && dst!=null && sc!=null) {
+ Binding bind = (Binding) getBusinessObjectForPictogramElement(context.getConnection());
+ BindingEndPoint ep1 = RoomFactory.eINSTANCE.createBindingEndPoint();
+ ActorContainerRef ar1 = SupportUtil.getRef(context.getConnection().getStart(), featureProvider);
+ ep1.setPort(src);
+ ep1.setActorRef(ar1);
+ BindingEndPoint ep2 = RoomFactory.eINSTANCE.createBindingEndPoint();
+ ActorContainerRef ar2 = SupportUtil.getRef(context.getConnection().getEnd(), featureProvider);
+ ep2.setPort(dst);
+ ep2.setActorRef(ar2);
+
+ GeneralProtocolClass srcGPC = src.getProtocol();
+ GeneralProtocolClass dstGPC = dst.getProtocol();
+ if (srcGPC instanceof GeneralProtocolClass || dstGPC instanceof GeneralProtocolClass) {
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ SubProtocolSelectionDialog dlg = new SubProtocolSelectionDialog(shell, src, ar1, dst, ar2, bind, sc);
+ if (dlg.open()!=Window.OK)
+ return;
+
+ ep1.setSub(dlg.getSelected().getLeft());
+ ep2.setSub(dlg.getSelected().getRight());
+ }
+
+ bind.setEndpoint1(ep1);
+ bind.setEndpoint2(ep2);
+
+ doneChanges = true;
+ }
+ }
+
+ @Override
+ public boolean hasDoneChanges() {
+ return doneChanges ;
+ }
+ }
+
+ private class UpdateFeature extends AbstractUpdateFeature {
+
+ public UpdateFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canUpdate(IUpdateContext context) {
+ Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
+ if (bo instanceof EObject && ((EObject)bo).eIsProxy())
+ return true;
+
+ return false;
+ }
+
+ @Override
+ public IReason updateNeeded(IUpdateContext context) {
+ Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
+ if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
+ return Reason.createTrueReason("Binding deleted from model");
+ }
+ return Reason.createFalseReason();
+ }
+
+ @Override
+ public boolean update(IUpdateContext context) {
+ PictogramElement pe = context.getPictogramElement();
+ Object bo = getBusinessObjectForPictogramElement(pe);
+ if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
+ IRemoveContext rc = new RemoveContext(pe);
+ IFeatureProvider featureProvider = getFeatureProvider();
+ IRemoveFeature removeFeature = featureProvider.getRemoveFeature(rc);
+ if (removeFeature != null) {
+ removeFeature.remove(rc);
+ }
+ EcoreUtil.delete((EObject) bo);
+ return true;
+ }
+ return false;
+ }
+ }
+
+ private class RemoveFeature extends DefaultRemoveFeature {
+
+ public RemoveFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canRemove(IRemoveContext context) {
+ return false;
+ }
+ }
+
+ private class DeleteFeature extends DeleteWithoutConfirmFeature {
+
+ public DeleteFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canDelete(IDeleteContext context) {
+ EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(context.getPictogramElement());
+ if (bo instanceof Binding) {
+ Binding b = (Binding) bo;
+ if (isInherited(getDiagram(), b))
+ return false;
+ }
+
+ return true;
+ }
+ }
+
+ private static class PropertyFeature extends AbstractCustomFeature {
+
+ private boolean doneChanges;
+
+ public PropertyFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public String getName() {
+ return "Edit Binding...";
+ }
+
+ @Override
+ public String getDescription() {
+ return "Edit Binding Properties";
+ }
+
+ public boolean canExecute(ICustomContext context) {
+ return getBusinessObjectForPictogramElement(context.getPictogramElements()[0]) instanceof Binding;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.graphiti.features.custom.ICustomFeature#execute(org.eclipse.graphiti.features.context.ICustomContext)
+ */
+ @Override
+ public void execute(ICustomContext context) {
+ doneChanges = false;
+ Binding bind = (Binding) getBusinessObjectForPictogramElement(context.getPictogramElements()[0]);
+ StructureClass sc = (StructureClass) bind.eContainer();
+
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ SubProtocolSelectionDialog dlg = new SubProtocolSelectionDialog(
+ shell,
+ bind.getEndpoint1().getPort(), bind.getEndpoint1().getActorRef(),
+ bind.getEndpoint2().getPort(), bind.getEndpoint2().getActorRef(),
+ bind, sc);
+ if (dlg.open()!=Window.OK)
+ return;
+
+ bind.getEndpoint1().setSub(dlg.getSelected().getLeft());
+ bind.getEndpoint2().setSub(dlg.getSelected().getRight());
+
+ doneChanges = true;
+ }
+
+ @Override
+ public boolean hasDoneChanges() {
+ return doneChanges;
+ }
+ }
+
+ private IFeatureProvider fp;
+
+ public FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp) {
+ super(dtp);
+ this.fp = fp;
+ }
+
+ private boolean isInherited(Diagram diag, Binding b) {
+ ActorContainerClass ac = (ActorContainerClass) Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(diag.getChildren().get(0));
+ return (b.eContainer()!=ac);
+ }
+
+ @Override
+ public ICreateConnectionFeature[] getCreateConnectionFeatures() {
+ return new ICreateConnectionFeature[] { new CreateFeature(fp) };
+ }
+
+ @Override
+ public IAddFeature getAddFeature(IAddContext context) {
+ return new AddFeature(fp);
+ }
+
+ @Override
+ public IUpdateFeature getUpdateFeature(IUpdateContext context) {
+ return new UpdateFeature(fp);
+ }
+
+ @Override
+ public IReconnectionFeature getReconnectionFeature(IReconnectionContext context) {
+ return new ReconnectionFeature(fp);
+ }
+
+ @Override
+ public IRemoveFeature getRemoveFeature(IRemoveContext context) {
+ return new RemoveFeature(fp);
+ }
+
+ @Override
+ public IDeleteFeature getDeleteFeature(IDeleteContext context) {
+ return new DeleteFeature(fp);
+ }
+
+ @Override
+ public ICustomFeature[] getCustomFeatures(ICustomContext context) {
+ return new ICustomFeature[] { new PropertyFeature(fp) };
+ }
+ }
+
+ class BehaviorProvider extends DefaultToolBehaviorProvider {
+
+ @Override
+ public Object getToolTip(GraphicsAlgorithm ga) {
+ // if this is called we know there is a business object!=null
+ PictogramElement pe = ga.getPictogramElement();
+ if (pe instanceof ConnectionDecorator)
+ pe = (PictogramElement) pe.eContainer();
+
+ EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe);
+ if (bo instanceof Binding) {
+ Binding bind = (Binding) bo;
+ return RoomNameProvider.getDisplayName(bind);
+ }
+
+ return super.getToolTip(ga);
+ }
+
+ @Override
+ public ICustomFeature getDoubleClickFeature(IDoubleClickContext context) {
+ return new FeatureProvider.PropertyFeature(getDiagramTypeProvider().getFeatureProvider());
+ }
+
+ public BehaviorProvider(IDiagramTypeProvider dtp) {
+ super(dtp);
+ }
+ }
+
+ private FeatureProvider pfp;
+ private BehaviorProvider tbp;
+
+ public BindingSupport(IDiagramTypeProvider dtp, IFeatureProvider fp) {
+ pfp = new FeatureProvider(dtp,fp);
+ tbp = new BehaviorProvider(dtp);
+ }
+
+ public IFeatureProvider getFeatureProvider() {
+ return pfp;
+ }
+
+ public IToolBehaviorProvider getToolBehaviorProvider() {
+ return tbp;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/Constants.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/Constants.java
index 99dc73249..7effdcd49 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/Constants.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/Constants.java
@@ -1,26 +1,26 @@
-/*******************************************************************************
- * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.structure.support;
-
-public interface Constants {
-
- static final String TYPE_KEY = "obj-type";
-
- static final String CLS_TYPE = "cls";
- static final String PORT_TYPE = "port";
- static final String SPP_TYPE = "spp";
- static final String REF_TYPE = "ref";
- static final String BIND_TYPE = "bind";
- static final String CONN_TYPE = "conn";
-
-}
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.support;
+
+public interface Constants {
+
+ static final String TYPE_KEY = "obj-type";
+
+ static final String CLS_TYPE = "cls";
+ static final String PORT_TYPE = "port";
+ static final String SPP_TYPE = "spp";
+ static final String REF_TYPE = "ref";
+ static final String BIND_TYPE = "bind";
+ static final String CONN_TYPE = "conn";
+
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/DecorationProvider.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/DecorationProvider.java
index 1cb852c02..c7008b997 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/DecorationProvider.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/DecorationProvider.java
@@ -1,51 +1,51 @@
-/*******************************************************************************
- * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-package org.eclipse.etrice.ui.structure.support;
-
-import java.util.ArrayList;
-
-import org.eclipse.graphiti.mm.pictograms.PictogramElement;
-import org.eclipse.graphiti.mm.pictograms.Shape;
-import org.eclipse.graphiti.tb.BorderDecorator;
-import org.eclipse.graphiti.tb.IDecorator;
-import org.eclipse.graphiti.util.IColorConstant;
-
-/**
- * @author Henrik Rentz-Reichert
- *
- */
-public class DecorationProvider {
-
- private static ArrayList<Shape> allowedPortShapes = new ArrayList<Shape>();
-
- public static void clearAllowedPortShapes() {
- allowedPortShapes.clear();
- }
-
- public static void addAllowedPortShape(Shape portShape) {
- allowedPortShapes.add(portShape);
- }
-
- public static IDecorator[] getDecorators(PictogramElement pe) {
- if (allowedPortShapes.contains(pe)) {
- BorderDecorator decorator = new BorderDecorator();
- decorator.setBorderColor(IColorConstant.GREEN);
- decorator.setBorderWidth(2);
-// ColorDecorator decorator = new ColorDecorator();
-// decorator.setForegroundColor(IColorConstant.GREEN);
-// decorator.setBackgroundColor(IColorConstant.GREEN);
- return new IDecorator[] { decorator };
- }
- return new IDecorator[0];
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+package org.eclipse.etrice.ui.structure.support;
+
+import java.util.ArrayList;
+
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.graphiti.tb.BorderDecorator;
+import org.eclipse.graphiti.tb.IDecorator;
+import org.eclipse.graphiti.util.IColorConstant;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public class DecorationProvider {
+
+ private static ArrayList<Shape> allowedPortShapes = new ArrayList<Shape>();
+
+ public static void clearAllowedPortShapes() {
+ allowedPortShapes.clear();
+ }
+
+ public static void addAllowedPortShape(Shape portShape) {
+ allowedPortShapes.add(portShape);
+ }
+
+ public static IDecorator[] getDecorators(PictogramElement pe) {
+ if (allowedPortShapes.contains(pe)) {
+ BorderDecorator decorator = new BorderDecorator();
+ decorator.setBorderColor(IColorConstant.GREEN);
+ decorator.setBorderWidth(2);
+// ColorDecorator decorator = new ColorDecorator();
+// decorator.setForegroundColor(IColorConstant.GREEN);
+// decorator.setBackgroundColor(IColorConstant.GREEN);
+ return new IDecorator[] { decorator };
+ }
+ return new IDecorator[0];
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/InterfaceItemSupport.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/InterfaceItemSupport.java
index 4befc71c4..e259d6218 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/InterfaceItemSupport.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/InterfaceItemSupport.java
@@ -1,816 +1,816 @@
-/*******************************************************************************
- * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.structure.support;
-
-import java.util.List;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.etrice.core.room.ActorClass;
-import org.eclipse.etrice.core.room.ActorContainerClass;
-import org.eclipse.etrice.core.room.ActorContainerRef;
-import org.eclipse.etrice.core.room.ActorRef;
-import org.eclipse.etrice.core.room.InterfaceItem;
-import org.eclipse.etrice.core.room.Port;
-import org.eclipse.etrice.core.room.SPPRef;
-import org.eclipse.etrice.core.room.SubSystemRef;
-import org.eclipse.etrice.core.room.util.RoomHelpers;
-import org.eclipse.etrice.ui.common.support.DeleteWithoutConfirmFeature;
-import org.eclipse.etrice.ui.common.support.NoResizeFeature;
-import org.eclipse.etrice.ui.structure.DiagramAccess;
-import org.eclipse.graphiti.dt.IDiagramTypeProvider;
-import org.eclipse.graphiti.features.IDeleteFeature;
-import org.eclipse.graphiti.features.IFeatureProvider;
-import org.eclipse.graphiti.features.IMoveShapeFeature;
-import org.eclipse.graphiti.features.IReason;
-import org.eclipse.graphiti.features.IRemoveFeature;
-import org.eclipse.graphiti.features.IResizeShapeFeature;
-import org.eclipse.graphiti.features.context.IAddContext;
-import org.eclipse.graphiti.features.context.ICreateContext;
-import org.eclipse.graphiti.features.context.ICustomContext;
-import org.eclipse.graphiti.features.context.IDeleteContext;
-import org.eclipse.graphiti.features.context.ILocationContext;
-import org.eclipse.graphiti.features.context.IMoveShapeContext;
-import org.eclipse.graphiti.features.context.IRemoveContext;
-import org.eclipse.graphiti.features.context.IResizeShapeContext;
-import org.eclipse.graphiti.features.context.ITargetContext;
-import org.eclipse.graphiti.features.context.IUpdateContext;
-import org.eclipse.graphiti.features.context.impl.RemoveContext;
-import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
-import org.eclipse.graphiti.features.impl.AbstractAddFeature;
-import org.eclipse.graphiti.features.impl.AbstractCreateFeature;
-import org.eclipse.graphiti.features.impl.AbstractUpdateFeature;
-import org.eclipse.graphiti.features.impl.DefaultMoveShapeFeature;
-import org.eclipse.graphiti.features.impl.DefaultRemoveFeature;
-import org.eclipse.graphiti.features.impl.Reason;
-import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
-import org.eclipse.graphiti.mm.algorithms.Rectangle;
-import org.eclipse.graphiti.mm.algorithms.Text;
-import org.eclipse.graphiti.mm.algorithms.styles.Color;
-import org.eclipse.graphiti.mm.algorithms.styles.Orientation;
-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.mm.pictograms.Shape;
-import org.eclipse.graphiti.services.Graphiti;
-import org.eclipse.graphiti.services.IGaService;
-import org.eclipse.graphiti.services.IPeCreateService;
-import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider;
-import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;
-import org.eclipse.graphiti.util.ColorConstant;
-import org.eclipse.graphiti.util.IColorConstant;
-
-public class InterfaceItemSupport {
-
- public static final int ITEM_SIZE = StructureClassSupport.MARGIN;
- public static final int ITEM_SIZE_SMALL = (int) (ActorContainerRefSupport.MARGIN*0.625);
- public static final int MARGIN = StructureClassSupport.MARGIN;
- public static final int MARGIN_SMALL = ActorContainerRefSupport.MARGIN;
-
- protected static final int LINE_WIDTH = 2;
- protected static final IColorConstant DARK_COLOR = new ColorConstant(0, 0, 0);
- protected static final IColorConstant INHERITED_COLOR = new ColorConstant(100, 100, 100);
- protected static final IColorConstant BRIGHT_COLOR = new ColorConstant(255, 255, 255);
- protected static final String PROP_KIND = "item-kind";
-
- protected static class FeatureProvider extends DefaultFeatureProvider {
-
- protected abstract static class CreateFeature extends AbstractCreateFeature {
-
- protected boolean internal;
- protected boolean doneChanges = false;
-
- public CreateFeature(IFeatureProvider fp, boolean internal, String name, String description) {
- super(fp, name, description);
- this.internal = internal;
- }
-
- @Override
- public boolean canCreate(ICreateContext context) {
- if (context.getTargetContainer().getLink()!=null)
- if (context.getTargetContainer().getLink().getBusinessObjects().size()==1) {
- EObject obj = context.getTargetContainer().getLink().getBusinessObjects().get(0);
- if (obj instanceof ActorContainerClass) {
- if (obj instanceof ActorClass)
- return isValidPosition(context, context, internal, StructureClassSupport.MARGIN);
- else
- return !internal;
- }
- }
- return false;
- }
-
- @Override
- public boolean hasDoneChanges() {
- return doneChanges;
- }
- }
-
- protected abstract static class AddFeature extends AbstractAddFeature {
-
- public AddFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canAdd(IAddContext context) {
- if (context.getNewObject() instanceof InterfaceItem) {
- if (context.getTargetContainer().getLink().getBusinessObjects().size()==1) {
- EObject obj = context.getTargetContainer().getLink().getBusinessObjects().get(0);
- if (obj instanceof ActorContainerClass) {
- return true;
- }
- if (obj instanceof ActorContainerRef) {
- return true;
- }
- }
- }
- return false;
- }
-
- @Override
- public PictogramElement add(IAddContext context) {
- InterfaceItem port = (InterfaceItem) context.getNewObject();
- boolean internal = isInternal(port);
- ContainerShape acShape = context.getTargetContainer();
- Object bo = getBusinessObjectForPictogramElement(acShape);
- boolean inherited = isInherited(port, bo, acShape);
- boolean refport = (bo instanceof ActorContainerRef);
-
- int margin = refport?MARGIN_SMALL:MARGIN;
- int size = refport?ITEM_SIZE_SMALL:ITEM_SIZE;
-
- // CONTAINER SHAPE WITH RECTANGLE
- IPeCreateService peCreateService = Graphiti.getPeCreateService();
- ContainerShape containerShape =
- peCreateService.createContainerShape(acShape, true);
-
- Graphiti.getPeService().setPropertyValue(containerShape, Constants.TYPE_KEY, Constants.PORT_TYPE);
-
- String kind = getItemKind(port);
- Graphiti.getPeService().setPropertyValue(containerShape, PROP_KIND, kind);
-
- // the context point is the midpoint relative to the invisible rectangle
- int x = context.getX();
- int y = context.getY();
- int width = acShape.getGraphicsAlgorithm().getWidth();
- int height = acShape.getGraphicsAlgorithm().getHeight();
- if (internal) {
- if (x<2*margin)
- x = 2*margin;
- else if (x>width-2*margin)
- x = width-2*margin;
- if (y<2*margin)
- y = 2*margin;
- else if (y>height-2*margin)
- y = height-2*margin;
- }
- else {
- // TODOHRR: remove duplicate code
- int dx = (x<=width/2)? x:width-x;
- int dy = (y<=height/2)? y:height-y;
- if (dx>dy) {
- // keep x, project y
- if (y<=height/2)
- y = margin;
- else
- y = height-margin;
-
- if (x<margin)
- x = margin;
- else if (x>width-margin)
- x = width-margin;
- }
- else {
- // keep y, project x
- if (x<=width/2)
- x = margin;
- else
- x = width-margin;
-
- if (y<margin)
- y = margin;
- else if (y>height-margin)
- y = height-margin;
- }
- }
- // finally we subtract the midpoint to get coordinates of the upper left corner
- x -= margin;
- y -= margin;
-
- Color dark = manageColor(inherited? INHERITED_COLOR:DARK_COLOR);
- IGaService gaService = Graphiti.getGaService();
- {
- final Rectangle invisibleRectangle = gaService.createInvisibleRectangle(containerShape);
- gaService.setLocationAndSize(invisibleRectangle, x, y, 2*margin, 2*margin);
-
- createItemFigure(port, refport,
- containerShape,
- invisibleRectangle,
- dark,
- manageColor(BRIGHT_COLOR));
-
- // create link and wire it
- link(containerShape, port);
- }
-
- {
- Shape labelShape = peCreateService.createShape(containerShape, false);
- Text label = gaService.createDefaultText(getDiagram(), labelShape, port.getName());
- label.setForeground(dark);
- label.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
- label.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
-// label.setBackground(manageColor(INHERITED_COLOR));
-// label.setFilled(true);
-// label.setLineVisible(true);
-// label.setLineWidth(3);
-// label.setLineStyle(LineStyle.DOT);
- gaService.setLocationAndSize(label, 0, margin+size/2, 2*margin, margin/2);
- adjustLabel(label, x, y, width, margin, size);
- }
-
- // call the layout feature
- layoutPictogramElement(containerShape);
-
- return containerShape;
-
- }
-
- protected abstract String getItemKind(InterfaceItem item);
- protected abstract void createItemFigure(InterfaceItem item, boolean refitem,
- ContainerShape containerShape,
- GraphicsAlgorithm invisibleRectangle, Color darkColor, Color brightDolor);
- }
-
- protected class MoveShapeFeature extends DefaultMoveShapeFeature {
-
- public MoveShapeFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canMoveShape(IMoveShapeContext context) {
- boolean canMove = super.canMoveShape(context);
-
- if (canMove) {
- Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
- if (bo instanceof InterfaceItem) {
- InterfaceItem item = (InterfaceItem) bo;
-
- ContainerShape acShape = context.getTargetContainer();
- Object parentBO = getBusinessObjectForPictogramElement(acShape);
- boolean refport = (parentBO instanceof ActorContainerRef);
- if (refport)
- return true;
-
- if (isInherited(item, parentBO, acShape))
- return false;
-
- int margin = refport?ActorContainerRefSupport.MARGIN:StructureClassSupport.MARGIN;
- return isValidPosition(context, context, isInternal(item), margin);
- }
- return false;
- }
-
- return canMove;
- }
-
- @Override
- protected void postMoveShape(IMoveShapeContext context) {
- ContainerShape shapeToMove = (ContainerShape) context.getShape();
-
- InterfaceItem item = (InterfaceItem) getBusinessObjectForPictogramElement(shapeToMove);
- boolean internal = isInternal(item);
- ContainerShape acShape = context.getTargetContainer();
- boolean refport = (getBusinessObjectForPictogramElement(acShape) instanceof ActorContainerRef);
-
- int margin = refport?MARGIN_SMALL:MARGIN;
- int size = refport?ITEM_SIZE_SMALL:ITEM_SIZE;
-
- int x = context.getX();
- int y = context.getY();
- int width = context.getTargetContainer().getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0).getWidth();
- int height = context.getTargetContainer().getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0).getHeight();
-
- if (internal) {
- // nothing to do
- }
- else {
- // project onto boundary
- if (refport) {
- int dx = (x<=width/2)? x:width-x;
- int dy = (y<=height/2)? y:height-y;
- if (dx>dy) {
- // keep x, project y
- if (y<=height/2)
- y = 0;
- else
- y = height-0;
-
- if (x<0)
- x = 0;
- else if (x>width-0)
- x = width-0;
- }
- else {
- // keep y, project x
- if (x<=width/2)
- x = 0;
- else
- x = width-0;
-
- if (y<0)
- y = 0;
- else if (y>height-0)
- y = height-0;
- }
- }
- else {
- if (x<=margin)
- x = 0;
- if (y<=margin)
- y = 0;
- if ((width-margin)<=x)
- x = width;
- if ((height-margin)<=y)
- y = height;
- }
- }
-
- Graphiti.getGaService().setLocation(shapeToMove.getGraphicsAlgorithm(), x, y, avoidNegativeCoordinates());
-
- GraphicsAlgorithm ga = shapeToMove.getChildren().get(0).getGraphicsAlgorithm();
- if (ga instanceof Text) {
- adjustLabel((Text) ga, x, y, width, margin, size);
- }
- }
- }
-
- protected abstract class UpdateFeature extends AbstractUpdateFeature {
-
- public UpdateFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canUpdate(IUpdateContext context) {
- Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
- if (bo instanceof EObject && ((EObject)bo).eIsProxy())
- return true;
-
- return bo instanceof InterfaceItem;
- }
-
- @Override
- public IReason updateNeeded(IUpdateContext context) {
- Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
- if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
- return Reason.createTrueReason("InterfaceItem deleted from model");
- }
- InterfaceItem port = (InterfaceItem) bo;
-
- String reason = "";
-
- // check if port still owned/inherited
- ContainerShape containerShape = (ContainerShape)context.getPictogramElement();
- bo = getBusinessObjectForPictogramElement(containerShape);
- if (bo instanceof ActorClass) {
- ActorClass ac = (ActorClass) bo;
- boolean found = false;
- do {
- if (ac==port.eContainer())
- found = true;
- ac = ac.getBase();
- }
- while (!found && ac!=null);
-
- if (!found)
- reason += "InterfaceItem not inherited anymore\n";
- }
-
- GraphicsAlgorithm ga = containerShape.getChildren().get(0).getGraphicsAlgorithm();
- if (ga instanceof Text) {
- if (!port.getName().equals(((Text)ga).getValue()))
- reason += "Name is out of date\n";
-
- String kind = getItemKind(port);
- if (!kind.equals(Graphiti.getPeService().getPropertyValue(context.getPictogramElement(), PROP_KIND)))
- reason += "Figure is out of date\n";
- }
-
- if (!reason.isEmpty())
- return Reason.createTrueReason(reason.substring(0, reason.length()-1));
-
- return Reason.createFalseReason();
- }
-
- @Override
- public boolean update(IUpdateContext context) {
- ContainerShape containerShape = (ContainerShape)context.getPictogramElement();
- Object bo = getBusinessObjectForPictogramElement(containerShape);
- if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
- IRemoveContext rc = new RemoveContext(containerShape);
- IFeatureProvider featureProvider = getFeatureProvider();
- IRemoveFeature removeFeature = featureProvider.getRemoveFeature(rc);
- if (removeFeature != null) {
- removeFeature.remove(rc);
- }
- EcoreUtil.delete((EObject) bo);
- return true;
- }
- InterfaceItem port = (InterfaceItem) bo;
-
- boolean inherited = isInherited(port, bo, containerShape);
-
- Color dark = manageColor(inherited? INHERITED_COLOR:DARK_COLOR);
- updateFigure(port, containerShape, dark, manageColor(BRIGHT_COLOR));
- String kind = getItemKind(port);
- Graphiti.getPeService().setPropertyValue(containerShape, PROP_KIND, kind);
- return true;
- }
-
- protected abstract String getItemKind(InterfaceItem item);
- protected abstract void updateFigure(InterfaceItem item, PictogramElement pe, Color dark, Color bright);
- }
-
-
- protected static abstract class PropertyFeature extends AbstractCustomFeature {
-
- private String name;
- private String description;
-
- public PropertyFeature(IFeatureProvider fp, String name, String description) {
- super(fp);
- this.name = name;
- this.description = description;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getDescription() {
- return description;
- }
-
- @Override
- public boolean canExecute(ICustomContext context) {
- PictogramElement[] pes = context.getPictogramElements();
- if (pes != null && pes.length == 1 && pes[0] instanceof ContainerShape) {
- Object bo = getBusinessObjectForPictogramElement(pes[0]);
- if (bo instanceof InterfaceItem) {
- ContainerShape shape = ((ContainerShape)pes[0]).getContainer();
- InterfaceItem item = (InterfaceItem) bo;
- Object parentBO = getBusinessObjectForPictogramElement(shape.getContainer());
-
- return !isRefItem(shape) && !isInherited(item, parentBO, shape);
- }
- }
- return false;
- }
- }
-
- protected static class RemoveFeature extends DefaultRemoveFeature {
-
- public RemoveFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- public boolean canRemove(IRemoveContext context) {
- return false;
- }
- }
-
- protected static class DeleteFeature extends DeleteWithoutConfirmFeature {
-
- public DeleteFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canDelete(IDeleteContext context) {
- ContainerShape shape = (ContainerShape) context.getPictogramElement();
- Object bo = getBusinessObjectForPictogramElement(shape);
- if (bo instanceof EObject && ((EObject)bo).eIsProxy())
- return true;
-
- InterfaceItem item = (InterfaceItem) bo;
- Object parentBO = getBusinessObjectForPictogramElement(shape.getContainer());
-
- return !isRefItem(shape) && !isInherited(item, parentBO, shape);
- }
- }
-
- protected IFeatureProvider fp;
-
- protected FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp) {
- super(dtp);
- this.fp = fp;
- }
-
- protected static boolean isRefItem(PictogramElement pe) {
- if (!(pe instanceof ContainerShape))
- return false;
-
- ContainerShape acShape = ((ContainerShape)pe).getContainer();
-
- if (acShape.getLink()==null || acShape.getLink().getBusinessObjects().isEmpty())
- return false;
-
- Object parent = acShape.getLink().getBusinessObjects().get(0);
-
- return (parent instanceof ActorContainerRef);
- }
-
- protected static boolean isInternal(InterfaceItem item) {
- if (item instanceof Port) {
- Port port = (Port) item;
-
- // NB: the port's container might be a base class of the depicted actor class
- ActorContainerClass acc = (ActorContainerClass) port.eContainer();
- if (acc instanceof ActorClass) {
- ActorClass ac = (ActorClass) acc;
- if (ac.getIntPorts().contains(port))
- return true;
- }
- }
- else if (item instanceof SPPRef) {
- return false;
- }
- else {
- assert(false): "unexpected sub type";
- }
-
- return false;
- }
-
- protected static boolean isInherited(InterfaceItem item, Object container, ContainerShape cs) {
- if (container instanceof ActorClass) {
- ActorClass ac = (ActorClass) container;
- return item.eContainer()!=ac;
- }
- else if (container instanceof ActorRef) {
- // have to check whether the ActorRef is inherited
- ActorRef ar = (ActorRef) container;
- ContainerShape arCont = cs.getContainer();
- EObject cls = arCont.getLink().getBusinessObjects().get(0);
- if (cls instanceof ActorClass)
- return ar.eContainer()!=cls;
-
- // cls is a SubSystemClass
- return false;
- }
- else if (container instanceof SubSystemRef) {
- // SubSystemRefs only occur in LogicalSystems, no inheritance
- return false;
- }
-
- return false;
- }
-
- protected static boolean isValidPosition(ILocationContext loc, ITargetContext tgt, boolean internal, int margin) {
- //System.out.println("isValidPosition "+tgt.getTargetContainer());
- if (tgt.getTargetContainer().getGraphicsAlgorithm()==null)
- return false;
- if (tgt.getTargetContainer().getGraphicsAlgorithm().getGraphicsAlgorithmChildren().isEmpty())
- return false;
-
- int x = loc.getX();
- int y = loc.getY();
- if (loc instanceof ICreateContext) {
- // adjust position as relative to visible rectangle
- x -= margin;
- y -= margin;
- }
- int width = tgt.getTargetContainer().getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0).getWidth();
- int height = tgt.getTargetContainer().getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0).getHeight();
-
- boolean inStripe = false;
-
- // may move in a stripe along the actor class border
- int stripe = margin/2;
- if (x<=stripe)
- inStripe = true;
- else if (y<=stripe)
- inStripe = true;
- else if ((width-stripe)<=x)
- inStripe = true;
- else if ((height-stripe)<=y)
- inStripe = true;
-
- //System.out.println("w:"+width+" h:"+height+" x:"+x+" y:"+y+" in stripe "+inStripe);
-
- if (internal)
- return !inStripe;
- else
- return inStripe;
- }
-
- @Override
- public IMoveShapeFeature getMoveShapeFeature(IMoveShapeContext context) {
- return new MoveShapeFeature(fp);
- }
-
- @Override
- public IResizeShapeFeature getResizeShapeFeature(IResizeShapeContext context) {
- return new NoResizeFeature(fp);
- }
-
- @Override
- public IRemoveFeature getRemoveFeature(IRemoveContext context) {
- return new RemoveFeature(fp);
- }
-
- @Override
- public IDeleteFeature getDeleteFeature(IDeleteContext context) {
- return new DeleteFeature(fp);
- }
-
- protected static void adjustLabel(Text label, int x, int y, int width, int margin, int size) {
- Orientation align = Orientation.ALIGNMENT_CENTER;
- label.setHorizontalAlignment(align);
-
- int pos = margin+size/2;
-
- if (x<=margin)
- align = Orientation.ALIGNMENT_LEFT;
- else if ((width-margin)<=x)
- align = Orientation.ALIGNMENT_RIGHT;
- if (y<=margin)
- pos = (margin-size)/2;
-
- if (align!=label.getHorizontalAlignment()) {
- label.setHorizontalAlignment(align);
- }
- if (pos!=label.getY()) {
- IGaService gaService = Graphiti.getGaService();
- gaService.setLocationAndSize(label, 0, pos, 2*margin, margin/2);
- }
- }
-
- }
-
- protected static class BehaviorProvider extends DefaultToolBehaviorProvider {
-
- public BehaviorProvider(IDiagramTypeProvider dtp) {
- super(dtp);
- }
-
- @Override
- public GraphicsAlgorithm[] getClickArea(PictogramElement pe) {
- GraphicsAlgorithm invisible = pe.getGraphicsAlgorithm();
- GraphicsAlgorithm rectangle =
- invisible.getGraphicsAlgorithmChildren().get(0);
- return new GraphicsAlgorithm[] { rectangle };
- }
-
- @Override
- public GraphicsAlgorithm getSelectionBorder(PictogramElement pe) {
- GraphicsAlgorithm invisible = pe.getGraphicsAlgorithm();
-
- GraphicsAlgorithm rectangle =
- invisible.getGraphicsAlgorithmChildren().get(0);
- return rectangle;
- }
-
- @Override
- public Object getToolTip(GraphicsAlgorithm ga) {
- // if this is called we know there is a business object!=null
- PictogramElement pe = ga.getPictogramElement();
-
- EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe);
- if (bo instanceof InterfaceItem) {
- InterfaceItem ifitem = (InterfaceItem) bo;
- String name = ifitem.getName();
- String protocol = RoomHelpers.getGeneralProtocol(ifitem).getName();
- if (ifitem instanceof Port) {
- Port port = (Port) ifitem;
- if (port.getMultiplicity()==-1)
- name += "[*]";
- else if (port.getMultiplicity()>1)
- name += "["+port.getMultiplicity()+"]";
- if (port.isConjugated())
- protocol = "conj "+protocol;
- }
-
- return name+"\n("+protocol+")";
- }
- return super.getToolTip(ga);
- }
- }
-
- public static void createRefItems(ActorContainerRef acr, ContainerShape refShape, IFeatureProvider featureProvider) {
-
- ActorContainerClass refClass = (acr instanceof ActorRef)?((ActorRef)acr).getType():((SubSystemRef)acr).getType();
- List<InterfaceItem> refItems = RoomHelpers.getInterfaceItems(refClass, true);
-
- if (refShape!=null && refClass!=null &&!refItems.isEmpty()) {
-
- // the diagram will be created and initialized if not present
- // TODOHRR: how to proceed if diagram not up to date?
- Diagram refDiag = new DiagramAccess().getDiagram(refClass);
-
- ResourceSet rs = acr.eResource().getResourceSet();
-
- if (!refDiag.getChildren().isEmpty()) {
- ContainerShape refAcShape = (ContainerShape) refDiag.getChildren().get(0);
- Object bo = featureProvider.getBusinessObjectForPictogramElement(refAcShape);
- if (bo instanceof ActorContainerClass) {
- ActorContainerClass extRefClass = (ActorContainerClass) bo;
- assert(extRefClass.getName().equals(refClass.getName())): "structure class names must match";
-
- List<InterfaceItem> extRefItems = RoomHelpers.getInterfaceItems(extRefClass, true);
- List<InterfaceItem> intRefItems = SupportUtil.getInterfaceItems(refShape, featureProvider);
-
- // relate visible rectangle sizes to each other and compute scale factors
- double scaleX = (refAcShape.getGraphicsAlgorithm().getWidth()-2*StructureClassSupport.MARGIN)
- /(double)(refShape.getGraphicsAlgorithm().getWidth()-2*ActorContainerRefSupport.MARGIN);
- double scaleY = (refAcShape.getGraphicsAlgorithm().getHeight()-2*StructureClassSupport.MARGIN)
- /(double)(refShape.getGraphicsAlgorithm().getHeight()-2*ActorContainerRefSupport.MARGIN);
-
- for (Shape childShape : refAcShape.getChildren()) {
- bo = featureProvider.getBusinessObjectForPictogramElement(childShape);
- if (bo instanceof InterfaceItem) {
- if (extRefItems.contains(bo)) {
- // this is an interface item, insert it
-
- EObject ownObject = SupportUtil.getOwnObject((InterfaceItem)bo, rs);
- if (!intRefItems.contains(ownObject)) {
- // original mid points relative to visible rectangle
- int origMidX = childShape.getGraphicsAlgorithm().getX();
- int origMidY = childShape.getGraphicsAlgorithm().getY();
- int x = (int) (origMidX/scaleX);
- int y = (int) (origMidY/scaleY);
-
- // translate to get mid points relative to invisible rectangle
- x += ActorContainerRefSupport.MARGIN;
- y += ActorContainerRefSupport.MARGIN;
-
- SupportUtil.addItem(ownObject, x, y, refShape, featureProvider);
- }
- }
- }
- }
- }
- }
- else {
- assert(false): "empty referenced structure class diagram";
- }
- }
- }
-
- protected static void createInheritedRefItems(ActorContainerRef acr, ContainerShape arShape, IFeatureProvider fp) {
-
- ActorClass ac = (ActorClass) acr.eContainer();
- ResourceSet rs = ac.eResource().getResourceSet();
- List<InterfaceItem> presentObjects = SupportUtil.getInterfaceItems(arShape, fp);
-
- Diagram refDiag = new DiagramAccess().getDiagram(ac);
- if (!refDiag.getChildren().isEmpty()) {
- ContainerShape refAcShape = (ContainerShape) refDiag.getChildren().get(0);
- Object bo = fp.getBusinessObjectForPictogramElement(refAcShape);
- if (bo instanceof ActorClass) {
- ActorClass extRefClass = (ActorClass) bo;
- assert(extRefClass.getName().equals(ac.getName())): "actor class names must match";
-
- for (Shape childShape : refAcShape.getChildren()) {
- bo = fp.getBusinessObjectForPictogramElement(childShape);
- if (bo instanceof ActorRef) {
- EObject ownObject = SupportUtil.getOwnObject((ActorRef)bo, rs);
- if (ownObject==acr) {
- int subScaleX = arShape.getGraphicsAlgorithm().getWidth()/ActorContainerRefSupport.DEFAULT_SIZE_X;
- int subScaleY = arShape.getGraphicsAlgorithm().getHeight()/ActorContainerRefSupport.DEFAULT_SIZE_Y;
-
- // add items of actor ref
- for (Shape grandChildShape : ((ContainerShape)childShape).getChildren()) {
- bo = fp.getBusinessObjectForPictogramElement(grandChildShape);
- if (bo instanceof InterfaceItem) {
- ownObject = SupportUtil.getOwnObject((Port)bo, rs);
- if (!presentObjects.contains(ownObject)) {
- int x = ITEM_SIZE_SMALL/2 + grandChildShape.getGraphicsAlgorithm().getX()/subScaleX;
- int y = ITEM_SIZE_SMALL/2 + grandChildShape.getGraphicsAlgorithm().getY()/subScaleY;
- SupportUtil.addItem(ownObject, x, y, arShape, fp);
- }
- }
- }
- break;
- }
- }
- }
- }
- }
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.support;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.ActorContainerClass;
+import org.eclipse.etrice.core.room.ActorContainerRef;
+import org.eclipse.etrice.core.room.ActorRef;
+import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.etrice.core.room.Port;
+import org.eclipse.etrice.core.room.SPPRef;
+import org.eclipse.etrice.core.room.SubSystemRef;
+import org.eclipse.etrice.core.room.util.RoomHelpers;
+import org.eclipse.etrice.ui.common.support.DeleteWithoutConfirmFeature;
+import org.eclipse.etrice.ui.common.support.NoResizeFeature;
+import org.eclipse.etrice.ui.structure.DiagramAccess;
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.features.IDeleteFeature;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.IMoveShapeFeature;
+import org.eclipse.graphiti.features.IReason;
+import org.eclipse.graphiti.features.IRemoveFeature;
+import org.eclipse.graphiti.features.IResizeShapeFeature;
+import org.eclipse.graphiti.features.context.IAddContext;
+import org.eclipse.graphiti.features.context.ICreateContext;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.context.IDeleteContext;
+import org.eclipse.graphiti.features.context.ILocationContext;
+import org.eclipse.graphiti.features.context.IMoveShapeContext;
+import org.eclipse.graphiti.features.context.IRemoveContext;
+import org.eclipse.graphiti.features.context.IResizeShapeContext;
+import org.eclipse.graphiti.features.context.ITargetContext;
+import org.eclipse.graphiti.features.context.IUpdateContext;
+import org.eclipse.graphiti.features.context.impl.RemoveContext;
+import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
+import org.eclipse.graphiti.features.impl.AbstractAddFeature;
+import org.eclipse.graphiti.features.impl.AbstractCreateFeature;
+import org.eclipse.graphiti.features.impl.AbstractUpdateFeature;
+import org.eclipse.graphiti.features.impl.DefaultMoveShapeFeature;
+import org.eclipse.graphiti.features.impl.DefaultRemoveFeature;
+import org.eclipse.graphiti.features.impl.Reason;
+import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.algorithms.Rectangle;
+import org.eclipse.graphiti.mm.algorithms.Text;
+import org.eclipse.graphiti.mm.algorithms.styles.Color;
+import org.eclipse.graphiti.mm.algorithms.styles.Orientation;
+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.mm.pictograms.Shape;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.IGaService;
+import org.eclipse.graphiti.services.IPeCreateService;
+import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider;
+import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;
+import org.eclipse.graphiti.util.ColorConstant;
+import org.eclipse.graphiti.util.IColorConstant;
+
+public class InterfaceItemSupport {
+
+ public static final int ITEM_SIZE = StructureClassSupport.MARGIN;
+ public static final int ITEM_SIZE_SMALL = (int) (ActorContainerRefSupport.MARGIN*0.625);
+ public static final int MARGIN = StructureClassSupport.MARGIN;
+ public static final int MARGIN_SMALL = ActorContainerRefSupport.MARGIN;
+
+ protected static final int LINE_WIDTH = 2;
+ protected static final IColorConstant DARK_COLOR = new ColorConstant(0, 0, 0);
+ protected static final IColorConstant INHERITED_COLOR = new ColorConstant(100, 100, 100);
+ protected static final IColorConstant BRIGHT_COLOR = new ColorConstant(255, 255, 255);
+ protected static final String PROP_KIND = "item-kind";
+
+ protected static class FeatureProvider extends DefaultFeatureProvider {
+
+ protected abstract static class CreateFeature extends AbstractCreateFeature {
+
+ protected boolean internal;
+ protected boolean doneChanges = false;
+
+ public CreateFeature(IFeatureProvider fp, boolean internal, String name, String description) {
+ super(fp, name, description);
+ this.internal = internal;
+ }
+
+ @Override
+ public boolean canCreate(ICreateContext context) {
+ if (context.getTargetContainer().getLink()!=null)
+ if (context.getTargetContainer().getLink().getBusinessObjects().size()==1) {
+ EObject obj = context.getTargetContainer().getLink().getBusinessObjects().get(0);
+ if (obj instanceof ActorContainerClass) {
+ if (obj instanceof ActorClass)
+ return isValidPosition(context, context, internal, StructureClassSupport.MARGIN);
+ else
+ return !internal;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean hasDoneChanges() {
+ return doneChanges;
+ }
+ }
+
+ protected abstract static class AddFeature extends AbstractAddFeature {
+
+ public AddFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canAdd(IAddContext context) {
+ if (context.getNewObject() instanceof InterfaceItem) {
+ if (context.getTargetContainer().getLink().getBusinessObjects().size()==1) {
+ EObject obj = context.getTargetContainer().getLink().getBusinessObjects().get(0);
+ if (obj instanceof ActorContainerClass) {
+ return true;
+ }
+ if (obj instanceof ActorContainerRef) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public PictogramElement add(IAddContext context) {
+ InterfaceItem port = (InterfaceItem) context.getNewObject();
+ boolean internal = isInternal(port);
+ ContainerShape acShape = context.getTargetContainer();
+ Object bo = getBusinessObjectForPictogramElement(acShape);
+ boolean inherited = isInherited(port, bo, acShape);
+ boolean refport = (bo instanceof ActorContainerRef);
+
+ int margin = refport?MARGIN_SMALL:MARGIN;
+ int size = refport?ITEM_SIZE_SMALL:ITEM_SIZE;
+
+ // CONTAINER SHAPE WITH RECTANGLE
+ IPeCreateService peCreateService = Graphiti.getPeCreateService();
+ ContainerShape containerShape =
+ peCreateService.createContainerShape(acShape, true);
+
+ Graphiti.getPeService().setPropertyValue(containerShape, Constants.TYPE_KEY, Constants.PORT_TYPE);
+
+ String kind = getItemKind(port);
+ Graphiti.getPeService().setPropertyValue(containerShape, PROP_KIND, kind);
+
+ // the context point is the midpoint relative to the invisible rectangle
+ int x = context.getX();
+ int y = context.getY();
+ int width = acShape.getGraphicsAlgorithm().getWidth();
+ int height = acShape.getGraphicsAlgorithm().getHeight();
+ if (internal) {
+ if (x<2*margin)
+ x = 2*margin;
+ else if (x>width-2*margin)
+ x = width-2*margin;
+ if (y<2*margin)
+ y = 2*margin;
+ else if (y>height-2*margin)
+ y = height-2*margin;
+ }
+ else {
+ // TODOHRR: remove duplicate code
+ int dx = (x<=width/2)? x:width-x;
+ int dy = (y<=height/2)? y:height-y;
+ if (dx>dy) {
+ // keep x, project y
+ if (y<=height/2)
+ y = margin;
+ else
+ y = height-margin;
+
+ if (x<margin)
+ x = margin;
+ else if (x>width-margin)
+ x = width-margin;
+ }
+ else {
+ // keep y, project x
+ if (x<=width/2)
+ x = margin;
+ else
+ x = width-margin;
+
+ if (y<margin)
+ y = margin;
+ else if (y>height-margin)
+ y = height-margin;
+ }
+ }
+ // finally we subtract the midpoint to get coordinates of the upper left corner
+ x -= margin;
+ y -= margin;
+
+ Color dark = manageColor(inherited? INHERITED_COLOR:DARK_COLOR);
+ IGaService gaService = Graphiti.getGaService();
+ {
+ final Rectangle invisibleRectangle = gaService.createInvisibleRectangle(containerShape);
+ gaService.setLocationAndSize(invisibleRectangle, x, y, 2*margin, 2*margin);
+
+ createItemFigure(port, refport,
+ containerShape,
+ invisibleRectangle,
+ dark,
+ manageColor(BRIGHT_COLOR));
+
+ // create link and wire it
+ link(containerShape, port);
+ }
+
+ {
+ Shape labelShape = peCreateService.createShape(containerShape, false);
+ Text label = gaService.createDefaultText(getDiagram(), labelShape, port.getName());
+ label.setForeground(dark);
+ label.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
+ label.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
+// label.setBackground(manageColor(INHERITED_COLOR));
+// label.setFilled(true);
+// label.setLineVisible(true);
+// label.setLineWidth(3);
+// label.setLineStyle(LineStyle.DOT);
+ gaService.setLocationAndSize(label, 0, margin+size/2, 2*margin, margin/2);
+ adjustLabel(label, x, y, width, margin, size);
+ }
+
+ // call the layout feature
+ layoutPictogramElement(containerShape);
+
+ return containerShape;
+
+ }
+
+ protected abstract String getItemKind(InterfaceItem item);
+ protected abstract void createItemFigure(InterfaceItem item, boolean refitem,
+ ContainerShape containerShape,
+ GraphicsAlgorithm invisibleRectangle, Color darkColor, Color brightDolor);
+ }
+
+ protected class MoveShapeFeature extends DefaultMoveShapeFeature {
+
+ public MoveShapeFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canMoveShape(IMoveShapeContext context) {
+ boolean canMove = super.canMoveShape(context);
+
+ if (canMove) {
+ Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
+ if (bo instanceof InterfaceItem) {
+ InterfaceItem item = (InterfaceItem) bo;
+
+ ContainerShape acShape = context.getTargetContainer();
+ Object parentBO = getBusinessObjectForPictogramElement(acShape);
+ boolean refport = (parentBO instanceof ActorContainerRef);
+ if (refport)
+ return true;
+
+ if (isInherited(item, parentBO, acShape))
+ return false;
+
+ int margin = refport?ActorContainerRefSupport.MARGIN:StructureClassSupport.MARGIN;
+ return isValidPosition(context, context, isInternal(item), margin);
+ }
+ return false;
+ }
+
+ return canMove;
+ }
+
+ @Override
+ protected void postMoveShape(IMoveShapeContext context) {
+ ContainerShape shapeToMove = (ContainerShape) context.getShape();
+
+ InterfaceItem item = (InterfaceItem) getBusinessObjectForPictogramElement(shapeToMove);
+ boolean internal = isInternal(item);
+ ContainerShape acShape = context.getTargetContainer();
+ boolean refport = (getBusinessObjectForPictogramElement(acShape) instanceof ActorContainerRef);
+
+ int margin = refport?MARGIN_SMALL:MARGIN;
+ int size = refport?ITEM_SIZE_SMALL:ITEM_SIZE;
+
+ int x = context.getX();
+ int y = context.getY();
+ int width = context.getTargetContainer().getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0).getWidth();
+ int height = context.getTargetContainer().getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0).getHeight();
+
+ if (internal) {
+ // nothing to do
+ }
+ else {
+ // project onto boundary
+ if (refport) {
+ int dx = (x<=width/2)? x:width-x;
+ int dy = (y<=height/2)? y:height-y;
+ if (dx>dy) {
+ // keep x, project y
+ if (y<=height/2)
+ y = 0;
+ else
+ y = height-0;
+
+ if (x<0)
+ x = 0;
+ else if (x>width-0)
+ x = width-0;
+ }
+ else {
+ // keep y, project x
+ if (x<=width/2)
+ x = 0;
+ else
+ x = width-0;
+
+ if (y<0)
+ y = 0;
+ else if (y>height-0)
+ y = height-0;
+ }
+ }
+ else {
+ if (x<=margin)
+ x = 0;
+ if (y<=margin)
+ y = 0;
+ if ((width-margin)<=x)
+ x = width;
+ if ((height-margin)<=y)
+ y = height;
+ }
+ }
+
+ Graphiti.getGaService().setLocation(shapeToMove.getGraphicsAlgorithm(), x, y, avoidNegativeCoordinates());
+
+ GraphicsAlgorithm ga = shapeToMove.getChildren().get(0).getGraphicsAlgorithm();
+ if (ga instanceof Text) {
+ adjustLabel((Text) ga, x, y, width, margin, size);
+ }
+ }
+ }
+
+ protected abstract class UpdateFeature extends AbstractUpdateFeature {
+
+ public UpdateFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canUpdate(IUpdateContext context) {
+ Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
+ if (bo instanceof EObject && ((EObject)bo).eIsProxy())
+ return true;
+
+ return bo instanceof InterfaceItem;
+ }
+
+ @Override
+ public IReason updateNeeded(IUpdateContext context) {
+ Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
+ if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
+ return Reason.createTrueReason("InterfaceItem deleted from model");
+ }
+ InterfaceItem port = (InterfaceItem) bo;
+
+ String reason = "";
+
+ // check if port still owned/inherited
+ ContainerShape containerShape = (ContainerShape)context.getPictogramElement();
+ bo = getBusinessObjectForPictogramElement(containerShape);
+ if (bo instanceof ActorClass) {
+ ActorClass ac = (ActorClass) bo;
+ boolean found = false;
+ do {
+ if (ac==port.eContainer())
+ found = true;
+ ac = ac.getBase();
+ }
+ while (!found && ac!=null);
+
+ if (!found)
+ reason += "InterfaceItem not inherited anymore\n";
+ }
+
+ GraphicsAlgorithm ga = containerShape.getChildren().get(0).getGraphicsAlgorithm();
+ if (ga instanceof Text) {
+ if (!port.getName().equals(((Text)ga).getValue()))
+ reason += "Name is out of date\n";
+
+ String kind = getItemKind(port);
+ if (!kind.equals(Graphiti.getPeService().getPropertyValue(context.getPictogramElement(), PROP_KIND)))
+ reason += "Figure is out of date\n";
+ }
+
+ if (!reason.isEmpty())
+ return Reason.createTrueReason(reason.substring(0, reason.length()-1));
+
+ return Reason.createFalseReason();
+ }
+
+ @Override
+ public boolean update(IUpdateContext context) {
+ ContainerShape containerShape = (ContainerShape)context.getPictogramElement();
+ Object bo = getBusinessObjectForPictogramElement(containerShape);
+ if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
+ IRemoveContext rc = new RemoveContext(containerShape);
+ IFeatureProvider featureProvider = getFeatureProvider();
+ IRemoveFeature removeFeature = featureProvider.getRemoveFeature(rc);
+ if (removeFeature != null) {
+ removeFeature.remove(rc);
+ }
+ EcoreUtil.delete((EObject) bo);
+ return true;
+ }
+ InterfaceItem port = (InterfaceItem) bo;
+
+ boolean inherited = isInherited(port, bo, containerShape);
+
+ Color dark = manageColor(inherited? INHERITED_COLOR:DARK_COLOR);
+ updateFigure(port, containerShape, dark, manageColor(BRIGHT_COLOR));
+ String kind = getItemKind(port);
+ Graphiti.getPeService().setPropertyValue(containerShape, PROP_KIND, kind);
+ return true;
+ }
+
+ protected abstract String getItemKind(InterfaceItem item);
+ protected abstract void updateFigure(InterfaceItem item, PictogramElement pe, Color dark, Color bright);
+ }
+
+
+ protected static abstract class PropertyFeature extends AbstractCustomFeature {
+
+ private String name;
+ private String description;
+
+ public PropertyFeature(IFeatureProvider fp, String name, String description) {
+ super(fp);
+ this.name = name;
+ this.description = description;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes != null && pes.length == 1 && pes[0] instanceof ContainerShape) {
+ Object bo = getBusinessObjectForPictogramElement(pes[0]);
+ if (bo instanceof InterfaceItem) {
+ ContainerShape shape = ((ContainerShape)pes[0]).getContainer();
+ InterfaceItem item = (InterfaceItem) bo;
+ Object parentBO = getBusinessObjectForPictogramElement(shape.getContainer());
+
+ return !isRefItem(shape) && !isInherited(item, parentBO, shape);
+ }
+ }
+ return false;
+ }
+ }
+
+ protected static class RemoveFeature extends DefaultRemoveFeature {
+
+ public RemoveFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ public boolean canRemove(IRemoveContext context) {
+ return false;
+ }
+ }
+
+ protected static class DeleteFeature extends DeleteWithoutConfirmFeature {
+
+ public DeleteFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canDelete(IDeleteContext context) {
+ ContainerShape shape = (ContainerShape) context.getPictogramElement();
+ Object bo = getBusinessObjectForPictogramElement(shape);
+ if (bo instanceof EObject && ((EObject)bo).eIsProxy())
+ return true;
+
+ InterfaceItem item = (InterfaceItem) bo;
+ Object parentBO = getBusinessObjectForPictogramElement(shape.getContainer());
+
+ return !isRefItem(shape) && !isInherited(item, parentBO, shape);
+ }
+ }
+
+ protected IFeatureProvider fp;
+
+ protected FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp) {
+ super(dtp);
+ this.fp = fp;
+ }
+
+ protected static boolean isRefItem(PictogramElement pe) {
+ if (!(pe instanceof ContainerShape))
+ return false;
+
+ ContainerShape acShape = ((ContainerShape)pe).getContainer();
+
+ if (acShape.getLink()==null || acShape.getLink().getBusinessObjects().isEmpty())
+ return false;
+
+ Object parent = acShape.getLink().getBusinessObjects().get(0);
+
+ return (parent instanceof ActorContainerRef);
+ }
+
+ protected static boolean isInternal(InterfaceItem item) {
+ if (item instanceof Port) {
+ Port port = (Port) item;
+
+ // NB: the port's container might be a base class of the depicted actor class
+ ActorContainerClass acc = (ActorContainerClass) port.eContainer();
+ if (acc instanceof ActorClass) {
+ ActorClass ac = (ActorClass) acc;
+ if (ac.getIntPorts().contains(port))
+ return true;
+ }
+ }
+ else if (item instanceof SPPRef) {
+ return false;
+ }
+ else {
+ assert(false): "unexpected sub type";
+ }
+
+ return false;
+ }
+
+ protected static boolean isInherited(InterfaceItem item, Object container, ContainerShape cs) {
+ if (container instanceof ActorClass) {
+ ActorClass ac = (ActorClass) container;
+ return item.eContainer()!=ac;
+ }
+ else if (container instanceof ActorRef) {
+ // have to check whether the ActorRef is inherited
+ ActorRef ar = (ActorRef) container;
+ ContainerShape arCont = cs.getContainer();
+ EObject cls = arCont.getLink().getBusinessObjects().get(0);
+ if (cls instanceof ActorClass)
+ return ar.eContainer()!=cls;
+
+ // cls is a SubSystemClass
+ return false;
+ }
+ else if (container instanceof SubSystemRef) {
+ // SubSystemRefs only occur in LogicalSystems, no inheritance
+ return false;
+ }
+
+ return false;
+ }
+
+ protected static boolean isValidPosition(ILocationContext loc, ITargetContext tgt, boolean internal, int margin) {
+ //System.out.println("isValidPosition "+tgt.getTargetContainer());
+ if (tgt.getTargetContainer().getGraphicsAlgorithm()==null)
+ return false;
+ if (tgt.getTargetContainer().getGraphicsAlgorithm().getGraphicsAlgorithmChildren().isEmpty())
+ return false;
+
+ int x = loc.getX();
+ int y = loc.getY();
+ if (loc instanceof ICreateContext) {
+ // adjust position as relative to visible rectangle
+ x -= margin;
+ y -= margin;
+ }
+ int width = tgt.getTargetContainer().getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0).getWidth();
+ int height = tgt.getTargetContainer().getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0).getHeight();
+
+ boolean inStripe = false;
+
+ // may move in a stripe along the actor class border
+ int stripe = margin/2;
+ if (x<=stripe)
+ inStripe = true;
+ else if (y<=stripe)
+ inStripe = true;
+ else if ((width-stripe)<=x)
+ inStripe = true;
+ else if ((height-stripe)<=y)
+ inStripe = true;
+
+ //System.out.println("w:"+width+" h:"+height+" x:"+x+" y:"+y+" in stripe "+inStripe);
+
+ if (internal)
+ return !inStripe;
+ else
+ return inStripe;
+ }
+
+ @Override
+ public IMoveShapeFeature getMoveShapeFeature(IMoveShapeContext context) {
+ return new MoveShapeFeature(fp);
+ }
+
+ @Override
+ public IResizeShapeFeature getResizeShapeFeature(IResizeShapeContext context) {
+ return new NoResizeFeature(fp);
+ }
+
+ @Override
+ public IRemoveFeature getRemoveFeature(IRemoveContext context) {
+ return new RemoveFeature(fp);
+ }
+
+ @Override
+ public IDeleteFeature getDeleteFeature(IDeleteContext context) {
+ return new DeleteFeature(fp);
+ }
+
+ protected static void adjustLabel(Text label, int x, int y, int width, int margin, int size) {
+ Orientation align = Orientation.ALIGNMENT_CENTER;
+ label.setHorizontalAlignment(align);
+
+ int pos = margin+size/2;
+
+ if (x<=margin)
+ align = Orientation.ALIGNMENT_LEFT;
+ else if ((width-margin)<=x)
+ align = Orientation.ALIGNMENT_RIGHT;
+ if (y<=margin)
+ pos = (margin-size)/2;
+
+ if (align!=label.getHorizontalAlignment()) {
+ label.setHorizontalAlignment(align);
+ }
+ if (pos!=label.getY()) {
+ IGaService gaService = Graphiti.getGaService();
+ gaService.setLocationAndSize(label, 0, pos, 2*margin, margin/2);
+ }
+ }
+
+ }
+
+ protected static class BehaviorProvider extends DefaultToolBehaviorProvider {
+
+ public BehaviorProvider(IDiagramTypeProvider dtp) {
+ super(dtp);
+ }
+
+ @Override
+ public GraphicsAlgorithm[] getClickArea(PictogramElement pe) {
+ GraphicsAlgorithm invisible = pe.getGraphicsAlgorithm();
+ GraphicsAlgorithm rectangle =
+ invisible.getGraphicsAlgorithmChildren().get(0);
+ return new GraphicsAlgorithm[] { rectangle };
+ }
+
+ @Override
+ public GraphicsAlgorithm getSelectionBorder(PictogramElement pe) {
+ GraphicsAlgorithm invisible = pe.getGraphicsAlgorithm();
+
+ GraphicsAlgorithm rectangle =
+ invisible.getGraphicsAlgorithmChildren().get(0);
+ return rectangle;
+ }
+
+ @Override
+ public Object getToolTip(GraphicsAlgorithm ga) {
+ // if this is called we know there is a business object!=null
+ PictogramElement pe = ga.getPictogramElement();
+
+ EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe);
+ if (bo instanceof InterfaceItem) {
+ InterfaceItem ifitem = (InterfaceItem) bo;
+ String name = ifitem.getName();
+ String protocol = RoomHelpers.getGeneralProtocol(ifitem).getName();
+ if (ifitem instanceof Port) {
+ Port port = (Port) ifitem;
+ if (port.getMultiplicity()==-1)
+ name += "[*]";
+ else if (port.getMultiplicity()>1)
+ name += "["+port.getMultiplicity()+"]";
+ if (port.isConjugated())
+ protocol = "conj "+protocol;
+ }
+
+ return name+"\n("+protocol+")";
+ }
+ return super.getToolTip(ga);
+ }
+ }
+
+ public static void createRefItems(ActorContainerRef acr, ContainerShape refShape, IFeatureProvider featureProvider) {
+
+ ActorContainerClass refClass = (acr instanceof ActorRef)?((ActorRef)acr).getType():((SubSystemRef)acr).getType();
+ List<InterfaceItem> refItems = RoomHelpers.getInterfaceItems(refClass, true);
+
+ if (refShape!=null && refClass!=null &&!refItems.isEmpty()) {
+
+ // the diagram will be created and initialized if not present
+ // TODOHRR: how to proceed if diagram not up to date?
+ Diagram refDiag = new DiagramAccess().getDiagram(refClass);
+
+ ResourceSet rs = acr.eResource().getResourceSet();
+
+ if (!refDiag.getChildren().isEmpty()) {
+ ContainerShape refAcShape = (ContainerShape) refDiag.getChildren().get(0);
+ Object bo = featureProvider.getBusinessObjectForPictogramElement(refAcShape);
+ if (bo instanceof ActorContainerClass) {
+ ActorContainerClass extRefClass = (ActorContainerClass) bo;
+ assert(extRefClass.getName().equals(refClass.getName())): "structure class names must match";
+
+ List<InterfaceItem> extRefItems = RoomHelpers.getInterfaceItems(extRefClass, true);
+ List<InterfaceItem> intRefItems = SupportUtil.getInterfaceItems(refShape, featureProvider);
+
+ // relate visible rectangle sizes to each other and compute scale factors
+ double scaleX = (refAcShape.getGraphicsAlgorithm().getWidth()-2*StructureClassSupport.MARGIN)
+ /(double)(refShape.getGraphicsAlgorithm().getWidth()-2*ActorContainerRefSupport.MARGIN);
+ double scaleY = (refAcShape.getGraphicsAlgorithm().getHeight()-2*StructureClassSupport.MARGIN)
+ /(double)(refShape.getGraphicsAlgorithm().getHeight()-2*ActorContainerRefSupport.MARGIN);
+
+ for (Shape childShape : refAcShape.getChildren()) {
+ bo = featureProvider.getBusinessObjectForPictogramElement(childShape);
+ if (bo instanceof InterfaceItem) {
+ if (extRefItems.contains(bo)) {
+ // this is an interface item, insert it
+
+ EObject ownObject = SupportUtil.getOwnObject((InterfaceItem)bo, rs);
+ if (!intRefItems.contains(ownObject)) {
+ // original mid points relative to visible rectangle
+ int origMidX = childShape.getGraphicsAlgorithm().getX();
+ int origMidY = childShape.getGraphicsAlgorithm().getY();
+ int x = (int) (origMidX/scaleX);
+ int y = (int) (origMidY/scaleY);
+
+ // translate to get mid points relative to invisible rectangle
+ x += ActorContainerRefSupport.MARGIN;
+ y += ActorContainerRefSupport.MARGIN;
+
+ SupportUtil.addItem(ownObject, x, y, refShape, featureProvider);
+ }
+ }
+ }
+ }
+ }
+ }
+ else {
+ assert(false): "empty referenced structure class diagram";
+ }
+ }
+ }
+
+ protected static void createInheritedRefItems(ActorContainerRef acr, ContainerShape arShape, IFeatureProvider fp) {
+
+ ActorClass ac = (ActorClass) acr.eContainer();
+ ResourceSet rs = ac.eResource().getResourceSet();
+ List<InterfaceItem> presentObjects = SupportUtil.getInterfaceItems(arShape, fp);
+
+ Diagram refDiag = new DiagramAccess().getDiagram(ac);
+ if (!refDiag.getChildren().isEmpty()) {
+ ContainerShape refAcShape = (ContainerShape) refDiag.getChildren().get(0);
+ Object bo = fp.getBusinessObjectForPictogramElement(refAcShape);
+ if (bo instanceof ActorClass) {
+ ActorClass extRefClass = (ActorClass) bo;
+ assert(extRefClass.getName().equals(ac.getName())): "actor class names must match";
+
+ for (Shape childShape : refAcShape.getChildren()) {
+ bo = fp.getBusinessObjectForPictogramElement(childShape);
+ if (bo instanceof ActorRef) {
+ EObject ownObject = SupportUtil.getOwnObject((ActorRef)bo, rs);
+ if (ownObject==acr) {
+ int subScaleX = arShape.getGraphicsAlgorithm().getWidth()/ActorContainerRefSupport.DEFAULT_SIZE_X;
+ int subScaleY = arShape.getGraphicsAlgorithm().getHeight()/ActorContainerRefSupport.DEFAULT_SIZE_Y;
+
+ // add items of actor ref
+ for (Shape grandChildShape : ((ContainerShape)childShape).getChildren()) {
+ bo = fp.getBusinessObjectForPictogramElement(grandChildShape);
+ if (bo instanceof InterfaceItem) {
+ ownObject = SupportUtil.getOwnObject((Port)bo, rs);
+ if (!presentObjects.contains(ownObject)) {
+ int x = ITEM_SIZE_SMALL/2 + grandChildShape.getGraphicsAlgorithm().getX()/subScaleX;
+ int y = ITEM_SIZE_SMALL/2 + grandChildShape.getGraphicsAlgorithm().getY()/subScaleY;
+ SupportUtil.addItem(ownObject, x, y, arShape, fp);
+ }
+ }
+ }
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/LayerConnectionSupport.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/LayerConnectionSupport.java
index d2e061b65..a48d1a879 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/LayerConnectionSupport.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/LayerConnectionSupport.java
@@ -1,421 +1,421 @@
-/*******************************************************************************
- * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.structure.support;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.etrice.core.room.ActorContainerClass;
-import org.eclipse.etrice.core.room.ActorContainerRef;
-import org.eclipse.etrice.core.room.LayerConnection;
-import org.eclipse.etrice.core.room.RefSAPoint;
-import org.eclipse.etrice.core.room.RelaySAPoint;
-import org.eclipse.etrice.core.room.RoomFactory;
-import org.eclipse.etrice.core.room.SAPoint;
-import org.eclipse.etrice.core.room.SPPRef;
-import org.eclipse.etrice.core.room.SPPoint;
-import org.eclipse.etrice.core.room.StructureClass;
-import org.eclipse.etrice.core.validation.ValidationUtil;
-import org.eclipse.etrice.ui.common.support.DeleteWithoutConfirmFeature;
-import org.eclipse.etrice.ui.structure.ImageProvider;
-import org.eclipse.graphiti.dt.IDiagramTypeProvider;
-import org.eclipse.graphiti.features.IAddFeature;
-import org.eclipse.graphiti.features.ICreateConnectionFeature;
-import org.eclipse.graphiti.features.IDeleteFeature;
-import org.eclipse.graphiti.features.IFeatureProvider;
-import org.eclipse.graphiti.features.IReason;
-import org.eclipse.graphiti.features.IReconnectionFeature;
-import org.eclipse.graphiti.features.IRemoveFeature;
-import org.eclipse.graphiti.features.IUpdateFeature;
-import org.eclipse.graphiti.features.context.IAddConnectionContext;
-import org.eclipse.graphiti.features.context.IAddContext;
-import org.eclipse.graphiti.features.context.ICreateConnectionContext;
-import org.eclipse.graphiti.features.context.IDeleteContext;
-import org.eclipse.graphiti.features.context.IReconnectionContext;
-import org.eclipse.graphiti.features.context.IRemoveContext;
-import org.eclipse.graphiti.features.context.IUpdateContext;
-import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
-import org.eclipse.graphiti.features.context.impl.ReconnectionContext;
-import org.eclipse.graphiti.features.context.impl.RemoveContext;
-import org.eclipse.graphiti.features.impl.AbstractAddFeature;
-import org.eclipse.graphiti.features.impl.AbstractCreateConnectionFeature;
-import org.eclipse.graphiti.features.impl.AbstractUpdateFeature;
-import org.eclipse.graphiti.features.impl.DefaultReconnectionFeature;
-import org.eclipse.graphiti.features.impl.DefaultRemoveFeature;
-import org.eclipse.graphiti.features.impl.Reason;
-import org.eclipse.graphiti.mm.GraphicsAlgorithmContainer;
-import org.eclipse.graphiti.mm.algorithms.Polyline;
-import org.eclipse.graphiti.mm.pictograms.Anchor;
-import org.eclipse.graphiti.mm.pictograms.Connection;
-import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
-import org.eclipse.graphiti.mm.pictograms.Diagram;
-import org.eclipse.graphiti.mm.pictograms.ManhattanConnection;
-import org.eclipse.graphiti.mm.pictograms.PictogramElement;
-import org.eclipse.graphiti.mm.pictograms.PictogramsFactory;
-import org.eclipse.graphiti.services.Graphiti;
-import org.eclipse.graphiti.services.IGaService;
-import org.eclipse.graphiti.services.IPeCreateService;
-import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider;
-import org.eclipse.graphiti.tb.IToolBehaviorProvider;
-import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;
-import org.eclipse.graphiti.util.ColorConstant;
-import org.eclipse.graphiti.util.IColorConstant;
-
-public class LayerConnectionSupport {
-
- private static final IColorConstant LINE_COLOR = new ColorConstant(0, 0, 0);
- private static final int LINE_WIDTH = 2;
-
- class FeatureProvider extends DefaultFeatureProvider {
-
- private class CreateFeature extends AbstractCreateConnectionFeature {
-
- public CreateFeature(IFeatureProvider fp) {
- super(fp, "LayerConnection", "create LayerConnection");
- }
-
- @Override
- public String getCreateImageId() {
- return ImageProvider.IMG_LAYER_CONNECTION;
- }
-
- @Override
- public boolean canCreate(ICreateConnectionContext context) {
- IFeatureProvider featureProvider = getFeatureProvider();
- SPPRef src = SupportUtil.getSPPRef(context.getSourceAnchor(), featureProvider);
- ActorContainerRef srcRef = SupportUtil.getRef(context.getSourceAnchor(), featureProvider);
- SPPRef tgt = SupportUtil.getSPPRef(context.getTargetAnchor(), featureProvider);
- ActorContainerRef tgtRef = SupportUtil.getRef(context.getTargetAnchor(), featureProvider);
- StructureClass sc = SupportUtil.getParent(context, featureProvider);
-
- return ValidationUtil.isConnectable(src, srcRef, tgt, tgtRef, sc).isOk();
- }
-
- public boolean canStartConnection(ICreateConnectionContext context) {
- IFeatureProvider featureProvider = getFeatureProvider();
- SPPRef src = SupportUtil.getSPPRef(context.getSourceAnchor(), featureProvider);
- ActorContainerRef ref = SupportUtil.getRef(context.getSourceAnchor(), featureProvider);
- StructureClass sc = SupportUtil.getParent(context, featureProvider);
- return ValidationUtil.isConnectableSrc(src, ref, sc);
- }
-
- @Override
- public Connection create(ICreateConnectionContext context) {
- IFeatureProvider featureProvider = getFeatureProvider();
- SPPRef src = SupportUtil.getSPPRef(context.getSourceAnchor(), featureProvider);
- ActorContainerRef srcRef = SupportUtil.getRef(context.getSourceAnchor(), featureProvider);
- SPPRef dst = SupportUtil.getSPPRef(context.getTargetAnchor(), featureProvider);
- ActorContainerRef dstRef = SupportUtil.getRef(context.getTargetAnchor(), featureProvider);
- StructureClass sc = SupportUtil.getParent(context, featureProvider);
-
- LayerConnection lc = RoomFactory.eINSTANCE.createLayerConnection();
- SAPoint sapt = null;
- if (src!=null) {
- sapt = RoomFactory.eINSTANCE.createRelaySAPoint();
- ((RelaySAPoint)sapt).setRelay(src);
- }
- else if (srcRef!=null) {
- sapt = RoomFactory.eINSTANCE.createRefSAPoint();
- ((RefSAPoint)sapt).setRef(srcRef);
- }
- lc.setFrom(sapt);
-
- SPPoint sppt = RoomFactory.eINSTANCE.createSPPoint();
- sppt.setRef(dstRef);
- sppt.setService(dst);
- lc.setTo(sppt);
-
- sc.getConnections().add(lc);
-
- AddConnectionContext addContext = new AddConnectionContext(context.getSourceAnchor(), context.getTargetAnchor());
- addContext.setNewObject(lc);
- return (Connection) getFeatureProvider().addIfPossible(addContext);
- }
- }
-
- private class AddFeature extends AbstractAddFeature {
-
- public AddFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canAdd(IAddContext context) {
- if (context instanceof IAddConnectionContext && context.getNewObject() instanceof LayerConnection) {
- return true;
- }
- return false;
- }
-
- @Override
- public PictogramElement add(IAddContext context) {
- IAddConnectionContext addConContext = (IAddConnectionContext) context;
- LayerConnection lc = (LayerConnection) context.getNewObject();
-
- IPeCreateService peCreateService = Graphiti.getPeCreateService();
-
- Connection connection = createConnection();
- connection.setStart(addConContext.getSourceAnchor());
- connection.setEnd(addConContext.getTargetAnchor());
-
- Graphiti.getPeService().setPropertyValue(connection, Constants.TYPE_KEY, Constants.CONN_TYPE);
-
- IGaService gaService = Graphiti.getGaService();
- Polyline polyline = gaService.createPolyline(connection);
- polyline.setForeground(manageColor(LINE_COLOR));
- polyline.setLineWidth(LINE_WIDTH);
-
- ConnectionDecorator cd = peCreateService
- .createConnectionDecorator(connection, false, 1.0, true);
- createArrow(cd);
-
- // create link and wire it
- link(connection, lc);
-
- return connection;
- }
-
- private Connection createConnection() {
-// IPeCreateService peCreateService = Graphiti.getPeCreateService();
-// Connection ret = peCreateService.createManhattanConnection(getDiagram());
- //peCreateService.createFreeFormConnection(getDiagram());
- ManhattanConnection ret = PictogramsFactory.eINSTANCE.createManhattanConnection();
- ret.setVisible(true);
- ret.setActive(true);
- ret.setParent(getDiagram());
- return ret;
- }
-
- private Polyline createArrow(GraphicsAlgorithmContainer gaContainer) {
-
- IGaService gaService = Graphiti.getGaService();
- Polyline polyline =
- gaService.createPolyline(gaContainer, new int[] { -15, 10, 0, 0, -15, -10 });
-
- polyline.setForeground(manageColor(LINE_COLOR));
- polyline.setLineWidth(LINE_WIDTH);
-
- return polyline;
-
- }
-
- }
-
- private class RemoveFeature extends DefaultRemoveFeature {
-
- public RemoveFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canRemove(IRemoveContext context) {
- return false;
- }
- }
-
- private class DeleteFeature extends DeleteWithoutConfirmFeature {
-
- public DeleteFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canDelete(IDeleteContext context) {
- EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(context.getPictogramElement());
- if (bo instanceof LayerConnection) {
- LayerConnection lc = (LayerConnection) bo;
- if (isInherited(getDiagram(), lc))
- return false;
- }
-
- return true;
- }
- }
-
- private class ReconnectionFeature extends DefaultReconnectionFeature {
-
- private boolean doneChanges = false;
-
- public ReconnectionFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canReconnect(IReconnectionContext context) {
- if (!super.canReconnect(context))
- return false;
-
- LayerConnection lc = (LayerConnection) getBusinessObjectForPictogramElement(context.getConnection());
- if (isInherited(getDiagram(), lc))
- return false;
-
- Anchor asrc = context.getConnection().getStart();
- Anchor atgt = context.getConnection().getEnd();
- if (context.getReconnectType().equals(ReconnectionContext.RECONNECT_SOURCE))
- asrc = context.getNewAnchor();
- else
- atgt = context.getNewAnchor();
-
- IFeatureProvider featureProvider = getFeatureProvider();
- SPPRef src = SupportUtil.getSPPRef(asrc, featureProvider);
- ActorContainerRef srcRef = SupportUtil.getRef(asrc, featureProvider);
- SPPRef tgt = SupportUtil.getSPPRef(atgt, featureProvider);
- ActorContainerRef tgtRef = SupportUtil.getRef(atgt, featureProvider);
- StructureClass sc = SupportUtil.getParent(getDiagram(), featureProvider);
-
- return ValidationUtil.isConnectable(src, srcRef, tgt, tgtRef, sc).isOk();
- }
-
- @Override
- public void postReconnect(IReconnectionContext context) {
- super.postReconnect(context);
-
- IFeatureProvider featureProvider = getFeatureProvider();
- SPPRef src = SupportUtil.getSPPRef(context.getConnection().getStart(), featureProvider);
- ActorContainerRef srcRef = SupportUtil.getRef(context.getConnection().getStart(), featureProvider);
- SPPRef dst = SupportUtil.getSPPRef(context.getConnection().getEnd(), featureProvider);
- ActorContainerRef dstRef = SupportUtil.getRef(context.getConnection().getEnd(), featureProvider);
-
- doneChanges = true;
-
- LayerConnection lc = (LayerConnection) getBusinessObjectForPictogramElement(context.getConnection());
- SAPoint sapt = null;
- if (src!=null) {
- sapt = RoomFactory.eINSTANCE.createRelaySAPoint();
- ((RelaySAPoint)sapt).setRelay(src);
- }
- else if (srcRef!=null) {
- sapt = RoomFactory.eINSTANCE.createRefSAPoint();
- ((RefSAPoint)sapt).setRef(srcRef);
- }
- lc.setFrom(sapt);
-
- SPPoint sppt = RoomFactory.eINSTANCE.createSPPoint();
- sppt.setRef(dstRef);
- sppt.setService(dst);
- lc.setTo(sppt);
- }
-
- @Override
- public boolean hasDoneChanges() {
- return doneChanges ;
- }
- }
-
- private class UpdateFeature extends AbstractUpdateFeature {
-
- public UpdateFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canUpdate(IUpdateContext context) {
- Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
- if (bo instanceof EObject && ((EObject)bo).eIsProxy())
- return true;
-
- return false;
- }
-
- @Override
- public IReason updateNeeded(IUpdateContext context) {
- Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
- if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
- return Reason.createTrueReason("LayerConnection deleted from model");
- }
- return Reason.createFalseReason();
- }
-
- @Override
- public boolean update(IUpdateContext context) {
- PictogramElement pe = context.getPictogramElement();
- Object bo = getBusinessObjectForPictogramElement(pe);
- if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
- IRemoveContext rc = new RemoveContext(pe);
- IFeatureProvider featureProvider = getFeatureProvider();
- IRemoveFeature removeFeature = featureProvider.getRemoveFeature(rc);
- if (removeFeature != null) {
- removeFeature.remove(rc);
- }
- EcoreUtil.delete((EObject) bo);
- return true;
- }
- return false;
- }
- }
-
- private IFeatureProvider fp;
-
- public FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp) {
- super(dtp);
- this.fp = fp;
- }
-
- private boolean isInherited(Diagram diag, LayerConnection lc) {
- ActorContainerClass acc = (ActorContainerClass) Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(diag.getChildren().get(0));
- return (lc.eContainer()!=acc);
- }
-
- @Override
- public ICreateConnectionFeature[] getCreateConnectionFeatures() {
- return new ICreateConnectionFeature[] { new CreateFeature(fp) };
- }
-
- @Override
- public IAddFeature getAddFeature(IAddContext context) {
- return new AddFeature(fp);
- }
-
- @Override
- public IRemoveFeature getRemoveFeature(IRemoveContext context) {
- return new RemoveFeature(fp);
- }
-
- @Override
- public IDeleteFeature getDeleteFeature(IDeleteContext context) {
- return new DeleteFeature(fp);
- }
-
- @Override
- public IUpdateFeature getUpdateFeature(IUpdateContext context) {
- return new UpdateFeature(fp);
- }
-
- @Override
- public IReconnectionFeature getReconnectionFeature(IReconnectionContext context) {
- return new ReconnectionFeature(fp);
- }
- }
-
- class BehaviorProvider extends DefaultToolBehaviorProvider {
-
- public BehaviorProvider(IDiagramTypeProvider dtp) {
- super(dtp);
- }
- }
-
- private FeatureProvider pfp;
- private BehaviorProvider tbp;
-
- public LayerConnectionSupport(IDiagramTypeProvider dtp, IFeatureProvider fp) {
- pfp = new FeatureProvider(dtp,fp);
- tbp = new BehaviorProvider(dtp);
- }
-
- public IFeatureProvider getFeatureProvider() {
- return pfp;
- }
-
- public IToolBehaviorProvider getToolBehaviorProvider() {
- return tbp;
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.support;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.etrice.core.room.ActorContainerClass;
+import org.eclipse.etrice.core.room.ActorContainerRef;
+import org.eclipse.etrice.core.room.LayerConnection;
+import org.eclipse.etrice.core.room.RefSAPoint;
+import org.eclipse.etrice.core.room.RelaySAPoint;
+import org.eclipse.etrice.core.room.RoomFactory;
+import org.eclipse.etrice.core.room.SAPoint;
+import org.eclipse.etrice.core.room.SPPRef;
+import org.eclipse.etrice.core.room.SPPoint;
+import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.core.validation.ValidationUtil;
+import org.eclipse.etrice.ui.common.support.DeleteWithoutConfirmFeature;
+import org.eclipse.etrice.ui.structure.ImageProvider;
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.features.IAddFeature;
+import org.eclipse.graphiti.features.ICreateConnectionFeature;
+import org.eclipse.graphiti.features.IDeleteFeature;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.IReason;
+import org.eclipse.graphiti.features.IReconnectionFeature;
+import org.eclipse.graphiti.features.IRemoveFeature;
+import org.eclipse.graphiti.features.IUpdateFeature;
+import org.eclipse.graphiti.features.context.IAddConnectionContext;
+import org.eclipse.graphiti.features.context.IAddContext;
+import org.eclipse.graphiti.features.context.ICreateConnectionContext;
+import org.eclipse.graphiti.features.context.IDeleteContext;
+import org.eclipse.graphiti.features.context.IReconnectionContext;
+import org.eclipse.graphiti.features.context.IRemoveContext;
+import org.eclipse.graphiti.features.context.IUpdateContext;
+import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
+import org.eclipse.graphiti.features.context.impl.ReconnectionContext;
+import org.eclipse.graphiti.features.context.impl.RemoveContext;
+import org.eclipse.graphiti.features.impl.AbstractAddFeature;
+import org.eclipse.graphiti.features.impl.AbstractCreateConnectionFeature;
+import org.eclipse.graphiti.features.impl.AbstractUpdateFeature;
+import org.eclipse.graphiti.features.impl.DefaultReconnectionFeature;
+import org.eclipse.graphiti.features.impl.DefaultRemoveFeature;
+import org.eclipse.graphiti.features.impl.Reason;
+import org.eclipse.graphiti.mm.GraphicsAlgorithmContainer;
+import org.eclipse.graphiti.mm.algorithms.Polyline;
+import org.eclipse.graphiti.mm.pictograms.Anchor;
+import org.eclipse.graphiti.mm.pictograms.Connection;
+import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.ManhattanConnection;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.PictogramsFactory;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.IGaService;
+import org.eclipse.graphiti.services.IPeCreateService;
+import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider;
+import org.eclipse.graphiti.tb.IToolBehaviorProvider;
+import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;
+import org.eclipse.graphiti.util.ColorConstant;
+import org.eclipse.graphiti.util.IColorConstant;
+
+public class LayerConnectionSupport {
+
+ private static final IColorConstant LINE_COLOR = new ColorConstant(0, 0, 0);
+ private static final int LINE_WIDTH = 2;
+
+ class FeatureProvider extends DefaultFeatureProvider {
+
+ private class CreateFeature extends AbstractCreateConnectionFeature {
+
+ public CreateFeature(IFeatureProvider fp) {
+ super(fp, "LayerConnection", "create LayerConnection");
+ }
+
+ @Override
+ public String getCreateImageId() {
+ return ImageProvider.IMG_LAYER_CONNECTION;
+ }
+
+ @Override
+ public boolean canCreate(ICreateConnectionContext context) {
+ IFeatureProvider featureProvider = getFeatureProvider();
+ SPPRef src = SupportUtil.getSPPRef(context.getSourceAnchor(), featureProvider);
+ ActorContainerRef srcRef = SupportUtil.getRef(context.getSourceAnchor(), featureProvider);
+ SPPRef tgt = SupportUtil.getSPPRef(context.getTargetAnchor(), featureProvider);
+ ActorContainerRef tgtRef = SupportUtil.getRef(context.getTargetAnchor(), featureProvider);
+ StructureClass sc = SupportUtil.getParent(context, featureProvider);
+
+ return ValidationUtil.isConnectable(src, srcRef, tgt, tgtRef, sc).isOk();
+ }
+
+ public boolean canStartConnection(ICreateConnectionContext context) {
+ IFeatureProvider featureProvider = getFeatureProvider();
+ SPPRef src = SupportUtil.getSPPRef(context.getSourceAnchor(), featureProvider);
+ ActorContainerRef ref = SupportUtil.getRef(context.getSourceAnchor(), featureProvider);
+ StructureClass sc = SupportUtil.getParent(context, featureProvider);
+ return ValidationUtil.isConnectableSrc(src, ref, sc);
+ }
+
+ @Override
+ public Connection create(ICreateConnectionContext context) {
+ IFeatureProvider featureProvider = getFeatureProvider();
+ SPPRef src = SupportUtil.getSPPRef(context.getSourceAnchor(), featureProvider);
+ ActorContainerRef srcRef = SupportUtil.getRef(context.getSourceAnchor(), featureProvider);
+ SPPRef dst = SupportUtil.getSPPRef(context.getTargetAnchor(), featureProvider);
+ ActorContainerRef dstRef = SupportUtil.getRef(context.getTargetAnchor(), featureProvider);
+ StructureClass sc = SupportUtil.getParent(context, featureProvider);
+
+ LayerConnection lc = RoomFactory.eINSTANCE.createLayerConnection();
+ SAPoint sapt = null;
+ if (src!=null) {
+ sapt = RoomFactory.eINSTANCE.createRelaySAPoint();
+ ((RelaySAPoint)sapt).setRelay(src);
+ }
+ else if (srcRef!=null) {
+ sapt = RoomFactory.eINSTANCE.createRefSAPoint();
+ ((RefSAPoint)sapt).setRef(srcRef);
+ }
+ lc.setFrom(sapt);
+
+ SPPoint sppt = RoomFactory.eINSTANCE.createSPPoint();
+ sppt.setRef(dstRef);
+ sppt.setService(dst);
+ lc.setTo(sppt);
+
+ sc.getConnections().add(lc);
+
+ AddConnectionContext addContext = new AddConnectionContext(context.getSourceAnchor(), context.getTargetAnchor());
+ addContext.setNewObject(lc);
+ return (Connection) getFeatureProvider().addIfPossible(addContext);
+ }
+ }
+
+ private class AddFeature extends AbstractAddFeature {
+
+ public AddFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canAdd(IAddContext context) {
+ if (context instanceof IAddConnectionContext && context.getNewObject() instanceof LayerConnection) {
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public PictogramElement add(IAddContext context) {
+ IAddConnectionContext addConContext = (IAddConnectionContext) context;
+ LayerConnection lc = (LayerConnection) context.getNewObject();
+
+ IPeCreateService peCreateService = Graphiti.getPeCreateService();
+
+ Connection connection = createConnection();
+ connection.setStart(addConContext.getSourceAnchor());
+ connection.setEnd(addConContext.getTargetAnchor());
+
+ Graphiti.getPeService().setPropertyValue(connection, Constants.TYPE_KEY, Constants.CONN_TYPE);
+
+ IGaService gaService = Graphiti.getGaService();
+ Polyline polyline = gaService.createPolyline(connection);
+ polyline.setForeground(manageColor(LINE_COLOR));
+ polyline.setLineWidth(LINE_WIDTH);
+
+ ConnectionDecorator cd = peCreateService
+ .createConnectionDecorator(connection, false, 1.0, true);
+ createArrow(cd);
+
+ // create link and wire it
+ link(connection, lc);
+
+ return connection;
+ }
+
+ private Connection createConnection() {
+// IPeCreateService peCreateService = Graphiti.getPeCreateService();
+// Connection ret = peCreateService.createManhattanConnection(getDiagram());
+ //peCreateService.createFreeFormConnection(getDiagram());
+ ManhattanConnection ret = PictogramsFactory.eINSTANCE.createManhattanConnection();
+ ret.setVisible(true);
+ ret.setActive(true);
+ ret.setParent(getDiagram());
+ return ret;
+ }
+
+ private Polyline createArrow(GraphicsAlgorithmContainer gaContainer) {
+
+ IGaService gaService = Graphiti.getGaService();
+ Polyline polyline =
+ gaService.createPolyline(gaContainer, new int[] { -15, 10, 0, 0, -15, -10 });
+
+ polyline.setForeground(manageColor(LINE_COLOR));
+ polyline.setLineWidth(LINE_WIDTH);
+
+ return polyline;
+
+ }
+
+ }
+
+ private class RemoveFeature extends DefaultRemoveFeature {
+
+ public RemoveFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canRemove(IRemoveContext context) {
+ return false;
+ }
+ }
+
+ private class DeleteFeature extends DeleteWithoutConfirmFeature {
+
+ public DeleteFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canDelete(IDeleteContext context) {
+ EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(context.getPictogramElement());
+ if (bo instanceof LayerConnection) {
+ LayerConnection lc = (LayerConnection) bo;
+ if (isInherited(getDiagram(), lc))
+ return false;
+ }
+
+ return true;
+ }
+ }
+
+ private class ReconnectionFeature extends DefaultReconnectionFeature {
+
+ private boolean doneChanges = false;
+
+ public ReconnectionFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canReconnect(IReconnectionContext context) {
+ if (!super.canReconnect(context))
+ return false;
+
+ LayerConnection lc = (LayerConnection) getBusinessObjectForPictogramElement(context.getConnection());
+ if (isInherited(getDiagram(), lc))
+ return false;
+
+ Anchor asrc = context.getConnection().getStart();
+ Anchor atgt = context.getConnection().getEnd();
+ if (context.getReconnectType().equals(ReconnectionContext.RECONNECT_SOURCE))
+ asrc = context.getNewAnchor();
+ else
+ atgt = context.getNewAnchor();
+
+ IFeatureProvider featureProvider = getFeatureProvider();
+ SPPRef src = SupportUtil.getSPPRef(asrc, featureProvider);
+ ActorContainerRef srcRef = SupportUtil.getRef(asrc, featureProvider);
+ SPPRef tgt = SupportUtil.getSPPRef(atgt, featureProvider);
+ ActorContainerRef tgtRef = SupportUtil.getRef(atgt, featureProvider);
+ StructureClass sc = SupportUtil.getParent(getDiagram(), featureProvider);
+
+ return ValidationUtil.isConnectable(src, srcRef, tgt, tgtRef, sc).isOk();
+ }
+
+ @Override
+ public void postReconnect(IReconnectionContext context) {
+ super.postReconnect(context);
+
+ IFeatureProvider featureProvider = getFeatureProvider();
+ SPPRef src = SupportUtil.getSPPRef(context.getConnection().getStart(), featureProvider);
+ ActorContainerRef srcRef = SupportUtil.getRef(context.getConnection().getStart(), featureProvider);
+ SPPRef dst = SupportUtil.getSPPRef(context.getConnection().getEnd(), featureProvider);
+ ActorContainerRef dstRef = SupportUtil.getRef(context.getConnection().getEnd(), featureProvider);
+
+ doneChanges = true;
+
+ LayerConnection lc = (LayerConnection) getBusinessObjectForPictogramElement(context.getConnection());
+ SAPoint sapt = null;
+ if (src!=null) {
+ sapt = RoomFactory.eINSTANCE.createRelaySAPoint();
+ ((RelaySAPoint)sapt).setRelay(src);
+ }
+ else if (srcRef!=null) {
+ sapt = RoomFactory.eINSTANCE.createRefSAPoint();
+ ((RefSAPoint)sapt).setRef(srcRef);
+ }
+ lc.setFrom(sapt);
+
+ SPPoint sppt = RoomFactory.eINSTANCE.createSPPoint();
+ sppt.setRef(dstRef);
+ sppt.setService(dst);
+ lc.setTo(sppt);
+ }
+
+ @Override
+ public boolean hasDoneChanges() {
+ return doneChanges ;
+ }
+ }
+
+ private class UpdateFeature extends AbstractUpdateFeature {
+
+ public UpdateFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canUpdate(IUpdateContext context) {
+ Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
+ if (bo instanceof EObject && ((EObject)bo).eIsProxy())
+ return true;
+
+ return false;
+ }
+
+ @Override
+ public IReason updateNeeded(IUpdateContext context) {
+ Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
+ if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
+ return Reason.createTrueReason("LayerConnection deleted from model");
+ }
+ return Reason.createFalseReason();
+ }
+
+ @Override
+ public boolean update(IUpdateContext context) {
+ PictogramElement pe = context.getPictogramElement();
+ Object bo = getBusinessObjectForPictogramElement(pe);
+ if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
+ IRemoveContext rc = new RemoveContext(pe);
+ IFeatureProvider featureProvider = getFeatureProvider();
+ IRemoveFeature removeFeature = featureProvider.getRemoveFeature(rc);
+ if (removeFeature != null) {
+ removeFeature.remove(rc);
+ }
+ EcoreUtil.delete((EObject) bo);
+ return true;
+ }
+ return false;
+ }
+ }
+
+ private IFeatureProvider fp;
+
+ public FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp) {
+ super(dtp);
+ this.fp = fp;
+ }
+
+ private boolean isInherited(Diagram diag, LayerConnection lc) {
+ ActorContainerClass acc = (ActorContainerClass) Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(diag.getChildren().get(0));
+ return (lc.eContainer()!=acc);
+ }
+
+ @Override
+ public ICreateConnectionFeature[] getCreateConnectionFeatures() {
+ return new ICreateConnectionFeature[] { new CreateFeature(fp) };
+ }
+
+ @Override
+ public IAddFeature getAddFeature(IAddContext context) {
+ return new AddFeature(fp);
+ }
+
+ @Override
+ public IRemoveFeature getRemoveFeature(IRemoveContext context) {
+ return new RemoveFeature(fp);
+ }
+
+ @Override
+ public IDeleteFeature getDeleteFeature(IDeleteContext context) {
+ return new DeleteFeature(fp);
+ }
+
+ @Override
+ public IUpdateFeature getUpdateFeature(IUpdateContext context) {
+ return new UpdateFeature(fp);
+ }
+
+ @Override
+ public IReconnectionFeature getReconnectionFeature(IReconnectionContext context) {
+ return new ReconnectionFeature(fp);
+ }
+ }
+
+ class BehaviorProvider extends DefaultToolBehaviorProvider {
+
+ public BehaviorProvider(IDiagramTypeProvider dtp) {
+ super(dtp);
+ }
+ }
+
+ private FeatureProvider pfp;
+ private BehaviorProvider tbp;
+
+ public LayerConnectionSupport(IDiagramTypeProvider dtp, IFeatureProvider fp) {
+ pfp = new FeatureProvider(dtp,fp);
+ tbp = new BehaviorProvider(dtp);
+ }
+
+ public IFeatureProvider getFeatureProvider() {
+ return pfp;
+ }
+
+ public IToolBehaviorProvider getToolBehaviorProvider() {
+ return tbp;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/PortSupport.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/PortSupport.java
index 9db2441da..8dea088a3 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/PortSupport.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/PortSupport.java
@@ -1,558 +1,558 @@
-/*******************************************************************************
- * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.structure.support;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature.Setting;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.etrice.core.naming.RoomNameProvider;
-import org.eclipse.etrice.core.room.ActorClass;
-import org.eclipse.etrice.core.room.ActorContainerClass;
-import org.eclipse.etrice.core.room.Binding;
-import org.eclipse.etrice.core.room.BindingEndPoint;
-import org.eclipse.etrice.core.room.ExternalPort;
-import org.eclipse.etrice.core.room.InterfaceItem;
-import org.eclipse.etrice.core.room.MessageFromIf;
-import org.eclipse.etrice.core.room.Port;
-import org.eclipse.etrice.core.room.RoomFactory;
-import org.eclipse.etrice.core.room.RoomPackage;
-import org.eclipse.etrice.core.room.StructureClass;
-import org.eclipse.etrice.core.room.SubSystemClass;
-import org.eclipse.etrice.core.room.util.RoomHelpers;
-import org.eclipse.etrice.ui.structure.DiagramTypeProvider;
-import org.eclipse.etrice.ui.structure.ImageProvider;
-import org.eclipse.etrice.ui.structure.dialogs.PortPropertyDialog;
-import org.eclipse.graphiti.dt.IDiagramTypeProvider;
-import org.eclipse.graphiti.features.IAddFeature;
-import org.eclipse.graphiti.features.ICreateConnectionFeature;
-import org.eclipse.graphiti.features.ICreateFeature;
-import org.eclipse.graphiti.features.IDeleteFeature;
-import org.eclipse.graphiti.features.IFeatureProvider;
-import org.eclipse.graphiti.features.IUpdateFeature;
-import org.eclipse.graphiti.features.context.IAddContext;
-import org.eclipse.graphiti.features.context.ICreateContext;
-import org.eclipse.graphiti.features.context.ICustomContext;
-import org.eclipse.graphiti.features.context.IDeleteContext;
-import org.eclipse.graphiti.features.context.IDoubleClickContext;
-import org.eclipse.graphiti.features.context.IPictogramElementContext;
-import org.eclipse.graphiti.features.context.IUpdateContext;
-import org.eclipse.graphiti.features.context.impl.CreateConnectionContext;
-import org.eclipse.graphiti.features.context.impl.DeleteContext;
-import org.eclipse.graphiti.features.context.impl.MultiDeleteInfo;
-import org.eclipse.graphiti.features.custom.ICustomFeature;
-import org.eclipse.graphiti.mm.algorithms.Ellipse;
-import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
-import org.eclipse.graphiti.mm.algorithms.Rectangle;
-import org.eclipse.graphiti.mm.algorithms.Text;
-import org.eclipse.graphiti.mm.algorithms.styles.Color;
-import org.eclipse.graphiti.mm.pictograms.Anchor;
-import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
-import org.eclipse.graphiti.mm.pictograms.ChopboxAnchor;
-import org.eclipse.graphiti.mm.pictograms.ContainerShape;
-import org.eclipse.graphiti.mm.pictograms.PictogramElement;
-import org.eclipse.graphiti.services.Graphiti;
-import org.eclipse.graphiti.services.IGaService;
-import org.eclipse.graphiti.services.IPeCreateService;
-import org.eclipse.graphiti.tb.ContextButtonEntry;
-import org.eclipse.graphiti.tb.IContextButtonPadData;
-import org.eclipse.graphiti.tb.IToolBehaviorProvider;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.xtext.scoping.IScope;
-import org.eclipse.xtext.scoping.IScopeProvider;
-
-public class PortSupport extends InterfaceItemSupport {
-
- private static final int REPL_OFFSET = ITEM_SIZE/8;
- private static final int REPL_OFFSET_SMALL = ITEM_SIZE_SMALL/8;
-
- private static class FeatureProvider extends InterfaceItemSupport.FeatureProvider {
-
- private class CreateFeature extends InterfaceItemSupport.FeatureProvider.CreateFeature {
-
- public CreateFeature(IFeatureProvider fp, boolean internal) {
- super(fp, internal, internal?"Internal Port":"Interface Port", internal?"create internal Port":"create interface Port");
- }
-
- @Override
- public String getCreateImageId() {
- return ImageProvider.IMG_PORT;
- }
-
- @Override
- public Object[] create(ICreateContext context) {
- ActorContainerClass acc = (ActorContainerClass) context.getTargetContainer().getLink().getBusinessObjects().get(0);
-
- // create Port
- Port port = RoomFactory.eINSTANCE.createPort();
- port.setName(RoomNameProvider.getUniqueInterfaceItemName("p", acc));
- ExternalPort xp = null;
-
- if (acc instanceof ActorClass) {
- ActorClass ac = (ActorClass) acc;
- if (internal)
- ac.getIntPorts().add(port);
- else {
- ac.getIfPorts().add(port);
-
- xp = RoomFactory.eINSTANCE.createExternalPort();
- xp.setIfport(port);
- ac.getExtPorts().add(xp);
- }
- }
- else if (acc instanceof SubSystemClass) {
- SubSystemClass ssc = (SubSystemClass) acc;
- ssc.getRelayPorts().add(port);
- }
- else {
- assert(false): "ActorClass or SubSystemClass expected";
- }
-
- IScopeProvider scopeProvider = ((DiagramTypeProvider)getFeatureProvider().getDiagramTypeProvider()).getScopeProvider();
- IScope scope = scopeProvider.getScope(port, RoomPackage.eINSTANCE.getPort_Protocol());
- Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- PortPropertyDialog dlg = new PortPropertyDialog(shell, port, scope, acc, true, false, internal);
- if (dlg.open()!=Window.OK) {
- if (acc instanceof ActorClass) {
- ActorClass ac = (ActorClass) acc;
- if (internal)
- ac.getIntPorts().remove(port);
- else {
- ac.getIfPorts().remove(port);
- ac.getExtPorts().remove(xp);
- }
- }
- else if (acc instanceof SubSystemClass) {
- SubSystemClass ssc = (SubSystemClass) acc;
- ssc.getRelayPorts().remove(port);
- }
- return EMPTY;
- }
-
- doneChanges = true;
-
- // do the add
- addGraphicalRepresentation(context, port);
-
- // return newly created business object(s)
- return new Object[] { port };
- }
- }
-
- private static class AddFeature extends InterfaceItemSupport.FeatureProvider.AddFeature {
-
- public AddFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- protected String getItemKind(InterfaceItem item) {
- if (item instanceof Port)
- return getPortKind((Port) item);
-
- return "";
- }
-
- @Override
- protected void createItemFigure(InterfaceItem item,
- boolean refitem, ContainerShape containerShape,
- GraphicsAlgorithm invisibleRectangle, Color darkColor,
- Color brightDolor) {
-
- if (item instanceof Port)
- createPortFigure((Port) item, refitem, containerShape, invisibleRectangle, darkColor, brightDolor);
- }
-
- }
-
- private static class PropertyFeature extends InterfaceItemSupport.FeatureProvider.PropertyFeature {
-
- private boolean doneChanges = false;
-
- public PropertyFeature(IFeatureProvider fp) {
- super(fp, "Edit Port...", "Edit Port Properties");
- }
-
- @Override
- public boolean canExecute(ICustomContext context) {
- if (!super.canExecute(context))
- return false;
-
- PictogramElement[] pes = context.getPictogramElements();
- if (pes != null && pes.length == 1 && pes[0] instanceof ContainerShape) {
- Object bo = getBusinessObjectForPictogramElement(pes[0]);
- return (bo instanceof Port);
- }
- return false;
- }
-
- @Override
- public void execute(ICustomContext context) {
- Object bo = getBusinessObjectForPictogramElement(context.getPictogramElements()[0]);
- if (bo instanceof Port) {
- Port port = (Port) bo;
- ActorContainerClass acc = (ActorContainerClass)port.eContainer();
- boolean internal = isInternal(port);
- boolean refport = isRefItem(context.getPictogramElements()[0]);
-
- IScopeProvider scopeProvider = ((DiagramTypeProvider)getFeatureProvider().getDiagramTypeProvider()).getScopeProvider();
- IScope scope = scopeProvider.getScope(port.eContainer().eContainer(), RoomPackage.eINSTANCE.getPort_Protocol());
- Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- PortPropertyDialog dlg = new PortPropertyDialog(shell, port, scope, acc, false, refport, internal);
- if (dlg.open()!=Window.OK)
- return;
-
- doneChanges = true;
- updatePortFigure(port, context.getPictogramElements()[0], manageColor(DARK_COLOR), manageColor(BRIGHT_COLOR));
- String kind = getPortKind(port);
- Graphiti.getPeService().setPropertyValue(context.getPictogramElements()[0], PROP_KIND, kind);
- }
- }
-
- @Override
- public boolean hasDoneChanges() {
- return doneChanges;
- }
-
- }
-
- private class UpdateFeature extends InterfaceItemSupport.FeatureProvider.UpdateFeature {
-
- public UpdateFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- protected String getItemKind(InterfaceItem item) {
- if (item instanceof Port)
- return getPortKind((Port)item);
-
- return "";
- }
-
- @Override
- protected void updateFigure(InterfaceItem item,
- PictogramElement pe, Color dark, Color bright) {
- updatePortFigure((Port)item, pe, dark, bright);
- }
-
- }
-
- private static class DeleteFeature extends InterfaceItemSupport.FeatureProvider.DeleteFeature {
-
- private ArrayList<Binding> external = new ArrayList<Binding>();
- private ArrayList<Binding> internal = new ArrayList<Binding>();
-
- public DeleteFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canDelete(IDeleteContext context) {
- if (!super.canDelete(context))
- return false;
-
- ContainerShape shape = (ContainerShape) context.getPictogramElement();
- Object bo = getBusinessObjectForPictogramElement(shape);
- if (bo instanceof EObject && ((EObject)bo).eIsProxy())
- return true;
-
- if (!(bo instanceof Port))
- return false;
-
- return true;
- }
-
- @Override
- public void delete(IDeleteContext context) {
- // check for bindings first
- external.clear();
- internal.clear();
- Port port = (Port) getBusinessObjectForPictogramElement(context.getPictogramElement());
- StructureClass sc = (StructureClass) port.eContainer();
- Collection<Setting> refs = EcoreUtil.UsageCrossReferencer.find(port, port.eResource().getResourceSet());
- for (Setting ref : refs) {
- if (ref.getEObject() instanceof BindingEndPoint) {
- if (ref.getEObject().eContainer().eContainer() instanceof StructureClass
- && ref.getEObject().eContainer().eContainer()==sc)
- internal.add((Binding) ref.getEObject().eContainer());
- else
- external.add((Binding) ref.getEObject().eContainer());
- }
- else if (ref.getEObject() instanceof MessageFromIf) {
- MessageDialog.openInformation(
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
- "Delete Port",
- "This port cannot be deleted since it is referenced from the state machine.");
- return;
- }
- }
- if (!external.isEmpty()) {
- boolean proceed = MessageDialog.openQuestion(
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
- "Delete Port",
- "This port is connected externally.\n"
- +"It can only be deleted if the external bindings are also deleted.\n\n"
- +"Proceed?");
- if (!proceed)
- return;
- }
-
- super.delete(context);
- }
-
- @Override
- public void preDelete(IDeleteContext context) {
- // delete all bindings
- for (Binding bind: internal) {
- PictogramElement connection = getFeatureProvider().getPictogramElementForBusinessObject(bind);
- DeleteContext ctx = new DeleteContext(connection);
- ctx.setMultiDeleteInfo(new MultiDeleteInfo(false, false, 1));
- IDeleteFeature deleteFeature = getFeatureProvider().getDeleteFeature(ctx);
- if (deleteFeature!=null)
- deleteFeature.delete(ctx);
- }
- for (Binding bind: external) {
- EcoreUtil.delete(bind);
- }
-
- super.preDelete(context);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.graphiti.ui.features.DefaultDeleteFeature#deleteBusinessObject(java.lang.Object)
- */
- @Override
- protected void deleteBusinessObject(Object bo) {
- if (bo instanceof Port) {
- Port port = (Port) bo;
- if (port.eContainer() instanceof ActorClass) {
- ExternalPort external = null;
- ActorClass ac = (ActorClass) port.eContainer();
- for (ExternalPort extp : ac.getExtPorts()) {
- if (extp.getIfport()==port) {
- external = extp;
- break;
- }
- }
- if (external!=null)
- super.deleteBusinessObject(external);
- }
- }
- super.deleteBusinessObject(bo);
- }
- }
-
- public FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp) {
- super(dtp, fp);
- }
-
- @Override
- public ICreateFeature[] getCreateFeatures() {
- return new ICreateFeature[] { new CreateFeature(fp, true), new CreateFeature(fp, false) };
- }
-
- @Override
- public IAddFeature getAddFeature(IAddContext context) {
- return new AddFeature(fp);
- }
-
- @Override
- public ICustomFeature[] getCustomFeatures(ICustomContext context) {
- return new ICustomFeature[] { new PropertyFeature(fp) };
- }
-
- @Override
- public IUpdateFeature getUpdateFeature(IUpdateContext context) {
- return new UpdateFeature(fp);
- }
-
- @Override
- public IDeleteFeature getDeleteFeature(IDeleteContext context) {
- return new DeleteFeature(fp);
- }
-
- protected static void createPortFigure(Port port, boolean refport,
- ContainerShape containerShape,
- GraphicsAlgorithm invisibleRectangle, Color darkColor, Color brightDolor) {
-
- boolean relay = RoomHelpers.isRelay(port);
-
- int size = refport?ITEM_SIZE_SMALL:ITEM_SIZE;
- int margin = refport?MARGIN_SMALL:MARGIN;
- int offset = refport?REPL_OFFSET_SMALL:REPL_OFFSET;
- int line = refport?LINE_WIDTH/2:LINE_WIDTH;
-
- Color bg = brightDolor;
- if (refport) {
- if (port.isConjugated())
- bg = brightDolor;
- else
- bg = darkColor;
- }
- else {
- if (!port.isConjugated() && !relay)
- bg = darkColor;
- else
- bg = brightDolor;
- }
-
- IGaService gaService = Graphiti.getGaService();
- if (port.isReplicated()) {
- Rectangle rect = gaService.createRectangle(invisibleRectangle);
- rect.setForeground(darkColor);
- rect.setBackground(brightDolor);
- rect.setLineWidth(line);
- gaService.setLocationAndSize(rect, margin-size/2+offset, margin-size/2-offset, size, size);
- }
-
- Rectangle rect = gaService.createRectangle(invisibleRectangle);
- rect.setForeground(darkColor);
- rect.setBackground(bg);
- if (!refport && relay && !port.isConjugated())
- rect.setLineWidth(4*line);
- else
- rect.setLineWidth(line);
- gaService.setLocationAndSize(rect, margin-size/2, margin-size/2, size, size);
-
- if (containerShape.getAnchors().isEmpty()) {
- // here we place our anchor
- IPeCreateService peCreateService = Graphiti.getPeCreateService();
- ChopboxAnchor anchor = peCreateService.createChopboxAnchor(containerShape);
- anchor.setReferencedGraphicsAlgorithm(rect);
- }
- else {
- // we just set the referenced GA
- containerShape.getAnchors().get(0).setReferencedGraphicsAlgorithm(rect);
- }
-
- if (!refport) {
- if (port.isConjugated() || !relay) {
- // we have more details
-
- if (relay) {
- // conjugated relay
- Rectangle inset = gaService.createRectangle(invisibleRectangle);
- inset.setForeground(darkColor);
- inset.setBackground(darkColor);
- inset.setLineWidth(LINE_WIDTH);
- gaService.setLocationAndSize(inset, margin-size/4, margin-size/4, size/2, size/2);
- }
- else {
- Color fill = port.isConjugated()?darkColor:brightDolor;
-
- Ellipse inset = gaService.createEllipse(invisibleRectangle);
- inset.setForeground(fill);
- inset.setBackground(fill);
- inset.setLineWidth(LINE_WIDTH);
- gaService.setLocationAndSize(inset, margin-size/4, margin-size/4, size/2, size/2);
- }
- }
- }
- }
-
- private static void updatePortFigure(Port port, PictogramElement pe, Color dark, Color bright) {
- ContainerShape container = (ContainerShape)pe;
-
- // we clear the figure and rebuild it
- GraphicsAlgorithm invisibleRect = pe.getGraphicsAlgorithm();
- invisibleRect.getGraphicsAlgorithmChildren().clear();
-
- boolean refport = isRefItem(pe);
- createPortFigure(port, refport, container, invisibleRect, dark, bright);
-
- GraphicsAlgorithm ga = container.getChildren().get(0).getGraphicsAlgorithm();
- if (ga instanceof Text) {
- ((Text)ga).setValue(port.getName());
- }
-
- }
-
- }
-
- private class BehaviorProvider extends InterfaceItemSupport.BehaviorProvider {
-
- public BehaviorProvider(IDiagramTypeProvider dtp) {
- super(dtp);
- }
-
- @Override
- public ICustomFeature getDoubleClickFeature(IDoubleClickContext context) {
- return new FeatureProvider.PropertyFeature(getDiagramTypeProvider().getFeatureProvider());
- }
-
- @Override
- public IContextButtonPadData getContextButtonPad(
- IPictogramElementContext context) {
-
- IContextButtonPadData data = super.getContextButtonPad(context);
- PictogramElement pe = context.getPictogramElement();
-
- CreateConnectionContext ccc = new CreateConnectionContext();
- ccc.setSourcePictogramElement(pe);
- Anchor anchor = null;
- if (pe instanceof AnchorContainer) {
- // our port has a chopbox anchor
- anchor = Graphiti.getPeService().getChopboxAnchor((AnchorContainer) pe);
- }
- ccc.setSourceAnchor(anchor);
-
- ContextButtonEntry button = new ContextButtonEntry(null, context);
- button.setText("Create Binding");
- button.setIconId(ImageProvider.IMG_BINDING);
- ICreateConnectionFeature[] features = getFeatureProvider().getCreateConnectionFeatures();
- for (ICreateConnectionFeature feature : features) {
- if (feature.isAvailable(ccc) && feature.canStartConnection(ccc))
- button.addDragAndDropFeature(feature);
- }
-
- if (button.getDragAndDropFeatures().size() > 0) {
- data.getDomainSpecificContextButtons().add(button);
- }
-
- return data;
- }
- }
-
- private FeatureProvider pfp;
- private BehaviorProvider tbp;
-
- public PortSupport(IDiagramTypeProvider dtp, IFeatureProvider fp) {
- pfp = new FeatureProvider(dtp,fp);
- tbp = new BehaviorProvider(dtp);
- }
-
- public IFeatureProvider getFeatureProvider() {
- return pfp;
- }
-
- public IToolBehaviorProvider getToolBehaviorProvider() {
- return tbp;
- }
-
- private static String getPortKind(Port port) {
- String kind = "";
- if (port.isConjugated())
- kind += "C";
- if (RoomHelpers.isRelay(port))
- kind += "R";
- if (port.isReplicated())
- kind += "M";
- return kind;
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.support;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature.Setting;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.etrice.core.naming.RoomNameProvider;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.ActorContainerClass;
+import org.eclipse.etrice.core.room.Binding;
+import org.eclipse.etrice.core.room.BindingEndPoint;
+import org.eclipse.etrice.core.room.ExternalPort;
+import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.etrice.core.room.MessageFromIf;
+import org.eclipse.etrice.core.room.Port;
+import org.eclipse.etrice.core.room.RoomFactory;
+import org.eclipse.etrice.core.room.RoomPackage;
+import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.core.room.SubSystemClass;
+import org.eclipse.etrice.core.room.util.RoomHelpers;
+import org.eclipse.etrice.ui.structure.DiagramTypeProvider;
+import org.eclipse.etrice.ui.structure.ImageProvider;
+import org.eclipse.etrice.ui.structure.dialogs.PortPropertyDialog;
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.features.IAddFeature;
+import org.eclipse.graphiti.features.ICreateConnectionFeature;
+import org.eclipse.graphiti.features.ICreateFeature;
+import org.eclipse.graphiti.features.IDeleteFeature;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.IUpdateFeature;
+import org.eclipse.graphiti.features.context.IAddContext;
+import org.eclipse.graphiti.features.context.ICreateContext;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.context.IDeleteContext;
+import org.eclipse.graphiti.features.context.IDoubleClickContext;
+import org.eclipse.graphiti.features.context.IPictogramElementContext;
+import org.eclipse.graphiti.features.context.IUpdateContext;
+import org.eclipse.graphiti.features.context.impl.CreateConnectionContext;
+import org.eclipse.graphiti.features.context.impl.DeleteContext;
+import org.eclipse.graphiti.features.context.impl.MultiDeleteInfo;
+import org.eclipse.graphiti.features.custom.ICustomFeature;
+import org.eclipse.graphiti.mm.algorithms.Ellipse;
+import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.algorithms.Rectangle;
+import org.eclipse.graphiti.mm.algorithms.Text;
+import org.eclipse.graphiti.mm.algorithms.styles.Color;
+import org.eclipse.graphiti.mm.pictograms.Anchor;
+import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
+import org.eclipse.graphiti.mm.pictograms.ChopboxAnchor;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.IGaService;
+import org.eclipse.graphiti.services.IPeCreateService;
+import org.eclipse.graphiti.tb.ContextButtonEntry;
+import org.eclipse.graphiti.tb.IContextButtonPadData;
+import org.eclipse.graphiti.tb.IToolBehaviorProvider;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.xtext.scoping.IScope;
+import org.eclipse.xtext.scoping.IScopeProvider;
+
+public class PortSupport extends InterfaceItemSupport {
+
+ private static final int REPL_OFFSET = ITEM_SIZE/8;
+ private static final int REPL_OFFSET_SMALL = ITEM_SIZE_SMALL/8;
+
+ private static class FeatureProvider extends InterfaceItemSupport.FeatureProvider {
+
+ private class CreateFeature extends InterfaceItemSupport.FeatureProvider.CreateFeature {
+
+ public CreateFeature(IFeatureProvider fp, boolean internal) {
+ super(fp, internal, internal?"Internal Port":"Interface Port", internal?"create internal Port":"create interface Port");
+ }
+
+ @Override
+ public String getCreateImageId() {
+ return ImageProvider.IMG_PORT;
+ }
+
+ @Override
+ public Object[] create(ICreateContext context) {
+ ActorContainerClass acc = (ActorContainerClass) context.getTargetContainer().getLink().getBusinessObjects().get(0);
+
+ // create Port
+ Port port = RoomFactory.eINSTANCE.createPort();
+ port.setName(RoomNameProvider.getUniqueInterfaceItemName("p", acc));
+ ExternalPort xp = null;
+
+ if (acc instanceof ActorClass) {
+ ActorClass ac = (ActorClass) acc;
+ if (internal)
+ ac.getIntPorts().add(port);
+ else {
+ ac.getIfPorts().add(port);
+
+ xp = RoomFactory.eINSTANCE.createExternalPort();
+ xp.setIfport(port);
+ ac.getExtPorts().add(xp);
+ }
+ }
+ else if (acc instanceof SubSystemClass) {
+ SubSystemClass ssc = (SubSystemClass) acc;
+ ssc.getRelayPorts().add(port);
+ }
+ else {
+ assert(false): "ActorClass or SubSystemClass expected";
+ }
+
+ IScopeProvider scopeProvider = ((DiagramTypeProvider)getFeatureProvider().getDiagramTypeProvider()).getScopeProvider();
+ IScope scope = scopeProvider.getScope(port, RoomPackage.eINSTANCE.getPort_Protocol());
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ PortPropertyDialog dlg = new PortPropertyDialog(shell, port, scope, acc, true, false, internal);
+ if (dlg.open()!=Window.OK) {
+ if (acc instanceof ActorClass) {
+ ActorClass ac = (ActorClass) acc;
+ if (internal)
+ ac.getIntPorts().remove(port);
+ else {
+ ac.getIfPorts().remove(port);
+ ac.getExtPorts().remove(xp);
+ }
+ }
+ else if (acc instanceof SubSystemClass) {
+ SubSystemClass ssc = (SubSystemClass) acc;
+ ssc.getRelayPorts().remove(port);
+ }
+ return EMPTY;
+ }
+
+ doneChanges = true;
+
+ // do the add
+ addGraphicalRepresentation(context, port);
+
+ // return newly created business object(s)
+ return new Object[] { port };
+ }
+ }
+
+ private static class AddFeature extends InterfaceItemSupport.FeatureProvider.AddFeature {
+
+ public AddFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ protected String getItemKind(InterfaceItem item) {
+ if (item instanceof Port)
+ return getPortKind((Port) item);
+
+ return "";
+ }
+
+ @Override
+ protected void createItemFigure(InterfaceItem item,
+ boolean refitem, ContainerShape containerShape,
+ GraphicsAlgorithm invisibleRectangle, Color darkColor,
+ Color brightDolor) {
+
+ if (item instanceof Port)
+ createPortFigure((Port) item, refitem, containerShape, invisibleRectangle, darkColor, brightDolor);
+ }
+
+ }
+
+ private static class PropertyFeature extends InterfaceItemSupport.FeatureProvider.PropertyFeature {
+
+ private boolean doneChanges = false;
+
+ public PropertyFeature(IFeatureProvider fp) {
+ super(fp, "Edit Port...", "Edit Port Properties");
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ if (!super.canExecute(context))
+ return false;
+
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes != null && pes.length == 1 && pes[0] instanceof ContainerShape) {
+ Object bo = getBusinessObjectForPictogramElement(pes[0]);
+ return (bo instanceof Port);
+ }
+ return false;
+ }
+
+ @Override
+ public void execute(ICustomContext context) {
+ Object bo = getBusinessObjectForPictogramElement(context.getPictogramElements()[0]);
+ if (bo instanceof Port) {
+ Port port = (Port) bo;
+ ActorContainerClass acc = (ActorContainerClass)port.eContainer();
+ boolean internal = isInternal(port);
+ boolean refport = isRefItem(context.getPictogramElements()[0]);
+
+ IScopeProvider scopeProvider = ((DiagramTypeProvider)getFeatureProvider().getDiagramTypeProvider()).getScopeProvider();
+ IScope scope = scopeProvider.getScope(port.eContainer().eContainer(), RoomPackage.eINSTANCE.getPort_Protocol());
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ PortPropertyDialog dlg = new PortPropertyDialog(shell, port, scope, acc, false, refport, internal);
+ if (dlg.open()!=Window.OK)
+ return;
+
+ doneChanges = true;
+ updatePortFigure(port, context.getPictogramElements()[0], manageColor(DARK_COLOR), manageColor(BRIGHT_COLOR));
+ String kind = getPortKind(port);
+ Graphiti.getPeService().setPropertyValue(context.getPictogramElements()[0], PROP_KIND, kind);
+ }
+ }
+
+ @Override
+ public boolean hasDoneChanges() {
+ return doneChanges;
+ }
+
+ }
+
+ private class UpdateFeature extends InterfaceItemSupport.FeatureProvider.UpdateFeature {
+
+ public UpdateFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ protected String getItemKind(InterfaceItem item) {
+ if (item instanceof Port)
+ return getPortKind((Port)item);
+
+ return "";
+ }
+
+ @Override
+ protected void updateFigure(InterfaceItem item,
+ PictogramElement pe, Color dark, Color bright) {
+ updatePortFigure((Port)item, pe, dark, bright);
+ }
+
+ }
+
+ private static class DeleteFeature extends InterfaceItemSupport.FeatureProvider.DeleteFeature {
+
+ private ArrayList<Binding> external = new ArrayList<Binding>();
+ private ArrayList<Binding> internal = new ArrayList<Binding>();
+
+ public DeleteFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canDelete(IDeleteContext context) {
+ if (!super.canDelete(context))
+ return false;
+
+ ContainerShape shape = (ContainerShape) context.getPictogramElement();
+ Object bo = getBusinessObjectForPictogramElement(shape);
+ if (bo instanceof EObject && ((EObject)bo).eIsProxy())
+ return true;
+
+ if (!(bo instanceof Port))
+ return false;
+
+ return true;
+ }
+
+ @Override
+ public void delete(IDeleteContext context) {
+ // check for bindings first
+ external.clear();
+ internal.clear();
+ Port port = (Port) getBusinessObjectForPictogramElement(context.getPictogramElement());
+ StructureClass sc = (StructureClass) port.eContainer();
+ Collection<Setting> refs = EcoreUtil.UsageCrossReferencer.find(port, port.eResource().getResourceSet());
+ for (Setting ref : refs) {
+ if (ref.getEObject() instanceof BindingEndPoint) {
+ if (ref.getEObject().eContainer().eContainer() instanceof StructureClass
+ && ref.getEObject().eContainer().eContainer()==sc)
+ internal.add((Binding) ref.getEObject().eContainer());
+ else
+ external.add((Binding) ref.getEObject().eContainer());
+ }
+ else if (ref.getEObject() instanceof MessageFromIf) {
+ MessageDialog.openInformation(
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ "Delete Port",
+ "This port cannot be deleted since it is referenced from the state machine.");
+ return;
+ }
+ }
+ if (!external.isEmpty()) {
+ boolean proceed = MessageDialog.openQuestion(
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ "Delete Port",
+ "This port is connected externally.\n"
+ +"It can only be deleted if the external bindings are also deleted.\n\n"
+ +"Proceed?");
+ if (!proceed)
+ return;
+ }
+
+ super.delete(context);
+ }
+
+ @Override
+ public void preDelete(IDeleteContext context) {
+ // delete all bindings
+ for (Binding bind: internal) {
+ PictogramElement connection = getFeatureProvider().getPictogramElementForBusinessObject(bind);
+ DeleteContext ctx = new DeleteContext(connection);
+ ctx.setMultiDeleteInfo(new MultiDeleteInfo(false, false, 1));
+ IDeleteFeature deleteFeature = getFeatureProvider().getDeleteFeature(ctx);
+ if (deleteFeature!=null)
+ deleteFeature.delete(ctx);
+ }
+ for (Binding bind: external) {
+ EcoreUtil.delete(bind);
+ }
+
+ super.preDelete(context);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.graphiti.ui.features.DefaultDeleteFeature#deleteBusinessObject(java.lang.Object)
+ */
+ @Override
+ protected void deleteBusinessObject(Object bo) {
+ if (bo instanceof Port) {
+ Port port = (Port) bo;
+ if (port.eContainer() instanceof ActorClass) {
+ ExternalPort external = null;
+ ActorClass ac = (ActorClass) port.eContainer();
+ for (ExternalPort extp : ac.getExtPorts()) {
+ if (extp.getIfport()==port) {
+ external = extp;
+ break;
+ }
+ }
+ if (external!=null)
+ super.deleteBusinessObject(external);
+ }
+ }
+ super.deleteBusinessObject(bo);
+ }
+ }
+
+ public FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp) {
+ super(dtp, fp);
+ }
+
+ @Override
+ public ICreateFeature[] getCreateFeatures() {
+ return new ICreateFeature[] { new CreateFeature(fp, true), new CreateFeature(fp, false) };
+ }
+
+ @Override
+ public IAddFeature getAddFeature(IAddContext context) {
+ return new AddFeature(fp);
+ }
+
+ @Override
+ public ICustomFeature[] getCustomFeatures(ICustomContext context) {
+ return new ICustomFeature[] { new PropertyFeature(fp) };
+ }
+
+ @Override
+ public IUpdateFeature getUpdateFeature(IUpdateContext context) {
+ return new UpdateFeature(fp);
+ }
+
+ @Override
+ public IDeleteFeature getDeleteFeature(IDeleteContext context) {
+ return new DeleteFeature(fp);
+ }
+
+ protected static void createPortFigure(Port port, boolean refport,
+ ContainerShape containerShape,
+ GraphicsAlgorithm invisibleRectangle, Color darkColor, Color brightDolor) {
+
+ boolean relay = RoomHelpers.isRelay(port);
+
+ int size = refport?ITEM_SIZE_SMALL:ITEM_SIZE;
+ int margin = refport?MARGIN_SMALL:MARGIN;
+ int offset = refport?REPL_OFFSET_SMALL:REPL_OFFSET;
+ int line = refport?LINE_WIDTH/2:LINE_WIDTH;
+
+ Color bg = brightDolor;
+ if (refport) {
+ if (port.isConjugated())
+ bg = brightDolor;
+ else
+ bg = darkColor;
+ }
+ else {
+ if (!port.isConjugated() && !relay)
+ bg = darkColor;
+ else
+ bg = brightDolor;
+ }
+
+ IGaService gaService = Graphiti.getGaService();
+ if (port.isReplicated()) {
+ Rectangle rect = gaService.createRectangle(invisibleRectangle);
+ rect.setForeground(darkColor);
+ rect.setBackground(brightDolor);
+ rect.setLineWidth(line);
+ gaService.setLocationAndSize(rect, margin-size/2+offset, margin-size/2-offset, size, size);
+ }
+
+ Rectangle rect = gaService.createRectangle(invisibleRectangle);
+ rect.setForeground(darkColor);
+ rect.setBackground(bg);
+ if (!refport && relay && !port.isConjugated())
+ rect.setLineWidth(4*line);
+ else
+ rect.setLineWidth(line);
+ gaService.setLocationAndSize(rect, margin-size/2, margin-size/2, size, size);
+
+ if (containerShape.getAnchors().isEmpty()) {
+ // here we place our anchor
+ IPeCreateService peCreateService = Graphiti.getPeCreateService();
+ ChopboxAnchor anchor = peCreateService.createChopboxAnchor(containerShape);
+ anchor.setReferencedGraphicsAlgorithm(rect);
+ }
+ else {
+ // we just set the referenced GA
+ containerShape.getAnchors().get(0).setReferencedGraphicsAlgorithm(rect);
+ }
+
+ if (!refport) {
+ if (port.isConjugated() || !relay) {
+ // we have more details
+
+ if (relay) {
+ // conjugated relay
+ Rectangle inset = gaService.createRectangle(invisibleRectangle);
+ inset.setForeground(darkColor);
+ inset.setBackground(darkColor);
+ inset.setLineWidth(LINE_WIDTH);
+ gaService.setLocationAndSize(inset, margin-size/4, margin-size/4, size/2, size/2);
+ }
+ else {
+ Color fill = port.isConjugated()?darkColor:brightDolor;
+
+ Ellipse inset = gaService.createEllipse(invisibleRectangle);
+ inset.setForeground(fill);
+ inset.setBackground(fill);
+ inset.setLineWidth(LINE_WIDTH);
+ gaService.setLocationAndSize(inset, margin-size/4, margin-size/4, size/2, size/2);
+ }
+ }
+ }
+ }
+
+ private static void updatePortFigure(Port port, PictogramElement pe, Color dark, Color bright) {
+ ContainerShape container = (ContainerShape)pe;
+
+ // we clear the figure and rebuild it
+ GraphicsAlgorithm invisibleRect = pe.getGraphicsAlgorithm();
+ invisibleRect.getGraphicsAlgorithmChildren().clear();
+
+ boolean refport = isRefItem(pe);
+ createPortFigure(port, refport, container, invisibleRect, dark, bright);
+
+ GraphicsAlgorithm ga = container.getChildren().get(0).getGraphicsAlgorithm();
+ if (ga instanceof Text) {
+ ((Text)ga).setValue(port.getName());
+ }
+
+ }
+
+ }
+
+ private class BehaviorProvider extends InterfaceItemSupport.BehaviorProvider {
+
+ public BehaviorProvider(IDiagramTypeProvider dtp) {
+ super(dtp);
+ }
+
+ @Override
+ public ICustomFeature getDoubleClickFeature(IDoubleClickContext context) {
+ return new FeatureProvider.PropertyFeature(getDiagramTypeProvider().getFeatureProvider());
+ }
+
+ @Override
+ public IContextButtonPadData getContextButtonPad(
+ IPictogramElementContext context) {
+
+ IContextButtonPadData data = super.getContextButtonPad(context);
+ PictogramElement pe = context.getPictogramElement();
+
+ CreateConnectionContext ccc = new CreateConnectionContext();
+ ccc.setSourcePictogramElement(pe);
+ Anchor anchor = null;
+ if (pe instanceof AnchorContainer) {
+ // our port has a chopbox anchor
+ anchor = Graphiti.getPeService().getChopboxAnchor((AnchorContainer) pe);
+ }
+ ccc.setSourceAnchor(anchor);
+
+ ContextButtonEntry button = new ContextButtonEntry(null, context);
+ button.setText("Create Binding");
+ button.setIconId(ImageProvider.IMG_BINDING);
+ ICreateConnectionFeature[] features = getFeatureProvider().getCreateConnectionFeatures();
+ for (ICreateConnectionFeature feature : features) {
+ if (feature.isAvailable(ccc) && feature.canStartConnection(ccc))
+ button.addDragAndDropFeature(feature);
+ }
+
+ if (button.getDragAndDropFeatures().size() > 0) {
+ data.getDomainSpecificContextButtons().add(button);
+ }
+
+ return data;
+ }
+ }
+
+ private FeatureProvider pfp;
+ private BehaviorProvider tbp;
+
+ public PortSupport(IDiagramTypeProvider dtp, IFeatureProvider fp) {
+ pfp = new FeatureProvider(dtp,fp);
+ tbp = new BehaviorProvider(dtp);
+ }
+
+ public IFeatureProvider getFeatureProvider() {
+ return pfp;
+ }
+
+ public IToolBehaviorProvider getToolBehaviorProvider() {
+ return tbp;
+ }
+
+ private static String getPortKind(Port port) {
+ String kind = "";
+ if (port.isConjugated())
+ kind += "C";
+ if (RoomHelpers.isRelay(port))
+ kind += "R";
+ if (port.isReplicated())
+ kind += "M";
+ return kind;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/SPPSupport.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/SPPSupport.java
index f95d69f70..43a7c46b2 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/SPPSupport.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/SPPSupport.java
@@ -1,482 +1,482 @@
-/*******************************************************************************
- * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.structure.support;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature.Setting;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.etrice.core.naming.RoomNameProvider;
-import org.eclipse.etrice.core.room.ActorContainerClass;
-import org.eclipse.etrice.core.room.InterfaceItem;
-import org.eclipse.etrice.core.room.LayerConnection;
-import org.eclipse.etrice.core.room.RelaySAPoint;
-import org.eclipse.etrice.core.room.RoomFactory;
-import org.eclipse.etrice.core.room.RoomPackage;
-import org.eclipse.etrice.core.room.SPPRef;
-import org.eclipse.etrice.core.room.SPPoint;
-import org.eclipse.etrice.core.room.ServiceImplementation;
-import org.eclipse.etrice.core.room.StructureClass;
-import org.eclipse.etrice.core.validation.ValidationUtil;
-import org.eclipse.etrice.ui.common.support.NoResizeFeature;
-import org.eclipse.etrice.ui.structure.DiagramTypeProvider;
-import org.eclipse.etrice.ui.structure.ImageProvider;
-import org.eclipse.etrice.ui.structure.dialogs.SPPPropertyDialog;
-import org.eclipse.graphiti.dt.IDiagramTypeProvider;
-import org.eclipse.graphiti.features.IAddFeature;
-import org.eclipse.graphiti.features.ICreateConnectionFeature;
-import org.eclipse.graphiti.features.ICreateFeature;
-import org.eclipse.graphiti.features.IDeleteFeature;
-import org.eclipse.graphiti.features.IFeatureProvider;
-import org.eclipse.graphiti.features.IMoveShapeFeature;
-import org.eclipse.graphiti.features.IResizeShapeFeature;
-import org.eclipse.graphiti.features.IUpdateFeature;
-import org.eclipse.graphiti.features.context.IAddContext;
-import org.eclipse.graphiti.features.context.ICreateContext;
-import org.eclipse.graphiti.features.context.ICustomContext;
-import org.eclipse.graphiti.features.context.IDeleteContext;
-import org.eclipse.graphiti.features.context.IDoubleClickContext;
-import org.eclipse.graphiti.features.context.IMoveShapeContext;
-import org.eclipse.graphiti.features.context.IPictogramElementContext;
-import org.eclipse.graphiti.features.context.IResizeShapeContext;
-import org.eclipse.graphiti.features.context.IUpdateContext;
-import org.eclipse.graphiti.features.context.impl.CreateConnectionContext;
-import org.eclipse.graphiti.features.context.impl.DeleteContext;
-import org.eclipse.graphiti.features.context.impl.MultiDeleteInfo;
-import org.eclipse.graphiti.features.custom.ICustomFeature;
-import org.eclipse.graphiti.mm.algorithms.Ellipse;
-import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
-import org.eclipse.graphiti.mm.algorithms.Text;
-import org.eclipse.graphiti.mm.algorithms.styles.Color;
-import org.eclipse.graphiti.mm.pictograms.Anchor;
-import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
-import org.eclipse.graphiti.mm.pictograms.ChopboxAnchor;
-import org.eclipse.graphiti.mm.pictograms.ContainerShape;
-import org.eclipse.graphiti.mm.pictograms.PictogramElement;
-import org.eclipse.graphiti.services.Graphiti;
-import org.eclipse.graphiti.services.IGaService;
-import org.eclipse.graphiti.services.IPeCreateService;
-import org.eclipse.graphiti.tb.ContextButtonEntry;
-import org.eclipse.graphiti.tb.IContextButtonPadData;
-import org.eclipse.graphiti.tb.IToolBehaviorProvider;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.xtext.scoping.IScope;
-import org.eclipse.xtext.scoping.IScopeProvider;
-
-public class SPPSupport extends InterfaceItemSupport {
-
- private static class FeatureProvider extends InterfaceItemSupport.FeatureProvider {
-
- private static class CreateFeature extends InterfaceItemSupport.FeatureProvider.CreateFeature {
-
- public CreateFeature(IFeatureProvider fp) {
- super(fp, false, "SPP", "create SPP");
- }
-
- @Override
- public String getCreateImageId() {
- return ImageProvider.IMG_SPP;
- }
-
- @Override
- public Object[] create(ICreateContext context) {
- ActorContainerClass acc = (ActorContainerClass) context.getTargetContainer().getLink().getBusinessObjects().get(0);
-
- // create SPP
- SPPRef spp = RoomFactory.eINSTANCE.createSPPRef();
- spp.setName(RoomNameProvider.getUniqueInterfaceItemName("spp", acc));
-
- acc.getIfSPPs().add(spp);
-
- IScopeProvider scopeProvider = ((DiagramTypeProvider)getFeatureProvider().getDiagramTypeProvider()).getScopeProvider();
- IScope scope = scopeProvider.getScope(spp.eContainer().eContainer(), RoomPackage.eINSTANCE.getSAPRef_Protocol());
- Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- SPPPropertyDialog dlg = new SPPPropertyDialog(shell, spp, scope, true, false);
- if (dlg.open()!=Window.OK) {
- acc.getIfSPPs().remove(spp);
- return EMPTY;
- }
-
- doneChanges = true;
-
- // do the add
- addGraphicalRepresentation(context, spp);
-
- // return newly created business object(s)
- return new Object[] { spp };
- }
- }
-
- private class AddFeature extends InterfaceItemSupport.FeatureProvider.AddFeature {
-
- public AddFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- protected String getItemKind(InterfaceItem item) {
- if (item instanceof SPPRef)
- return getSPPKind((SPPRef)item);
-
- return "";
- }
-
- @Override
- protected void createItemFigure(InterfaceItem item,
- boolean refitem, ContainerShape containerShape,
- GraphicsAlgorithm invisibleRectangle, Color darkColor,
- Color brightDolor) {
-
- if (item instanceof SPPRef)
- createSPPFigure((SPPRef) item, refitem, containerShape, invisibleRectangle, darkColor, brightDolor);
- }
-
- }
-
- private static class PropertyFeature extends InterfaceItemSupport.FeatureProvider.PropertyFeature {
-
- private boolean doneChanges = false;
-
- public PropertyFeature(IFeatureProvider fp) {
- super(fp, "Edit SPP...", "Edit SPP Properties");
- }
-
- @Override
- public boolean canExecute(ICustomContext context) {
- if (!super.canExecute(context))
- return false;
-
- PictogramElement[] pes = context.getPictogramElements();
- if (pes != null && pes.length == 1 && pes[0] instanceof ContainerShape) {
- Object bo = getBusinessObjectForPictogramElement(pes[0]);
- return (bo instanceof SPPRef);
- }
- return false;
- }
-
- @Override
- public void execute(ICustomContext context) {
- SPPRef spp = (SPPRef) getBusinessObjectForPictogramElement(context.getPictogramElements()[0]);
- boolean refport = isRefItem(context.getPictogramElements()[0]);
-
- IScopeProvider scopeProvider = ((DiagramTypeProvider)getFeatureProvider().getDiagramTypeProvider()).getScopeProvider();
- IScope scope = scopeProvider.getScope(spp.eContainer().eContainer(), RoomPackage.eINSTANCE.getSAPRef_Protocol());
- Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- SPPPropertyDialog dlg = new SPPPropertyDialog(shell, spp, scope, false, refport);
- if (dlg.open()!=Window.OK)
- return;
-
- doneChanges = true;
- updateSPPFigure(spp, context.getPictogramElements()[0], manageColor(DARK_COLOR), manageColor(BRIGHT_COLOR));
- }
-
- @Override
- public boolean hasDoneChanges() {
- return doneChanges;
- }
-
- }
-
- private class UpdateFeature extends InterfaceItemSupport.FeatureProvider.UpdateFeature {
-
- public UpdateFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- protected String getItemKind(InterfaceItem item) {
- if (item instanceof SPPRef)
- return getSPPKind((SPPRef)item);
-
- return "";
- }
-
- @Override
- protected void updateFigure(InterfaceItem item,
- PictogramElement pe, Color dark, Color bright) {
- updateSPPFigure((SPPRef)item, pe, dark, bright);
- }
-
- }
-
- private static class DeleteFeature extends InterfaceItemSupport.FeatureProvider.DeleteFeature {
-
- private ArrayList<LayerConnection> external = new ArrayList<LayerConnection>();
- private ArrayList<LayerConnection> internal = new ArrayList<LayerConnection>();
-
- public DeleteFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canDelete(IDeleteContext context) {
- if (!super.canDelete(context))
- return false;
-
- ContainerShape shape = (ContainerShape) context.getPictogramElement();
- Object bo = getBusinessObjectForPictogramElement(shape);
- if (bo instanceof EObject && ((EObject)bo).eIsProxy())
- return true;
-
- if (!(bo instanceof SPPRef))
- return false;
-
- return true;
- }
-
- @Override
- public void delete(IDeleteContext context) {
- // check for bindings first
- external.clear();
- internal.clear();
- SPPRef spp = (SPPRef) getBusinessObjectForPictogramElement(context.getPictogramElement());
- StructureClass sc = (StructureClass) spp.eContainer();
- Collection<Setting> refs = EcoreUtil.UsageCrossReferencer.find(spp, spp.eResource().getResourceSet());
- for (Setting ref : refs) {
- if (ref.getEObject() instanceof RelaySAPoint || ref.getEObject() instanceof SPPoint) {
- if (ref.getEObject().eContainer().eContainer() instanceof StructureClass
- && ref.getEObject().eContainer().eContainer()==sc)
- internal.add((LayerConnection) ref.getEObject().eContainer());
- else
- external.add((LayerConnection) ref.getEObject().eContainer());
- }
- else if (ref.getEObject() instanceof ServiceImplementation) {
- MessageDialog.openInformation(
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
- "Delete SPP",
- "This spp cannot be deleted since it is referenced by a service implementation.");
- return;
- }
- }
- if (!external.isEmpty()) {
- boolean proceed = MessageDialog.openQuestion(
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
- "Delete SPP",
- "This spp is connected externally.\n"
- +"It can only be deleted if the external layer connections are also deleted.\n\n"
- +"Proceed?");
- if (!proceed)
- return;
- }
-
- super.delete(context);
- }
-
- @Override
- public void preDelete(IDeleteContext context) {
- // delete all bindings
- for (LayerConnection bind: internal) {
- PictogramElement connection = getFeatureProvider().getPictogramElementForBusinessObject(bind);
- DeleteContext ctx = new DeleteContext(connection);
- ctx.setMultiDeleteInfo(new MultiDeleteInfo(false, false, 1));
- IDeleteFeature deleteFeature = getFeatureProvider().getDeleteFeature(ctx);
- if (deleteFeature!=null)
- deleteFeature.delete(ctx);
- }
- for (LayerConnection bind: external) {
- EcoreUtil.delete(bind);
- }
-
- super.preDelete(context);
- }
- }
-
- public FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp) {
- super(dtp, fp);
- }
-
- @Override
- public ICreateFeature[] getCreateFeatures() {
- return new ICreateFeature[] { new CreateFeature(fp) };
- }
-
- @Override
- public IAddFeature getAddFeature(IAddContext context) {
- return new AddFeature(fp);
- }
-
- @Override
- public IMoveShapeFeature getMoveShapeFeature(IMoveShapeContext context) {
- return new MoveShapeFeature(fp);
- }
-
- @Override
- public IResizeShapeFeature getResizeShapeFeature(IResizeShapeContext context) {
- return new NoResizeFeature(fp);
- }
-
- @Override
- public ICustomFeature[] getCustomFeatures(ICustomContext context) {
- return new ICustomFeature[] { new PropertyFeature(fp) };
- }
-
- @Override
- public IUpdateFeature getUpdateFeature(IUpdateContext context) {
- return new UpdateFeature(fp);
- }
-
- @Override
- public IDeleteFeature getDeleteFeature(IDeleteContext context) {
- return new DeleteFeature(fp);
- }
-
- protected static void createSPPFigure(SPPRef spp, boolean refspp,
- ContainerShape containerShape,
- GraphicsAlgorithm invisibleRectangle, Color darkColor, Color brightDolor) {
-
- boolean relay = ValidationUtil.isRelay(spp);
-
- int size = refspp?ITEM_SIZE_SMALL:ITEM_SIZE;
- int margin = refspp?MARGIN_SMALL:MARGIN;
- int line = refspp?LINE_WIDTH/2:LINE_WIDTH;
-
- Color bg = brightDolor;
- if (refspp) {
- bg = darkColor;
- }
- else {
- if (relay)
- bg = brightDolor;
- else
- bg = darkColor;
- }
-
- IGaService gaService = Graphiti.getGaService();
-
- // TODOHRR: depicting SPPs as diamond using polygon didn't work
-// int s2 = margin-size/2;
-// int xy[] = new int[] { s2, 0, margin, s2, s2, margin, 0, s2};
-// Polygon rect = gaService.createPolygon(invisibleRectangle, xy);
-// rect.setForeground(darkColor);
-// rect.setBackground(bg);
-// rect.setLineWidth(line);
-// gaService.setLocation(rect, s2, s2);
- //Rectangle rect = gaService.createRectangle(invisibleRectangle);
-
- Ellipse rect = gaService.createEllipse(invisibleRectangle);
- rect.setForeground(darkColor);
- rect.setBackground(bg);
- rect.setLineWidth(line);
- gaService.setLocationAndSize(rect, margin-size/2, margin-size/2, size, size);
-
- if (containerShape.getAnchors().isEmpty()) {
- // here we place our anchor
- IPeCreateService peCreateService = Graphiti.getPeCreateService();
-// FixPointAnchor anchor = peCreateService.createFixPointAnchor(containerShape);
-// anchor.setLocation(gaService.createPoint(xy[0], xy[1]));
-// anchor = peCreateService.createFixPointAnchor(containerShape);
-// anchor.setLocation(gaService.createPoint(xy[2], xy[3]));
-// anchor = peCreateService.createFixPointAnchor(containerShape);
-// anchor.setLocation(gaService.createPoint(xy[4], xy[5]));
-// anchor = peCreateService.createFixPointAnchor(containerShape);
-// anchor.setLocation(gaService.createPoint(xy[6], xy[7]));
- // TODOHRR: EllipseAnchor would be nice
- ChopboxAnchor anchor = peCreateService.createChopboxAnchor(containerShape);
- anchor.setReferencedGraphicsAlgorithm(rect);
- }
- else {
- // we just set the referenced GA
- //containerShape.getAnchors().get(0).setReferencedGraphicsAlgorithm(rect);
- }
- }
-
- private static void updateSPPFigure(SPPRef spp, PictogramElement pe, Color dark, Color bright) {
- ContainerShape container = (ContainerShape)pe;
-
- // we clear the figure and rebuild it
- GraphicsAlgorithm invisibleRect = pe.getGraphicsAlgorithm();
- invisibleRect.getGraphicsAlgorithmChildren().clear();
-
- createSPPFigure(spp, false, container, invisibleRect, dark, bright);
-
- GraphicsAlgorithm ga = container.getChildren().get(0).getGraphicsAlgorithm();
- if (ga instanceof Text) {
- ((Text)ga).setValue(spp.getName());
- }
-
- }
-
- }
-
- private class BehaviorProvider extends InterfaceItemSupport.BehaviorProvider {
-
- public BehaviorProvider(IDiagramTypeProvider dtp) {
- super(dtp);
- }
-
- @Override
- public ICustomFeature getDoubleClickFeature(IDoubleClickContext context) {
- return new FeatureProvider.PropertyFeature(getDiagramTypeProvider().getFeatureProvider());
- }
-
- @Override
- public IContextButtonPadData getContextButtonPad(
- IPictogramElementContext context) {
-
- IContextButtonPadData data = super.getContextButtonPad(context);
- PictogramElement pe = context.getPictogramElement();
-
- CreateConnectionContext ccc = new CreateConnectionContext();
- ccc.setSourcePictogramElement(pe);
- Anchor anchor = null;
- if (pe instanceof AnchorContainer) {
- // our spp has four fixed point anchor - we choose the first one
- anchor = ((ContainerShape)pe).getAnchors().get(0);
- }
- ccc.setSourceAnchor(anchor);
-
- ContextButtonEntry button = new ContextButtonEntry(null, context);
- button.setText("Create Layer Connection");
- button.setIconId(ImageProvider.IMG_LAYER_CONNECTION);
- ICreateConnectionFeature[] features = getFeatureProvider().getCreateConnectionFeatures();
- for (ICreateConnectionFeature feature : features) {
- if (feature.isAvailable(ccc) && feature.canStartConnection(ccc))
- button.addDragAndDropFeature(feature);
- }
-
- if (button.getDragAndDropFeatures().size() > 0) {
- data.getDomainSpecificContextButtons().add(button);
- }
-
- return data;
- }
- }
-
- private FeatureProvider pfp;
- private BehaviorProvider tbp;
-
- public SPPSupport(IDiagramTypeProvider dtp, IFeatureProvider fp) {
- pfp = new FeatureProvider(dtp,fp);
- tbp = new BehaviorProvider(dtp);
- }
-
- public IFeatureProvider getFeatureProvider() {
- return pfp;
- }
-
- public IToolBehaviorProvider getToolBehaviorProvider() {
- return tbp;
- }
-
- protected static String getSPPKind(SPPRef spp) {
- String kind = "";
- if (ValidationUtil.isRelay(spp))
- kind += "R";
- return kind;
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.support;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature.Setting;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.etrice.core.naming.RoomNameProvider;
+import org.eclipse.etrice.core.room.ActorContainerClass;
+import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.etrice.core.room.LayerConnection;
+import org.eclipse.etrice.core.room.RelaySAPoint;
+import org.eclipse.etrice.core.room.RoomFactory;
+import org.eclipse.etrice.core.room.RoomPackage;
+import org.eclipse.etrice.core.room.SPPRef;
+import org.eclipse.etrice.core.room.SPPoint;
+import org.eclipse.etrice.core.room.ServiceImplementation;
+import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.core.validation.ValidationUtil;
+import org.eclipse.etrice.ui.common.support.NoResizeFeature;
+import org.eclipse.etrice.ui.structure.DiagramTypeProvider;
+import org.eclipse.etrice.ui.structure.ImageProvider;
+import org.eclipse.etrice.ui.structure.dialogs.SPPPropertyDialog;
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.features.IAddFeature;
+import org.eclipse.graphiti.features.ICreateConnectionFeature;
+import org.eclipse.graphiti.features.ICreateFeature;
+import org.eclipse.graphiti.features.IDeleteFeature;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.IMoveShapeFeature;
+import org.eclipse.graphiti.features.IResizeShapeFeature;
+import org.eclipse.graphiti.features.IUpdateFeature;
+import org.eclipse.graphiti.features.context.IAddContext;
+import org.eclipse.graphiti.features.context.ICreateContext;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.context.IDeleteContext;
+import org.eclipse.graphiti.features.context.IDoubleClickContext;
+import org.eclipse.graphiti.features.context.IMoveShapeContext;
+import org.eclipse.graphiti.features.context.IPictogramElementContext;
+import org.eclipse.graphiti.features.context.IResizeShapeContext;
+import org.eclipse.graphiti.features.context.IUpdateContext;
+import org.eclipse.graphiti.features.context.impl.CreateConnectionContext;
+import org.eclipse.graphiti.features.context.impl.DeleteContext;
+import org.eclipse.graphiti.features.context.impl.MultiDeleteInfo;
+import org.eclipse.graphiti.features.custom.ICustomFeature;
+import org.eclipse.graphiti.mm.algorithms.Ellipse;
+import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.algorithms.Text;
+import org.eclipse.graphiti.mm.algorithms.styles.Color;
+import org.eclipse.graphiti.mm.pictograms.Anchor;
+import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
+import org.eclipse.graphiti.mm.pictograms.ChopboxAnchor;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.IGaService;
+import org.eclipse.graphiti.services.IPeCreateService;
+import org.eclipse.graphiti.tb.ContextButtonEntry;
+import org.eclipse.graphiti.tb.IContextButtonPadData;
+import org.eclipse.graphiti.tb.IToolBehaviorProvider;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.xtext.scoping.IScope;
+import org.eclipse.xtext.scoping.IScopeProvider;
+
+public class SPPSupport extends InterfaceItemSupport {
+
+ private static class FeatureProvider extends InterfaceItemSupport.FeatureProvider {
+
+ private static class CreateFeature extends InterfaceItemSupport.FeatureProvider.CreateFeature {
+
+ public CreateFeature(IFeatureProvider fp) {
+ super(fp, false, "SPP", "create SPP");
+ }
+
+ @Override
+ public String getCreateImageId() {
+ return ImageProvider.IMG_SPP;
+ }
+
+ @Override
+ public Object[] create(ICreateContext context) {
+ ActorContainerClass acc = (ActorContainerClass) context.getTargetContainer().getLink().getBusinessObjects().get(0);
+
+ // create SPP
+ SPPRef spp = RoomFactory.eINSTANCE.createSPPRef();
+ spp.setName(RoomNameProvider.getUniqueInterfaceItemName("spp", acc));
+
+ acc.getIfSPPs().add(spp);
+
+ IScopeProvider scopeProvider = ((DiagramTypeProvider)getFeatureProvider().getDiagramTypeProvider()).getScopeProvider();
+ IScope scope = scopeProvider.getScope(spp.eContainer().eContainer(), RoomPackage.eINSTANCE.getSAPRef_Protocol());
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ SPPPropertyDialog dlg = new SPPPropertyDialog(shell, spp, scope, true, false);
+ if (dlg.open()!=Window.OK) {
+ acc.getIfSPPs().remove(spp);
+ return EMPTY;
+ }
+
+ doneChanges = true;
+
+ // do the add
+ addGraphicalRepresentation(context, spp);
+
+ // return newly created business object(s)
+ return new Object[] { spp };
+ }
+ }
+
+ private class AddFeature extends InterfaceItemSupport.FeatureProvider.AddFeature {
+
+ public AddFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ protected String getItemKind(InterfaceItem item) {
+ if (item instanceof SPPRef)
+ return getSPPKind((SPPRef)item);
+
+ return "";
+ }
+
+ @Override
+ protected void createItemFigure(InterfaceItem item,
+ boolean refitem, ContainerShape containerShape,
+ GraphicsAlgorithm invisibleRectangle, Color darkColor,
+ Color brightDolor) {
+
+ if (item instanceof SPPRef)
+ createSPPFigure((SPPRef) item, refitem, containerShape, invisibleRectangle, darkColor, brightDolor);
+ }
+
+ }
+
+ private static class PropertyFeature extends InterfaceItemSupport.FeatureProvider.PropertyFeature {
+
+ private boolean doneChanges = false;
+
+ public PropertyFeature(IFeatureProvider fp) {
+ super(fp, "Edit SPP...", "Edit SPP Properties");
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ if (!super.canExecute(context))
+ return false;
+
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes != null && pes.length == 1 && pes[0] instanceof ContainerShape) {
+ Object bo = getBusinessObjectForPictogramElement(pes[0]);
+ return (bo instanceof SPPRef);
+ }
+ return false;
+ }
+
+ @Override
+ public void execute(ICustomContext context) {
+ SPPRef spp = (SPPRef) getBusinessObjectForPictogramElement(context.getPictogramElements()[0]);
+ boolean refport = isRefItem(context.getPictogramElements()[0]);
+
+ IScopeProvider scopeProvider = ((DiagramTypeProvider)getFeatureProvider().getDiagramTypeProvider()).getScopeProvider();
+ IScope scope = scopeProvider.getScope(spp.eContainer().eContainer(), RoomPackage.eINSTANCE.getSAPRef_Protocol());
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ SPPPropertyDialog dlg = new SPPPropertyDialog(shell, spp, scope, false, refport);
+ if (dlg.open()!=Window.OK)
+ return;
+
+ doneChanges = true;
+ updateSPPFigure(spp, context.getPictogramElements()[0], manageColor(DARK_COLOR), manageColor(BRIGHT_COLOR));
+ }
+
+ @Override
+ public boolean hasDoneChanges() {
+ return doneChanges;
+ }
+
+ }
+
+ private class UpdateFeature extends InterfaceItemSupport.FeatureProvider.UpdateFeature {
+
+ public UpdateFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ protected String getItemKind(InterfaceItem item) {
+ if (item instanceof SPPRef)
+ return getSPPKind((SPPRef)item);
+
+ return "";
+ }
+
+ @Override
+ protected void updateFigure(InterfaceItem item,
+ PictogramElement pe, Color dark, Color bright) {
+ updateSPPFigure((SPPRef)item, pe, dark, bright);
+ }
+
+ }
+
+ private static class DeleteFeature extends InterfaceItemSupport.FeatureProvider.DeleteFeature {
+
+ private ArrayList<LayerConnection> external = new ArrayList<LayerConnection>();
+ private ArrayList<LayerConnection> internal = new ArrayList<LayerConnection>();
+
+ public DeleteFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canDelete(IDeleteContext context) {
+ if (!super.canDelete(context))
+ return false;
+
+ ContainerShape shape = (ContainerShape) context.getPictogramElement();
+ Object bo = getBusinessObjectForPictogramElement(shape);
+ if (bo instanceof EObject && ((EObject)bo).eIsProxy())
+ return true;
+
+ if (!(bo instanceof SPPRef))
+ return false;
+
+ return true;
+ }
+
+ @Override
+ public void delete(IDeleteContext context) {
+ // check for bindings first
+ external.clear();
+ internal.clear();
+ SPPRef spp = (SPPRef) getBusinessObjectForPictogramElement(context.getPictogramElement());
+ StructureClass sc = (StructureClass) spp.eContainer();
+ Collection<Setting> refs = EcoreUtil.UsageCrossReferencer.find(spp, spp.eResource().getResourceSet());
+ for (Setting ref : refs) {
+ if (ref.getEObject() instanceof RelaySAPoint || ref.getEObject() instanceof SPPoint) {
+ if (ref.getEObject().eContainer().eContainer() instanceof StructureClass
+ && ref.getEObject().eContainer().eContainer()==sc)
+ internal.add((LayerConnection) ref.getEObject().eContainer());
+ else
+ external.add((LayerConnection) ref.getEObject().eContainer());
+ }
+ else if (ref.getEObject() instanceof ServiceImplementation) {
+ MessageDialog.openInformation(
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ "Delete SPP",
+ "This spp cannot be deleted since it is referenced by a service implementation.");
+ return;
+ }
+ }
+ if (!external.isEmpty()) {
+ boolean proceed = MessageDialog.openQuestion(
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ "Delete SPP",
+ "This spp is connected externally.\n"
+ +"It can only be deleted if the external layer connections are also deleted.\n\n"
+ +"Proceed?");
+ if (!proceed)
+ return;
+ }
+
+ super.delete(context);
+ }
+
+ @Override
+ public void preDelete(IDeleteContext context) {
+ // delete all bindings
+ for (LayerConnection bind: internal) {
+ PictogramElement connection = getFeatureProvider().getPictogramElementForBusinessObject(bind);
+ DeleteContext ctx = new DeleteContext(connection);
+ ctx.setMultiDeleteInfo(new MultiDeleteInfo(false, false, 1));
+ IDeleteFeature deleteFeature = getFeatureProvider().getDeleteFeature(ctx);
+ if (deleteFeature!=null)
+ deleteFeature.delete(ctx);
+ }
+ for (LayerConnection bind: external) {
+ EcoreUtil.delete(bind);
+ }
+
+ super.preDelete(context);
+ }
+ }
+
+ public FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp) {
+ super(dtp, fp);
+ }
+
+ @Override
+ public ICreateFeature[] getCreateFeatures() {
+ return new ICreateFeature[] { new CreateFeature(fp) };
+ }
+
+ @Override
+ public IAddFeature getAddFeature(IAddContext context) {
+ return new AddFeature(fp);
+ }
+
+ @Override
+ public IMoveShapeFeature getMoveShapeFeature(IMoveShapeContext context) {
+ return new MoveShapeFeature(fp);
+ }
+
+ @Override
+ public IResizeShapeFeature getResizeShapeFeature(IResizeShapeContext context) {
+ return new NoResizeFeature(fp);
+ }
+
+ @Override
+ public ICustomFeature[] getCustomFeatures(ICustomContext context) {
+ return new ICustomFeature[] { new PropertyFeature(fp) };
+ }
+
+ @Override
+ public IUpdateFeature getUpdateFeature(IUpdateContext context) {
+ return new UpdateFeature(fp);
+ }
+
+ @Override
+ public IDeleteFeature getDeleteFeature(IDeleteContext context) {
+ return new DeleteFeature(fp);
+ }
+
+ protected static void createSPPFigure(SPPRef spp, boolean refspp,
+ ContainerShape containerShape,
+ GraphicsAlgorithm invisibleRectangle, Color darkColor, Color brightDolor) {
+
+ boolean relay = ValidationUtil.isRelay(spp);
+
+ int size = refspp?ITEM_SIZE_SMALL:ITEM_SIZE;
+ int margin = refspp?MARGIN_SMALL:MARGIN;
+ int line = refspp?LINE_WIDTH/2:LINE_WIDTH;
+
+ Color bg = brightDolor;
+ if (refspp) {
+ bg = darkColor;
+ }
+ else {
+ if (relay)
+ bg = brightDolor;
+ else
+ bg = darkColor;
+ }
+
+ IGaService gaService = Graphiti.getGaService();
+
+ // TODOHRR: depicting SPPs as diamond using polygon didn't work
+// int s2 = margin-size/2;
+// int xy[] = new int[] { s2, 0, margin, s2, s2, margin, 0, s2};
+// Polygon rect = gaService.createPolygon(invisibleRectangle, xy);
+// rect.setForeground(darkColor);
+// rect.setBackground(bg);
+// rect.setLineWidth(line);
+// gaService.setLocation(rect, s2, s2);
+ //Rectangle rect = gaService.createRectangle(invisibleRectangle);
+
+ Ellipse rect = gaService.createEllipse(invisibleRectangle);
+ rect.setForeground(darkColor);
+ rect.setBackground(bg);
+ rect.setLineWidth(line);
+ gaService.setLocationAndSize(rect, margin-size/2, margin-size/2, size, size);
+
+ if (containerShape.getAnchors().isEmpty()) {
+ // here we place our anchor
+ IPeCreateService peCreateService = Graphiti.getPeCreateService();
+// FixPointAnchor anchor = peCreateService.createFixPointAnchor(containerShape);
+// anchor.setLocation(gaService.createPoint(xy[0], xy[1]));
+// anchor = peCreateService.createFixPointAnchor(containerShape);
+// anchor.setLocation(gaService.createPoint(xy[2], xy[3]));
+// anchor = peCreateService.createFixPointAnchor(containerShape);
+// anchor.setLocation(gaService.createPoint(xy[4], xy[5]));
+// anchor = peCreateService.createFixPointAnchor(containerShape);
+// anchor.setLocation(gaService.createPoint(xy[6], xy[7]));
+ // TODOHRR: EllipseAnchor would be nice
+ ChopboxAnchor anchor = peCreateService.createChopboxAnchor(containerShape);
+ anchor.setReferencedGraphicsAlgorithm(rect);
+ }
+ else {
+ // we just set the referenced GA
+ //containerShape.getAnchors().get(0).setReferencedGraphicsAlgorithm(rect);
+ }
+ }
+
+ private static void updateSPPFigure(SPPRef spp, PictogramElement pe, Color dark, Color bright) {
+ ContainerShape container = (ContainerShape)pe;
+
+ // we clear the figure and rebuild it
+ GraphicsAlgorithm invisibleRect = pe.getGraphicsAlgorithm();
+ invisibleRect.getGraphicsAlgorithmChildren().clear();
+
+ createSPPFigure(spp, false, container, invisibleRect, dark, bright);
+
+ GraphicsAlgorithm ga = container.getChildren().get(0).getGraphicsAlgorithm();
+ if (ga instanceof Text) {
+ ((Text)ga).setValue(spp.getName());
+ }
+
+ }
+
+ }
+
+ private class BehaviorProvider extends InterfaceItemSupport.BehaviorProvider {
+
+ public BehaviorProvider(IDiagramTypeProvider dtp) {
+ super(dtp);
+ }
+
+ @Override
+ public ICustomFeature getDoubleClickFeature(IDoubleClickContext context) {
+ return new FeatureProvider.PropertyFeature(getDiagramTypeProvider().getFeatureProvider());
+ }
+
+ @Override
+ public IContextButtonPadData getContextButtonPad(
+ IPictogramElementContext context) {
+
+ IContextButtonPadData data = super.getContextButtonPad(context);
+ PictogramElement pe = context.getPictogramElement();
+
+ CreateConnectionContext ccc = new CreateConnectionContext();
+ ccc.setSourcePictogramElement(pe);
+ Anchor anchor = null;
+ if (pe instanceof AnchorContainer) {
+ // our spp has four fixed point anchor - we choose the first one
+ anchor = ((ContainerShape)pe).getAnchors().get(0);
+ }
+ ccc.setSourceAnchor(anchor);
+
+ ContextButtonEntry button = new ContextButtonEntry(null, context);
+ button.setText("Create Layer Connection");
+ button.setIconId(ImageProvider.IMG_LAYER_CONNECTION);
+ ICreateConnectionFeature[] features = getFeatureProvider().getCreateConnectionFeatures();
+ for (ICreateConnectionFeature feature : features) {
+ if (feature.isAvailable(ccc) && feature.canStartConnection(ccc))
+ button.addDragAndDropFeature(feature);
+ }
+
+ if (button.getDragAndDropFeatures().size() > 0) {
+ data.getDomainSpecificContextButtons().add(button);
+ }
+
+ return data;
+ }
+ }
+
+ private FeatureProvider pfp;
+ private BehaviorProvider tbp;
+
+ public SPPSupport(IDiagramTypeProvider dtp, IFeatureProvider fp) {
+ pfp = new FeatureProvider(dtp,fp);
+ tbp = new BehaviorProvider(dtp);
+ }
+
+ public IFeatureProvider getFeatureProvider() {
+ return pfp;
+ }
+
+ public IToolBehaviorProvider getToolBehaviorProvider() {
+ return tbp;
+ }
+
+ protected static String getSPPKind(SPPRef spp) {
+ String kind = "";
+ if (ValidationUtil.isRelay(spp))
+ kind += "R";
+ return kind;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassSupport.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassSupport.java
index 9a70e1ca9..b29881fcf 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassSupport.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassSupport.java
@@ -1,689 +1,689 @@
-/*******************************************************************************
- * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.structure.support;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.etrice.core.room.ActorClass;
-import org.eclipse.etrice.core.room.ActorContainerRef;
-import org.eclipse.etrice.core.room.Binding;
-import org.eclipse.etrice.core.room.InterfaceItem;
-import org.eclipse.etrice.core.room.LayerConnection;
-import org.eclipse.etrice.core.room.Port;
-import org.eclipse.etrice.core.room.StructureClass;
-import org.eclipse.etrice.core.room.util.RoomHelpers;
-import org.eclipse.etrice.ui.common.support.DeleteWithoutConfirmFeature;
-import org.eclipse.etrice.ui.structure.DiagramAccess;
-import org.eclipse.graphiti.dt.IDiagramTypeProvider;
-import org.eclipse.graphiti.features.IAddFeature;
-import org.eclipse.graphiti.features.IDeleteFeature;
-import org.eclipse.graphiti.features.IFeatureProvider;
-import org.eclipse.graphiti.features.ILayoutFeature;
-import org.eclipse.graphiti.features.IReason;
-import org.eclipse.graphiti.features.IRemoveFeature;
-import org.eclipse.graphiti.features.IResizeShapeFeature;
-import org.eclipse.graphiti.features.IUpdateFeature;
-import org.eclipse.graphiti.features.context.IAddContext;
-import org.eclipse.graphiti.features.context.ICustomContext;
-import org.eclipse.graphiti.features.context.IDeleteContext;
-import org.eclipse.graphiti.features.context.ILayoutContext;
-import org.eclipse.graphiti.features.context.IRemoveContext;
-import org.eclipse.graphiti.features.context.IResizeShapeContext;
-import org.eclipse.graphiti.features.context.IUpdateContext;
-import org.eclipse.graphiti.features.context.impl.RemoveContext;
-import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
-import org.eclipse.graphiti.features.custom.ICustomFeature;
-import org.eclipse.graphiti.features.impl.AbstractAddFeature;
-import org.eclipse.graphiti.features.impl.AbstractLayoutFeature;
-import org.eclipse.graphiti.features.impl.AbstractUpdateFeature;
-import org.eclipse.graphiti.features.impl.DefaultRemoveFeature;
-import org.eclipse.graphiti.features.impl.DefaultResizeShapeFeature;
-import org.eclipse.graphiti.features.impl.Reason;
-import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
-import org.eclipse.graphiti.mm.algorithms.Rectangle;
-import org.eclipse.graphiti.mm.pictograms.Anchor;
-import org.eclipse.graphiti.mm.pictograms.Connection;
-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.mm.pictograms.Shape;
-import org.eclipse.graphiti.services.Graphiti;
-import org.eclipse.graphiti.services.IGaService;
-import org.eclipse.graphiti.services.IPeCreateService;
-import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider;
-import org.eclipse.graphiti.tb.IToolBehaviorProvider;
-import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;
-import org.eclipse.graphiti.util.ColorConstant;
-import org.eclipse.graphiti.util.IColorConstant;
-
-public class StructureClassSupport {
-
- public static final int MARGIN = 40;
-
- private static final int LINE_WIDTH = 4;
- public static final int DEFAULT_SIZE_X = 600;
- public static final int DEFAULT_SIZE_Y = 400;
- private static final IColorConstant LINE_COLOR = new ColorConstant(0, 0, 0);
- private static final IColorConstant BACKGROUND = new ColorConstant(255, 255, 255);
-
- private class FeatureProvider extends DefaultFeatureProvider {
-
- private class AddFeature extends AbstractAddFeature {
-
- public AddFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canAdd(IAddContext context) {
- if (context.getNewObject() instanceof StructureClass) {
- if (context.getTargetContainer() instanceof Diagram) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public PictogramElement add(IAddContext context) {
- StructureClass ac = (StructureClass) context.getNewObject();
- Diagram diag = (Diagram) context.getTargetContainer();
-
- // CONTAINER SHAPE WITH RECTANGLE
- IPeCreateService peCreateService = Graphiti.getPeCreateService();
- ContainerShape containerShape =
- peCreateService.createContainerShape(diag, true);
-
- Graphiti.getPeService().setPropertyValue(containerShape, Constants.TYPE_KEY, Constants.CLS_TYPE);
-
- // check whether the context has a size (e.g. from a create feature)
- // otherwise define a default size for the shape
- int width = context.getWidth() <= 0 ? DEFAULT_SIZE_X : context.getWidth();
- int height = context.getHeight() <= 0 ? DEFAULT_SIZE_Y : context.getHeight();
-
- {
- IGaService gaService = Graphiti.getGaService();
-
- // create invisible outer rectangle expanded by
- // the width needed for the ports
- Rectangle invisibleRectangle =
- gaService.createInvisibleRectangle(containerShape);
-
- gaService.setLocationAndSize(invisibleRectangle,
- context.getX(), context.getY(), width + 2*MARGIN, height + 2*MARGIN);
-
- // create and set visible rectangle inside invisible rectangle
- // transparent first
- Rectangle rect = gaService.createRectangle(invisibleRectangle);
- rect.setForeground(manageColor(LINE_COLOR));
- rect.setBackground(manageColor(BACKGROUND));
- rect.setTransparency(0.5);
- rect.setLineWidth(LINE_WIDTH);
- gaService.setLocationAndSize(rect, MARGIN, MARGIN, width, height);
- // then unfilled opaque
- rect = gaService.createRectangle(invisibleRectangle);
- rect.setForeground(manageColor(LINE_COLOR));
- rect.setFilled(false);
- rect.setLineWidth(LINE_WIDTH);
- gaService.setLocationAndSize(rect, MARGIN, MARGIN, width, height);
-
- // create link and wire it
- link(containerShape, ac);
- link(getDiagram(), ac);
- }
-
- // call the layout feature
- layoutPictogramElement(containerShape);
-
- return containerShape;
-
- }
-
- }
-
- private class LayoutFeature extends AbstractLayoutFeature {
-
- private static final int MIN_HEIGHT = 100;
- private static final int MIN_WIDTH = 250;
-
- public LayoutFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canLayout(ILayoutContext context) {
- // return true, if pictogram element is linked to an ActorClass
- PictogramElement pe = context.getPictogramElement();
- if (!(pe instanceof ContainerShape))
- return false;
-
- EList<EObject> businessObjects = pe.getLink().getBusinessObjects();
- return businessObjects.size() == 1
- && businessObjects.get(0) instanceof StructureClass;
- }
-
- @Override
- public boolean layout(ILayoutContext context) {
- boolean anythingChanged = false;
- ContainerShape containerShape = (ContainerShape) context
- .getPictogramElement();
-
- GraphicsAlgorithm containerGa = containerShape.getGraphicsAlgorithm();
-
- // height
- if (containerGa.getHeight() < MIN_HEIGHT) {
- containerGa.setHeight(MIN_HEIGHT);
- anythingChanged = true;
- }
-
- // width
- if (containerGa.getWidth() < MIN_WIDTH) {
- containerGa.setWidth(MIN_WIDTH);
- anythingChanged = true;
- }
-
- int w = containerGa.getWidth();
- int h = containerGa.getHeight();
-
- if (containerGa.getGraphicsAlgorithmChildren().size()==2) {
- GraphicsAlgorithm ga = containerGa.getGraphicsAlgorithmChildren().get(0);
- ga.setWidth(w-2*MARGIN);
- ga.setHeight(h-2*MARGIN);
- ga = containerGa.getGraphicsAlgorithmChildren().get(1);
- ga.setWidth(w-2*MARGIN);
- ga.setHeight(h-2*MARGIN);
- anythingChanged = true;
- }
-
- return anythingChanged;
- }
-
- }
-
- private class UpdateFeature extends AbstractUpdateFeature {
-
- public UpdateFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canUpdate(IUpdateContext context) {
- if (context.getPictogramElement() instanceof Diagram)
- return false;
-
- Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
- if (bo instanceof EObject && ((EObject)bo).eIsProxy())
- return true;
-
- return bo instanceof StructureClass;
- }
-
- @Override
- public IReason updateNeeded(IUpdateContext context) {
- Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
- if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
- return Reason.createTrueReason("Structure class deleted from model");
- }
-
- StructureClass sc = (StructureClass) bo;
- ContainerShape shape = (ContainerShape) context.getPictogramElement();
-
- String reason = "";
- int missing = 0;
-
- // check for interface items added in model not present in diagram (including inherited)
- {
- List<InterfaceItem> expectedItems = RoomHelpers.getInterfaceItems(sc, true);
- List<InterfaceItem> presentItems = SupportUtil.getInterfaceItems(shape, fp);
- for (InterfaceItem interfaceItem : expectedItems) {
- if (!presentItems.contains(interfaceItem))
- ++missing;
- }
- if (missing>0)
- reason += missing+" missing interface items\n";
- }
-
- // check for refs added in model not present in diagram (including inherited)
- {
- missing = 0;
- List<ActorContainerRef> expectedRefs = RoomHelpers.getRefs(sc, true);
- List<ActorContainerRef> presentRefs = SupportUtil.getRefs(shape, fp);
- for (ActorContainerRef actorContainerRef : expectedRefs) {
- if (!presentRefs.contains(actorContainerRef))
- ++missing;
- }
- if (missing>0)
- reason += missing+" missing refs\n";
- }
-
- // check for bindings added in model not present in diagram (including inherited)
- {
- missing = 0;
- List<Binding> expectedBindings = RoomHelpers.getBindings(sc, true);
- List<Binding> presentBindings = SupportUtil.getBindings(getDiagram(), fp);
- for (Binding binding : expectedBindings) {
- if (!presentBindings.contains(binding))
- ++missing;
- }
- if (missing>0)
- reason += missing+" missing bindings\n";
- }
-
- // check for layer connections added in model not present in diagram (including inherited)
- {
- missing = 0;
- List<LayerConnection> expectedBindings = RoomHelpers.getConnections(sc, true);
- List<LayerConnection> presentBindings = SupportUtil.getConnections(getDiagram(), fp);
- for (LayerConnection binding : expectedBindings) {
- if (!presentBindings.contains(binding))
- ++missing;
- }
- if (missing>0)
- reason += missing+" missing layer connections\n";
- }
-
- if (!reason.isEmpty())
- return Reason.createTrueReason(reason.substring(0, reason.length()-1));
-
- return Reason.createFalseReason();
- }
-
- @Override
- public boolean update(IUpdateContext context) {
- ContainerShape containerShape = (ContainerShape)context.getPictogramElement();
- if (containerShape instanceof Diagram)
- containerShape = (ContainerShape) containerShape.getChildren().get(0);
- Object bo = getBusinessObjectForPictogramElement(containerShape);
- if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
- IRemoveContext rc = new RemoveContext(containerShape);
- IFeatureProvider featureProvider = getFeatureProvider();
- IRemoveFeature removeFeature = featureProvider.getRemoveFeature(rc);
- if (removeFeature != null) {
- removeFeature.remove(rc);
- }
- EcoreUtil.delete((EObject) bo);
- return true;
- }
-
- StructureClass sc = (StructureClass) bo;
- addMissingItems(sc, containerShape, fp);
-
- return true;
- }
- }
-
- private class OpenBehaviorDiagram extends AbstractCustomFeature {
-
- public OpenBehaviorDiagram(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public String getName() {
- return "Open Class Behavior";
- }
-
- @Override
- public boolean canExecute(ICustomContext context) {
- PictogramElement[] pes = context.getPictogramElements();
- if (pes != null && pes.length == 1) {
- Object bo = getBusinessObjectForPictogramElement(pes[0]);
- if (bo instanceof ActorClass) {
- return true;
- }
- }
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.graphiti.features.custom.ICustomFeature#execute(org.eclipse.graphiti.features.context.ICustomContext)
- */
- @Override
- public void execute(ICustomContext context) {
- PictogramElement[] pes = context.getPictogramElements();
- if (pes != null && pes.length == 1) {
- Object bo = getBusinessObjectForPictogramElement(pes[0]);
- if (bo instanceof ActorClass) {
- org.eclipse.etrice.ui.behavior.DiagramAccess diagramAccess = new org.eclipse.etrice.ui.behavior.DiagramAccess();
- diagramAccess.openDiagramEditor((ActorClass)bo);
- }
- }
- }
-
- @Override
- public boolean hasDoneChanges() {
- return false;
- }
- }
-
- private class ResizeFeature extends DefaultResizeShapeFeature {
-
- public ResizeFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canResizeShape(IResizeShapeContext context) {
- if (!super.canResizeShape(context))
- return false;
-
- int width = context.getWidth()-MARGIN;
- int height = context.getHeight()-MARGIN;
- int xmax = 0;
- int ymax = 0;
- ContainerShape containerShape = (ContainerShape)context.getShape();
- StructureClass sc = (StructureClass) getBusinessObjectForPictogramElement(containerShape);
- for (Shape childShape : containerShape.getChildren()) {
- if (isOnInterface(sc, getBusinessObjectForPictogramElement(childShape)))
- continue;
-
- GraphicsAlgorithm ga = childShape.getGraphicsAlgorithm();
- int x = ga.getX()+ga.getWidth()-ActorContainerRefSupport.MARGIN;
- int y = ga.getY()+ga.getHeight()-ActorContainerRefSupport.MARGIN;
- if (x>xmax)
- xmax = x;
- if (y>ymax)
- ymax = y;
- }
- if (width>0 && width<xmax)
- return false;
- if (height>0 && height<ymax)
- return false;
-
- return true;
- }
-
- @Override
- public void resizeShape(IResizeShapeContext context) {
- ContainerShape containerShape = (ContainerShape) context.getShape();
- StructureClass sc = (StructureClass) getBusinessObjectForPictogramElement(containerShape);
-
- if (containerShape.getGraphicsAlgorithm()!=null) {
- GraphicsAlgorithm containerGa = containerShape.getGraphicsAlgorithm();
- if (containerGa.getGraphicsAlgorithmChildren().size()==2) {
- // scale interface item coordinates
- // we refer to the visible rectangle which defines the border of our structure class
- // since the margin is not scaled
- GraphicsAlgorithm ga = containerGa.getGraphicsAlgorithmChildren().get(0);
- double sx = (context.getWidth()-2*MARGIN)/(double)ga.getWidth();
- double sy = (context.getHeight()-2*MARGIN)/(double)ga.getHeight();
-
- for (Shape childShape : containerShape.getChildren()) {
- if (isOnInterface(sc, getBusinessObjectForPictogramElement(childShape))) {
- ga = childShape.getGraphicsAlgorithm();
- ga.setX((int) (ga.getX()*sx));
- ga.setY((int) (ga.getY()*sy));
- }
- }
- }
- }
- super.resizeShape(context);
- }
-
- private boolean isOnInterface(StructureClass sc, Object childBo) {
- boolean onInterface = false;
- if (childBo instanceof InterfaceItem) {
- // in general InterfaceItem sit on the interface...
- onInterface = true;
-
- // ...with the exception of internal end ports
- if (childBo instanceof Port) {
- if (sc instanceof ActorClass) {
- if (((ActorClass) sc).getIntPorts().contains(childBo))
- onInterface = false;
- }
- }
- }
- return onInterface;
- }
- }
-
- private class RemoveFeature extends DefaultRemoveFeature {
-
- public RemoveFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canRemove(IRemoveContext context) {
- return false;
- }
- }
-
- private class DeleteFeature extends DeleteWithoutConfirmFeature {
-
- public DeleteFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canDelete(IDeleteContext context) {
- return false;
- }
- }
-
- private IFeatureProvider fp;
-
- public FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp) {
- super(dtp);
- this.fp = fp;
- }
-
- @Override
- public IAddFeature getAddFeature(IAddContext context) {
- return new AddFeature(fp);
- }
-
- @Override
- public ILayoutFeature getLayoutFeature(ILayoutContext context) {
- return new LayoutFeature(fp);
- }
-
- @Override
- public IUpdateFeature getUpdateFeature(IUpdateContext context) {
- return new UpdateFeature(fp);
- }
-
- @Override
- public ICustomFeature[] getCustomFeatures(ICustomContext context) {
- return new ICustomFeature[] {
- new OpenBehaviorDiagram(fp)};
- }
-
- @Override
- public IResizeShapeFeature getResizeShapeFeature(
- IResizeShapeContext context) {
- return new ResizeFeature(fp);
- }
-
- @Override
- public IRemoveFeature getRemoveFeature(IRemoveContext context) {
- return new RemoveFeature(fp);
- }
-
- @Override
- public IDeleteFeature getDeleteFeature(IDeleteContext context) {
- return new DeleteFeature(fp);
- }
- }
-
- private class BehaviorProvider extends DefaultToolBehaviorProvider {
-
- public BehaviorProvider(IDiagramTypeProvider dtp) {
- super(dtp);
- }
-
- @Override
- public GraphicsAlgorithm[] getClickArea(PictogramElement pe) {
- GraphicsAlgorithm invisible = pe.getGraphicsAlgorithm();
- GraphicsAlgorithm rectangle =
- invisible.getGraphicsAlgorithmChildren().get(0);
- return new GraphicsAlgorithm[] { rectangle };
- }
-
- @Override
- public GraphicsAlgorithm getSelectionBorder(PictogramElement pe) {
- GraphicsAlgorithm invisible = pe.getGraphicsAlgorithm();
-
- GraphicsAlgorithm rectangle =
- invisible.getGraphicsAlgorithmChildren().get(0);
- return rectangle;
- }
- }
-
- private FeatureProvider afp;
- private BehaviorProvider tbp;
-
- public StructureClassSupport(IDiagramTypeProvider dtp, IFeatureProvider fp) {
- afp = new FeatureProvider(dtp, fp);
- tbp = new BehaviorProvider(dtp);
- }
-
- public IFeatureProvider getFeatureProvider() {
- return afp;
- }
-
- public IToolBehaviorProvider getToolBehaviorProvider() {
- return tbp;
- }
-
- public static void addInheritedItems(ActorClass ac, ContainerShape acShape, Map<String,Anchor> ifitem2anchor, IFeatureProvider fp) {
-
- // we don't have to recurse since the base class diagram already contains all inherited items
- Diagram diag = (Diagram) acShape.eContainer();
- ResourceSet rs = ac.eResource().getResourceSet();
- List<InterfaceItem> presentIfItems = SupportUtil.getInterfaceItems(acShape, fp, ifitem2anchor);
- List<ActorContainerRef> presentRefs = SupportUtil.getRefs(acShape, fp, ifitem2anchor);
- List<Binding> presentBindings = SupportUtil.getBindings(diag, fp);
- List<LayerConnection> presentConnections = SupportUtil.getConnections(diag, fp);
-
- Diagram refDiag = new DiagramAccess().getDiagram(ac);
- if (!refDiag.getChildren().isEmpty()) {
- ContainerShape refAcShape = (ContainerShape) refDiag.getChildren().get(0);
- Object bo = fp.getBusinessObjectForPictogramElement(refAcShape);
- if (bo instanceof StructureClass) {
- StructureClass extRefClass = (StructureClass) bo;
- assert(extRefClass.getName().equals(ac.getName())): "actor class names must match";
-
- int scaleX = refAcShape.getGraphicsAlgorithm().getWidth()/acShape.getGraphicsAlgorithm().getWidth();
- int scaleY = refAcShape.getGraphicsAlgorithm().getHeight()/acShape.getGraphicsAlgorithm().getHeight();
-
- for (Shape childShape : refAcShape.getChildren()) {
- bo = fp.getBusinessObjectForPictogramElement(childShape);
- GraphicsAlgorithm ga = childShape.getGraphicsAlgorithm();
- if (bo instanceof InterfaceItem || bo instanceof ActorContainerRef) {
- EObject ownObject = SupportUtil.getOwnObject((EObject)bo, rs);
- if (!presentIfItems.contains(ownObject) && !presentRefs.contains(ownObject)) {
- int x = (ga.getX()+ga.getWidth()/2)/scaleX;
- int y = (ga.getY()+ga.getHeight()/2)/scaleY;
- SupportUtil.addItem(ownObject, x, y, acShape, ifitem2anchor, fp);
- }
- }
- }
- for (Connection conn : refDiag.getConnections()) {
- bo = fp.getBusinessObjectForPictogramElement(conn);
- if (bo instanceof Binding) {
- Binding bind = (Binding) SupportUtil.getOwnObject((Binding)bo, rs);
- if (!presentBindings.contains(bind))
- SupportUtil.addBinding(bind, fp, ifitem2anchor);
- }
- else if (bo instanceof LayerConnection) {
- LayerConnection lc = (LayerConnection) SupportUtil.getOwnObject((LayerConnection)bo, rs);
- if (!presentConnections.contains(lc))
- SupportUtil.addLayerConnection(lc, fp, ifitem2anchor);
- }
- }
- }
- }
- }
-
- private static void addMissingItems(StructureClass sc, ContainerShape acShape, IFeatureProvider fp) {
-
- int width = acShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0).getWidth();
-
- HashMap<String, Anchor> ifitem2anchor = new HashMap<String, Anchor>();
-
- // interface items
- {
- List<InterfaceItem> present = SupportUtil.getInterfaceItems(acShape, fp, ifitem2anchor);
- {
- List<InterfaceItem> expected = RoomHelpers.getInterfaceItems(sc, false);
- List<InterfaceItem> items = new ArrayList<InterfaceItem>();
- for (InterfaceItem item : expected) {
- if (!present.contains(item))
- items.add(item);
- }
- SupportUtil.addInterfaceItems(items, 0, acShape, width, fp, ifitem2anchor);
- }
- if (sc instanceof ActorClass) {
-
- List<InterfaceItem> ports = new ArrayList<InterfaceItem>();
- for (Port port : ((ActorClass) sc).getIntPorts()) {
- if (!present.contains(port))
- ports.add(port);
- }
- SupportUtil.addInterfaceItems(ports, 3*StructureClassSupport.MARGIN, acShape, width, fp, ifitem2anchor);
- }
- }
-
- // actor container references
- {
- List<ActorContainerRef> present = SupportUtil.getRefs(acShape, fp, ifitem2anchor);
- List<ActorContainerRef> expected = RoomHelpers.getRefs(sc, false);
- List<ActorContainerRef> items = new ArrayList<ActorContainerRef>();
- for (ActorContainerRef item : expected) {
- if (!present.contains(item))
- items.add(item);
- }
- SupportUtil.addRefItems(items, acShape, width, fp, ifitem2anchor);
- }
-
- // base class items
- if (sc instanceof ActorClass) {
- ActorClass base = ((ActorClass) sc).getBase();
-
- // add inherited ports and refs and bindings (and preserve layout)
- if (base!=null)
- StructureClassSupport.addInheritedItems(base, acShape, ifitem2anchor, fp);
- }
-
- Diagram diag = (Diagram) acShape.eContainer();
-
- // bindings
- {
- List<Binding> present = SupportUtil.getBindings(diag, fp);
- List<Binding> expected = RoomHelpers.getBindings(sc, false);
- for (Binding bind : expected) {
- if (!present.contains(bind))
- SupportUtil.addBinding(bind, fp, ifitem2anchor);
- }
- }
-
- // layer connections
- {
- List<LayerConnection> present = SupportUtil.getConnections(diag, fp);
- List<LayerConnection> expected = RoomHelpers.getConnections(sc, false);
- for (LayerConnection lc : expected) {
- if (!present.contains(lc))
- SupportUtil.addLayerConnection(lc, fp, ifitem2anchor);
- }
- }
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.support;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.ActorContainerRef;
+import org.eclipse.etrice.core.room.Binding;
+import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.etrice.core.room.LayerConnection;
+import org.eclipse.etrice.core.room.Port;
+import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.core.room.util.RoomHelpers;
+import org.eclipse.etrice.ui.common.support.DeleteWithoutConfirmFeature;
+import org.eclipse.etrice.ui.structure.DiagramAccess;
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.features.IAddFeature;
+import org.eclipse.graphiti.features.IDeleteFeature;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.ILayoutFeature;
+import org.eclipse.graphiti.features.IReason;
+import org.eclipse.graphiti.features.IRemoveFeature;
+import org.eclipse.graphiti.features.IResizeShapeFeature;
+import org.eclipse.graphiti.features.IUpdateFeature;
+import org.eclipse.graphiti.features.context.IAddContext;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.context.IDeleteContext;
+import org.eclipse.graphiti.features.context.ILayoutContext;
+import org.eclipse.graphiti.features.context.IRemoveContext;
+import org.eclipse.graphiti.features.context.IResizeShapeContext;
+import org.eclipse.graphiti.features.context.IUpdateContext;
+import org.eclipse.graphiti.features.context.impl.RemoveContext;
+import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
+import org.eclipse.graphiti.features.custom.ICustomFeature;
+import org.eclipse.graphiti.features.impl.AbstractAddFeature;
+import org.eclipse.graphiti.features.impl.AbstractLayoutFeature;
+import org.eclipse.graphiti.features.impl.AbstractUpdateFeature;
+import org.eclipse.graphiti.features.impl.DefaultRemoveFeature;
+import org.eclipse.graphiti.features.impl.DefaultResizeShapeFeature;
+import org.eclipse.graphiti.features.impl.Reason;
+import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.algorithms.Rectangle;
+import org.eclipse.graphiti.mm.pictograms.Anchor;
+import org.eclipse.graphiti.mm.pictograms.Connection;
+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.mm.pictograms.Shape;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.IGaService;
+import org.eclipse.graphiti.services.IPeCreateService;
+import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider;
+import org.eclipse.graphiti.tb.IToolBehaviorProvider;
+import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;
+import org.eclipse.graphiti.util.ColorConstant;
+import org.eclipse.graphiti.util.IColorConstant;
+
+public class StructureClassSupport {
+
+ public static final int MARGIN = 40;
+
+ private static final int LINE_WIDTH = 4;
+ public static final int DEFAULT_SIZE_X = 600;
+ public static final int DEFAULT_SIZE_Y = 400;
+ private static final IColorConstant LINE_COLOR = new ColorConstant(0, 0, 0);
+ private static final IColorConstant BACKGROUND = new ColorConstant(255, 255, 255);
+
+ private class FeatureProvider extends DefaultFeatureProvider {
+
+ private class AddFeature extends AbstractAddFeature {
+
+ public AddFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canAdd(IAddContext context) {
+ if (context.getNewObject() instanceof StructureClass) {
+ if (context.getTargetContainer() instanceof Diagram) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public PictogramElement add(IAddContext context) {
+ StructureClass ac = (StructureClass) context.getNewObject();
+ Diagram diag = (Diagram) context.getTargetContainer();
+
+ // CONTAINER SHAPE WITH RECTANGLE
+ IPeCreateService peCreateService = Graphiti.getPeCreateService();
+ ContainerShape containerShape =
+ peCreateService.createContainerShape(diag, true);
+
+ Graphiti.getPeService().setPropertyValue(containerShape, Constants.TYPE_KEY, Constants.CLS_TYPE);
+
+ // check whether the context has a size (e.g. from a create feature)
+ // otherwise define a default size for the shape
+ int width = context.getWidth() <= 0 ? DEFAULT_SIZE_X : context.getWidth();
+ int height = context.getHeight() <= 0 ? DEFAULT_SIZE_Y : context.getHeight();
+
+ {
+ IGaService gaService = Graphiti.getGaService();
+
+ // create invisible outer rectangle expanded by
+ // the width needed for the ports
+ Rectangle invisibleRectangle =
+ gaService.createInvisibleRectangle(containerShape);
+
+ gaService.setLocationAndSize(invisibleRectangle,
+ context.getX(), context.getY(), width + 2*MARGIN, height + 2*MARGIN);
+
+ // create and set visible rectangle inside invisible rectangle
+ // transparent first
+ Rectangle rect = gaService.createRectangle(invisibleRectangle);
+ rect.setForeground(manageColor(LINE_COLOR));
+ rect.setBackground(manageColor(BACKGROUND));
+ rect.setTransparency(0.5);
+ rect.setLineWidth(LINE_WIDTH);
+ gaService.setLocationAndSize(rect, MARGIN, MARGIN, width, height);
+ // then unfilled opaque
+ rect = gaService.createRectangle(invisibleRectangle);
+ rect.setForeground(manageColor(LINE_COLOR));
+ rect.setFilled(false);
+ rect.setLineWidth(LINE_WIDTH);
+ gaService.setLocationAndSize(rect, MARGIN, MARGIN, width, height);
+
+ // create link and wire it
+ link(containerShape, ac);
+ link(getDiagram(), ac);
+ }
+
+ // call the layout feature
+ layoutPictogramElement(containerShape);
+
+ return containerShape;
+
+ }
+
+ }
+
+ private class LayoutFeature extends AbstractLayoutFeature {
+
+ private static final int MIN_HEIGHT = 100;
+ private static final int MIN_WIDTH = 250;
+
+ public LayoutFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canLayout(ILayoutContext context) {
+ // return true, if pictogram element is linked to an ActorClass
+ PictogramElement pe = context.getPictogramElement();
+ if (!(pe instanceof ContainerShape))
+ return false;
+
+ EList<EObject> businessObjects = pe.getLink().getBusinessObjects();
+ return businessObjects.size() == 1
+ && businessObjects.get(0) instanceof StructureClass;
+ }
+
+ @Override
+ public boolean layout(ILayoutContext context) {
+ boolean anythingChanged = false;
+ ContainerShape containerShape = (ContainerShape) context
+ .getPictogramElement();
+
+ GraphicsAlgorithm containerGa = containerShape.getGraphicsAlgorithm();
+
+ // height
+ if (containerGa.getHeight() < MIN_HEIGHT) {
+ containerGa.setHeight(MIN_HEIGHT);
+ anythingChanged = true;
+ }
+
+ // width
+ if (containerGa.getWidth() < MIN_WIDTH) {
+ containerGa.setWidth(MIN_WIDTH);
+ anythingChanged = true;
+ }
+
+ int w = containerGa.getWidth();
+ int h = containerGa.getHeight();
+
+ if (containerGa.getGraphicsAlgorithmChildren().size()==2) {
+ GraphicsAlgorithm ga = containerGa.getGraphicsAlgorithmChildren().get(0);
+ ga.setWidth(w-2*MARGIN);
+ ga.setHeight(h-2*MARGIN);
+ ga = containerGa.getGraphicsAlgorithmChildren().get(1);
+ ga.setWidth(w-2*MARGIN);
+ ga.setHeight(h-2*MARGIN);
+ anythingChanged = true;
+ }
+
+ return anythingChanged;
+ }
+
+ }
+
+ private class UpdateFeature extends AbstractUpdateFeature {
+
+ public UpdateFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canUpdate(IUpdateContext context) {
+ if (context.getPictogramElement() instanceof Diagram)
+ return false;
+
+ Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
+ if (bo instanceof EObject && ((EObject)bo).eIsProxy())
+ return true;
+
+ return bo instanceof StructureClass;
+ }
+
+ @Override
+ public IReason updateNeeded(IUpdateContext context) {
+ Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
+ if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
+ return Reason.createTrueReason("Structure class deleted from model");
+ }
+
+ StructureClass sc = (StructureClass) bo;
+ ContainerShape shape = (ContainerShape) context.getPictogramElement();
+
+ String reason = "";
+ int missing = 0;
+
+ // check for interface items added in model not present in diagram (including inherited)
+ {
+ List<InterfaceItem> expectedItems = RoomHelpers.getInterfaceItems(sc, true);
+ List<InterfaceItem> presentItems = SupportUtil.getInterfaceItems(shape, fp);
+ for (InterfaceItem interfaceItem : expectedItems) {
+ if (!presentItems.contains(interfaceItem))
+ ++missing;
+ }
+ if (missing>0)
+ reason += missing+" missing interface items\n";
+ }
+
+ // check for refs added in model not present in diagram (including inherited)
+ {
+ missing = 0;
+ List<ActorContainerRef> expectedRefs = RoomHelpers.getRefs(sc, true);
+ List<ActorContainerRef> presentRefs = SupportUtil.getRefs(shape, fp);
+ for (ActorContainerRef actorContainerRef : expectedRefs) {
+ if (!presentRefs.contains(actorContainerRef))
+ ++missing;
+ }
+ if (missing>0)
+ reason += missing+" missing refs\n";
+ }
+
+ // check for bindings added in model not present in diagram (including inherited)
+ {
+ missing = 0;
+ List<Binding> expectedBindings = RoomHelpers.getBindings(sc, true);
+ List<Binding> presentBindings = SupportUtil.getBindings(getDiagram(), fp);
+ for (Binding binding : expectedBindings) {
+ if (!presentBindings.contains(binding))
+ ++missing;
+ }
+ if (missing>0)
+ reason += missing+" missing bindings\n";
+ }
+
+ // check for layer connections added in model not present in diagram (including inherited)
+ {
+ missing = 0;
+ List<LayerConnection> expectedBindings = RoomHelpers.getConnections(sc, true);
+ List<LayerConnection> presentBindings = SupportUtil.getConnections(getDiagram(), fp);
+ for (LayerConnection binding : expectedBindings) {
+ if (!presentBindings.contains(binding))
+ ++missing;
+ }
+ if (missing>0)
+ reason += missing+" missing layer connections\n";
+ }
+
+ if (!reason.isEmpty())
+ return Reason.createTrueReason(reason.substring(0, reason.length()-1));
+
+ return Reason.createFalseReason();
+ }
+
+ @Override
+ public boolean update(IUpdateContext context) {
+ ContainerShape containerShape = (ContainerShape)context.getPictogramElement();
+ if (containerShape instanceof Diagram)
+ containerShape = (ContainerShape) containerShape.getChildren().get(0);
+ Object bo = getBusinessObjectForPictogramElement(containerShape);
+ if (bo instanceof EObject && ((EObject)bo).eIsProxy()) {
+ IRemoveContext rc = new RemoveContext(containerShape);
+ IFeatureProvider featureProvider = getFeatureProvider();
+ IRemoveFeature removeFeature = featureProvider.getRemoveFeature(rc);
+ if (removeFeature != null) {
+ removeFeature.remove(rc);
+ }
+ EcoreUtil.delete((EObject) bo);
+ return true;
+ }
+
+ StructureClass sc = (StructureClass) bo;
+ addMissingItems(sc, containerShape, fp);
+
+ return true;
+ }
+ }
+
+ private class OpenBehaviorDiagram extends AbstractCustomFeature {
+
+ public OpenBehaviorDiagram(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public String getName() {
+ return "Open Class Behavior";
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes != null && pes.length == 1) {
+ Object bo = getBusinessObjectForPictogramElement(pes[0]);
+ if (bo instanceof ActorClass) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.graphiti.features.custom.ICustomFeature#execute(org.eclipse.graphiti.features.context.ICustomContext)
+ */
+ @Override
+ public void execute(ICustomContext context) {
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes != null && pes.length == 1) {
+ Object bo = getBusinessObjectForPictogramElement(pes[0]);
+ if (bo instanceof ActorClass) {
+ org.eclipse.etrice.ui.behavior.DiagramAccess diagramAccess = new org.eclipse.etrice.ui.behavior.DiagramAccess();
+ diagramAccess.openDiagramEditor((ActorClass)bo);
+ }
+ }
+ }
+
+ @Override
+ public boolean hasDoneChanges() {
+ return false;
+ }
+ }
+
+ private class ResizeFeature extends DefaultResizeShapeFeature {
+
+ public ResizeFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canResizeShape(IResizeShapeContext context) {
+ if (!super.canResizeShape(context))
+ return false;
+
+ int width = context.getWidth()-MARGIN;
+ int height = context.getHeight()-MARGIN;
+ int xmax = 0;
+ int ymax = 0;
+ ContainerShape containerShape = (ContainerShape)context.getShape();
+ StructureClass sc = (StructureClass) getBusinessObjectForPictogramElement(containerShape);
+ for (Shape childShape : containerShape.getChildren()) {
+ if (isOnInterface(sc, getBusinessObjectForPictogramElement(childShape)))
+ continue;
+
+ GraphicsAlgorithm ga = childShape.getGraphicsAlgorithm();
+ int x = ga.getX()+ga.getWidth()-ActorContainerRefSupport.MARGIN;
+ int y = ga.getY()+ga.getHeight()-ActorContainerRefSupport.MARGIN;
+ if (x>xmax)
+ xmax = x;
+ if (y>ymax)
+ ymax = y;
+ }
+ if (width>0 && width<xmax)
+ return false;
+ if (height>0 && height<ymax)
+ return false;
+
+ return true;
+ }
+
+ @Override
+ public void resizeShape(IResizeShapeContext context) {
+ ContainerShape containerShape = (ContainerShape) context.getShape();
+ StructureClass sc = (StructureClass) getBusinessObjectForPictogramElement(containerShape);
+
+ if (containerShape.getGraphicsAlgorithm()!=null) {
+ GraphicsAlgorithm containerGa = containerShape.getGraphicsAlgorithm();
+ if (containerGa.getGraphicsAlgorithmChildren().size()==2) {
+ // scale interface item coordinates
+ // we refer to the visible rectangle which defines the border of our structure class
+ // since the margin is not scaled
+ GraphicsAlgorithm ga = containerGa.getGraphicsAlgorithmChildren().get(0);
+ double sx = (context.getWidth()-2*MARGIN)/(double)ga.getWidth();
+ double sy = (context.getHeight()-2*MARGIN)/(double)ga.getHeight();
+
+ for (Shape childShape : containerShape.getChildren()) {
+ if (isOnInterface(sc, getBusinessObjectForPictogramElement(childShape))) {
+ ga = childShape.getGraphicsAlgorithm();
+ ga.setX((int) (ga.getX()*sx));
+ ga.setY((int) (ga.getY()*sy));
+ }
+ }
+ }
+ }
+ super.resizeShape(context);
+ }
+
+ private boolean isOnInterface(StructureClass sc, Object childBo) {
+ boolean onInterface = false;
+ if (childBo instanceof InterfaceItem) {
+ // in general InterfaceItem sit on the interface...
+ onInterface = true;
+
+ // ...with the exception of internal end ports
+ if (childBo instanceof Port) {
+ if (sc instanceof ActorClass) {
+ if (((ActorClass) sc).getIntPorts().contains(childBo))
+ onInterface = false;
+ }
+ }
+ }
+ return onInterface;
+ }
+ }
+
+ private class RemoveFeature extends DefaultRemoveFeature {
+
+ public RemoveFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canRemove(IRemoveContext context) {
+ return false;
+ }
+ }
+
+ private class DeleteFeature extends DeleteWithoutConfirmFeature {
+
+ public DeleteFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canDelete(IDeleteContext context) {
+ return false;
+ }
+ }
+
+ private IFeatureProvider fp;
+
+ public FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp) {
+ super(dtp);
+ this.fp = fp;
+ }
+
+ @Override
+ public IAddFeature getAddFeature(IAddContext context) {
+ return new AddFeature(fp);
+ }
+
+ @Override
+ public ILayoutFeature getLayoutFeature(ILayoutContext context) {
+ return new LayoutFeature(fp);
+ }
+
+ @Override
+ public IUpdateFeature getUpdateFeature(IUpdateContext context) {
+ return new UpdateFeature(fp);
+ }
+
+ @Override
+ public ICustomFeature[] getCustomFeatures(ICustomContext context) {
+ return new ICustomFeature[] {
+ new OpenBehaviorDiagram(fp)};
+ }
+
+ @Override
+ public IResizeShapeFeature getResizeShapeFeature(
+ IResizeShapeContext context) {
+ return new ResizeFeature(fp);
+ }
+
+ @Override
+ public IRemoveFeature getRemoveFeature(IRemoveContext context) {
+ return new RemoveFeature(fp);
+ }
+
+ @Override
+ public IDeleteFeature getDeleteFeature(IDeleteContext context) {
+ return new DeleteFeature(fp);
+ }
+ }
+
+ private class BehaviorProvider extends DefaultToolBehaviorProvider {
+
+ public BehaviorProvider(IDiagramTypeProvider dtp) {
+ super(dtp);
+ }
+
+ @Override
+ public GraphicsAlgorithm[] getClickArea(PictogramElement pe) {
+ GraphicsAlgorithm invisible = pe.getGraphicsAlgorithm();
+ GraphicsAlgorithm rectangle =
+ invisible.getGraphicsAlgorithmChildren().get(0);
+ return new GraphicsAlgorithm[] { rectangle };
+ }
+
+ @Override
+ public GraphicsAlgorithm getSelectionBorder(PictogramElement pe) {
+ GraphicsAlgorithm invisible = pe.getGraphicsAlgorithm();
+
+ GraphicsAlgorithm rectangle =
+ invisible.getGraphicsAlgorithmChildren().get(0);
+ return rectangle;
+ }
+ }
+
+ private FeatureProvider afp;
+ private BehaviorProvider tbp;
+
+ public StructureClassSupport(IDiagramTypeProvider dtp, IFeatureProvider fp) {
+ afp = new FeatureProvider(dtp, fp);
+ tbp = new BehaviorProvider(dtp);
+ }
+
+ public IFeatureProvider getFeatureProvider() {
+ return afp;
+ }
+
+ public IToolBehaviorProvider getToolBehaviorProvider() {
+ return tbp;
+ }
+
+ public static void addInheritedItems(ActorClass ac, ContainerShape acShape, Map<String,Anchor> ifitem2anchor, IFeatureProvider fp) {
+
+ // we don't have to recurse since the base class diagram already contains all inherited items
+ Diagram diag = (Diagram) acShape.eContainer();
+ ResourceSet rs = ac.eResource().getResourceSet();
+ List<InterfaceItem> presentIfItems = SupportUtil.getInterfaceItems(acShape, fp, ifitem2anchor);
+ List<ActorContainerRef> presentRefs = SupportUtil.getRefs(acShape, fp, ifitem2anchor);
+ List<Binding> presentBindings = SupportUtil.getBindings(diag, fp);
+ List<LayerConnection> presentConnections = SupportUtil.getConnections(diag, fp);
+
+ Diagram refDiag = new DiagramAccess().getDiagram(ac);
+ if (!refDiag.getChildren().isEmpty()) {
+ ContainerShape refAcShape = (ContainerShape) refDiag.getChildren().get(0);
+ Object bo = fp.getBusinessObjectForPictogramElement(refAcShape);
+ if (bo instanceof StructureClass) {
+ StructureClass extRefClass = (StructureClass) bo;
+ assert(extRefClass.getName().equals(ac.getName())): "actor class names must match";
+
+ int scaleX = refAcShape.getGraphicsAlgorithm().getWidth()/acShape.getGraphicsAlgorithm().getWidth();
+ int scaleY = refAcShape.getGraphicsAlgorithm().getHeight()/acShape.getGraphicsAlgorithm().getHeight();
+
+ for (Shape childShape : refAcShape.getChildren()) {
+ bo = fp.getBusinessObjectForPictogramElement(childShape);
+ GraphicsAlgorithm ga = childShape.getGraphicsAlgorithm();
+ if (bo instanceof InterfaceItem || bo instanceof ActorContainerRef) {
+ EObject ownObject = SupportUtil.getOwnObject((EObject)bo, rs);
+ if (!presentIfItems.contains(ownObject) && !presentRefs.contains(ownObject)) {
+ int x = (ga.getX()+ga.getWidth()/2)/scaleX;
+ int y = (ga.getY()+ga.getHeight()/2)/scaleY;
+ SupportUtil.addItem(ownObject, x, y, acShape, ifitem2anchor, fp);
+ }
+ }
+ }
+ for (Connection conn : refDiag.getConnections()) {
+ bo = fp.getBusinessObjectForPictogramElement(conn);
+ if (bo instanceof Binding) {
+ Binding bind = (Binding) SupportUtil.getOwnObject((Binding)bo, rs);
+ if (!presentBindings.contains(bind))
+ SupportUtil.addBinding(bind, fp, ifitem2anchor);
+ }
+ else if (bo instanceof LayerConnection) {
+ LayerConnection lc = (LayerConnection) SupportUtil.getOwnObject((LayerConnection)bo, rs);
+ if (!presentConnections.contains(lc))
+ SupportUtil.addLayerConnection(lc, fp, ifitem2anchor);
+ }
+ }
+ }
+ }
+ }
+
+ private static void addMissingItems(StructureClass sc, ContainerShape acShape, IFeatureProvider fp) {
+
+ int width = acShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0).getWidth();
+
+ HashMap<String, Anchor> ifitem2anchor = new HashMap<String, Anchor>();
+
+ // interface items
+ {
+ List<InterfaceItem> present = SupportUtil.getInterfaceItems(acShape, fp, ifitem2anchor);
+ {
+ List<InterfaceItem> expected = RoomHelpers.getInterfaceItems(sc, false);
+ List<InterfaceItem> items = new ArrayList<InterfaceItem>();
+ for (InterfaceItem item : expected) {
+ if (!present.contains(item))
+ items.add(item);
+ }
+ SupportUtil.addInterfaceItems(items, 0, acShape, width, fp, ifitem2anchor);
+ }
+ if (sc instanceof ActorClass) {
+
+ List<InterfaceItem> ports = new ArrayList<InterfaceItem>();
+ for (Port port : ((ActorClass) sc).getIntPorts()) {
+ if (!present.contains(port))
+ ports.add(port);
+ }
+ SupportUtil.addInterfaceItems(ports, 3*StructureClassSupport.MARGIN, acShape, width, fp, ifitem2anchor);
+ }
+ }
+
+ // actor container references
+ {
+ List<ActorContainerRef> present = SupportUtil.getRefs(acShape, fp, ifitem2anchor);
+ List<ActorContainerRef> expected = RoomHelpers.getRefs(sc, false);
+ List<ActorContainerRef> items = new ArrayList<ActorContainerRef>();
+ for (ActorContainerRef item : expected) {
+ if (!present.contains(item))
+ items.add(item);
+ }
+ SupportUtil.addRefItems(items, acShape, width, fp, ifitem2anchor);
+ }
+
+ // base class items
+ if (sc instanceof ActorClass) {
+ ActorClass base = ((ActorClass) sc).getBase();
+
+ // add inherited ports and refs and bindings (and preserve layout)
+ if (base!=null)
+ StructureClassSupport.addInheritedItems(base, acShape, ifitem2anchor, fp);
+ }
+
+ Diagram diag = (Diagram) acShape.eContainer();
+
+ // bindings
+ {
+ List<Binding> present = SupportUtil.getBindings(diag, fp);
+ List<Binding> expected = RoomHelpers.getBindings(sc, false);
+ for (Binding bind : expected) {
+ if (!present.contains(bind))
+ SupportUtil.addBinding(bind, fp, ifitem2anchor);
+ }
+ }
+
+ // layer connections
+ {
+ List<LayerConnection> present = SupportUtil.getConnections(diag, fp);
+ List<LayerConnection> expected = RoomHelpers.getConnections(sc, false);
+ for (LayerConnection lc : expected) {
+ if (!present.contains(lc))
+ SupportUtil.addLayerConnection(lc, fp, ifitem2anchor);
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/SupportUtil.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/SupportUtil.java
index 3d5d46860..746854995 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/SupportUtil.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/SupportUtil.java
@@ -1,327 +1,327 @@
-/*******************************************************************************
- * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.structure.support;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.etrice.core.room.ActorContainerRef;
-import org.eclipse.etrice.core.room.Binding;
-import org.eclipse.etrice.core.room.BindingEndPoint;
-import org.eclipse.etrice.core.room.InterfaceItem;
-import org.eclipse.etrice.core.room.LayerConnection;
-import org.eclipse.etrice.core.room.Port;
-import org.eclipse.etrice.core.room.RefSAPoint;
-import org.eclipse.etrice.core.room.RelaySAPoint;
-import org.eclipse.etrice.core.room.SAPoint;
-import org.eclipse.etrice.core.room.SPPRef;
-import org.eclipse.etrice.core.room.SPPoint;
-import org.eclipse.etrice.core.room.StructureClass;
-import org.eclipse.graphiti.features.IFeatureProvider;
-import org.eclipse.graphiti.features.context.ICreateConnectionContext;
-import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
-import org.eclipse.graphiti.features.context.impl.AddContext;
-import org.eclipse.graphiti.mm.pictograms.Anchor;
-import org.eclipse.graphiti.mm.pictograms.Connection;
-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.mm.pictograms.Shape;
-
-/**
- * description
- *
- * @author Henrik Rentz-Reichert initial contribution and API
- *
- */
-public class SupportUtil {
-
- public static final String SEP = "#";
-
- public static EObject getOwnObject(EObject obj, ResourceSet rs) {
- URI uri = EcoreUtil.getURI(obj);
- EObject own = rs.getEObject(uri, true);
- assert(own!=null): "own object must exist";
- return own;
- }
-
- public static ContainerShape addItem(EObject obj, int x, int y, ContainerShape container, IFeatureProvider fp) {
- return addItem(obj, x, y, container, null, fp);
- }
-
- public static ContainerShape addItem(EObject obj, int x, int y, ContainerShape container, Map<String,Anchor> ifitem2anchor, IFeatureProvider fp) {
- AddContext addContext = new AddContext();
-
- addContext.setNewObject(obj);
- addContext.setTargetContainer(container);
- addContext.setX(x);
- addContext.setY(y);
- ContainerShape newShape = (ContainerShape) fp.addIfPossible(addContext);
- assert(newShape!=null): "shape creation must succeed";
-
- if (ifitem2anchor!=null) {
- if (obj instanceof ActorContainerRef)
- getAnchors((ActorContainerRef)obj, newShape, ifitem2anchor);
- else if (obj instanceof InterfaceItem) {
- assert(!newShape.getAnchors().isEmpty()): "interface item must have an anchor";
- ifitem2anchor.put(SEP+((InterfaceItem)obj).getName(), newShape.getAnchors().get(0));
- }
- }
-
- return newShape;
- }
-
- public static void getAnchors(ActorContainerRef acr, PictogramElement refShape,
- final Map<String, Anchor> ifitem2anchor) {
-
- if (refShape instanceof ContainerShape) {
- ifitem2anchor.put(acr.getName()+SEP, ((ContainerShape)refShape).getAnchors().get(0));
- for (Shape child : ((ContainerShape) refShape).getChildren()) {
- if (child instanceof ContainerShape) {
- ContainerShape childShape = (ContainerShape) child;
- if (!childShape.getAnchors().isEmpty()) {
- if (!childShape.getLink().getBusinessObjects().isEmpty()) {
- EObject obj = childShape.getLink().getBusinessObjects().get(0);
- if (obj instanceof Port) {
- ifitem2anchor.put(acr.getName()+SEP+((Port)obj).getName(), childShape.getAnchors().get(0));
- }
- if (obj instanceof SPPRef) {
- ifitem2anchor.put(acr.getName()+SEP+((SPPRef)obj).getName(), childShape.getAnchors().get(0));
- }
- }
- }
- }
- }
- }
- }
-
- public static void addRefItem(ActorContainerRef obj, ContainerShape acShape, int x, int y, IFeatureProvider featureProvider, final Map<String, Anchor> ifitem2anchor) {
- AddContext addContext = new AddContext();
- addContext.setNewObject(obj);
- addContext.setTargetContainer(acShape);
- addContext.setX(x);
- addContext.setY(y);
-
- ContainerShape refShape = (ContainerShape) featureProvider.addIfPossible(addContext);
-
- SupportUtil.getAnchors(obj, refShape, ifitem2anchor);
- }
-
- public static void addInterfaceItem(InterfaceItem item, ContainerShape acShape, int x, int y, IFeatureProvider featureProvider, final Map<String, Anchor> ifitem2anchor) {
- AddContext addContext = new AddContext();
- addContext.setNewObject(item);
- addContext.setTargetContainer(acShape);
- addContext.setX(x);
- addContext.setY(y);
-
- ContainerShape pe = (ContainerShape) featureProvider.addIfPossible(addContext);
- assert(!pe.getAnchors().isEmpty()): "interface item should have an anchor";
- ifitem2anchor.put(SEP+item.getName(), pe.getAnchors().get(0));
- }
-
- public static void addBinding(Binding bind, IFeatureProvider featureProvider,
- final Map<String, Anchor> ifitem2anchor) {
- String ep1 = getName(bind.getEndpoint1());
- String ep2 = getName(bind.getEndpoint2());
- Anchor a1 = ifitem2anchor.get(ep1);
- Anchor a2 = ifitem2anchor.get(ep2);
- assert(a1!=null && a2!=null): "ports for binding must be present";
-
- AddConnectionContext context = new AddConnectionContext(a1, a2);
- context.setNewObject(bind);
- featureProvider.addIfPossible(context);
- }
-
- public static void addLayerConnection(LayerConnection lc, IFeatureProvider featureProvider,
- final Map<String, Anchor> ifitem2anchor) {
- String ep1 = getName(lc.getFrom());
- String ep2 = getName(lc.getTo());
- Anchor a1 = ifitem2anchor.get(ep1);
- Anchor a2 = ifitem2anchor.get(ep2);
- assert(a1!=null && a2!=null): "spps for layer connection must be present";
-
- AddConnectionContext context = new AddConnectionContext(a1, a2);
- context.setNewObject(lc);
- featureProvider.addIfPossible(context);
- }
-
- public static void addInterfaceItems(List<? extends InterfaceItem> items, int y, ContainerShape acShape, int width,
- IFeatureProvider fp,
- final Map<String, Anchor> ifitem2anchor) {
-
- int n = items.size();
- int delta = width/(n+1);
- int pos = delta;
- for (InterfaceItem item : items) {
- SupportUtil.addInterfaceItem(item, acShape, pos+StructureClassSupport.MARGIN, y, fp, ifitem2anchor);
- pos += delta;
- }
- }
-
- public static void addRefItems(List<? extends ActorContainerRef> actorRefs,
- ContainerShape acShape, int width,
- IFeatureProvider fp, final Map<String, Anchor> ifitem2anchor) {
- int ncols = width/ActorContainerRefSupport.DEFAULT_SIZE_X;
- int nrows = actorRefs.size()/ncols;
- int gap = (width-(ncols*ActorContainerRefSupport.DEFAULT_SIZE_X))/(ncols+1);
- int delta = gap+ActorContainerRefSupport.DEFAULT_SIZE_X;
- int x0 = gap+ActorContainerRefSupport.DEFAULT_SIZE_X/2;
- int y0 = ActorContainerRefSupport.DEFAULT_SIZE_Y*5/2;
- int i = 0;
- for (ActorContainerRef ar : actorRefs) {
- int row = i/ncols;
- int col = i%ncols;
- if (row>=nrows) {
- int nc = actorRefs.size()%ncols;
- gap = (width-(nc*ActorContainerRefSupport.DEFAULT_SIZE_X))/(nc+1);
- delta = gap+ActorContainerRefSupport.DEFAULT_SIZE_X;
- x0 = gap+ActorContainerRefSupport.DEFAULT_SIZE_X/2;
- }
- int x = x0+delta*col;
- int y = y0+(ActorContainerRefSupport.MARGIN+ActorContainerRefSupport.DEFAULT_SIZE_Y)*row;
- SupportUtil.addRefItem(ar, acShape, x+StructureClassSupport.MARGIN, y+StructureClassSupport.MARGIN, fp, ifitem2anchor);
- ++i;
- }
- }
-
- public static String getName(BindingEndPoint ep) {
- String ar = ep.getActorRef()==null? "":ep.getActorRef().getName();
- String p = ep.getPort().getName();
- return ar+SEP+p;
- }
-
- public static String getName(SAPoint sapt) {
- if (sapt instanceof RelaySAPoint) {
- return SEP+((RelaySAPoint)sapt).getRelay().getName();
- }
- else if (sapt instanceof RefSAPoint) {
- RefSAPoint rpt = (RefSAPoint) sapt;
- return rpt.getRef().getName()+SEP;
- }
- assert(false): "unexpected sub type";
- return null;
- }
-
- public static String getName(SPPoint sppt) {
- return sppt.getRef().getName()+SEP+sppt.getService().getName();
- }
-
- public static List<InterfaceItem> getInterfaceItems(ContainerShape shape, IFeatureProvider fp) {
- return getInterfaceItems(shape, fp, null);
- }
-
- public static List<InterfaceItem> getInterfaceItems(ContainerShape shape, IFeatureProvider fp, Map<String, Anchor> ifitem2anchor) {
- List<InterfaceItem> items = new ArrayList<InterfaceItem>();
- for (Shape ch : shape.getChildren()) {
- Object bo = fp.getBusinessObjectForPictogramElement(ch);
- if (bo instanceof InterfaceItem) {
- items.add((InterfaceItem)bo);
- if (ifitem2anchor!=null)
- ifitem2anchor.put(SEP+((InterfaceItem)bo).getName(), ch.getAnchors().get(0));
- }
- }
- return items;
- }
-
- public static List<ActorContainerRef> getRefs(ContainerShape shape, IFeatureProvider fp) {
- return getRefs(shape, fp, null);
- }
-
- public static List<ActorContainerRef> getRefs(ContainerShape shape, IFeatureProvider fp, Map<String, Anchor> ifitem2anchor) {
- List<ActorContainerRef> refs = new ArrayList<ActorContainerRef>();
- for (Shape ch : shape.getChildren()) {
- Object bo = fp.getBusinessObjectForPictogramElement(ch);
- if (bo instanceof ActorContainerRef) {
- refs.add((ActorContainerRef)bo);
- if (ifitem2anchor!=null)
- getAnchors((ActorContainerRef)bo, ch, ifitem2anchor);
- }
- }
- return refs;
- }
-
- public static List<Binding> getBindings(Diagram diag, IFeatureProvider fp) {
- List<Binding> bindings = new ArrayList<Binding>();
-
- for (Connection conn : diag.getConnections()) {
- Object bo = fp.getBusinessObjectForPictogramElement(conn);
- if (bo instanceof Binding)
- bindings.add((Binding)bo);
- }
- return bindings;
- }
-
- public static List<LayerConnection> getConnections(Diagram diag, IFeatureProvider fp) {
- List<LayerConnection> bindings = new ArrayList<LayerConnection>();
-
- for (Connection conn : diag.getConnections()) {
- Object bo = fp.getBusinessObjectForPictogramElement(conn);
- if (bo instanceof LayerConnection)
- bindings.add((LayerConnection)bo);
- }
- return bindings;
- }
-
- public static StructureClass getParent(ICreateConnectionContext context, IFeatureProvider fp) {
- ContainerShape shape = (ContainerShape) context.getSourcePictogramElement().eContainer();
- return getParent(shape, fp);
- }
-
- public static StructureClass getParent(ContainerShape shape, IFeatureProvider fp) {
- Object bo = fp.getBusinessObjectForPictogramElement(shape);
- if (bo instanceof StructureClass)
- return (StructureClass) bo;
-
- shape = (ContainerShape) shape.eContainer();
- bo = fp.getBusinessObjectForPictogramElement(shape);
- if (bo instanceof StructureClass)
- return (StructureClass) bo;
-
- return null;
- }
-
- public static Port getPort(Anchor anchor, IFeatureProvider fp) {
- if (anchor != null) {
- Object obj = fp.getBusinessObjectForPictogramElement(anchor.getParent());
- if (obj instanceof Port) {
- return (Port) obj;
- }
- }
- return null;
- }
-
- public static SPPRef getSPPRef(Anchor anchor, IFeatureProvider fp) {
- if (anchor != null) {
- Object obj = fp.getBusinessObjectForPictogramElement(anchor.getParent());
- if (obj instanceof SPPRef) {
- return (SPPRef) obj;
- }
- }
- return null;
- }
-
- public static ActorContainerRef getRef(Anchor anchor, IFeatureProvider fp) {
- if (anchor != null) {
- ContainerShape shape = (ContainerShape) anchor.getParent().eContainer();
- Object bo = fp.getBusinessObjectForPictogramElement(shape);
- if (bo instanceof ActorContainerRef)
- return (ActorContainerRef) bo;
- shape = (ContainerShape) anchor.getParent();
- bo = fp.getBusinessObjectForPictogramElement(shape);
- if (bo instanceof ActorContainerRef)
- return (ActorContainerRef) bo;
- }
- return null;
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.structure.support;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.etrice.core.room.ActorContainerRef;
+import org.eclipse.etrice.core.room.Binding;
+import org.eclipse.etrice.core.room.BindingEndPoint;
+import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.etrice.core.room.LayerConnection;
+import org.eclipse.etrice.core.room.Port;
+import org.eclipse.etrice.core.room.RefSAPoint;
+import org.eclipse.etrice.core.room.RelaySAPoint;
+import org.eclipse.etrice.core.room.SAPoint;
+import org.eclipse.etrice.core.room.SPPRef;
+import org.eclipse.etrice.core.room.SPPoint;
+import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ICreateConnectionContext;
+import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
+import org.eclipse.graphiti.features.context.impl.AddContext;
+import org.eclipse.graphiti.mm.pictograms.Anchor;
+import org.eclipse.graphiti.mm.pictograms.Connection;
+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.mm.pictograms.Shape;
+
+/**
+ * description
+ *
+ * @author Henrik Rentz-Reichert initial contribution and API
+ *
+ */
+public class SupportUtil {
+
+ public static final String SEP = "#";
+
+ public static EObject getOwnObject(EObject obj, ResourceSet rs) {
+ URI uri = EcoreUtil.getURI(obj);
+ EObject own = rs.getEObject(uri, true);
+ assert(own!=null): "own object must exist";
+ return own;
+ }
+
+ public static ContainerShape addItem(EObject obj, int x, int y, ContainerShape container, IFeatureProvider fp) {
+ return addItem(obj, x, y, container, null, fp);
+ }
+
+ public static ContainerShape addItem(EObject obj, int x, int y, ContainerShape container, Map<String,Anchor> ifitem2anchor, IFeatureProvider fp) {
+ AddContext addContext = new AddContext();
+
+ addContext.setNewObject(obj);
+ addContext.setTargetContainer(container);
+ addContext.setX(x);
+ addContext.setY(y);
+ ContainerShape newShape = (ContainerShape) fp.addIfPossible(addContext);
+ assert(newShape!=null): "shape creation must succeed";
+
+ if (ifitem2anchor!=null) {
+ if (obj instanceof ActorContainerRef)
+ getAnchors((ActorContainerRef)obj, newShape, ifitem2anchor);
+ else if (obj instanceof InterfaceItem) {
+ assert(!newShape.getAnchors().isEmpty()): "interface item must have an anchor";
+ ifitem2anchor.put(SEP+((InterfaceItem)obj).getName(), newShape.getAnchors().get(0));
+ }
+ }
+
+ return newShape;
+ }
+
+ public static void getAnchors(ActorContainerRef acr, PictogramElement refShape,
+ final Map<String, Anchor> ifitem2anchor) {
+
+ if (refShape instanceof ContainerShape) {
+ ifitem2anchor.put(acr.getName()+SEP, ((ContainerShape)refShape).getAnchors().get(0));
+ for (Shape child : ((ContainerShape) refShape).getChildren()) {
+ if (child instanceof ContainerShape) {
+ ContainerShape childShape = (ContainerShape) child;
+ if (!childShape.getAnchors().isEmpty()) {
+ if (!childShape.getLink().getBusinessObjects().isEmpty()) {
+ EObject obj = childShape.getLink().getBusinessObjects().get(0);
+ if (obj instanceof Port) {
+ ifitem2anchor.put(acr.getName()+SEP+((Port)obj).getName(), childShape.getAnchors().get(0));
+ }
+ if (obj instanceof SPPRef) {
+ ifitem2anchor.put(acr.getName()+SEP+((SPPRef)obj).getName(), childShape.getAnchors().get(0));
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public static void addRefItem(ActorContainerRef obj, ContainerShape acShape, int x, int y, IFeatureProvider featureProvider, final Map<String, Anchor> ifitem2anchor) {
+ AddContext addContext = new AddContext();
+ addContext.setNewObject(obj);
+ addContext.setTargetContainer(acShape);
+ addContext.setX(x);
+ addContext.setY(y);
+
+ ContainerShape refShape = (ContainerShape) featureProvider.addIfPossible(addContext);
+
+ SupportUtil.getAnchors(obj, refShape, ifitem2anchor);
+ }
+
+ public static void addInterfaceItem(InterfaceItem item, ContainerShape acShape, int x, int y, IFeatureProvider featureProvider, final Map<String, Anchor> ifitem2anchor) {
+ AddContext addContext = new AddContext();
+ addContext.setNewObject(item);
+ addContext.setTargetContainer(acShape);
+ addContext.setX(x);
+ addContext.setY(y);
+
+ ContainerShape pe = (ContainerShape) featureProvider.addIfPossible(addContext);
+ assert(!pe.getAnchors().isEmpty()): "interface item should have an anchor";
+ ifitem2anchor.put(SEP+item.getName(), pe.getAnchors().get(0));
+ }
+
+ public static void addBinding(Binding bind, IFeatureProvider featureProvider,
+ final Map<String, Anchor> ifitem2anchor) {
+ String ep1 = getName(bind.getEndpoint1());
+ String ep2 = getName(bind.getEndpoint2());
+ Anchor a1 = ifitem2anchor.get(ep1);
+ Anchor a2 = ifitem2anchor.get(ep2);
+ assert(a1!=null && a2!=null): "ports for binding must be present";
+
+ AddConnectionContext context = new AddConnectionContext(a1, a2);
+ context.setNewObject(bind);
+ featureProvider.addIfPossible(context);
+ }
+
+ public static void addLayerConnection(LayerConnection lc, IFeatureProvider featureProvider,
+ final Map<String, Anchor> ifitem2anchor) {
+ String ep1 = getName(lc.getFrom());
+ String ep2 = getName(lc.getTo());
+ Anchor a1 = ifitem2anchor.get(ep1);
+ Anchor a2 = ifitem2anchor.get(ep2);
+ assert(a1!=null && a2!=null): "spps for layer connection must be present";
+
+ AddConnectionContext context = new AddConnectionContext(a1, a2);
+ context.setNewObject(lc);
+ featureProvider.addIfPossible(context);
+ }
+
+ public static void addInterfaceItems(List<? extends InterfaceItem> items, int y, ContainerShape acShape, int width,
+ IFeatureProvider fp,
+ final Map<String, Anchor> ifitem2anchor) {
+
+ int n = items.size();
+ int delta = width/(n+1);
+ int pos = delta;
+ for (InterfaceItem item : items) {
+ SupportUtil.addInterfaceItem(item, acShape, pos+StructureClassSupport.MARGIN, y, fp, ifitem2anchor);
+ pos += delta;
+ }
+ }
+
+ public static void addRefItems(List<? extends ActorContainerRef> actorRefs,
+ ContainerShape acShape, int width,
+ IFeatureProvider fp, final Map<String, Anchor> ifitem2anchor) {
+ int ncols = width/ActorContainerRefSupport.DEFAULT_SIZE_X;
+ int nrows = actorRefs.size()/ncols;
+ int gap = (width-(ncols*ActorContainerRefSupport.DEFAULT_SIZE_X))/(ncols+1);
+ int delta = gap+ActorContainerRefSupport.DEFAULT_SIZE_X;
+ int x0 = gap+ActorContainerRefSupport.DEFAULT_SIZE_X/2;
+ int y0 = ActorContainerRefSupport.DEFAULT_SIZE_Y*5/2;
+ int i = 0;
+ for (ActorContainerRef ar : actorRefs) {
+ int row = i/ncols;
+ int col = i%ncols;
+ if (row>=nrows) {
+ int nc = actorRefs.size()%ncols;
+ gap = (width-(nc*ActorContainerRefSupport.DEFAULT_SIZE_X))/(nc+1);
+ delta = gap+ActorContainerRefSupport.DEFAULT_SIZE_X;
+ x0 = gap+ActorContainerRefSupport.DEFAULT_SIZE_X/2;
+ }
+ int x = x0+delta*col;
+ int y = y0+(ActorContainerRefSupport.MARGIN+ActorContainerRefSupport.DEFAULT_SIZE_Y)*row;
+ SupportUtil.addRefItem(ar, acShape, x+StructureClassSupport.MARGIN, y+StructureClassSupport.MARGIN, fp, ifitem2anchor);
+ ++i;
+ }
+ }
+
+ public static String getName(BindingEndPoint ep) {
+ String ar = ep.getActorRef()==null? "":ep.getActorRef().getName();
+ String p = ep.getPort().getName();
+ return ar+SEP+p;
+ }
+
+ public static String getName(SAPoint sapt) {
+ if (sapt instanceof RelaySAPoint) {
+ return SEP+((RelaySAPoint)sapt).getRelay().getName();
+ }
+ else if (sapt instanceof RefSAPoint) {
+ RefSAPoint rpt = (RefSAPoint) sapt;
+ return rpt.getRef().getName()+SEP;
+ }
+ assert(false): "unexpected sub type";
+ return null;
+ }
+
+ public static String getName(SPPoint sppt) {
+ return sppt.getRef().getName()+SEP+sppt.getService().getName();
+ }
+
+ public static List<InterfaceItem> getInterfaceItems(ContainerShape shape, IFeatureProvider fp) {
+ return getInterfaceItems(shape, fp, null);
+ }
+
+ public static List<InterfaceItem> getInterfaceItems(ContainerShape shape, IFeatureProvider fp, Map<String, Anchor> ifitem2anchor) {
+ List<InterfaceItem> items = new ArrayList<InterfaceItem>();
+ for (Shape ch : shape.getChildren()) {
+ Object bo = fp.getBusinessObjectForPictogramElement(ch);
+ if (bo instanceof InterfaceItem) {
+ items.add((InterfaceItem)bo);
+ if (ifitem2anchor!=null)
+ ifitem2anchor.put(SEP+((InterfaceItem)bo).getName(), ch.getAnchors().get(0));
+ }
+ }
+ return items;
+ }
+
+ public static List<ActorContainerRef> getRefs(ContainerShape shape, IFeatureProvider fp) {
+ return getRefs(shape, fp, null);
+ }
+
+ public static List<ActorContainerRef> getRefs(ContainerShape shape, IFeatureProvider fp, Map<String, Anchor> ifitem2anchor) {
+ List<ActorContainerRef> refs = new ArrayList<ActorContainerRef>();
+ for (Shape ch : shape.getChildren()) {
+ Object bo = fp.getBusinessObjectForPictogramElement(ch);
+ if (bo instanceof ActorContainerRef) {
+ refs.add((ActorContainerRef)bo);
+ if (ifitem2anchor!=null)
+ getAnchors((ActorContainerRef)bo, ch, ifitem2anchor);
+ }
+ }
+ return refs;
+ }
+
+ public static List<Binding> getBindings(Diagram diag, IFeatureProvider fp) {
+ List<Binding> bindings = new ArrayList<Binding>();
+
+ for (Connection conn : diag.getConnections()) {
+ Object bo = fp.getBusinessObjectForPictogramElement(conn);
+ if (bo instanceof Binding)
+ bindings.add((Binding)bo);
+ }
+ return bindings;
+ }
+
+ public static List<LayerConnection> getConnections(Diagram diag, IFeatureProvider fp) {
+ List<LayerConnection> bindings = new ArrayList<LayerConnection>();
+
+ for (Connection conn : diag.getConnections()) {
+ Object bo = fp.getBusinessObjectForPictogramElement(conn);
+ if (bo instanceof LayerConnection)
+ bindings.add((LayerConnection)bo);
+ }
+ return bindings;
+ }
+
+ public static StructureClass getParent(ICreateConnectionContext context, IFeatureProvider fp) {
+ ContainerShape shape = (ContainerShape) context.getSourcePictogramElement().eContainer();
+ return getParent(shape, fp);
+ }
+
+ public static StructureClass getParent(ContainerShape shape, IFeatureProvider fp) {
+ Object bo = fp.getBusinessObjectForPictogramElement(shape);
+ if (bo instanceof StructureClass)
+ return (StructureClass) bo;
+
+ shape = (ContainerShape) shape.eContainer();
+ bo = fp.getBusinessObjectForPictogramElement(shape);
+ if (bo instanceof StructureClass)
+ return (StructureClass) bo;
+
+ return null;
+ }
+
+ public static Port getPort(Anchor anchor, IFeatureProvider fp) {
+ if (anchor != null) {
+ Object obj = fp.getBusinessObjectForPictogramElement(anchor.getParent());
+ if (obj instanceof Port) {
+ return (Port) obj;
+ }
+ }
+ return null;
+ }
+
+ public static SPPRef getSPPRef(Anchor anchor, IFeatureProvider fp) {
+ if (anchor != null) {
+ Object obj = fp.getBusinessObjectForPictogramElement(anchor.getParent());
+ if (obj instanceof SPPRef) {
+ return (SPPRef) obj;
+ }
+ }
+ return null;
+ }
+
+ public static ActorContainerRef getRef(Anchor anchor, IFeatureProvider fp) {
+ if (anchor != null) {
+ ContainerShape shape = (ContainerShape) anchor.getParent().eContainer();
+ Object bo = fp.getBusinessObjectForPictogramElement(shape);
+ if (bo instanceof ActorContainerRef)
+ return (ActorContainerRef) bo;
+ shape = (ContainerShape) anchor.getParent();
+ bo = fp.getBusinessObjectForPictogramElement(shape);
+ if (bo instanceof ActorContainerRef)
+ return (ActorContainerRef) bo;
+ }
+ return null;
+ }
+}

Back to the top