(no commit message)
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / 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 public class OpenViewAction extends Action {
10
11 private final IWorkbenchWindow window;
12 private int instanceNum = 0;
13 private final String viewId;
14
15 public OpenViewAction(IWorkbenchWindow window, String label, String viewId) {
16
17 this.window = window;
18 this.viewId = viewId;
19 setText(label); //Open Another Message View
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(Activator.getImageDescriptorOrig("/icons/sample2.gif"));
25 }
26
27 public void run() {
28
29 if(window != null) {
30 try {
31 window.getActivePage().showView(viewId, Integer.toString(instanceNum++), IWorkbenchPage.VIEW_ACTIVATE);
32 } catch (PartInitException e) {
33 MessageDialog.openError(window.getShell(), "Error", "Error opening view:" + e.getMessage());
34 }
35 }
36 }
37 }