blob: 5c3794911d5c89d1078cba3567c7cf305e916184 (
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
|
/*****************************************************************************
* Copyright (c) 2018 CEA LIST and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.properties.modelelement;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.papyrus.infra.properties.ui.creation.EcorePropertyEditorFactory;
import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory;
import org.eclipse.papyrus.uml.profile.ui.dialogs.ProfileDefinitionDialog;
import org.eclipse.papyrus.uml.tools.util.PapyrusProfileDefinition;
import org.eclipse.swt.widgets.Control;
import org.eclipse.uml2.uml.Profile;
/**
* Property Editor Factory for Profile Definition.
*/
public class ProfileDefinitionValueFactory extends EcorePropertyEditorFactory implements ReferenceValueFactory {
/** The Constant EDIT_DIALOG_TITLE. */
private static final String EDIT_DIALOG_TITLE = "Edit Profile Definition"; //$NON-NLS-1$
/** The profile to define. */
private final Profile profileToDefine;
/**
* Instantiates a new profile definition value factory.
*
* @param profile
* The profile.
* @param referenceIn
* The reference.
*/
public ProfileDefinitionValueFactory(final Profile profile, final EReference referenceIn) {
super(referenceIn);
profileToDefine = profile;
}
/**
* {@inheritDoc}
*
* @see org.eclipse.papyrus.views.properties.creation.EcorePropertyEditorFactory#doCreateObject(org.eclipse.swt.widgets.Control, java.lang.Object)
*/
@Override
protected Object doCreateObject(final Control widget, final Object context) {
Object createdObject = null;
EObject rootProfile = EcoreUtil.getRootContainer(profileToDefine);
if (rootProfile instanceof Profile) {
ProfileDefinitionDialog dialog = new ProfileDefinitionDialog(widget.getShell(), (Profile) rootProfile);
int returnDialog = dialog.open();
if (Dialog.OK == returnDialog) {
createdObject = new PapyrusProfileDefinition(dialog.getPapyrusDefinitionAnnotation(), dialog.saveConstraintInDefinition());
}
}
return createdObject;
}
/**
* {@inheritDoc}
*
* @see org.eclipse.papyrus.views.properties.creation.EcorePropertyEditorFactory#getEditionDialogTitle(java.lang.Object)
*/
@Override
public String getEditionDialogTitle(final Object objectToEdit) {
String dialogTitle = null;
if (objectToEdit instanceof EPackage) {
dialogTitle = EDIT_DIALOG_TITLE;
} else {
dialogTitle = super.getEditionDialogTitle(objectToEdit);
}
return dialogTitle;
}
}
|