Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6cdc93283a8157823c830643ebe0accbee17471d (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
/**
 * Copyright (c) 2012 CEA LIST.
 * 
 *  
 * 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:
 *   Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
 */
package org.eclipse.papyrus.infra.table.efacet.common.listener;

import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.facet.efacet.core.IFacetManager;
import org.eclipse.emf.facet.efacet.core.IFacetManagerFactory;
import org.eclipse.emf.facet.widgets.celleditors.ICommandFactoriesRegistry;
import org.eclipse.emf.facet.widgets.celleditors.ICommandFactory;
import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Table;
import org.eclipse.emf.facet.widgets.table.ui.command.ITableCommandFactory;
import org.eclipse.emf.facet.widgets.table.ui.command.ITableCommandFactoryFactory;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.TriggerListener;
import org.eclipse.papyrus.infra.table.efacet.metamodel.papyrustable.PapyrusTable;



public abstract class AbstractTableTriggerListener extends TriggerListener {

	/** The table. */
	protected final PapyrusTable table;

	/**
	 * Instantiates a new abstract table trigger listener.
	 * 
	 * @param papyrusTable
	 *        the papyrus table
	 */
	public AbstractTableTriggerListener(final PapyrusTable papyrusTable) {
		this.table = papyrusTable;
	}

	/**
	 * @see org.eclipse.emf.transaction.TriggerListener#trigger(org.eclipse.emf.transaction.TransactionalEditingDomain,
	 *      org.eclipse.emf.common.notify.Notification)
	 * 
	 * @param domain
	 * @param notification
	 * @return
	 */

	@Override
	protected final Command trigger(final TransactionalEditingDomain domain, final Notification notification) {
		if(isManagedNotification(notification)) {
			return getSynchronizationCommand(domain, notification);
		}
		return null;
	}

	/**
	 * Gets the synchronization command.
	 * 
	 * @param domain
	 *        the domain
	 * @param notification
	 *        the notification
	 * @return the synchronization command
	 */
	protected Command getSynchronizationCommand(final TransactionalEditingDomain domain, final Notification notification) {
		return null;
	}

	/**
	 * Checks if is managed notification.
	 * 
	 * @param notification
	 *        the notification
	 * @return true, if is managed notification
	 */
	protected abstract boolean isManagedNotification(Notification notification);

	/**
	 * Gets the command name.
	 * 
	 * @param notification
	 *        the notification
	 * @return the command name
	 */
	protected abstract String getCommandName(final Notification notification);

	/**
	 * 
	 * @param editingDomain
	 *        the editing domain
	 * @param resourceSet
	 *        the resource set
	 * @param table
	 *        the table
	 * @return
	 *         the command factory for these parameters
	 */
	public static ITableCommandFactory getTableCmdFactory(final TransactionalEditingDomain editingDomain, final ResourceSet resourceSet, final Table table) {
		final IFacetManager facetManager = IFacetManagerFactory.DEFAULT.getOrCreateFacetManager(resourceSet);
		final ICommandFactory commandFactory = ICommandFactoriesRegistry.INSTANCE.getCommandFactoryFor(editingDomain);
		final ITableCommandFactory tableCmdFactory = ITableCommandFactoryFactory.DEFAULT.createTableCommandFactory(table, editingDomain, commandFactory, facetManager);
		return tableCmdFactory;
	}
}

Back to the top