Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/sysml')
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/META-INF/MANIFEST.MF127
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/messages.properties21
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/plugin.xml26
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/handler/BlockDefinitionManageInterfacesHandler.java38
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/handler/ManageProvidedInterfacesHandler.java121
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/messages/Messages.java86
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/ui/BlockDefinitionInterfaceManagerDialog.java82
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/ui/CreateUmlElementDialog.java434
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/ui/InterfaceManagerDialog.java1040
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/ui/NewElementRepresentation.java172
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/META-INF/MANIFEST.MF50
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/messages.properties27
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/plugin.xml2
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/handler/InternalBlockManageInterfacesHandler.java46
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/handler/ManageProvidedInterfacesHandler.java119
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/messages/Messages.java94
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/ui/CreateUmlElementDialog.java433
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/ui/InterfaceManagerDialog.java1008
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/ui/InternalBlockInterfaceManagerDialog.java76
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/ui/NewElementRepresentation.java172
20 files changed, 411 insertions, 3763 deletions
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/META-INF/MANIFEST.MF b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/META-INF/MANIFEST.MF
index 707ea91c2ab..78f89b83f5c 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/META-INF/MANIFEST.MF
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/META-INF/MANIFEST.MF
@@ -1,65 +1,62 @@
-Manifest-Version: 1.0
-Export-Package: org.eclipse.papyrus.sysml.diagram.blockdefinition,
- org.eclipse.papyrus.sysml.diagram.blockdefinition.command,
- org.eclipse.papyrus.sysml.diagram.blockdefinition.dnd.helper,
- org.eclipse.papyrus.sysml.diagram.blockdefinition.edit.part,
- org.eclipse.papyrus.sysml.diagram.blockdefinition.edit.policy,
- org.eclipse.papyrus.sysml.diagram.blockdefinition.factory,
- org.eclipse.papyrus.sysml.diagram.blockdefinition.handler,
- org.eclipse.papyrus.sysml.diagram.blockdefinition.helper.advice,
- org.eclipse.papyrus.sysml.diagram.blockdefinition.messages,
- org.eclipse.papyrus.sysml.diagram.blockdefinition.part,
- org.eclipse.papyrus.sysml.diagram.blockdefinition.preferences,
- org.eclipse.papyrus.sysml.diagram.blockdefinition.provider,
- org.eclipse.papyrus.sysml.diagram.blockdefinition.ui,
- org.eclipse.papyrus.sysml.diagram.blockdefinition.utils
-Require-Bundle: org.eclipse.ui,
- org.eclipse.core.runtime,
- org.eclipse.papyrus.sysml;bundle-version="1.0.0",
- org.eclipse.papyrus.uml.diagram.common;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="1.0.0",
- org.eclipse.emf.common.ui;bundle-version="2.5.0",
- org.eclipse.gmf.runtime.diagram.ui.resources.editor;bundle-version="1.2.0",
- org.eclipse.papyrus.uml.diagram.clazz;bundle-version="1.0.0",
- org.eclipse.gmf.runtime.diagram.ui.providers;bundle-version="1.3.0",
- org.eclipse.core.expressions;bundle-version="3.4.100",
- org.eclipse.papyrus.infra.gmfdiag.preferences;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.widgets;bundle-version="1.0.0",
- org.eclipse.papyrus.sysml.diagram.common;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.services.edit;bundle-version="1.0.0",
- org.eclipse.papyrus.uml.service.types;bundle-version="1.0.0",
- org.eclipse.papyrus.sysml.service.types;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.widgets.toolbox;bundle-version="1.0.0",
- org.eclipse.gmf.runtime.notation;bundle-version="1.5.0",
- org.eclipse.gmf.runtime.diagram.core;bundle-version="1.4.1",
- org.eclipse.draw2d;bundle-version="3.7.1",
- org.eclipse.gef;bundle-version="3.7.1",
- org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.5.0",
- org.eclipse.papyrus.uml.tools;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.core;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.core.log;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.core.sasheditor;bundle-version="1.0.0",
- org.eclipse.papyrus.uml.tools.utils;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.gmfdiag.navigation;bundle-version="1.0.0",
- org.eclipse.ui.ide;bundle-version="3.8.0",
- org.eclipse.papyrus.infra.emf;bundle-version="1.0.0",
- org.eclipse.uml2.uml;bundle-version="4.0.0",
- org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.0.0",
- org.eclipse.gmf.tooling.runtime;bundle-version="3.1.0",
- org.eclipse.papyrus.infra.tools;bundle-version="1.0.0",
- org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.0.0",
- org.eclipse.papyrus.emf.facet.custom.core;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.viewpoints.configuration;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.extendedtypes;bundle-version="1.0.0"
-Bundle-Vendor: %providerName
-Bundle-ActivationPolicy: lazy
-Bundle-Version: 1.0.0.qualifier
-Bundle-Localization: plugin
-Bundle-Name: %pluginName
-Bundle-Activator: org.eclipse.papyrus.sysml.diagram.blockdefinition.Activator
-Bundle-ManifestVersion: 2
-Bundle-SymbolicName: org.eclipse.papyrus.sysml.diagram.blockdefinition;singleton:=true
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
-
+Manifest-Version: 1.0
+Export-Package: org.eclipse.papyrus.sysml.diagram.blockdefinition,
+ org.eclipse.papyrus.sysml.diagram.blockdefinition.command,
+ org.eclipse.papyrus.sysml.diagram.blockdefinition.dnd.helper,
+ org.eclipse.papyrus.sysml.diagram.blockdefinition.edit.part,
+ org.eclipse.papyrus.sysml.diagram.blockdefinition.edit.policy,
+ org.eclipse.papyrus.sysml.diagram.blockdefinition.factory,
+ org.eclipse.papyrus.sysml.diagram.blockdefinition.helper.advice,
+ org.eclipse.papyrus.sysml.diagram.blockdefinition.messages,
+ org.eclipse.papyrus.sysml.diagram.blockdefinition.part,
+ org.eclipse.papyrus.sysml.diagram.blockdefinition.preferences,
+ org.eclipse.papyrus.sysml.diagram.blockdefinition.provider,
+ org.eclipse.papyrus.sysml.diagram.blockdefinition.ui,
+ org.eclipse.papyrus.sysml.diagram.blockdefinition.utils
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.papyrus.sysml;bundle-version="1.0.0",
+ org.eclipse.papyrus.uml.diagram.common;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="1.0.0",
+ org.eclipse.emf.common.ui;bundle-version="2.5.0",
+ org.eclipse.gmf.runtime.diagram.ui.resources.editor;bundle-version="1.2.0",
+ org.eclipse.papyrus.uml.diagram.clazz;bundle-version="1.0.0",
+ org.eclipse.gmf.runtime.diagram.ui.providers;bundle-version="1.3.0",
+ org.eclipse.core.expressions;bundle-version="3.4.100",
+ org.eclipse.papyrus.infra.gmfdiag.preferences;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.widgets;bundle-version="1.0.0",
+ org.eclipse.papyrus.sysml.diagram.common;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.services.edit;bundle-version="1.0.0",
+ org.eclipse.papyrus.uml.service.types;bundle-version="1.0.0",
+ org.eclipse.papyrus.sysml.service.types;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.widgets.toolbox;bundle-version="1.0.0",
+ org.eclipse.gmf.runtime.notation;bundle-version="1.5.0",
+ org.eclipse.gmf.runtime.diagram.core;bundle-version="1.4.1",
+ org.eclipse.draw2d;bundle-version="3.7.1",
+ org.eclipse.gef;bundle-version="3.7.1",
+ org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.5.0",
+ org.eclipse.papyrus.uml.tools;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.core;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.core.log;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.core.sasheditor;bundle-version="1.0.0",
+ org.eclipse.papyrus.uml.tools.utils;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.gmfdiag.navigation;bundle-version="1.0.0",
+ org.eclipse.ui.ide;bundle-version="3.8.0",
+ org.eclipse.papyrus.infra.emf;bundle-version="1.0.0",
+ org.eclipse.uml2.uml;bundle-version="4.0.0",
+ org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.0.0",
+ org.eclipse.gmf.tooling.runtime;bundle-version="3.1.0",
+ org.eclipse.papyrus.infra.tools;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.viewpoints.configuration;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.extendedtypes;bundle-version="1.0.0"
+Bundle-Vendor: %providerName
+Bundle-ActivationPolicy: lazy
+Bundle-Version: 1.0.0.qualifier
+Bundle-Localization: plugin
+Bundle-Name: %pluginName
+Bundle-Activator: org.eclipse.papyrus.sysml.diagram.blockdefinition.Activator
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: org.eclipse.papyrus.sysml.diagram.blockdefinition;singleton:=true
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/messages.properties b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/messages.properties
index dffb67cc8ee..0fbb20aa31b 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/messages.properties
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/messages.properties
@@ -1,21 +1,2 @@
-CreateUmlElementDialog_New_Element_Name=New Element Name
-InterfaceManagerDialog_CreateANewInterface=Create a new Interface
-InterfaceManagerDialog_CreateNewInterface=Create new Interface
-InterfaceManagerDialog_SelectedTheProvidedInterfaces=Select the provided Interfaces
-InterfaceManagerDialog_SelectionHasToBeAPackageOrAClassifier=Selection has to be a Package or a Classifier
-InterfaceManagerDialog_SelectTheParentOfThisNewInterface=Select the parent of this new Interface
-InterfaceManagerDialog_SelectTheRequiredInterfaces=Select the required Interfaces
-InterfaceManagerDialog_ThePortIsTypedWithAnInterfaceWarningMessage=\nThe managed port is typed with an Interface, so this interface is not available as a provided Interface.\n
-InterfaceManagerDialog_Title=Select the provided and the required Interfaces
-ManageProvidedInterfacesHandler_OK=OK
-ManageProvidedInterfacesHandler_TheTypeOfThePortIsNotDefined=The type of the Port (should be a Block) is not defined. You need to define it before managing its Interfaces.
-SelectionValidated=Selection validated.
-NoSelectionFound=No selection found.
-
-ManageProvidedInterfacesHandler_OK=OK
-ManageProvidedInterfacesHandler_TheTypeOfThePortIsNotDefined=The type of the Port (should be a Block) is not defined. You need to define it before managing its Interfaces.
-SelectionValidated=Selection validated.
-NoSelectionFound=No selection found.
-
-Notification_Drop_Title=Drop in diagram
+Notification_Drop_Title=Drop in diagram
Notification_Drop_UMLAssociationWarning=The Association ({0}) can not be dropped in this diagram because it is not a SysML Association.\nIt was probably not created in a SysML Diagram. \ No newline at end of file
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/plugin.xml b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/plugin.xml
index ff866954efe..410f1b4a6b4 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/plugin.xml
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/plugin.xml
@@ -970,10 +970,10 @@
</extension>
-<!-- // Start of user code custom extensions
- -->
-
-<!-- Insert custom extensions here. -->
+<!-- // Start of user code custom extensions
+ -->
+
+<!-- Insert custom extensions here. -->
<!-- Palette tool declaration (declares the real palette containment) -->
<extension point="org.eclipse.papyrus.uml.diagram.common.paletteDefinition"
@@ -1032,8 +1032,8 @@
<!-- Specify diagram this palette tools relate to -->
<editor id="org.eclipse.papyrus.sysml.diagram.blockdefinition"/>
- </paletteDefinition>
-</extension>
+ </paletteDefinition>
+</extension>
<!-- Palette tool declaration (declares the real palette containment) -->
<extension point="org.eclipse.papyrus.uml.diagram.common.paletteDefinition"
@@ -1050,12 +1050,12 @@
</paletteDefinition>
</extension>
-<!-- Parser provider declaration -->
-<extension point="org.eclipse.gmf.runtime.common.ui.services.parserProviders">
- <ParserProvider class="org.eclipse.papyrus.sysml.diagram.blockdefinition.provider.ParserProvider">
- <Priority name="Low"/>
- </ParserProvider>
-</extension>
+<!-- Parser provider declaration -->
+<extension point="org.eclipse.gmf.runtime.common.ui.services.parserProviders">
+ <ParserProvider class="org.eclipse.papyrus.sysml.diagram.blockdefinition.provider.ParserProvider">
+ <Priority name="Low"/>
+ </ParserProvider>
+</extension>
<!-- Validation markers declaration -->
<extension point="org.eclipse.gmf.runtime.common.ui.services.markerNavigationProviders" id="markers-navigation">
@@ -1093,7 +1093,7 @@
<extension
point="org.eclipse.ui.handlers">
<handler
- class="org.eclipse.papyrus.sysml.diagram.blockdefinition.handler.ManageProvidedInterfacesHandler"
+ class="org.eclipse.papyrus.sysml.diagram.blockdefinition.handler.BlockDefinitionManageInterfacesHandler"
commandId="org.eclipse.papyrus.sysml.diagram.blockdefinition.command.manage.interfaces">
<activeWhen>
<and>
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/handler/BlockDefinitionManageInterfacesHandler.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/handler/BlockDefinitionManageInterfacesHandler.java
new file mode 100644
index 00000000000..77465458c44
--- /dev/null
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/handler/BlockDefinitionManageInterfacesHandler.java
@@ -0,0 +1,38 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.sysml.diagram.blockdefinition.handler;
+
+import org.eclipse.gmf.runtime.common.ui.util.DisplayUtils;
+import org.eclipse.papyrus.sysml.diagram.blockdefinition.ui.BlockDefinitionInterfaceManagerDialog;
+import org.eclipse.papyrus.uml.diagram.common.actions.handlers.ManagePortInterfacesHandler;
+import org.eclipse.papyrus.uml.diagram.common.dialogs.InterfaceManagerDialog;
+import org.eclipse.uml2.uml.Port;
+
+/**
+ * Manage Interface handler for Block Definition diagram.
+ *
+ * @author Gabriel Pascual
+ */
+public class BlockDefinitionManageInterfacesHandler extends ManagePortInterfacesHandler {
+
+ /**
+ * @see org.eclipse.papyrus.uml.diagram.common.actions.handlers.ManagePortInterfacesHandler#getInterfaceManagerDialog(org.eclipse.uml2.uml.Port)
+ *
+ * @param port
+ * @return
+ */
+ @Override
+ public InterfaceManagerDialog getInterfaceManagerDialog(Port port) {
+ return new BlockDefinitionInterfaceManagerDialog(DisplayUtils.getDefaultShell(), port);
+ }
+}
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/handler/ManageProvidedInterfacesHandler.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/handler/ManageProvidedInterfacesHandler.java
deleted file mode 100644
index 38304bdf99a..00000000000
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/handler/ManageProvidedInterfacesHandler.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.sysml.diagram.blockdefinition.handler;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.UnexecutableCommand;
-import org.eclipse.gmf.runtime.common.ui.util.DisplayUtils;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.papyrus.commands.wrappers.GEFtoEMFCommandWrapper;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
-import org.eclipse.papyrus.sysml.diagram.blockdefinition.messages.Messages;
-import org.eclipse.papyrus.sysml.diagram.blockdefinition.ui.InterfaceManagerDialog;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.Interface;
-import org.eclipse.uml2.uml.InterfaceRealization;
-import org.eclipse.uml2.uml.Port;
-import org.eclipse.uml2.uml.Type;
-import org.eclipse.uml2.uml.Usage;
-
-
-/**
- * <pre>
- * This handler provides the handler to manage the provided and required {@link Interface}
- * of a {@link Port} without graphically creating {@link InterfaceRealization} and
- * {@link Usage} relationships.
- * </pre>
- */
-public class ManageProvidedInterfacesHandler extends AbstractHandler {
-
- public Object execute(ExecutionEvent event) throws ExecutionException {
- ISelection selection = HandlerUtil.getCurrentSelection(event);
- if(selection.isEmpty()) {
- return null;
- }
-
- if(selection instanceof IStructuredSelection) {
- IStructuredSelection structuredSelection = (IStructuredSelection)selection;
- EObject selectedElement = EMFHelper.getEObject(structuredSelection.getFirstElement());
- if(selectedElement instanceof Port) {
- Port port = (Port)selectedElement;
- ManageProvidedInterfaceAction action = new ManageProvidedInterfaceAction(port);
- try {
- ServiceUtilsForEObject.getInstance().getTransactionalEditingDomain(port).getCommandStack().execute(new GEFtoEMFCommandWrapper(action.getCommand()));
- } catch (ServiceException ex) {
- throw new ExecutionException("An unexpected exception occurred", ex);
- }
- }
- }
-
- return null;
- }
-
- /**
- *
- * This class provides the action to manage the provided and required interfaces
- *
- *
- */
- public class ManageProvidedInterfaceAction {
-
- /** the {@link Port} */
- private Port port;
-
- /** the {@link Type} of the port */
- private Type type;
-
- /**
- *
- * Constructor.
- *
- * @param editpart
- * the editpart of the port
- */
- public ManageProvidedInterfaceAction(Port port) {
- this.port = port;
- this.type = port.getType();
- }
-
- /**
- * Returns the command to add/remove provided/required interfaces
- *
- * @return
- * the command to add/remove provided/required interfaces
- */
- public Command getCommand() {
- if(type != null && !(type instanceof Classifier)) {
- return UnexecutableCommand.INSTANCE;
- } else if(type == null) {
- MessageDialog dialog = new MessageDialog(DisplayUtils.getDefaultShell(), Messages.InterfaceManagerDialog_Title, null, Messages.ManageProvidedInterfacesHandler_TheTypeOfThePortIsNotDefined, MessageDialog.WARNING, new String[]{ Messages.ManageProvidedInterfacesHandler_OK }, 0);
- dialog.open();
- } else {
- InterfaceManagerDialog dialog = new InterfaceManagerDialog(DisplayUtils.getDefaultShell(), this.port);
- if(dialog.open() == Dialog.OK) {
- return dialog.getCommand();
- }
- }
- return UnexecutableCommand.INSTANCE;
- }
- }
-}
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/messages/Messages.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/messages/Messages.java
index e71a3dc66f9..e56007cb5ad 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/messages/Messages.java
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/messages/Messages.java
@@ -1,56 +1,30 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.sysml.diagram.blockdefinition.messages;
-
-import org.eclipse.osgi.util.NLS;
-
-public class Messages extends NLS {
-
- public static String CreateUmlElementDialog_New_Element_Name;
-
- public static String InterfaceManagerDialog_CreateANewInterface;
-
- public static String InterfaceManagerDialog_CreateNewInterface;
-
- public static String InterfaceManagerDialog_SelectedTheProvidedInterfaces;
-
- public static String InterfaceManagerDialog_SelectionHasToBeAPackageOrAClassifier;
-
- public static String InterfaceManagerDialog_SelectTheParentOfThisNewInterface;
-
- public static String InterfaceManagerDialog_SelectTheRequiredInterfaces;
-
- public static String InterfaceManagerDialog_ThePortIsTypedWithAnInterfaceWarningMessage;
-
- public static String InterfaceManagerDialog_Title;
-
- public static String ManageProvidedInterfacesHandler_OK;
-
- public static String ManageProvidedInterfacesHandler_TheTypeOfThePortIsNotDefined;
-
- public static String SelectionValidated;
-
- public static String NoSelectionFound;
-
- public static String Notification_Drop_Title;
-
- public static String Notification_Drop_UMLAssociationWarning;
-
- static {
- NLS.initializeMessages("messages", Messages.class); //$NON-NLS-1$
- }
-
- private Messages() {
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.sysml.diagram.blockdefinition.messages;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ public static String Notification_Drop_Title;
+
+ public static String Notification_Drop_UMLAssociationWarning;
+
+ static {
+ NLS.initializeMessages("messages", Messages.class); //$NON-NLS-1$
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/ui/BlockDefinitionInterfaceManagerDialog.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/ui/BlockDefinitionInterfaceManagerDialog.java
new file mode 100644
index 00000000000..76a96fba5ec
--- /dev/null
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/ui/BlockDefinitionInterfaceManagerDialog.java
@@ -0,0 +1,82 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.sysml.diagram.blockdefinition.ui;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.papyrus.sysml.portandflows.FlowSpecification;
+import org.eclipse.papyrus.uml.diagram.common.dialogs.InterfaceManagerDialog;
+import org.eclipse.papyrus.uml.diagram.common.util.Visitor;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Interface;
+import org.eclipse.uml2.uml.Namespace;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Port;
+import org.eclipse.uml2.uml.util.UMLUtil;
+
+/**
+ * <pre>
+ * This class provides a Dialog to manage easily the provided and
+ * the required Interfaces for a {@link Port}.
+ * </pre>
+ */
+public class BlockDefinitionInterfaceManagerDialog extends InterfaceManagerDialog {
+
+
+ /**
+ * Instantiates a new block definition interface manager dialog.
+ *
+ * @param parentShell
+ * the parent shell
+ * @param port
+ * the port
+ */
+ public BlockDefinitionInterfaceManagerDialog(Shell parentShell, Port port) {
+ super(parentShell, port);
+
+ }
+
+
+ /**
+ * Gets the all available interfaces.
+ *
+ * @param pack
+ * the pack
+ * @return the all available interfaces
+ * @see org.eclipse.papyrus.uml.diagram.common.dialogs.InterfaceManagerDialog#getAllAvailableInterfaces(org.eclipse.uml2.uml.Package)
+ */
+ protected List<Interface> getAllAvailableInterfaces(Package pack) {
+ Set<Interface> otherInterfaces = new HashSet<Interface>();
+ List<Element> interfaces = Visitor.getOwnedAndImportedElement(pack, Interface.class);
+ for(Namespace namespace : Visitor.getOwnedAndImportedNamespaces(pack)) {
+ interfaces.addAll(Visitor.getOwnedAndImportedElement(namespace, Interface.class));
+
+ }
+
+ for(Element element : interfaces) {
+ // Test if the interface is a FlowSpecification
+ FlowSpecification flowSpec = UMLUtil.getStereotypeApplication(element, FlowSpecification.class);
+ if(flowSpec == null) {
+ otherInterfaces.add((Interface)element);
+ }
+ }
+
+ return Arrays.asList(otherInterfaces.toArray(new Interface[otherInterfaces.size()]));
+ }
+
+
+}
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/ui/CreateUmlElementDialog.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/ui/CreateUmlElementDialog.java
deleted file mode 100644
index 0215eb996a8..00000000000
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/ui/CreateUmlElementDialog.java
+++ /dev/null
@@ -1,434 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
- *
- *
- * 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:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.sysml.diagram.blockdefinition.ui;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
-import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
-import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
-import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
-import org.eclipse.papyrus.sysml.diagram.blockdefinition.messages.Messages;
-import org.eclipse.papyrus.uml.diagram.common.util.Util;
-import org.eclipse.papyrus.uml.tools.utils.NamedElementUtil;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
-import org.eclipse.uml2.uml.Interface;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.Package;
-import org.eclipse.uml2.uml.UMLPackage;
-
-/**
- * This dialog allows to create easily a new element in a UML Model.
- */
-public class CreateUmlElementDialog extends ElementTreeSelectionDialog {
-
- /** the hinted type of the element to create. */
- private IHintedType hintedType;
-
- /** the parent container of the element to create. */
- private Object parentContainer;
-
- /** the type of the element to create. */
- private String type;
-
- /** the root of the model. */
- private Package pack;
-
- /** the text field used to display the choose the name of the future element. */
- private Text text;
-
- /** creation request. */
- private CreateElementRequest request;
-
- /** the editing domain. */
- private TransactionalEditingDomain domain;
-
- /** The element to create is represented by this field. */
- private NewElementRepresentation elementToCreate;
-
- /** this Set contains names to exclude from the proposed name. */
- private List<String> forbiddenNames;
-
-
-
-
- /**
- * Constructor.
- *
- * @param parent
- * the parent
- * @param domain
- * the domain
- * @param labelProvider
- * the label provider
- * @param contentProvider
- * the content provider
- * @param pack
- * the pack
- * @param hintedType
- * the hinted type
- */
- public CreateUmlElementDialog(Shell parent, TransactionalEditingDomain domain, ILabelProvider labelProvider, ITreeContentProvider contentProvider, Package pack, IHintedType hintedType) {
- super(parent, labelProvider, contentProvider);
- Assert.isNotNull(pack);
- Assert.isNotNull(hintedType);
- this.pack = pack;
- this.hintedType = hintedType;
- this.domain = domain;
- init();
- }
-
- /**
- * Initializes the field {@link #type};.
- */
- protected void init() {
- EClass eClass = hintedType.getEClass();
- this.type = eClass.getName();
- this.parentContainer = null;
- this.forbiddenNames = null;
- }
-
- /**
- * Sets the forbidden names.
- *
- * @param forbiddenNames
- * the new forbidden names
- */
- public void setForbiddenNames(List<String> forbiddenNames) {
- this.forbiddenNames = forbiddenNames;
- }
-
- /**
- * Creates the dialog area.
- *
- * @param parent
- * the parent
- * @return the control
- * @see org.eclipse.ui.dialogs.ElementTreeSelectionDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
- */
- @Override
- protected Control createDialogArea(Composite parent) {
-
- GridData data = (GridData)parent.getLayoutData();
- data.grabExcessHorizontalSpace = true;
- data.horizontalSpan = 1;
- data.horizontalAlignment = SWT.FILL;
- data.verticalAlignment = SWT.FILL;
- Composite composite = (Composite)super.createDialogArea(parent);
- composite.setLayout(new GridLayout());
- GridData dat = new GridData(GridData.FILL_BOTH);
- composite.setLayoutData(dat);
- createNameSection(parent);
-
- return composite;
- }
-
- /**
- * Creates the name section and put it at the top of the composite.
- *
- * @param parent
- * the composite parent
- */
- protected void createNameSection(Composite parent) {
-
- Composite nameSection = new Composite(parent, SWT.NONE);
-
- //the label
- Label label = new Label(nameSection, SWT.NONE);
- label.setText(Messages.CreateUmlElementDialog_New_Element_Name);
-
- //the text field
- text = new Text(nameSection, SWT.BORDER);
- text.setText(getDefaultName());
- GridData textData = new GridData(GridData.FILL_HORIZONTAL);
- text.setLayoutData(textData);
-
- //layout for the nameSection
- GridLayout layout = new GridLayout(2, false);
- GridData data = new GridData(GridData.FILL_BOTH);
- nameSection.setLayout(layout);
- nameSection.setLayoutData(data);
-
- //we set the name section in first!
- nameSection.moveAbove(null);
- }
-
- /**
- * Returns the default name for the new Element.
- *
- * @return the default name
- * the default name for the new Element
- */
- protected String getDefaultName() {
-
- boolean existsInterface = false;
- String defaultName;
- int max = 0;
- do {
-
- List<Interface> allInterface = Util.getInstancesFilteredByType(pack, Interface.class, null);
- for(Object object : allInterface) {
- String name = NamedElementUtil.getName((NamedElement)object);
- if(name != null && name.startsWith(type)) {
- name = name.substring(type.length());
- Integer val = null;
- try {
- val = Integer.parseInt(name);
- } catch (NumberFormatException e) {
- //Nothing to do
- }
- if(val != null) {
- max = Math.max(Integer.valueOf(val), max);
- existsInterface = true;
- }
- }
- }
- if(existsInterface) {
- defaultName = type + new Integer(max + 1).toString();
- } else {
- defaultName = type + new Integer(max).toString();
- }
- max++;
- } while(!isCorrectName(defaultName));
- return defaultName;
- }
-
- /**
- * Tests if the proposed name is not forbidden
- *
- * @param name
- * a name
- * @return
- * <code>true</code> if the proposed name is not forbidden
- */
- protected boolean isCorrectName(String name) {
- if(forbiddenNames == null) {
- return true;
- }
- return !forbiddenNames.contains(name);
- }
-
- /**
- * Returns the command to create the new element which the chosen name.
- *
- * @return the command
- * the command to create the new element which the chosen name
- */
- public Command getCommand() {
-
- CompositeCommand cmd = new CompositeCommand("Create new element command"); //$NON-NLS-1$
- //request to create the new Interface
- if(elementToCreate.getCreateElementRequest() != null) {
- ICommand command = getCommand(elementToCreate.getCreateElementRequest());
- if(command.canExecute()) {
- cmd.add(command);
- SetNameCommand nameCommand = new SetNameCommand(domain, "Set Name Command", null, request, elementToCreate); //$NON-NLS-1$
- if(nameCommand.canExecute()) {
- cmd.add(nameCommand);
- }
- }
- return new ICommandProxy(cmd);
- } else {
- return new ICommandProxy(new CustomCreateElementCommand(domain, "CustomCreateElementCommand", null, elementToCreate)); //$NON-NLS-1$
- }
- }
-
- /**
- * Compute result.
- *
- * @see org.eclipse.ui.dialogs.ElementTreeSelectionDialog#computeResult()
- */
- @Override
- protected void computeResult() {
- java.util.List<Object> result = new ArrayList<Object>();
- result.add(elementToCreate);
- setResult(result);
- }
-
- /**
- * Set the value to {@link #name} and {@link #parentContainer}.
- *
- * @see org.eclipse.ui.dialogs.SelectionStatusDialog#okPressed()
- */
- @Override
- protected void okPressed() {
- ISelection selection = getTreeViewer().getSelection();
- parentContainer = ((IStructuredSelection)selection).getFirstElement();
- CreateElementRequest request = null;
- if(parentContainer instanceof EObject) {
- request = new CreateElementRequest(domain, (EObject)parentContainer, this.hintedType);
- }
- elementToCreate = new NewElementRepresentation(this.text.getText(), parentContainer, hintedType, request);
- super.okPressed();
- }
-
- /**
- * Returns a command corresponding to this request.
- *
- * @param request
- * a request
- * @return the command
- * The command corresponding to this request or an {@link UnexecutableCommand} when the command can not be build
- */
- private ICommand getCommand(IEditCommandRequest request) {
- IElementEditService provider = ElementEditServiceUtils.getCommandProvider(UMLPackage.eINSTANCE.getNamedElement());
- {
- if(provider != null) {
- ICommand cmd = provider.getEditCommand(request);
- if(cmd != null && cmd.canExecute()) {
- return cmd;
- }
- }
- }
- return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE;
- }
-
- /**
- * This command is used to set the chosen name to the new element.
- */
- public class SetNameCommand extends AbstractTransactionalCommand {
-
- /** the representation that will own the new element when it will be created. */
- private NewElementRepresentation representation;
-
- /**
- * Constructor.
- *
- * @param domain
- * the domain
- * @param label
- * the label
- * @param affectedFiles
- * the affected files
- * @param previousRequest
- * the previous request
- * @param representation
- * the representation
- */
- public SetNameCommand(TransactionalEditingDomain domain, String label, List<?> affectedFiles, CreateElementRequest previousRequest, NewElementRepresentation representation) {
- super(domain, label, affectedFiles);
- this.representation = representation;
- }
-
- /**
- * Do execute with result.
- *
- * @param monitor
- * the monitor
- * @param info
- * the info
- * @return the command result
- * @throws ExecutionException
- * the execution exception
- * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor,
- * org.eclipse.core.runtime.IAdaptable)
- */
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- if(representation.getEObject() instanceof NamedElement) {
- NamedElement el = (NamedElement)representation.getEObject();
- el.setName(representation.getName());
- }
-
- return CommandResult.newOKCommandResult(representation);
- }
-
- }
-
- /**
- * This command allows to create a new element when its parent is not yet created when the command is build
- *
- * We need a such command, because {@link CreateRelationshipCommand#getCommandResult()} return <code>null</code> when the command has not been
- * executed.
- */
- public class CustomCreateElementCommand extends AbstractTransactionalCommand {
-
- /** the representation of the element to create. */
- private NewElementRepresentation elementToCreate;
-
- /**
- * Constructor.
- *
- * @param domain
- * the domain
- * @param label
- * the label
- * @param affectedFiles
- * the affected files
- * @param elementToCreate
- * the element to create
- */
- public CustomCreateElementCommand(TransactionalEditingDomain domain, String label, List<?> affectedFiles, NewElementRepresentation elementToCreate) {
- super(domain, label, affectedFiles);
- this.elementToCreate = elementToCreate;
- }
-
- /**
- * Do execute with result.
- *
- * @param monitor
- * the monitor
- * @param info
- * the info
- * @return the command result
- * @throws ExecutionException
- * the execution exception
- * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor,
- * org.eclipse.core.runtime.IAdaptable)
- */
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- EObject container = elementToCreate.getEObjectParent();
- CreateElementRequest request = new CreateElementRequest(domain, container, hintedType);
- ICommand command = getCommand(request);
- command.execute(new NullProgressMonitor(), null);
- EObject newEl = request.getNewElement();
-
- if(newEl instanceof NamedElement) {
- ((NamedElement)newEl).setName(elementToCreate.getName());
- }
-
- elementToCreate.setCreateElement(request.getNewElement());
- return CommandResult.newOKCommandResult(elementToCreate);
- }
- }
-}
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/ui/InterfaceManagerDialog.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/ui/InterfaceManagerDialog.java
deleted file mode 100644
index ce699e9b062..00000000000
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/ui/InterfaceManagerDialog.java
+++ /dev/null
@@ -1,1040 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.sysml.diagram.blockdefinition.ui;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.CompoundCommand;
-import org.eclipse.gef.commands.UnexecutableCommand;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.AbstractEditCommandRequest;
-import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
-import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
-import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
-import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
-import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
-import org.eclipse.papyrus.infra.widgets.editors.IElementSelector;
-import org.eclipse.papyrus.infra.widgets.editors.SelectionEditor;
-import org.eclipse.papyrus.infra.widgets.providers.AbstractStaticContentProvider;
-import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
-import org.eclipse.papyrus.infra.widgets.selectors.ReferenceSelector;
-import org.eclipse.papyrus.sysml.diagram.blockdefinition.messages.Messages;
-import org.eclipse.papyrus.sysml.portandflows.FlowSpecification;
-import org.eclipse.papyrus.uml.diagram.common.Activator;
-import org.eclipse.papyrus.uml.diagram.common.util.Util;
-import org.eclipse.papyrus.uml.diagram.common.util.Visitor;
-import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
-import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CLabel;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.dialogs.ISelectionStatusValidator;
-import org.eclipse.ui.dialogs.SelectionDialog;
-import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.Dependency;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.Interface;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.Namespace;
-import org.eclipse.uml2.uml.Package;
-import org.eclipse.uml2.uml.Port;
-import org.eclipse.uml2.uml.Realization;
-import org.eclipse.uml2.uml.UMLPackage;
-import org.eclipse.uml2.uml.Usage;
-import org.eclipse.uml2.uml.util.UMLUtil;
-
-
-/**
- * <pre>
- * This class provides a Dialog to manage easily the provided and
- * the required Interfaces for a {@link Port}.
- * </pre>
- */
-public class InterfaceManagerDialog extends SelectionDialog {
-
- /** the selected port */
- private Port port;
-
- /** the list of the provided interfaces */
- private List<Object> providedInterfaces;
-
- /** the list of the required interfaces */
- private List<Object> requiredInterfaces;
-
- /** the {@link ReferenceSelector} for the provided interfaces */
- private ReferenceSelector providedSelector;
-
- /** the {@link ReferenceSelector} for the required interfaces */
- private ReferenceSelector requiredSelector;
-
- /** the Editor for the provided interfaces */
- private SelectionEditor providedEditor;
-
- /** the Editor for the required interfaces */
- private SelectionEditor requiredEditor;
-
- /**
- * In this map, we link the {@link Interface} with their {@link Usage} This map is used when we want remove an Interface from a Usage
- */
- private Map<Interface, List<Usage>> requiredInterfacesMappedWithUsage = new HashMap<Interface, List<Usage>>();
-
- /**
- * In this map, we link the {@link Interface} with their {@link Realization} This map is used when we want remove an Interface from a Realization
- */
- private Map<Interface, List<Realization>> providedInterfacesMappedWithRealization = new HashMap<Interface, List<Realization>>();
-
- /** the label provider for selector */
- private final ILabelProvider selectorLabelProvider = new SelectorLabelProvider();
-
- /** the label provider for the create new element dialog */
- private final ILabelProvider newElementLabelProvider = new CreateElementLabelProvider();
-
- /** the domain used for the commands */
- private TransactionalEditingDomain domain;
-
- /** the model */
- private Package model = null;
-
- /** this command contains the list of the command to create the new Interfaces */
- private CompoundCommand interfaceCreationCommand = new CompoundCommand("Create Interfaces Commands"); //$NON-NLS-1$
-
- /** This list contains representation of the Interface before their creation */
- private List<NewElementRepresentation> interfaceRepresentations;
-
- /** boolean used to know if the {@link Port} is typed with an {@link Interface} */
- private boolean typedWithInterface;
-
- /** path for the warning icons */
- private static final String ICON_WARNING = "/icons/warning.gif"; //$NON-NLS-1$
-
- /**
- * This list contains the names used for the new elements.
- * We need to remember these names are used in order don't suggest them when we create other new elements
- */
- private List<String> forbiddenNames;
-
- /**
- *
- * Constructor.
- *
- * @param parentShell
- * the parent {@link Shell}
- * @param port
- * the {@link Port} for which we want manage the Interfaces
- */
- public InterfaceManagerDialog(Shell parentShell, Port port) {
- super(parentShell);
- this.setTitle(Messages.InterfaceManagerDialog_Title);
- this.port = port;
- Assert.isTrue(this.port.getType() instanceof Classifier);
- this.typedWithInterface = (this.port.getType() instanceof Interface);
- }
-
- /**
- *
- * @see org.eclipse.jface.dialogs.Dialog#create()
- *
- */
- @Override
- public void create() {
- super.create();
- init();
- }
-
- /**
- * This method initialize some fields of the class
- */
- protected void init() {
-
- this.forbiddenNames = new ArrayList<String>();
- this.interfaceRepresentations = new ArrayList<NewElementRepresentation>();
- EList<Namespace> namespaces = port.allNamespaces();
- Element el = namespaces.get(namespaces.size() - 1);
- if(el instanceof Package) {
- model = (Package)el;
- } else {
- model = el.getNearestPackage();
- }
-
- //fill the hashmap to link Interfaces with Usage and InterfaceRealization
- buildProvidedInterfaces();
- buildRequiredInterfaces();
-
- //we build the list of the provided interfaces
- this.providedInterfaces = new ArrayList<Object>();
- for(Interface current : this.port.getProvideds()) {
- this.providedInterfaces.add(current);
- }
- //when the port is typed by an Interface, we don't propose this interface in the possible Provided Interfaces list.
- if(typedWithInterface) {
- this.providedInterfaces.remove(this.port.getType());
- }
-
- //we build the list of the required interfaces
- this.requiredInterfaces = new ArrayList<Object>();
- for(Interface current : this.port.getRequireds()) {
- this.requiredInterfaces.add(current);
- }
-
- //initialize the transactional editing domain
- IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- IEditorPart editor = activePage.getActiveEditor();
- if(editor instanceof IMultiDiagramEditor) {
- try {
- this.domain = ServiceUtils.getInstance().getTransactionalEditingDomain(((IMultiDiagramEditor)editor).getServicesRegistry());
- } catch (ServiceException e) {
- e.printStackTrace();
- }
- }
-
- //selectors creation
- createSelectors();
- //editors creation
- createEditors();
-
- }
-
-
- /**
- * This method fills the map {@link #requiredInterfacesMappedWithUsage}
- */
- protected void buildRequiredInterfaces() {
- List<?> allUsage = Util.getInstancesFilteredByType(this.model, Usage.class, null);
- List<Classifier> classifiers = new ArrayList<Classifier>();
- classifiers.add((Classifier)this.port.getType());
-
- classifiers.addAll(Util.getAllSuperClasses(null, (Classifier)this.port.getType()));
-
-
- for(Object current : allUsage) {
- Usage usage = (Usage)current;
- for(Classifier classifier : classifiers) {//we test if the current Usage is linked with the type of the Port
- if(usage.getClients().contains(classifier)) {//this Usage concerns the current port
- for(EObject target : usage.getSuppliers()) {
- if(this.port.getRequireds().contains(target)) {
- List<Usage> usages = requiredInterfacesMappedWithUsage.get(target);
- if(usages != null) {
- usages.add(usage);
- } else {
- usages = new ArrayList<Usage>();
- usages.add(usage);
- this.requiredInterfacesMappedWithUsage.put((Interface)target, usages);
- }
- }
- }
- break;
- }
- }
- }
- }
-
- /**
- * This method fills the map {@link #providedInterfacesMappedWithRealization}
- */
- protected void buildProvidedInterfaces() {
- List<?> allRealization = Util.getInstancesFilteredByType(this.model, Realization.class, null);
- List<Classifier> classifiers = new ArrayList<Classifier>();
- classifiers.add((Classifier)this.port.getType());
-
- classifiers.addAll(Util.getAllSuperClasses(null, (Classifier)this.port.getType()));
-
-
- for(Object current : allRealization) {
- Realization realization = (Realization)current;
- for(Classifier classifier : classifiers) {//we test if the current Realization is linked with the type of the Port
- if(realization.getClients().contains(classifier)) {//this Realization concerns the current port
- for(EObject target : realization.getSuppliers()) {
- if(this.port.getProvideds().contains(target)) {
- List<Realization> realizations = providedInterfacesMappedWithRealization.get(target);
- if(realizations != null) {
- realizations.add(realization);
- } else {
- realizations = new ArrayList<Realization>();
- realizations.add(realization);
- this.providedInterfacesMappedWithRealization.put((Interface)target, realizations);
- }
- }
- }
- break;
- }
- }
- }
- }
-
- /**
- * This method creates the selectors {@link #providedSelector} and {@link #requiredSelector}
- */
- protected void createSelectors() {
- //the provided selector
- this.providedSelector = new ReferenceSelector(true);
- this.providedSelector.setLabelProvider(selectorLabelProvider);
- this.providedSelector.setContentProvider(new IStaticContentProvider() {
-
- /**
- *
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
- *
- * @param viewer
- * @param oldInput
- * @param newInput
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- *
- */
- public void dispose() {
-
- }
-
- /**
- *
- * @see org.eclipse.papyrus.editors.providers.IStaticContentProvider#getElements()
- *
- * @return
- */
- public Object[] getElements() {
- List<Object> tmp = new ArrayList<Object>();
- tmp.addAll(getAllAvailableInterfaces(model));
- if(typedWithInterface) {
- tmp.remove(port.getType());
- }
- //we add the new interfaces which are not yet created
- tmp.addAll(interfaceRepresentations);
- return tmp.toArray();
- }
-
- public Object[] getElements(Object inputElement) {
- return getElements();
- }
- });
- //the required selector
- this.requiredSelector = new ReferenceSelector(true);
- this.requiredSelector.setLabelProvider(selectorLabelProvider);
- this.requiredSelector.setContentProvider(new AbstractStaticContentProvider() {
-
- /**
- *
- * @see org.eclipse.papyrus.editors.providers.IStaticContentProvider#getElements()
- *
- * @return
- */
- public Object[] getElements() {
- List<Object> tmp = new ArrayList<Object>();
- tmp.addAll(getAllAvailableInterfaces(model));
-
- //we add the new interfaces which are not yet created
- tmp.addAll(interfaceRepresentations);
- return tmp.toArray();
- }
- });
- }
-
-
- /**
- * This method create the 2 Editors {@link #providedEditor} and {@link #requiredEditor} and provides the listener for the button of these editors
- */
- protected void createEditors() {
- Composite parent = (Composite)getDialogArea();
- CreateButtonListener listener = new CreateButtonListener();
- //we set a specific message if the port is typed with an Interface
- if(typedWithInterface) {
- Composite messageSection = new Composite(parent, SWT.BORDER);
- CLabel label = new CLabel(messageSection, SWT.NONE);
-
- label.setText(Messages.InterfaceManagerDialog_ThePortIsTypedWithAnInterfaceWarningMessage);
- Image errorImage = Activator.getPluginIconImage(Activator.ID, ICON_WARNING);
- label.setImage(errorImage);
- GridLayout layout = new GridLayout(1, true);
- GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
- messageSection.setLayout(layout);
- messageSection.setLayoutData(data);
- messageSection.setEnabled(false);
- }
- this.providedEditor = createEditor(parent, providedSelector, Messages.InterfaceManagerDialog_SelectedTheProvidedInterfaces, false, listener, this.providedInterfaces);
- this.requiredEditor = createEditor(parent, requiredSelector, Messages.InterfaceManagerDialog_SelectTheRequiredInterfaces, true, listener, this.requiredInterfaces);
-
- this.providedEditor.create();
- this.requiredEditor.create();
-
- GridLayout layout = (GridLayout)parent.getLayout();
- layout.numColumns = 1;
- layout.makeColumnsEqualWidth = true;
- GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
- this.providedEditor.setLayoutData(data);
- this.requiredEditor.setLayoutData(data);
- getShell().setSize(950, 700);
- getShell().layout();
- }
-
- /**
- * Creates a {@link SelectionEditor} and returns it
- *
- * @param parent
- * the composite parent
- * @param selector
- * the selector used by the created editor
- * @param message
- * the message to display in the created editor
- * @param withCreateButton
- * indicates if the editor provides an additional button for a specific action
- * @param listener
- * the listener for the button
- * @param initialSelection
- * the initial selection for this editor
- * @return
- * the created {@link SelectionEditor}
- */
- protected SelectionEditor createEditor(Composite parent, IElementSelector selector, String message, boolean withCreateButton, SelectionListener listener, List<Object> initialSelection) {
- SelectionEditor editor = new SelectionEditor(parent, selector, selectorLabelProvider, initialSelection);
- editor.setMessage(message);
- editor.setAdditionalButton(withCreateButton, Messages.InterfaceManagerDialog_CreateNewInterface, listener);
- return editor;
- }
-
- /**
- * Returns all the available Interfaces (except {@link FlowSpecification})
- *
- * @return
- * all the available Interfaces
- * //TODO add the interfaces from the package import!
- */
- @SuppressWarnings("unchecked")
- protected List<Interface> getAllAvailableInterfaces(Package pack) {
- List<Interface> otherInterfaces = new ArrayList<Interface>();
- List<Element> interfaces = Visitor.getOwnedAndImportedElement(pack, Interface.class);
- for(Namespace namespace : Visitor.getOwnedAndImportedNamespaces(pack)) {
- interfaces.addAll(Visitor.getOwnedAndImportedElement(namespace, Interface.class));
-
- }
-
- for(Element element : interfaces) {
- // Test if the interface is a FlowSpecification
- FlowSpecification flowSpec = UMLUtil.getStereotypeApplication(element, FlowSpecification.class);
- if(flowSpec == null) {
- otherInterfaces.add((Interface)element);
- }
- }
-
- return otherInterfaces;
- }
-
- /**
- * Returns the commands to apply the changes
- *
- * @return
- * the commands to apply the changes
- */
- public Command getCommand() {
- CompoundCommand command = new CompoundCommand("Command to manage interfaces on Port"); //$NON-NLS-1$
- if(!interfaceCreationCommand.isEmpty()) {
- command.add(interfaceCreationCommand);
- }
- Command cmd = getCommandsToCreateElements();
- if(cmd.canExecute()) {
- command.add(cmd);
- }
- cmd = getCommandToRemoveReferencedInterfaces();
- if(cmd.canExecute()) {
- command.add(cmd);
- }
- return command;
- }
-
- /**
- * Returns the command to remove referenced Interfaces in Usage and InterfaceRealization
- *
- * @return
- * The command to remove referenced Interfaces the Usage and InterfaceRealization.
- * Moreover, we add a command to destroy Usage and InterfaceRealization when they have any Suppliers after this action
- */
- protected Command getCommandToRemoveReferencedInterfaces() {
- CompoundCommand command = new CompoundCommand("Command to destroy Usage and InterfaceRealization"); //$NON-NLS-1$
-
- Set<Dependency> relationshipToDestroy = new HashSet<Dependency>();
- //commands to destroy Usage
- for(Object current : this.requiredEditor.getElementToRemove()) {
- //we get all usage associated with this interface
- List<Usage> usages = requiredInterfacesMappedWithUsage.get(current);
- for(Usage currentUsage : usages) {
- //we remove the reference to the Interface in the Usage
- DestroyReferenceRequest request = new DestroyReferenceRequest(domain, currentUsage, UMLPackage.eINSTANCE.getDependency_Supplier(), (EObject)current, false);
- Command cmd = getCommand(request);
- if(cmd.canExecute()) {
- command.add(cmd);
- relationshipToDestroy.add(currentUsage);
- }
- }
- }
-
- //commands to destroy InterfaceRealization
- for(Object current : this.providedEditor.getElementToRemove()) {
- //we get all usage associated with this interface
- List<Realization> realizations = providedInterfacesMappedWithRealization.get(current);
- for(Realization currentRealization : realizations) {
- //we remove the reference to the Interface in the Usage
- DestroyReferenceRequest request = new DestroyReferenceRequest(domain, currentRealization, UMLPackage.eINSTANCE.getDependency_Supplier(), (EObject)current, false);
- Command cmd = getCommand(request);
- if(cmd.canExecute()) {
- command.add(cmd);
- relationshipToDestroy.add(currentRealization);
- }
- }
- }
- if(!relationshipToDestroy.isEmpty()) {
- command.add(new ICommandProxy(new DestroyDependencyWithoutSupplierCommand(this.domain, null, relationshipToDestroy)));
- return command;
- }
-
- //nothing to do
- return UnexecutableCommand.INSTANCE;
- }
-
- /**
- * Returns the command to create new Usage and new InterfaceRealization
- *
- * @return
- * the command to create new Usage and new InterfaceRealization
- */
- protected Command getCommandsToCreateElements() {
- CompoundCommand command = new CompoundCommand("Command to create Usage and InterfaceRealization"); //$NON-NLS-1$
- //commands for Usage Creation
- for(Object current : this.requiredEditor.getElementToAdd()) {
- if(current instanceof EObject) {
- CreateRelationshipRequest request = new CreateRelationshipRequest(this.port.getType().eContainer(), this.port.getType(), (EObject)current, org.eclipse.papyrus.uml.service.types.element.UMLElementTypes.USAGE);
- Command cmd = getCommand(request);
- if(cmd.canExecute()) {
- command.add(cmd);
- }
- } else {//its an NewElementRepresentation
-
- CreateUsageCommand cmd = new CreateUsageCommand(this.domain, this.port.getType().eContainer(), this.port.getType(), (NewElementRepresentation)current, null);
- if(cmd.canExecute()) {
- command.add(new ICommandProxy(cmd));
- }
- }
- }
-
- //commands for InterfaceRealization Creation
- for(Object current : providedEditor.getElementToAdd()) {
- if(current instanceof EObject) {
- CreateRelationshipRequest request = new CreateRelationshipRequest(this.port.getType().eContainer(), this.port.getType(), (EObject)current, org.eclipse.papyrus.uml.service.types.element.UMLElementTypes.INTERFACE_REALIZATION);
- Command cmd = getCommand(request);
- if(cmd.canExecute()) {
- command.add(cmd);
- }
- } else {//its an NewElementRepresentation
- CreateInterfaceRealizationCommand cmd = new CreateInterfaceRealizationCommand(this.domain, this.port.getType().eContainer(), this.port.getType(), (NewElementRepresentation)current, null);
- if(cmd.canExecute()) {
- command.add(new ICommandProxy(cmd));
- }
- }
- }
- if(!command.isEmpty()) {
- return command;
- }
- return UnexecutableCommand.INSTANCE;
- }
-
-
- /**
- * Return the command corresponding to the request
- *
- * @param req
- * a request
- * @return
- * the command corresponding to the request
- */
- protected Command getCommand(AbstractEditCommandRequest req) {
- IElementEditService provider = ElementEditServiceUtils.getCommandProvider(model);
- if(provider != null) {
- ICommand setCommand = provider.getEditCommand(req);
- if(setCommand != null) {
- return new ICommandProxy(setCommand.reduce());
- }
- }
- return UnexecutableCommand.INSTANCE;
- }
-
- /**
- * This listener is used to know when the user clicks on the Button to create a new {@link Interface}
- *
- *
- *
- */
- public class CreateButtonListener implements SelectionListener {
-
- /**
- *
- * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
- *
- * @param e
- */
- public void widgetSelected(SelectionEvent e) {
- CreateUmlElementDialog dialog = new CreateUmlElementDialog(getShell(), domain, newElementLabelProvider, new CustomContentProvider(), model, UMLElementTypes.INTERFACE);
- dialog.setTitle(Messages.InterfaceManagerDialog_CreateANewInterface);
- dialog.setMessage(Messages.InterfaceManagerDialog_SelectTheParentOfThisNewInterface);
- dialog.setHelpAvailable(false);
- dialog.setForbiddenNames(forbiddenNames);
- List<Object> input = new ArrayList<Object>();
- input.add(model);
- dialog.setInput(input);
- dialog.setValidator(new ParentInterfaceValidator());
- if(dialog.open() == org.eclipse.jface.dialogs.Dialog.OK) {
- interfaceCreationCommand.add(dialog.getCommand());
- Object[] res = dialog.getResult();
- for(Object current : res) {
- if(current instanceof NewElementRepresentation) {
- interfaceRepresentations.add((NewElementRepresentation)current);
- forbiddenNames.add(((NewElementRepresentation)current).getName());
- }
- }
- providedSelector.refresh();
- requiredSelector.refresh();
- }
- }
-
- /**
- *
- * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
- *
- * @param e
- */
- public void widgetDefaultSelected(SelectionEvent e) {
-
- }
-
- }
-
-
- /**
- *
- * This class provides a validator for the selection of the parent of the new Interface
- *
- *
- */
- public class ParentInterfaceValidator implements ISelectionStatusValidator {
-
- /**
- * Selection has to be a Classifier or an Interface to allow creation
- *
- * @see org.eclipse.ui.dialogs.ISelectionStatusValidator#validate(java.lang.Object[])
- *
- * @param selection
- * @return
- */
- public IStatus validate(Object[] selection) {
-
- IStatus status = new Status(IStatus.ERROR, org.eclipse.papyrus.sysml.diagram.blockdefinition.Activator.PLUGIN_ID, Messages.NoSelectionFound);
- if(selection.length >= 1) {
- for(int i = 0; i < selection.length; i++) {
- if(selection[i] instanceof Package || selection[i] instanceof Classifier || selection[i] instanceof NewElementRepresentation)
- status = new Status(IStatus.OK, org.eclipse.papyrus.sysml.diagram.blockdefinition.Activator.PLUGIN_ID, Messages.SelectionValidated);
- else {
- status = new Status(IStatus.ERROR, org.eclipse.papyrus.sysml.diagram.blockdefinition.Activator.PLUGIN_ID, Messages.InterfaceManagerDialog_SelectionHasToBeAPackageOrAClassifier);
- break;
- }
- }
- }
- return status;
- }
- }
-
- /**
- *
- * This class provides a CustomLabelProvider for this dialog.
- * This class manages the {@link NewElementRepresentation} and consider them like Interfaces
- *
- *
- */
- public class SelectorLabelProvider extends CreateElementLabelProvider {
-
-
- /**
- *
- * @see org.eclipse.papyrus.uml.diagram.common.providers.EditorLabelProvider#getText(java.lang.Object)
- *
- * @param element
- * @return
- */
- @Override
- public String getText(Object element) {
- if(element instanceof NewElementRepresentation) {
- return ((NewElementRepresentation)element).getQualifiedName();
- } else if(element instanceof NamedElement) {
- return ((NamedElement)element).getQualifiedName();
- }
- return super.getText(element);
- }
-
- }
-
- public class CreateElementLabelProvider extends UMLLabelProvider {
-
- /**
- *
- * @see org.eclipse.papyrus.uml.diagram.common.providers.EditorLabelProvider#getImage(java.lang.Object)
- *
- * @param element
- * @return
- */
- @Override
- public Image getImage(Object element) {
- if(element instanceof NewElementRepresentation) {
- return org.eclipse.papyrus.uml.tools.Activator.getDefault().getImageForUMLMetaclass(UMLPackage.eINSTANCE.getInterface());
- }
- return super.getImage(element);
- }
-
- /**
- *
- * @see org.eclipse.papyrus.uml.diagram.common.providers.EditorLabelProvider#getText(java.lang.Object)
- *
- * @param element
- * @return
- */
- @Override
- public String getText(Object element) {
- if(element instanceof NewElementRepresentation) {
- return ((NewElementRepresentation)element).getName();
- }
- return super.getText(element);
- }
-
- }
-
- /**
- *
- * This content provider is used in this dialog. It returns the available element in the model + the future element which are
- * {@link NewElementRepresentation}
- *
- *
- */
- public class CustomContentProvider implements ITreeContentProvider {
-
- /**
- *
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- *
- */
- public void dispose() {
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
- *
- * @param viewer
- * @param oldInput
- * @param newInput
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)
- *
- * @param inputElement
- * @return
- */
- public Object[] getElements(Object inputElement) {
- if(inputElement instanceof List<?>) {
- return ((List<?>)inputElement).toArray();
- }
- return new Object[0];
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
- *
- * @param parentElement
- * @return
- */
- public Object[] getChildren(Object parentElement) {
- List<Object> children = new ArrayList<Object>();
- List<?> tmp = null;
- if(parentElement instanceof Package) {
- tmp = ((Package)parentElement).getOwnedMembers();
- } else if(parentElement instanceof Classifier) {
- tmp = ((Classifier)parentElement).getOwnedMembers();
- }
- if(tmp != null) {
- for(Object current : tmp) {
- if(current instanceof Classifier || current instanceof Package) {
- children.add(current);
- }
- }
- }
- //we add the future Interfaces to this selection
- for(NewElementRepresentation current : interfaceRepresentations) {
- if(current.getParent() == parentElement) {
- children.add(current);
- }
- }
- return children.toArray();
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
- *
- * @param element
- * @return
- */
- public Object getParent(Object element) {
- if(element == model) {
- return model;
- } else if(element instanceof NamedElement) {
- return ((NamedElement)element).eContainer();
- }
- return null;
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
- *
- * @param element
- * @return
- */
- public boolean hasChildren(Object element) {
- return getChildren(element).length != 0;
- }
-
- }
-
- /**
- *
- * This command is used to create a New Usage, when its target (an Interface) doesn't exist when the command is created
- * (but this Interface will exist when the command will be executed)
- *
- *
- */
- public class CreateUsageCommand extends AbstractTransactionalCommand {
-
- /** The container for the new Usage */
- private EObject container;
-
- /** the source of this Usage */
- private EObject source;
-
- /** the target : the representation of the new interface */
- private NewElementRepresentation target;
-
- /**
- *
- * Constructor.
- *
- * @param domain
- * the domain
- * @param container
- * the container for the Usage
- * @param source
- * the source for the Usage
- * @param target
- * the target for the Usage
- * @param affectedFiles
- * the affected files
- */
- public CreateUsageCommand(TransactionalEditingDomain domain, EObject container, EObject source, NewElementRepresentation target, List<?> affectedFiles) {
- super(domain, "Create Usage Command", affectedFiles); //$NON-NLS-1$
- this.container = container;
- this.source = source;
- this.target = target;
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor,
- * org.eclipse.core.runtime.IAdaptable)
- *
- * @param monitor
- * @param info
- * @return
- * @throws ExecutionException
- */
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- CreateRelationshipRequest request = new CreateRelationshipRequest(domain, container, source, target.getEObject(), UMLElementTypes.USAGE);
- Command command = getCommand(request);
- if(command.canExecute()) {
- command.execute();
- }
- return CommandResult.newOKCommandResult(request.getNewElement());
- }
-
- }
-
- /**
- *
- * This command is used to create a New InterfaceRealition, when its target (an Interface) doesn't exist when the command is created
- * (but this Interface will exist when the command will be executed)
- *
- *
- */
- public class CreateInterfaceRealizationCommand extends AbstractTransactionalCommand {
-
- /** The container for the new InterfaceRealization */
- private EObject container;
-
- /** The source for the new InterfaceRealization */
- private EObject source;
-
- /** the target : the representation of the new interface */
- private NewElementRepresentation target;
-
- /**
- *
- * Constructor.
- *
- * @param domain
- * the domain
- * @param container
- * the container for the InterfaceRealization
- * @param source
- * the source for the InterfaceRealization
- * @param target
- * the target for the InterfaceRealization
- * @param affectedFiles
- * the affected files
- */
- public CreateInterfaceRealizationCommand(TransactionalEditingDomain domain, EObject container, EObject source, NewElementRepresentation target, List<?> affectedFiles) {
- super(domain, "Create InterfaceRealization Command", affectedFiles); //$NON-NLS-1$
- this.container = container;
- this.source = source;
- this.target = target;
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor,
- * org.eclipse.core.runtime.IAdaptable)
- *
- * @param monitor
- * @param info
- * @return
- * @throws ExecutionException
- */
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
-
- CreateRelationshipRequest request = new CreateRelationshipRequest(domain, container, source, target.getEObject(), UMLElementTypes.INTERFACE_REALIZATION);
- Command command = getCommand(request);
- if(command.canExecute()) {
- command.execute();
- }
- return CommandResult.newOKCommandResult(request.getNewElement());
- }
-
- }
-
- /**
- *
- * This command is used to destroy Dependencies which have any supplier before the deletion of the Interface
- *
- *
- */
- public class DestroyDependencyWithoutSupplierCommand extends AbstractTransactionalCommand {
-
- /**
- * the dependencies to test
- */
- private Set<Dependency> dependencies;
-
- /**
- *
- * Constructor.
- *
- * @param domain
- * the domain
- * @param affectedFiles
- * the affected files
- * @param dependencies
- * the dependencies to test
- */
- public DestroyDependencyWithoutSupplierCommand(TransactionalEditingDomain domain, List<?> affectedFiles, Set<Dependency> dependencies) {
- super(domain, "Destroy the empty elements", affectedFiles); //$NON-NLS-1$
- this.dependencies = dependencies;
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor,
- * org.eclipse.core.runtime.IAdaptable)
- *
- * @param monitor
- * @param info
- * @return
- * @throws ExecutionException
- */
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- CompoundCommand command = new CompoundCommand("Destroy relationship without suppliers"); //$NON-NLS-1$
- for(Dependency current : dependencies) {
- if(current.getSuppliers().isEmpty()) {
- DestroyElementRequest request = new DestroyElementRequest(domain, current, false);
- Command cmd = getCommand(request);
- if(cmd.canExecute()) {
- command.add(cmd);
- }
- }
- }
-
- if(!command.isEmpty() && command.canExecute()) {
- command.execute();
- }
- return CommandResult.newOKCommandResult();
- }
- }
-}
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/ui/NewElementRepresentation.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/ui/NewElementRepresentation.java
deleted file mode 100644
index 219df0375c5..00000000000
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/ui/NewElementRepresentation.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.sysml.diagram.blockdefinition.ui;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
-import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
-import org.eclipse.uml2.uml.NamedElement;
-
-/**
- * This class provides facilities to represent a New Element before its real creation.
- * We can store in this class :
- * <ul>
- * <li>the name of the new element</li>
- * <li>the parent of the new element</li>
- * <li>the {@link IHintedType} of the new element</li>
- * <li>the request to build the new element (optional)</li>
- * <li>the element itself when it has been created</li>
- * </ul>
- *
- *
- *
- */
-public class NewElementRepresentation {
-
- /** the name of the new element */
- private String name;
-
- /** the parent of the new element */
- private Object parent;
-
- /** the created element itself */
- private EObject createdElement;
-
- /** the {@link IHintedType} of the new element */
- private IHintedType hintedType;
-
- /** this field is used only when the element have an existing parent */
- private CreateElementRequest request;
-
- /**
- *
- * Constructor.
- *
- * @param name
- * the name of the new element
- * @param parent
- * the parent of the new element
- * @param hintedType
- * the hinted type of the new element
- * @param request
- * the request to build the new element (can be <code>null</code>)
- */
- public NewElementRepresentation(String name, Object parent, IHintedType hintedType, CreateElementRequest request) {
- this.name = name;
- this.parent = parent;
- this.createdElement = null;
- this.hintedType = hintedType;
- this.request = request;
- }
-
- /**
- * Getter for {@link #hintedType}
- *
- * @return
- * {@link #hintedType}
- */
- public IHintedType getHintedType() {
- return this.hintedType;
- }
-
- /**
- * Getter for {@link #name}
- *
- * @return
- * {@link #name}
- */
- public String getName() {
- return this.name;
- }
-
- /**
- * Getter for {@link #parent}
- *
- * @return
- * {@link #parent}
- */
- public Object getParent() {
- return this.parent;
- }
-
- /**
- * Returns the parent of this element
- *
- * @return
- * the parent of this element or <code>null</code> if the parent is a {@link NewElementRepresentation} itself and if it has not been
- * created
- */
- public EObject getEObjectParent() {
- if(parent instanceof EObject) {
- return (EObject)this.parent;
- } else if(parent instanceof NewElementRepresentation) {
- return ((NewElementRepresentation)parent).getEObject();
- }
- return null;
- }
-
- /**
- * Returns the created object
- *
- * @return
- * the created Object or <code>null</code> if the object has not been created
- */
- public EObject getEObject() {
- if(this.request != null) {
- return this.request.getNewElement();
- }
- return this.createdElement;
- }
-
- /**
- * Setter for {@link #createdElement}
- *
- * @param newElement
- *
- */
- public void setCreateElement(EObject newElement) {
- this.createdElement = newElement;
- }
-
- /**
- * Setter for {@link #request}
- *
- * @return
- * {@link #request}
- */
- public CreateElementRequest getCreateElementRequest() {
- return this.request;
- }
-
- /**
- *
- * @see java.lang.Object#toString()
- *
- * @return
- */
- @Override
- public String toString() {
- return "Name : " + this.name + ", parent : " + this.parent;
- }
-
- public String getQualifiedName() {
- String qualifiedName = "";
- if(parent instanceof NewElementRepresentation) {
- qualifiedName = ((NewElementRepresentation)parent).getQualifiedName();
- } else if(parent instanceof NamedElement) {
- qualifiedName = ((NamedElement)parent).getQualifiedName() + "::" + this.name;
- }
- return qualifiedName;
- }
-}
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/META-INF/MANIFEST.MF b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/META-INF/MANIFEST.MF
index b4e48de3d4a..a593df72bfe 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/META-INF/MANIFEST.MF
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/META-INF/MANIFEST.MF
@@ -1,18 +1,18 @@
Manifest-Version: 1.0
-Export-Package: org.eclipse.papyrus.sysml.diagram.internalblock,
- org.eclipse.papyrus.sysml.diagram.internalblock.compatibility,
- org.eclipse.papyrus.sysml.diagram.internalblock.dnd.helper,
- org.eclipse.papyrus.sysml.diagram.internalblock.edit.part,
- org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy,
- org.eclipse.papyrus.sysml.diagram.internalblock.factory,
- org.eclipse.papyrus.sysml.diagram.internalblock.handler,
- org.eclipse.papyrus.sysml.diagram.internalblock.helper.advice,
- org.eclipse.papyrus.sysml.diagram.internalblock.messages,
- org.eclipse.papyrus.sysml.diagram.internalblock.part,
- org.eclipse.papyrus.sysml.diagram.internalblock.preferences,
- org.eclipse.papyrus.sysml.diagram.internalblock.provider,
- org.eclipse.papyrus.sysml.diagram.internalblock.ui,
- org.eclipse.papyrus.sysml.diagram.internalblock.utils
+Export-Package: org.eclipse.papyrus.sysml.diagram.internalblock,
+ org.eclipse.papyrus.sysml.diagram.internalblock.compatibility,
+ org.eclipse.papyrus.sysml.diagram.internalblock.dnd.helper,
+ org.eclipse.papyrus.sysml.diagram.internalblock.edit.part,
+ org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy,
+ org.eclipse.papyrus.sysml.diagram.internalblock.factory,
+ org.eclipse.papyrus.sysml.diagram.internalblock.handler,
+ org.eclipse.papyrus.sysml.diagram.internalblock.helper.advice,
+ org.eclipse.papyrus.sysml.diagram.internalblock.messages,
+ org.eclipse.papyrus.sysml.diagram.internalblock.part,
+ org.eclipse.papyrus.sysml.diagram.internalblock.preferences,
+ org.eclipse.papyrus.sysml.diagram.internalblock.provider,
+ org.eclipse.papyrus.sysml.diagram.internalblock.ui,
+ org.eclipse.papyrus.sysml.diagram.internalblock.utils
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.papyrus.sysml;bundle-version="1.0.0",
@@ -44,19 +44,17 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.0.0",
org.eclipse.gmf.tooling.runtime;bundle-version="3.1.0",
org.eclipse.papyrus.infra.tools;bundle-version="1.0.0",
- org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.0.0",
- org.eclipse.papyrus.emf.facet.custom.core;bundle-version="1.0.0",
org.eclipse.papyrus.uml.diagram.common;bundle-version="1.0.0",
org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="1.0.0",
org.eclipse.papyrus.infra.viewpoints.configuration;bundle-version="1.0.0",
org.eclipse.papyrus.infra.extendedtypes;bundle-version="1.0.0"
-Bundle-Vendor: %providerName
-Bundle-ActivationPolicy: lazy
-Bundle-Version: 1.0.0.qualifier
-Bundle-Localization: plugin
-Bundle-Name: %pluginName
-Bundle-Activator: org.eclipse.papyrus.sysml.diagram.internalblock.Activator
-Bundle-ManifestVersion: 2
-Bundle-SymbolicName: org.eclipse.papyrus.sysml.diagram.internalblock;singleton:=true
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
-
+Bundle-Vendor: %providerName
+Bundle-ActivationPolicy: lazy
+Bundle-Version: 1.0.0.qualifier
+Bundle-Localization: plugin
+Bundle-Name: %pluginName
+Bundle-Activator: org.eclipse.papyrus.sysml.diagram.internalblock.Activator
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: org.eclipse.papyrus.sysml.diagram.internalblock;singleton:=true
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/messages.properties b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/messages.properties
index d3a328f40e1..66027e54464 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/messages.properties
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/messages.properties
@@ -1,24 +1,5 @@
-CreateUmlElementDialog_New_Element_Name=New Element Name
-InterfaceManagerDialog_CreateANewInterface=Create a new Interface
-InterfaceManagerDialog_CreateNewInterface=Create new Interface
-InterfaceManagerDialog_SelectedTheProvidedInterfaces=Select the provided Interfaces
-InterfaceManagerDialog_SelectionHasToBeAPackageOrAClassifier=Selection has to be a Package or a Classifier
-InterfaceManagerDialog_SelectTheParentOfThisNewInterface=Select the parent of this new Interface
-InterfaceManagerDialog_SelectTheRequiredInterfaces=Select the required Interfaces
-InterfaceManagerDialog_ThePortIsTypedWithAnInterfaceWarningMessage=\nThe managed port is typed with an Interface, so this interface is not available as a provided Interface.\n
-InterfaceManagerDialog_Title=Select the provided and the required Interfaces
-ManageProvidedInterfacesHandler_OK=OK
-ManageProvidedInterfacesHandler_TheTypeOfThePortIsNotDefined=The type of the Port (should be a Block) is not defined. You need to define it before managing its Interfaces.
-SelectionValidated=Selection validated.
-NoSelectionFound=No selection found.
-
-ManageProvidedInterfacesHandler_OK=OK
-ManageProvidedInterfacesHandler_TheTypeOfThePortIsNotDefined=The type of the Port (should be a Block) is not defined. You need to define it before managing its Interfaces.
-SelectionValidated=Selection validated.
-NoSelectionFound=No selection found.
-
-Notification_Drop_Title=Drop in diagram
-Notification_Drop_UMLAssociationWarning=The Association ({0}) can not be dropped in this diagram because it is not a SysML Association.\nIt was probably not created in a SysML Diagram.
-
-ShowHideRelatedContentsAction_Message=Choose the elements to show
+Notification_Drop_Title=Drop in diagram
+Notification_Drop_UMLAssociationWarning=The Association ({0}) can not be dropped in this diagram because it is not a SysML Association.\nIt was probably not created in a SysML Diagram.
+
+ShowHideRelatedContentsAction_Message=Choose the elements to show
ShowHideRelatedContentsAction_Title=Show/Hide Related Contents \ No newline at end of file
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/plugin.xml b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/plugin.xml
index 773dfa54098..7767ab31c04 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/plugin.xml
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/plugin.xml
@@ -355,7 +355,7 @@
-->
<extension point="org.eclipse.ui.handlers">
- <handler commandId="org.eclipse.papyrus.sysml.diagram.internalblock.command.manage.interfaces" class="org.eclipse.papyrus.sysml.diagram.internalblock.handler.ManageProvidedInterfacesHandler">
+ <handler commandId="org.eclipse.papyrus.sysml.diagram.internalblock.command.manage.interfaces" class="org.eclipse.papyrus.sysml.diagram.internalblock.handler.InternalBlockManageInterfacesHandler">
<activeWhen>
<and>
<with variable="selection">
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/handler/InternalBlockManageInterfacesHandler.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/handler/InternalBlockManageInterfacesHandler.java
new file mode 100644
index 00000000000..8a4c4d2ae1d
--- /dev/null
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/handler/InternalBlockManageInterfacesHandler.java
@@ -0,0 +1,46 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.sysml.diagram.internalblock.handler;
+
+import org.eclipse.gmf.runtime.common.ui.util.DisplayUtils;
+import org.eclipse.papyrus.sysml.diagram.internalblock.ui.InternalBlockInterfaceManagerDialog;
+import org.eclipse.papyrus.uml.diagram.common.actions.handlers.ManagePortInterfacesHandler;
+import org.eclipse.papyrus.uml.diagram.common.dialogs.IPortInterfaceManagerDialog;
+import org.eclipse.uml2.uml.Interface;
+import org.eclipse.uml2.uml.InterfaceRealization;
+import org.eclipse.uml2.uml.Port;
+import org.eclipse.uml2.uml.Usage;
+
+/**
+ * <pre>
+ * This handler provides the handler to manage the provided and required {@link Interface}
+ * of a {@link Port} without graphically creating {@link InterfaceRealization} and
+ * {@link Usage} relationships.
+ * </pre>
+ */
+public class InternalBlockManageInterfacesHandler extends ManagePortInterfacesHandler {
+
+
+
+ /**
+ * @see org.eclipse.papyrus.uml.diagram.common.actions.handlers.ManagePortInterfacesHandler#getInterfaceManagerDialog(org.eclipse.uml2.uml.Port)
+ *
+ * @param port
+ * @return
+ */
+ @Override
+ public IPortInterfaceManagerDialog getInterfaceManagerDialog(Port port) {
+ return new InternalBlockInterfaceManagerDialog(DisplayUtils.getDefaultShell(), port);
+
+ }
+}
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/handler/ManageProvidedInterfacesHandler.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/handler/ManageProvidedInterfacesHandler.java
deleted file mode 100644
index 7214786414a..00000000000
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/handler/ManageProvidedInterfacesHandler.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.sysml.diagram.internalblock.handler;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.UnexecutableCommand;
-import org.eclipse.gmf.runtime.common.ui.util.DisplayUtils;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.papyrus.commands.wrappers.GEFtoEMFCommandWrapper;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
-import org.eclipse.papyrus.sysml.diagram.internalblock.messages.Messages;
-import org.eclipse.papyrus.sysml.diagram.internalblock.ui.InterfaceManagerDialog;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.Interface;
-import org.eclipse.uml2.uml.InterfaceRealization;
-import org.eclipse.uml2.uml.Port;
-import org.eclipse.uml2.uml.Type;
-import org.eclipse.uml2.uml.Usage;
-
-/**
- * <pre>
- * This handler provides the handler to manage the provided and required {@link Interface}
- * of a {@link Port} without graphically creating {@link InterfaceRealization} and
- * {@link Usage} relationships.
- * </pre>
- */
-public class ManageProvidedInterfacesHandler extends AbstractHandler {
-
- public Object execute(ExecutionEvent event) throws ExecutionException {
- ISelection selection = HandlerUtil.getCurrentSelection(event);
- if(selection.isEmpty()) {
- return null;
- }
-
- if(selection instanceof IStructuredSelection) {
- IStructuredSelection structuredSelection = (IStructuredSelection)selection;
- EObject selectedElement = EMFHelper.getEObject(structuredSelection.getFirstElement());
- if(selectedElement instanceof Port) {
- Port port = (Port)selectedElement;
- ManageProvidedInterfaceAction action = new ManageProvidedInterfaceAction(port);
- try {
- ServiceUtilsForEObject.getInstance().getTransactionalEditingDomain(port).getCommandStack().execute(new GEFtoEMFCommandWrapper(action.getCommand()));
- } catch (ServiceException ex) {
- throw new ExecutionException("An unexpected exception occurred", ex);
- }
- }
- }
-
- return null;
- }
-
- /**
- * This class provides the action to manage the provided and required interfaces
- */
- public class ManageProvidedInterfaceAction {
-
- /** the {@link Port} */
- private Port port;
-
- /** the {@link Type} of the port */
- private Type type;
-
- /**
- *
- * Constructor.
- *
- * @param editpart
- * the editpart of the port
- */
- public ManageProvidedInterfaceAction(Port port) {
- this.port = port;
- this.type = port.getType();
- }
-
-
- /**
- * Returns the command to add/remove provided/required interfaces
- *
- * @return
- * the command to add/remove provided/required interfaces
- */
- public Command getCommand() {
- if(type != null && !(type instanceof Classifier)) {
- return UnexecutableCommand.INSTANCE;
- } else if(type == null) {
- MessageDialog dialog = new MessageDialog(DisplayUtils.getDefaultShell(), Messages.InterfaceManagerDialog_Title, null, Messages.ManageProvidedInterfacesHandler_TheTypeOfThePortIsNotDefined, MessageDialog.WARNING, new String[]{ Messages.ManageProvidedInterfacesHandler_OK }, 0);
- dialog.open();
- } else {
- InterfaceManagerDialog dialog = new InterfaceManagerDialog(DisplayUtils.getDefaultShell(), this.port);
- if(dialog.open() == Dialog.OK) {
- return dialog.getCommand();
- }
- }
- return UnexecutableCommand.INSTANCE;
- }
- }
-
-}
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/messages/Messages.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/messages/Messages.java
index d0923107f94..4b47caf1ee0 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/messages/Messages.java
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/messages/Messages.java
@@ -1,60 +1,34 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.sysml.diagram.internalblock.messages;
-
-import org.eclipse.osgi.util.NLS;
-
-public class Messages extends NLS {
-
- public static String CreateUmlElementDialog_New_Element_Name;
-
- public static String InterfaceManagerDialog_CreateANewInterface;
-
- public static String InterfaceManagerDialog_CreateNewInterface;
-
- public static String InterfaceManagerDialog_SelectedTheProvidedInterfaces;
-
- public static String InterfaceManagerDialog_SelectionHasToBeAPackageOrAClassifier;
-
- public static String InterfaceManagerDialog_SelectTheParentOfThisNewInterface;
-
- public static String InterfaceManagerDialog_SelectTheRequiredInterfaces;
-
- public static String InterfaceManagerDialog_ThePortIsTypedWithAnInterfaceWarningMessage;
-
- public static String InterfaceManagerDialog_Title;
-
- public static String ManageProvidedInterfacesHandler_OK;
-
- public static String ManageProvidedInterfacesHandler_TheTypeOfThePortIsNotDefined;
-
- public static String SelectionValidated;
-
- public static String NoSelectionFound;
-
- public static String Notification_Drop_Title;
-
- public static String Notification_Drop_UMLAssociationWarning;
-
- public static String ShowHideRelatedContentsAction_Title;
-
- public static String ShowHideRelatedContentsAction_Message;
-
- static {
- NLS.initializeMessages("messages", Messages.class); //$NON-NLS-1$
- }
-
- private Messages() {
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.sysml.diagram.internalblock.messages;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ public static String Notification_Drop_Title;
+
+ public static String Notification_Drop_UMLAssociationWarning;
+
+ public static String ShowHideRelatedContentsAction_Title;
+
+ public static String ShowHideRelatedContentsAction_Message;
+
+ static {
+ NLS.initializeMessages("messages", Messages.class); //$NON-NLS-1$
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/ui/CreateUmlElementDialog.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/ui/CreateUmlElementDialog.java
deleted file mode 100644
index 090a09899a8..00000000000
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/ui/CreateUmlElementDialog.java
+++ /dev/null
@@ -1,433 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.sysml.diagram.internalblock.ui;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
-import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
-import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
-import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
-import org.eclipse.papyrus.sysml.diagram.internalblock.messages.Messages;
-import org.eclipse.papyrus.uml.tools.utils.ElementUtil;
-import org.eclipse.papyrus.uml.tools.utils.NamedElementUtil;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
-import org.eclipse.uml2.uml.Interface;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.Package;
-import org.eclipse.uml2.uml.UMLPackage;
-
-/**
- * This dialog allows to create easily a new element in a UML Model.
- */
-public class CreateUmlElementDialog extends ElementTreeSelectionDialog {
-
- /** the hinted type of the element to create. */
- private IHintedType hintedType;
-
- /** the parent container of the element to create. */
- private Object parentContainer;
-
- /** the type of the element to create. */
- private String type;
-
- /** the root of the model. */
- private Package pack;
-
- /** the text field used to display the choose the name of the future element. */
- private Text text;
-
- /** creation request. */
- private CreateElementRequest request;
-
- /** the editing domain. */
- private TransactionalEditingDomain domain;
-
- /** The element to create is represented by this field. */
- private NewElementRepresentation elementToCreate;
-
- /** this Set contains names to exclude from the proposed name. */
- private List<String> forbiddenNames;
-
- /**
- * Constructor.
- *
- * @param parent
- * the parent
- * @param domain
- * the domain
- * @param labelProvider
- * the label provider
- * @param contentProvider
- * the content provider
- * @param pack
- * the pack
- * @param hintedType
- * the hinted type
- */
- public CreateUmlElementDialog(Shell parent, TransactionalEditingDomain domain, ILabelProvider labelProvider, ITreeContentProvider contentProvider, Package pack, IHintedType hintedType) {
- super(parent, labelProvider, contentProvider);
- Assert.isNotNull(pack);
- Assert.isNotNull(hintedType);
- this.pack = pack;
- this.hintedType = hintedType;
- this.domain = domain;
- init();
- }
-
- /**
- * Initializes the field {@link #type};.
- */
- protected void init() {
- EClass eClass = hintedType.getEClass();
- this.type = eClass.getName();
- this.parentContainer = null;
- this.forbiddenNames = null;
- }
-
- /**
- * Sets the forbidden names.
- *
- * @param forbiddenNames
- * the new forbidden names
- */
- public void setForbiddenNames(List<String> forbiddenNames) {
- this.forbiddenNames = forbiddenNames;
- }
-
- /**
- * Creates the dialog area.
- *
- * @param parent
- * the parent
- * @return the control
- * @see org.eclipse.ui.dialogs.ElementTreeSelectionDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
- */
- @Override
- protected Control createDialogArea(Composite parent) {
-
- GridData data = (GridData)parent.getLayoutData();
- data.grabExcessHorizontalSpace = true;
- data.horizontalSpan = 1;
- data.horizontalAlignment = SWT.FILL;
- data.verticalAlignment = SWT.FILL;
- Composite composite = (Composite)super.createDialogArea(parent);
- composite.setLayout(new GridLayout());
- GridData dat = new GridData(GridData.FILL_BOTH);
- composite.setLayoutData(dat);
- createNameSection(parent);
-
- return composite;
- }
-
- /**
- * Creates the name section and put it at the top of the composite.
- *
- * @param parent
- * the composite parent
- */
- protected void createNameSection(Composite parent) {
-
- Composite nameSection = new Composite(parent, SWT.NONE);
-
- //the label
- Label label = new Label(nameSection, SWT.NONE);
- label.setText(Messages.CreateUmlElementDialog_New_Element_Name);
-
- //the text field
- text = new Text(nameSection, SWT.BORDER);
- text.setText(getDefaultName());
- GridData textData = new GridData(GridData.FILL_HORIZONTAL);
- text.setLayoutData(textData);
-
- //layout for the nameSection
- GridLayout layout = new GridLayout(2, false);
- GridData data = new GridData(GridData.FILL_BOTH);
- nameSection.setLayout(layout);
- nameSection.setLayoutData(data);
-
- //we set the name section in first!
- nameSection.moveAbove(null);
- }
-
- /**
- * Returns the default name for the new Element.
- *
- * @return the default name
- * the default name for the new Element
- */
- protected String getDefaultName() {
-
- boolean existsInterface = false;
- String defaultName;
- int max = 0;
- do {
-
- List<Interface> allInterface = ElementUtil.getInstancesFilteredByType(pack, Interface.class, null);
- for(Object object : allInterface) {
- String name = NamedElementUtil.getName((NamedElement)object);
- if(name != null && name.startsWith(type)) {
- name = name.substring(type.length());
- Integer val = null;
- try {
- val = Integer.parseInt(name);
- } catch (NumberFormatException e) {
- //Nothing to do
- }
- if(val != null) {
- max = Math.max(Integer.valueOf(val), max);
- existsInterface = true;
- }
- }
- }
- if(existsInterface) {
- defaultName = type + new Integer(max + 1).toString();
- } else {
- defaultName = type + new Integer(max).toString();
- }
- max++;
- } while(!isCorrectName(defaultName));
- return defaultName;
- }
-
- /**
- * Tests if the proposed name is not forbidden
- *
- * @param name
- * a name
- * @return
- * <code>true</code> if the proposed name is not forbidden
- */
- protected boolean isCorrectName(String name) {
- if(forbiddenNames == null) {
- return true;
- }
- return !forbiddenNames.contains(name);
- }
-
- /**
- * Returns the command to create the new element which the chosen name.
- *
- * @return the command
- * the command to create the new element which the chosen name
- */
- public Command getCommand() {
-
- CompositeCommand cmd = new CompositeCommand("Create new element command"); //$NON-NLS-1$
- //request to create the new Interface
- if(elementToCreate.getCreateElementRequest() != null) {
- ICommand command = getCommand(elementToCreate.getCreateElementRequest());
- if(command.canExecute()) {
- cmd.add(command);
- SetNameCommand nameCommand = new SetNameCommand(domain, "Set Name Command", null, request, elementToCreate); //$NON-NLS-1$
- if(nameCommand.canExecute()) {
- cmd.add(nameCommand);
- }
- }
- return new ICommandProxy(cmd);
- } else {
- return new ICommandProxy(new CustomCreateElementCommand(domain, "CustomCreateElementCommand", null, elementToCreate)); //$NON-NLS-1$
- }
- }
-
- /**
- * Compute result.
- *
- * @see org.eclipse.ui.dialogs.ElementTreeSelectionDialog#computeResult()
- */
- @Override
- protected void computeResult() {
- java.util.List<Object> result = new ArrayList<Object>();
- result.add(elementToCreate);
- setResult(result);
- }
-
- /**
- * Set the value to {@link #name} and {@link #parentContainer}.
- *
- * @see org.eclipse.ui.dialogs.SelectionStatusDialog#okPressed()
- */
- @Override
- protected void okPressed() {
- ISelection selection = getTreeViewer().getSelection();
- parentContainer = ((IStructuredSelection)selection).getFirstElement();
- CreateElementRequest request = null;
- if(parentContainer instanceof EObject) {
- request = new CreateElementRequest(domain, (EObject)parentContainer, this.hintedType);
- }
- elementToCreate = new NewElementRepresentation(this.text.getText(), parentContainer, hintedType, request);
- super.okPressed();
- }
-
- /**
- * Returns a command corresponding to this request.
- *
- * @param request
- * a request
- * @return the command
- * The command corresponding to this request or an {@link UnexecutableCommand} when the command can not be build
- */
- private ICommand getCommand(IEditCommandRequest request) {
- IElementEditService provider = ElementEditServiceUtils.getCommandProvider(UMLPackage.eINSTANCE.getNamedElement());
- {
- if(provider != null) {
- ICommand cmd = provider.getEditCommand(request);
- if(cmd != null && cmd.canExecute()) {
- return cmd;
- }
- }
- }
- return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE;
- }
-
- /**
- * This command is used to set the chosen name to the new element.
- */
- public class SetNameCommand extends AbstractTransactionalCommand {
-
- /** the representation that will own the new element when it will be created. */
- private NewElementRepresentation representation;
-
- /**
- * Constructor.
- *
- * @param domain
- * the domain
- * @param label
- * the label
- * @param affectedFiles
- * the affected files
- * @param previousRequest
- * the previous request
- * @param representation
- * the representation
- */
- public SetNameCommand(TransactionalEditingDomain domain, String label, List<?> affectedFiles, CreateElementRequest previousRequest, NewElementRepresentation representation) {
- super(domain, label, affectedFiles);
- this.representation = representation;
- }
-
- /**
- * Do execute with result.
- *
- * @param monitor
- * the monitor
- * @param info
- * the info
- * @return the command result
- * @throws ExecutionException
- * the execution exception
- * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor,
- * org.eclipse.core.runtime.IAdaptable)
- */
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- if(representation.getEObject() instanceof NamedElement) {
- NamedElement el = (NamedElement)representation.getEObject();
- el.setName(representation.getName());
- }
-
- return CommandResult.newOKCommandResult(representation);
- }
-
- }
-
- /**
- * This command allows to create a new element when its parent is not yet created when the command is build
- *
- * We need a such command, because {@link CreateRelationshipCommand#getCommandResult()} return <code>null</code> when the command has not been
- * executed.
- */
- public class CustomCreateElementCommand extends AbstractTransactionalCommand {
-
- /** the representation of the element to create. */
- private NewElementRepresentation elementToCreate;
-
- /**
- * Constructor.
- *
- * @param domain
- * the domain
- * @param label
- * the label
- * @param affectedFiles
- * the affected files
- * @param elementToCreate
- * the element to create
- */
- public CustomCreateElementCommand(TransactionalEditingDomain domain, String label, List<?> affectedFiles, NewElementRepresentation elementToCreate) {
- super(domain, label, affectedFiles);
- this.elementToCreate = elementToCreate;
- }
-
- /**
- * Do execute with result.
- *
- * @param monitor
- * the monitor
- * @param info
- * the info
- * @return the command result
- * @throws ExecutionException
- * the execution exception
- * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor,
- * org.eclipse.core.runtime.IAdaptable)
- */
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- EObject container = elementToCreate.getEObjectParent();
- CreateElementRequest request = new CreateElementRequest(domain, container, hintedType);
- ICommand command = getCommand(request);
- command.execute(new NullProgressMonitor(), null);
- EObject newEl = request.getNewElement();
-
- if(newEl instanceof NamedElement) {
- ((NamedElement)newEl).setName(elementToCreate.getName());
- }
-
- elementToCreate.setCreateElement(request.getNewElement());
- return CommandResult.newOKCommandResult(elementToCreate);
- }
- }
-}
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/ui/InterfaceManagerDialog.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/ui/InterfaceManagerDialog.java
deleted file mode 100644
index 8420500dccf..00000000000
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/ui/InterfaceManagerDialog.java
+++ /dev/null
@@ -1,1008 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.sysml.diagram.internalblock.ui;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.CompoundCommand;
-import org.eclipse.gef.commands.UnexecutableCommand;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.AbstractEditCommandRequest;
-import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
-import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
-import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
-import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
-import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
-import org.eclipse.papyrus.infra.widgets.editors.IElementSelector;
-import org.eclipse.papyrus.infra.widgets.editors.SelectionEditor;
-import org.eclipse.papyrus.infra.widgets.providers.AbstractStaticContentProvider;
-import org.eclipse.papyrus.infra.widgets.selectors.ReferenceSelector;
-import org.eclipse.papyrus.sysml.diagram.internalblock.messages.Messages;
-import org.eclipse.papyrus.sysml.portandflows.FlowSpecification;
-import org.eclipse.papyrus.uml.diagram.common.Activator;
-import org.eclipse.papyrus.uml.diagram.common.util.Util;
-import org.eclipse.papyrus.uml.diagram.common.util.Visitor;
-import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
-import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CLabel;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.dialogs.ISelectionStatusValidator;
-import org.eclipse.ui.dialogs.SelectionDialog;
-import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.Dependency;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.Interface;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.Namespace;
-import org.eclipse.uml2.uml.Package;
-import org.eclipse.uml2.uml.Port;
-import org.eclipse.uml2.uml.Realization;
-import org.eclipse.uml2.uml.UMLPackage;
-import org.eclipse.uml2.uml.Usage;
-import org.eclipse.uml2.uml.util.UMLUtil;
-
-/**
- * <pre>
- * This class provides a Dialog to manage easily the provided and
- * the required Interfaces for a {@link Port}.
- * </pre>
- */
-public class InterfaceManagerDialog extends SelectionDialog {
-
- /** the selected port */
- private Port port;
-
- /** the list of the provided interfaces */
- private List<Object> providedInterfaces;
-
- /** the list of the required interfaces */
- private List<Object> requiredInterfaces;
-
- /** the {@link ReferenceSelector} for the provided interfaces */
- private ReferenceSelector providedSelector;
-
- /** the {@link ReferenceSelector} for the required interfaces */
- private ReferenceSelector requiredSelector;
-
- /** the Editor for the provided interfaces */
- private SelectionEditor providedEditor;
-
- /** the Editor for the required interfaces */
- private SelectionEditor requiredEditor;
-
- /**
- * In this map, we link the {@link Interface} with their {@link Usage} This map is used when we want remove an Interface from a Usage
- */
- private Map<Interface, List<Usage>> requiredInterfacesMappedWithUsage = new HashMap<Interface, List<Usage>>();
-
- /**
- * In this map, we link the {@link Interface} with their {@link Realization} This map is used when we want remove an Interface from a Realization
- */
- private Map<Interface, List<Realization>> providedInterfacesMappedWithRealization = new HashMap<Interface, List<Realization>>();
-
- /** the label provider for selector */
- private final ILabelProvider selectorLabelProvider = new SelectorLabelProvider();
-
- /** the label provider for the create new element dialog */
- private final ILabelProvider newElementLabelProvider = new CreateElementLabelProvider();
-
- /** the domain used for the commands */
- private TransactionalEditingDomain domain;
-
- /** the model */
- private Package model = null;
-
- /** this command contains the list of the command to create the new Interfaces */
- private CompoundCommand interfaceCreationCommand = new CompoundCommand("Create Interfaces Commands"); //$NON-NLS-1$
-
- /** This list contains representation of the Interface before their creation */
- private List<NewElementRepresentation> interfaceRepresentations;
-
- /** boolean used to know if the {@link Port} is typed with an {@link Interface} */
- private boolean typedWithInterface;
-
- /** path for the warning icons */
- private static final String ICON_WARNING = "/icons/warning.gif"; //$NON-NLS-1$
-
- /**
- * This list contains the names used for the new elements.
- * We need to remember these names are used in order don't suggest them when we create other new elements
- */
- private List<String> forbiddenNames;
-
- /**
- *
- * Constructor.
- *
- * @param parentShell
- * the parent {@link Shell}
- * @param port
- * the {@link Port} for which we want manage the Interfaces
- */
- public InterfaceManagerDialog(Shell parentShell, Port port) {
- super(parentShell);
- this.setTitle(Messages.InterfaceManagerDialog_Title);
- this.port = port;
- Assert.isTrue(this.port.getType() instanceof Classifier);
- this.typedWithInterface = (this.port.getType() instanceof Interface);
- }
-
- /**
- *
- * @see org.eclipse.jface.dialogs.Dialog#create()
- *
- */
- @Override
- public void create() {
- super.create();
- init();
- }
-
- /**
- * This method initialize some fields of the class
- */
- protected void init() {
-
- this.forbiddenNames = new ArrayList<String>();
- this.interfaceRepresentations = new ArrayList<NewElementRepresentation>();
- EList<Namespace> namespaces = port.allNamespaces();
- Element el = namespaces.get(namespaces.size() - 1);
- if(el instanceof Package) {
- model = (Package)el;
- } else {
- model = el.getNearestPackage();
- }
-
- //fill the hashmap to link Interfaces with Usage and InterfaceRealization
- buildProvidedInterfaces();
- buildRequiredInterfaces();
-
- //we build the list of the provided interfaces
- this.providedInterfaces = new ArrayList<Object>();
- for(Interface current : this.port.getProvideds()) {
- this.providedInterfaces.add(current);
- }
- //when the port is typed by an Interface, we don't propose this interface in the possible Provided Interfaces list.
- if(typedWithInterface) {
- this.providedInterfaces.remove(this.port.getType());
- }
-
- //we build the list of the required interfaces
- this.requiredInterfaces = new ArrayList<Object>();
- for(Interface current : this.port.getRequireds()) {
- this.requiredInterfaces.add(current);
- }
-
- //initialize the transactional editing domain
- IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- IEditorPart editor = activePage.getActiveEditor();
- if(editor instanceof IMultiDiagramEditor) {
- try {
- this.domain = ServiceUtils.getInstance().getTransactionalEditingDomain(((IMultiDiagramEditor)editor).getServicesRegistry());
- } catch (ServiceException e) {
- e.printStackTrace();
- }
- }
-
- //selectors creation
- createSelectors();
- //editors creation
- createEditors();
-
- }
-
- /**
- * This method fills the map {@link #requiredInterfacesMappedWithUsage}
- */
- protected void buildRequiredInterfaces() {
- List<?> allUsage = Util.getInstancesFilteredByType(this.model, Usage.class, null);
- List<Classifier> classifiers = new ArrayList<Classifier>();
- classifiers.add((Classifier)this.port.getType());
-
- classifiers.addAll(Util.getAllSuperClasses(null, (Classifier)this.port.getType()));
-
- for(Object current : allUsage) {
- Usage usage = (Usage)current;
- for(Classifier classifier : classifiers) {//we test if the current Usage is linked with the type of the Port
- if(usage.getClients().contains(classifier)) {//this Usage concerns the current port
- for(EObject target : usage.getSuppliers()) {
- if(this.port.getRequireds().contains(target)) {
- List<Usage> usages = requiredInterfacesMappedWithUsage.get(target);
- if(usages != null) {
- usages.add(usage);
- } else {
- usages = new ArrayList<Usage>();
- usages.add(usage);
- this.requiredInterfacesMappedWithUsage.put((Interface)target, usages);
- }
- }
- }
- break;
- }
- }
- }
- }
-
- /**
- * This method fills the map {@link #providedInterfacesMappedWithRealization}
- */
- protected void buildProvidedInterfaces() {
- List<?> allRealization = Util.getInstancesFilteredByType(this.model, Realization.class, null);
- List<Classifier> classifiers = new ArrayList<Classifier>();
- classifiers.add((Classifier)this.port.getType());
-
- classifiers.addAll(Util.getAllSuperClasses(null, (Classifier)this.port.getType()));
-
- for(Object current : allRealization) {
- Realization realization = (Realization)current;
- for(Classifier classifier : classifiers) {//we test if the current Realization is linked with the type of the Port
- if(realization.getClients().contains(classifier)) {//this Realization concerns the current port
- for(EObject target : realization.getSuppliers()) {
- if(this.port.getProvideds().contains(target)) {
- List<Realization> realizations = providedInterfacesMappedWithRealization.get(target);
- if(realizations != null) {
- realizations.add(realization);
- } else {
- realizations = new ArrayList<Realization>();
- realizations.add(realization);
- this.providedInterfacesMappedWithRealization.put((Interface)target, realizations);
- }
- }
- }
- break;
- }
- }
- }
- }
-
- /**
- * This method creates the selectors {@link #providedSelector} and {@link #requiredSelector}
- */
- protected void createSelectors() {
- //the provided selector
- this.providedSelector = new ReferenceSelector(true);
- this.providedSelector.setLabelProvider(selectorLabelProvider);
- this.providedSelector.setContentProvider(new AbstractStaticContentProvider() {
-
- /**
- *
- * @see org.eclipse.papyrus.editors.providers.IStaticContentProvider#getElements()
- *
- * @return
- */
- public Object[] getElements() {
- List<Object> tmp = new ArrayList<Object>();
- tmp.addAll(getAllAvailableInterfaces(model));
- if(typedWithInterface) {
- tmp.remove(port.getType());
- }
- //we add the new interfaces which are not yet created
- tmp.addAll(interfaceRepresentations);
- return tmp.toArray();
- }
- });
- //the required selector
- this.requiredSelector = new ReferenceSelector(true);
- this.requiredSelector.setLabelProvider(selectorLabelProvider);
- this.requiredSelector.setContentProvider(new AbstractStaticContentProvider() {
-
- /**
- *
- * @see org.eclipse.papyrus.editors.providers.IStaticContentProvider#getElements()
- *
- * @return
- */
- public Object[] getElements() {
- List<Object> tmp = new ArrayList<Object>();
- tmp.addAll(getAllAvailableInterfaces(model));
-
- //we add the new interfaces which are not yet created
- tmp.addAll(interfaceRepresentations);
- return tmp.toArray();
- }
- });
- }
-
- /**
- * This method create the 2 Editors {@link #providedEditor} and {@link #requiredEditor} and provides the listener for the button of these editors
- */
- protected void createEditors() {
- Composite parent = (Composite)getDialogArea();
- CreateButtonListener listener = new CreateButtonListener();
- //we set a specific message if the port is typed with an Interface
- if(typedWithInterface) {
- Composite messageSection = new Composite(parent, SWT.BORDER);
- CLabel label = new CLabel(messageSection, SWT.NONE);
-
- label.setText(Messages.InterfaceManagerDialog_ThePortIsTypedWithAnInterfaceWarningMessage);
- Image errorImage = Activator.getPluginIconImage(Activator.ID, ICON_WARNING);
- label.setImage(errorImage);
- GridLayout layout = new GridLayout(1, true);
- GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
- messageSection.setLayout(layout);
- messageSection.setLayoutData(data);
- messageSection.setEnabled(false);
- }
- this.providedEditor = createEditor(parent, providedSelector, Messages.InterfaceManagerDialog_SelectedTheProvidedInterfaces, false, listener, this.providedInterfaces);
- this.requiredEditor = createEditor(parent, requiredSelector, Messages.InterfaceManagerDialog_SelectTheRequiredInterfaces, true, listener, this.requiredInterfaces);
-
- this.providedEditor.create();
- this.requiredEditor.create();
-
- GridLayout layout = (GridLayout)parent.getLayout();
- layout.numColumns = 1;
- layout.makeColumnsEqualWidth = true;
- GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
- this.providedEditor.setLayoutData(data);
- this.requiredEditor.setLayoutData(data);
- getShell().setSize(950, 700);
- getShell().layout();
- }
-
- /**
- * Creates a {@link SelectionEditor} and returns it
- *
- * @param parent
- * the composite parent
- * @param selector
- * the selector used by the created editor
- * @param message
- * the message to display in the created editor
- * @param withCreateButton
- * indicates if the editor provides an additional button for a specific action
- * @param listener
- * the listener for the button
- * @param initialSelection
- * the initial selection for this editor
- * @return
- * the created {@link SelectionEditor}
- */
- protected SelectionEditor createEditor(Composite parent, IElementSelector selector, String message, boolean withCreateButton, SelectionListener listener, List<Object> initialSelection) {
- SelectionEditor editor = new SelectionEditor(parent, selector, selectorLabelProvider, initialSelection);
- editor.setMessage(message);
- editor.setAdditionalButton(withCreateButton, Messages.InterfaceManagerDialog_CreateNewInterface, listener);
- return editor;
- }
-
- /**
- * Returns all the available Interfaces (except {@link FlowSpecification})
- *
- * @return
- * all the available Interfaces
- * //TODO add the interfaces from the package import!
- */
- protected List<Interface> getAllAvailableInterfaces(Package pack) {
- List<Interface> otherInterfaces = new ArrayList<Interface>();
- List<Element> interfaces = Visitor.getOwnedAndImportedElement(pack, Interface.class);
- for(Namespace namespace : Visitor.getOwnedAndImportedNamespaces(pack)) {
- interfaces.addAll(Visitor.getOwnedAndImportedElement(namespace, Interface.class));
-
- }
-
- for(Element element : interfaces) {
- // Test if the interface is a FlowSpecification
- FlowSpecification flowSpec = UMLUtil.getStereotypeApplication(element, FlowSpecification.class);
- if(flowSpec == null) {
- otherInterfaces.add((Interface)element);
- }
- }
-
- return otherInterfaces;
- }
-
- /**
- * Returns the commands to apply the changes
- *
- * @return
- * the commands to apply the changes
- */
- public Command getCommand() {
- CompoundCommand command = new CompoundCommand("Command to manage interfaces on Port"); //$NON-NLS-1$
- if(!interfaceCreationCommand.isEmpty()) {
- command.add(interfaceCreationCommand);
- }
- Command cmd = getCommandsToCreateElements();
- if(cmd.canExecute()) {
- command.add(cmd);
- }
- cmd = getCommandToRemoveReferencedInterfaces();
- if(cmd.canExecute()) {
- command.add(cmd);
- }
- return command;
- }
-
- /**
- * Returns the command to remove referenced Interfaces in Usage and InterfaceRealization
- *
- * @return
- * The command to remove referenced Interfaces the Usage and InterfaceRealization.
- * Moreover, we add a command to destroy Usage and InterfaceRealization when they have any Suppliers after this action
- */
- protected Command getCommandToRemoveReferencedInterfaces() {
- CompoundCommand command = new CompoundCommand("Command to destroy Usage and InterfaceRealization"); //$NON-NLS-1$
-
- Set<Dependency> relationshipToDestroy = new HashSet<Dependency>();
- //commands to destroy Usage
- for(Object current : this.requiredEditor.getElementToRemove()) {
- //we get all usage associated with this interface
- List<Usage> usages = requiredInterfacesMappedWithUsage.get(current);
- for(Usage currentUsage : usages) {
- //we remove the reference to the Interface in the Usage
- DestroyReferenceRequest request = new DestroyReferenceRequest(domain, currentUsage, UMLPackage.eINSTANCE.getDependency_Supplier(), (EObject)current, false);
- Command cmd = getCommand(request);
- if(cmd.canExecute()) {
- command.add(cmd);
- relationshipToDestroy.add(currentUsage);
- }
- }
- }
-
- //commands to destroy InterfaceRealization
- for(Object current : this.providedEditor.getElementToRemove()) {
- //we get all usage associated with this interface
- List<Realization> realizations = providedInterfacesMappedWithRealization.get(current);
- for(Realization currentRealization : realizations) {
- //we remove the reference to the Interface in the Usage
- DestroyReferenceRequest request = new DestroyReferenceRequest(domain, currentRealization, UMLPackage.eINSTANCE.getDependency_Supplier(), (EObject)current, false);
- Command cmd = getCommand(request);
- if(cmd.canExecute()) {
- command.add(cmd);
- relationshipToDestroy.add(currentRealization);
- }
- }
- }
- if(!relationshipToDestroy.isEmpty()) {
- command.add(new ICommandProxy(new DestroyDependencyWithoutSupplierCommand(this.domain, null, relationshipToDestroy)));
- return command;
- }
-
- //nothing to do
- return UnexecutableCommand.INSTANCE;
- }
-
- /**
- * Returns the command to create new Usage and new InterfaceRealization
- *
- * @return
- * the command to create new Usage and new InterfaceRealization
- */
- protected Command getCommandsToCreateElements() {
- CompoundCommand command = new CompoundCommand("Command to create Usage and InterfaceRealization"); //$NON-NLS-1$
- //commands for Usage Creation
- for(Object current : this.requiredEditor.getElementToAdd()) {
- if(current instanceof EObject) {
- CreateRelationshipRequest request =
- new CreateRelationshipRequest(this.port.getType().eContainer(), this.port.getType(), (EObject)current, org.eclipse.papyrus.uml.service.types.element.UMLElementTypes.USAGE);
- Command cmd = getCommand(request);
- if(cmd.canExecute()) {
- command.add(cmd);
- }
- } else {//its an NewElementRepresentation
-
- CreateUsageCommand cmd = new CreateUsageCommand(this.domain, this.port.getType().eContainer(), this.port.getType(), (NewElementRepresentation)current, null);
- if(cmd.canExecute()) {
- command.add(new ICommandProxy(cmd));
- }
- }
- }
-
- //commands for InterfaceRealization Creation
- for(Object current : providedEditor.getElementToAdd()) {
- if(current instanceof EObject) {
- CreateRelationshipRequest request =
- new CreateRelationshipRequest(this.port.getType().eContainer(), this.port.getType(), (EObject)current, org.eclipse.papyrus.uml.service.types.element.UMLElementTypes.INTERFACE_REALIZATION);
- Command cmd = getCommand(request);
- if(cmd.canExecute()) {
- command.add(cmd);
- }
- } else {//its an NewElementRepresentation
- CreateInterfaceRealizationCommand cmd =
- new CreateInterfaceRealizationCommand(this.domain, this.port.getType().eContainer(), this.port.getType(), (NewElementRepresentation)current, null);
- if(cmd.canExecute()) {
- command.add(new ICommandProxy(cmd));
- }
- }
- }
- if(!command.isEmpty()) {
- return command;
- }
- return UnexecutableCommand.INSTANCE;
- }
-
- /**
- * Return the command corresponding to the request
- *
- * @param req
- * a request
- * @return
- * the command corresponding to the request
- */
- protected Command getCommand(AbstractEditCommandRequest req) {
- IElementEditService provider = ElementEditServiceUtils.getCommandProvider(model);
- if(provider != null) {
- ICommand setCommand = provider.getEditCommand(req);
- if(setCommand != null) {
- return new ICommandProxy(setCommand.reduce());
- }
- }
- return UnexecutableCommand.INSTANCE;
- }
-
- /**
- * This listener is used to know when the user clicks on the Button to create a new {@link Interface}
- *
- *
- *
- */
- public class CreateButtonListener implements SelectionListener {
-
- /**
- *
- * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
- *
- * @param e
- */
- public void widgetSelected(SelectionEvent e) {
- CreateUmlElementDialog dialog = new CreateUmlElementDialog(getShell(), domain, newElementLabelProvider, new CustomContentProvider(), model, UMLElementTypes.INTERFACE);
- dialog.setTitle(Messages.InterfaceManagerDialog_CreateANewInterface);
- dialog.setMessage(Messages.InterfaceManagerDialog_SelectTheParentOfThisNewInterface);
- dialog.setHelpAvailable(false);
- dialog.setForbiddenNames(forbiddenNames);
- List<Object> input = new ArrayList<Object>();
- input.add(model);
- dialog.setInput(input);
- dialog.setValidator(new ParentInterfaceValidator());
- if(dialog.open() == org.eclipse.jface.dialogs.Dialog.OK) {
- interfaceCreationCommand.add(dialog.getCommand());
- Object[] res = dialog.getResult();
- for(Object current : res) {
- if(current instanceof NewElementRepresentation) {
- interfaceRepresentations.add((NewElementRepresentation)current);
- forbiddenNames.add(((NewElementRepresentation)current).getName());
- }
- }
- providedSelector.refresh();
- requiredSelector.refresh();
- }
- }
-
- /**
- *
- * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
- *
- * @param e
- */
- public void widgetDefaultSelected(SelectionEvent e) {
-
- }
-
- }
-
- /**
- *
- * This class provides a validator for the selection of the parent of the new Interface
- *
- *
- */
- public class ParentInterfaceValidator implements ISelectionStatusValidator {
-
- /**
- * Selection has to be a Classifier or an Interface to allow creation
- *
- * @see org.eclipse.ui.dialogs.ISelectionStatusValidator#validate(java.lang.Object[])
- *
- * @param selection
- * @return
- */
- public IStatus validate(Object[] selection) {
-
- IStatus status = new Status(IStatus.ERROR, org.eclipse.papyrus.sysml.diagram.internalblock.Activator.PLUGIN_ID, Messages.NoSelectionFound);
- if(selection.length >= 1) {
- for(int i = 0; i < selection.length; i++) {
- if(selection[i] instanceof Package || selection[i] instanceof Classifier || selection[i] instanceof NewElementRepresentation)
- status = new Status(IStatus.OK, org.eclipse.papyrus.sysml.diagram.internalblock.Activator.PLUGIN_ID, Messages.SelectionValidated);
- else {
- status = new Status(IStatus.ERROR, org.eclipse.papyrus.sysml.diagram.internalblock.Activator.PLUGIN_ID, Messages.InterfaceManagerDialog_SelectionHasToBeAPackageOrAClassifier);
- break;
- }
- }
- }
- return status;
- }
- }
-
- /**
- *
- * This class provides a CustomLabelProvider for this dialog.
- * This class manages the {@link NewElementRepresentation} and consider them like Interfaces
- *
- *
- */
- public class SelectorLabelProvider extends CreateElementLabelProvider {
-
- /**
- *
- * @see org.eclipse.papyrus.uml.diagram.common.providers.EditorLabelProvider#getText(java.lang.Object)
- *
- * @param element
- * @return
- */
- @Override
- public String getText(Object element) {
- if(element instanceof NewElementRepresentation) {
- return ((NewElementRepresentation)element).getQualifiedName();
- } else if(element instanceof NamedElement) {
- return ((NamedElement)element).getQualifiedName();
- }
- return super.getText(element);
- }
-
- }
-
- public class CreateElementLabelProvider extends UMLLabelProvider {
-
- /**
- *
- * @see org.eclipse.papyrus.uml.diagram.common.providers.EditorLabelProvider#getImage(java.lang.Object)
- *
- * @param element
- * @return
- */
- @Override
- public Image getImage(Object element) {
- if(element instanceof NewElementRepresentation) {
- return org.eclipse.papyrus.uml.tools.Activator.getDefault().getImageForUMLMetaclass(UMLPackage.eINSTANCE.getInterface());
- }
- return super.getImage(element);
- }
-
- /**
- *
- * @see org.eclipse.papyrus.uml.diagram.common.providers.EditorLabelProvider#getText(java.lang.Object)
- *
- * @param element
- * @return
- */
- @Override
- public String getText(Object element) {
- if(element instanceof NewElementRepresentation) {
- return ((NewElementRepresentation)element).getName();
- }
- return super.getText(element);
- }
-
- }
-
- /**
- *
- * This content provider is used in this dialog. It returns the available element in the model + the future element which are
- * {@link NewElementRepresentation}
- *
- *
- */
- public class CustomContentProvider implements ITreeContentProvider {
-
- /**
- *
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- *
- */
- public void dispose() {
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
- *
- * @param viewer
- * @param oldInput
- * @param newInput
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)
- *
- * @param inputElement
- * @return
- */
- public Object[] getElements(Object inputElement) {
- if(inputElement instanceof List<?>) {
- return ((List<?>)inputElement).toArray();
- }
- return new Object[0];
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
- *
- * @param parentElement
- * @return
- */
- public Object[] getChildren(Object parentElement) {
- List<Object> children = new ArrayList<Object>();
- List<?> tmp = null;
- if(parentElement instanceof Package) {
- tmp = ((Package)parentElement).getOwnedMembers();
- } else if(parentElement instanceof Classifier) {
- tmp = ((Classifier)parentElement).getOwnedMembers();
- }
- if(tmp != null) {
- for(Object current : tmp) {
- if(current instanceof Classifier || current instanceof Package) {
- children.add(current);
- }
- }
- }
- //we add the future Interfaces to this selection
- for(NewElementRepresentation current : interfaceRepresentations) {
- if(current.getParent() == parentElement) {
- children.add(current);
- }
- }
- return children.toArray();
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
- *
- * @param element
- * @return
- */
- public Object getParent(Object element) {
- if(element == model) {
- return model;
- } else if(element instanceof NamedElement) {
- return ((NamedElement)element).eContainer();
- }
- return null;
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
- *
- * @param element
- * @return
- */
- public boolean hasChildren(Object element) {
- return getChildren(element).length != 0;
- }
-
- }
-
- /**
- *
- * This command is used to create a New Usage, when its target (an Interface) doesn't exist when the command is created
- * (but this Interface will exist when the command will be executed)
- *
- *
- */
- public class CreateUsageCommand extends AbstractTransactionalCommand {
-
- /** The container for the new Usage */
- private EObject container;
-
- /** the source of this Usage */
- private EObject source;
-
- /** the target : the representation of the new interface */
- private NewElementRepresentation target;
-
- /**
- *
- * Constructor.
- *
- * @param domain
- * the domain
- * @param container
- * the container for the Usage
- * @param source
- * the source for the Usage
- * @param target
- * the target for the Usage
- * @param affectedFiles
- * the affected files
- */
- public CreateUsageCommand(TransactionalEditingDomain domain, EObject container, EObject source, NewElementRepresentation target, List<?> affectedFiles) {
- super(domain, "Create Usage Command", affectedFiles); //$NON-NLS-1$
- this.container = container;
- this.source = source;
- this.target = target;
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor,
- * org.eclipse.core.runtime.IAdaptable)
- *
- * @param monitor
- * @param info
- * @return
- * @throws ExecutionException
- */
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- CreateRelationshipRequest request = new CreateRelationshipRequest(domain, container, source, target.getEObject(), UMLElementTypes.USAGE);
- Command command = getCommand(request);
- if(command.canExecute()) {
- command.execute();
- }
- return CommandResult.newOKCommandResult(request.getNewElement());
- }
-
- }
-
- /**
- *
- * This command is used to create a New InterfaceRealition, when its target (an Interface) doesn't exist when the command is created
- * (but this Interface will exist when the command will be executed)
- *
- *
- */
- public class CreateInterfaceRealizationCommand extends AbstractTransactionalCommand {
-
- /** The container for the new InterfaceRealization */
- private EObject container;
-
- /** The source for the new InterfaceRealization */
- private EObject source;
-
- /** the target : the representation of the new interface */
- private NewElementRepresentation target;
-
- /**
- *
- * Constructor.
- *
- * @param domain
- * the domain
- * @param container
- * the container for the InterfaceRealization
- * @param source
- * the source for the InterfaceRealization
- * @param target
- * the target for the InterfaceRealization
- * @param affectedFiles
- * the affected files
- */
- public CreateInterfaceRealizationCommand(TransactionalEditingDomain domain, EObject container, EObject source, NewElementRepresentation target, List<?> affectedFiles) {
- super(domain, "Create InterfaceRealization Command", affectedFiles); //$NON-NLS-1$
- this.container = container;
- this.source = source;
- this.target = target;
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor,
- * org.eclipse.core.runtime.IAdaptable)
- *
- * @param monitor
- * @param info
- * @return
- * @throws ExecutionException
- */
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
-
- CreateRelationshipRequest request = new CreateRelationshipRequest(domain, container, source, target.getEObject(), UMLElementTypes.INTERFACE_REALIZATION);
- Command command = getCommand(request);
- if(command.canExecute()) {
- command.execute();
- }
- return CommandResult.newOKCommandResult(request.getNewElement());
- }
-
- }
-
- /**
- *
- * This command is used to destroy Dependencies which have any supplier before the deletion of the Interface
- *
- *
- */
- public class DestroyDependencyWithoutSupplierCommand extends AbstractTransactionalCommand {
-
- /**
- * the dependencies to test
- */
- private Set<Dependency> dependencies;
-
- /**
- *
- * Constructor.
- *
- * @param domain
- * the domain
- * @param affectedFiles
- * the affected files
- * @param dependencies
- * the dependencies to test
- */
- public DestroyDependencyWithoutSupplierCommand(TransactionalEditingDomain domain, List<?> affectedFiles, Set<Dependency> dependencies) {
- super(domain, "Destroy the empty elements", affectedFiles); //$NON-NLS-1$
- this.dependencies = dependencies;
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor,
- * org.eclipse.core.runtime.IAdaptable)
- *
- * @param monitor
- * @param info
- * @return
- * @throws ExecutionException
- */
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- CompoundCommand command = new CompoundCommand("Destroy relationship without suppliers"); //$NON-NLS-1$
- for(Dependency current : dependencies) {
- if(current.getSuppliers().isEmpty()) {
- DestroyElementRequest request = new DestroyElementRequest(domain, current, false);
- Command cmd = getCommand(request);
- if(cmd.canExecute()) {
- command.add(cmd);
- }
- }
- }
-
- if(!command.isEmpty() && command.canExecute()) {
- command.execute();
- }
- return CommandResult.newOKCommandResult();
- }
- }
-}
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/ui/InternalBlockInterfaceManagerDialog.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/ui/InternalBlockInterfaceManagerDialog.java
new file mode 100644
index 00000000000..4c835596ad9
--- /dev/null
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/ui/InternalBlockInterfaceManagerDialog.java
@@ -0,0 +1,76 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.sysml.diagram.internalblock.ui;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.papyrus.sysml.portandflows.FlowSpecification;
+import org.eclipse.papyrus.uml.diagram.common.dialogs.InterfaceManagerDialog;
+import org.eclipse.papyrus.uml.diagram.common.util.Visitor;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Interface;
+import org.eclipse.uml2.uml.Namespace;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Port;
+import org.eclipse.uml2.uml.util.UMLUtil;
+
+/**
+ * <pre>
+ * This class provides a Dialog to manage easily the provided and
+ * the required Interfaces for a {@link Port}.
+ * </pre>
+ */
+public class InternalBlockInterfaceManagerDialog extends InterfaceManagerDialog {
+
+
+ /**
+ * Constructor.
+ *
+ * @param parentShell
+ * @param port
+ */
+ public InternalBlockInterfaceManagerDialog(Shell parentShell, Port port) {
+ super(parentShell, port);
+ }
+
+ /**
+ * Returns all the available Interfaces (except {@link FlowSpecification})
+ *
+ * @return
+ * all the available Interfaces
+ * //TODO add the interfaces from the package import!
+ */
+ protected List<Interface> getAllAvailableInterfaces(Package pack) {
+ Set<Interface> otherInterfaces = new HashSet<Interface>();
+ List<Element> interfaces = Visitor.getOwnedAndImportedElement(pack, Interface.class);
+ for(Namespace namespace : Visitor.getOwnedAndImportedNamespaces(pack)) {
+ interfaces.addAll(Visitor.getOwnedAndImportedElement(namespace, Interface.class));
+
+ }
+
+ for(Element element : interfaces) {
+ // Test if the interface is a FlowSpecification
+ FlowSpecification flowSpec = UMLUtil.getStereotypeApplication(element, FlowSpecification.class);
+ if(flowSpec == null) {
+ otherInterfaces.add((Interface)element);
+ }
+ }
+
+ return Arrays.asList(otherInterfaces.toArray(new Interface[otherInterfaces.size()]));
+ }
+
+}
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/ui/NewElementRepresentation.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/ui/NewElementRepresentation.java
deleted file mode 100644
index 5d44337bb1f..00000000000
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/ui/NewElementRepresentation.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.sysml.diagram.internalblock.ui;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
-import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
-import org.eclipse.uml2.uml.NamedElement;
-
-/**
- * This class provides facilities to represent a New Element before its real creation.
- * We can store in this class :
- * <ul>
- * <li>the name of the new element</li>
- * <li>the parent of the new element</li>
- * <li>the {@link IHintedType} of the new element</li>
- * <li>the request to build the new element (optional)</li>
- * <li>the element itself when it has been created</li>
- * </ul>
- *
- *
- *
- */
-public class NewElementRepresentation {
-
- /** the name of the new element */
- private String name;
-
- /** the parent of the new element */
- private Object parent;
-
- /** the created element itself */
- private EObject createdElement;
-
- /** the {@link IHintedType} of the new element */
- private IHintedType hintedType;
-
- /** this field is used only when the element have an existing parent */
- private CreateElementRequest request;
-
- /**
- *
- * Constructor.
- *
- * @param name
- * the name of the new element
- * @param parent
- * the parent of the new element
- * @param hintedType
- * the hinted type of the new element
- * @param request
- * the request to build the new element (can be <code>null</code>)
- */
- public NewElementRepresentation(String name, Object parent, IHintedType hintedType, CreateElementRequest request) {
- this.name = name;
- this.parent = parent;
- this.createdElement = null;
- this.hintedType = hintedType;
- this.request = request;
- }
-
- /**
- * Getter for {@link #hintedType}
- *
- * @return
- * {@link #hintedType}
- */
- public IHintedType getHintedType() {
- return this.hintedType;
- }
-
- /**
- * Getter for {@link #name}
- *
- * @return
- * {@link #name}
- */
- public String getName() {
- return this.name;
- }
-
- /**
- * Getter for {@link #parent}
- *
- * @return
- * {@link #parent}
- */
- public Object getParent() {
- return this.parent;
- }
-
- /**
- * Returns the parent of this element
- *
- * @return
- * the parent of this element or <code>null</code> if the parent is a {@link NewElementRepresentation} itself and if it has not been
- * created
- */
- public EObject getEObjectParent() {
- if(parent instanceof EObject) {
- return (EObject)this.parent;
- } else if(parent instanceof NewElementRepresentation) {
- return ((NewElementRepresentation)parent).getEObject();
- }
- return null;
- }
-
- /**
- * Returns the created object
- *
- * @return
- * the created Object or <code>null</code> if the object has not been created
- */
- public EObject getEObject() {
- if(this.request != null) {
- return this.request.getNewElement();
- }
- return this.createdElement;
- }
-
- /**
- * Setter for {@link #createdElement}
- *
- * @param newElement
- *
- */
- public void setCreateElement(EObject newElement) {
- this.createdElement = newElement;
- }
-
- /**
- * Setter for {@link #request}
- *
- * @return
- * {@link #request}
- */
- public CreateElementRequest getCreateElementRequest() {
- return this.request;
- }
-
- /**
- *
- * @see java.lang.Object#toString()
- *
- * @return
- */
- @Override
- public String toString() {
- return "Name : " + this.name + ", parent : " + this.parent;
- }
-
- public String getQualifiedName() {
- String qualifiedName = "";
- if(parent instanceof NewElementRepresentation) {
- qualifiedName = ((NewElementRepresentation)parent).getQualifiedName();
- } else if(parent instanceof NamedElement) {
- qualifiedName = ((NamedElement)parent).getQualifiedName() + "::" + this.name;
- }
- return qualifiedName;
- }
-}

Back to the top