1 11 12 package org.eclipse.ui.views.bookmarkexplorer; 13 14 import java.util.Iterator ; 15 16 import org.eclipse.core.resources.IMarker; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IStatus; 19 import org.eclipse.jface.dialogs.ErrorDialog; 20 import org.eclipse.jface.dialogs.MessageDialog; 21 import org.eclipse.jface.util.OpenStrategy; 22 import org.eclipse.jface.viewers.IStructuredSelection; 23 import org.eclipse.ui.IWorkbenchPage; 24 import org.eclipse.ui.PartInitException; 25 import org.eclipse.ui.PlatformUI; 26 import org.eclipse.ui.ide.IDE; 27 import org.eclipse.ui.internal.views.bookmarkexplorer.BookmarkMessages; 28 29 32 class OpenBookmarkAction extends BookmarkAction { 33 34 39 public OpenBookmarkAction(BookmarkNavigator view) { 40 super(view, BookmarkMessages.OpenBookmark_text); 41 setToolTipText(BookmarkMessages.OpenBookmark_toolTip); 42 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, 43 IBookmarkHelpContextIds.OPEN_BOOKMARK_ACTION); 44 setEnabled(false); 45 } 46 47 public void run() { 48 IWorkbenchPage page = getView().getSite().getPage(); 49 for (Iterator i = getStructuredSelection().iterator(); i.hasNext();) { 50 IMarker marker = (IMarker) i.next(); 51 try { 52 IDE.openEditor(page, marker, OpenStrategy.activateOnOpen()); 53 } catch (PartInitException e) { 54 58 CoreException nestedException = null; 60 IStatus status = e.getStatus(); 61 if (status != null 62 && status.getException() instanceof CoreException) { 63 nestedException = (CoreException) status.getException(); 64 } 65 66 if (nestedException != null) { 67 ErrorDialog.openError(getView().getShell(), 70 BookmarkMessages.OpenBookmark_errorTitle, 71 e.getMessage(), nestedException.getStatus()); 72 } else { 73 MessageDialog.openError(getView().getShell(), 76 BookmarkMessages.OpenBookmark_errorTitle, 77 e.getMessage()); 78 } 79 } 80 } 81 } 82 83 public void selectionChanged(IStructuredSelection sel) { 84 setEnabled(!sel.isEmpty()); 85 } 86 } 87 | Popular Tags |