From 710fffcfa0d6982000e4c6ce048b032945f21ea3 Mon Sep 17 00:00:00 2001 From: Gabriel Pascual Date: Fri, 18 Jul 2014 14:44:15 +0200 Subject: 374050: [Properties view] Manage interfaces for ports does not refresh "provided" and "required" interfaces immediatly https://bugs.eclipse.org/bugs/show_bug.cgi?id=374050 Composite diagram : - Add adapter for derived attribute - Add actions (add and remove) on observable list of properties view - Connected menu action Interface Manager and Properties view - Refactor Manage interface Handler and UI - Fix several bugs about NewElementRepresentation handling during commands execution. - Clean dependencies after refactor - Manage strictly adapters Change-Id: I3635b1a94f53acb3ef592b741afe76c13d767093 Signed-off-by: Gabriel Pascual --- .../META-INF/MANIFEST.MF | 127 +- .../messages.properties | 21 +- .../plugin.xml | 26 +- .../BlockDefinitionManageInterfacesHandler.java | 38 + .../handler/ManageProvidedInterfacesHandler.java | 121 - .../diagram/blockdefinition/messages/Messages.java | 86 +- .../ui/BlockDefinitionInterfaceManagerDialog.java | 82 + .../blockdefinition/ui/CreateUmlElementDialog.java | 434 --- .../blockdefinition/ui/InterfaceManagerDialog.java | 1040 ------ .../ui/NewElementRepresentation.java | 172 - .../META-INF/MANIFEST.MF | 50 +- .../messages.properties | 27 +- .../plugin.xml | 2 +- .../InternalBlockManageInterfacesHandler.java | 46 + .../handler/ManageProvidedInterfacesHandler.java | 119 - .../diagram/internalblock/messages/Messages.java | 94 +- .../internalblock/ui/CreateUmlElementDialog.java | 433 --- .../internalblock/ui/InterfaceManagerDialog.java | 1008 ------ .../ui/InternalBlockInterfaceManagerDialog.java | 76 + .../internalblock/ui/NewElementRepresentation.java | 172 - .../META-INF/MANIFEST.MF | 3 +- .../messages.properties | 17 + .../papyrus/uml/diagram/common/Messages.java | 28 +- .../handlers/ManagePortInterfacesHandler.java | 172 + .../common/dialogs/CreateUmlElementDialog.java | 417 +++ .../common/dialogs/ExtendedSelectionEditor.java | 546 +++ .../dialogs/IPortInterfaceManagerDialog.java | 36 + .../common/dialogs/InterfaceManagerDialog.java | 1024 ++++++ .../common/dialogs/NewElementRepresentation.java | 173 + .../common/dialogs/SelectionEditorWrapper.java | 180 + .../actions/ComponentManageInterfacesHandler.java | 44 + .../actions/ManageProvidedInterfacesHandler.java | 114 - .../custom/command/CreateLollipopPortCommand.java | 99 +- .../component/custom/messages/Messages.java | 125 +- .../component/custom/messages/messages.properties | 39 +- .../custom/ui/ComponentInterfaceManagerDialog.java | 295 ++ .../custom/ui/CreateUmlElementDialog.java | 404 --- .../custom/ui/DisplayInterfaceMDialog.java | 257 -- .../custom/ui/ExtendedSelectionEditor.java | 545 --- .../custom/ui/InterfaceManagerDialog.java | 936 ------ .../custom/ui/NewElementRepresentation.java | 177 - .../plugin.xml | 1938 +++++------ .../META-INF/MANIFEST.MF | 162 +- .../actions/ManageProvidedInterfacesHandler.java | 112 - .../composite/custom/messages/Messages.java | 144 +- .../composite/custom/messages/messages.properties | 45 +- .../custom/ui/CreateUmlElementDialog.java | 404 --- .../custom/ui/InterfaceManagerDialog.java | 1008 ------ .../custom/ui/NewElementRepresentation.java | 172 - .../plugin.xml | 3542 ++++++++++---------- .../properties/modelelement/UMLModelElement.java | 599 ++-- .../tools/adapters/DerivedAttributeAdapter.java | 270 ++ .../uml/tools/adapters/PortTypeAdapter.java | 205 ++ .../DestroyDependencyWithoutSupplierCommand.java | 125 + .../ProvidedInterfaceObservableList.java | 323 +- .../RequiredInterfaceObservableList.java | 307 +- .../providers/PortInterfaceContentProvider.java | 97 + .../uml/tools/providers/UMLContentProvider.java | 453 +-- 58 files changed, 8055 insertions(+), 11656 deletions(-) create mode 100644 plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/handler/BlockDefinitionManageInterfacesHandler.java delete mode 100644 plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/handler/ManageProvidedInterfacesHandler.java create mode 100644 plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/ui/BlockDefinitionInterfaceManagerDialog.java delete mode 100644 plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/ui/CreateUmlElementDialog.java delete mode 100644 plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/ui/InterfaceManagerDialog.java delete mode 100644 plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/ui/NewElementRepresentation.java create mode 100644 plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/handler/InternalBlockManageInterfacesHandler.java delete mode 100644 plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/handler/ManageProvidedInterfacesHandler.java delete mode 100644 plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/ui/CreateUmlElementDialog.java delete mode 100644 plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/ui/InterfaceManagerDialog.java create mode 100644 plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/ui/InternalBlockInterfaceManagerDialog.java delete mode 100644 plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/ui/NewElementRepresentation.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/actions/handlers/ManagePortInterfacesHandler.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/CreateUmlElementDialog.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/ExtendedSelectionEditor.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/IPortInterfaceManagerDialog.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/InterfaceManagerDialog.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/NewElementRepresentation.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/SelectionEditorWrapper.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/actions/ComponentManageInterfacesHandler.java delete mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/actions/ManageProvidedInterfacesHandler.java create mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/ui/ComponentInterfaceManagerDialog.java delete mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/ui/CreateUmlElementDialog.java delete mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/ui/DisplayInterfaceMDialog.java delete mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/ui/ExtendedSelectionEditor.java delete mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/ui/InterfaceManagerDialog.java delete mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/ui/NewElementRepresentation.java delete mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/actions/ManageProvidedInterfacesHandler.java delete mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/ui/CreateUmlElementDialog.java delete mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/ui/InterfaceManagerDialog.java delete mode 100644 plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/ui/NewElementRepresentation.java create mode 100644 plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/adapters/DerivedAttributeAdapter.java create mode 100644 plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/adapters/PortTypeAdapter.java create mode 100644 plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/DestroyDependencyWithoutSupplierCommand.java create mode 100644 plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/PortInterfaceContentProvider.java (limited to 'plugins') 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 @@ - - - + + + - - + + - - - - - - + + + + + + @@ -1093,7 +1093,7 @@ 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; - - -/** - *
- * 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.
- * 
- */ -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; + +/** + *
+ * This class provides a Dialog to manage easily the provided and 
+ * the required Interfaces for a {@link Port}.
+ * 
+ */ +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 getAllAvailableInterfaces(Package pack) { + Set otherInterfaces = new HashSet(); + List 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 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 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 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 - * true 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 result = new ArrayList(); - 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 null 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; - - -/** - *
- * This class provides a Dialog to manage easily the provided and 
- * the required Interfaces for a {@link Port}.
- * 
- */ -public class InterfaceManagerDialog extends SelectionDialog { - - /** the selected port */ - private Port port; - - /** the list of the provided interfaces */ - private List providedInterfaces; - - /** the list of the required interfaces */ - private List 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> requiredInterfacesMappedWithUsage = new HashMap>(); - - /** - * 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> providedInterfacesMappedWithRealization = new HashMap>(); - - /** 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 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 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(); - this.interfaceRepresentations = new ArrayList(); - EList 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(); - 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(); - 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 classifiers = new ArrayList(); - 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 usages = requiredInterfacesMappedWithUsage.get(target); - if(usages != null) { - usages.add(usage); - } else { - usages = new ArrayList(); - 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 classifiers = new ArrayList(); - 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 realizations = providedInterfacesMappedWithRealization.get(target); - if(realizations != null) { - realizations.add(realization); - } else { - realizations = new ArrayList(); - 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 tmp = new ArrayList(); - 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 tmp = new ArrayList(); - 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 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 getAllAvailableInterfaces(Package pack) { - List otherInterfaces = new ArrayList(); - List 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 relationshipToDestroy = new HashSet(); - //commands to destroy Usage - for(Object current : this.requiredEditor.getElementToRemove()) { - //we get all usage associated with this interface - List 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 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 input = new ArrayList(); - 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 children = new ArrayList(); - 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 dependencies; - - /** - * - * Constructor. - * - * @param domain - * the domain - * @param affectedFiles - * the affected files - * @param dependencies - * the dependencies to test - */ - public DestroyDependencyWithoutSupplierCommand(TransactionalEditingDomain domain, List affectedFiles, Set 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 : - *
    - *
  • the name of the new element
  • - *
  • the parent of the new element
  • - *
  • the {@link IHintedType} of the new element
  • - *
  • the request to build the new element (optional)
  • - *
  • the element itself when it has been created
  • - *
- * - * - * - */ -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 null) - */ - 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 null 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 null 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 @@ --> - + 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; + +/** + *
+ * 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.
+ * 
+ */ +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; - -/** - *
- * 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.
- * 
- */ -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 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 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 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 - * true 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 result = new ArrayList(); - 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 null 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; - -/** - *
- * This class provides a Dialog to manage easily the provided and 
- * the required Interfaces for a {@link Port}.
- * 
- */ -public class InterfaceManagerDialog extends SelectionDialog { - - /** the selected port */ - private Port port; - - /** the list of the provided interfaces */ - private List providedInterfaces; - - /** the list of the required interfaces */ - private List 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> requiredInterfacesMappedWithUsage = new HashMap>(); - - /** - * 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> providedInterfacesMappedWithRealization = new HashMap>(); - - /** 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 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 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(); - this.interfaceRepresentations = new ArrayList(); - EList 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(); - 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(); - 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 classifiers = new ArrayList(); - 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 usages = requiredInterfacesMappedWithUsage.get(target); - if(usages != null) { - usages.add(usage); - } else { - usages = new ArrayList(); - 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 classifiers = new ArrayList(); - 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 realizations = providedInterfacesMappedWithRealization.get(target); - if(realizations != null) { - realizations.add(realization); - } else { - realizations = new ArrayList(); - 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 tmp = new ArrayList(); - 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 tmp = new ArrayList(); - 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 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 getAllAvailableInterfaces(Package pack) { - List otherInterfaces = new ArrayList(); - List 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 relationshipToDestroy = new HashSet(); - //commands to destroy Usage - for(Object current : this.requiredEditor.getElementToRemove()) { - //we get all usage associated with this interface - List 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 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 input = new ArrayList(); - 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 children = new ArrayList(); - 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 dependencies; - - /** - * - * Constructor. - * - * @param domain - * the domain - * @param affectedFiles - * the affected files - * @param dependencies - * the dependencies to test - */ - public DestroyDependencyWithoutSupplierCommand(TransactionalEditingDomain domain, List affectedFiles, Set 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; + +/** + *
+ * This class provides a Dialog to manage easily the provided and 
+ * the required Interfaces for a {@link Port}.
+ * 
+ */ +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 getAllAvailableInterfaces(Package pack) { + Set otherInterfaces = new HashSet(); + List 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 : - *
    - *
  • the name of the new element
  • - *
  • the parent of the new element
  • - *
  • the {@link IHintedType} of the new element
  • - *
  • the request to build the new element (optional)
  • - *
  • the element itself when it has been created
  • - *
- * - * - * - */ -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 null) - */ - 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 null 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 null 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/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF index 82f01440b95..fb293e6341a 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF @@ -99,7 +99,8 @@ Require-Bundle: org.eclipse.papyrus.infra.core;bundle-version="1.0.0", org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="1.0.0", org.eclipse.papyrus.uml.diagram.paletteconfiguration;bundle-version="1.0.0", org.eclipse.papyrus.infra.tools;bundle-version="1.0.0", - org.eclipse.papyrus.uml.modelrepair;bundle-version="1.0.0" + org.eclipse.papyrus.uml.modelrepair;bundle-version="1.0.0", + org.eclipse.papyrus.emf.facet.custom.core;bundle-version="1.0.0" Bundle-Vendor: %providerName Ant-Version: Apache Ant 1.7.0 Bundle-Version: 1.0.0.qualifier diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/messages.properties b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/messages.properties index 39a8a5f34fb..cf04fa5b87b 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/messages.properties +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/messages.properties @@ -171,3 +171,20 @@ PartActivationListener_RemovedTitle=Resource removal ########### Execution exception messages ########## CommonDeferredCreateConnectionViewCommand_NullConnectionCommand=Connection creation command is null. + + +CreateUmlElementDialog_New_Element_Name=New Element Name + +ManageProvidedInterfacesHandler_OK=OK +ManageProvidedInterfacesHandler_TheTypeOfThePortIsNotDefined=The type of the Port is not defined. You need to define it before managing its Interfaces. + +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 +SelectionValidated=Selection validated. +NoSelectionFound=No selection found. \ No newline at end of file diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/Messages.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/Messages.java index 3df09963ffb..b31c97e5235 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/Messages.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/Messages.java @@ -8,7 +8,7 @@ * * Contributors: Francisco Javier Cano Muñoz (Prodevelop) - initial API implementation * Emilien Perico (Atos Origin) - add tags for links with keywords - * + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation ******************************************************************************/ package org.eclipse.papyrus.uml.diagram.common; @@ -18,6 +18,8 @@ public class Messages extends NLS { private static final String BUNDLE_NAME = "messages"; //$NON-NLS-1$ + public static String CreateUmlElementDialog_New_Element_Name; + public static String ElementImportParser_undefined_value; public static String IconStylePreferencePage_cheerful_style; @@ -26,8 +28,32 @@ public class Messages extends NLS { public static String IconStylePreferencePage_icon_style_group; + 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 ModelElementSelectionPageMessage; + public static String ManageProvidedInterfacesHandler_OK; + + public static String ManageProvidedInterfacesHandler_TheTypeOfThePortIsNotDefined; + + public static String SelectionValidated; + + public static String NoSelectionFound; + public static String UMLNewDiagramFileWizard_RootSelectionPageSelectionTitle; public static String UMLNewDiagramFileWizard_RootSelectionPageNoSelectionMessage; diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/actions/handlers/ManagePortInterfacesHandler.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/actions/handlers/ManagePortInterfacesHandler.java new file mode 100644 index 00000000000..9bb6838f7bd --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/actions/handlers/ManagePortInterfacesHandler.java @@ -0,0 +1,172 @@ +/***************************************************************************** + * Copyright (c) 2009-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: + * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.common.actions.handlers; + +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.EditPart; +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.uml.diagram.common.Messages; +import org.eclipse.papyrus.uml.diagram.common.dialogs.IPortInterfaceManagerDialog; +import org.eclipse.papyrus.uml.diagram.common.dialogs.InterfaceManagerDialog; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.uml2.uml.Classifier; +import org.eclipse.uml2.uml.Interface; +import org.eclipse.uml2.uml.Port; +import org.eclipse.uml2.uml.Type; + +/** + * This handler provides the action to manage the provided and required {@link Interface} for a {@link Port}. + */ +public class ManagePortInterfacesHandler extends AbstractHandler { + + /** The port edit part. */ + private EditPart portEditPart = null; + + + /** + * Instantiates a new manage port interfaces handler. + */ + public ManagePortInterfacesHandler() { + super(); + } + + /** + * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) + * + * @param event + * @return + * @throws ExecutionException + */ + public Object execute(ExecutionEvent event) throws ExecutionException { + ISelection selection = HandlerUtil.getCurrentSelection(event); + + // Do something only if there is a selection + if(selection.isEmpty()) { + return null; + } + + // Handle structured selection + if(selection instanceof IStructuredSelection) { + IStructuredSelection structuredSelection = (IStructuredSelection)selection; + + // Verify if selection is an EditPart + Object firstElement = structuredSelection.getFirstElement(); + if(firstElement instanceof EditPart) { + portEditPart = (EditPart)firstElement; + + // Verify if semantic element is a Port + EObject selectedElement = EMFHelper.getEObject(portEditPart); + if(selectedElement instanceof Port) { + Port port = (Port)selectedElement; + + // Run action + 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; + } + + /** + * Gets the interface manager dialog. + *

+ * Default implementation returns {@link InterfaceManagerDialog}. + *

+ * + * @param port + * the port + * @return the interface manager dialog + */ + public IPortInterfaceManagerDialog getInterfaceManagerDialog(Port port) { + return new InterfaceManagerDialog(DisplayUtils.getDefaultShell(), port); + } + + /** + * Gets the port edit part. + * + * @return the port edit part + */ + protected EditPart getPortEditPart() { + return portEditPart; + } + + /** + * This class provides the action to manage the provided and required interfaces. + */ + public class ManageProvidedInterfaceAction { + + /** the {@link Port}. */ + private Port port = null; + + /** the {@link Type} of the port. */ + private Type type = null; + + /** + * + * 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 + * the command to add/remove provided/required interfaces + */ + public Command getCommand() { + if(type != null && !(type instanceof Classifier)) { + return UnexecutableCommand.INSTANCE; + } else if(type == null) { + // Display message if Port type is undefined + MessageDialog dialog = new MessageDialog(DisplayUtils.getDefaultShell(), Messages.InterfaceManagerDialog_Title, null, Messages.ManageProvidedInterfacesHandler_TheTypeOfThePortIsNotDefined, MessageDialog.WARNING, new String[]{ Messages.ManageProvidedInterfacesHandler_OK }, 0); + dialog.open(); + + } else { + + // Launch manager + IPortInterfaceManagerDialog dialog = getInterfaceManagerDialog(port); + if(dialog.open() == Dialog.OK) { + return dialog.getCommand(); + } + } + return UnexecutableCommand.INSTANCE; + } + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/CreateUmlElementDialog.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/CreateUmlElementDialog.java new file mode 100644 index 00000000000..b2b92eba063 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/CreateUmlElementDialog.java @@ -0,0 +1,417 @@ +/***************************************************************************** + * Copyright (c) 2009-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: + * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.common.dialogs; + +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.IElementType; +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.uml.diagram.common.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 IElementType 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; + + /** 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 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, IElementType 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 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 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 + * true 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) { + CreateElementRequest request = elementToCreate.getCreateElementRequest(); + ICommand command = getCommand(request); + 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 result = new ArrayList(); + 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 null 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/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/ExtendedSelectionEditor.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/ExtendedSelectionEditor.java new file mode 100644 index 00000000000..378c68c59b9 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/ExtendedSelectionEditor.java @@ -0,0 +1,546 @@ +/***************************************************************************** + * Copyright (c) 2013 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: + * Patrick Tessier (CEA LIST) - Initial API and implementation + /*****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.common.dialogs; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedList; + +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.papyrus.infra.widgets.Activator; +import org.eclipse.papyrus.infra.widgets.editors.IElementSelector; +import org.eclipse.papyrus.infra.widgets.messages.Messages; +import org.eclipse.papyrus.infra.widgets.providers.CollectionContentProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Table; + +/** + * Extension of selection editor with a table to display icon of element + * normally this class must inherits of SelectionEditor but list and table are type that are not compatible, so entire creation of this class was + * needed + */ +public class ExtendedSelectionEditor extends Composite implements SelectionListener { + + + /** the initial selection */ + protected final java.util.List initialSelection; + + /** The object selector */ + private IElementSelector selector; + + /** The SWT Composite in which the selector is drawn */ + protected Composite selectorSection; + + /** The message section */ + protected Composite messageSection; + + /** The additional button section */ + protected Composite createAdditionalButtonSection; + + /** The up/down buttons section */ + protected Composite rightButtonsSection; + + /** The listViewer for chosen elements */ + protected TableViewer selectedElementsViewer; + + /** The list for chosen elements */ + protected Table selectedElements; + + /** The add action button */ + private Button add; + + /** The remove action button */ + private Button remove; + + /** The add all action button */ + private Button addAll; + + /** The remove all action button */ + private Button removeAll; + + /** the up action button */ + private Button up; + + /** the down action button */ + private Button down; + + /** The label provider for the listViewer of chosen elements */ + private ILabelProvider labelProvider; + + /** The currently chosen elements */ + protected final Collection currentSelection; + + /** the listener for the additional button */ + private SelectionListener additionalButtonSelectionListener; + + /** the message for the editor */ + private String message; + + + /* + * This dialog can provide a Button to do some optional action + */ + + /** Indicates if the dialog provides a button */ + private boolean withAdditionalButton = false; + + /** the label of the button */ + private String additionalButtonLabel = null; + + /** the button */ + private Button additionalButton; + + /** The add/remove/addAll buttons section */ + protected Composite buttonSection; + + /** + * + * Constructor. + * + * @param parent + * the parent of this composite + * @param selector + * the selector + * @param labelProvider + * the label provider + * @param initialSelection + * the initial selection + */ + public ExtendedSelectionEditor(Composite parent, IElementSelector selector, ILabelProvider labelProvider, java.util.List initialSelection) { + super(parent, SWT.NONE); + this.selector = selector; + this.labelProvider = labelProvider; + this.initialSelection = new ArrayList(); + for(Object current : initialSelection) { + this.initialSelection.add(current); + } + currentSelection = initialSelection; + } + + /** + * This methods create this editor + */ + public void create() { + Composite parent = this; + GridLayout layout = new GridLayout(1, true); + GridData data = new GridData(); + data.grabExcessHorizontalSpace = true; + data.grabExcessVerticalSpace = true; + parent.setLayout(layout); + createMessageSection(parent); + createBody(parent); + createCreateButtonSection(parent); + } + + /** + * This method create the body of the editor : + *
    + *
  • the selector
  • + *
  • the list
  • + *
  • the buttons Add, AddAll, Remove, RemoveAll, Up, Down
  • + *
+ * + * @param parent + * the parent composite + */ + protected void createBody(Composite parent) { + + Composite par = new Composite(parent, SWT.NONE); + createSelectorSection(par); + createControlsSection(par); + createListSection(par); + createRightButtonsSection(par); + GridLayout layout = new GridLayout(); + layout.makeColumnsEqualWidth = false; + layout.numColumns = 4; + par.setLayout(layout); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + par.setLayoutData(data); + + } + + /** + * Creates the Message section + * + * @param parent + * the parent of the {@link Composite} + */ + protected void createMessageSection(Composite parent) { + messageSection = new Composite(parent, SWT.NONE); + Label label = new Label(messageSection, SWT.NONE); + label.setText(message); + messageSection.setLayout(new FillLayout(SWT.HORIZONTAL)); + } + + /** + * Creates the button section + * + * @param parent + * the parent of the {@link Composite} + */ + protected void createCreateButtonSection(Composite parent) { + if(this.withAdditionalButton) { + buttonSection = new Composite(parent, SWT.NONE); + additionalButton = new Button(buttonSection, SWT.PUSH); + if(additionalButtonLabel != null) { + additionalButton.setText(additionalButtonLabel); + } + buttonSection.setLayout(new FillLayout()); + this.additionalButton.addSelectionListener(additionalButtonSelectionListener); + } + } + + /** + * Creates the selector section + * + * @param parent + * The composite in which the section is created + */ + protected void createSelectorSection(Composite parent) { + selectorSection = new Composite(parent, SWT.NONE); + selectorSection.setLayout(new FillLayout()); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + data.widthHint = 400; + + // data.exclude = true; + selectorSection.setLayoutData(data); + selector.createControls(selectorSection); + + } + + /** + * Creates the main controls section (Add, remove, Add all, remove all) + * + * @param parent + * The composite in which the section is created + */ + protected void createControlsSection(Composite parent) { + buttonSection = new Composite(parent, SWT.NONE); + buttonSection.setLayout(new GridLayout(1, true)); + + add = new Button(buttonSection, SWT.PUSH); + add.setImage(Activator.getDefault().getImage("/icons/arrow_right.gif")); //$NON-NLS-1$ + add.addSelectionListener(this); + add.setToolTipText(Messages.MultipleValueSelectorDialog_AddSelectedElements); + + remove = new Button(buttonSection, SWT.PUSH); + remove.setImage(Activator.getDefault().getImage("/icons/arrow_left.gif")); //$NON-NLS-1$ + remove.addSelectionListener(this); + remove.setToolTipText(Messages.MultipleValueEditor_RemoveSelectedElements); + + addAll = new Button(buttonSection, SWT.PUSH); + addAll.setImage(Activator.getDefault().getImage("/icons/arrow_double.gif")); //$NON-NLS-1$ + addAll.addSelectionListener(this); + addAll.setToolTipText(Messages.MultipleValueSelectorDialog_AddAllElements); + + removeAll = new Button(buttonSection, SWT.PUSH); + removeAll.setImage(Activator.getDefault().getImage("/icons/arrow_left_double.gif")); //$NON-NLS-1$ + removeAll.addSelectionListener(this); + removeAll.setToolTipText(Messages.MultipleValueSelectorDialog_RemoveAllElements); + } + + + /** + * Creates the list displaying the currently selected elements + * + * @param parent + * The composite in which the section is created + */ + protected void createListSection(Composite parent) { + Composite listSection = new Composite(parent, SWT.NONE); + selectedElements = new Table(listSection, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + data.widthHint = 400; + listSection.setLayout(new FillLayout()); + listSection.setLayoutData(data); + + selectedElementsViewer = new TableViewer(selectedElements); + + selectedElementsViewer.setContentProvider(CollectionContentProvider.instance); + + if(labelProvider != null) + selectedElementsViewer.setLabelProvider(labelProvider); + + selectedElementsViewer.setInput(currentSelection); + selector.setSelectedElements(currentSelection.toArray()); + + } + + /** + * Creates the up/down controls section + * + * @param parent + * The composite in which the section is created + */ + protected void createRightButtonsSection(Composite parent) { + rightButtonsSection = new Composite(parent, SWT.NONE); + rightButtonsSection.setLayout(new GridLayout(1, true)); + + up = new Button(rightButtonsSection, SWT.PUSH); + up.setImage(Activator.getDefault().getImage("/icons/Up_12x12.gif")); //$NON-NLS-1$ + up.addSelectionListener(this); + up.setToolTipText(Messages.MultipleValueEditor_MoveSelectedElementsUp); + + down = new Button(rightButtonsSection, SWT.PUSH); + down.setImage(Activator.getDefault().getImage("/icons/Down_12x12.gif")); //$NON-NLS-1$ + down.addSelectionListener(this); + down.setToolTipText(Messages.MultipleValueEditor_MoveSelectedElementsDown); + } + + + + /** + * {@inheritDoc} Handles the events on one of the control buttons + * + * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) + * + * @param e + * The event that occurred + */ + public void widgetSelected(SelectionEvent e) { + if(e.widget == add) { + addAction(); + } else if(e.widget == remove) { + removeAction(); + } else if(e.widget == addAll) { + addAllAction(); + } else if(e.widget == removeAll) { + removeAllAction(); + } else if(e.widget == up) { + upAction(); + } else if(e.widget == down) { + downAction(); + } + } + + /** + * Handles the "Add" action + */ + protected void addAction() { + Object[] elements = selector.getSelectedElements(); + addElements(elements); + } + + /** + * Handles the "Up" action + */ + protected void upAction() { + IStructuredSelection selection = (IStructuredSelection)selectedElementsViewer.getSelection(); + + //We need a list to move objects. LinkedHashSet can't do that + java.util.List list = new LinkedList(currentSelection); + for(Object o : selection.toArray()) { + int oldIndex = list.indexOf(o); + if(oldIndex > 0) + move(list, oldIndex, oldIndex - 1); + } + + currentSelection.clear(); + currentSelection.addAll(list); + + IStructuredSelection selectionCopy = new StructuredSelection(selection.toArray()); + selectedElementsViewer.setSelection(selectionCopy); + selectedElementsViewer.refresh(); + } + + /** + * Handles the "Down" action + */ + protected void downAction() { + IStructuredSelection selection = (IStructuredSelection)selectedElementsViewer.getSelection(); + + //We need a list to move objects. LinkedHashSet can't do that + java.util.List list = new LinkedList(currentSelection); + + int maxIndex = list.size() - 1; + + Object[] selectionArray = selection.toArray(); + for(int i = selectionArray.length - 1; i >= 0; i--) { + Object o = selectionArray[i]; + int oldIndex = list.indexOf(o); + if(oldIndex < maxIndex) + move(list, oldIndex, oldIndex + 1); + } + + currentSelection.clear(); + currentSelection.addAll(list); + + IStructuredSelection selectionCopy = new StructuredSelection(selection.toArray()); + selectedElementsViewer.setSelection(selectionCopy); + selectedElementsViewer.refresh(); + } + + /** + * Moves an element from oldIndex to newIndex + * + * @param list + * The list in which to move the object + * @param oldIndex + * @param newIndex + */ + protected void move(java.util.List list, int oldIndex, int newIndex) { + int size = list.size(); + + if(oldIndex < 0 || oldIndex >= size) + throw new IndexOutOfBoundsException("oldIndex: " + oldIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ + if(newIndex < 0 || newIndex >= size) + throw new IndexOutOfBoundsException("newIndex: " + newIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ + Object element = list.remove(oldIndex); + list.add(newIndex, element); + } + + /** + * Handles the "Remove" action + */ + protected void removeAction() { + IStructuredSelection selection = (IStructuredSelection)selectedElementsViewer.getSelection(); + if(selection.isEmpty()) + return; + + for(Object element : selection.toArray()) { + currentSelection.remove(element); + } + + selector.setSelectedElements(currentSelection.toArray()); + selectedElementsViewer.setSelection(null); + selectedElementsViewer.refresh(); + } + + /** + * Handles the "Remove all" action + */ + protected void removeAllAction() { + currentSelection.clear(); + selector.setSelectedElements(new Object[0]); + selectedElementsViewer.setSelection(null); + selectedElementsViewer.refresh(); + } + + /** + * Handles the "Add All" action + */ + protected void addAllAction() { + Object[] elements = selector.getAllElements(); + addElements(elements); + } + + /** + * Adds the specified elements to the currently selected elements (For + * "Add" and "Add all" actions) + * + * @param elements + * The elements to be added + */ + protected void addElements(Object[] elements) { + if(elements != null) { + currentSelection.addAll(Arrays.asList(elements)); + selectedElementsViewer.refresh(); + } + } + + + /** + * + * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) + * + * @param e + */ + public void widgetDefaultSelected(SelectionEvent e) { + //Nothing to do + } + + /** + * + * @param withAdditionalButton + * @param messageButton + * @param listener + */ + public void setAdditionalButton(boolean withAdditionalButton, String messageButton, SelectionListener listener) { + this.withAdditionalButton = withAdditionalButton; + this.additionalButtonLabel = messageButton; + this.additionalButtonSelectionListener = listener; + } + + /** + * Set the message displayed by the Editor + * + * @param string + * the message displayed by the editor + */ + public void setMessage(String string) { + this.message = string; + } + + /** + * Returns all selected elements + * + * @return + * all selected elements + */ + public Collection getSelectedElements() { + return currentSelection; + } + + + /** + * Returns the list of the elements to remove + * + * @return + * the list of the elements to remove + */ + public java.util.List getElementToRemove() { + java.util.List removedObject = new ArrayList(); + for(Object current : this.initialSelection) { + if(!getSelectedElements().contains(current)) { + removedObject.add(current); + } + } + return removedObject; + } + + /** + * Returns the list of the elements to add + * + * @return + * the list of the elements to add + */ + public java.util.List getElementToAdd() { + java.util.List addedObject = new ArrayList(); + for(Object current : getSelectedElements()) { + if(!this.initialSelection.contains(current)) { + addedObject.add(current); + } + } + return addedObject; + } + + /** + * + * @return the table viewer in order to get the element selection + */ + public TableViewer getSelectedElementsViewer() { + return selectedElementsViewer; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/IPortInterfaceManagerDialog.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/IPortInterfaceManagerDialog.java new file mode 100644 index 00000000000..11842933f7e --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/IPortInterfaceManagerDialog.java @@ -0,0 +1,36 @@ +/***************************************************************************** + * 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.uml.diagram.common.dialogs; + +import org.eclipse.gef.commands.Command; + + +/** + * Interface for Port interface manager dialog. + */ +public interface IPortInterfaceManagerDialog { + + /** + * Returns the commands to apply the changes. + * + * @return the commands to apply the changes + */ + Command getCommand(); + + /** + * @see org.eclipse.jface.dialogs.Dialog#open() + * + * @return + */ + int open(); + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/InterfaceManagerDialog.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/InterfaceManagerDialog.java new file mode 100644 index 00000000000..d5dcde44442 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/InterfaceManagerDialog.java @@ -0,0 +1,1024 @@ +/***************************************************************************** + * Copyright (c) 2009-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: + * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.fr - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.common.dialogs; + +import java.util.ArrayList; +import java.util.Arrays; +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.ElementTypeRegistry; +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.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.uml.diagram.common.Activator; +import org.eclipse.papyrus.uml.diagram.common.Messages; +import org.eclipse.papyrus.uml.diagram.common.util.Util; +import org.eclipse.papyrus.uml.diagram.common.util.Visitor; +import org.eclipse.papyrus.uml.tools.commands.DestroyDependencyWithoutSupplierCommand; +import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider; +import org.eclipse.papyrus.uml.tools.utils.ElementUtil; +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.edit.providers.ImageItemProvider; +import org.eclipse.uml2.uml.edit.providers.UMLItemProviderAdapterFactory; + + +/** + * This class provides a Dialog to manage easily the provided and the required Interfaces for a {@link Port}. + */ +public class InterfaceManagerDialog extends SelectionDialog implements IPortInterfaceManagerDialog { + + /** the selected port. */ + private Port port; + + /** the list of the provided interfaces. */ + private List providedInterfaces; + + /** the list of the required interfaces. */ + private List 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 SelectionEditorWrapper providedEditor; + + /** the Editor for the required interfaces. */ + private SelectionEditorWrapper 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> requiredInterfacesMappedWithUsage = new HashMap>(); + + /** + * 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> providedInterfacesMappedWithRealization = new HashMap>(); + + /** the label provider for selector. */ + private 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 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 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); + } + + /** + * Creates the dialog. + * + * @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(); + this.interfaceRepresentations = new ArrayList(); + EList 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(); + 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(); + 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 = ElementUtil.getInstancesFilteredByType(this.model, Usage.class, null); + List classifiers = new ArrayList(); + 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 usages = requiredInterfacesMappedWithUsage.get(target); + if(usages != null) { + usages.add(usage); + } else { + usages = new ArrayList(); + usages.add(usage); + this.requiredInterfacesMappedWithUsage.put((Interface)target, usages); + } + } + } + break; + } + } + } + } + + /** + * This method fills the map {@link #providedInterfacesMappedWithRealization}. + */ + protected void buildProvidedInterfaces() { + List allRealization = ElementUtil.getInstancesFilteredByType(this.model, Realization.class, null); + List classifiers = new ArrayList(); + 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 realizations = providedInterfacesMappedWithRealization.get(target); + if(realizations != null) { + realizations.add(realization); + } else { + realizations = new ArrayList(); + 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 + */ + @Override + public Object[] getElements() { + List tmp = new ArrayList(); + 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 + */ + @Override + public Object[] getElements() { + List tmp = new ArrayList(); + 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 SelectionEditorWrapper createEditor(Composite parent, IElementSelector selector, String message, boolean withCreateButton, SelectionListener listener, List initialSelection) { + SelectionEditor editor = new SelectionEditor(parent, selector, selectorLabelProvider, initialSelection); + editor.setMessage(message); + editor.setAdditionalButton(withCreateButton, Messages.InterfaceManagerDialog_CreateNewInterface, listener); + return new SelectionEditorWrapper(editor, editor.getClass()); + } + + /** + * Returns all the available Interfaces. + * + * @param pack + * the pack + * @return all the available Interfaces + * //TODO add the interfaces of the package import! + */ + protected List getAllAvailableInterfaces(Package pack) { + + // Set ensure there is not duplicated interface + Set otherInterfaces = new HashSet(); + + List interfaces = Visitor.getOwnedAndImportedElement(pack, Interface.class); + for(Namespace namespace : Visitor.getOwnedAndImportedNamespaces(pack)) { + interfaces.addAll(Visitor.getOwnedAndImportedElement(namespace, Interface.class)); + + } + + for(Element element : interfaces) { + otherInterfaces.add((Interface)element); + } + + return Arrays.asList(otherInterfaces.toArray(new Interface[otherInterfaces.size()])); + } + + + /** + * Gets the command. + * + * @return the command + * @see org.eclipse.papyrus.uml.diagram.common.dialogs.IPortInterfaceManagerDialog#getCommand() + */ + 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 relationshipToDestroy = new HashSet(); + // commands to destroy Usage + for(Object current : this.requiredEditor.getElementToRemove()) { + // we get all usage associated with this interface + List 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 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, relationshipToDestroy, getCommandProvider()))); + 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, ElementTypeRegistry.getInstance().getType("org.eclipse.papyrus.uml.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 : this.providedEditor.getElementToAdd()) { + if(current instanceof EObject) { + CreateRelationshipRequest request = new CreateRelationshipRequest(this.port.getType(), this.port.getType(), (EObject)current, ElementTypeRegistry.getInstance().getType("org.eclipse.papyrus.uml.InterfaceRealization")); + Command cmd = getCommand(request); + if(cmd.canExecute()) { + command.add(cmd); + } + } else {// its an NewElementRepresentation + CreateInterfaceRealizationCommand cmd = new CreateInterfaceRealizationCommand(this.domain, this.port.getType(), 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 = getCommandProvider(); + if(provider != null) { + ICommand setCommand = provider.getEditCommand(req); + if(setCommand != null) { + return new ICommandProxy(setCommand.reduce()); + } + } + return UnexecutableCommand.INSTANCE; + } + + /** + * Gets the command provider. + * + * @return the command provider + */ + private IElementEditService getCommandProvider() { + IElementEditService provider = ElementEditServiceUtils.getCommandProvider(model); + return provider; + } + + + + /** + * Gets the selector label provider. + * + * @return the selector label provider + */ + public ILabelProvider getSelectorLabelProvider() { + return selectorLabelProvider; + } + + + /** + * Sets the selector label provider. + * + * @param selectorLabelProvider + * the new selector label provider + */ + public void setSelectorLabelProvider(ILabelProvider selectorLabelProvider) { + this.selectorLabelProvider = selectorLabelProvider; + } + + + + /** + * Gets the provided editor. + * + * @return the provided editor + */ + public SelectionEditorWrapper getProvidedEditor() { + return providedEditor; + } + + + /** + * Gets the required editor. + * + * @return the required editor + */ + public SelectionEditorWrapper getRequiredEditor() { + return requiredEditor; + } + + + /** + * This listener is used to know when the user clicks on the Button to create a new {@link Interface}. + * + * @see CreateButtonEvent + */ + public class CreateButtonListener implements SelectionListener { + + /** + * Widget selected. + * + * @param e + * the e + * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) + */ + @Override + public void widgetSelected(SelectionEvent e) { + + CreateUmlElementDialog dialog = new CreateUmlElementDialog(getShell(), domain, newElementLabelProvider, new CustomContentProvider(), model, ElementTypeRegistry.getInstance().getType("org.eclipse.papyrus.uml.Interface")); + dialog.setTitle(Messages.InterfaceManagerDialog_CreateANewInterface); + dialog.setMessage(Messages.InterfaceManagerDialog_SelectTheParentOfThisNewInterface); + dialog.setHelpAvailable(false); + dialog.setForbiddenNames(forbiddenNames); + List input = new ArrayList(); + 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(); + } + } + + /** + * Widget default selected. + * + * @param e + * the e + * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) + */ + @Override + 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. + * + * @param selection + * the selection + * @return the i status + * @see org.eclipse.ui.dialogs.ISelectionStatusValidator#validate(java.lang.Object[]) + */ + @Override + public IStatus validate(Object[] selection) { + + IStatus status = new Status(IStatus.ERROR, Activator.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, Activator.ID, Messages.SelectionValidated); + } else { + status = new Status(IStatus.ERROR, Activator.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 { + + /** + * Gets the text. + * + * @param element + * the element + * @return the text + * @see org.eclipse.papyrus.uml.diagram.common.providers.EditorLabelProvider#getText(java.lang.Object) + */ + @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); + } + + } + + /** + * The Class CreateElementLabelProvider. + */ + public class CreateElementLabelProvider extends UMLLabelProvider { + + /** + * Gets the image. + * + * @param element + * the element + * @return the image + * @see org.eclipse.papyrus.uml.diagram.common.providers.EditorLabelProvider#getImage(java.lang.Object) + */ + @Override + public Image getImage(Object element) { + if(element instanceof NewElementRepresentation) { + + ImageItemProvider imageProvider = new ImageItemProvider(new UMLItemProviderAdapterFactory()); + Object obj = imageProvider.getImage(((NewElementRepresentation)element).getEObject()); + return org.eclipse.papyrus.uml.tools.Activator.getDefault().getImageForUMLMetaclass(UMLPackage.eINSTANCE.getInterface()); + } + return super.getImage(element); + } + + /** + * Gets the text. + * + * @param element + * the element + * @return the text + * @see org.eclipse.papyrus.uml.diagram.common.providers.EditorLabelProvider#getText(java.lang.Object) + */ + @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 { + + /** + * Dispose. + * + * @see org.eclipse.jface.viewers.IContentProvider#dispose() + */ + @Override + public void dispose() { + } + + /** + * Input changed. + * + * @param viewer + * the viewer + * @param oldInput + * the old input + * @param newInput + * the new input + * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) + */ + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + + } + + /** + * Gets the elements. + * + * @param inputElement + * the input element + * @return the elements + * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object) + */ + @Override + public Object[] getElements(Object inputElement) { + if(inputElement instanceof List) { + return ((List)inputElement).toArray(); + } + return new Object[0]; + } + + /** + * Gets the children. + * + * @param parentElement + * the parent element + * @return the children + * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) + */ + @Override + public Object[] getChildren(Object parentElement) { + List children = new ArrayList(); + 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(); + } + + /** + * Gets the parent. + * + * @param element + * the element + * @return the parent + * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) + */ + @Override + public Object getParent(Object element) { + if(element == model) { + return model; + } else if(element instanceof NamedElement) { + return ((NamedElement)element).eContainer(); + } + return null; + } + + /** + * Checks for children. + * + * @param element + * the element + * @return true, if successful + * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) + */ + @Override + 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; + } + + /** + * 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 { + CreateRelationshipRequest request = new CreateRelationshipRequest(domain, container, source, target.getEObject(), ElementTypeRegistry.getInstance().getType("org.eclipse.papyrus.uml.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; + } + + /** + * 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 { + + CreateRelationshipRequest request = new CreateRelationshipRequest(domain, container, source, target.getEObject(), ElementTypeRegistry.getInstance().getType("org.eclipse.papyrus.uml.InterfaceRealization")); + Command command = getCommand(request); + if(command.canExecute()) { + command.execute(); + } + return CommandResult.newOKCommandResult(request.getNewElement()); + } + + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/NewElementRepresentation.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/NewElementRepresentation.java new file mode 100644 index 00000000000..43717966d4d --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/NewElementRepresentation.java @@ -0,0 +1,173 @@ +/***************************************************************************** + * Copyright (c) 2009-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: + * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.common.dialogs; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.gmf.runtime.emf.type.core.IElementType; +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 : + *
    + *
  • the name of the new element
  • + *
  • the parent of the new element
  • + *
  • the {@link IHintedType} of the new element
  • + *
  • the request to build the new element (optional)
  • + *
  • the element itself when it has been created
  • + *
+ * + * + * + */ +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 IElementType 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 null) + */ + public NewElementRepresentation(String name, Object parent, IElementType 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 IElementType 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 null 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 null 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/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/SelectionEditorWrapper.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/SelectionEditorWrapper.java new file mode 100644 index 00000000000..8b04a1aadd2 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/SelectionEditorWrapper.java @@ -0,0 +1,180 @@ +/***************************************************************************** + * 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.uml.diagram.common.dialogs; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.papyrus.infra.widgets.editors.SelectionEditor; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; + + +/** + * Wrapper for both selection editor. + *
    + *
  • SelectionEditor
  • + *
  • ExtendedSelectionEditor
  • + *
+ * + * @author Gabriel Pascual (ALL4TEC) + * + */ +public class SelectionEditorWrapper implements SelectionListener { + + /** The wrapped selection editor. */ + private SelectionListener wrappedSelectionEditor = null; + + /** The wrapped editor class. */ + private Class wrappedEditorClass = null; + + /** + * Instantiates a new selection editor wrapper. + * + * @param selectionEditor + * the selection editor + * @param editorClass + * the editor class + */ + public SelectionEditorWrapper(SelectionListener selectionEditor, Class editorClass) { + wrappedSelectionEditor = selectionEditor; + wrappedEditorClass = editorClass; + } + + /** + * Creates the. + */ + public void create() { + if(SelectionEditor.class.equals(wrappedEditorClass)) { + ((SelectionEditor)wrappedSelectionEditor).create(); + } else if(ExtendedSelectionEditor.class.equals(wrappedEditorClass)) { + ((ExtendedSelectionEditor)wrappedSelectionEditor).create(); + } + + } + + /** + * Sets the layout data. + * + * @param layoutData + * the new layout data + */ + public void setLayoutData(Object layoutData) { + if(SelectionEditor.class.equals(wrappedEditorClass)) { + ((SelectionEditor)wrappedSelectionEditor).setLayoutData(layoutData); + } else if(ExtendedSelectionEditor.class.equals(wrappedEditorClass)) { + ((ExtendedSelectionEditor)wrappedSelectionEditor).setLayoutData(layoutData); + } + + } + + /** + * Gets the selected elements. + * + * @return the selected elements + */ + public Collection getSelectedElements() { + + Collection selectedElements = null; + if(SelectionEditor.class.equals(wrappedEditorClass)) { + selectedElements = ((SelectionEditor)wrappedSelectionEditor).getSelectedElements(); + } else if(ExtendedSelectionEditor.class.equals(wrappedEditorClass)) { + selectedElements = ((ExtendedSelectionEditor)wrappedSelectionEditor).getSelectedElements(); + } + + return selectedElements; + } + + /** + * Gets the element to remove. + * + * @return the element to remove + */ + public List getElementToRemove() { + List elementsToRemove = null; + if(SelectionEditor.class.equals(wrappedEditorClass)) { + elementsToRemove = ((SelectionEditor)wrappedSelectionEditor).getElementToRemove(); + } else if(ExtendedSelectionEditor.class.equals(wrappedEditorClass)) { + elementsToRemove = ((ExtendedSelectionEditor)wrappedSelectionEditor).getElementToRemove(); + } else { + elementsToRemove = new ArrayList(); + } + + return elementsToRemove; + } + + /** + * Gets the element to add. + * + * @return the element to add + */ + public List getElementToAdd() { + List elementsToAdd = null; + if(SelectionEditor.class.equals(wrappedEditorClass)) { + elementsToAdd = ((SelectionEditor)wrappedSelectionEditor).getElementToAdd(); + } else if(ExtendedSelectionEditor.class.equals(wrappedEditorClass)) { + elementsToAdd = ((ExtendedSelectionEditor)wrappedSelectionEditor).getElementToAdd(); + } else { + elementsToAdd = new ArrayList(); + } + + return elementsToAdd; + } + + /** + * Gets the selection. + * + * @return the selection + */ + public ISelection getSelection() { + if(ExtendedSelectionEditor.class.equals(wrappedEditorClass)) { + return ((ExtendedSelectionEditor)wrappedSelectionEditor).getSelectedElementsViewer().getSelection(); + } + return null; + } + + /** + * Refresh. + */ + public void refresh() { + if(ExtendedSelectionEditor.class.equals(wrappedEditorClass)) { + ((ExtendedSelectionEditor)wrappedSelectionEditor).getSelectedElementsViewer().refresh(); + } + + } + + /** + * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) + * + * @param e + */ + @Override + public void widgetSelected(SelectionEvent e) { + wrappedSelectionEditor.widgetSelected(e); + + } + + /** + * Widget default selected. + * + * @param e + * the e + * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) + */ + @Override + public void widgetDefaultSelected(SelectionEvent e) { + wrappedSelectionEditor.widgetDefaultSelected(e); + + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/actions/ComponentManageInterfacesHandler.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/actions/ComponentManageInterfacesHandler.java new file mode 100644 index 00000000000..845ae668115 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/actions/ComponentManageInterfacesHandler.java @@ -0,0 +1,44 @@ +/***************************************************************************** + * 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 + * Gabriel Pascual (ALL4TEc) gabriel.pascual@all4tec.net - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.component.custom.actions; + +import org.eclipse.gmf.runtime.common.ui.util.DisplayUtils; +import org.eclipse.papyrus.uml.diagram.common.actions.handlers.ManagePortInterfacesHandler; +import org.eclipse.papyrus.uml.diagram.common.dialogs.IPortInterfaceManagerDialog; +import org.eclipse.papyrus.uml.diagram.component.custom.ui.ComponentInterfaceManagerDialog; +import org.eclipse.papyrus.uml.diagram.component.edit.parts.PortEditPart; +import org.eclipse.uml2.uml.Interface; +import org.eclipse.uml2.uml.Port; + +/** + * This handler provides the action to manage the provided and required {@link Interface} for a {@link Port}. + */ +public class ComponentManageInterfacesHandler extends ManagePortInterfacesHandler { + + public ComponentManageInterfacesHandler() { + super(); + } + + + /** + * @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 ComponentInterfaceManagerDialog(DisplayUtils.getDefaultShell(), (PortEditPart)getPortEditPart()); + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/actions/ManageProvidedInterfacesHandler.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/actions/ManageProvidedInterfacesHandler.java deleted file mode 100644 index 9c9e9c57d61..00000000000 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/actions/ManageProvidedInterfacesHandler.java +++ /dev/null @@ -1,114 +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.uml.diagram.component.custom.actions; - -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.EditPart; -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.uml.diagram.component.custom.messages.Messages; -import org.eclipse.papyrus.uml.diagram.component.custom.ui.DisplayInterfaceMDialog; -import org.eclipse.papyrus.uml.diagram.component.custom.ui.InterfaceManagerDialog; -import org.eclipse.papyrus.uml.diagram.component.edit.parts.PortEditPart; -import org.eclipse.ui.handlers.HandlerUtil; -import org.eclipse.uml2.uml.Classifier; -import org.eclipse.uml2.uml.Interface; -import org.eclipse.uml2.uml.Port; -import org.eclipse.uml2.uml.Type; - -/** - * This handler provides the action to manage the provided and required {@link Interface} for a {@link Port}. - */ -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; - if (structuredSelection.getFirstElement() instanceof PortEditPart) { - EObject selectedElement = EMFHelper.getEObject(structuredSelection.getFirstElement()); - if (selectedElement instanceof Port) { - Port port = (Port) selectedElement; - ManageProvidedInterfaceAction action = new ManageProvidedInterfaceAction(port, (EditPart) structuredSelection.getFirstElement()); - 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 Type} of the port. */ - private Type type; - private EditPart portEditPart; - - /** - * - * Constructor. - * - * @param port - * the semantic port - * - * @param aportEditpart - * the editpart of the port - */ - public ManageProvidedInterfaceAction(Port port, EditPart aportEditpart) { - this.type = port.getType(); - this.portEditPart = aportEditpart; - } - - /** - * Returns the command to add/remove provided/required interfaces. - * - * @return the command - * 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 DisplayInterfaceMDialog(DisplayUtils.getDefaultShell(), (PortEditPart) portEditPart); - if (dialog.open() == Dialog.OK) { - return dialog.getCommand(); - } - } - return UnexecutableCommand.INSTANCE; - } - } -} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/command/CreateLollipopPortCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/command/CreateLollipopPortCommand.java index 76cf791d048..58e763e4d4b 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/command/CreateLollipopPortCommand.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/command/CreateLollipopPortCommand.java @@ -9,16 +9,19 @@ * * Contributors: * Patrick Tessier (CEA LIST) - Initial API and implementation + * Gabriel Pascual (ALL4TEC) - Initial API and implementation /*****************************************************************************/ package org.eclipse.papyrus.uml.diagram.component.custom.command; import java.util.ArrayList; import java.util.Collection; +import java.util.List; import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; import org.eclipse.draw2d.geometry.Insets; import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.transaction.RecordingCommand; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.gef.EditPart; @@ -31,17 +34,20 @@ import org.eclipse.gmf.runtime.notation.Node; import org.eclipse.gmf.runtime.notation.NotationFactory; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.uml.diagram.common.dialogs.NewElementRepresentation; import org.eclipse.papyrus.uml.diagram.component.edit.parts.PortEditPart; import org.eclipse.papyrus.uml.diagram.component.providers.UMLViewProvider; -import org.eclipse.uml2.uml.Interface; /** * this class is used to create the lollipop interface from a port * */ public class CreateLollipopPortCommand extends RecordingCommand { - protected ArrayList providedInterface = new ArrayList(); - protected ArrayList requiredInterface = new ArrayList(); + + protected List providedInterface = new ArrayList(); + + protected List requiredInterface = new ArrayList(); + protected PortEditPart porteditPart = null; /** @@ -49,15 +55,15 @@ public class CreateLollipopPortCommand extends RecordingCommand { * Constructor. * * @param domain - * the transactional editing domain + * the transactional editing domain * @param provided - * a list of provided interface to display + * a list of provided interface to display * @param required - * a list of required interface to display + * a list of required interface to display * @param portEditpart - * the port editpart form which interfaces will be displayed + * the port editpart form which interfaces will be displayed */ - public CreateLollipopPortCommand(TransactionalEditingDomain domain, Collection provided, Collection required, PortEditPart portEditpart) { + public CreateLollipopPortCommand(TransactionalEditingDomain domain, Collection provided, Collection required, PortEditPart portEditpart) { super(domain, "Creation of lollipop for ports"); providedInterface.addAll(provided); requiredInterface.addAll(required); @@ -68,21 +74,39 @@ public class CreateLollipopPortCommand extends RecordingCommand { protected void doExecute() { UMLViewProvider umlViewProvider = new UMLViewProvider(); // get the position of the port around its container... - IFigure parentFigure = ((GraphicalEditPart) porteditPart.getParent()).getFigure(); + IFigure parentFigure = ((GraphicalEditPart)porteditPart.getParent()).getFigure(); Rectangle bounds = parentFigure.getBounds(); Rectangle insideRect = bounds.getCopy().shrink(new Insets(30)); int position = insideRect.getPosition(porteditPart.getLocation()); // take the great parent of the port EditPart componentEditPart = porteditPart.getParent(); EditPart container = componentEditPart.getParent(); - for (Interface currentRequired : requiredInterface) { - Node node = createInterfacenode(umlViewProvider, container, currentRequired); + for(Object currentRequired : requiredInterface) { + + + EObject interfaceRequired = null; + if(currentRequired instanceof NewElementRepresentation) { + interfaceRequired = ((NewElementRepresentation)currentRequired).getEObject(); + } else { + interfaceRequired = (EObject)currentRequired; + } + + Node node = createInterfacenode(umlViewProvider, container, interfaceRequired); setPositionNode(node, position); String kind = "REQUIRED"; createEdge(umlViewProvider, node, kind); } - for (Interface currentprovided : providedInterface) { - Node node = createInterfacenode(umlViewProvider, container, currentprovided); + for(Object currentprovided : providedInterface) { + + + EObject interfaceProvided = null; + if(currentprovided instanceof NewElementRepresentation) { + interfaceProvided = ((NewElementRepresentation)currentprovided).getEObject(); + } else { + interfaceProvided = (EObject)currentprovided; + } + + Node node = createInterfacenode(umlViewProvider, container, interfaceProvided); setPositionNode(node, position); String kind = "PROVIDED"; createEdge(umlViewProvider, node, kind); @@ -94,20 +118,20 @@ public class CreateLollipopPortCommand extends RecordingCommand { * * @param umlViewProvider * @param node - * the node that represent the interface + * the node that represent the interface * @param kind - * kind of the interface REQUIRED or PROVIDED + * kind of the interface REQUIRED or PROVIDED */ protected void createEdge(UMLViewProvider umlViewProvider, Node node, String kind) { - Edge edge = umlViewProvider.createLink_4018(((View) porteditPart.getModel()).getDiagram(), -1, true, porteditPart.getDiagramPreferencesHint()); + Edge edge = umlViewProvider.createLink_4018(((View)porteditPart.getModel()).getDiagram(), -1, true, porteditPart.getDiagramPreferencesHint()); IdentityAnchor anchor = NotationFactory.eINSTANCE.createIdentityAnchor(); edge.setSourceAnchor(anchor); anchor = NotationFactory.eINSTANCE.createIdentityAnchor(); edge.setTargetAnchor(anchor); - edge.setSource((View) porteditPart.getModel()); + edge.setSource((View)porteditPart.getModel()); edge.setTarget(node); edge.setElement(null); - EObjectValueStyle eObjectValueStyle = (EObjectValueStyle) edge.createStyle(NotationPackage.eINSTANCE.getEObjectValueStyle()); + EObjectValueStyle eObjectValueStyle = (EObjectValueStyle)edge.createStyle(NotationPackage.eINSTANCE.getEObjectValueStyle()); eObjectValueStyle.setName(kind); } @@ -116,15 +140,15 @@ public class CreateLollipopPortCommand extends RecordingCommand { * * @param umlViewProvider * @param container - * the container of the interface node + * the container of the interface node * @param currentInterface - * the interface + * the interface * @return the node */ - protected Node createInterfacenode(UMLViewProvider umlViewProvider, EditPart container, Interface currentInterface) { - Node node = umlViewProvider.createInterface_2003(currentInterface, (View) container.getModel(), -1, true, porteditPart.getDiagramPreferencesHint()); - ((Bounds) node.getLayoutConstraint()).setWidth(20); - ((Bounds) node.getLayoutConstraint()).setHeight(20); + protected Node createInterfacenode(UMLViewProvider umlViewProvider, EditPart container, EObject currentInterface) { + Node node = umlViewProvider.createInterface_2003(currentInterface, (View)container.getModel(), -1, true, porteditPart.getDiagramPreferencesHint()); + ((Bounds)node.getLayoutConstraint()).setWidth(20); + ((Bounds)node.getLayoutConstraint()).setHeight(20); return node; } @@ -132,25 +156,22 @@ public class CreateLollipopPortCommand extends RecordingCommand { * use to place the interface node around the component form the port * * @param node - * the interface node + * the interface node * @param position - * the position where is the port NORTH SOUTH, EAST, WEST + * the position where is the port NORTH SOUTH, EAST, WEST */ protected void setPositionNode(Node node, int position) { - ((Bounds) node.getLayoutConstraint()).setX(porteditPart.getLocation().x); - ((Bounds) node.getLayoutConstraint()).setY(porteditPart.getLocation().y); + ((Bounds)node.getLayoutConstraint()).setX(porteditPart.getLocation().x); + ((Bounds)node.getLayoutConstraint()).setY(porteditPart.getLocation().y); int distance = 60; - if (position == PositionConstants.SOUTH) { - ((Bounds) node.getLayoutConstraint()).setY(((Bounds) node.getLayoutConstraint()).getY() + distance); - } - else if (position == PositionConstants.NORTH) { - ((Bounds) node.getLayoutConstraint()).setY(((Bounds) node.getLayoutConstraint()).getY() - distance); - } - else if (position == PositionConstants.EAST) { - ((Bounds) node.getLayoutConstraint()).setX(((Bounds) node.getLayoutConstraint()).getX() + distance); - } - else if (position == PositionConstants.WEST) { - ((Bounds) node.getLayoutConstraint()).setX(((Bounds) node.getLayoutConstraint()).getX() - distance); + if(position == PositionConstants.SOUTH) { + ((Bounds)node.getLayoutConstraint()).setY(((Bounds)node.getLayoutConstraint()).getY() + distance); + } else if(position == PositionConstants.NORTH) { + ((Bounds)node.getLayoutConstraint()).setY(((Bounds)node.getLayoutConstraint()).getY() - distance); + } else if(position == PositionConstants.EAST) { + ((Bounds)node.getLayoutConstraint()).setX(((Bounds)node.getLayoutConstraint()).getX() + distance); + } else if(position == PositionConstants.WEST) { + ((Bounds)node.getLayoutConstraint()).setX(((Bounds)node.getLayoutConstraint()).getX() - distance); } } } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/messages/Messages.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/messages/Messages.java index 81dae954839..34a84797d1b 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/messages/Messages.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/messages/Messages.java @@ -1,82 +1,43 @@ -/***************************************************************************** - * 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: - * Amine EL KOUHEN (CEA LIST/INRIA DaRT) amine.el_kouhen@inria.fr - *****************************************************************************/ -package org.eclipse.papyrus.uml.diagram.component.custom.messages; - -import org.eclipse.osgi.util.NLS; - -// TODO: Auto-generated Javadoc -/** - * The Class Messages. - */ -public class Messages extends NLS { - - /** The Constant BUNDLE_NAME. */ - private static final String BUNDLE_NAME = "org.eclipse.papyrus.uml.diagram.component.custom.messages.messages"; //$NON-NLS-1$ - - - /** The Create uml element dialog_ new_ element_ name. */ - public static String CreateUmlElementDialog_New_Element_Name; - - /** The Selection validated. */ - public static String SelectionValidated; - - /** The Show hide related contents action_ message. */ - public static String ShowHideRelatedContentsAction_Message; - - /** The Show hide related contents action_ title. */ - public static String ShowHideRelatedContentsAction_Title; - - /** The Interface manager dialog_ create a new interface. */ - public static String InterfaceManagerDialog_CreateANewInterface; - - /** The Interface manager dialog_ create new interface. */ - public static String InterfaceManagerDialog_CreateNewInterface; - - /** The Interface manager dialog_ selected the provided interfaces. */ - public static String InterfaceManagerDialog_SelectedTheProvidedInterfaces; - - /** The Interface manager dialog_ selection has to be a package or a classifier. */ - public static String InterfaceManagerDialog_SelectionHasToBeAPackageOrAClassifier; - - /** The Interface manager dialog_ select the parent of this new interface. */ - public static String InterfaceManagerDialog_SelectTheParentOfThisNewInterface; - - /** The Interface manager dialog_ select the required interfaces. */ - public static String InterfaceManagerDialog_SelectTheRequiredInterfaces; - - /** The Interface manager dialog_ the port is typed with an interface warning message. */ - public static String InterfaceManagerDialog_ThePortIsTypedWithAnInterfaceWarningMessage; - - /** The Interface manager dialog_ title. */ - public static String InterfaceManagerDialog_Title; - - /** The Manage provided interfaces handler_ ok. */ - public static String ManageProvidedInterfacesHandler_OK; - - /** The Manage provided interfaces handler_ the type of the port is not defined. */ - public static String ManageProvidedInterfacesHandler_TheTypeOfThePortIsNotDefined; - - /** The No selection found. */ - public static String NoSelectionFound; - - static { - // initialize resource bundle - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } - - /** - * Instantiates a new messages. - */ - 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: + * Amine EL KOUHEN (CEA LIST/INRIA DaRT) amine.el_kouhen@inria.fr + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.component.custom.messages; + +import org.eclipse.osgi.util.NLS; + +// TODO: Auto-generated Javadoc +/** + * The Class Messages. + */ +public class Messages extends NLS { + + /** The Constant BUNDLE_NAME. */ + private static final String BUNDLE_NAME = "org.eclipse.papyrus.uml.diagram.component.custom.messages.messages"; //$NON-NLS-1$ + + /** The Show hide related contents action_ message. */ + public static String ShowHideRelatedContentsAction_Message; + + /** The Show hide related contents action_ title. */ + public static String ShowHideRelatedContentsAction_Title; + + + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + /** + * Instantiates a new messages. + */ + private Messages() { + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/messages/messages.properties b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/messages/messages.properties index 30939585760..6542cfeb463 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/messages/messages.properties +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/messages/messages.properties @@ -1,26 +1,13 @@ -############################################################################### -# 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: -# Amine EL KOUHEN (CEA LIST) amine.el_kouhen@cea.fr -############################################################################### -CreateUmlElementDialog_New_Element_Name=New Element Name -SelectionValidated=Selection validated. -ShowHideRelatedContentsAction_Message=Choose the elements to show -ShowHideRelatedContentsAction_Title=Show/Hide Related Contents -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 is not defined. You need to define it before managing its Interfaces. -NoSelectionFound=No selection found. \ No newline at end of file +############################################################################### +# 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: +# Amine EL KOUHEN (CEA LIST) amine.el_kouhen@cea.fr +############################################################################### +ShowHideRelatedContentsAction_Message=Choose the elements to show +ShowHideRelatedContentsAction_Title=Show/Hide Related Contents \ No newline at end of file diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/ui/ComponentInterfaceManagerDialog.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/ui/ComponentInterfaceManagerDialog.java new file mode 100644 index 00000000000..87af5f56cc5 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/ui/ComponentInterfaceManagerDialog.java @@ -0,0 +1,295 @@ +/***************************************************************************** + * Copyright (c) 2013 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: + * Patrick Tessier (CEA LIST) - Initial API and implementation + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - initial API and implementation + /*****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.component.custom.ui; + +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; + +import org.eclipse.gef.Request; +import org.eclipse.gef.RequestConstants; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CompoundCommand; +import org.eclipse.gef.requests.GroupRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart; +import org.eclipse.gmf.runtime.notation.EObjectValueStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.papyrus.infra.widgets.editors.IElementSelector; +import org.eclipse.papyrus.uml.diagram.common.Messages; +import org.eclipse.papyrus.uml.diagram.common.dialogs.ExtendedSelectionEditor; +import org.eclipse.papyrus.uml.diagram.common.dialogs.InterfaceManagerDialog; +import org.eclipse.papyrus.uml.diagram.common.dialogs.NewElementRepresentation; +import org.eclipse.papyrus.uml.diagram.common.dialogs.SelectionEditorWrapper; +import org.eclipse.papyrus.uml.diagram.component.custom.command.CreateLollipopPortCommand; +import org.eclipse.papyrus.uml.diagram.component.edit.parts.PortEditPart; +import org.eclipse.papyrus.uml.diagram.component.part.UMLDiagramEditorPlugin; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.uml2.uml.Interface; +import org.eclipse.uml2.uml.Port; + +/** + * This interface is used to displayed required and provided interfaces + * + */ +public class ComponentInterfaceManagerDialog extends InterfaceManagerDialog { + + protected HashSet displayedRequiredInterfacesList = new HashSet(); + + protected HashSet displayedProvidedInterfacesList = new HashSet(); + + protected PortEditPart portEditPart = null; + + protected HashMap initialList = new HashMap(); + + /** + * + * Constructor. + * + * @param parentShell + * @param portEditPart + */ + public ComponentInterfaceManagerDialog(Shell parentShell, PortEditPart portEditPart) { + super(parentShell, (Port)portEditPart.resolveSemanticElement()); + this.portEditPart = portEditPart; + setSelectorLabelProvider(new DisplayedSelectorLabelProvider()); + initDisplayInterfaceList(); + } + + /** + * init the collection to detect displayed interfaces + */ + protected void initDisplayInterfaceList() { + + if((portEditPart.getSourceConnections().size() > 0)) { + + for(Object currentConnection : portEditPart.getSourceConnections()) { + ConnectionEditPart connection = (ConnectionEditPart)currentConnection; + EObjectValueStyle valueStyle = (EObjectValueStyle)((View)connection.getModel()).getStyle(NotationPackage.eINSTANCE.getEObjectValueStyle()); + if(valueStyle != null) { + if(valueStyle.getName().equals("REQUIRED")) { + displayedRequiredInterfacesList.add((Interface)((GraphicalEditPart)connection.getTarget()).resolveSemanticElement()); + } else { + displayedProvidedInterfacesList.add((Interface)((GraphicalEditPart)connection.getTarget()).resolveSemanticElement()); + } + initialList.put((Interface)((GraphicalEditPart)connection.getTarget()).resolveSemanticElement(), ((GraphicalEditPart)connection.getTarget())); + + } + } + } + + } + + /** + * @see org.eclipse.papyrus.uml.diagram.common.dialogs.InterfaceManagerDialog#getCommand() + * + * @return + */ + @Override + public Command getCommand() { + CompoundCommand cmd = new CompoundCommand(); + Command supCmd = super.getCommand(); + if(supCmd.canExecute()) { + cmd.add(super.getCommand()); + } + cmd.add(createDisplayedInterfaceCommand()); + return cmd; + } + + @Override + protected void createEditors() { + Composite parent = (Composite)getDialogArea(); + Composite subComposite = new Composite(parent, SWT.NONE); + + subComposite.setLayout(new FormLayout()); + //createDisplay button + Button Displaybutton = new Button(subComposite, SWT.PUSH); + Displaybutton.setText("Display seletected Interface"); + DisplayInterfaceListener displayInterfaceListener = new DisplayInterfaceListener(); + Displaybutton.addSelectionListener(displayInterfaceListener); + + + FormData formData = new FormData(); + formData.left = new FormAttachment(0, 700); + Displaybutton.setLayoutData(formData); + + //create Remove + Button RemoveDisplaybutton = new Button(subComposite, SWT.PUSH); + RemoveDisplaybutton.setText(" Do not Display selected Interface"); + RemoveDisplayInterfaceListener removeDisplayInterfaceListener = new RemoveDisplayInterfaceListener(); + RemoveDisplaybutton.addSelectionListener(removeDisplayInterfaceListener); + + formData = new FormData(); + formData.left = new FormAttachment(0, 500); + RemoveDisplaybutton.setLayoutData(formData); + + super.createEditors(); + } + + /** + * + * @return the command that will be used to display interfaces + */ + protected Command createDisplayedInterfaceCommand() { + // Update list from initial List + HashMap viewToRemove = new HashMap(); + HashSet requiredInterfaceToDisplay = new HashSet(); + HashSet providedInterfaceToDisplay = new HashSet(); + // create the list of provided interface to display + for(Object currentInterface : displayedProvidedInterfacesList) { + if(!initialList.keySet().contains(currentInterface)) { + providedInterfaceToDisplay.add(currentInterface); + } + } + // create the list of required interface to display + for(Object currentInterface : displayedRequiredInterfacesList) { + if(!initialList.keySet().contains(currentInterface)) { + requiredInterfaceToDisplay.add(currentInterface); + } + } + // create the list of interface to not display + for(Interface currentInterface : initialList.keySet()) { + if((!displayedRequiredInterfacesList.contains(currentInterface)) && (!displayedProvidedInterfacesList.contains(currentInterface))) { + viewToRemove.put(currentInterface, initialList.get(currentInterface)); + } + } + + CompoundCommand cmd = new CompoundCommand(); + CreateLollipopPortCommand comd = new CreateLollipopPortCommand(this.portEditPart.getEditingDomain(), providedInterfaceToDisplay, requiredInterfaceToDisplay, this.portEditPart); + cmd.add(new org.eclipse.papyrus.commands.wrappers.EMFtoGEFCommandWrapper(comd)); + if(viewToRemove.values().size() > 0) { + cmd.add(deleteDisplayInterface(viewToRemove.values())); + } + return cmd; + } + + @Override + protected SelectionEditorWrapper createEditor(Composite parent, IElementSelector selector, String message, boolean withCreateButton, SelectionListener listener, List initialSelection) { + ExtendedSelectionEditor editor = new ExtendedSelectionEditor(parent, selector, getSelectorLabelProvider(), initialSelection); + editor.setMessage(message); + editor.setAdditionalButton(withCreateButton, Messages.InterfaceManagerDialog_CreateNewInterface, listener); + return new SelectionEditorWrapper(editor, editor.getClass()); + } + + /** + * @param editPartToRemove + * list of editpart that represents displayed interfaces, never null + * @return the command of interface representation to remove, never null + */ + protected Command deleteDisplayInterface(Collection editPartToRemove) { + CompoundCommand cmd = new CompoundCommand(); + Request deleteViewRequest = new GroupRequest(RequestConstants.REQ_DELETE); + + + for(GraphicalEditPart editPart : editPartToRemove) { + cmd.add(editPart.getCommand(deleteViewRequest)); + } + + return cmd; + } + + /** + * inner to class attached to a button to display interfaces + * + */ + class DisplayInterfaceListener extends SelectionAdapter { + + public void widgetSelected(SelectionEvent event) { + IStructuredSelection selection = (IStructuredSelection)getProvidedEditor().getSelection(); + for(Object o : selection.toArray()) { + + displayedProvidedInterfacesList.add(o); + } + + + selection = (IStructuredSelection)getRequiredEditor().getSelection(); + for(Object o : selection.toArray()) { + displayedRequiredInterfacesList.add(o); + } + getProvidedEditor().refresh(); + getRequiredEditor().refresh(); + } + + } + + /** + * inner to class attached to a button to remove displayed interfaces + * + */ + class RemoveDisplayInterfaceListener extends SelectionAdapter { + + public void widgetSelected(SelectionEvent event) { + + // Handle provided interfaces selection + IStructuredSelection structuredSelection = (IStructuredSelection)getProvidedEditor().getSelection(); + for(Object selection : structuredSelection.toArray()) { + displayedProvidedInterfacesList.remove(selection); + } + + // Handle required interfaces selection + structuredSelection = (IStructuredSelection)getRequiredEditor().getSelection(); + for(Object o : structuredSelection.toArray()) { + + displayedRequiredInterfacesList.remove(o); + } + + // Refresh both list + getProvidedEditor().refresh(); + getRequiredEditor().refresh(); + } + + } + + + /** + * + * This class provides a CustomLabelProvider for this dialog. + * This class manages the {@link NewElementRepresentation} and consider them like Interfaces + * + * + */ + public class DisplayedSelectorLabelProvider extends SelectorLabelProvider { + + private static final String ICONS_OBJ16_LOLLIPOP_GIF = "icons/obj16/lollipop.gif"; //$NON-NLS-1$ + + /** + * @see org.eclipse.papyrus.uml.diagram.component.custom.ui.InterfaceManagerDialog.CreateElementLabelProvider#getImage(java.lang.Object) + * + * @param element + * @return + */ + @Override + public Image getImage(Object element) { + + if(displayedRequiredInterfacesList.contains(element) || displayedProvidedInterfacesList.contains(element)) { + return org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage(UMLDiagramEditorPlugin.ID, ICONS_OBJ16_LOLLIPOP_GIF); + } + return super.getImage(element); + } + + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/ui/CreateUmlElementDialog.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/ui/CreateUmlElementDialog.java deleted file mode 100644 index faecb5afc3a..00000000000 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/ui/CreateUmlElementDialog.java +++ /dev/null @@ -1,404 +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.uml.diagram.component.custom.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.uml.diagram.component.custom.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; - -// TODO: Auto-generated Javadoc -/** - * 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; - /** 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 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 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 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 true, if is correct name true 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, null, 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 result = new ArrayList(); - 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 null 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/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/ui/DisplayInterfaceMDialog.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/ui/DisplayInterfaceMDialog.java deleted file mode 100644 index 10c67084153..00000000000 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/ui/DisplayInterfaceMDialog.java +++ /dev/null @@ -1,257 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2013 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: - * Patrick Tessier (CEA LIST) - Initial API and implementation - /*****************************************************************************/ -package org.eclipse.papyrus.uml.diagram.component.custom.ui; - -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.gef.Request; -import org.eclipse.gef.RequestConstants; -import org.eclipse.gef.commands.Command; -import org.eclipse.gef.commands.CompoundCommand; -import org.eclipse.gef.requests.GroupRequest; -import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart; -import org.eclipse.gmf.runtime.notation.EObjectValueStyle; -import org.eclipse.gmf.runtime.notation.NotationPackage; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.papyrus.uml.diagram.component.custom.command.CreateLollipopPortCommand; -import org.eclipse.papyrus.uml.diagram.component.edit.parts.PortEditPart; -import org.eclipse.papyrus.uml.diagram.component.part.UMLDiagramEditorPlugin; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.FormAttachment; -import org.eclipse.swt.layout.FormData; -import org.eclipse.swt.layout.FormLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.uml2.uml.Interface; -import org.eclipse.uml2.uml.Port; - -/** - * this interface is used to displayed required and provided interfaces - * - */ -public class DisplayInterfaceMDialog extends InterfaceManagerDialog { - - protected HashSet displayedRequiredInterface=new HashSet(); - protected HashSet displayedProvidedInterface=new HashSet(); - protected PortEditPart portEditPart=null; - protected HashMap initialList=new HashMap(); - - /** - * - * Constructor. - * - * @param parentShell - * @param portEditPart - */ - public DisplayInterfaceMDialog(Shell parentShell, PortEditPart portEditPart) { - super(parentShell, (Port)portEditPart.resolveSemanticElement()); - this.portEditPart=portEditPart; - this.selectorLabelProvider=new DisplayedSelectorLabelProvider(); - initDisplayInterfaceList(); - } - - /** - * init the collection to detect displayed interfaces - */ - protected void initDisplayInterfaceList(){ - - if((portEditPart.getSourceConnections().size()>0) ){ - - for(Object currentConnection : portEditPart.getSourceConnections()) { - ConnectionEditPart connection=(ConnectionEditPart) currentConnection; - EObjectValueStyle valueStyle=(EObjectValueStyle)((View)connection.getModel()).getStyle(NotationPackage.eINSTANCE.getEObjectValueStyle()); - if( valueStyle!=null){ - if(valueStyle.getName().equals("REQUIRED")){ - displayedRequiredInterface.add((Interface)((GraphicalEditPart)connection.getTarget()).resolveSemanticElement()); - } - else{ - displayedProvidedInterface.add((Interface)((GraphicalEditPart)connection.getTarget()).resolveSemanticElement()); - } - initialList.put((Interface)((GraphicalEditPart)connection.getTarget()).resolveSemanticElement(),((GraphicalEditPart)connection.getTarget())); - - } - } - } - - } - - /** - * Overload the result in order to display provided and required interfaces - * @see org.eclipse.papyrus.uml.diagram.component.custom.ui.InterfaceManagerDialog#getCommand() - * - */ - @Override - public Command getCommand() { - CompoundCommand cmd= new CompoundCommand(); - Command supCmd=super.getCommand(); - if( supCmd.canExecute()){ - cmd.add(super.getCommand()); - } - cmd.add(createDisplayedInterfaceCommand()); - return cmd; - } - @Override - protected void createEditors() { - Composite parent = (Composite)getDialogArea(); - Composite subComposite= new Composite(parent, SWT.NONE); - - subComposite.setLayout(new FormLayout()); - //createDisplay button - Button Displaybutton = new Button(subComposite, SWT.PUSH); - Displaybutton.setText("Display seletected Interface"); - DisplayInterfaceListener displayInterfaceListener= new DisplayInterfaceListener(); - Displaybutton.addSelectionListener(displayInterfaceListener); - - - FormData formData = new FormData(); - formData.left = new FormAttachment(0,700); - Displaybutton.setLayoutData(formData); - - //create Remove - Button RemoveDisplaybutton = new Button(subComposite, SWT.PUSH); - RemoveDisplaybutton.setText(" Do not Display selected Interface"); - RemoveDisplayInterfaceListener removeDisplayInterfaceListener= new RemoveDisplayInterfaceListener(); - RemoveDisplaybutton.addSelectionListener(removeDisplayInterfaceListener); - - formData = new FormData(); - formData.left = new FormAttachment(0,500); - RemoveDisplaybutton.setLayoutData(formData); - - super.createEditors(); - } - - /** - * - * @return teh command that will be used to display interfaces - */ - protected Command createDisplayedInterfaceCommand(){ - //update list from initial List - HashMap viewToRemove= new HashMap(); - HashSetrequiredInterfaceToDisplay= new HashSet(); - HashSetprovidedInterfaceToDisplay= new HashSet(); - // create the list of provided interface to display - for(Interface currentInterface : displayedProvidedInterface) { - if(!initialList.keySet().contains(currentInterface)){ - providedInterfaceToDisplay.add(currentInterface); - } - } - // create the list of required interface to display - for(Interface currentInterface : displayedRequiredInterface) { - if(!initialList.keySet().contains(currentInterface)){ - requiredInterfaceToDisplay.add(currentInterface); - } - } - // create the list of interface to not display - for(Interface currentInterface : initialList.keySet()) { - if((!displayedRequiredInterface.contains(currentInterface))&&(!displayedProvidedInterface.contains(currentInterface))){ - viewToRemove.put(currentInterface, initialList.get(currentInterface)); - } - } - - CompoundCommand cmd= new CompoundCommand(); - CreateLollipopPortCommand comd= new CreateLollipopPortCommand(this.portEditPart.getEditingDomain(),providedInterfaceToDisplay, requiredInterfaceToDisplay , this.portEditPart); - cmd.add( new org.eclipse.papyrus.commands.wrappers.EMFtoGEFCommandWrapper(comd)); - if(viewToRemove.values().size()>0 ){ - cmd.add(deleteDisplayInterface(viewToRemove.values())); - } - return cmd; - } - - /** - * @param editPartToRemove list of editpart that represents displayed interfaces, never null - * @return the command of interface representation to remove, never null - */ - protected Command deleteDisplayInterface(Collection editPartToRemove){ - CompoundCommand cmd= new CompoundCommand(); - Request deleteViewRequest = new GroupRequest(RequestConstants.REQ_DELETE); - - - for(GraphicalEditPart editPart : editPartToRemove) { - cmd.add(editPart.getCommand(deleteViewRequest)); - } - - return cmd; - } - - /** - * inner to class attached to a button to display interfaces - * - */ - class DisplayInterfaceListener extends SelectionAdapter { - public void widgetSelected(SelectionEvent event) { - IStructuredSelection selection = (IStructuredSelection)providedEditor.getSelectedElementsViewer().getSelection(); - for(Object o : selection.toArray()) { - displayedProvidedInterface.add((Interface)o); - } - selection = (IStructuredSelection)requiredEditor.getSelectedElementsViewer().getSelection(); - for(Object o : selection.toArray()) { - displayedRequiredInterface.add((Interface)o); - } - providedEditor.getSelectedElementsViewer().refresh(); - requiredEditor.getSelectedElementsViewer().refresh(); - } - - } - - /** - * inner to class attached to a button to remove displayed interfaces - * - */ - class RemoveDisplayInterfaceListener extends SelectionAdapter { - public void widgetSelected(SelectionEvent event) { - - IStructuredSelection selection = (IStructuredSelection)providedEditor.getSelectedElementsViewer().getSelection(); - for(Object o : selection.toArray()) { - displayedProvidedInterface.remove((Interface)o); - } - selection = (IStructuredSelection)requiredEditor.getSelectedElementsViewer().getSelection(); - for(Object o : selection.toArray()) { - displayedRequiredInterface.remove((Interface)o); - } - providedEditor.getSelectedElementsViewer().refresh(); - requiredEditor.getSelectedElementsViewer().refresh(); - } - - } - - - /** - * - * This class provides a CustomLabelProvider for this dialog. - * This class manages the {@link NewElementRepresentation} and consider them like Interfaces - * - * - */ - public class DisplayedSelectorLabelProvider extends SelectorLabelProvider { - - private static final String ICONS_OBJ16_LOLLIPOP_GIF = "icons/obj16/lollipop.gif"; //$NON-NLS-1$ - - @Override - protected Image getImage(EObject element) { - if(displayedRequiredInterface.contains(element)||displayedProvidedInterface.contains(element)){ - return org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage(UMLDiagramEditorPlugin.ID, ICONS_OBJ16_LOLLIPOP_GIF); - } - return super.getImage(element); - } - - } -} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/ui/ExtendedSelectionEditor.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/ui/ExtendedSelectionEditor.java deleted file mode 100644 index 748c329cd3a..00000000000 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/ui/ExtendedSelectionEditor.java +++ /dev/null @@ -1,545 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2013 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: - * Patrick Tessier (CEA LIST) - Initial API and implementation - /*****************************************************************************/ -package org.eclipse.papyrus.uml.diagram.component.custom.ui; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedList; - -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.papyrus.infra.widgets.Activator; -import org.eclipse.papyrus.infra.widgets.editors.IElementSelector; -import org.eclipse.papyrus.infra.widgets.messages.Messages; -import org.eclipse.papyrus.infra.widgets.providers.CollectionContentProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Table; -/** - * Extension of selection editor with a table to display icon of element - *normally this class must inherits of SelectionEditor but list and table are type that are not compatible, so entire creation of this class was needed - */ - -public class ExtendedSelectionEditor extends Composite implements SelectionListener { - - - /** the initial selection */ - protected final java.util.List initialSelection; - - /** The object selector */ - private IElementSelector selector; - - /** The SWT Composite in which the selector is drawn */ - protected Composite selectorSection; - - /** The message section */ - protected Composite messageSection; - - /** The additional button section */ - protected Composite createAdditionalButtonSection; - - /** The up/down buttons section */ - protected Composite rightButtonsSection; - - /** The listViewer for chosen elements */ - protected TableViewer selectedElementsViewer; - - /** - * - * @return the table viewer in order to get the element selection - */ - public TableViewer getSelectedElementsViewer() { - return selectedElementsViewer; - } - - /** The list for chosen elements */ - protected Table selectedElements; - - /** The add action button */ - private Button add; - - /** The remove action button */ - private Button remove; - - /** The add all action button */ - private Button addAll; - - /** The remove all action button */ - private Button removeAll; - - /** the up action button */ - private Button up; - - /** the down action button */ - private Button down; - - /** The label provider for the listViewer of chosen elements */ - private ILabelProvider labelProvider; - - /** The currently chosen elements */ - protected final Collection currentSelection; - - /** the listener for the additional button */ - private SelectionListener additionalButtonSelectionListener; - - /** the message for the editor */ - private String message; - - - /* - * This dialog can provide a Button to do some optional action - */ - - /** Indicates if the dialog provides a button */ - private boolean withAdditionalButton = false; - - /** the label of the button */ - private String additionalButtonLabel = null; - - /** the button */ - private Button additionalButton; - - /** The add/remove/addAll buttons section */ - protected Composite buttonSection; - - /** - * - * Constructor. - * - * @param parent - * the parent of this composite - * @param selector - * the selector - * @param labelProvider - * the label provider - * @param initialSelection - * the initial selection - */ - public ExtendedSelectionEditor(Composite parent, IElementSelector selector, ILabelProvider labelProvider, java.util.List initialSelection) { - super(parent, SWT.NONE); - this.selector = selector; - this.labelProvider = labelProvider; - this.initialSelection = new ArrayList(); - for(Object current : initialSelection) { - this.initialSelection.add(current); - } - currentSelection = initialSelection; - } - - /** - * This methods create this editor - */ - public void create() { - Composite parent = this; - GridLayout layout = new GridLayout(1, true); - GridData data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.grabExcessVerticalSpace = true; - parent.setLayout(layout); - createMessageSection(parent); - createBody(parent); - createCreateButtonSection(parent); - } - - /** - * This method create the body of the editor : - *
    - *
  • the selector
  • - *
  • the list
  • - *
  • the buttons Add, AddAll, Remove, RemoveAll, Up, Down
  • - *
- * - * @param parent - * the parent composite - */ - protected void createBody(Composite parent) { - - Composite par = new Composite(parent, SWT.NONE); - createSelectorSection(par); - createControlsSection(par); - createListSection(par); - createRightButtonsSection(par); - GridLayout layout = new GridLayout(); - layout.makeColumnsEqualWidth = false; - layout.numColumns = 4; - par.setLayout(layout); - GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); - par.setLayoutData(data); - - } - - /** - * Creates the Message section - * - * @param parent - * the parent of the {@link Composite} - */ - protected void createMessageSection(Composite parent) { - messageSection = new Composite(parent, SWT.NONE); - Label label = new Label(messageSection, SWT.NONE); - label.setText(message); - messageSection.setLayout(new FillLayout(SWT.HORIZONTAL)); - } - - /** - * Creates the button section - * - * @param parent - * the parent of the {@link Composite} - */ - protected void createCreateButtonSection(Composite parent) { - if(this.withAdditionalButton) { - buttonSection = new Composite(parent, SWT.NONE); - additionalButton = new Button(buttonSection, SWT.PUSH); - if(additionalButtonLabel != null) { - additionalButton.setText(additionalButtonLabel); - } - buttonSection.setLayout(new FillLayout()); - this.additionalButton.addSelectionListener(additionalButtonSelectionListener); - } - } - - /** - * Creates the selector section - * - * @param parent - * The composite in which the section is created - */ - protected void createSelectorSection(Composite parent) { - selectorSection = new Composite(parent, SWT.NONE); - selectorSection.setLayout(new FillLayout()); - GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); - data.widthHint = 400; - - // data.exclude = true; - selectorSection.setLayoutData(data); - selector.createControls(selectorSection); - - } - - /** - * Creates the main controls section (Add, remove, Add all, remove all) - * - * @param parent - * The composite in which the section is created - */ - protected void createControlsSection(Composite parent) { - buttonSection = new Composite(parent, SWT.NONE); - buttonSection.setLayout(new GridLayout(1, true)); - - add = new Button(buttonSection, SWT.PUSH); - add.setImage(Activator.getDefault().getImage("/icons/arrow_right.gif")); //$NON-NLS-1$ - add.addSelectionListener(this); - add.setToolTipText(Messages.MultipleValueSelectorDialog_AddSelectedElements); - - remove = new Button(buttonSection, SWT.PUSH); - remove.setImage(Activator.getDefault().getImage("/icons/arrow_left.gif")); //$NON-NLS-1$ - remove.addSelectionListener(this); - remove.setToolTipText(Messages.MultipleValueEditor_RemoveSelectedElements); - - addAll = new Button(buttonSection, SWT.PUSH); - addAll.setImage(Activator.getDefault().getImage("/icons/arrow_double.gif")); //$NON-NLS-1$ - addAll.addSelectionListener(this); - addAll.setToolTipText(Messages.MultipleValueSelectorDialog_AddAllElements); - - removeAll = new Button(buttonSection, SWT.PUSH); - removeAll.setImage(Activator.getDefault().getImage("/icons/arrow_left_double.gif")); //$NON-NLS-1$ - removeAll.addSelectionListener(this); - removeAll.setToolTipText(Messages.MultipleValueSelectorDialog_RemoveAllElements); - } - - - /** - * Creates the list displaying the currently selected elements - * - * @param parent - * The composite in which the section is created - */ - protected void createListSection(Composite parent) { - Composite listSection = new Composite(parent, SWT.NONE); - selectedElements = new Table(listSection, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); - GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); - data.widthHint = 400; - listSection.setLayout(new FillLayout()); - listSection.setLayoutData(data); - - selectedElementsViewer = new TableViewer(selectedElements); - - selectedElementsViewer.setContentProvider(CollectionContentProvider.instance); - - if(labelProvider != null) - selectedElementsViewer.setLabelProvider(labelProvider); - - selectedElementsViewer.setInput(currentSelection); - selector.setSelectedElements(currentSelection.toArray()); - - } - - /** - * Creates the up/down controls section - * - * @param parent - * The composite in which the section is created - */ - protected void createRightButtonsSection(Composite parent) { - rightButtonsSection = new Composite(parent, SWT.NONE); - rightButtonsSection.setLayout(new GridLayout(1, true)); - - up = new Button(rightButtonsSection, SWT.PUSH); - up.setImage(Activator.getDefault().getImage("/icons/Up_12x12.gif")); //$NON-NLS-1$ - up.addSelectionListener(this); - up.setToolTipText(Messages.MultipleValueEditor_MoveSelectedElementsUp); - - down = new Button(rightButtonsSection, SWT.PUSH); - down.setImage(Activator.getDefault().getImage("/icons/Down_12x12.gif")); //$NON-NLS-1$ - down.addSelectionListener(this); - down.setToolTipText(Messages.MultipleValueEditor_MoveSelectedElementsDown); - } - - - - /** - * {@inheritDoc} Handles the events on one of the control buttons - * - * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) - * - * @param e - * The event that occurred - */ - public void widgetSelected(SelectionEvent e) { - if(e.widget == add) { - addAction(); - } else if(e.widget == remove) { - removeAction(); - } else if(e.widget == addAll) { - addAllAction(); - } else if(e.widget == removeAll) { - removeAllAction(); - } else if(e.widget == up) { - upAction(); - } else if(e.widget == down) { - downAction(); - } - } - - /** - * Handles the "Add" action - */ - protected void addAction() { - Object[] elements = selector.getSelectedElements(); - addElements(elements); - } - - /** - * Handles the "Up" action - */ - protected void upAction() { - IStructuredSelection selection = (IStructuredSelection)selectedElementsViewer.getSelection(); - - //We need a list to move objects. LinkedHashSet can't do that - java.util.List list = new LinkedList(currentSelection); - for(Object o : selection.toArray()) { - int oldIndex = list.indexOf(o); - if(oldIndex > 0) - move(list, oldIndex, oldIndex - 1); - } - - currentSelection.clear(); - currentSelection.addAll(list); - - IStructuredSelection selectionCopy = new StructuredSelection(selection.toArray()); - selectedElementsViewer.setSelection(selectionCopy); - selectedElementsViewer.refresh(); - } - - /** - * Handles the "Down" action - */ - protected void downAction() { - IStructuredSelection selection = (IStructuredSelection)selectedElementsViewer.getSelection(); - - //We need a list to move objects. LinkedHashSet can't do that - java.util.List list = new LinkedList(currentSelection); - - int maxIndex = list.size() - 1; - - Object[] selectionArray = selection.toArray(); - for(int i = selectionArray.length - 1; i >= 0; i--) { - Object o = selectionArray[i]; - int oldIndex = list.indexOf(o); - if(oldIndex < maxIndex) - move(list, oldIndex, oldIndex + 1); - } - - currentSelection.clear(); - currentSelection.addAll(list); - - IStructuredSelection selectionCopy = new StructuredSelection(selection.toArray()); - selectedElementsViewer.setSelection(selectionCopy); - selectedElementsViewer.refresh(); - } - - /** - * Moves an element from oldIndex to newIndex - * - * @param list - * The list in which to move the object - * @param oldIndex - * @param newIndex - */ - protected void move(java.util.List list, int oldIndex, int newIndex) { - int size = list.size(); - - if(oldIndex < 0 || oldIndex >= size) - throw new IndexOutOfBoundsException("oldIndex: " + oldIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ - if(newIndex < 0 || newIndex >= size) - throw new IndexOutOfBoundsException("newIndex: " + newIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ - Object element = list.remove(oldIndex); - list.add(newIndex, element); - } - - /** - * Handles the "Remove" action - */ - protected void removeAction() { - IStructuredSelection selection = (IStructuredSelection)selectedElementsViewer.getSelection(); - if(selection.isEmpty()) - return; - - for(Object element : selection.toArray()) { - currentSelection.remove(element); - } - - selector.setSelectedElements(currentSelection.toArray()); - selectedElementsViewer.setSelection(null); - selectedElementsViewer.refresh(); - } - - /** - * Handles the "Remove all" action - */ - protected void removeAllAction() { - currentSelection.clear(); - selector.setSelectedElements(new Object[0]); - selectedElementsViewer.setSelection(null); - selectedElementsViewer.refresh(); - } - - /** - * Handles the "Add All" action - */ - protected void addAllAction() { - Object[] elements = selector.getAllElements(); - addElements(elements); - } - - /** - * Adds the specified elements to the currently selected elements (For - * "Add" and "Add all" actions) - * - * @param elements - * The elements to be added - */ - protected void addElements(Object[] elements) { - if(elements != null) { - currentSelection.addAll(Arrays.asList(elements)); - selectedElementsViewer.refresh(); - } - } - - - /** - * - * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) - * - * @param e - */ - public void widgetDefaultSelected(SelectionEvent e) { - //Nothing to do - } - - /** - * - * @param withAdditionalButton - * @param messageButton - * @param listener - */ - public void setAdditionalButton(boolean withAdditionalButton, String messageButton, SelectionListener listener) { - this.withAdditionalButton = withAdditionalButton; - this.additionalButtonLabel = messageButton; - this.additionalButtonSelectionListener = listener; - } - - /** - * Set the message displayed by the Editor - * - * @param string - * the message displayed by the editor - */ - public void setMessage(String string) { - this.message = string; - } - - /** - * Returns all selected elements - * - * @return - * all selected elements - */ - public Collection getSelectedElements() { - return currentSelection; - } - - - /** - * Returns the list of the elements to remove - * - * @return - * the list of the elements to remove - */ - public java.util.List getElementToRemove() { - java.util.List removedObject = new ArrayList(); - for(Object current : this.initialSelection) { - if(!getSelectedElements().contains(current)) { - removedObject.add(current); - } - } - return removedObject; - } - - /** - * Returns the list of the elements to add - * - * @return - * the list of the elements to add - */ - public java.util.List getElementToAdd() { - java.util.List addedObject = new ArrayList(); - for(Object current : getSelectedElements()) { - if(!this.initialSelection.contains(current)) { - addedObject.add(current); - } - } - return addedObject; - } - } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/ui/InterfaceManagerDialog.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/ui/InterfaceManagerDialog.java deleted file mode 100644 index db6fe9a2c7a..00000000000 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/ui/InterfaceManagerDialog.java +++ /dev/null @@ -1,936 +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.uml.diagram.component.custom.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.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.diagram.component.custom.messages.Messages; -import org.eclipse.papyrus.uml.diagram.component.part.UMLDiagramEditorPlugin; -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; - -/** - * This class provides a Dialog to manage easily the provided and the required Interfaces for a {@link Port}. - */ -public class InterfaceManagerDialog extends SelectionDialog { - /** the selected port. */ - private Port port; - /** the list of the provided interfaces. */ - private List providedInterfaces; - /** the list of the required interfaces. */ - private List 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. */ - protected ExtendedSelectionEditor providedEditor; - /** the Editor for the required interfaces. */ - protected ExtendedSelectionEditor 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> requiredInterfacesMappedWithUsage = new HashMap>(); - /** - * 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> providedInterfacesMappedWithRealization = new HashMap>(); - /** the label provider for selector. */ - protected 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 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 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); - } - - /** - * Creates the. - * - * @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(); - this.interfaceRepresentations = new ArrayList(); - EList 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(); - 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(); - 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 = org.eclipse.papyrus.uml.tools.utils.ElementUtil.getInstancesFilteredByType(this.model, Usage.class, null); - List classifiers = new ArrayList(); - 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 usages = requiredInterfacesMappedWithUsage.get(target); - if (usages != null) { - usages.add(usage); - } else { - usages = new ArrayList(); - usages.add(usage); - this.requiredInterfacesMappedWithUsage.put((Interface) target, usages); - } - } - } - break; - } - } - } - } - - /** - * This method fills the map {@link #providedInterfacesMappedWithRealization}. - */ - protected void buildProvidedInterfaces() { - List allRealization = org.eclipse.papyrus.uml.tools.utils.ElementUtil.getInstancesFilteredByType(this.model, Realization.class, null); - List classifiers = new ArrayList(); - 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 realizations = providedInterfacesMappedWithRealization.get(target); - if (realizations != null) { - realizations.add(realization); - } else { - realizations = new ArrayList(); - 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 tmp = new ArrayList(); - 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 tmp = new ArrayList(); - 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 selection editor - * the created {@link SelectionEditor} - */ - protected ExtendedSelectionEditor createEditor(Composite parent, IElementSelector selector, String message, boolean withCreateButton, SelectionListener listener, List initialSelection) { - ExtendedSelectionEditor editor = new ExtendedSelectionEditor(parent, selector, selectorLabelProvider, initialSelection); - editor.setMessage(message); - editor.setAdditionalButton(withCreateButton, Messages.InterfaceManagerDialog_CreateNewInterface, listener); - return editor; - } - - /** - * Returns all the available Interfaces. - * - * @param pack - * the pack - * @return the all available interfaces - * all the available Interfaces - * //TODO add the interfaces of the package import! - */ - protected List getAllAvailableInterfaces(Package pack) { - List otherInterfaces = new ArrayList(); - List interfaces = Visitor.getOwnedAndImportedElement(pack, Interface.class); - for (Namespace namespace : Visitor.getOwnedAndImportedNamespaces(pack)) { - interfaces.addAll(Visitor.getOwnedAndImportedElement(namespace, Interface.class)); - } - for (Element element : interfaces) { - otherInterfaces.add((Interface) element); - } - return otherInterfaces; - } - - /** - * Returns the commands to apply the changes. - * - * @return the command - * 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 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 relationshipToDestroy = new HashSet(); - // commands to destroy Usage - for (Object current : this.requiredEditor.getElementToRemove()) { - // we get all usage associated with this interface - List 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 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 commands to create elements - * 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(), 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(), 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 - * 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}. - * - * @see CreateButtonEvent - */ - public class CreateButtonListener implements SelectionListener { - /** - * Widget selected. - * - * @param e - * the e - * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) - */ - 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 input = new ArrayList(); - 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(); - } - } - - /** - * Widget default selected. - * - * @param e - * the e - * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) - */ - 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. - * - * @param selection - * the selection - * @return the i status - * @see org.eclipse.ui.dialogs.ISelectionStatusValidator#validate(java.lang.Object[]) - */ - public IStatus validate(Object[] selection) { - IStatus status = new Status(IStatus.ERROR, UMLDiagramEditorPlugin.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, UMLDiagramEditorPlugin.ID, Messages.SelectionValidated); - } else { - status = new Status(IStatus.ERROR, UMLDiagramEditorPlugin.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 { - /** - * Gets the text. - * - * @param element - * the element - * @return the text - * @see org.eclipse.papyrus.uml.diagram.common.providers.EditorLabelProvider#getText(java.lang.Object) - */ - @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); - } - } - - /** - * The Class CreateElementLabelProvider. - */ - public class CreateElementLabelProvider extends UMLLabelProvider { - /** - * Gets the image. - * - * @param element - * the element - * @return the image - * @see org.eclipse.papyrus.uml.diagram.common.providers.EditorLabelProvider#getImage(java.lang.Object) - */ - @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); - } - - /** - * Gets the text. - * - * @param element - * the element - * @return the text - * @see org.eclipse.papyrus.uml.diagram.common.providers.EditorLabelProvider#getText(java.lang.Object) - */ - @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 { - /** - * Dispose. - * - * @see org.eclipse.jface.viewers.IContentProvider#dispose() - */ - public void dispose() { - } - - /** - * Input changed. - * - * @param viewer - * the viewer - * @param oldInput - * the old input - * @param newInput - * the new input - * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) - */ - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - - /** - * Gets the elements. - * - * @param inputElement - * the input element - * @return the elements - * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object) - */ - public Object[] getElements(Object inputElement) { - if (inputElement instanceof List) { - return ((List) inputElement).toArray(); - } - return new Object[0]; - } - - /** - * Gets the children. - * - * @param parentElement - * the parent element - * @return the children - * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) - */ - public Object[] getChildren(Object parentElement) { - List children = new ArrayList(); - 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(); - } - - /** - * Gets the parent. - * - * @param element - * the element - * @return the parent - * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) - */ - public Object getParent(Object element) { - if (element == model) { - return model; - } else if (element instanceof NamedElement) { - return ((NamedElement) element).eContainer(); - } - return null; - } - - /** - * Checks for children. - * - * @param element - * the element - * @return true, if successful - * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) - */ - 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; - } - - /** - * 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 { - CreateRelationshipRequest request = new CreateRelationshipRequest(domain, container, source, target.getEObject(), org.eclipse.papyrus.uml.service.types.element.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; - } - - /** - * 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 { - CreateRelationshipRequest request = new CreateRelationshipRequest(domain, container, source, target.getEObject(), org.eclipse.papyrus.uml.service.types.element.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 dependencies; - - /** - * - * Constructor. - * - * @param domain - * the domain - * @param affectedFiles - * the affected files - * @param dependencies - * the dependencies to test - */ - public DestroyDependencyWithoutSupplierCommand(TransactionalEditingDomain domain, List affectedFiles, Set dependencies) { - super(domain, "Destroy the empty elements", affectedFiles); //$NON-NLS-1$ - this.dependencies = dependencies; - } - - /** - * 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 { - 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/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/ui/NewElementRepresentation.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/ui/NewElementRepresentation.java deleted file mode 100644 index bfe1061c0fa..00000000000 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/ui/NewElementRepresentation.java +++ /dev/null @@ -1,177 +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.uml.diagram.component.custom.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; - -// TODO: Auto-generated Javadoc -/** - * This class provides facilities to represent a New Element before its real creation. - * We can store in this class : - *
    - *
  • the name of the new element
  • - *
  • the parent of the new element
  • - *
  • the {@link IHintedType} of the new element
  • - *
  • the request to build the new element (optional)
  • - *
  • the element itself when it has been created
  • - *
- * - * - * - */ -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 null) - */ - 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 the hinted type - * {@link #hintedType} - */ - public IHintedType getHintedType() { - return this.hintedType; - } - - /** - * Getter for {@link #name}. - * - * @return the name - * {@link #name} - */ - public String getName() { - return this.name; - } - - /** - * Getter for {@link #parent}. - * - * @return the parent - * {@link #parent} - */ - public Object getParent() { - return this.parent; - } - - /** - * Returns the parent of this element. - * - * @return the e object parent - * the parent of this element or null 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 e object - * the created Object or null 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 the new creates the element - */ - public void setCreateElement(EObject newElement) { - this.createdElement = newElement; - } - - /** - * Setter for {@link #request}. - * - * @return the creates the element request - * {@link #request} - */ - public CreateElementRequest getCreateElementRequest() { - return this.request; - } - - /** - * To string. - * - * @return the string - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return "Name : " + this.name + ", parent : " + this.parent; - } - - /** - * Gets the qualified name. - * - * @return the qualified name - */ - 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/uml/diagram/org.eclipse.papyrus.uml.diagram.component/plugin.xml b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/plugin.xml index 0743da36765..328b86106aa 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/plugin.xml +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/plugin.xml @@ -75,7 +75,7 @@ - - - - - + + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - - - - + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - + + + + + - - - + + + @@ -758,395 +758,395 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + - - - - - - - + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + 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 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 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 - * true 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, null, 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 result = new ArrayList(); - 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 null 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/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/ui/InterfaceManagerDialog.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/ui/InterfaceManagerDialog.java deleted file mode 100644 index b8f92c6d967..00000000000 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/ui/InterfaceManagerDialog.java +++ /dev/null @@ -1,1008 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2009-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: - * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation - * - *****************************************************************************/ -package org.eclipse.papyrus.uml.diagram.composite.custom.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.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.diagram.composite.custom.messages.Messages; -import org.eclipse.papyrus.uml.diagram.composite.part.UMLDiagramEditorPlugin; -import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes; -import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider; -import org.eclipse.papyrus.uml.tools.utils.ElementUtil; -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; - -/** - * - * This class provides a Dialog to manage easily the provided and the required Interfaces for a {@link Port} - * - * - */ -public class InterfaceManagerDialog extends SelectionDialog { - - /** the selected port */ - private Port port; - - /** the list of the provided interfaces */ - private List providedInterfaces; - - /** the list of the required interfaces */ - private List 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> requiredInterfacesMappedWithUsage = new HashMap>(); - - /** - * 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> providedInterfacesMappedWithRealization = new HashMap>(); - - /** 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 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 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(); - this.interfaceRepresentations = new ArrayList(); - EList 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(); - 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(); - 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 = ElementUtil.getInstancesFilteredByType(this.model, Usage.class, null); - List classifiers = new ArrayList(); - 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 usages = requiredInterfacesMappedWithUsage.get(target); - if (usages != null) { - usages.add(usage); - } else { - usages = new ArrayList(); - usages.add(usage); - this.requiredInterfacesMappedWithUsage.put((Interface) target, usages); - } - } - } - break; - } - } - } - } - - /** - * This method fills the map {@link #providedInterfacesMappedWithRealization} - */ - protected void buildProvidedInterfaces() { - List allRealization = ElementUtil.getInstancesFilteredByType(this.model, Realization.class, null); - List classifiers = new ArrayList(); - 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 realizations = providedInterfacesMappedWithRealization.get(target); - if (realizations != null) { - realizations.add(realization); - } else { - realizations = new ArrayList(); - 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 - */ - @Override - public Object[] getElements() { - List tmp = new ArrayList(); - 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 - */ - @Override - public Object[] getElements() { - List tmp = new ArrayList(); - 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 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 - * - * @return - * all the available Interfaces - * //TODO add the interfaces of the package import! - */ - protected List getAllAvailableInterfaces(Package pack) { - List otherInterfaces = new ArrayList(); - List interfaces = Visitor.getOwnedAndImportedElement(pack, Interface.class); - for (Namespace namespace : Visitor.getOwnedAndImportedNamespaces(pack)) { - interfaces.addAll(Visitor.getOwnedAndImportedElement(namespace, Interface.class)); - - } - - for (Element element : interfaces) { - 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 relationshipToDestroy = new HashSet(); - // commands to destroy Usage - for (Object current : this.requiredEditor.getElementToRemove()) { - // we get all usage associated with this interface - List 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 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(), 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(), 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 - */ - @Override - 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 input = new ArrayList(); - 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 - */ - @Override - 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 - */ - @Override - public IStatus validate(Object[] selection) { - - IStatus status = new Status(IStatus.ERROR, UMLDiagramEditorPlugin.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, UMLDiagramEditorPlugin.ID, Messages.SelectionValidated); - } else { - status = new Status(IStatus.ERROR, UMLDiagramEditorPlugin.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() - * - */ - @Override - 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 - */ - @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - - } - - /** - * - * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object) - * - * @param inputElement - * @return - */ - @Override - 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 - */ - @Override - public Object[] getChildren(Object parentElement) { - List children = new ArrayList(); - 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 - */ - @Override - 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 - */ - @Override - 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(), org.eclipse.papyrus.uml.service.types.element.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(), org.eclipse.papyrus.uml.service.types.element.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 dependencies; - - /** - * - * Constructor. - * - * @param domain - * the domain - * @param affectedFiles - * the affected files - * @param dependencies - * the dependencies to test - */ - public DestroyDependencyWithoutSupplierCommand(TransactionalEditingDomain domain, List affectedFiles, Set 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/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/ui/NewElementRepresentation.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/ui/NewElementRepresentation.java deleted file mode 100644 index 5befe27ca80..00000000000 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/ui/NewElementRepresentation.java +++ /dev/null @@ -1,172 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2009-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: - * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation - * - *****************************************************************************/ -package org.eclipse.papyrus.uml.diagram.composite.custom.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 : - *
    - *
  • the name of the new element
  • - *
  • the parent of the new element
  • - *
  • the {@link IHintedType} of the new element
  • - *
  • the request to build the new element (optional)
  • - *
  • the element itself when it has been created
  • - *
- * - * - * - */ -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 null) - */ - 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 null 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 null 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/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/plugin.xml b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/plugin.xml index 9caedc21e89..1bc51bf18b8 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/plugin.xml +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/plugin.xml @@ -15,22 +15,22 @@ --> - - - - - + + + + + - - - - + + + + @@ -57,77 +57,77 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -153,1175 +153,1175 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + @@ -1506,7 +1506,7 @@ @@ -1564,475 +1564,475 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/UMLModelElement.java b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/UMLModelElement.java index 3405051dc38..9bb01b24f90 100644 --- a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/UMLModelElement.java +++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/UMLModelElement.java @@ -1,302 +1,297 @@ -/***************************************************************************** - * Copyright (c) 2011, 2014 CEA LIST and others. - * - * 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: - * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation - * Christian W. Damus (CEA) - bug 323802 - * Christian W. Damus (CEA) - bug 440108 - * - *****************************************************************************/ -package org.eclipse.papyrus.uml.properties.modelelement; - -import static org.eclipse.uml2.uml.ParameterDirectionKind.INOUT_LITERAL; -import static org.eclipse.uml2.uml.ParameterDirectionKind.IN_LITERAL; -import static org.eclipse.uml2.uml.ParameterDirectionKind.OUT_LITERAL; -import static org.eclipse.uml2.uml.ParameterDirectionKind.RETURN_LITERAL; - -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.emf.databinding.EMFProperties; -import org.eclipse.emf.databinding.FeaturePath; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EEnum; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EReference; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.edit.domain.EditingDomain; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.papyrus.infra.emf.providers.EMFGraphicalContentProvider; -import org.eclipse.papyrus.infra.emf.providers.EMFLabelProvider; -import org.eclipse.papyrus.infra.emf.utils.HistoryUtil; -import org.eclipse.papyrus.infra.emf.utils.ProviderHelper; -import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory; -import org.eclipse.papyrus.infra.widgets.providers.EmptyContentProvider; -import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider; -import org.eclipse.papyrus.uml.properties.creation.ConnectorTypeEditorFactory; -import org.eclipse.papyrus.uml.properties.creation.MessageValueSpecificationFactory; -import org.eclipse.papyrus.uml.properties.creation.OwnedRuleCreationFactory; -import org.eclipse.papyrus.uml.properties.creation.UMLPropertyEditorFactory; -import org.eclipse.papyrus.uml.tools.databinding.ExtensionRequiredObservableValue; -import org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableList; -import org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableValue; -import org.eclipse.papyrus.uml.tools.databinding.ProvidedInterfaceObservableList; -import org.eclipse.papyrus.uml.tools.databinding.RequiredInterfaceObservableList; -import org.eclipse.papyrus.uml.tools.databinding.UnsettableStringValue; -import org.eclipse.papyrus.uml.tools.providers.ConstrainedElementContentProvider; -import org.eclipse.papyrus.uml.tools.providers.UMLContainerContentProvider; -import org.eclipse.papyrus.uml.tools.providers.UMLContentProvider; -import org.eclipse.papyrus.uml.tools.providers.UMLFilteredLabelProvider; -import org.eclipse.papyrus.views.properties.modelelement.EMFModelElement; -import org.eclipse.papyrus.views.properties.providers.FeatureContentProvider; -import org.eclipse.uml2.uml.Connector; -import org.eclipse.uml2.uml.Extension; -import org.eclipse.uml2.uml.Message; -import org.eclipse.uml2.uml.ParameterDirectionKind; -import org.eclipse.uml2.uml.Port; -import org.eclipse.uml2.uml.UMLPackage; - -/** - * A ModelElement representing a UML Element - * - * @author Camille Letavernier - * - */ -public class UMLModelElement extends EMFModelElement { - - /** - * - * Constructor. - * - * @param source - * The EObject represented by this ModelElement - */ - public UMLModelElement(EObject source) { - super(source); - } - - /** - * - * Constructor. - * - * @param source - * The EObject represented by this ModelElement - * @param domain - * The EditingDomain on which the commands will be executed - */ - public UMLModelElement(EObject source, EditingDomain domain) { - super(source, domain); - } - - @Override - public IObservable doGetObservable(String propertyPath) { - FeaturePath featurePath = getFeaturePath(propertyPath); - EStructuralFeature feature = getFeature(propertyPath); - - if(feature == UMLPackage.eINSTANCE.getExtension_IsRequired()) { - return new ExtensionRequiredObservableValue((Extension)source, domain); - } - - if(feature == UMLPackage.eINSTANCE.getPort_Provided()) { - //TODO : Currently, this is read-only - //See #isEditable(String) - return new ProvidedInterfaceObservableList((Port)source, domain); - } - - if(feature == UMLPackage.eINSTANCE.getPort_Required()) { - //TODO : Currently, this is read-only - //See #isEditable(String) - return new RequiredInterfaceObservableList((Port)source, domain); - } - - if(feature == null) { - return null; - } - - if(feature.getUpperBound() != 1) { - IObservableList list = domain == null ? EMFProperties.list(featurePath).observe(source) : new PapyrusObservableList(EMFProperties.list(featurePath).observe(source), domain, getSource(featurePath), feature); - return list; - } - - if((feature == UMLPackage.Literals.NAMED_ELEMENT__NAME) && (domain != null)) { - // Empty string as a name is not useful, so we unset instead - return new UnsettableStringValue(getSource(featurePath), feature, domain); - } - - IObservableValue value = domain == null ? EMFProperties.value(featurePath).observe(source) : new PapyrusObservableValue(getSource(featurePath), feature, domain); - return value; - } - - @Override - protected boolean isFeatureEditable(String propertyPath) { - EStructuralFeature feature = getFeature(propertyPath); - if(feature == UMLPackage.eINSTANCE.getMessage_Signature()) { - return true; - } - if(feature == UMLPackage.eINSTANCE.getExtension_IsRequired()) { - return true; - } - if(feature == UMLPackage.eINSTANCE.getPort_Provided()) { - return false; - //return true; //TODO : Unsupported yet - } - if(feature == UMLPackage.eINSTANCE.getPort_Required()) { - return false; - //return true; //TODO : Unsupported yet - } - return super.isFeatureEditable(propertyPath); - } - - @Override - public IStaticContentProvider getContentProvider(String propertyPath) { - EStructuralFeature feature = getFeature(propertyPath); - - if(feature == null) { - return EmptyContentProvider.instance; - } - - //Workaround: the standard ContentProvider does not correctly hide the selected elements in ReferenceSelector. - //With a ContainmentBasedBrowseStrategy, it works better (But we don't have the infinite tree in the selection dialog). - if(feature == UMLPackage.eINSTANCE.getConstraint_ConstrainedElement()) { - return new ConstrainedElementContentProvider(source, feature); - } - - return new UMLContentProvider(source, feature); - } - - @Override - public ILabelProvider getLabelProvider(String propertyPath) { - EStructuralFeature feature = getFeature(propertyPath); - if(feature != null && feature.getEType() instanceof EEnum) { - return super.getLabelProvider(propertyPath); - } - return new UMLFilteredLabelProvider(); - } - - @Override - public boolean isOrdered(String propertyPath) { - EStructuralFeature feature = getFeature(propertyPath); - if(feature == UMLPackage.eINSTANCE.getStereotype_Icon()) { - return true; - } - return super.isOrdered(propertyPath); - } - - @Override - public ReferenceValueFactory getValueFactory(String propertyPath) { - EStructuralFeature feature = getFeature(propertyPath); - if(!(feature instanceof EReference)) { - return null; - } - EReference reference = (EReference)feature; - if(reference == UMLPackage.eINSTANCE.getMessage_Argument()) { - if(source instanceof Message) { - Set directions = new HashSet(); - switch(((Message)source).getMessageSort()) { - case REPLY_LITERAL: - directions.add(OUT_LITERAL); - directions.add(INOUT_LITERAL); - directions.add(RETURN_LITERAL); - return new MessageValueSpecificationFactory(reference, (Message)source, directions); - case SYNCH_CALL_LITERAL: - case ASYNCH_CALL_LITERAL: - case ASYNCH_SIGNAL_LITERAL: - directions.add(IN_LITERAL); - directions.add(INOUT_LITERAL); - return new MessageValueSpecificationFactory(reference, (Message)source, directions); - } - } - } - - boolean isOwnedRuleSubset = ownedRuleSubsets.contains(reference); - - if(isOwnedRuleSubset) { - return new OwnedRuleCreationFactory(reference); - } - - UMLPropertyEditorFactory factory; - - if(reference == UMLPackage.eINSTANCE.getConnector_Type() && source instanceof Connector) { - factory = new ConnectorTypeEditorFactory(reference); - } else { - factory = new UMLPropertyEditorFactory(reference); - } - - EClass type = reference.getEReferenceType(); - - factory.setContainerLabelProvider(new UMLFilteredLabelProvider()); - factory.setReferenceLabelProvider(new EMFLabelProvider()); - ITreeContentProvider contentProvider = new UMLContainerContentProvider(source, reference); - - ResourceSet rs = source == null ? null : source.eResource() == null ? null : source.eResource().getResourceSet(); - EMFGraphicalContentProvider provider = ProviderHelper.encapsulateProvider(contentProvider, rs, HistoryUtil.getHistoryID(source, feature, "container")); - - factory.setContainerContentProvider(provider); - factory.setReferenceContentProvider(new FeatureContentProvider(type)); - - return factory; - } - - @Override - public boolean isMandatory(String propertyPath) { - EStructuralFeature feature = getFeature(propertyPath); - - //Avoid unsetting container references (i.e. reference to the parent) - //(Which would result in detaching the edited object from the model) - //See Bug 404445: [Constraint] Unsetting the context of a constraint destroys it (Semantically) - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=404445 - if(feature instanceof EReference) { - EReference reference = (EReference)feature; - if(reference.isContainer()) { - return true; - } - } - - return super.isMandatory(propertyPath); - } - - /** - * The set of all EStructuralFeature representing subsets of {@link Namespace#getOwnedRules()} - */ - public final static Set ownedRuleSubsets = new HashSet(); - static { - //Behavior - ownedRuleSubsets.add(UMLPackage.eINSTANCE.getBehavior_Precondition()); - ownedRuleSubsets.add(UMLPackage.eINSTANCE.getBehavior_Postcondition()); - - //Operation - ownedRuleSubsets.add(UMLPackage.eINSTANCE.getOperation_BodyCondition()); - ownedRuleSubsets.add(UMLPackage.eINSTANCE.getOperation_Precondition()); - ownedRuleSubsets.add(UMLPackage.eINSTANCE.getOperation_Postcondition()); - - //ProtocolTransition - ownedRuleSubsets.add(UMLPackage.eINSTANCE.getProtocolTransition_PreCondition()); - ownedRuleSubsets.add(UMLPackage.eINSTANCE.getProtocolTransition_PostCondition()); - - //Transition - ownedRuleSubsets.add(UMLPackage.eINSTANCE.getTransition_Guard()); - } - - public IValidator getValidator(String propertyPath){ - EStructuralFeature feature = getFeature(propertyPath); - if(feature == UMLPackage.eINSTANCE.getNamedElement_Name()){ - - return new org.eclipse.papyrus.uml.tools.databinding.NamedElementValidator(source); - } - - //TODO improve if our model add his own constraint - return null; - } - -} +/***************************************************************************** + * Copyright (c) 2011, 2014 CEA LIST and others. + * + * 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: + * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation + * Christian W. Damus (CEA) - bug 323802 + * Christian W. Damus (CEA) - bug 440108 + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.properties.modelelement; + +import static org.eclipse.uml2.uml.ParameterDirectionKind.INOUT_LITERAL; +import static org.eclipse.uml2.uml.ParameterDirectionKind.IN_LITERAL; +import static org.eclipse.uml2.uml.ParameterDirectionKind.OUT_LITERAL; +import static org.eclipse.uml2.uml.ParameterDirectionKind.RETURN_LITERAL; + +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.core.databinding.observable.IObservable; +import org.eclipse.core.databinding.observable.list.IObservableList; +import org.eclipse.core.databinding.observable.value.IObservableValue; +import org.eclipse.core.databinding.validation.IValidator; +import org.eclipse.emf.databinding.EMFProperties; +import org.eclipse.emf.databinding.FeaturePath; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EEnum; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.papyrus.infra.emf.providers.EMFGraphicalContentProvider; +import org.eclipse.papyrus.infra.emf.providers.EMFLabelProvider; +import org.eclipse.papyrus.infra.emf.utils.HistoryUtil; +import org.eclipse.papyrus.infra.emf.utils.ProviderHelper; +import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory; +import org.eclipse.papyrus.infra.widgets.providers.EmptyContentProvider; +import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider; +import org.eclipse.papyrus.uml.properties.creation.ConnectorTypeEditorFactory; +import org.eclipse.papyrus.uml.properties.creation.MessageValueSpecificationFactory; +import org.eclipse.papyrus.uml.properties.creation.OwnedRuleCreationFactory; +import org.eclipse.papyrus.uml.properties.creation.UMLPropertyEditorFactory; +import org.eclipse.papyrus.uml.tools.databinding.ExtensionRequiredObservableValue; +import org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableList; +import org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableValue; +import org.eclipse.papyrus.uml.tools.databinding.ProvidedInterfaceObservableList; +import org.eclipse.papyrus.uml.tools.databinding.RequiredInterfaceObservableList; +import org.eclipse.papyrus.uml.tools.databinding.UnsettableStringValue; +import org.eclipse.papyrus.uml.tools.providers.ConstrainedElementContentProvider; +import org.eclipse.papyrus.uml.tools.providers.UMLContainerContentProvider; +import org.eclipse.papyrus.uml.tools.providers.UMLContentProvider; +import org.eclipse.papyrus.uml.tools.providers.UMLFilteredLabelProvider; +import org.eclipse.papyrus.views.properties.modelelement.EMFModelElement; +import org.eclipse.papyrus.views.properties.providers.FeatureContentProvider; +import org.eclipse.uml2.uml.Connector; +import org.eclipse.uml2.uml.Extension; +import org.eclipse.uml2.uml.Message; +import org.eclipse.uml2.uml.ParameterDirectionKind; +import org.eclipse.uml2.uml.Port; +import org.eclipse.uml2.uml.UMLPackage; + +/** + * A ModelElement representing a UML Element + * + * @author Camille Letavernier + * + */ +public class UMLModelElement extends EMFModelElement { + + /** + * + * Constructor. + * + * @param source + * The EObject represented by this ModelElement + */ + public UMLModelElement(EObject source) { + super(source); + } + + /** + * + * Constructor. + * + * @param source + * The EObject represented by this ModelElement + * @param domain + * The EditingDomain on which the commands will be executed + */ + public UMLModelElement(EObject source, EditingDomain domain) { + super(source, domain); + } + + @Override + public IObservable doGetObservable(String propertyPath) { + FeaturePath featurePath = getFeaturePath(propertyPath); + EStructuralFeature feature = getFeature(propertyPath); + + if(feature == UMLPackage.eINSTANCE.getExtension_IsRequired()) { + return new ExtensionRequiredObservableValue((Extension)source, domain); + } + + if(feature == UMLPackage.eINSTANCE.getPort_Provided()) { + return new ProvidedInterfaceObservableList((Port)source, domain); + } + + if(feature == UMLPackage.eINSTANCE.getPort_Required()) { + return new RequiredInterfaceObservableList((Port)source, domain); + } + + if(feature == null) { + return null; + } + + if(feature.getUpperBound() != 1) { + IObservableList list = domain == null ? EMFProperties.list(featurePath).observe(source) : new PapyrusObservableList(EMFProperties.list(featurePath).observe(source), domain, getSource(featurePath), feature); + return list; + } + + if((feature == UMLPackage.Literals.NAMED_ELEMENT__NAME) && (domain != null)) { + // Empty string as a name is not useful, so we unset instead + return new UnsettableStringValue(getSource(featurePath), feature, domain); + } + + IObservableValue value = domain == null ? EMFProperties.value(featurePath).observe(source) : new PapyrusObservableValue(getSource(featurePath), feature, domain); + return value; + } + + @Override + protected boolean isFeatureEditable(String propertyPath) { + EStructuralFeature feature = getFeature(propertyPath); + if(feature == UMLPackage.eINSTANCE.getMessage_Signature()) { + return true; + } + if(feature == UMLPackage.eINSTANCE.getExtension_IsRequired()) { + return true; + } + if(feature == UMLPackage.eINSTANCE.getPort_Provided() || feature == UMLPackage.eINSTANCE.getPort_Required()) { + if(source instanceof Port) { + return ((Port)source).getType() != null; + } + } + + return super.isFeatureEditable(propertyPath); + } + + @Override + public IStaticContentProvider getContentProvider(String propertyPath) { + EStructuralFeature feature = getFeature(propertyPath); + + if(feature == null) { + return EmptyContentProvider.instance; + } + + //Workaround: the standard ContentProvider does not correctly hide the selected elements in ReferenceSelector. + //With a ContainmentBasedBrowseStrategy, it works better (But we don't have the infinite tree in the selection dialog). + if(feature == UMLPackage.eINSTANCE.getConstraint_ConstrainedElement()) { + return new ConstrainedElementContentProvider(source, feature); + } + + return new UMLContentProvider(source, feature); + } + + @Override + public ILabelProvider getLabelProvider(String propertyPath) { + EStructuralFeature feature = getFeature(propertyPath); + if(feature != null && feature.getEType() instanceof EEnum) { + return super.getLabelProvider(propertyPath); + } + return new UMLFilteredLabelProvider(); + } + + @Override + public boolean isOrdered(String propertyPath) { + EStructuralFeature feature = getFeature(propertyPath); + if(feature == UMLPackage.eINSTANCE.getStereotype_Icon()) { + return true; + } + return super.isOrdered(propertyPath); + } + + @Override + public ReferenceValueFactory getValueFactory(String propertyPath) { + EStructuralFeature feature = getFeature(propertyPath); + if(!(feature instanceof EReference)) { + return null; + } + EReference reference = (EReference)feature; + if(reference == UMLPackage.eINSTANCE.getMessage_Argument()) { + if(source instanceof Message) { + Set directions = new HashSet(); + switch(((Message)source).getMessageSort()) { + case REPLY_LITERAL: + directions.add(OUT_LITERAL); + directions.add(INOUT_LITERAL); + directions.add(RETURN_LITERAL); + return new MessageValueSpecificationFactory(reference, (Message)source, directions); + case SYNCH_CALL_LITERAL: + case ASYNCH_CALL_LITERAL: + case ASYNCH_SIGNAL_LITERAL: + directions.add(IN_LITERAL); + directions.add(INOUT_LITERAL); + return new MessageValueSpecificationFactory(reference, (Message)source, directions); + } + } + } + + boolean isOwnedRuleSubset = ownedRuleSubsets.contains(reference); + + if(isOwnedRuleSubset) { + return new OwnedRuleCreationFactory(reference); + } + + UMLPropertyEditorFactory factory; + + if(reference == UMLPackage.eINSTANCE.getConnector_Type() && source instanceof Connector) { + factory = new ConnectorTypeEditorFactory(reference); + } else { + factory = new UMLPropertyEditorFactory(reference); + } + + EClass type = reference.getEReferenceType(); + + factory.setContainerLabelProvider(new UMLFilteredLabelProvider()); + factory.setReferenceLabelProvider(new EMFLabelProvider()); + ITreeContentProvider contentProvider = new UMLContainerContentProvider(source, reference); + + ResourceSet rs = source == null ? null : source.eResource() == null ? null : source.eResource().getResourceSet(); + EMFGraphicalContentProvider provider = ProviderHelper.encapsulateProvider(contentProvider, rs, HistoryUtil.getHistoryID(source, feature, "container")); + + factory.setContainerContentProvider(provider); + factory.setReferenceContentProvider(new FeatureContentProvider(type)); + + return factory; + } + + @Override + public boolean isMandatory(String propertyPath) { + EStructuralFeature feature = getFeature(propertyPath); + + //Avoid unsetting container references (i.e. reference to the parent) + //(Which would result in detaching the edited object from the model) + //See Bug 404445: [Constraint] Unsetting the context of a constraint destroys it (Semantically) + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=404445 + if(feature instanceof EReference) { + EReference reference = (EReference)feature; + if(reference.isContainer()) { + return true; + } + } + + return super.isMandatory(propertyPath); + } + + /** + * The set of all EStructuralFeature representing subsets of {@link Namespace#getOwnedRules()} + */ + public final static Set ownedRuleSubsets = new HashSet(); + static { + //Behavior + ownedRuleSubsets.add(UMLPackage.eINSTANCE.getBehavior_Precondition()); + ownedRuleSubsets.add(UMLPackage.eINSTANCE.getBehavior_Postcondition()); + + //Operation + ownedRuleSubsets.add(UMLPackage.eINSTANCE.getOperation_BodyCondition()); + ownedRuleSubsets.add(UMLPackage.eINSTANCE.getOperation_Precondition()); + ownedRuleSubsets.add(UMLPackage.eINSTANCE.getOperation_Postcondition()); + + //ProtocolTransition + ownedRuleSubsets.add(UMLPackage.eINSTANCE.getProtocolTransition_PreCondition()); + ownedRuleSubsets.add(UMLPackage.eINSTANCE.getProtocolTransition_PostCondition()); + + //Transition + ownedRuleSubsets.add(UMLPackage.eINSTANCE.getTransition_Guard()); + } + + public IValidator getValidator(String propertyPath){ + EStructuralFeature feature = getFeature(propertyPath); + if(feature == UMLPackage.eINSTANCE.getNamedElement_Name()){ + + return new org.eclipse.papyrus.uml.tools.databinding.NamedElementValidator(source); + } + + //TODO improve if our model add his own constraint + return null; + } + +} diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/adapters/DerivedAttributeAdapter.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/adapters/DerivedAttributeAdapter.java new file mode 100644 index 00000000000..84429f2154a --- /dev/null +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/adapters/DerivedAttributeAdapter.java @@ -0,0 +1,270 @@ +/***************************************************************************** + * 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.uml.tools.adapters; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.impl.AdapterImpl; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.InternalEObject; +import org.eclipse.emf.ecore.impl.ENotificationImpl; + + +/** + * Adapter for derived attribute.
+ * + * Based on article : Derived Attribute Notifier + * + * @author Gabriel Pascual + */ +public class DerivedAttributeAdapter extends AdapterImpl { + + /** The source. */ + private InternalEObject source; + + /** The derived feature. */ + private EStructuralFeature derivedFeature; + + /** The local features. */ + private List localFeatures = new ArrayList(); + + /** The navigation feature. */ + private EStructuralFeature navigationFeature = null; + + /** The dependant adapter. */ + private Adapter dependantAdapter = null; + + + /** + * Instantiates a new derived attribute adapter. + * + * @param source + * the source + * @param derivedFeature + * the derived feature + * @param navigationFeature + * the navigation feature + * @param dependantFeature + * the dependant feature + * @param eventType + * the event type + */ + public DerivedAttributeAdapter(EObject source, EStructuralFeature derivedFeature, EStructuralFeature navigationFeature, EStructuralFeature dependantFeature, int eventType) { + this(source, derivedFeature); + addNavigatedDependency(navigationFeature, dependantFeature, eventType); + } + + /** + * Instantiates a new derived attribute adapter. + * + * @param source + * the source + * @param derivedFeature + * the derived feature + * @param navigationFeature + * the navigation feature + * @param dependentFeaturesMap + * the dependent features map + */ + public DerivedAttributeAdapter(EObject source, EStructuralFeature derivedFeature, EStructuralFeature navigationFeature, Map dependentFeaturesMap) { + this(source, derivedFeature); + + addNavigatedDependency(navigationFeature, dependentFeaturesMap); + + } + + + /** + * Instantiates a new derived attribute adapter. + * + * @param source + * the source + * @param derivedFeature + * the derived feature + * @param localFeature + * the local feature + */ + public DerivedAttributeAdapter(EObject source, EStructuralFeature derivedFeature, EStructuralFeature localFeature) { + this(source, derivedFeature); + addLocalDependency(localFeature); + } + + /** + * Instantiates a new derived attribute adapter. + * + * @param source + * the source + * @param derivedFeature + * the derived feature + */ + public DerivedAttributeAdapter(EObject source, EStructuralFeature derivedFeature) { + super(); + this.source = (InternalEObject)source; + this.derivedFeature = derivedFeature; + source.eAdapters().add(this); + } + + /** + * Adds the navigated dependency. + * + * @param navigationFeature + * the navigation feature + * @param dependentFeaturesMap + * the dependent features map + */ + public void addNavigatedDependency(EStructuralFeature navigationFeature, Map dependentFeaturesMap) { + this.navigationFeature = navigationFeature; + this.dependantAdapter = new DependentFeatureAdapter(dependentFeaturesMap); + } + + /** + * Adds the navigated dependency. + * + * @param navigationFeature + * the navigation feature + * @param dependantFeature + * the dependant feature + * @param eventType + * the event type + */ + public void addNavigatedDependency(EStructuralFeature navigationFeature, EStructuralFeature dependantFeature, int eventType) { + this.navigationFeature = navigationFeature; + this.dependantAdapter = new DependentFeatureAdapter(eventType, dependantFeature); + } + + /** + * Adds the local dependency. + * + * @param localFeature + * the local feature + */ + public void addLocalDependency(EStructuralFeature localFeature) { + localFeatures.add(localFeature); + } + + /** + * @see org.eclipse.emf.common.notify.impl.AdapterImpl#notifyChanged(org.eclipse.emf.common.notify.Notification) + * + * @param notification + */ + @Override + public void notifyChanged(Notification notification) { + Object notificationFeature = notification.getFeature(); + if(notificationFeature != null && notificationFeature.equals(navigationFeature)) { + switch(notification.getEventType()) { + case Notification.ADD: + EObject added = (EObject)notification.getNewValue(); + added.eAdapters().add(dependantAdapter); + break; + case Notification.SET: + EObject newValue = (EObject)notification.getNewValue(); + EObject oldValue = (EObject)notification.getOldValue(); + if(oldValue != null) + oldValue.eAdapters().remove(dependantAdapter); + if(newValue != null) + newValue.eAdapters().add(dependantAdapter); + break; + case Notification.REMOVE: + EObject removed = (EObject)notification.getOldValue(); + removed.eAdapters().remove(dependantAdapter); + break; + default: + return; // No notification + } + notifyDerivedAttributeChange(notification); + } else if(localFeatures.contains(notificationFeature)) { + notifyDerivedAttributeChange(notification); + } + } + + /** + * Notify derived attribute change. + *

+ * The default implementation notifies the source element with notification. + *

+ * + * @param msg + * the msg + */ + protected void notifyDerivedAttributeChange(Notification msg) { + if(source.eNotificationRequired()) { + source.eNotify(getNotification()); + } + } + + /** + * Gets the notification. + *

+ * Default implementation build a notification of type SET with the source and associated derived attribute as new value. + *

+ * + * @return the notification + */ + protected Notification getNotification() { + return new ENotificationImpl(source, Notification.SET, derivedFeature, null, source.eGet(derivedFeature, true, true)); + } + + /** + * Adapter to observe modification of dependent feature. + */ + private class DependentFeatureAdapter extends AdapterImpl { + + /** The dependent features map. */ + private Map dependentFeaturesMap = new HashMap(); + + /** + * Instantiates a new dependent feature adapter. + * + * @param eventType + * the event type + * @param feature + * the feature + */ + public DependentFeatureAdapter(int eventType, EStructuralFeature feature) { + super(); + dependentFeaturesMap.put(feature, Integer.valueOf(eventType)); + + } + + /** + * Instantiates a new dependent feature adapter. + * + * @param dependentFeaturesMap + * the dependent features map + */ + public DependentFeatureAdapter(Map dependentFeaturesMap) { + super(); + this.dependentFeaturesMap.putAll(dependentFeaturesMap); + } + + /** + * @see org.eclipse.emf.common.notify.impl.AdapterImpl#notifyChanged(org.eclipse.emf.common.notify.Notification) + * + * @param notification + */ + + @Override + public void notifyChanged(Notification notification) { + if(dependentFeaturesMap.containsKey(notification.getFeature()) && dependentFeaturesMap.get(notification.getFeature()).equals(notification.getEventType())) { + notifyDerivedAttributeChange(notification); + } + } + } + + +} diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/adapters/PortTypeAdapter.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/adapters/PortTypeAdapter.java new file mode 100644 index 00000000000..90e8b4e8f55 --- /dev/null +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/adapters/PortTypeAdapter.java @@ -0,0 +1,205 @@ +/***************************************************************************** + * 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.uml.tools.adapters; + +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.impl.AdapterImpl; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.InternalEObject; +import org.eclipse.emf.ecore.impl.ENotificationImpl; +import org.eclipse.uml2.common.util.CacheAdapter; +import org.eclipse.uml2.uml.Port; +import org.eclipse.uml2.uml.Type; +import org.eclipse.uml2.uml.UMLPackage; + +/** + * Adapter to manage interaction between volatile attributes (provided or required interfaces) of a port. + */ +public class PortTypeAdapter extends AdapterImpl { + + /** The adapter. */ + private Adapter adapter = null; + + /** The port. */ + private Port port = null; + + /** The feature. */ + private EStructuralFeature derivedFeature = null; + + /** The navigation feature to adapt. */ + private EStructuralFeature navigationFeature = null; + + + /** + * Instantiates a new port type adapter. + * + * @param port + * the port + * @param volatileFeature + * the volatile feature + * @param navigationFeature + */ + public PortTypeAdapter(Port port, EStructuralFeature volatileFeature, EStructuralFeature navigationFeature) { + + this.port = port; + this.derivedFeature = volatileFeature; + this.navigationFeature = navigationFeature; + + if(port.getType() != null) { + attachAdapter(null, port.getType()); + } + } + + /** + * Notify changed. + * + * @param msg + * the msg + * @see org.eclipse.emf.common.notify.impl.AdapterImpl#notifyChanged(org.eclipse.emf.common.notify.Notification) + */ + + @Override + public void notifyChanged(Notification msg) { + + Object notificationFeature = msg.getFeature(); + + // Listen only type setting on Port element + if(notificationFeature != null && notificationFeature.equals(UMLPackage.Literals.TYPED_ELEMENT__TYPE)) { + switch(msg.getEventType()) { + + case Notification.SET: + Type newType = (Type)msg.getNewValue(); + if(newType != null) { + + // Set a type to Port + attachAdapter((Type)msg.getOldValue(), newType); + updateObservableList(); + } else { + + // Unset type to port + detachAdapter((Type)msg.getOldValue()); + updateObservableList(); + } + break; + default: + //Nothing to do + break; + } + } + + + + } + + /** + * Detach adapter of old type. + * + * @param type + * Type where adapter will be removed + * + */ + private void detachAdapter(Type type) { + EObject source = determineSource(type); + source.eAdapters().remove(adapter); + + } + + /** + * Attach adapter to setted type. + * + * @param newType + * Type where adapter will be added + */ + private void attachAdapter(Type oldType, Type newType) { + + + EObject newSource = determineSource(newType); + if(newSource != null) { + + // Dispose adapter on old type + if(oldType != null && adapter != null) { + EObject oldSource = determineSource(oldType); + + if(!oldSource.equals(newSource)) { + oldSource.eAdapters().remove(adapter); + } + } + + + // Attach adapter for new type + if(adapter == null || !newSource.eAdapters().contains(adapter)) { + + // Create a new one only if source don't have already one because last type can have same source to observe + adapter = new DerivedAttributeAdapter(newSource, derivedFeature, navigationFeature, UMLPackage.Literals.DEPENDENCY__SUPPLIER, Notification.ADD) { + + protected void notifyDerivedAttributeChange(Notification notification) { + if(UMLPackage.Literals.DEPENDENCY__SUPPLIER.equals(notification.getFeature())) { + port.eNotify(new ENotificationImpl((InternalEObject)port, notification.getEventType(), derivedFeature, notification.getOldValue(), notification.getNewValue())); + } else if(Notification.REMOVE == notification.getEventType()) { + port.eNotify(new ENotificationImpl((InternalEObject)port, notification.getEventType(), derivedFeature, notification.getOldValue(), notification.getNewValue())); + } + + }; + + }; + + } + } + + + + + } + + /** + * Determine on which element the adapter will be attached/detached according derived feature. + *

+ * Warning: Result can be null for case of Required interfaces when Type was not yet affected to container. + *

+ * + * @param type + * Type is origin of evaluation + * @return + * Source according of derived feature + */ + private EObject determineSource(Type type) { + EObject source = type; + + if(UMLPackage.Literals.PORT__REQUIRED.equals(derivedFeature)) { + source = type.eContainer(); + } + + return source; + } + + /** + * Fire observable list. + * + * @param type + * the type + */ + private void updateObservableList() { + + // Clear cache for derived feature + CacheAdapter cache = CacheAdapter.getCacheAdapter(port); + if(cache != null) { + cache.put(port, derivedFeature, null); + } + + // Notify observers + port.eNotify(new ENotificationImpl((InternalEObject)port, Notification.SET, derivedFeature, null, port.eGet(derivedFeature), true)); + + + } +} diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/DestroyDependencyWithoutSupplierCommand.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/DestroyDependencyWithoutSupplierCommand.java new file mode 100644 index 00000000000..7aed40677ce --- /dev/null +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/DestroyDependencyWithoutSupplierCommand.java @@ -0,0 +1,125 @@ +/***************************************************************************** + * 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.uml.tools.commands; + +import java.util.Collections; +import java.util.Set; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +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.emf.commands.core.command.AbstractTransactionalCommand; +import org.eclipse.gmf.runtime.emf.type.core.requests.AbstractEditCommandRequest; +import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; +import org.eclipse.papyrus.infra.services.edit.service.IElementEditService; +import org.eclipse.uml2.uml.Dependency; + +/** + * 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 dependencies; + + /** The provider. */ + private IElementEditService provider; + + /** + * Constructor. + * + * @param domain + * the domain + * @param dependencies + * the dependencies to test + * @param provider + * the provider + */ + public DestroyDependencyWithoutSupplierCommand(TransactionalEditingDomain domain, Set dependencies, IElementEditService provider) { + super(domain, "Destroy the empty elements", null); //$NON-NLS-1$ + this.dependencies = dependencies; + this.provider = provider; + } + + /** + * Constructor. + * + * @param domain + * the domain + * @param dependency + * the dependency + * @param provider + * the provider + */ + public DestroyDependencyWithoutSupplierCommand(TransactionalEditingDomain domain, Dependency dependency, IElementEditService provider) { + super(domain, "Destroy the empty elements", null); //$NON-NLS-1$ + this.dependencies = Collections.singleton(dependency); + this.provider = provider; + } + + /** + * 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 { + CompositeCommand command = new CompositeCommand("Destroy relationship without suppliers"); //$NON-NLS-1$ + + for(Dependency current : dependencies) { + if(current.getSuppliers().isEmpty()) { + DestroyElementRequest request = new DestroyElementRequest(getEditingDomain(), current, false); + ICommand cmd = getCommand(request); + if(cmd.canExecute()) { + command.add(cmd); + } + } + } + + + if(!command.isEmpty() && command.canExecute()) { + command.execute(monitor, info); + } + return CommandResult.newOKCommandResult(); + } + + /** + * Return the command corresponding to the request. + * + * @param req + * a request + * @return the command corresponding to the request + */ + private ICommand getCommand(AbstractEditCommandRequest req) { + + if(provider != null) { + ICommand setCommand = provider.getEditCommand(req); + if(setCommand != null) { + return setCommand.reduce(); + } + } + return UnexecutableCommand.INSTANCE; + } +} diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/ProvidedInterfaceObservableList.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/ProvidedInterfaceObservableList.java index da06416e0d8..ad6b15bd172 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/ProvidedInterfaceObservableList.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/ProvidedInterfaceObservableList.java @@ -1,78 +1,245 @@ -/***************************************************************************** - * 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: - * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation - *****************************************************************************/ -package org.eclipse.papyrus.uml.tools.databinding; - -import java.util.Collection; - -import org.eclipse.emf.common.command.Command; -import org.eclipse.emf.databinding.EMFProperties; -import org.eclipse.emf.edit.domain.EditingDomain; -import org.eclipse.uml2.uml.Interface; -import org.eclipse.uml2.uml.Port; -import org.eclipse.uml2.uml.UMLPackage; - -/** - * An IObservableList to edit the UML Derived feature {@link Port#getProvideds()} - * - * @author Camille Letavernier - * - */ -public class ProvidedInterfaceObservableList extends PapyrusObservableList { - - protected Port port; - - public ProvidedInterfaceObservableList(Port source, EditingDomain domain) { - super(EMFProperties.list(UMLPackage.eINSTANCE.getPort_Provided()).observe(source), domain, source, UMLPackage.eINSTANCE.getPort_Provided()); - this.port = source; - } - - @Override - public Command getRemoveCommand(Object value) { - throw new UnsupportedOperationException("TODO"); //TODO - } - - @Override - public Command getRemoveAllCommand(Collection values) { - throw new UnsupportedOperationException("TODO"); //TODO - } - - @Override - public Command getAddCommand(int index, Object value) { - if(!(value instanceof Interface)) { - throw new IllegalArgumentException("The value must be an Interface"); //$NON-NLS-1$ - } - Interface providedInterface = (Interface)value; - - //Pseudo code - //Use a command - //Use the Papyrus UML Layer - //InterfaceRealization realization = createInterfaceRealization(providedInterface); - //((org.eclipse.uml2.uml.Class)port.getType()).getInterfaceRealizations().add(realization); - throw new UnsupportedOperationException("TODO"); //TODO - } - - @Override - public Command getAddCommand(Object value) { - throw new UnsupportedOperationException("TODO"); //TODO - } - - @Override - public Command getAddAllCommand(Collection values) { - throw new UnsupportedOperationException("TODO"); //TODO - } - - @Override - public Command getAddAllCommand(int index, Collection values) { - throw new UnsupportedOperationException("TODO"); //TODO - } - -} +/***************************************************************************** + * Copyright (c) 2011 - 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: + * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.uml.tools.databinding; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.databinding.EMFProperties; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry; +import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest; +import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest; +import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest; +import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper; +import org.eclipse.papyrus.uml.tools.adapters.PortTypeAdapter; +import org.eclipse.papyrus.uml.tools.commands.DestroyDependencyWithoutSupplierCommand; +import org.eclipse.papyrus.uml.tools.utils.ElementUtil; +import org.eclipse.uml2.common.util.CacheAdapter; +import org.eclipse.uml2.uml.Dependency; +import org.eclipse.uml2.uml.Interface; +import org.eclipse.uml2.uml.Port; +import org.eclipse.uml2.uml.Realization; +import org.eclipse.uml2.uml.UMLPackage; + +/** + * An IObservableList to edit the UML Derived feature {@link Port#getProvideds()}. + * + * @author Camille Letavernier + */ +public class ProvidedInterfaceObservableList extends PapyrusObservableList { + + + /** The port. */ + protected Port port = null; + + /** Adapter for port type. */ + private Adapter portTypeAdapter = null; + + /** + * Instantiates a new provided interface observable list. + * + * @param source + * the source + * @param domain + * the domain + */ + public ProvidedInterfaceObservableList(Port source, EditingDomain domain) { + super(EMFProperties.list(UMLPackage.eINSTANCE.getPort_Provided()).observe(source), domain, source, UMLPackage.eINSTANCE.getPort_Provided()); + this.port = source; + port.eAdapters().add(portTypeAdapter = new PortTypeAdapter(port, UMLPackage.eINSTANCE.getPort_Provided(), UMLPackage.Literals.BEHAVIORED_CLASSIFIER__INTERFACE_REALIZATION)); + + } + + /** + * Gets the adds the all command. + * + * @param values + * the values + * @return the adds the all command + * @see org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableList#getAddAllCommand(java.util.Collection) + */ + @Override + public Command getAddAllCommand(Collection values) { + CompoundCommand returnedCommand = new CompoundCommand(); + List requests = new LinkedList(); + List commonInterfacesList = new ArrayList(); + + EList providedInterfaceList = port.getProvideds(); + + + // Sort input values + for(Object current : values) { + + if(current instanceof Interface) { + if(!providedInterfaceList.contains(current)) { + // Added interface + IEditCommandRequest request = new CreateRelationshipRequest(port.getType(), port.getType(), (EObject)current, ElementTypeRegistry.getInstance().getType("org.eclipse.papyrus.uml.InterfaceRealization")); + requests.add(request); + } else { + //Common interfaces + commonInterfacesList.add((Interface)current); + } + } + } + + if(!requests.isEmpty()) { + returnedCommand.append(getCommandFromRequests(getProvider(), requests)); + } + + + // Handle deleted interfaces + if(providedInterfaceList.size() != commonInterfacesList.size()) { + List removedInterfacesList = new ArrayList(); + + for(Interface current : providedInterfaceList) { + if(!commonInterfacesList.contains(current)) { + removedInterfacesList.add(current); + } + } + + returnedCommand.append(getRemoveAllCommand(removedInterfacesList)); + } + + + + return returnedCommand; + + } + + /** + * Gets the removes the command. + * + * @param value + * the value + * @return the removes the command + * @see org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableList#getRemoveCommand(java.lang.Object) + */ + @Override + public Command getRemoveCommand(Object value) { + CompoundCommand commands = null; + Dependency realization = getRealization(value); + + if(realization != null) { + commands = new CompoundCommand(); + IEditCommandRequest request = new DestroyReferenceRequest((TransactionalEditingDomain)editingDomain, realization, UMLPackage.eINSTANCE.getDependency_Supplier(), (EObject)value, false); + commands.append(new GMFtoEMFCommandWrapper(getProvider().getEditCommand(request))); + commands.append(new GMFtoEMFCommandWrapper(new DestroyDependencyWithoutSupplierCommand((TransactionalEditingDomain)editingDomain, realization, getProvider()))); + + } + return commands; + + + } + + /** + * @see org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableList#getRemoveAllCommand(java.util.Collection) + * + * @param values + * @return + */ + @Override + public Command getRemoveAllCommand(Collection values) { + CompoundCommand commands = new CompoundCommand(); + Set dependenciesSet = new HashSet(); + + for(Object value : values) { + Dependency realization = getRealization(value); + if(realization != null) { + IEditCommandRequest request = new DestroyReferenceRequest((TransactionalEditingDomain)editingDomain, realization, UMLPackage.eINSTANCE.getDependency_Supplier(), (EObject)value, false); + commands.append(new GMFtoEMFCommandWrapper(getProvider().getEditCommand(request))); + dependenciesSet.add(realization); + } + } + + commands.append(new GMFtoEMFCommandWrapper(new DestroyDependencyWithoutSupplierCommand((TransactionalEditingDomain)editingDomain, dependenciesSet, getProvider()))); + + return commands; + } + + /** + * Gets the realization. + * + * @param value + * the value + * @return the realization + */ + private Dependency getRealization(Object value) { + Realization realization = null; + if(value instanceof Interface) { + Interface deletedInterface = (Interface)value; + List realizationsList = ElementUtil.getInstancesFilteredByType(port.getModel(), Realization.class, null); + + // Parse all Realizations of model + boolean isRealization = false; + Iterator realizationsIterator = realizationsList.iterator(); + Realization current = null; + while(realizationsIterator.hasNext() && !isRealization) { + current = realizationsIterator.next(); + + // Check if Realization links port's type to deleted interface + isRealization = current.getSuppliers().contains(deletedInterface) && current.getClients().contains(port.getType()); + if(isRealization) { + realization = current; + } + } + } + + return realization; + } + + /** + * Gets the clear command. + * + * @return the clear command + * @see org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableList#getClearCommand() + */ + + @Override + public Command getClearCommand() { + + return new RecordingCommand((TransactionalEditingDomain)editingDomain) { + + @Override + protected void doExecute() { + CacheAdapter cache = CacheAdapter.getCacheAdapter(port); + cache.put(port, UMLPackage.Literals.PORT__PROVIDED, null); + + } + }; + } + + + /** + * @see org.eclipse.papyrus.infra.emf.databinding.EMFObservableList#dispose() + * + */ + @Override + public synchronized void dispose() { + port.eAdapters().remove(portTypeAdapter); + super.dispose(); + } + +} diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/RequiredInterfaceObservableList.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/RequiredInterfaceObservableList.java index 30cb1a4f04b..78cd9140ab4 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/RequiredInterfaceObservableList.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/RequiredInterfaceObservableList.java @@ -1,76 +1,231 @@ -/***************************************************************************** - * 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: - * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation - *****************************************************************************/ -package org.eclipse.papyrus.uml.tools.databinding; - -import java.util.Collection; - -import org.eclipse.emf.common.command.Command; -import org.eclipse.emf.databinding.EMFProperties; -import org.eclipse.emf.edit.domain.EditingDomain; -import org.eclipse.uml2.uml.Interface; -import org.eclipse.uml2.uml.Port; -import org.eclipse.uml2.uml.UMLPackage; - -/** - * An IObservableList to edit the UML Derived feature {@link Port#getRequireds()} - * - * @author Camille Letavernier - * - */ -public class RequiredInterfaceObservableList extends PapyrusObservableList { - - protected Port port; - - public RequiredInterfaceObservableList(Port source, EditingDomain domain) { - super(EMFProperties.list(UMLPackage.eINSTANCE.getPort_Required()).observe(source), domain, source, UMLPackage.eINSTANCE.getPort_Required()); - this.port = source; - } - - @Override - public Command getRemoveCommand(Object value) { - throw new UnsupportedOperationException("TODO"); //TODO - } - - @Override - public Command getRemoveAllCommand(Collection values) { - throw new UnsupportedOperationException("TODO"); //TODO - } - - @Override - public Command getAddCommand(int index, Object value) { - throw new UnsupportedOperationException("TODO"); //TODO - } - - protected Interface getRequiredInterface(Object value) { - if(!(value instanceof Interface)) { - throw new IllegalArgumentException("The value must be an Interface"); //$NON-NLS-1$ - } - Interface requiredInterface = (Interface)value; - return requiredInterface; - } - - @Override - public Command getAddCommand(Object value) { - throw new UnsupportedOperationException("TODO"); //TODO - } - - @Override - public Command getAddAllCommand(Collection values) { - throw new UnsupportedOperationException("TODO"); //TODO - } - - @Override - public Command getAddAllCommand(int index, Collection values) { - throw new UnsupportedOperationException("TODO"); //TODO - } - -} +/***************************************************************************** + * 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: + * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.uml.tools.databinding; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.databinding.EMFProperties; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry; +import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest; +import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest; +import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest; +import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper; +import org.eclipse.papyrus.uml.tools.adapters.PortTypeAdapter; +import org.eclipse.papyrus.uml.tools.commands.DestroyDependencyWithoutSupplierCommand; +import org.eclipse.papyrus.uml.tools.utils.ElementUtil; +import org.eclipse.uml2.common.util.CacheAdapter; +import org.eclipse.uml2.uml.Dependency; +import org.eclipse.uml2.uml.Interface; +import org.eclipse.uml2.uml.Port; +import org.eclipse.uml2.uml.UMLPackage; +import org.eclipse.uml2.uml.Usage; + +/** + * An IObservableList to edit the UML Derived feature {@link Port#getRequireds()} + * + * @author Camille Letavernier + * + */ +public class RequiredInterfaceObservableList extends PapyrusObservableList { + + /** The port. */ + protected Port port = null; + + /** The port type adapter. */ + private Adapter portTypeAdapter = null; + + /** + * Instantiates a new required interface observable list. + * + * @param source + * the source + * @param domain + * the domain + */ + public RequiredInterfaceObservableList(Port source, EditingDomain domain) { + super(EMFProperties.list(UMLPackage.eINSTANCE.getPort_Required()).observe(source), domain, source, UMLPackage.eINSTANCE.getPort_Required()); + this.port = source; + port.eAdapters().add(portTypeAdapter = new PortTypeAdapter(port, UMLPackage.Literals.PORT__REQUIRED, UMLPackage.Literals.PACKAGE__PACKAGED_ELEMENT)); + } + + /** + * @see org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableList#getAddAllCommand(java.util.Collection) + * + * @param values + * @return + */ + @Override + public Command getAddAllCommand(Collection values) { + + CompoundCommand returnedCommand = new CompoundCommand(); + List requests = new LinkedList(); + List commonInterfacesList = new ArrayList(); + EList requiredInterfacesList = port.getRequireds(); + + for(Object current : values) { + if(current instanceof Interface) { + + if(!requiredInterfacesList.contains(current)) { + + // Added interface + IEditCommandRequest request = new CreateRelationshipRequest(port.getType().eContainer(), port.getType(), (EObject)current, ElementTypeRegistry.getInstance().getType("org.eclipse.papyrus.uml.Usage")); + requests.add(request); + } else { + + // Conserved interface + commonInterfacesList.add((Interface)current); + } + } + } + + if(!requests.isEmpty()) { + returnedCommand.append(getCommandFromRequests(getProvider(), requests)); + } + + // Handle deleted interfaces + if(requiredInterfacesList.size() != commonInterfacesList.size()) { + List removedInterfacesList = new ArrayList(); + + for(Interface current : requiredInterfacesList) { + if(!commonInterfacesList.contains(current)) { + removedInterfacesList.add(current); + } + } + + returnedCommand.append(getRemoveAllCommand(removedInterfacesList)); + } + + return returnedCommand; + } + + /** + * @see org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableList#getRemoveCommand(java.lang.Object) + * + * @param value + * @return + */ + @Override + public Command getRemoveCommand(Object value) { + CompoundCommand commands = null; + Dependency usage = getUsage(value); + if(usage != null) { + commands = new CompoundCommand(); + IEditCommandRequest request = new DestroyReferenceRequest((TransactionalEditingDomain)editingDomain, usage, UMLPackage.eINSTANCE.getDependency_Supplier(), (EObject)value, false); + commands.append(new GMFtoEMFCommandWrapper(getProvider().getEditCommand(request))); + commands.append(new GMFtoEMFCommandWrapper(new DestroyDependencyWithoutSupplierCommand((TransactionalEditingDomain)editingDomain, usage, getProvider()))); + + } + + return commands; + } + + /** + * @see org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableList#getRemoveAllCommand(java.util.Collection) + * + * @param values + * @return + */ + @Override + public Command getRemoveAllCommand(Collection values) { + CompoundCommand commands = new CompoundCommand(); + Set dependenciesSet = new HashSet(); + + for(Object value : values) { + Dependency usage = getUsage(value); + if(usage != null) { + IEditCommandRequest request = new DestroyReferenceRequest((TransactionalEditingDomain)editingDomain, usage, UMLPackage.eINSTANCE.getDependency_Supplier(), (EObject)value, false); + commands.append(new GMFtoEMFCommandWrapper(getProvider().getEditCommand(request))); + dependenciesSet.add(usage); + } + } + + commands.append(new GMFtoEMFCommandWrapper(new DestroyDependencyWithoutSupplierCommand((TransactionalEditingDomain)editingDomain, dependenciesSet, getProvider()))); + + return commands; + } + + /** + * @see org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableList#getClearCommand() + * + * @return + */ + @Override + public Command getClearCommand() { + return new RecordingCommand((TransactionalEditingDomain)editingDomain) { + + @Override + protected void doExecute() { + CacheAdapter cache = CacheAdapter.getCacheAdapter(port); + cache.put(port, UMLPackage.Literals.PORT__REQUIRED, null); + + } + }; + } + + /** + * Gets the usage. + * + * @param value + * the value + * @return the usage + */ + private Dependency getUsage(Object value) { + Usage usage = null; + if(value instanceof Interface) { + Interface deletedInterface = (Interface)value; + List usagesList = ElementUtil.getInstancesFilteredByType(port.getModel(), Usage.class, null); + + // Parse all Usages of model + boolean isUsage = false; + Iterator usagesIterator = usagesList.iterator(); + Usage current = null; + while(usagesIterator.hasNext() && !isUsage) { + current = usagesIterator.next(); + + // Check if Usage links port's type to deleted interface + isUsage = current.getSuppliers().contains(deletedInterface) && current.getClients().contains(port.getType()); + if(isUsage) { + usage = current; + } + } + } + + return usage; + } + + /** + * @see org.eclipse.papyrus.infra.emf.databinding.EMFObservableList#dispose() + * + */ + @Override + public synchronized void dispose() { + port.eAdapters().remove(portTypeAdapter); + super.dispose(); + } + + +} diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/PortInterfaceContentProvider.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/PortInterfaceContentProvider.java new file mode 100644 index 00000000000..bce40814985 --- /dev/null +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/PortInterfaceContentProvider.java @@ -0,0 +1,97 @@ +/***************************************************************************** + * 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.uml.tools.providers; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.papyrus.uml.tools.utils.ElementUtil; +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; + +/** + * Content provider for Interfaces of provided or required attribute of a {@link Port}. + * + * @author Gabriel Pascual + * + */ +public class PortInterfaceContentProvider extends SemanticUMLContentProvider { + + + /** + * Instantiates a new port interface content provider. + * + * @param source + * the source + * @param feature + * the feature + */ + public PortInterfaceContentProvider(EObject source, EStructuralFeature feature) { + super(source, feature); + + } + + /** + * @see org.eclipse.papyrus.infra.emf.providers.strategy.SemanticEMFContentProvider#getElements() + * + * @return + */ + + public Object[] getElements() { + if(feature == UMLPackage.eINSTANCE.getPort_Provided()) { + return buildProvidedInterfaceElements(); + } else if(feature == UMLPackage.eINSTANCE.getPort_Required()) { + return buildRequiredInterfaceElements(); + } + return null; + } + + /** + * Gets the top package. + * + * @return the top package + */ + private Package getTopPackage() { + Package topPackage = null; + + EObject rootContainer = EcoreUtil.getRootContainer(eObject); + if(rootContainer instanceof Package) { + topPackage = (Package)rootContainer; + } + return topPackage; + } + + /** + * Builds the required interface elements. + * + * @return the object[] + */ + private Object[] buildRequiredInterfaceElements() { + Package rootPackage = getTopPackage(); + + return ElementUtil.getInstancesFilteredByType(rootPackage, Usage.class, null).toArray(); + } + + /** + * Builds the provided interface elements. + * + * @return the object[] + */ + private Object[] buildProvidedInterfaceElements() { + Package rootPackage = getTopPackage(); + + return ElementUtil.getInstancesFilteredByType(rootPackage, Realization.class, null).toArray(); + } +} diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/UMLContentProvider.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/UMLContentProvider.java index 879edaa0d32..b58d7e986ac 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/UMLContentProvider.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/UMLContentProvider.java @@ -1,226 +1,227 @@ -/***************************************************************************** - * 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: - * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation - * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - *****************************************************************************/ -package org.eclipse.papyrus.uml.tools.providers; - -import java.util.Collections; - -import org.eclipse.emf.ecore.EEnum; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.papyrus.infra.core.services.ServiceException; -import org.eclipse.papyrus.infra.core.services.ServicesRegistry; -import org.eclipse.papyrus.infra.core.utils.ServiceUtils; -import org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers; -import org.eclipse.papyrus.infra.emf.providers.EMFEnumeratorContentProvider; -import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResource; -import org.eclipse.papyrus.infra.widgets.providers.EmptyContentProvider; -import org.eclipse.papyrus.infra.widgets.providers.EncapsulatedContentProvider; -import org.eclipse.papyrus.infra.widgets.providers.IHierarchicContentProvider; -import org.eclipse.papyrus.uml.tools.Activator; -import org.eclipse.papyrus.uml.tools.util.UMLProviderHelper; -import org.eclipse.papyrus.uml.tools.utils.ProfileUtil; -import org.eclipse.uml2.uml.InstanceValue; -import org.eclipse.uml2.uml.Property; -import org.eclipse.uml2.uml.Stereotype; -import org.eclipse.uml2.uml.UMLPackage; -import org.eclipse.uml2.uml.util.UMLUtil; - -/** - * A global content provider for UML - */ -public class UMLContentProvider extends EncapsulatedContentProvider { - - protected EObject eObject; - - protected EStructuralFeature feature; - - protected Stereotype stereotype; - - protected ResourceSet root; - - public UMLContentProvider() { - //Empty (@see #inputChanged(Viewer, Object, Object)) - } - - @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - IStructuredContentProvider semanticProvider = null; - - if(newInput instanceof EObject) { - EObject eObject = (EObject)newInput; - semanticProvider = getSemanticProvider(eObject); - } - - if(newInput instanceof Resource) { - semanticProvider = getSemanticProvider((Resource)newInput); - } - - if(newInput instanceof ResourceSet) { - root = (ResourceSet)newInput; - semanticProvider = getSemanticProvider(root); - } - - if(newInput instanceof ServicesRegistry) { - try { - root = ServiceUtils.getInstance().getModelSet((ServicesRegistry)newInput); - semanticProvider = getSemanticProvider(root); - } catch (Exception ex) { - Activator.log.error(ex); - } - } - - if(semanticProvider != null) { - encapsulated = UMLProviderHelper.encapsulateProvider(semanticProvider, null, feature, root); - } - - super.inputChanged(viewer, oldInput, newInput); - } - - /** - * Constructor. - * - * @param source - * The edited EObject - * @param feature - * The edited EStructuralFeature - */ - public UMLContentProvider(final EObject source, final EStructuralFeature feature) { - this(source, feature, null); - } - - /** - * - * @param source - * The edited {@link EObject} (Should be either a UML Element or a StereotypeApplication) - * @param feature - * The edited {@link EStructuralFeature} - * @param stereotype - * The {@link Stereotype} of the source EObject. May be null if the source is not a StereotypeApplication - */ - public UMLContentProvider(final EObject source, final EStructuralFeature feature, final Stereotype stereotype) { - this(source, feature, stereotype, null); - } - - /** - * - * @param source - * The edited {@link EObject} (Should be either a UML Element or a StereotypeApplication) - * @param feature - * The edited {@link EStructuralFeature} - * @param stereotype - * The {@link Stereotype} of the source EObject. May be null if the source is not a StereotypeApplication - * @param root - * The resource set in which the objects could be found. If null, derive resource set automatically - */ - public UMLContentProvider(final EObject source, final EStructuralFeature feature, final Stereotype stereotype, ResourceSet root) { - this.eObject = source; - this.feature = feature; - this.stereotype = stereotype; - - if(root == null && eObject.eResource() != null) { - try { - // try to retrieve the root from the object to edit - root = ServiceUtilsForResource.getInstance().getModelSet(eObject.eResource()); - } catch (ServiceException e) { - //Nothing - } - } - if(root == null) { - // try to retrieve the root from the current editor - try { - root = ServiceUtilsForActionHandlers.getInstance().getModelSet(); - } catch (ServiceException e) { - //Nothing - } - } - this.root = root; - - IStructuredContentProvider semanticProvider = getSemanticProvider(source, feature, stereotype); - encapsulated = UMLProviderHelper.encapsulateProvider(semanticProvider, eObject, feature, root); - } - - protected IStructuredContentProvider getSemanticProvider(ResourceSet root) { - return new SemanticUMLContentProvider(root); - } - - protected IStructuredContentProvider getSemanticProvider(Resource root) { - return new SemanticUMLContentProvider(root.getContents().toArray(new EObject[0])); - } - - protected IStructuredContentProvider getSemanticProvider(EObject root) { - return new SemanticUMLContentProvider(new EObject[]{ root }); - } - - /** - * - * @param source - * The edited {@link EObject} (Should be either a UML Element or a StereotypeApplication) - * @param feature - * The edited {@link EStructuralFeature} - * @param stereotype - * The {@link Stereotype} of the source {@link EObject}. May be null if the source is not a StereotypeApplication - * @return - */ - protected IStructuredContentProvider getSemanticProvider(final EObject source, final EStructuralFeature feature, final Stereotype stereotype) { - if(UMLUtil.getBaseElement(source) != null) { - Property umlReference = ProfileUtil.findStereotypedProperty(stereotype, feature.getName()); - if(umlReference != null) { - return getStereotypedReferenceContentProvider(source, feature, (Stereotype)umlReference.getType()); - } - } - - if(feature == null) { - return EmptyContentProvider.instance; - } - - //Bug 383401: [Sequence Diagram] Interaction operator - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=383401 - if(feature == UMLPackage.eINSTANCE.getCombinedFragment_InteractionOperator()) { - return new InteractionOperatorContentProvider(source, feature); - } - - if(feature.getEType() instanceof EEnum) { - return new EMFEnumeratorContentProvider(feature); - } - - if(feature == UMLPackage.eINSTANCE.getPort_Provided() || feature == UMLPackage.eINSTANCE.getPort_Required()) { - //TODO : Use a specific content provider here, when it exists - return new ServiceEditFilteredContentProvider(source, feature, root); - } else if(feature == UMLPackage.eINSTANCE.getInstanceValue_Instance()) { - return new InstanceValueContentProvider((InstanceValue)source, feature, root); - } else { - return new ServiceEditFilteredContentProvider(source, feature, root); - } - } - - /** - * Uses the content provider for reference properties typed by a stereotype - * - * @param propertyPath - * The name of the property being edited - * @return - * The Content Provider for properties typed by a stereotype - */ - protected IHierarchicContentProvider getStereotypedReferenceContentProvider(EObject source, EStructuralFeature feature, Stereotype type) { - ResourceSet root = UMLUtil.getBaseElement(source).eResource().getResourceSet(); - - ServiceEditFilteredContentProvider contentProvider = new ServiceEditFilteredContentProvider(source, feature, root); - contentProvider.setWantedMetaclasses(Collections.singletonList(type)); - - return contentProvider; - } -} +/***************************************************************************** + * 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: + * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation + * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.tools.providers; + +import java.util.Collections; + +import org.eclipse.emf.ecore.EEnum; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.papyrus.infra.core.services.ServiceException; +import org.eclipse.papyrus.infra.core.services.ServicesRegistry; +import org.eclipse.papyrus.infra.core.utils.ServiceUtils; +import org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers; +import org.eclipse.papyrus.infra.emf.providers.EMFEnumeratorContentProvider; +import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResource; +import org.eclipse.papyrus.infra.widgets.providers.EmptyContentProvider; +import org.eclipse.papyrus.infra.widgets.providers.EncapsulatedContentProvider; +import org.eclipse.papyrus.infra.widgets.providers.IHierarchicContentProvider; +import org.eclipse.papyrus.uml.tools.Activator; +import org.eclipse.papyrus.uml.tools.util.UMLProviderHelper; +import org.eclipse.papyrus.uml.tools.utils.ProfileUtil; +import org.eclipse.uml2.uml.InstanceValue; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.Stereotype; +import org.eclipse.uml2.uml.UMLPackage; +import org.eclipse.uml2.uml.util.UMLUtil; + +/** + * A global content provider for UML + */ +public class UMLContentProvider extends EncapsulatedContentProvider { + + protected EObject eObject; + + protected EStructuralFeature feature; + + protected Stereotype stereotype; + + protected ResourceSet root; + + public UMLContentProvider() { + //Empty (@see #inputChanged(Viewer, Object, Object)) + } + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + IStructuredContentProvider semanticProvider = null; + + if(newInput instanceof EObject) { + EObject eObject = (EObject)newInput; + semanticProvider = getSemanticProvider(eObject); + } + + if(newInput instanceof Resource) { + semanticProvider = getSemanticProvider((Resource)newInput); + } + + if(newInput instanceof ResourceSet) { + root = (ResourceSet)newInput; + semanticProvider = getSemanticProvider(root); + } + + if(newInput instanceof ServicesRegistry) { + try { + root = ServiceUtils.getInstance().getModelSet((ServicesRegistry)newInput); + semanticProvider = getSemanticProvider(root); + } catch (Exception ex) { + Activator.log.error(ex); + } + } + + if(semanticProvider != null) { + encapsulated = UMLProviderHelper.encapsulateProvider(semanticProvider, null, feature, root); + } + + super.inputChanged(viewer, oldInput, newInput); + } + + /** + * Constructor. + * + * @param source + * The edited EObject + * @param feature + * The edited EStructuralFeature + */ + public UMLContentProvider(final EObject source, final EStructuralFeature feature) { + this(source, feature, null); + } + + /** + * + * @param source + * The edited {@link EObject} (Should be either a UML Element or a StereotypeApplication) + * @param feature + * The edited {@link EStructuralFeature} + * @param stereotype + * The {@link Stereotype} of the source EObject. May be null if the source is not a StereotypeApplication + */ + public UMLContentProvider(final EObject source, final EStructuralFeature feature, final Stereotype stereotype) { + this(source, feature, stereotype, null); + } + + /** + * + * @param source + * The edited {@link EObject} (Should be either a UML Element or a StereotypeApplication) + * @param feature + * The edited {@link EStructuralFeature} + * @param stereotype + * The {@link Stereotype} of the source EObject. May be null if the source is not a StereotypeApplication + * @param root + * The resource set in which the objects could be found. If null, derive resource set automatically + */ + public UMLContentProvider(final EObject source, final EStructuralFeature feature, final Stereotype stereotype, ResourceSet root) { + this.eObject = source; + this.feature = feature; + this.stereotype = stereotype; + + if(root == null && eObject.eResource() != null) { + try { + // try to retrieve the root from the object to edit + root = ServiceUtilsForResource.getInstance().getModelSet(eObject.eResource()); + } catch (ServiceException e) { + //Nothing + } + } + if(root == null) { + // try to retrieve the root from the current editor + try { + root = ServiceUtilsForActionHandlers.getInstance().getModelSet(); + } catch (ServiceException e) { + //Nothing + } + } + this.root = root; + + IStructuredContentProvider semanticProvider = getSemanticProvider(source, feature, stereotype); + encapsulated = UMLProviderHelper.encapsulateProvider(semanticProvider, eObject, feature, root); + } + + protected IStructuredContentProvider getSemanticProvider(ResourceSet root) { + return new SemanticUMLContentProvider(root); + } + + protected IStructuredContentProvider getSemanticProvider(Resource root) { + return new SemanticUMLContentProvider(root.getContents().toArray(new EObject[0])); + } + + protected IStructuredContentProvider getSemanticProvider(EObject root) { + return new SemanticUMLContentProvider(new EObject[]{ root }); + } + + /** + * + * @param source + * The edited {@link EObject} (Should be either a UML Element or a StereotypeApplication) + * @param feature + * The edited {@link EStructuralFeature} + * @param stereotype + * The {@link Stereotype} of the source {@link EObject}. May be null if the source is not a StereotypeApplication + * @return + */ + protected IStructuredContentProvider getSemanticProvider(final EObject source, final EStructuralFeature feature, final Stereotype stereotype) { + if(UMLUtil.getBaseElement(source) != null) { + Property umlReference = ProfileUtil.findStereotypedProperty(stereotype, feature.getName()); + if(umlReference != null) { + return getStereotypedReferenceContentProvider(source, feature, (Stereotype)umlReference.getType()); + } + } + + if(feature == null) { + return EmptyContentProvider.instance; + } + + //Bug 383401: [Sequence Diagram] Interaction operator + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=383401 + if(feature == UMLPackage.eINSTANCE.getCombinedFragment_InteractionOperator()) { + return new InteractionOperatorContentProvider(source, feature); + } + + if(feature.getEType() instanceof EEnum) { + return new EMFEnumeratorContentProvider(feature); + } + + if(feature == UMLPackage.eINSTANCE.getPort_Provided() || feature == UMLPackage.eINSTANCE.getPort_Required()) { + return new PortInterfaceContentProvider(source, feature); + } else if(feature == UMLPackage.eINSTANCE.getInstanceValue_Instance()) { + return new InstanceValueContentProvider((InstanceValue)source, feature, root); + } else { + return new ServiceEditFilteredContentProvider(source, feature, root); + } + } + + /** + * Uses the content provider for reference properties typed by a stereotype + * + * @param propertyPath + * The name of the property being edited + * @return + * The Content Provider for properties typed by a stereotype + */ + protected IHierarchicContentProvider getStereotypedReferenceContentProvider(EObject source, EStructuralFeature feature, Stereotype type) { + ResourceSet root = UMLUtil.getBaseElement(source).eResource().getResourceSet(); + + ServiceEditFilteredContentProvider contentProvider = new ServiceEditFilteredContentProvider(source, feature, root); + contentProvider.setWantedMetaclasses(Collections.singletonList(type)); + + return contentProvider; + } +} \ No newline at end of file -- cgit v1.2.3