1 package $packageName$; 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 setId(ICommandIds.CMD_OPEN); 22 setActionDefinitionId(ICommandIds.CMD_OPEN); 24 setImageDescriptor($pluginClass$.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 } 37 | Popular Tags |