blob: 45a2205e36a16e433c914ce41a3d2c3b93dffcba (
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
106
107
108
109
110
|
/*****************************************************************************
* 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.uml.diagram.activity.edit.advices;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.papyrus.uml.diagram.activity.edit.commands.util.ImportUMLPrimitiveTypePackageCommand;
import org.eclipse.papyrus.uml.diagram.activity.edit.commands.util.PinUpdateCommand;
import org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater.PinUpdaterFactory;
import org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater.UpdaterPinUtils;
import org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater.preferences.AutomatedModelCompletionPreferencesInitializer;
import org.eclipse.papyrus.uml.diagram.activity.edit.utils.updater.preferences.IAutomatedModelCompletionPreferencesConstants;
import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.papyrus.uml.tools.utils.PackageUtil;
import org.eclipse.uml2.uml.AddStructuralFeatureValueAction;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.UMLPackage;
/**
*
* Pins of AddStructuralFeatureValueAction should be create and update automatically
* @since 3.0
*
*/
public class AddStructuralFeatureValueActionEditHelperAdvice extends AbstractEditHelperAdvice {
/**
* @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#getAfterConfigureCommand(org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest)
*
* @param request
* @return
*/
@Override
protected ICommand getAfterConfigureCommand(ConfigureRequest request) {
// 1] get the preference for AddStructuralFeatureValueAction
final IPreferenceStore prefStore = Activator.getDefault().getPreferenceStore();
boolean synchronizePin = (prefStore.getString(IAutomatedModelCompletionPreferencesConstants.ADD_STRUCTURAL_FEATURE_VALUE_ACTION_ACCELERATOR).equals(AutomatedModelCompletionPreferencesInitializer.PIN_SYNCHRONIZATION));
// 2] check preference
if (synchronizePin) {
// 3] call the command for the AddStructuralFeatureValueAction
AddStructuralFeatureValueAction addStructuralFeatureValueAction = (AddStructuralFeatureValueAction) request.getElementToConfigure();
if (addStructuralFeatureValueAction != null) {
return new PinUpdateCommand<AddStructuralFeatureValueAction>("Update add structural feature value action pins", PinUpdaterFactory.getInstance().instantiate(addStructuralFeatureValueAction), addStructuralFeatureValueAction); //$NON-NLS-1$
}
}
return null;
}
/**
* @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#getBeforeSetCommand(org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest)
*
* @param request
* @return
*/
@Override
protected ICommand getBeforeConfigureCommand(ConfigureRequest request) {
// 1] get the preference for AddStructuralFeatureValueAction
final IPreferenceStore prefStore = Activator.getDefault().getPreferenceStore();
boolean synchronizePin = (prefStore.getString(IAutomatedModelCompletionPreferencesConstants.ADD_STRUCTURAL_FEATURE_VALUE_ACTION_ACCELERATOR).equals(AutomatedModelCompletionPreferencesInitializer.PIN_SYNCHRONIZATION));
// 2] check preference
if (synchronizePin) {
// 3] call the command to import UML primitive types package
Package root = PackageUtil.getRootPackage((Element) request.getElementToConfigure());
if (!UpdaterPinUtils.isPrimitiveTypeLibraryImported(root)) {
return new ImportUMLPrimitiveTypePackageCommand("Import UML primitive type package", root); //$NON-NLS-1$
}
}
return null;
}
/**
* @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#getAfterSetCommand(org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest)
*
* @param request
* @return
*/
@Override
protected ICommand getAfterSetCommand(SetRequest request) {
// 1] check if the setFeature is StructuralFeature
if (request.getFeature().equals(UMLPackage.eINSTANCE.getStructuralFeatureAction_StructuralFeature())) {
// 2] get the preference for AddStructuralFeatureValueAction
final IPreferenceStore prefStore = Activator.getDefault().getPreferenceStore();
boolean synchronizePin = (prefStore.getString(IAutomatedModelCompletionPreferencesConstants.ADD_STRUCTURAL_FEATURE_VALUE_ACTION_ACCELERATOR).equals(AutomatedModelCompletionPreferencesInitializer.PIN_SYNCHRONIZATION));
// 3] check preference
if (synchronizePin) {
// 4] call the command for the AddStructuralFeatureValueAction
AddStructuralFeatureValueAction addStructuralFeatureValueAction = (AddStructuralFeatureValueAction) request.getElementToEdit();
if (addStructuralFeatureValueAction != null) {
return new PinUpdateCommand<AddStructuralFeatureValueAction>("Update add structural feature value action pins", PinUpdaterFactory.getInstance().instantiate(addStructuralFeatureValueAction), addStructuralFeatureValueAction); //$NON-NLS-1$
}
}
}
return null;
}
}
|