diff options
author | Gabriel Pascual | 2014-11-20 16:55:49 +0000 |
---|---|---|
committer | Remi Schnekenburger | 2014-11-28 13:54:01 +0000 |
commit | 59af16c820bad6ff056d7c65550e7e1408c7dde0 (patch) | |
tree | 190ab2324edc0e20ad77a1121c6ac2f3051a3450 | |
parent | cc7f71f988dcce1564681ddf6841596409159319 (diff) | |
download | org.eclipse.papyrus-59af16c820bad6ff056d7c65550e7e1408c7dde0.tar.gz org.eclipse.papyrus-59af16c820bad6ff056d7c65550e7e1408c7dde0.tar.xz org.eclipse.papyrus-59af16c820bad6ff056d7c65550e7e1408c7dde0.zip |
Bug 452518 - [Profile Diagram] Cannot delete a profile diagram in Model
Explorer
- Controlled element test not working for page (Diagram/Table)
- Fix Control helper
Change-Id: I04703646b6eaba44d4606af4579e796f62b9ce85
Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr>
Signed-off-by: Gabriel Pascual <gabriel.pascual@all4tec.net>
(cherry picked from commit a90b83a322760bd43c4929ab8c6b168f23239953)
2 files changed, 74 insertions, 55 deletions
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/util/ControlHelper.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/util/ControlHelper.java index dddc4ef7c3c..ac8534b296a 100644 --- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/util/ControlHelper.java +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/util/ControlHelper.java @@ -1,42 +1,48 @@ -/*****************************************************************************
- * 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
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.services.controlmode.util;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-
-/**
- * Helper for control command
- *
- * @author adaussy
- *
- */
-public class ControlHelper {
-
- /**
- * Return true if the object is an controlled object
- *
- * @param eObject
- * @return
- */
- public static boolean isRootControlledObject(EObject eObject) {
- if (eObject != null) {
- Resource resource = eObject.eResource();
- if (resource != null) {
- return resource.getContents().contains(eObject);
- }
- }
- return false;
- }
-}
+/***************************************************************************** + * 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 + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 452518 + * + *****************************************************************************/ +package org.eclipse.papyrus.infra.services.controlmode.util; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.InternalEObject; + +/** + * Helper for control command + * + * @author adaussy + * + */ +public class ControlHelper { + + /** + * Return true if the object is the root of a resource and it also has a container. It must verify : + * <ol> + * <li>it is an InternalEObject</li> + * <li>it has both eDirectResource() and eContainer() not null</li> + * </ol> + * + * @param eObject + * @return + */ + public static boolean isRootControlledObject(EObject eObject) { + boolean result = false; + + if (eObject != null) { + if (eObject instanceof InternalEObject) { + result = ((InternalEObject) eObject).eDirectResource() != null && eObject.eContainer() != null; + } + + } + return result; + } +} diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/DeleteCommandHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/DeleteCommandHandler.java index a3cb865b0cd..fe970a60f5e 100644 --- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/DeleteCommandHandler.java +++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/DeleteCommandHandler.java @@ -9,6 +9,7 @@ * * Contributors: * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation + * Benoit Maggi (CEA LIST) benoit.maggi@cea.fr _ Bug 436952 * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec - Bug 436952 * *****************************************************************************/ @@ -63,14 +64,9 @@ public class DeleteCommandHandler extends AbstractCommandHandler implements IHan } // the root of the model can't be deleted! if (current.eContainer() == null) { - try { - // Pages can be deleted even when they are root elements - IPageManager pageManager = ServiceUtilsForEObject.getInstance().getIPageManager(current); - if (pageManager.allPages().contains(current)) { - return true; - } - } catch (ServiceException ex) { - // Cannot retrieve the ServicesRegistry: ignore + // Pages can be deleted even when they are root elements + if (isPage(current)) { + return true; } return false; } @@ -82,6 +78,24 @@ public class DeleteCommandHandler extends AbstractCommandHandler implements IHan } /** + * Return if the parameter is page. + * + * @param current + * @return + */ + protected static boolean isPage(EObject current) { + try { + IPageManager pageManager = ServiceUtilsForEObject.getInstance().getIPageManager(current); + if (pageManager.allPages().contains(current)) { + return true; + } + } catch (ServiceException ex) { + // Cannot retrieve the ServicesRegistry: ignore + } + return false; + } + + /** * <pre> * * Build the delete command for a set of EObject selected in the ModelExplorer. @@ -89,7 +103,7 @@ public class DeleteCommandHandler extends AbstractCommandHandler implements IHan * elements. * @param selectedElements elements to delete * @return the composite deletion command for current selection - * + * * @TODO : Manage possible Diagrams listed in the selection * * </pre> @@ -112,7 +126,7 @@ public class DeleteCommandHandler extends AbstractCommandHandler implements IHan if (provider == null) { continue; } - + // Look for uncontrol mode command TransactionalEditingDomain editingDomain = null; try { @@ -120,12 +134,12 @@ public class DeleteCommandHandler extends AbstractCommandHandler implements IHan } catch (ServiceException e) { Activator.log.error(e); } - if (editingDomain !=null && ControlHelper.isRootControlledObject(selectedEObject)) { + if (editingDomain != null && ControlHelper.isRootControlledObject(selectedEObject)) { ControlModeRequest controlRequest = ControlModeRequest.createUIUncontrolModelRequest(editingDomain, selectedEObject); IControlModeManager controlMng = ControlModeManager.getInstance(); ICommand controlCommand = controlMng.getUncontrolCommand(controlRequest); - gmfCommand = CompositeCommand.compose(gmfCommand, controlCommand); + gmfCommand = CompositeCommand.compose(gmfCommand, controlCommand); } // Retrieve delete command from the Element Edit service @@ -151,7 +165,6 @@ public class DeleteCommandHandler extends AbstractCommandHandler implements IHan return GMFtoEMFCommandWrapper.wrap(gmfCommand.reduce()); } - /** * * @see org.eclipse.papyrus.views.modelexplorer.handler.AbstractCommandHandler#getCommand() |