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
|
/*****************************************************************************
* Copyright (c) 2013, 2014 CEA 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:
* Soyatec - Initial API and implementation
* Christian W. Damus (CEA) - bug 417409
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.util;
import org.eclipse.core.databinding.observable.IObservable;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.emf.commands.CreateEAnnotationCommand;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.gmfdiag.common.helper.NotationHelper;
import org.eclipse.papyrus.infra.properties.contexts.DataContextElement;
import org.eclipse.papyrus.infra.ui.emf.databinding.AnnotationObservableValue;
import org.eclipse.papyrus.views.properties.Activator;
import org.eclipse.papyrus.views.properties.modelelement.AnnotationModelElement;
import org.eclipse.papyrus.views.properties.modelelement.AnnotationModelElementFactory;
/**
* @author Jin Liu (jin.liu@soyatec.com)
*/
public class GateModelElementFactory extends AnnotationModelElementFactory {
private static final String GATE_SHOW_NAME = "showName";
@Override
protected AnnotationModelElement doCreateFromSource(Object sourceElement, DataContextElement context) {
View source = NotationHelper.findView(sourceElement);
if (source == null) {
Activator.log.warn("Unable to resolve the selected element to an EObject"); //$NON-NLS-1$
return null;
}
EditingDomain domain = EMFHelper.resolveEditingDomain(source);
return new AnnotationModelElement(source, domain, GATE_SHOW_NAME) {
@Override
public IObservable doGetObservable(String propertyPath) {
return new AnnotationObservableValue(source, domain, GATE_SHOW_NAME, GATE_SHOW_NAME) {
@Override
protected Command getCommand(final Object value) {
return new CreateEAnnotationCommand((TransactionalEditingDomain) domain, source, GATE_SHOW_NAME) {
@Override
protected void doExecute() {
EAnnotation annotation = createEAnnotation();
replaceEannotation(annotation, getObject());
replaceEntry(annotation, GATE_SHOW_NAME, value == null ? "" : value.toString());
}
};
}
@Override
protected Object doGetValue() {
Object value = super.doGetValue();
if (value == null) {
// By default, return true.
return "true";
}
return value;
}
};
}
};
}
public static final boolean isShowNameChanged(Notification msg) {
if (msg == null || !(msg.getNewValue() instanceof EAnnotation)) {
return false;
}
EAnnotation anno = (EAnnotation) msg.getNewValue();
return GATE_SHOW_NAME.equals(anno.getSource());
}
public static final boolean isShowName(View view) {
if (view != null) {
EAnnotation anno = view.getEAnnotation(GATE_SHOW_NAME);
if (anno != null) {
return !"false".equalsIgnoreCase(anno.getDetails().get(GATE_SHOW_NAME));
}
}
return true;
}
}
|