KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > actions > FollowHyperlinkAction


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

11 package org.eclipse.debug.internal.ui.actions;
12
13
14 import org.eclipse.debug.internal.ui.DebugUIPlugin;
15 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
16 import org.eclipse.debug.internal.ui.views.console.ConsoleViewer;
17 import org.eclipse.debug.ui.console.IConsoleHyperlink;
18 import org.eclipse.jface.text.ITextSelection;
19 import org.eclipse.jface.viewers.ISelectionProvider;
20 import org.eclipse.ui.ISharedImages;
21 import org.eclipse.ui.actions.SelectionProviderAction;
22 import org.eclipse.ui.help.WorkbenchHelp;
23 import org.eclipse.ui.ide.IDE;
24
25 /**
26  * Follows a hyperlink in the console
27  */

28 public class FollowHyperlinkAction extends SelectionProviderAction {
29
30     /**
31      * Constructs a follow link action
32      */

33     public FollowHyperlinkAction(ISelectionProvider selectionProvider) {
34         super(selectionProvider, ActionMessages.getString("FollowHyperlinkAction.&Open_Link_1")); //$NON-NLS-1$
35
setToolTipText(ActionMessages.getString("FollowHyperlinkAction.Follow_the_selected_hyperlink._2")); //$NON-NLS-1$
36
ISharedImages images= DebugUIPlugin.getDefault().getWorkbench().getSharedImages();
37         setImageDescriptor(images.getImageDescriptor(IDE.SharedImages.IMG_OPEN_MARKER));
38         WorkbenchHelp.setHelp(
39             this,
40             IDebugHelpContextIds.FOLLOW_CONSOLE_HYPERLINK_ACTION);
41     }
42     
43     public IConsoleHyperlink getHyperLink() {
44         ISelectionProvider selectionProvider = getSelectionProvider();
45         if (selectionProvider instanceof ConsoleViewer) {
46             ITextSelection textSelection = (ITextSelection)selectionProvider.getSelection();
47             ConsoleViewer consoleViewer = (ConsoleViewer)selectionProvider;
48             if (textSelection != null) {
49                 return consoleViewer.getHyperlink(textSelection.getOffset());
50             }
51         }
52         return null;
53     }
54
55     /**
56      * @see org.eclipse.jface.action.IAction#run()
57      */

58     public void run() {
59         IConsoleHyperlink link = getHyperLink();
60         if (link != null) {
61             link.linkActivated();
62         }
63     }
64
65 }
66
Popular Tags