KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > bookmarkexplorer > OpenBookmarkAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.views.bookmarkexplorer;
13
14 import java.util.Iterator JavaDoc;
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 /**
30  * Action to open an editor on the selected bookmarks.
31  */

32 class OpenBookmarkAction extends BookmarkAction {
33
34     /**
35      * Create a new instance of this class.
36      *
37      * @param view the view
38      */

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 JavaDoc 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                 // 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.getException();
64                 }
65
66                 if (nestedException != null) {
67                     // Open an error dialog and include the extra
68
// status information from the nested CoreException
69
ErrorDialog.openError(getView().getShell(),
70                             BookmarkMessages.OpenBookmark_errorTitle,
71                             e.getMessage(), nestedException.getStatus());
72                 } else {
73                     // Open a regular error dialog since there is no
74
// extra information to display
75
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