Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabriel Pascual2014-12-01 03:35:28 -0500
committerGabriel Pascual2014-12-10 09:13:00 -0500
commit39a5c10ecb6e965a5357ff3e443082fb5da852fb (patch)
treeaab5cfbdcaf1f890fc24e4a0cf48dd278d959f85 /plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode
parent01b0d3e3a76c33d0fdc1252cd3bdf0dced05b2d8 (diff)
downloadorg.eclipse.papyrus-39a5c10ecb6e965a5357ff3e443082fb5da852fb.tar.gz
org.eclipse.papyrus-39a5c10ecb6e965a5357ff3e443082fb5da852fb.tar.xz
org.eclipse.papyrus-39a5c10ecb6e965a5357ff3e443082fb5da852fb.zip
450146: [Diagram][table] Delete action does nothing for Table and
Diagram in ModelExplorer https://bugs.eclipse.org/bugs/show_bug.cgi?id=450146 - Create AdviceHelper to uncontrol during DestroyRequest - Use Papyrus editor fixture in abstract unit test implementation - Create a Request Parameter to ensure undo/redo action after uncontrol Change-Id: Ibdd840489de30bb8b7d56d4d3cf62bd916326fa8 Signed-off-by: Gabriel Pascual <gabriel.pascual@all4tec.net>
Diffstat (limited to 'plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode')
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/META-INF/MANIFEST.MF8
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/build.properties3
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/icons/CreateSubModel_16.pngbin0 -> 547 bytes
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/icons/ReintegrateSubModel_16.pngbin0 -> 576 bytes
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/plugin.xml95
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/helper/advice/ControlModeEditHelperAdvice.java99
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/listener/LoadResourceSnippet.java178
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/handler/ControlCommandHandler.java182
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/handler/UncontrolCommandHandler.java83
9 files changed, 552 insertions, 96 deletions
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/META-INF/MANIFEST.MF b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/META-INF/MANIFEST.MF
index 5a8b4426a1e..aa6e0c111e0 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/META-INF/MANIFEST.MF
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/META-INF/MANIFEST.MF
@@ -3,7 +3,8 @@ Export-Package: org.eclipse.papyrus.infra.services.controlmode,
org.eclipse.papyrus.infra.services.controlmode.commands,
org.eclipse.papyrus.infra.services.controlmode.participants,
org.eclipse.papyrus.infra.services.controlmode.ui,
- org.eclipse.papyrus.infra.services.controlmode.util
+ org.eclipse.papyrus.infra.services.controlmode.util,
+ org.eclipse.papyrus.infra.services.handler
Require-Bundle: org.eclipse.emf.edit.ui,
org.eclipse.papyrus.infra.core;bundle-version="1.1.0",
org.eclipse.core.expressions;bundle-version="3.4.400",
@@ -14,9 +15,10 @@ Require-Bundle: org.eclipse.emf.edit.ui,
org.eclipse.gmf.runtime.common.core,
org.eclipse.gmf.runtime.emf.commands.core,
org.eclipse.gmf.runtime.emf.type.core,
- org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="1.1.0",
org.eclipse.papyrus.infra.widgets.toolbox;bundle-version="1.1.0",
- org.eclipse.papyrus.infra.emf;bundle-version="1.1.0"
+ org.eclipse.papyrus.infra.emf;bundle-version="1.1.0",
+ org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="1.1.0",
+ org.eclipse.papyrus.infra.services.edit;bundle-version="1.1.0"
Bundle-Vendor: %providerName
Bundle-ActivationPolicy: lazy
Bundle-Version: 1.1.0.qualifier
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/build.properties b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/build.properties
index e57e797453e..ccae1d13261 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/build.properties
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/build.properties
@@ -5,7 +5,8 @@ bin.includes = META-INF/,\
plugin.xml,\
plugin.properties,\
schema/,\
- about.html
+ about.html,\
+ icons/
output..=bin/
src.includes = about.html
source..=src/
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/icons/CreateSubModel_16.png b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/icons/CreateSubModel_16.png
new file mode 100644
index 00000000000..2140dc439e1
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/icons/CreateSubModel_16.png
Binary files differ
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/icons/ReintegrateSubModel_16.png b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/icons/ReintegrateSubModel_16.png
new file mode 100644
index 00000000000..a9ddbb8b0cd
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/icons/ReintegrateSubModel_16.png
Binary files differ
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/plugin.xml b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/plugin.xml
index 3859f2ff6b4..2074fa2fb9f 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/plugin.xml
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/plugin.xml
@@ -25,5 +25,98 @@
description="Snippet to attach listener on the resourceSet">
</modelSetSnippet>
</extension>
-
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ defaultHandler="org.eclipse.papyrus.infra.services.handler.ControlCommandHandler"
+ description="Move this submodel into its own resource (file)"
+ id="org.eclipse.papyrus.infra.services.controlmode.createsubmodel"
+ name="Create submodel unit">
+ <commandParameter
+ id="org.eclipse.papyrus.infra.services.controlmode.useDialogParameter"
+ name="Show control mode dialog"
+ optional="true">
+ <values
+ class="org.eclipse.papyrus.infra.services.controlmode.commands.ControlModeCommandParameterValues">
+ </values>
+ </commandParameter>
+ </command>
+ <command
+ defaultHandler="org.eclipse.papyrus.infra.services.handler.UncontrolCommandHandler"
+ description="Reintegrate this submodel into the resource (file) of the parent model"
+ id="org.eclipse.papyrus.infra.services.controlmode.reintegratesubmodel"
+ name="Reintegrate submodel unit into parent model">
+ </command>
+ </extension>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.papyrus.views.modelexplorer.modelexplorer.popup?after=tools">
+ <command
+ commandId="org.eclipse.papyrus.infra.services.controlmode.createsubmodel"
+ icon="icons/CreateSubModel_16.png"
+ label="Create Submodel"
+ style="push"
+ tooltip="Move this submodel into its own resource (file)">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.papyrus.infra.services.controlmode.isFragmentModel"
+ value="false">
+ </test>
+ </with>
+ </visibleWhen>
+ </command>
+ <command
+ commandId="org.eclipse.papyrus.infra.services.controlmode.reintegratesubmodel"
+ icon="icons/ReintegrateSubModel_16.png"
+ label="Reintegrate Submodel"
+ style="push"
+ tooltip="Reintegrate this submodel into the resource (file) of the parent model">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <and>
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.papyrus.infra.services.controlmode.isFragmentModel"
+ value="true">
+ </test>
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.papyrus.infra.services.controlmode.isParentLoaded"
+ value="true">
+ </test>
+ </and>
+ </with>
+ </visibleWhen>
+ </command>
+ </menuContribution>
+ </extension>
+ <extension
+ point="org.eclipse.gmf.runtime.emf.type.core.elementTypeBindings">
+ <binding
+ context="org.eclipse.papyrus.infra.services.edit.TypeContext">
+ <advice
+ ref="org.eclipse.papyrus.infra.services.controlmode.advice.ControlModeAdviceHelper">
+ </advice>
+ </binding>
+ </extension>
+ <extension
+ point="org.eclipse.gmf.runtime.emf.type.core.elementTypes">
+ <metamodel
+ nsURI="http://www.eclipse.org/emf/2002/Ecore">
+ <adviceBinding
+ class="org.eclipse.papyrus.infra.services.controlmode.helper.advice.ControlModeEditHelperAdvice"
+ id="org.eclipse.papyrus.infra.services.controlmode.advice.ControlModeAdviceHelper"
+ inheritance="all"
+ typeId="*">
+ </adviceBinding>
+ </metamodel>
+ </extension>
</plugin>
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/helper/advice/ControlModeEditHelperAdvice.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/helper/advice/ControlModeEditHelperAdvice.java
new file mode 100644
index 00000000000..8dfe6f2c3c9
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/helper/advice/ControlModeEditHelperAdvice.java
@@ -0,0 +1,99 @@
+/*****************************************************************************
+ * Copyright (c) 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:
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.services.controlmode.helper.advice;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.papyrus.infra.services.controlmode.ControlModeManager;
+import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest;
+import org.eclipse.papyrus.infra.services.controlmode.IControlModeManager;
+import org.eclipse.papyrus.infra.services.controlmode.util.ControlHelper;
+import org.eclipse.papyrus.infra.services.edit.utils.RequestParameterConstants;
+
+/**
+ * Advice helper for Control Mode service to manage uncontrol during deletion action on the model.
+ *
+ * @author Gabriel Pascual
+ */
+public class ControlModeEditHelperAdvice extends AbstractEditHelperAdvice {
+
+
+ /**
+ * Instantiates a new control mode advice helper.
+ */
+ public ControlModeEditHelperAdvice() {
+ super();
+ }
+
+ /**
+ * Gets the before destroy element command.
+ *
+ * @param request
+ * the request
+ * @return the before destroy element command
+ * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#getAfterDestroyElementCommand(org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest)
+ */
+ @Override
+ protected ICommand getBeforeDestroyElementCommand(DestroyElementRequest request) {
+ EObject objectToDestroy = validateRequest(request);
+ ICommand afterDestroyElementCommand = null;
+
+ if (objectToDestroy != null) {
+ ControlModeRequest controlRequest = ControlModeRequest.createUIUncontrolModelRequest(request.getEditingDomain(), objectToDestroy);
+ IControlModeManager controlMng = ControlModeManager.getInstance();
+ afterDestroyElementCommand = controlMng.getUncontrolCommand(controlRequest);
+ }
+
+
+
+ return afterDestroyElementCommand;
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#configureRequest(org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest)
+ *
+ * @param request
+ */
+ @Override
+ public void configureRequest(IEditCommandRequest request) {
+
+ // Add the parameter only if the deleted element has to be uncontrolled
+ if (validateRequest(request) != null) {
+ request.getParameters().put(RequestParameterConstants.TRANSACTIONAL_NESTING, Boolean.TRUE);
+ }
+ }
+
+
+
+ /**
+ * Validate that request is a destroy element one and that element can is Rooted Controlled Object.
+ *
+ * @param request
+ * the request
+ * @return true, if successful
+ */
+ protected EObject validateRequest(IEditCommandRequest request) {
+ EObject uncontrolledObject = null;
+ if (request instanceof DestroyElementRequest) {
+ EObject objectToDestroy = ((DestroyElementRequest) request).getElementToDestroy();
+ if (ControlHelper.isRootControlledObject(objectToDestroy)) {
+ uncontrolledObject = objectToDestroy;
+ }
+ }
+ return uncontrolledObject;
+ }
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/listener/LoadResourceSnippet.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/listener/LoadResourceSnippet.java
index 2b7bdfe61f5..7f5287822e9 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/listener/LoadResourceSnippet.java
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/listener/LoadResourceSnippet.java
@@ -1,91 +1,87 @@
-/*****************************************************************************
- * Copyright (c) 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:
- * Céline Janssens (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.services.controlmode.listener;
-
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.emf.transaction.RollbackException;
-import org.eclipse.papyrus.infra.core.resource.IModelSetSnippet;
-import org.eclipse.papyrus.infra.core.resource.ModelSet;
-import org.eclipse.papyrus.infra.core.resource.ResourceAdapter;
-import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.internal.PageManagerImpl;
-import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.utils.TransactionHelper;
-import org.eclipse.papyrus.infra.services.controlmode.commands.LoadDiagramCommand;
-
-
-/**
- * This Snippet is used to attach Loading listener on the resourceSet.
- *
- * @author Céline JANSSENS
- *
- */
-public class LoadResourceSnippet implements IModelSetSnippet {
-
- private LoadResourceAdapter adapter;
-
- /**
- * @see org.eclipse.papyrus.infra.core.resource.IModelSnippet#start(org.eclipse.papyrus.infra.core.resource.IModel)
- *
- * @param startingModel
- */
- public void start(ModelSet startingModel) {
- adapter = new LoadResourceAdapter();
- startingModel.eAdapters().add(adapter);
-
- }
-
- /**
- * @see org.eclipse.papyrus.infra.core.resource.IModelSnippet#dispose(org.eclipse.papyrus.infra.core.resource.IModel)
- *
- * @param stoppingModel
- */
- public void dispose(ModelSet stoppingModel) {
- stoppingModel.eAdapters().remove(adapter);
- adapter = null;
- }
-
-
- /**
- * This Adapter allows to load associated pages of the resources.
- * It uses {@link LoadingPagesHandler} to do so with the help of the {@link PageManagerImpl}.
- *
- * @author Céline JANSSENS
- *
- */
- private class LoadResourceAdapter extends ResourceAdapter {
-
- /**
- * @see org.eclipse.papyrus.infra.core.resource.ResourceAdapter#handleResourceLoaded(org.eclipse.emf.ecore.resource.Resource)
- *
- * @param resource
- */
- @Override
- protected void handleResourceLoaded(Resource resource) {
- EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(resource);
- final LoadDiagramCommand loadCommand = new LoadDiagramCommand(resource);
- try {
- TransactionHelper.run(editingDomain, new Runnable() {
- public void run() {
- loadCommand.run();
- }
- });
- } catch (InterruptedException e) {
- // Nothing to do
- } catch (RollbackException e) {
- // Nothing to do
- }
- }
- }
-}
+/*****************************************************************************
+ * Copyright (c) 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:
+ * Céline Janssens (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.services.controlmode.listener;
+
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.RollbackException;
+import org.eclipse.papyrus.infra.core.resource.IModelSetSnippet;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.ResourceAdapter;
+import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.internal.PageManagerImpl;
+import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.utils.TransactionHelper;
+import org.eclipse.papyrus.infra.services.controlmode.commands.LoadDiagramCommand;
+
+
+/**
+ * This Snippet is used to attach Loading listener on the resourceSet.
+ *
+ * @author Céline JANSSENS
+ *
+ */
+public class LoadResourceSnippet implements IModelSetSnippet {
+
+ private LoadResourceAdapter adapter;
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.resource.IModelSnippet#start(org.eclipse.papyrus.infra.core.resource.IModel)
+ *
+ * @param startingModel
+ */
+ public void start(ModelSet startingModel) {
+ adapter = new LoadResourceAdapter();
+ startingModel.eAdapters().add(adapter);
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.resource.IModelSnippet#dispose(org.eclipse.papyrus.infra.core.resource.IModel)
+ *
+ * @param stoppingModel
+ */
+ public void dispose(ModelSet stoppingModel) {
+ stoppingModel.eAdapters().remove(adapter);
+ adapter = null;
+ }
+
+
+ /**
+ * This Adapter allows to load associated pages of the resources.
+ * It uses {@link LoadingPagesHandler} to do so with the help of the {@link PageManagerImpl}.
+ *
+ * @author Céline JANSSENS
+ *
+ */
+ private class LoadResourceAdapter extends ResourceAdapter {
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.resource.ResourceAdapter#handleResourceLoaded(org.eclipse.emf.ecore.resource.Resource)
+ *
+ * @param resource
+ */
+ @Override
+ protected void handleResourceLoaded(Resource resource) {
+ EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(resource);
+ final LoadDiagramCommand loadCommand = new LoadDiagramCommand(resource);
+ try {
+ TransactionHelper.run(editingDomain, loadCommand);
+ } catch (InterruptedException e) {
+ // Nothing to do
+ } catch (RollbackException e) {
+ // Nothing to do
+ }
+ }
+ }
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/handler/ControlCommandHandler.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/handler/ControlCommandHandler.java
new file mode 100644
index 00000000000..fa622c8ea6a
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/handler/ControlCommandHandler.java
@@ -0,0 +1,182 @@
+/*****************************************************************************
+ * Copyright (c) 2013, 2014 Atos, 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:
+ * Arthur Daussy (Atos) arthur.daussy@atos.net - Initial API and implementation
+ * Christian W. Damus (CEA LIST) - pluggable providers of fragment-resource selection dialogs
+ * Christian W. Damus (CEA) - bug 410346
+ * Juan Cadavid <juan.cadavid@cea.fr> - bug 399877
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 436952
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.handler;
+
+import java.util.regex.Pattern;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.ParameterValuesException;
+import org.eclipse.core.commands.common.NotDefinedException;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.utils.AdapterUtils;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.services.controlmode.ControlModeManager;
+import org.eclipse.papyrus.infra.services.controlmode.ControlModePlugin;
+import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest;
+import org.eclipse.papyrus.infra.services.controlmode.IControlModeManager;
+import org.eclipse.papyrus.infra.services.controlmode.commands.ControlModeCommandParameterValues;
+import org.eclipse.papyrus.infra.services.controlmode.ui.IControlModeFragmentDialogProvider;
+import org.eclipse.papyrus.infra.services.controlmode.util.LabelHelper;
+import org.eclipse.papyrus.infra.widgets.toolbox.notification.builders.NotificationBuilder;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * Handler used to control an element
+ *
+ * @author adaussy
+ */
+public class ControlCommandHandler extends AbstractHandler {
+
+ /** The Constant NO_EDITING_DOMAIN_MESSAGE. */
+ private static final String NO_EDITING_DOMAIN_MESSAGE = "No editing domain has not be found. The Uncontrol failed.";
+
+ /** The Constant EMPTY_SELECTION_MESSAGE. */
+ private static final String EMPTY_SELECTION_MESSAGE = "Nothing to control";
+
+ /** The Constant CONTROLMODE_USE_DIALOG_PARAMETER. */
+ public static final String CONTROLMODE_USE_DIALOG_PARAMETER = "org.eclipse.papyrus.infra.services.controlmode.useDialogParameter"; //$NON-NLS-1$
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+
+ if (selection instanceof IStructuredSelection) {
+ if (selection == null || selection.isEmpty() || ((IStructuredSelection) selection).size() > 1) {
+ NotificationBuilder.createInfoPopup(EMPTY_SELECTION_MESSAGE).run();
+ return null;
+ }
+ EObject eObjectToControl = EMFHelper.getEObject(((IStructuredSelection) selection).getFirstElement());
+ try {
+ TransactionalEditingDomain editingDomain = ServiceUtilsForEObject.getInstance().getTransactionalEditingDomain(eObjectToControl);
+ if (getShowDialogParameterValue(event)) {
+ IControlModeFragmentDialogProvider provider = getDialogProvider(eObjectToControl);
+ Dialog dialog = provider.createDialog(Display.getCurrent().getActiveShell(), eObjectToControl.eResource(), getDefaultLabelResource(eObjectToControl));
+ if (dialog.open() == Window.OK) {
+ ControlModeRequest controlRequest = ControlModeRequest.createUIControlModelRequest(editingDomain, eObjectToControl, provider.getSelectedURI(dialog));
+ IControlModeManager controlMng = ControlModeManager.getInstance();
+ ICommand controlCommand = controlMng.getControlCommand(controlRequest);
+ editingDomain.getCommandStack().execute(new GMFtoEMFCommandWrapper(controlCommand));
+ }
+ } else {
+ URI defaultURI = computeDefaultURI(eObjectToControl.eResource(), getDefaultLabelResource(eObjectToControl));
+ ControlModeRequest controlRequest = ControlModeRequest.createUIControlModelRequest(editingDomain, eObjectToControl, defaultURI);
+ IControlModeManager controlMng = ControlModeManager.getInstance();
+ ICommand controlCommand = controlMng.getControlCommand(controlRequest);
+ editingDomain.getCommandStack().execute(new GMFtoEMFCommandWrapper(controlCommand));
+ }
+ } catch (ServiceException e) {
+ NotificationBuilder.createInfoPopup(NO_EDITING_DOMAIN_MESSAGE).run();
+ }
+ } else {
+ NotificationBuilder.createInfoPopup(EMPTY_SELECTION_MESSAGE).run();
+ }
+
+ return null;
+ }
+
+ public URI computeDefaultURI(Resource currentResource, String defaultName) {
+ String ext = currentResource.getURI().fileExtension();
+ URI uri = currentResource.getURI().trimSegments(1);
+ uri = uri.appendSegment(defaultName).appendFileExtension(ext);
+ return uri;
+ }
+
+ /**
+ *
+ * @param event
+ * @return true if the dialog will be displayed to the user, false if it will be bypassed and the default values will be used
+ */
+ protected Boolean getShowDialogParameterValue(ExecutionEvent event) {
+ Boolean showDialogValue = null;
+
+ ControlModeCommandParameterValues parameterValues = null;
+ try {
+ Command command = event.getCommand();
+ parameterValues = (ControlModeCommandParameterValues) command.getParameter(CONTROLMODE_USE_DIALOG_PARAMETER).getValues();
+ showDialogValue = parameterValues.get("showDialog");
+ if (showDialogValue == null) {
+ showDialogValue = true; // By default, the dialog is always displayed to the user
+ }
+ } catch (ParameterValuesException e) {
+ ControlModePlugin.log.error("Parameter values exception in control mode command.", e);
+ } catch (NotDefinedException e) {
+ ControlModePlugin.log.error("Parameter not defined for control mode command.", e);
+ }
+ return showDialogValue;
+ }
+
+ IControlModeFragmentDialogProvider getDialogProvider(EObject context) {
+ try {
+ ModelSet modelSet = ServiceUtilsForEObject.getInstance().getModelSet(context);
+ return AdapterUtils.adapt(modelSet, IControlModeFragmentDialogProvider.class, IControlModeFragmentDialogProvider.DEFAULT);
+ } catch (ServiceException e) {
+ // can't get the model set? Odd
+ ControlModePlugin.log.error("Cannot obtain ModelSet for controlled object.", e);
+ return IControlModeFragmentDialogProvider.DEFAULT;
+ }
+ }
+
+ /**
+ * Compute a default name for the new resource
+ * TODO plug in naming strategy
+ *
+ * @param eObject
+ * @return
+ */
+ protected String getDefaultLabelResource(EObject eObject) {
+ String defaultName = null;
+ EStructuralFeature feature = eObject.eClass().getEStructuralFeature("name");
+ if (feature != null) {
+ Object eGet = eObject.eGet(feature);
+ if (eGet instanceof String) {
+ defaultName = (String) eGet;
+ }
+ }
+ if (defaultName == null) {
+ defaultName = LabelHelper.getPrettyLabel(eObject);
+ Pattern p = Pattern.compile("<<.*?>>|<.*?>");
+ defaultName = p.matcher(defaultName).replaceAll("").trim();
+ }
+ StringBuilder b = new StringBuilder();
+ for (Character c : defaultName.toCharArray()) {
+ if (Character.isJavaIdentifierPart(c)) {
+ b.append(c);
+ } else {
+ b.append("_");
+ }
+ }
+ return b.toString();
+ }
+
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/handler/UncontrolCommandHandler.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/handler/UncontrolCommandHandler.java
new file mode 100644
index 00000000000..47223e7e7fc
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/handler/UncontrolCommandHandler.java
@@ -0,0 +1,83 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Atos.
+ *
+ *
+ * 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:
+ * Arthur Daussy (Atos) arthur.daussy@atos.net - Initial API and implementation
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 436952
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.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.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForSelection;
+import org.eclipse.papyrus.infra.services.controlmode.ControlModeManager;
+import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest;
+import org.eclipse.papyrus.infra.services.controlmode.IControlModeManager;
+import org.eclipse.papyrus.infra.widgets.toolbox.notification.builders.NotificationBuilder;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * Handler use to uncontrol an element
+ *
+ * @author adaussy
+ *
+ */
+public class UncontrolCommandHandler extends AbstractHandler {
+
+ /** The Constant NO_EDITING_DOMAIN_MESSAGE. */
+ private static final String NO_EDITING_DOMAIN_MESSAGE = "No editing domain has not be found. The Uncontrol failed.";
+
+ /** The Constant EMPTY_SELECTION_MESSAGE. */
+ private static final String EMPTY_SELECTION_MESSAGE = "Nothing to Uncontrol";
+
+ /**
+ * @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);
+
+ if (selection instanceof IStructuredSelection) {
+ if (selection == null || selection.isEmpty() || ((IStructuredSelection) selection).size() > 1) {
+ NotificationBuilder.createInfoPopup(EMPTY_SELECTION_MESSAGE).run();
+ return null;
+ }
+
+ try {
+ TransactionalEditingDomain editingDomain = ServiceUtilsForSelection.getInstance().getTransactionalEditingDomain(selection);
+ EObject eObjectToControl = EMFHelper.getEObject(((IStructuredSelection) selection).getFirstElement());
+ ControlModeRequest controlRequest = ControlModeRequest.createUIUncontrolModelRequest(editingDomain, eObjectToControl);
+ IControlModeManager controlMng = ControlModeManager.getInstance();
+ ICommand controlCommand = controlMng.getUncontrolCommand(controlRequest);
+ editingDomain.getCommandStack().execute(new GMFtoEMFCommandWrapper(controlCommand));
+ } catch (ServiceException e) {
+ NotificationBuilder.createInfoPopup(NO_EDITING_DOMAIN_MESSAGE).run();
+
+ }
+
+ } else {
+ NotificationBuilder.createInfoPopup(EMPTY_SELECTION_MESSAGE).run();
+ }
+
+ return null;
+ }
+}

Back to the top