129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2008 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 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.jface.text.hyperlink.MultipleHyperlinkPresenter;
|
|
14
|
131
|
15 import dwtx.jface.text.hyperlink.IHyperlinkPresenterExtension; // packageimport
|
|
16 import dwtx.jface.text.hyperlink.HyperlinkManager; // packageimport
|
|
17 import dwtx.jface.text.hyperlink.URLHyperlink; // packageimport
|
|
18 import dwtx.jface.text.hyperlink.IHyperlinkDetectorExtension2; // packageimport
|
|
19 import dwtx.jface.text.hyperlink.IHyperlinkDetector; // packageimport
|
|
20 import dwtx.jface.text.hyperlink.IHyperlinkPresenter; // packageimport
|
|
21 import dwtx.jface.text.hyperlink.URLHyperlinkDetector; // packageimport
|
|
22 import dwtx.jface.text.hyperlink.DefaultHyperlinkPresenter; // packageimport
|
|
23 import dwtx.jface.text.hyperlink.AbstractHyperlinkDetector; // packageimport
|
|
24 import dwtx.jface.text.hyperlink.IHyperlinkDetectorExtension; // packageimport
|
|
25 import dwtx.jface.text.hyperlink.HyperlinkMessages; // packageimport
|
|
26 import dwtx.jface.text.hyperlink.IHyperlink; // packageimport
|
|
27
|
|
28
|
129
|
29 import dwt.dwthelper.utils;
|
|
30
|
|
31
|
|
32 import dwt.DWT;
|
|
33 import dwt.events.KeyAdapter;
|
|
34 import dwt.events.KeyEvent;
|
|
35 import dwt.events.KeyListener;
|
|
36 import dwt.events.MouseAdapter;
|
|
37 import dwt.events.MouseEvent;
|
|
38 import dwt.events.MouseMoveListener;
|
|
39 import dwt.events.SelectionAdapter;
|
|
40 import dwt.events.SelectionEvent;
|
|
41 import dwt.events.ShellAdapter;
|
|
42 import dwt.events.ShellEvent;
|
|
43 import dwt.graphics.Color;
|
|
44 import dwt.graphics.Point;
|
|
45 import dwt.graphics.RGB;
|
|
46 import dwt.graphics.Rectangle;
|
|
47 import dwt.layout.GridLayout;
|
|
48 import dwt.widgets.Composite;
|
|
49 import dwt.widgets.Control;
|
|
50 import dwt.widgets.Display;
|
|
51 import dwt.widgets.Event;
|
|
52 import dwt.widgets.Listener;
|
|
53 import dwt.widgets.Shell;
|
|
54 import dwt.widgets.Table;
|
|
55 import dwt.widgets.TableItem;
|
|
56 import dwtx.jface.preference.IPreferenceStore;
|
|
57 import dwtx.jface.text.AbstractInformationControl;
|
|
58 import dwtx.jface.text.AbstractInformationControlManager;
|
|
59 import dwtx.jface.text.IInformationControl;
|
|
60 import dwtx.jface.text.IInformationControlCreator;
|
|
61 import dwtx.jface.text.IInformationControlExtension2;
|
|
62 import dwtx.jface.text.IInformationControlExtension3;
|
|
63 import dwtx.jface.text.IRegion;
|
|
64 import dwtx.jface.text.ITextHover;
|
|
65 import dwtx.jface.text.ITextHoverExtension;
|
|
66 import dwtx.jface.text.ITextViewer;
|
|
67 import dwtx.jface.text.IWidgetTokenKeeper;
|
|
68 import dwtx.jface.text.IWidgetTokenKeeperExtension;
|
|
69 import dwtx.jface.text.IWidgetTokenOwner;
|
|
70 import dwtx.jface.text.IWidgetTokenOwnerExtension;
|
|
71 import dwtx.jface.text.JFaceTextUtil;
|
|
72 import dwtx.jface.text.Region;
|
|
73 import dwtx.jface.util.Geometry;
|
|
74 import dwtx.jface.viewers.ColumnLabelProvider;
|
|
75 import dwtx.jface.viewers.IStructuredContentProvider;
|
|
76 import dwtx.jface.viewers.TableViewer;
|
|
77 import dwtx.jface.viewers.Viewer;
|
|
78
|
|
79
|
|
80 /**
|
|
81 * A hyperlink presenter capable of showing multiple hyperlinks in a hover.
|
|
82 *
|
|
83 * @since 3.4
|
|
84 */
|
|
85 public class MultipleHyperlinkPresenter : DefaultHyperlinkPresenter {
|
|
86
|
|
87 /**
|
|
88 * An information control capable of showing a list of hyperlinks. The hyperlinks can be opened.
|
|
89 */
|
|
90 private static class LinkListInformationControl : AbstractInformationControl , IInformationControlExtension2 {
|
|
91
|
|
92 private static final class LinkContentProvider : IStructuredContentProvider {
|
|
93
|
|
94 /*
|
|
95 * @see dwtx.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
|
|
96 */
|
|
97 public Object[] getElements(Object inputElement) {
|
|
98 return (Object[]) inputElement;
|
|
99 }
|
|
100
|
|
101 /*
|
|
102 * @see dwtx.jface.viewers.IContentProvider#dispose()
|
|
103 */
|
|
104 public void dispose() {
|
|
105 }
|
|
106
|
|
107 /*
|
|
108 * @see dwtx.jface.viewers.IContentProvider#inputChanged(dwtx.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
|
|
109 */
|
|
110 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
|
111 }
|
|
112 }
|
|
113
|
|
114 private static final class LinkLabelProvider : ColumnLabelProvider {
|
|
115 /*
|
|
116 * @see dwtx.jface.viewers.ColumnLabelProvider#getText(java.lang.Object)
|
|
117 */
|
|
118 public String getText(Object element) {
|
|
119 IHyperlink link= (IHyperlink)element;
|
|
120 String text= link.getHyperlinkText();
|
|
121 if (text !is null)
|
|
122 return text;
|
|
123 return HyperlinkMessages.getString("LinkListInformationControl.unknownLink"); //$NON-NLS-1$
|
|
124 }
|
|
125 }
|
|
126
|
|
127 private final MultipleHyperlinkHoverManager fManager;
|
|
128
|
|
129 private IHyperlink[] fInput;
|
|
130 private Composite fParent;
|
|
131 private Table fTable;
|
|
132
|
|
133 private Color fForegroundColor;
|
|
134 private Color fBackgroundColor;
|
|
135
|
|
136
|
|
137 /**
|
|
138 * Creates a link list information control with the given shell as parent.
|
|
139 *
|
|
140 * @param parentShell the parent shell
|
|
141 * @param manager the hover manager
|
|
142 * @param foregroundColor the foreground color, must not be disposed
|
|
143 * @param backgroundColor the background color, must not be disposed
|
|
144 */
|
|
145 public LinkListInformationControl(Shell parentShell, MultipleHyperlinkHoverManager manager, Color foregroundColor, Color backgroundColor) {
|
|
146 super(parentShell, false);
|
|
147 fManager= manager;
|
|
148 fForegroundColor= foregroundColor;
|
|
149 fBackgroundColor= backgroundColor;
|
|
150 create();
|
|
151 }
|
|
152
|
|
153 /*
|
|
154 * @see dwtx.jface.text.IInformationControl#setInformation(java.lang.String)
|
|
155 */
|
|
156 public void setInformation(String information) {
|
|
157 //replaced by IInformationControlExtension2#setInput(java.lang.Object)
|
|
158 }
|
|
159
|
|
160 /*
|
|
161 * @see dwtx.jface.text.IInformationControlExtension2#setInput(java.lang.Object)
|
|
162 */
|
|
163 public void setInput(Object input) {
|
|
164 fInput= (IHyperlink[]) input;
|
|
165 deferredCreateContent(fParent);
|
|
166 }
|
|
167
|
|
168 /*
|
|
169 * @see dwtx.jface.text.AbstractInformationControl#createContent(dwt.widgets.Composite)
|
|
170 */
|
|
171 protected void createContent(Composite parent) {
|
|
172 fParent= parent;
|
|
173 if ("win32".equals(DWT.getPlatform())) { //$NON-NLS-1$
|
|
174 GridLayout layout= new GridLayout();
|
|
175 layout.marginWidth= 0;
|
|
176 layout.marginRight= 4;
|
|
177 fParent.setLayout(layout);
|
|
178 }
|
|
179 fParent.setForeground(fForegroundColor);
|
|
180 fParent.setBackground(fBackgroundColor);
|
|
181 }
|
|
182
|
|
183 /*
|
|
184 * @see dwtx.jface.text.AbstractInformationControl#computeSizeHint()
|
|
185 */
|
|
186 public Point computeSizeHint() {
|
|
187 Point preferedSize= getShell().computeSize(DWT.DEFAULT, DWT.DEFAULT, true);
|
|
188
|
|
189 Point constraints= getSizeConstraints();
|
|
190 if (constraints is null)
|
|
191 return preferedSize;
|
|
192
|
|
193 if (fTable.getVerticalBar() is null || fTable.getHorizontalBar() is null)
|
|
194 return Geometry.min(constraints, preferedSize);
|
|
195
|
|
196 int scrollBarWidth= fTable.getVerticalBar().getSize().x;
|
|
197 int scrollBarHeight= fTable.getHorizontalBar().getSize().y;
|
|
198
|
|
199 int width;
|
|
200 if (preferedSize.y - scrollBarHeight <= constraints.y) {
|
|
201 width= preferedSize.x - scrollBarWidth;
|
|
202 fTable.getVerticalBar().setVisible(false);
|
|
203 } else {
|
|
204 width= Math.min(preferedSize.x, constraints.x);
|
|
205 }
|
|
206
|
|
207 int height;
|
|
208 if (preferedSize.x - scrollBarWidth <= constraints.x) {
|
|
209 height= preferedSize.y - scrollBarHeight;
|
|
210 fTable.getHorizontalBar().setVisible(false);
|
|
211 } else {
|
|
212 height= Math.min(preferedSize.y, constraints.y);
|
|
213 }
|
|
214
|
|
215 return new Point(width, height);
|
|
216 }
|
|
217
|
|
218 private void deferredCreateContent(Composite parent) {
|
|
219 fTable= new Table(parent, DWT.SINGLE | DWT.FULL_SELECTION);
|
|
220 fTable.setLinesVisible(false);
|
|
221 fTable.setHeaderVisible(false);
|
|
222 fTable.setForeground(fForegroundColor);
|
|
223 fTable.setBackground(fBackgroundColor);
|
|
224
|
|
225 final TableViewer viewer= new TableViewer(fTable);
|
|
226 viewer.setContentProvider(new LinkContentProvider());
|
|
227 viewer.setLabelProvider(new LinkLabelProvider());
|
|
228 viewer.setInput(fInput);
|
|
229 fTable.setSelection(0);
|
|
230
|
|
231 registerTableListeners();
|
|
232
|
|
233 getShell().addShellListener(new ShellAdapter() {
|
|
234
|
|
235 /*
|
|
236 * @see dwt.events.ShellAdapter#shellActivated(dwt.events.ShellEvent)
|
|
237 */
|
|
238 public void shellActivated(ShellEvent e) {
|
|
239 if (viewer.getTable().getSelectionCount() is 0) {
|
|
240 viewer.getTable().setSelection(0);
|
|
241 }
|
|
242
|
|
243 viewer.getTable().setFocus();
|
|
244 }
|
|
245 });
|
|
246 }
|
|
247
|
|
248 private void registerTableListeners() {
|
|
249
|
|
250 fTable.addMouseMoveListener(new MouseMoveListener() {
|
|
251 TableItem fLastItem= null;
|
|
252
|
|
253 public void mouseMove(MouseEvent e) {
|
|
254 if (fTable.equals(e.getSource())) {
|
|
255 Object o= fTable.getItem(new Point(e.x, e.y));
|
|
256 if (o instanceof TableItem) {
|
|
257 TableItem item= (TableItem) o;
|
|
258 if (!o.equals(fLastItem)) {
|
|
259 fLastItem= (TableItem) o;
|
|
260 fTable.setSelection(new TableItem[] { fLastItem });
|
|
261 } else if (e.y < fTable.getItemHeight() / 4) {
|
|
262 // Scroll up
|
|
263 int index= fTable.indexOf(item);
|
|
264 if (index > 0) {
|
|
265 fLastItem= fTable.getItem(index - 1);
|
|
266 fTable.setSelection(new TableItem[] { fLastItem });
|
|
267 }
|
|
268 } else if (e.y > fTable.getBounds().height - fTable.getItemHeight() / 4) {
|
|
269 // Scroll down
|
|
270 int index= fTable.indexOf(item);
|
|
271 if (index < fTable.getItemCount() - 1) {
|
|
272 fLastItem= fTable.getItem(index + 1);
|
|
273 fTable.setSelection(new TableItem[] { fLastItem });
|
|
274 }
|
|
275 }
|
|
276 }
|
|
277 }
|
|
278 }
|
|
279 });
|
|
280
|
|
281 fTable.addSelectionListener(new SelectionAdapter() {
|
|
282 public void widgetSelected(SelectionEvent e) {
|
|
283 openSelectedLink();
|
|
284 }
|
|
285 });
|
|
286
|
|
287 fTable.addMouseListener(new MouseAdapter() {
|
|
288 public void mouseUp(MouseEvent e) {
|
|
289 if (fTable.getSelectionCount() < 1)
|
|
290 return;
|
|
291
|
|
292 if (e.button !is 1)
|
|
293 return;
|
|
294
|
|
295 if (fTable.equals(e.getSource())) {
|
|
296 Object o= fTable.getItem(new Point(e.x, e.y));
|
|
297 TableItem selection= fTable.getSelection()[0];
|
|
298 if (selection.equals(o))
|
|
299 openSelectedLink();
|
|
300 }
|
|
301 }
|
|
302 });
|
|
303
|
|
304 fTable.addKeyListener(new KeyAdapter() {
|
|
305 public void keyPressed(KeyEvent e) {
|
|
306 if (e.keyCode is 0x0D) // return
|
|
307 openSelectedLink();
|
|
308 }
|
|
309 });
|
|
310 }
|
|
311
|
|
312 /*
|
|
313 * @see dwtx.jface.text.IInformationControlExtension#hasContents()
|
|
314 */
|
|
315 public bool hasContents() {
|
|
316 return true;
|
|
317 }
|
|
318
|
|
319 /**
|
|
320 * Opens the currently selected link.
|
|
321 */
|
|
322 private void openSelectedLink() {
|
|
323 TableItem selection= fTable.getSelection()[0];
|
|
324 IHyperlink link= (IHyperlink)selection.getData();
|
|
325 fManager.hideInformationControl();
|
|
326 link.open();
|
|
327 }
|
|
328 }
|
|
329
|
|
330 private class MultipleHyperlinkHover : ITextHover, ITextHoverExtension {
|
|
331
|
|
332 /**
|
|
333 * @see dwtx.jface.text.ITextHover#getHoverInfo(dwtx.jface.text.ITextViewer, dwtx.jface.text.IRegion)
|
|
334 * @deprecated
|
|
335 */
|
|
336 public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
|
|
337 return null;
|
|
338 }
|
|
339
|
|
340 /*
|
|
341 * @see dwtx.jface.text.ITextHover#getHoverRegion(dwtx.jface.text.ITextViewer, int)
|
|
342 */
|
|
343 public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
|
|
344 return fSubjectRegion;
|
|
345 }
|
|
346
|
|
347 /*
|
|
348 * @see dwtx.jface.text.ITextHoverExtension2#getHoverInfo2(dwtx.jface.text.ITextViewer, dwtx.jface.text.IRegion)
|
|
349 */
|
|
350 public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
|
|
351 return fHyperlinks;
|
|
352 }
|
|
353
|
|
354 /*
|
|
355 * @see dwtx.jface.text.ITextHoverExtension#getHoverControlCreator()
|
|
356 */
|
|
357 public IInformationControlCreator getHoverControlCreator() {
|
|
358 return new IInformationControlCreator() {
|
|
359 public IInformationControl createInformationControl(Shell parent) {
|
|
360 Color foregroundColor= fTextViewer.getTextWidget().getForeground();
|
|
361 Color backgroundColor= fTextViewer.getTextWidget().getBackground();
|
|
362 return new LinkListInformationControl(parent, fManager, foregroundColor, backgroundColor);
|
|
363 }
|
|
364 };
|
|
365 }
|
|
366 }
|
|
367
|
|
368 private static class MultipleHyperlinkHoverManager : AbstractInformationControlManager , IWidgetTokenKeeper, IWidgetTokenKeeperExtension {
|
|
369
|
|
370 private class Closer : IInformationControlCloser, Listener, KeyListener {
|
|
371
|
|
372 private Control fSubjectControl;
|
|
373 private Display fDisplay;
|
|
374 private IInformationControl fControl;
|
|
375 private Rectangle fSubjectArea;
|
|
376
|
|
377 /*
|
|
378 * @see dwtx.jface.text.AbstractInformationControlManager.IInformationControlCloser#setInformationControl(dwtx.jface.text.IInformationControl)
|
|
379 */
|
|
380 public void setInformationControl(IInformationControl control) {
|
|
381 fControl= control;
|
|
382 }
|
|
383
|
|
384 /*
|
|
385 * @see dwtx.jface.text.AbstractInformationControlManager.IInformationControlCloser#setSubjectControl(dwt.widgets.Control)
|
|
386 */
|
|
387 public void setSubjectControl(Control subject) {
|
|
388 fSubjectControl= subject;
|
|
389 }
|
|
390
|
|
391 /*
|
|
392 * @see dwtx.jface.text.AbstractInformationControlManager.IInformationControlCloser#start(dwt.graphics.Rectangle)
|
|
393 */
|
|
394 public void start(Rectangle subjectArea) {
|
|
395 fSubjectArea= subjectArea;
|
|
396
|
|
397 fDisplay= fSubjectControl.getDisplay();
|
|
398 if (!fDisplay.isDisposed()) {
|
|
399 fDisplay.addFilter(DWT.FocusOut, this);
|
|
400 fDisplay.addFilter(DWT.MouseMove, this);
|
|
401 fTextViewer.getTextWidget().addKeyListener(this);
|
|
402 }
|
|
403 }
|
|
404
|
|
405 /*
|
|
406 * @see dwtx.jface.text.AbstractInformationControlManager.IInformationControlCloser#stop()
|
|
407 */
|
|
408 public void stop() {
|
|
409 if (fDisplay !is null && !fDisplay.isDisposed()) {
|
|
410 fDisplay.removeFilter(DWT.FocusOut, this);
|
|
411 fDisplay.removeFilter(DWT.MouseMove, this);
|
|
412 fTextViewer.getTextWidget().removeKeyListener(this);
|
|
413 }
|
|
414
|
|
415 fSubjectArea= null;
|
|
416 }
|
|
417
|
|
418 /*
|
|
419 * @see dwt.widgets.Listener#handleEvent(dwt.widgets.Event)
|
|
420 */
|
|
421 public void handleEvent(Event event) {
|
|
422 switch (event.type) {
|
|
423 case DWT.FocusOut:
|
|
424 if (!fControl.isFocusControl())
|
|
425 disposeInformationControl();
|
|
426 break;
|
|
427 case DWT.MouseMove:
|
|
428 handleMouseMove(event);
|
|
429 break;
|
|
430 }
|
|
431 }
|
|
432
|
|
433 /**
|
|
434 * Handle mouse movement events.
|
|
435 *
|
|
436 * @param event the event
|
|
437 */
|
|
438 private void handleMouseMove(Event event) {
|
|
439 if (!(event.widget instanceof Control))
|
|
440 return;
|
|
441
|
|
442 if (fControl.isFocusControl())
|
|
443 return;
|
|
444
|
|
445 Control eventControl= (Control) event.widget;
|
|
446
|
|
447 //transform coordinates to subject control:
|
|
448 Point mouseLoc= event.display.map(eventControl, fSubjectControl, event.x, event.y);
|
|
449
|
|
450 if (fSubjectArea.contains(mouseLoc))
|
|
451 return;
|
|
452
|
|
453 if (inKeepUpZone(mouseLoc.x, mouseLoc.y, ((IInformationControlExtension3) fControl).getBounds()))
|
|
454 return;
|
|
455
|
|
456 hideInformationControl();
|
|
457 }
|
|
458
|
|
459 /**
|
|
460 * Tests whether a given mouse location is within the keep-up zone.
|
|
461 * The hover should not be hidden as long as the mouse stays inside this zone.
|
|
462 *
|
|
463 * @param x the x coordinate, relative to the <em>subject control</em>
|
|
464 * @param y the y coordinate, relative to the <em>subject control</em>
|
|
465 * @param controlBounds the bounds of the current control
|
|
466 *
|
|
467 * @return <code>true</code> iff the mouse event occurred in the keep-up zone
|
|
468 */
|
|
469 private bool inKeepUpZone(int x, int y, Rectangle controlBounds) {
|
|
470 // +-----------+
|
|
471 // |subjectArea|
|
|
472 // +-----------+
|
|
473 // |also keepUp|
|
|
474 // ++-----------+-------+
|
|
475 // | totalBounds |
|
|
476 // +--------------------+
|
|
477 if (fSubjectArea.contains(x, y))
|
|
478 return true;
|
|
479
|
|
480 Rectangle iControlBounds= fSubjectControl.getDisplay().map(null, fSubjectControl, controlBounds);
|
|
481 Rectangle totalBounds= Geometry.copy(iControlBounds);
|
|
482 if (totalBounds.contains(x, y))
|
|
483 return true;
|
|
484
|
|
485 int keepUpY= fSubjectArea.y + fSubjectArea.height;
|
|
486 Rectangle alsoKeepUp= new Rectangle(fSubjectArea.x, keepUpY, fSubjectArea.width, totalBounds.y - keepUpY);
|
|
487 return alsoKeepUp.contains(x, y);
|
|
488 }
|
|
489
|
|
490 /*
|
|
491 * @see dwt.events.KeyListener#keyPressed(dwt.events.KeyEvent)
|
|
492 */
|
|
493 public void keyPressed(KeyEvent e) {
|
|
494 }
|
|
495
|
|
496 /*
|
|
497 * @see dwt.events.KeyListener#keyReleased(dwt.events.KeyEvent)
|
|
498 */
|
|
499 public void keyReleased(KeyEvent e) {
|
|
500 hideInformationControl();
|
|
501 }
|
|
502
|
|
503 }
|
|
504
|
|
505 /**
|
|
506 * Priority of the hover managed by this manager.
|
|
507 * Default value: One higher then for the hovers
|
|
508 * managed by TextViewerHoverManager.
|
|
509 */
|
|
510 private static final int WIDGET_TOKEN_PRIORITY= 1;
|
|
511
|
|
512 private final MultipleHyperlinkHover fHover;
|
|
513 private final ITextViewer fTextViewer;
|
|
514 private final MultipleHyperlinkPresenter fHyperlinkPresenter;
|
|
515 private Closer fCloser;
|
|
516 private bool fIsControlVisible;
|
|
517
|
|
518
|
|
519 /**
|
|
520 * Create a new MultipleHyperlinkHoverManager. The MHHM can show and hide
|
|
521 * the given MultipleHyperlinkHover inside the given ITextViewer.
|
|
522 *
|
|
523 * @param hover the hover to manage
|
|
524 * @param viewer the viewer to show the hover in
|
|
525 * @param hyperlinkPresenter the hyperlink presenter using this manager to present hyperlinks
|
|
526 */
|
|
527 public MultipleHyperlinkHoverManager(MultipleHyperlinkHover hover, ITextViewer viewer, MultipleHyperlinkPresenter hyperlinkPresenter) {
|
|
528 super(hover.getHoverControlCreator());
|
|
529
|
|
530 fHover= hover;
|
|
531 fTextViewer= viewer;
|
|
532 fHyperlinkPresenter= hyperlinkPresenter;
|
|
533
|
|
534 fCloser= new Closer();
|
|
535 setCloser(fCloser);
|
|
536 fIsControlVisible= false;
|
|
537 }
|
|
538
|
|
539 /*
|
|
540 * @see dwtx.jface.text.AbstractInformationControlManager#computeInformation()
|
|
541 */
|
|
542 protected void computeInformation() {
|
|
543 IRegion region= fHover.getHoverRegion(fTextViewer, -1);
|
|
544 if (region is null) {
|
|
545 setInformation(null, null);
|
|
546 return;
|
|
547 }
|
|
548
|
|
549 Rectangle area= JFaceTextUtil.computeArea(region, fTextViewer);
|
|
550 if (area is null || area.isEmpty()) {
|
|
551 setInformation(null, null);
|
|
552 return;
|
|
553 }
|
|
554
|
|
555 Object information= fHover.getHoverInfo2(fTextViewer, region);
|
|
556 setCustomInformationControlCreator(fHover.getHoverControlCreator());
|
|
557 setInformation(information, area);
|
|
558 }
|
|
559
|
|
560 /*
|
|
561 * @see dwtx.jface.text.AbstractInformationControlManager#computeInformationControlLocation(dwt.graphics.Rectangle, dwt.graphics.Point)
|
|
562 */
|
|
563 protected Point computeInformationControlLocation(Rectangle subjectArea, Point controlSize) {
|
|
564 Point result= super.computeInformationControlLocation(subjectArea, controlSize);
|
|
565
|
|
566 Point cursorLocation= fTextViewer.getTextWidget().getDisplay().getCursorLocation();
|
|
567 if (cursorLocation.x <= result.x + controlSize.x)
|
|
568 return result;
|
|
569
|
|
570 result.x= cursorLocation.x + 20 - controlSize.x;
|
|
571 return result;
|
|
572 }
|
|
573
|
|
574 /*
|
|
575 * @see dwtx.jface.text.AbstractInformationControlManager#showInformationControl(dwt.graphics.Rectangle)
|
|
576 */
|
|
577 protected void showInformationControl(Rectangle subjectArea) {
|
|
578 if (fTextViewer instanceof IWidgetTokenOwnerExtension) {
|
|
579 if (((IWidgetTokenOwnerExtension) fTextViewer).requestWidgetToken(this, WIDGET_TOKEN_PRIORITY))
|
|
580 super.showInformationControl(subjectArea);
|
|
581 } else if (fTextViewer instanceof IWidgetTokenOwner) {
|
|
582 if (((IWidgetTokenOwner) fTextViewer).requestWidgetToken(this))
|
|
583 super.showInformationControl(subjectArea);
|
|
584 } else {
|
|
585 super.showInformationControl(subjectArea);
|
|
586 }
|
|
587
|
|
588 fIsControlVisible= true;
|
|
589 }
|
|
590
|
|
591 /*
|
|
592 * @see dwtx.jface.text.AbstractInformationControlManager#hideInformationControl()
|
|
593 */
|
|
594 protected void hideInformationControl() {
|
|
595 super.hideInformationControl();
|
|
596
|
|
597 if (fTextViewer instanceof IWidgetTokenOwner) {
|
|
598 ((IWidgetTokenOwner) fTextViewer).releaseWidgetToken(this);
|
|
599 }
|
|
600
|
|
601 fIsControlVisible= false;
|
|
602 fHyperlinkPresenter.hideHyperlinks();
|
|
603 }
|
|
604
|
|
605 /*
|
|
606 * @see dwtx.jface.text.AbstractInformationControlManager#disposeInformationControl()
|
|
607 */
|
|
608 public void disposeInformationControl() {
|
|
609 super.disposeInformationControl();
|
|
610
|
|
611 if (fTextViewer instanceof IWidgetTokenOwner) {
|
|
612 ((IWidgetTokenOwner) fTextViewer).releaseWidgetToken(this);
|
|
613 }
|
|
614
|
|
615 fIsControlVisible= false;
|
|
616 fHyperlinkPresenter.hideHyperlinks();
|
|
617 }
|
|
618
|
|
619 /*
|
|
620 * @see dwtx.jface.text.IWidgetTokenKeeper#requestWidgetToken(dwtx.jface.text.IWidgetTokenOwner)
|
|
621 */
|
|
622 public bool requestWidgetToken(IWidgetTokenOwner owner) {
|
|
623 hideInformationControl();
|
|
624 return true;
|
|
625 }
|
|
626
|
|
627 /*
|
|
628 * @see dwtx.jface.text.IWidgetTokenKeeperExtension#requestWidgetToken(dwtx.jface.text.IWidgetTokenOwner, int)
|
|
629 */
|
|
630 public bool requestWidgetToken(IWidgetTokenOwner owner, int priority) {
|
|
631 if (priority < WIDGET_TOKEN_PRIORITY)
|
|
632 return false;
|
|
633
|
|
634 hideInformationControl();
|
|
635 return true;
|
|
636 }
|
|
637
|
|
638 /*
|
|
639 * @see dwtx.jface.text.IWidgetTokenKeeperExtension#setFocus(dwtx.jface.text.IWidgetTokenOwner)
|
|
640 */
|
|
641 public bool setFocus(IWidgetTokenOwner owner) {
|
|
642 return false;
|
|
643 }
|
|
644
|
|
645 /**
|
|
646 * Returns <code>true</code> if the information control managed by
|
|
647 * this manager is visible, <code>false</code> otherwise.
|
|
648 *
|
|
649 * @return <code>true</code> if information control is visible
|
|
650 */
|
|
651 public bool isInformationControlVisible() {
|
|
652 return fIsControlVisible;
|
|
653 }
|
|
654 }
|
|
655
|
|
656 private ITextViewer fTextViewer;
|
|
657
|
|
658 private IHyperlink[] fHyperlinks;
|
|
659 private Region fSubjectRegion;
|
|
660 private MultipleHyperlinkHoverManager fManager;
|
|
661
|
|
662 /**
|
|
663 * Creates a new multiple hyperlink presenter which uses
|
|
664 * {@link #HYPERLINK_COLOR} to read the color from the given preference store.
|
|
665 *
|
|
666 * @param store the preference store
|
|
667 */
|
|
668 public MultipleHyperlinkPresenter(IPreferenceStore store) {
|
|
669 super(store);
|
|
670 }
|
|
671
|
|
672 /**
|
|
673 * Creates a new multiple hyperlink presenter.
|
|
674 *
|
|
675 * @param color the hyperlink color, to be disposed by the caller
|
|
676 */
|
|
677 public MultipleHyperlinkPresenter(RGB color) {
|
|
678 super(color);
|
|
679 }
|
|
680
|
|
681 /*
|
|
682 * @see dwtx.jface.text.hyperlink.DefaultHyperlinkPresenter#install(dwtx.jface.text.ITextViewer)
|
|
683 */
|
|
684 public void install(ITextViewer viewer) {
|
|
685 super.install(viewer);
|
|
686 fTextViewer= viewer;
|
|
687
|
|
688 fManager= new MultipleHyperlinkHoverManager(new MultipleHyperlinkHover(), fTextViewer, this);
|
|
689 fManager.install(viewer.getTextWidget());
|
|
690 fManager.setSizeConstraints(100, 12, false, true);
|
|
691 }
|
|
692
|
|
693 /*
|
|
694 * @see dwtx.jface.text.hyperlink.DefaultHyperlinkPresenter#uninstall()
|
|
695 */
|
|
696 public void uninstall() {
|
|
697 super.uninstall();
|
|
698
|
|
699 if (fTextViewer !is null) {
|
|
700 fManager.dispose();
|
|
701
|
|
702 fTextViewer= null;
|
|
703 }
|
|
704 }
|
|
705
|
|
706 /*
|
|
707 * @see dwtx.jface.text.hyperlink.DefaultHyperlinkPresenter#canShowMultipleHyperlinks()
|
|
708 */
|
|
709 public bool canShowMultipleHyperlinks() {
|
|
710 return true;
|
|
711 }
|
|
712
|
|
713 /*
|
|
714 * @see dwtx.jface.text.hyperlink.DefaultHyperlinkPresenter#canHideHyperlinks()
|
|
715 */
|
|
716 public bool canHideHyperlinks() {
|
|
717 return !fManager.isInformationControlVisible();
|
|
718 }
|
|
719
|
|
720 /*
|
|
721 * @see dwtx.jface.text.hyperlink.DefaultHyperlinkPresenter#hideHyperlinks()
|
|
722 */
|
|
723 public void hideHyperlinks() {
|
|
724 super.hideHyperlinks();
|
|
725
|
|
726 fHyperlinks= null;
|
|
727 }
|
|
728
|
|
729 /*
|
|
730 * @see dwtx.jface.text.hyperlink.DefaultHyperlinkPresenter#showHyperlinks(dwtx.jface.text.hyperlink.IHyperlink[])
|
|
731 */
|
|
732 public void showHyperlinks(IHyperlink[] hyperlinks) {
|
|
733 super.showHyperlinks(new IHyperlink[] { hyperlinks[0] });
|
|
734
|
|
735 fSubjectRegion= null;
|
|
736 fHyperlinks= hyperlinks;
|
|
737
|
|
738 if (hyperlinks.length is 1)
|
|
739 return;
|
|
740
|
|
741 int start= hyperlinks[0].getHyperlinkRegion().getOffset();
|
|
742 int end= start + hyperlinks[0].getHyperlinkRegion().getLength();
|
|
743
|
|
744 for (int i= 1; i < hyperlinks.length; i++) {
|
|
745 int hstart= hyperlinks[i].getHyperlinkRegion().getOffset();
|
|
746 int hend= hstart + hyperlinks[i].getHyperlinkRegion().getLength();
|
|
747
|
|
748 start= Math.min(start, hstart);
|
|
749 end= Math.max(end, hend);
|
|
750 }
|
|
751
|
|
752 fSubjectRegion= new Region(start, end - start);
|
|
753
|
|
754 fManager.showInformation();
|
|
755 }
|
|
756 }
|