Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: cd63d361ca66c5bbf59d7ebaf53685d949a68b2b (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
/*****************************************************************************
 * Copyright (c) 2013, 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:
 *   CEA LIST - Initial API and implementation
 *   Christian W. Damus (CEA) - bug 323802
 *   Christian W. Damus (CEA) - bug 415639
 *
 *****************************************************************************/
package org.eclipse.papyrus.cdo.core.resource;

import java.util.Collections;
import java.util.List;

import org.eclipse.emf.cdo.dawn.transaction.DawnTransactionChangeRecorder;
import org.eclipse.emf.cdo.view.CDOViewInvalidationEvent;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.transaction.NotificationFilter;
import org.eclipse.emf.transaction.ResourceSetChangeEvent;
import org.eclipse.emf.transaction.ResourceSetListener;
import org.eclipse.emf.transaction.Transaction;
import org.eclipse.emf.transaction.TransactionalCommandStack;
import org.eclipse.emf.transaction.impl.TransactionChangeRecorder;
import org.eclipse.emf.transaction.impl.TransactionImpl;
import org.eclipse.papyrus.cdo.internal.core.Activator;
import org.eclipse.papyrus.cdo.internal.core.CDOUtils;
import org.eclipse.papyrus.infra.emf.readonly.PapyrusROTransactionalEditingDomain;

/**
 * This is the CDOAwareTransactionalEditingDomain type. Enjoy.
 */
public class CDOAwareTransactionalEditingDomain extends PapyrusROTransactionalEditingDomain {

	public CDOAwareTransactionalEditingDomain(AdapterFactory adapterFactory, TransactionalCommandStack stack, ResourceSet resourceSet) {
		super(adapterFactory, stack, resourceSet);
	}

	@Override
	protected TransactionChangeRecorder doCreateChangeRecorder(ResourceSet rset) {
		return new DawnTransactionChangeRecorder(this, rset) {

			@Override
			protected void appendNotification(Notification notification) {
				// Append to the transaction first
				super.appendNotification(notification);

				if (!NotificationFilter.READ.matches(notification)) {
					// Check whether we are modifying a read-only object
					assertNotReadOnly(notification.getNotifier());
				} else {
					// Maybe we resolved a cross-resource containment proxy
					handleCrossResourceContainmentProxy(notification);
				}
			}
		};
	}

	protected void fireResourceSetChanged(CDOViewInvalidationEvent event) {
		final ResourceSetListener[] listeners = getPostcommitListeners();
		final Transaction transaction = new TransactionImpl(this, false, Collections.singletonMap(Transaction.OPTION_UNPROTECTED, Boolean.TRUE));

		// TODO: Compute notifications from the revision deltas? Model Explorer
		// doesn't need any, and this is here primarily to kick the explorer.
		final List<Notification> notifications = Collections.emptyList();

		CDOUtils.notify(this, new Runnable() {

			@Override
			public void run() {
				for (ResourceSetListener element : listeners) {
					try {
						element.resourceSetChanged(new ResourceSetChangeEvent(CDOAwareTransactionalEditingDomain.this, transaction, notifications));
					} catch (Exception e) {
						Activator.log.error("Uncaught exception in resource set change listener.", //$NON-NLS-1$
								e);
					}
				}
			}
		});
	}
}

Back to the top