Skip to main content
summaryrefslogtreecommitdiffstats
blob: 37963dbc973b056e9ab5f46ae5626a6c36f3af63 (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
/*****************************************************************************
 * Copyright (c) 2013 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:
 *  Juan Cadavid (CEA LIST) juan.cadavid@cea.fr - Initial API and implementation
 *****************************************************************************/
package org.eclipse.papyrus.uml.nattable.menu.util;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.papyrus.infra.core.sasheditor.editor.AbstractMultiPageSashEditor;
import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
import org.eclipse.papyrus.uml.service.types.utils.CommandContext;
import org.eclipse.papyrus.uml.service.types.utils.ICommandContext;
import org.eclipse.ui.IWorkbenchPart;

/**
 * Utilities for the creation of contextual menus from the Nattable editor
 */
public class TableMenuUtils {

	/**
	 * FIXME move me in an upper plugin
	 * 
	 * @param tableManager
	 *        the table manager
	 * @return
	 *         the command context to use to create new elements in the table
	 */
	public static ICommandContext getTableCommandContext(INattableModelManager tableManager) {
		INattableModelManager manager = tableManager;
		if(manager != null) {
			final EObject container = manager.getTable().getContext();
			ICommandContext context = null;
			if(container != null) {
				context = new CommandContext(container);
			}
			return context;
		}
		return null;
	}

	/**
	 * FIXME move me in an upper plugin
	 * 
	 * @param activeWorkbenchPart
	 * @return
	 *         the table manager from the workbench part
	 */
	public static INattableModelManager getTableManager(IWorkbenchPart activeWorkbenchPart) {
		IWorkbenchPart activePart = activeWorkbenchPart;
		if(activePart instanceof AbstractMultiPageSashEditor) {
			activePart = ((AbstractMultiPageSashEditor)activePart).getActiveEditor();
			if(activePart != null) {
				return (INattableModelManager)activePart.getAdapter(INattableModelManager.class);
			}

		}
		return null;
	}

}

Back to the top