blob: 970085b7893d5ef07ec9794ee55a5277ea266933 (
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
/*****************************************************************************
* 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.controlmode.commands;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.papyrus.controlmode.helper.ControlCommandHelper;
import org.eclipse.papyrus.controlmode.request.ControlModeRequest;
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
/**
* This command do the basic operation of the control. That is to say move the semantic element to a new resource previously created.
* This resource id got thanks to the request.
*
* @author adaussy
*
*/
public class BasicControlCommand extends AbstractControlCommandRequest {
/**
* @param request
*/
public BasicControlCommand(ControlModeRequest request) {
super("Control command", null, request);
Set<Resource> affectedResources = new HashSet<Resource>();
ControlCommandHelper.getAffectedResourceByControlCommand(request.getTargetObject(), affectedResources);
Collection<IFile> affectedFile = Collections2.transform(affectedResources, new Function<Resource, IFile>() {
public IFile apply(Resource arg0) {
return WorkspaceSynchronizer.getFile(arg0);
}
});
System.out.println(affectedFile);
getAffectedFiles().addAll(affectedFile);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.core.commands.operations.AbstractOperation#canExecute()
*/
@Override
public boolean canExecute() {
return super.canExecute() && getObjectToControl() != null && !getObjectToControl().eIsProxy();
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor,
* org.eclipse.core.runtime.IAdaptable)
*/
@Override
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
ResourceSet currentResourceSet = getRequest().getModelSet();
Resource resource = currentResourceSet.getResource(getNewURI(), false);
if(resource == null) {
throw new ExecutionException("The resource was not created");
}
resource.getContents().add(getObjectToControl());
return CommandResult.newOKCommandResult(resource);
}
/**
* @return the object being controled
*/
public EObject getObjectToControl() {
return getRequest().getTargetObject();
}
/**
* @return
*/
public URI getNewURI() {
return getRequest().getNewURI();
}
}
|