blob: e5d238572c44f3f85e595237703a822db921bcd3 (
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/*******************************************************************************
* Copyright (c) 2013 THALES GLOBAL SERVICES.
* 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:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.diagram.ui.internal.refresh.listeners;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CompoundCommand;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.util.ECrossReferenceAdapter;
import org.eclipse.emf.transaction.NotificationFilter;
import org.eclipse.emf.transaction.ResourceSetChangeEvent;
import org.eclipse.emf.transaction.ResourceSetListenerImpl;
import org.eclipse.emf.transaction.RollbackException;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.notation.Edge;
import org.eclipse.sirius.diagram.DEdge;
import org.eclipse.sirius.diagram.DiagramPackage;
import org.eclipse.sirius.diagram.EdgeStyle;
import org.eclipse.sirius.diagram.ui.business.api.view.SiriusGMFHelper;
import org.eclipse.sirius.diagram.ui.tools.internal.commands.UpdateGMFEdgeStyleCommand;
/**
* This listener is in charge of updating the GMF informations related to Edge
* styles (e.g. routing style) when the {@link EdgeStyle} changes.
*
* @author <a href="mailto:alex.lagarde@obeo.fr">Alex Lagarde</a>
*
*/
public class EdgeStyleUpdater extends ResourceSetListenerImpl {
/**
* The Viewpoint features that, when modified, should trigger an update of
* GMF features.
*/
private static final NotificationFilter LISTENED_FEATURES = NotificationFilter.NOT_TOUCH.and(NotificationFilter.createFeatureFilter(DiagramPackage.eINSTANCE.getDEdge_OwnedStyle()).or(
NotificationFilter.createFeatureFilter(DiagramPackage.eINSTANCE.getEdgeStyle_RoutingStyle())));
/**
* The viewpoint cross reference used to get GMF elements from
* DDiagramElements.
*/
private ECrossReferenceAdapter crossReference;
/**
* Default constructor.
*
* @param domain
* The {@link TransactionalEditingDomain} to listen.
* @param crossReference
* The viewpoint cross reference used to get GMF elements from
* DDiagramElements.
*/
public EdgeStyleUpdater(TransactionalEditingDomain domain, ECrossReferenceAdapter crossReference) {
super(LISTENED_FEATURES);
domain.addResourceSetListener(this);
this.crossReference = crossReference;
}
/**
*
* {@inheritDoc}
*
* @see org.eclipse.emf.transaction.ResourceSetListenerImpl#isPrecommitOnly()
*/
@Override
public boolean isPrecommitOnly() {
return true;
}
/**
*
* {@inheritDoc}
*
* @see org.eclipse.emf.transaction.ResourceSetListenerImpl#isAggregatePrecommitListener()
*/
@Override
public boolean isAggregatePrecommitListener() {
return true;
}
/**
* {@inheritDoc}
*/
@Override
public Command transactionAboutToCommit(final ResourceSetChangeEvent event) throws RollbackException {
CompoundCommand cc = new CompoundCommand();
for (Notification notification : event.getNotifications()) {
EdgeStyle viewpointEdgeStyle = null;
Edge gmfEdge = null;
// If the notification indicates:
// - a new edge style
if (notification.getNotifier() instanceof DEdge && notification.getNewValue() instanceof EdgeStyle) {
viewpointEdgeStyle = (EdgeStyle) notification.getNewValue();
gmfEdge = SiriusGMFHelper.getGmfEdge((DEdge) notification.getNotifier(), crossReference);
}
// - a change of EdgeStyle
else if (notification.getNotifier() instanceof EdgeStyle && DiagramPackage.eINSTANCE.getEdgeStyle_RoutingStyle().equals(notification.getFeature())) {
viewpointEdgeStyle = (EdgeStyle) notification.getNotifier();
gmfEdge = SiriusGMFHelper.getGmfEdge((DEdge) viewpointEdgeStyle.eContainer(), crossReference);
}
// Propagate change to GMF
if (gmfEdge != null && viewpointEdgeStyle != null) {
cc.append(new UpdateGMFEdgeStyleCommand(getTarget(), gmfEdge, viewpointEdgeStyle));
}
}
return cc;
}
/**
* Dispose this listener.
*/
public void dispose() {
if (getTarget() != null) {
getTarget().removeResourceSetListener(this);
}
crossReference = null;
}
}
|