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
|
/*****************************************************************************
* Copyright (c) 2011, 2014 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:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
* Christian W. Damus (CEA) - bug 417409
*
*****************************************************************************/
package org.eclipse.papyrus.uml.properties.widgets;
import org.eclipse.core.databinding.observable.ChangeEvent;
import org.eclipse.core.databinding.observable.IChangeListener;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.widgets.editors.AbstractEditor;
import org.eclipse.papyrus.uml.profile.tree.objects.StereotypedElementTreeObject;
import org.eclipse.papyrus.uml.properties.modelelement.StereotypeApplicationModelElement;
import org.eclipse.papyrus.uml.properties.profile.ui.compositeforview.AppliedStereotypeCompositeWithView;
import org.eclipse.papyrus.views.properties.modelelement.ModelElement;
import org.eclipse.papyrus.views.properties.widgets.AbstractPropertyEditor;
import org.eclipse.papyrus.views.properties.widgets.layout.PropertiesLayout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.uml2.uml.Element;
public class StereotypeApplication extends AbstractPropertyEditor {
private AppliedStereotypeCompositeWithView stereotypeComposite;
private Composite self;
public StereotypeApplication(Composite parent, int style) {
self = new Composite(parent, style);
self.setLayout(new PropertiesLayout(2, true));
int heightHint = 200;
stereotypeComposite = new AppliedStereotypeCompositeWithView(self);
stereotypeComposite.createContent(self, AbstractEditor.factory);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
data.heightHint = heightHint;
stereotypeComposite.setLayoutData(data);
StereotypePropertyEditor propertyEditor = new StereotypePropertyEditor(self, style, stereotypeComposite);
data = new GridData(SWT.FILL, SWT.FILL, true, false);
data.heightHint = heightHint;
propertyEditor.setLayoutData(data);
stereotypeComposite.setPropertySelectionChangeListener(propertyEditor);
}
@Override
protected void doBinding() {
// No Databinding here ; the AppliedStereotypeCompositeWithView is responsible
// for editing the data
ModelElement element = input.getModelElement(propertyPath);
if(element instanceof StereotypeApplicationModelElement) {
internalDoBinding();
input.getObservable(propertyPath).addChangeListener(new IChangeListener() {
public void handleChange(ChangeEvent event) {
// re-do the injection into the stereotype composite because the
// underlying model element selection may have been changed
internalDoBinding();
}
});
}
}
protected void internalDoBinding() {
ModelElement element = input.getModelElement(propertyPath);
if(element instanceof StereotypeApplicationModelElement) {
StereotypeApplicationModelElement modelElement = (StereotypeApplicationModelElement)element;
View diagramElement = (View)modelElement.getGraphicalElement();
//EditPart editPart = ((StereotypeApplicationModelElement)element).getEditPart();
final Element umlElement = modelElement.getUMLElement();
if(stereotypeComposite.getElement() != umlElement) {
stereotypeComposite.setElement(umlElement);
stereotypeComposite.setInput(new StereotypedElementTreeObject(umlElement));
}
stereotypeComposite.setDiagramElement(diagramElement);
stereotypeComposite.refresh();
}
}
}
|