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