1 11 12 package org.eclipse.ui.internal.ide.actions; 13 14 import org.eclipse.core.resources.IContainer; 15 import org.eclipse.core.resources.IFile; 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.resources.ResourcesPlugin; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.jface.action.Action; 20 import org.eclipse.jface.action.IAction; 21 import org.eclipse.jface.dialogs.ErrorDialog; 22 import org.eclipse.jface.dialogs.IDialogConstants; 23 import org.eclipse.jface.viewers.ISelection; 24 import org.eclipse.swt.widgets.Shell; 25 import org.eclipse.ui.IWorkbenchPage; 26 import org.eclipse.ui.IWorkbenchWindow; 27 import org.eclipse.ui.IWorkbenchWindowActionDelegate; 28 import org.eclipse.ui.PlatformUI; 29 import org.eclipse.ui.ide.IDE; 30 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; 31 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; 32 import org.eclipse.ui.internal.ide.IIDEHelpContextIds; 33 import org.eclipse.ui.internal.ide.dialogs.OpenResourceDialog; 34 35 41 public class OpenWorkspaceFileAction extends Action implements 42 IWorkbenchWindowActionDelegate { 43 IWorkbenchWindow workbenchWindow; 44 45 48 public OpenWorkspaceFileAction() { 49 super(); 50 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, 51 IIDEHelpContextIds.OPEN_WORKSPACE_FILE_ACTION); 52 } 53 54 57 public void dispose() { 58 } 60 61 64 public void init(IWorkbenchWindow window) { 65 workbenchWindow = window; 66 } 67 68 74 IFile queryFileResource() { 75 Shell parent = workbenchWindow.getShell(); 76 IContainer input = ResourcesPlugin.getWorkspace().getRoot(); 77 78 OpenResourceDialog dialog = new OpenResourceDialog(parent, input, 79 IResource.FILE); 80 int resultCode = dialog.open(); 81 if (resultCode != IDialogConstants.OK_ID) 82 return null; 83 84 Object [] result = dialog.getResult(); 85 if (result == null || result.length == 0 86 || result[0] instanceof IFile == false) 87 return null; 88 89 return (IFile) result[0]; 90 } 91 92 96 public void run(IAction action) { 97 IFile file = queryFileResource(); 98 99 if (file == null) 100 return; 101 try { 102 IWorkbenchPage page = workbenchWindow.getActivePage(); 103 if (page != null) { 104 IDE.openEditor(page, file, true); 105 } 106 } catch (CoreException x) { 107 String title = IDEWorkbenchMessages.OpenWorkspaceFileAction_errorTitle; 108 String message = IDEWorkbenchMessages.OpenWorkspaceFileAction_errorMessage; 109 IDEWorkbenchPlugin.log(title, x.getStatus()); 110 ErrorDialog.openError(workbenchWindow.getShell(), title, message, x 111 .getStatus()); 112 } 113 } 114 115 118 public void selectionChanged(IAction action, ISelection selection) { 119 } 121 122 } 123 | Popular Tags |