Initial version of project - RCP Mail Template.
[taxeditor.git] / src / eu / etaxonomy / taxeditor / OpenViewAction.java
1 package eu.etaxonomy.taxeditor;
2
3 import org.eclipse.jface.action.Action;
4 import org.eclipse.jface.dialogs.MessageDialog;
5 import org.eclipse.ui.IWorkbenchPage;
6 import org.eclipse.ui.IWorkbenchWindow;
7 import org.eclipse.ui.PartInitException;
8
9
10 public class OpenViewAction extends Action {
11
12 private final IWorkbenchWindow window;
13 private int instanceNum = 0;
14 private final String viewId;
15
16 public OpenViewAction(IWorkbenchWindow window, String label, String viewId) {
17 this.window = window;
18 this.viewId = viewId;
19 setText(label);
20 // The id is used to refer to the action in a menu or toolbar
21 setId(ICommandIds.CMD_OPEN);
22 // Associate the action with a pre-defined command, to allow key bindings.
23 setActionDefinitionId(ICommandIds.CMD_OPEN);
24 setImageDescriptor(eu.etaxonomy.taxeditor.Activator.getImageDescriptor("/icons/sample2.gif"));
25 }
26
27 public void run() {
28 if(window != null) {
29 try {
30 window.getActivePage().showView(viewId, Integer.toString(instanceNum++), IWorkbenchPage.VIEW_ACTIVATE);
31 } catch (PartInitException e) {
32 MessageDialog.openError(window.getShell(), "Error", "Error opening view:" + e.getMessage());
33 }
34 }
35 }
36 }