1
|
package eu.etaxonomy.taxeditor.handler;
|
2
|
|
3
|
import org.eclipse.core.commands.AbstractHandler;
|
4
|
import org.eclipse.core.commands.ExecutionEvent;
|
5
|
import org.eclipse.core.commands.ExecutionException;
|
6
|
import org.eclipse.jface.viewers.ISelection;
|
7
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
8
|
import org.eclipse.ui.handlers.HandlerUtil;
|
9
|
|
10
|
import eu.etaxonomy.taxeditor.view.CdmViewerChooser;
|
11
|
|
12
|
/**
|
13
|
* Opens the (first) currently selected element in a viewer. Opens a list of
|
14
|
* possible viewers if more than one are registered for this element.
|
15
|
*
|
16
|
* @author pplitzner
|
17
|
* @date Jul 6, 2015
|
18
|
*
|
19
|
*/
|
20
|
public class OpenHandler extends AbstractHandler {
|
21
|
|
22
|
@Override
|
23
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
24
|
ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
|
25
|
if(currentSelection instanceof IStructuredSelection){
|
26
|
Object firstElement = ((IStructuredSelection) currentSelection).getFirstElement();
|
27
|
CdmViewerChooser viewerChooser = new CdmViewerChooser(HandlerUtil.getActiveShell(event));
|
28
|
viewerChooser.chooseViewer(firstElement);
|
29
|
}
|
30
|
return null;
|
31
|
}
|
32
|
|
33
|
}
|