Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: eba85f83db007546ae129aa768e79f88a4eab299 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package org.eclipse.debug.internal.ui.actions;

/**********************************************************************
Copyright (c) 2000, 2002 IBM Corp.  All rights reserved.
This file is made available under the terms of the Common Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/cpl-v10.html
**********************************************************************/

import org.eclipse.debug.internal.ui.views.console.ConsoleView;
import org.eclipse.debug.ui.console.IConsoleHyperlink;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;

/**
 * A follow hyperlink action that is always enabled but reports problems
 * when a run fails. Bound to the open editor action definition by the
 * ConsoleView.
 */
public class KeyBindingFollowHyperlinkAction extends FollowHyperlinkAction {

	ConsoleView fView;
	boolean fSelectionNotAHyperlink = false;
	
	public KeyBindingFollowHyperlinkAction(ConsoleView view) {
		super(view.getConsoleViewer());
		fView= view;
	}

	/**
	 * @see org.eclipse.jface.action.IAction#run()
	 */
	public void run() {
		IConsoleHyperlink link = getHyperLink();
		if (link == null) {		
			IStatusLineManager statusLine= getStatusLineManager();
			if (statusLine != null) {
				statusLine.setErrorMessage(ActionMessages.getString("KeyBindingFollowHyperLinkAction.No_hyperlink")); //$NON-NLS-1$
				fSelectionNotAHyperlink = true;
			}
			fView.getSite().getShell().getDisplay().beep();
		} else {
			link.linkActivated();
			fSelectionNotAHyperlink = false;
		}
	}
	
	public void clearStatusLine() {
		if (fSelectionNotAHyperlink) {
			IStatusLineManager statusLine= getStatusLineManager();
			if (statusLine != null) {		
				statusLine.setErrorMessage(null);
				fSelectionNotAHyperlink = false;
			}
		}		
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.actions.SelectionProviderAction#selectionChanged(org.eclipse.jface.viewers.ISelection)
	 */
	public void selectionChanged(ISelection selection) {
		if (isEmptySelection(selection)) {
			clearStatusLine();
		}
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.actions.SelectionProviderAction#selectionChanged(org.eclipse.jface.viewers.IStructuredSelection)
	 */
	public void selectionChanged(IStructuredSelection selection) {
		selectionChanged((ISelection)selection);
	}
	
	/**
	 * This method is required because ITextSelection's of length zero are
	 * NOT considered empty according to the implementation of TextSelection.isEmpty()
	 * (see bug 32063).
	 */
	protected boolean isEmptySelection(ISelection selection) {
		if (selection instanceof ITextSelection) {
			return ((ITextSelection)selection).getLength() < 1;
		} else {
			return selection.isEmpty();
		}
	}
	
	/**
	 * Convenience method
	 */
	protected IStatusLineManager getStatusLineManager() {
		return fView.getViewSite().getActionBars().getStatusLineManager();
	}

}

Back to the top