blob: 24e4bd993ec00e553eef046223674192b60f76d9 (
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
|
/*****************************************************************************
* 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:
*
* Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.service.types.helper;
import java.util.Map;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
import org.eclipse.papyrus.infra.gmfdiag.common.helper.DefaultEditHelper;
import org.eclipse.papyrus.infra.services.edit.commands.IConfigureCommandFactory;
import org.eclipse.papyrus.uml.service.types.command.UnapplyAllStereotypesCommand;
import org.eclipse.uml2.uml.Element;
/**
* <pre>
*
* Edit helper class for {@link Element}
*
* Expected behavior:
* - Removes any stereotype application before deletion
*
* The configure command allows contributions provided by the request parameters.
* </pre>
*/
public class ElementEditHelper extends DefaultEditHelper {
/**
* {@inheritDoc}
*/
@Override
protected ICommand getConfigureCommand(ConfigureRequest req) {
if (req.getParameter(IConfigureCommandFactory.CONFIGURE_COMMAND_FACTORY_ID) != null) {
IConfigureCommandFactory factory = (IConfigureCommandFactory) req.getParameter(IConfigureCommandFactory.CONFIGURE_COMMAND_FACTORY_ID);
return factory.create(req);
}
return super.getConfigureCommand(req);
}
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
protected Map<EClass, EReference> getDefaultContainmentFeatures() {
return (Map<EClass, EReference>) super.getDefaultContainmentFeatures();
}
/**
* {@inheritDoc}
*/
@Override
protected ICommand getDestroyElementCommand(DestroyElementRequest req) {
// Default destroy command
ICommand destroyCommand = super.getDestroyElementCommand(req);
// Stereotype application remove command
ICommand removeStereotypeCommand = null;
// Prepare stereotype application remove command
EObject elementToDestroy = req.getElementToDestroy();
if (elementToDestroy instanceof Element) {
removeStereotypeCommand = new UnapplyAllStereotypesCommand(req.getEditingDomain(), req.getLabel(), (Element) elementToDestroy);
}
// Compose both commands
destroyCommand = CompositeCommand.compose(removeStereotypeCommand, destroyCommand);
if (destroyCommand != null) {
destroyCommand = destroyCommand.reduce();
}
return destroyCommand;
}
}
|