blob: 81f52d60ea212d428e5afdab921c731b6beedf55 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
/*****************************************************************************
* 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.Collections;
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.emf.ecore.resource.Resource;
import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
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.uml2.uml.Package;
/**
* Command used to move Profile application to new resource
*
* @author adaussy
*
*/
public class MoveProfileApplicationCommand extends AbstractControlCommand {
public MoveProfileApplicationCommand(ControlModeRequest request) {
super("Move stereotype application to new resource", Collections.singletonList(WorkspaceSynchronizer.getFile(request.getTargetObject().eContainer().eResource())), request);
Assert.isLegal(request.getTargetObject() instanceof Package);
}
@Override
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
Package packageUncontroled = (Package) getRequest().getTargetObject();
Resource sourceResource = packageUncontroled.eContainer().eResource();
Resource targetResource = getRequest().getTargetResource(getRequest().getNewURI().fileExtension());
if (targetResource == null) {
return CommandResult.newErrorCommandResult("Unable to retreive target resource");
}
ProfileApplicationHelper.nestedRelocateStereotypeApplications(packageUncontroled, sourceResource, targetResource);
return CommandResult.newOKCommandResult();
}
}
|