KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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.ui.console.IConsoleHyperlink;
16 import org.eclipse.jface.action.IStatusLineManager;
17 import org.eclipse.jface.text.ITextSelection;
18 import org.eclipse.jface.viewers.ISelection;
19 import org.eclipse.jface.viewers.ISelectionProvider;
20 import org.eclipse.jface.viewers.IStructuredSelection;
21 import org.eclipse.ui.IActionBars;
22
23 /**
24  * A follow hyperlink action that is always enabled but reports problems
25  * when a run fails. Bound to the open editor action definition by the
26  * ConsoleView.
27  */

28 public class KeyBindingFollowHyperlinkAction extends FollowHyperlinkAction {
29
30     private boolean fSelectionNotAHyperlink = false;
31     private IActionBars fActionBars;
32     
33     public KeyBindingFollowHyperlinkAction(ISelectionProvider selectionProvider, IActionBars actionBars) {
34         super(selectionProvider);
35         fActionBars = actionBars;
36     }
37
38     /**
39      * @see org.eclipse.jface.action.IAction#run()
40      */

41     public void run() {
42         IConsoleHyperlink link = getHyperLink();
43         if (link == null) {
44             IStatusLineManager statusLine= getStatusLineManager();
45             if (statusLine != null) {
46                 statusLine.setErrorMessage(ActionMessages.getString("KeyBindingFollowHyperLinkAction.No_hyperlink")); //$NON-NLS-1$
47
fSelectionNotAHyperlink = true;
48             }
49             DebugUIPlugin.getStandardDisplay().beep();
50         } else {
51             link.linkActivated();
52             fSelectionNotAHyperlink = false;
53         }
54     }
55     
56     public void clearStatusLine() {
57         if (fSelectionNotAHyperlink) {
58             IStatusLineManager statusLine= getStatusLineManager();
59             if (statusLine != null) {
60                 statusLine.setErrorMessage(null);
61                 fSelectionNotAHyperlink = false;
62             }
63         }
64     }
65
66     /* (non-Javadoc)
67      * @see org.eclipse.ui.actions.SelectionProviderAction#selectionChanged(org.eclipse.jface.viewers.ISelection)
68      */

69     public void selectionChanged(ISelection selection) {
70         if (isEmptySelection(selection)) {
71             clearStatusLine();
72         }
73     }
74
75     /* (non-Javadoc)
76      * @see org.eclipse.ui.actions.SelectionProviderAction#selectionChanged(org.eclipse.jface.viewers.IStructuredSelection)
77      */

78     public void selectionChanged(IStructuredSelection selection) {
79         selectionChanged((ISelection)selection);
80     }
81     
82     /**
83      * This method is required because ITextSelection's of length zero are
84      * NOT considered empty according to the implementation of TextSelection.isEmpty()
85      * (see bug 32063).
86      */

87     protected boolean isEmptySelection(ISelection selection) {
88         if (selection instanceof ITextSelection) {
89             return ((ITextSelection)selection).getLength() < 1;
90         }
91         return selection.isEmpty();
92     }
93     
94     /**
95      * Convenience method
96      */

97     protected IStatusLineManager getStatusLineManager() {
98         return fActionBars.getStatusLineManager();
99     }
100
101 }
102
Popular Tags