diff options
author | Gabriel Pascual | 2014-10-15 07:27:19 +0000 |
---|---|---|
committer | Gabriel Pascual | 2014-12-01 11:28:22 +0000 |
commit | ad0487efb0ac75b7e01df00866a5e0302e7a9590 (patch) | |
tree | 01d73f56dff39144966be0b3de19cf538c39230e /plugins/views | |
parent | 82bb884962e01a57bf27da78fc834d20edbc5e86 (diff) | |
download | org.eclipse.papyrus-ad0487efb0ac75b7e01df00866a5e0302e7a9590.tar.gz org.eclipse.papyrus-ad0487efb0ac75b7e01df00866a5e0302e7a9590.tar.xz org.eclipse.papyrus-ad0487efb0ac75b7e01df00866a5e0302e7a9590.zip |
447025: [Model explorer] impossible to change the order of use casses in
the model explorer
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=447025
- Fix forbidden to change order of use case ( maybe of other semantic
elements)
Change-Id: I319203729aa5a95a686296bfeb929ea3ff631ea0
Signed-off-by: Gabriel Pascual <gabriel.pascual@all4tec.net>
Diffstat (limited to 'plugins/views')
3 files changed, 106 insertions, 69 deletions
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/Messages.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/Messages.java index a43ad3f6266..ff1b1af0397 100644 --- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/Messages.java +++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/Messages.java @@ -1,28 +1,29 @@ -/*****************************************************************************
- * 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:
- * Patrick Tessier (CEA LIST) - Initial API and implementation
- /*****************************************************************************/
-package org.eclipse.papyrus.views.modelexplorer;
-
-import org.eclipse.osgi.util.NLS;
-
-public class Messages extends NLS {
- private static final String BUNDLE_NAME = "org.eclipse.papyrus.views.modelexplorer.messages"; //$NON-NLS-1$
- public static String DoubleClickListener_Error_NoLoadManagerToOpen;
- public static String MoDiscoLabelProvider_ProxyLabel;
- static {
- // initialize resource bundle
- NLS.initializeMessages(BUNDLE_NAME, Messages.class);
- }
-
- private Messages() {
- }
-}
+/***************************************************************************** + * 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: + * Patrick Tessier (CEA LIST) - Initial API and implementation + /*****************************************************************************/ +package org.eclipse.papyrus.views.modelexplorer; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.papyrus.views.modelexplorer.messages"; //$NON-NLS-1$ + public static String DiagramOrderChangeCommand_Label; + public static String DoubleClickListener_Error_NoLoadManagerToOpen; + public static String MoDiscoLabelProvider_ProxyLabel; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/dnd/CommonDropAdapterAssistant.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/dnd/CommonDropAdapterAssistant.java index 7c5a684346c..ba56fdf5cc3 100644 --- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/dnd/CommonDropAdapterAssistant.java +++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/dnd/CommonDropAdapterAssistant.java @@ -9,7 +9,7 @@ * * Contributors: * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation - * + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 447025 *****************************************************************************/ package org.eclipse.papyrus.views.modelexplorer.dnd; @@ -38,12 +38,11 @@ import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.gmf.runtime.common.core.command.ICommand; import org.eclipse.gmf.runtime.emf.type.core.requests.MoveRequest; import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; +import org.eclipse.gmf.runtime.notation.Diagram; import org.eclipse.jface.util.LocalSelectionTransfer; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ViewerDropAdapter; -import org.eclipse.papyrus.commands.CreationCommandRegistry; -import org.eclipse.papyrus.commands.ICreationCommandRegistry; import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper; import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.internal.treeproxy.EObjectTreeElement; import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.internal.treeproxy.EReferenceTreeElement; @@ -109,14 +108,6 @@ public class CommonDropAdapterAssistant extends org.eclipse.ui.navigator.CommonD return commandList; } - /** - * Get the creation command registry to test when diagrams can be created - * - * @return instance - */ - private static ICreationCommandRegistry getCreationCommandRegistry() { - return CreationCommandRegistry.getInstance(org.eclipse.papyrus.infra.core.Activator.PLUGIN_ID); - } /** * get a list that contains command to move a view into a new element @@ -164,7 +155,7 @@ public class CommonDropAdapterAssistant extends org.eclipse.ui.navigator.CommonD protected Resource getTargetNotationResource(EObject targetOwner) { if (targetOwner.eResource() != null && targetOwner.eResource().getResourceSet() instanceof ModelSet) { ModelSet modelSet = (ModelSet) targetOwner.eResource().getResourceSet(); - return modelSet.getAssociatedResource(targetOwner, NotationModel.NOTATION_FILE_EXTENSION); + return modelSet.getAssociatedResource(targetOwner, NotationModel.NOTATION_FILE_EXTENSION, true); } return null; } @@ -185,15 +176,40 @@ public class CommonDropAdapterAssistant extends org.eclipse.ui.navigator.CommonD */ protected List<Command> getOrderChangeCommand(TransactionalEditingDomain domain, EObject targetOwner, EObject objectLocation, EObject newElement, boolean before) { ArrayList<Command> commandList = new ArrayList<Command>(); - ArrayList<EStructuralFeature> possibleEFeatures = new ArrayList<EStructuralFeature>(); - EList<EStructuralFeature> featureList = targetOwner.eClass().getEAllStructuralFeatures(); + // Abort when trying to change order moving the element in one of its children if (EcoreUtil.isAncestor(newElement, targetOwner)) { return Collections.emptyList(); } - // find the feature between childreen and owner + // Sequencing eOject + commandList.addAll(handleEObject(targetOwner, objectLocation, newElement, before)); + + return commandList; + } + + /** + * Handle EObjects. + * + * @param targetOwner + * the target owner + * @param objectLocation + * the object location + * @param newElement + * the new element + * @param before + * the before + * @return the list + */ + private List<Command> handleEObject(final EObject targetOwner, final EObject objectLocation, final EObject newElement, boolean before) { + + // Ordered EObject of the model + ArrayList<EStructuralFeature> possibleEFeatures = new ArrayList<EStructuralFeature>(); + EList<EStructuralFeature> featureList = targetOwner.eClass().getEAllStructuralFeatures(); + List<Command> commandList = new ArrayList<Command>(); + + // Find the feature between children and owner Iterator<EStructuralFeature> iterator = featureList.iterator(); while (iterator.hasNext()) { EStructuralFeature eStructuralFeature = iterator.next(); @@ -211,45 +227,62 @@ public class CommonDropAdapterAssistant extends org.eclipse.ui.navigator.CommonD } } - // create the command + // Create the command Iterator<EStructuralFeature> iteratorFeature = possibleEFeatures.iterator(); while (iteratorFeature.hasNext()) { EStructuralFeature eStructuralFeature = iteratorFeature.next(); - ArrayList<EObject> tmp = new ArrayList<EObject>(); - if (targetOwner.eGet(eStructuralFeature) instanceof Collection<?>) { - // get all element of this efeature + List<EObject> tmp = new ArrayList<EObject>(); + + if (eStructuralFeature.isMany()) { + + // Get all element of this EStructuralFeature tmp.addAll((Collection<EObject>) targetOwner.eGet(eStructuralFeature)); if (!newElement.equals(objectLocation)) { tmp.remove(newElement); // normally tmp.indexOf(objectLocation)!= -1 - // if this the case objectlocation=new element and + // if this the case objectLocation=new element and // it has been removed int indexObject = tmp.indexOf(objectLocation); if (before && indexObject != -1) { - tmp.add(tmp.indexOf(objectLocation), newElement); + tmp.add(indexObject, newElement); } else if (!before && indexObject != -1) { - tmp.add(tmp.indexOf(objectLocation) + 1, newElement); + tmp.add(indexObject + 1, newElement); } } } else { tmp.add(newElement); } + // Get the command from Edit service SetRequest setRequest = new SetRequest(targetOwner, eStructuralFeature, tmp); IElementEditService provider = ElementEditServiceUtils.getCommandProvider(targetOwner); if (provider != null) { // Retrieve delete command from the Element Edit service ICommand command = provider.getEditCommand(setRequest); - if (command != null) { + /* + * Add only the executable command because, if the command cannot be executed, + * it was a bad possible EStructuralFeature which was selected before. + */ + if (command != null && command.canExecute()) { + commandList.add(new GMFtoEMFCommandWrapper(command)); } } } + return commandList; } + /** + * Execute. + * + * @param domain + * the domain + * @param dropCommand + * the drop command + */ protected void execute(EditingDomain domain, Command dropCommand) { domain.getCommandStack().execute(dropCommand); } @@ -369,7 +402,7 @@ public class CommonDropAdapterAssistant extends org.eclipse.ui.navigator.CommonD */ private List<Object> getEditors(EObject context) { try { - return ServiceUtilsForEObject.getInstance().getIPageMngr(context).allPages(); + return ServiceUtilsForEObject.getInstance().getIPageManager(context).allPages(); } catch (ServiceException ex) { return Collections.emptyList(); } @@ -393,8 +426,11 @@ public class CommonDropAdapterAssistant extends org.eclipse.ui.navigator.CommonD if (objectLocation == null) { return result; } - - objectOwner = objectLocation.eContainer(); + if (objectLocation instanceof Diagram) { + objectOwner = ((Diagram) objectLocation).getElement(); + } else { + objectOwner = objectLocation.eContainer(); + } // get Command from the selection ISelection selection = LocalSelectionTransfer.getTransfer().getSelection(); diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/messages.properties b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/messages.properties index 809af86755d..b530b40e3a1 100644 --- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/messages.properties +++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/messages.properties @@ -1,15 +1,15 @@ -##########################################################################################
-# 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:
-# Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
-#
-########################################################################################
-MoDiscoLabelProvider_ProxyLabel=Unreachable {0} in {1}
-DoubleClickListener_Error_NoLoadManagerToOpen=Impossibility to load the page manager
+########################################################################################## +# 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: +# Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation +# +######################################################################################## +MoDiscoLabelProvider_ProxyLabel=Unreachable {0} in {1} +DoubleClickListener_Error_NoLoadManagerToOpen=Impossibility to load the page manager |