blob: 776c0bcd66bedf179fe244693bf093e5bde2508a (
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
|
/*****************************************************************************
* Copyright (c) 2016 CEA LIST 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:
* CEA LIST - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.sysml.propertylifecycle.processors;
import org.eclipse.emf.ecore.EStructuralFeature;
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.AbstractEditCommandRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
import org.eclipse.papyrus.propertylifecycle.commands.LifecycleSetCommand;
import org.eclipse.papyrus.propertylifecycle.messages.Messages;
import org.eclipse.papyrus.propertylifecycle.utils.CommandValueProcessor;
import org.eclipse.papyrus.sysml.portandflows.PortandflowsPackage;
import org.eclipse.papyrus.uml.tools.utils.NamedElementUtil;
import org.eclipse.uml2.uml.NamedElement;
/**
*
*/
public class FlowPortProcessor implements CommandValueProcessor {
@Override
public ICommand setValueFromRequest(String featureLabel, boolean isImmutable, AbstractEditCommandRequest request) {
return setName(request);
}
public FlowPortProcessor() {
}
public ICommand setName(AbstractEditCommandRequest request) {
ICommand gmfCommand = null;
if (request instanceof ConfigureRequest) {
ConfigureRequest confRequest = (ConfigureRequest) request;
NamedElement element = (NamedElement) confRequest.getElementToConfigure();
EStructuralFeature feature = element.eClass().getEStructuralFeature(Messages.FEATURELABEL_NAME);
if (element != null && feature != null) {
// Set default name
String initializedName = NamedElementUtil.getDefaultNameWithIncrementFromBase(PortandflowsPackage.eINSTANCE.getFlowPort().getName().toLowerCase(), element.eContainer().eContents());
LifecycleSetCommand setCommand = new LifecycleSetCommand("FlowPort_SetName", element, feature, initializedName);
gmfCommand = CompositeCommand.compose(gmfCommand, setCommand);
}
}
return gmfCommand;
}
}
|