/
HyperLinkHandler.java
97 lines (87 loc) · 2.51 KB
/
HyperLinkHandler.java
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
97
/*******************************************************************************
* Copyright (c) 2017 Red Hat, Inc and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc - initial API and implementation
*******************************************************************************/
package org.eclipse.reddeer.uiforms.handler;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
import org.eclipse.ui.forms.widgets.Hyperlink;
import org.eclipse.reddeer.common.util.Display;
import org.eclipse.reddeer.common.util.ResultRunnable;
import org.eclipse.reddeer.core.handler.ControlHandler;
/**
* Contains methods that handle UI operations on {@link Hyperlink} widgets.
*
* @author Lucia Jelinkova
*
*/
public class HyperLinkHandler extends ControlHandler{
private static HyperLinkHandler instance;
/**
* Gets instance of HyperLinkHandler.
*
* @return instance of HyperLinkHandler
*/
public static HyperLinkHandler getInstance(){
if(instance == null){
instance = new HyperLinkHandler();
}
return instance;
}
/**
* Activates specified hyper link widget.
*
* @param hyperLink the hyper link
*/
public void activate(final Hyperlink hyperLink) {
Display.asyncExec(new Runnable() {
@Override
public void run() {
hyperLink.setFocus();
notifyHyperlink(SWT.MouseEnter, hyperLink);
notifyHyperlink(SWT.MouseDown, hyperLink);
notifyHyperlink(SWT.MouseUp, hyperLink);
}
});
}
/**
* Notifies specified hyper link widget with specified event.
*
* @param eventType event to notify specified hyper link about
* @param widget widget to notify
*/
public void notifyHyperlink(int eventType, Hyperlink widget) {
Event event = createHyperlinkEvent(widget);
notifyWidget(eventType, event, widget);
}
private Event createHyperlinkEvent(Hyperlink widget){
Event event = new Event();
event.time = (int) System.currentTimeMillis();
event.widget = widget;
event.display = Display.getDisplay();
event.button=1;
event.x=0;
event.y=0;
return event;
}
/**
* Gets text of hyperlink
* @param widget to handle
* @return text of specified hyperlink
*/
public String getText(final Hyperlink widget){
return Display.syncExec(new ResultRunnable<String>() {
@Override
public String run() {
return widget.getText();
}
});
}
}