1 11 package org.eclipse.ui.actions; 12 13 import java.util.Iterator ; 14 15 import org.eclipse.core.resources.IFile; 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.jface.viewers.IStructuredSelection; 18 import org.eclipse.ui.IEditorRegistry; 19 import org.eclipse.ui.IWorkbenchPage; 20 import org.eclipse.ui.PartInitException; 21 import org.eclipse.ui.PlatformUI; 22 import org.eclipse.ui.internal.ide.DialogUtil; 23 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; 24 import org.eclipse.ui.internal.ide.IIDEHelpContextIds; 25 import org.eclipse.ui.part.FileEditorInput; 26 27 34 public class OpenSystemEditorAction extends SelectionListenerAction { 35 36 39 public static final String ID = PlatformUI.PLUGIN_ID 40 + ".OpenSystemEditorAction"; 42 45 private IWorkbenchPage workbenchPage; 46 47 53 public OpenSystemEditorAction(IWorkbenchPage page) { 54 super(IDEWorkbenchMessages.OpenSystemEditorAction_text); 55 setToolTipText(IDEWorkbenchMessages.OpenSystemEditorAction_toolTip); 56 setId(ID); 57 page.getWorkbenchWindow().getWorkbench().getHelpSystem().setHelp(this, 58 IIDEHelpContextIds.OPEN_SYSTEM_EDITOR_ACTION); 59 if (page == null) { 60 throw new IllegalArgumentException (); 61 } 62 this.workbenchPage = page; 63 } 64 65 70 final IWorkbenchPage getWorkbenchPage() { 71 return workbenchPage; 72 } 73 74 79 void openFile(IFile file) { 80 try { 81 getWorkbenchPage().openEditor(new FileEditorInput(file), 82 IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID); 83 } catch (PartInitException e) { 84 DialogUtil.openError(getWorkbenchPage().getWorkbenchWindow() 85 .getShell(), IDEWorkbenchMessages.OpenSystemEditorAction_dialogTitle, 86 e.getMessage(), e); 87 } 88 } 89 90 93 public void run() { 94 Iterator itr = getSelectedResources().iterator(); 95 while (itr.hasNext()) { 96 IResource resource = (IResource) itr.next(); 97 if (resource instanceof IFile) { 98 openFile((IFile) resource); 99 } 100 } 101 } 102 103 108 protected boolean updateSelection(IStructuredSelection selection) { 109 return super.updateSelection(selection) 110 && selectionIsOfType(IResource.FILE); 111 } 112 } 113 | Popular Tags |