01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.views.bookmarkexplorer;
11:
12: import java.util.Iterator;
13:
14: import org.eclipse.core.resources.IMarker;
15: import org.eclipse.core.runtime.CoreException;
16: import org.eclipse.core.runtime.IStatus;
17: import org.eclipse.jface.dialogs.ErrorDialog;
18: import org.eclipse.jface.dialogs.MessageDialog;
19: import org.eclipse.jface.util.OpenStrategy;
20: import org.eclipse.jface.viewers.IStructuredSelection;
21: import org.eclipse.ui.IWorkbenchPage;
22: import org.eclipse.ui.PartInitException;
23: import org.eclipse.ui.PlatformUI;
24: import org.eclipse.ui.ide.IDE;
25: import org.eclipse.ui.internal.views.bookmarkexplorer.BookmarkMessages;
26:
27: /**
28: * Action to open an editor on the selected bookmarks.
29: */
30: class OpenBookmarkAction extends BookmarkAction {
31:
32: /**
33: * Create a new instance of this class.
34: *
35: * @param view the view
36: */
37: public OpenBookmarkAction(BookmarkNavigator view) {
38: super (view, BookmarkMessages.OpenBookmark_text);
39: setToolTipText(BookmarkMessages.OpenBookmark_toolTip);
40: PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
41: IBookmarkHelpContextIds.OPEN_BOOKMARK_ACTION);
42: setEnabled(false);
43: }
44:
45: public void run() {
46: IWorkbenchPage page = getView().getSite().getPage();
47: for (Iterator i = getStructuredSelection().iterator(); i
48: .hasNext();) {
49: IMarker marker = (IMarker) i.next();
50: try {
51: IDE.openEditor(page, marker, OpenStrategy
52: .activateOnOpen());
53: } catch (PartInitException e) {
54: // Open an error style dialog for PartInitException by
55: // including any extra information from the nested
56: // CoreException if present.
57:
58: // Check for a nested CoreException
59: CoreException nestedException = null;
60: IStatus status = e.getStatus();
61: if (status != null
62: && status.getException() instanceof CoreException) {
63: nestedException = (CoreException) status
64: .getException();
65: }
66:
67: if (nestedException != null) {
68: // Open an error dialog and include the extra
69: // status information from the nested CoreException
70: ErrorDialog.openError(getView().getShell(),
71: BookmarkMessages.OpenBookmark_errorTitle, e
72: .getMessage(), nestedException
73: .getStatus());
74: } else {
75: // Open a regular error dialog since there is no
76: // extra information to display
77: MessageDialog.openError(getView().getShell(),
78: BookmarkMessages.OpenBookmark_errorTitle, e
79: .getMessage());
80: }
81: }
82: }
83: }
84:
85: public void selectionChanged(IStructuredSelection sel) {
86: setEnabled(!sel.isEmpty());
87: }
88: }
|