Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4c7b467b7cf4dff144739d0947cf985feb07aa5d (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
/*****************************************************************************
 * Copyright (c) 2010 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:
 *  Ansgar Radermacher (CEA LIST) ansgar.radermacher@cea.fr - Initial API and implementation
 *****************************************************************************/

package org.eclipse.papyrus.uml.diagram.example.programmaticcreation;


import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.ui.PlatformUI;


/**
 * Superclass for handlers. It converts a selection into an EObject
 */
public abstract class CmdHandler extends AbstractHandler {

	/**
	 * Convert selected elements within model explorer or diagram to an eObject
	 */
	public void updateSelectedEObject() {
		// Retrieve selected elements
		IStructuredSelection selection = (IStructuredSelection)PlatformUI
				.getWorkbench().getActiveWorkbenchWindow()
				.getSelectionService().getSelection();
				
		if(selection != null) {
			selectedEObject = EMFHelper.getEObject(selection.getFirstElement());
		}
	}

	/**
	 * Store the selected EObject. Accessible for subclasses
	 */
	protected EObject selectedEObject;
}

Back to the top