diff options
author | Gabriel Pascual | 2015-03-09 16:40:23 +0000 |
---|---|---|
committer | Gabriel Pascual | 2015-03-09 16:50:30 +0000 |
commit | ccee23a1ee4bc6e5e5846a644abd814d1f9f7581 (patch) | |
tree | 3db8aa6d084ddba151dd69f7feaf3e5c97996eb5 /plugins/uml/org.eclipse.papyrus.uml.controlmode.profile/src | |
parent | d485df9ba4f2806f5586e991287b23825bf9c976 (diff) | |
download | org.eclipse.papyrus-ccee23a1ee4bc6e5e5846a644abd814d1f9f7581.tar.gz org.eclipse.papyrus-ccee23a1ee4bc6e5e5846a644abd814d1f9f7581.tar.xz org.eclipse.papyrus-ccee23a1ee4bc6e5e5846a644abd814d1f9f7581.zip |
Bug 460435: [Submodel] Reintegrate submodel does not remove the submodel
https://bugs.eclipse.org/bugs/show_bug.cgi?id=460435
- Change the way to retrieve source's resource
Change-Id: Idb68b87bf92b6ac4759f038122450d5de0b420ca
Signed-off-by: Gabriel Pascual <gabriel.pascual@all4tec.net>
Diffstat (limited to 'plugins/uml/org.eclipse.papyrus.uml.controlmode.profile/src')
-rw-r--r-- | plugins/uml/org.eclipse.papyrus.uml.controlmode.profile/src/org/eclipse/papyrus/uml/controlmode/profile/commands/MoveStereotypeApplicationToControlResource.java | 173 |
1 files changed, 102 insertions, 71 deletions
diff --git a/plugins/uml/org.eclipse.papyrus.uml.controlmode.profile/src/org/eclipse/papyrus/uml/controlmode/profile/commands/MoveStereotypeApplicationToControlResource.java b/plugins/uml/org.eclipse.papyrus.uml.controlmode.profile/src/org/eclipse/papyrus/uml/controlmode/profile/commands/MoveStereotypeApplicationToControlResource.java index d1973f4df83..c8d0b136d57 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.controlmode.profile/src/org/eclipse/papyrus/uml/controlmode/profile/commands/MoveStereotypeApplicationToControlResource.java +++ b/plugins/uml/org.eclipse.papyrus.uml.controlmode.profile/src/org/eclipse/papyrus/uml/controlmode/profile/commands/MoveStereotypeApplicationToControlResource.java @@ -1,72 +1,103 @@ -/*****************************************************************************
- * Copyright (c) 2013, 2014 Atos, Christian W. Damus, 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 - bug 399859
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.controlmode.profile.commands;
-
-import java.util.List;
-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.common.util.TreeIterator;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest;
-import org.eclipse.papyrus.infra.services.controlmode.commands.AbstractControlCommand;
-import org.eclipse.papyrus.uml.controlmode.profile.helpers.ProfileApplicationHelper;
-import org.eclipse.papyrus.uml.tools.model.UmlModel;
-import org.eclipse.uml2.uml.Element;
-
-import com.google.common.collect.Sets;
-
-/**
- * Command to move stereotype application to new resource when controling or uncontroling elements
- *
- * @author adaussy
- *
- */
-public final class MoveStereotypeApplicationToControlResource extends AbstractControlCommand {
-
-
- @SuppressWarnings("rawtypes")
- public MoveStereotypeApplicationToControlResource(List affectedFiles, ControlModeRequest request) {
- super("Move stereotype application", affectedFiles, request);
- }
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- Element elem = (Element) getRequest().getTargetObject();
- Set<Element> elements = Sets.newHashSet(elem);
- TreeIterator<Object> contents = EcoreUtil.getAllProperContents(elem, true);
- while (contents.hasNext()) {
- EObject eObject = (EObject) contents.next();
- if (eObject instanceof Element) {
- elements.add((Element) eObject);
- }
- }
-
- Resource sourceResource = elem.eContainer().eResource();
- Resource targetResource = getRequest().getTargetResource(UmlModel.UML_FILE_EXTENSION);
- if (targetResource == null) {
- return createNewControlCommandError("No uml resource created");//
- }
- for (Element e : elements) {
- ProfileApplicationHelper.relocateStereotypeApplications(e, sourceResource, targetResource);
- }
- return CommandResult.newOKCommandResult();
-
- }
+/***************************************************************************** + * Copyright (c) 2013, 2014 Atos, Christian W. Damus, 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 - bug 399859 + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - bug 460435 + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.controlmode.profile.commands; + +import java.util.List; +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.common.util.TreeIterator; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.gmf.runtime.common.core.command.CommandResult; +import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest; +import org.eclipse.papyrus.infra.services.controlmode.commands.AbstractControlCommand; +import org.eclipse.papyrus.uml.controlmode.profile.helpers.ProfileApplicationHelper; +import org.eclipse.papyrus.uml.tools.model.UmlModel; +import org.eclipse.uml2.uml.Element; + +import com.google.common.collect.Sets; + +/** + * Command to move stereotype application to new resource when controling or uncontroling elements + * + * @author adaussy + * + */ +public final class MoveStereotypeApplicationToControlResource extends AbstractControlCommand { + + /** The Constant UNKNOWN_TARGET_RESOURCE_ERROR. */ + private static final String UNKNOWN_TARGET_RESOURCE_ERROR = "Target resource is unknown"; + + /** The Constant COMMAND_LABEL. */ + private static final String COMMAND_LABEL = "Move stereotype application"; + + /** + * Instantiates a new move stereotype application to control resource. + * + * @param affectedFiles + * the affected files + * @param request + * the request + */ + @SuppressWarnings("rawtypes") + public MoveStereotypeApplicationToControlResource(List affectedFiles, ControlModeRequest request) { + super(COMMAND_LABEL, affectedFiles, request); + } + + /** + * @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 { + + // Build a set with target element and its related contents + Element targetElement = (Element) getRequest().getTargetObject(); + Set<Element> targetElementsSet = Sets.newHashSet(targetElement); + + // Retrieve related contents + TreeIterator<Object> contents = EcoreUtil.getAllProperContents(targetElement, true); + while (contents.hasNext()) { + EObject currentElement = (EObject) contents.next(); + if (currentElement instanceof Element) { + targetElementsSet.add((Element) currentElement); + } + } + + // Retrieve related resources by control command + Resource sourceResource = getRequest().getModelSet().getAssociatedResource(targetElement, UmlModel.UML_FILE_EXTENSION, false); + Resource targetResource = getRequest().getTargetResource(UmlModel.UML_FILE_EXTENSION); + + if (targetResource == null) { + return createNewControlCommandError(UNKNOWN_TARGET_RESOURCE_ERROR); + } + + // Relocate all target elements + for (Element currentElement : targetElementsSet) { + ProfileApplicationHelper.relocateStereotypeApplications(currentElement, sourceResource, targetResource); + } + + return CommandResult.newOKCommandResult(); + + } }
\ No newline at end of file |