blob: 00f20b716b8de2d174ac81a32a1ec5de4758d9b6 (
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
|
/*****************************************************************************
* Copyright (c) 2013 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:
* Juan Cadavid (CEA LIST) juan.cadavid@cea.fr - Initial API and implementation
*****************************************************************************/
package org.eclipse.papyrus.sysml.modelexplorer.handler;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.UnexecutableCommand;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
import org.eclipse.papyrus.infra.services.edit.commands.ConfigureFeatureCommandFactory;
import org.eclipse.papyrus.infra.services.edit.commands.IConfigureCommandFactory;
import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
import org.eclipse.papyrus.uml.tools.utils.NamedElementUtil;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.UMLPackage;
/**
* <pre>
* Command handler for Problem creation
*
* </pre>
*
* @generated
*/
public class ConstraintBlockParameterHandler extends AbstractSysmlModelExplorerCreateCommandHandler {
/**
* <pre>
* @see org.eclipse.papyrus.uml.service.types.ui.handlers.AbstractCreateCommandHandler#getElementTypeToCreate()
*
* @return the IElementType this handler is supposed to create
*
* </pre>
*
* @generated
*/
@Override
protected IElementType getElementTypeToCreate() {
return UMLElementTypes.PROPERTY;
}
/**
* {@inheritDoc}
*/
@Override
protected Command buildCommand() {
if (getCommandContext() == null) {
return UnexecutableCommand.INSTANCE;
}
EObject container = getCommandContext().getContainer();
EReference reference = getCommandContext().getReference();
if (!(container instanceof Element)) {
return UnexecutableCommand.INSTANCE;
}
IElementEditService provider = ElementEditServiceUtils.getCommandProvider(container);
if (provider == null) {
return UnexecutableCommand.INSTANCE;
}
CreateElementRequest createRequest = null;
if (reference == null) {
createRequest = new CreateElementRequest(container, getElementTypeToCreate());
} else {
createRequest = new CreateElementRequest(container, getElementTypeToCreate(), reference);
}
String name = NamedElementUtil.getDefaultNameWithIncrementFromBase("parameter", ((Element) container).eContents()); //$NON-NLS-1$
createRequest.setParameter(IConfigureCommandFactory.CONFIGURE_COMMAND_FACTORY_ID, new ConfigureFeatureCommandFactory(UMLPackage.eINSTANCE.getNamedElement_Name(), name));
// Retrieve create command from the Element Edit service
ICommand createGMFCommand = provider.getEditCommand(createRequest);
if (createGMFCommand != null) {
Command emfCommand = new org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper(createGMFCommand);
return emfCommand;
}
return UnexecutableCommand.INSTANCE;
}
}
|