Lines 11-19
Link Here
|
11 |
|
11 |
|
12 |
package org.eclipse.gmf.runtime.diagram.core; |
12 |
package org.eclipse.gmf.runtime.diagram.core; |
13 |
|
13 |
|
|
|
14 |
import java.util.ArrayList; |
15 |
import java.util.HashMap; |
16 |
import java.util.List; |
17 |
import java.util.Map; |
18 |
|
19 |
import org.eclipse.core.commands.operations.IOperationHistory; |
20 |
import org.eclipse.core.commands.operations.OperationHistoryFactory; |
21 |
import org.eclipse.emf.common.notify.AdapterFactory; |
22 |
import org.eclipse.emf.ecore.resource.ResourceSet; |
23 |
import org.eclipse.emf.edit.provider.ComposedAdapterFactory; |
24 |
import org.eclipse.emf.transaction.ResourceSetChangeEvent; |
25 |
import org.eclipse.emf.transaction.ResourceSetListener; |
26 |
import org.eclipse.emf.transaction.RollbackException; |
27 |
import org.eclipse.emf.transaction.Transaction; |
28 |
import org.eclipse.emf.transaction.TransactionalCommandStack; |
14 |
import org.eclipse.emf.transaction.TransactionalEditingDomain; |
29 |
import org.eclipse.emf.transaction.TransactionalEditingDomain; |
|
|
30 |
import org.eclipse.emf.transaction.impl.FilterManager; |
31 |
import org.eclipse.emf.transaction.impl.InternalTransaction; |
32 |
import org.eclipse.emf.transaction.impl.ReadWriteValidatorImpl; |
33 |
import org.eclipse.emf.transaction.impl.TransactionValidator; |
34 |
import org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl; |
35 |
import org.eclipse.emf.transaction.util.CompositeChangeDescription; |
15 |
import org.eclipse.emf.workspace.WorkspaceEditingDomainFactory; |
36 |
import org.eclipse.emf.workspace.WorkspaceEditingDomainFactory; |
|
|
37 |
import org.eclipse.emf.workspace.impl.WorkspaceCommandStackImpl; |
16 |
import org.eclipse.gmf.runtime.diagram.core.internal.listener.NotationSemProc; |
38 |
import org.eclipse.gmf.runtime.diagram.core.internal.listener.NotationSemProc; |
|
|
39 |
import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker; |
17 |
import org.eclipse.gmf.runtime.emf.core.GMFEditingDomainFactory; |
40 |
import org.eclipse.gmf.runtime.emf.core.GMFEditingDomainFactory; |
18 |
|
41 |
|
19 |
|
42 |
|
Lines 21-33
Link Here
|
21 |
* Factory for {@link TransactionalEditingDomain}s that are properly configured |
44 |
* Factory for {@link TransactionalEditingDomain}s that are properly configured |
22 |
* to support a GMF diagram application. This factory should be preferred over |
45 |
* to support a GMF diagram application. This factory should be preferred over |
23 |
* the {@link GMFEditingDomainFactory} because it attaches a listener required |
46 |
* the {@link GMFEditingDomainFactory} because it attaches a listener required |
24 |
* to update the notation model after changes to the semantic model. |
47 |
* to update the notation model after changes to the semantic model. Also, it |
|
|
48 |
* handles special use cases involving the DiagramEventBroker. |
25 |
* |
49 |
* |
26 |
* @author cmahoney |
50 |
* @author cmahoney |
27 |
*/ |
51 |
*/ |
28 |
public class DiagramEditingDomainFactory |
52 |
public class DiagramEditingDomainFactory |
29 |
extends GMFEditingDomainFactory { |
53 |
extends GMFEditingDomainFactory { |
|
|
54 |
|
55 |
private static class DiagramEditingDomain extends TransactionalEditingDomainImpl { |
56 |
// The following variable acts as a special latch for the DiagramEventBroker |
57 |
// listener so that we can allow it to execute in a write transaction context |
58 |
// while handling a post-commit event. |
59 |
private InternalTransaction originatingTransaction = null; |
60 |
private DiagramEventBroker deb = null; |
61 |
|
62 |
public void addResourceSetListener(ResourceSetListener l) { |
63 |
if (l.getClass() == DiagramEventBroker.class) { |
64 |
assert deb == null; |
65 |
deb = (DiagramEventBroker)l; |
66 |
} |
67 |
|
68 |
super.addResourceSetListener(l); |
69 |
} |
70 |
|
71 |
public void removeResourceSetListener(ResourceSetListener l) { |
72 |
if (l.getClass() == DiagramEventBroker.class) { |
73 |
assert deb != null; |
74 |
deb = null; |
75 |
} |
76 |
|
77 |
super.removeResourceSetListener(l); |
78 |
} |
79 |
|
80 |
public DiagramEditingDomain(AdapterFactory adapterFactory, ResourceSet resourceSet) { |
81 |
super(adapterFactory, resourceSet); |
82 |
} |
83 |
|
84 |
public DiagramEditingDomain(AdapterFactory adapterFactory, TransactionalCommandStack stack, ResourceSet resourceSet) { |
85 |
super(adapterFactory, stack, resourceSet); |
86 |
} |
87 |
|
88 |
public DiagramEditingDomain(AdapterFactory adapterFactory, TransactionalCommandStack stack) { |
89 |
super(adapterFactory, stack); |
90 |
} |
30 |
|
91 |
|
|
|
92 |
public DiagramEditingDomain(AdapterFactory adapterFactory) { |
93 |
super(adapterFactory); |
94 |
} |
95 |
|
96 |
protected void postcommit(InternalTransaction tx) { |
97 |
try { |
98 |
List notifications = getValidator().getNotificationsForPostcommit(tx); |
99 |
|
100 |
if (deb != null && notifications != null && !notifications.isEmpty()) { |
101 |
TransactionValidator originalValidator = null; |
102 |
|
103 |
// Set the latch if it has not yet been set |
104 |
if (originatingTransaction == null) { |
105 |
originatingTransaction = tx; |
106 |
originalValidator = getValidator(); |
107 |
setValidator(new ReadWriteValidatorImpl()); |
108 |
} else { |
109 |
// In this case we must copy over the notifications and change |
110 |
// descriptions to the originatingTransaction. |
111 |
((CompositeChangeDescription)originatingTransaction.getChangeDescription()).add(tx.getChangeDescription()); |
112 |
originatingTransaction.getNotifications().addAll(notifications); |
113 |
} |
114 |
|
115 |
try { |
116 |
ArrayList cache = new ArrayList(notifications.size()); |
117 |
|
118 |
List filtered = FilterManager.getInstance().select( |
119 |
notifications, |
120 |
deb.getFilter(), |
121 |
cache); |
122 |
|
123 |
HashMap options = new HashMap(originatingTransaction.getOptions()); |
124 |
options.put(Transaction.OPTION_NO_UNDO, Boolean.FALSE); |
125 |
InternalTransaction newTx = startTransaction(false, options); |
126 |
deb.resourceSetChanged( |
127 |
new ResourceSetChangeEvent( |
128 |
this, |
129 |
tx, |
130 |
filtered)); |
131 |
|
132 |
newTx.commit(); |
133 |
} catch (RollbackException e) { |
134 |
// Do nothing in the rollback case, we have no change descriptions |
135 |
// or notifications to propagate. |
136 |
} finally { |
137 |
// Undo the latch if we are top-most in the recursion. |
138 |
if (originatingTransaction == tx) { |
139 |
originatingTransaction = null; |
140 |
getValidator().dispose(); |
141 |
setValidator(originalValidator); |
142 |
} |
143 |
} |
144 |
} |
145 |
} catch (InterruptedException e) { |
146 |
// Simply fall-through in this case and allow the post commit listeners |
147 |
// to be notified. |
148 |
} |
149 |
|
150 |
// We will only call super on the top-most in the recursion. |
151 |
if (originatingTransaction == null) { |
152 |
super.postcommit(tx); |
153 |
} |
154 |
} |
155 |
} |
156 |
|
31 |
/** |
157 |
/** |
32 |
* The single shared instance of the GMF diagram editing domain factory. |
158 |
* The single shared instance of the GMF diagram editing domain factory. |
33 |
*/ |
159 |
*/ |
Lines 50-53
Link Here
|
50 |
domain.addResourceSetListener(new NotationSemProc()); |
176 |
domain.addResourceSetListener(new NotationSemProc()); |
51 |
} |
177 |
} |
52 |
|
178 |
|
|
|
179 |
public TransactionalEditingDomain createEditingDomain() { |
180 |
TransactionalEditingDomain result = createEditingDomain(OperationHistoryFactory.getOperationHistory()); |
181 |
configure(result); |
182 |
return result; |
183 |
} |
184 |
|
185 |
public TransactionalEditingDomain createEditingDomain(IOperationHistory history) { |
186 |
WorkspaceCommandStackImpl stack = new WorkspaceCommandStackImpl(history); |
187 |
|
188 |
TransactionalEditingDomain result = new DiagramEditingDomain( |
189 |
new ComposedAdapterFactory( |
190 |
ComposedAdapterFactory.Descriptor.Registry.INSTANCE), |
191 |
stack); |
192 |
|
193 |
mapResourceSet(result); |
194 |
|
195 |
configure(result); |
196 |
return result; |
197 |
} |
198 |
|
199 |
public TransactionalEditingDomain createEditingDomain(ResourceSet rset) { |
200 |
TransactionalEditingDomain result = createEditingDomain( |
201 |
rset, |
202 |
OperationHistoryFactory.getOperationHistory()); |
203 |
configure(result); |
204 |
return result; |
205 |
} |
206 |
|
207 |
public TransactionalEditingDomain createEditingDomain(ResourceSet rset, IOperationHistory history) { |
208 |
WorkspaceCommandStackImpl stack = new WorkspaceCommandStackImpl(history); |
209 |
|
210 |
TransactionalEditingDomain result = new DiagramEditingDomain( |
211 |
new ComposedAdapterFactory( |
212 |
ComposedAdapterFactory.Descriptor.Registry.INSTANCE), |
213 |
stack, |
214 |
rset); |
215 |
|
216 |
mapResourceSet(result); |
217 |
configure(result); |
218 |
return result; |
219 |
} |
53 |
} |
220 |
} |