blob: 259c2332439f3775e9180a6170f08b3ae461a01c (
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
|
/*****************************************************************************
* Copyright (c) 2010 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:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.profile.custom.commands;
import java.util.Collections;
import java.util.List;
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.transaction.TransactionalEditingDomain;
import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
import org.eclipse.papyrus.uml.profile.definition.PapyrusDefinitionAnnotation;
import org.eclipse.papyrus.uml.profile.definition.ProfileRedefinition;
import org.eclipse.papyrus.uml.tools.utils.PackageUtil;
import org.eclipse.uml2.uml.Profile;
/**
* This command is used to define a profile
*
* @author VL222926
*
*/
public class DefineProfileCommand extends AbstractTransactionalCommand {
/**
* the {@link PapyrusDefinitionAnnotation}
*/
private PapyrusDefinitionAnnotation papyrusAnnotation;
/**
* the profile to define
*/
private Profile rootProfile;
/**
*
* Constructor.
*
* @param domain
* @param papyrusAnnotation
* @param rootProfile
* @param viewer
*/
public DefineProfileCommand(TransactionalEditingDomain domain, PapyrusDefinitionAnnotation papyrusAnnotation, Profile rootProfile) {
super(domain, "DefineProfileCommand", null); //$NON-NLS-1$
this.rootProfile = rootProfile;
this.papyrusAnnotation = papyrusAnnotation;
}
/**
*
*
* @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 {
PackageUtil.defineProfiles(rootProfile);
try {
ProfileRedefinition.redefineProfile(rootProfile, papyrusAnnotation);
ProfileRedefinition.cleanProfile(rootProfile);
} catch (Exception e) {
e.printStackTrace();
}
setResult(CommandResult.newOKCommandResult());
return CommandResult.newOKCommandResult();
}
/**
*
* @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#getAffectedFiles()
*
* @return
*/
@Override
public List<IFile> getAffectedFiles() {
IFile f = WorkspaceSynchronizer.getFile(rootProfile.eResource());
return f != null ? Collections.<IFile> singletonList(f) : Collections.<IFile> emptyList();
}
}
|