Mercurial > projects > dwt-samples
comparison jface/snippets/viewers/Snippet011CustomTooltips.d @ 178:61dd51f8d45f
Added JFace snippet 11
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 01 Feb 2009 19:43:48 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
177:9940f681d053 | 178:61dd51f8d45f |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2006 Tom Schindl 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 * Tom Schindl - initial API and implementation | |
10 * IBM - Improvement for Bug 159625 [Snippets] Update Snippet011CustomTooltips to reflect new API | |
11 *******************************************************************************/ | |
12 | |
13 module org.eclipse.jface.snippets.viewers.Snippet011CustomTooltips; | |
14 | |
15 import dwt.dwthelper.utils; | |
16 | |
17 import dwtx.jface.viewers.CellLabelProvider; | |
18 import dwtx.jface.viewers.ColumnViewerToolTipSupport; | |
19 import dwtx.jface.viewers.IStructuredContentProvider; | |
20 import dwtx.jface.viewers.TableViewer; | |
21 import dwtx.jface.viewers.TableViewerColumn; | |
22 import dwtx.jface.viewers.Viewer; | |
23 import dwtx.jface.viewers.ViewerCell; | |
24 import dwtx.jface.window.ToolTip; | |
25 import dwt.DWT; | |
26 import dwt.graphics.Point; | |
27 import dwt.layout.FillLayout; | |
28 import dwt.widgets.Display; | |
29 import dwt.widgets.Shell; | |
30 | |
31 /** | |
32 * Explore New API: JFace custom tooltips drawing. | |
33 * | |
34 * @author Tom Schindl <tom.schindl@bestsolution.at> | |
35 * @since 3.3 | |
36 */ | |
37 public class Snippet011CustomTooltips { | |
38 private static class MyContentProvider : | |
39 IStructuredContentProvider { | |
40 | |
41 public Object[] getElements(Object inputElement) { | |
42 return stringcast( [ "one", "two", "three", "four", "five", "six", | |
43 "seven", "eight", "nine", "ten" ]); | |
44 } | |
45 | |
46 public void dispose() { | |
47 | |
48 } | |
49 | |
50 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { | |
51 | |
52 } | |
53 } | |
54 | |
55 /** | |
56 * @param args | |
57 */ | |
58 public static void main(char[][] args) { | |
59 final Display display = new Display(); | |
60 Shell shell = new Shell(display); | |
61 shell.setLayout(new FillLayout()); | |
62 | |
63 TableViewer v = new TableViewer(shell, DWT.FULL_SELECTION); | |
64 v.getTable().setLinesVisible(true); | |
65 v.getTable().setHeaderVisible(true); | |
66 v.setContentProvider(new MyContentProvider()); | |
67 ColumnViewerToolTipSupport.enableFor(v,ToolTip.NO_RECREATE); | |
68 | |
69 CellLabelProvider labelProvider = new class CellLabelProvider { | |
70 | |
71 public char[] getToolTipText(Object element) { | |
72 return "Tooltip (" ~ stringcast(element) ~ ")"; | |
73 } | |
74 | |
75 public Point getToolTipShift(Object object) { | |
76 return new Point(5, 5); | |
77 } | |
78 | |
79 public int getToolTipDisplayDelayTime(Object object) { | |
80 return 2000; | |
81 } | |
82 | |
83 public int getToolTipTimeDisplayed(Object object) { | |
84 return 5000; | |
85 } | |
86 | |
87 public void update(ViewerCell cell) { | |
88 cell.setText( cell.getElement().toString()); | |
89 | |
90 } | |
91 }; | |
92 | |
93 TableViewerColumn column = new TableViewerColumn(v, DWT.NONE); | |
94 column.setLabelProvider(labelProvider); | |
95 column.getColumn().setText("Column 1"); | |
96 column.getColumn().setWidth(100); | |
97 | |
98 v.setInput( new Object() ); | |
99 | |
100 shell.setSize(200, 200); | |
101 shell.open(); | |
102 | |
103 while (!shell.isDisposed()) { | |
104 if (!display.readAndDispatch()) { | |
105 display.sleep(); | |
106 } | |
107 } | |
108 | |
109 display.dispose(); | |
110 } | |
111 | |
112 } | |
113 | |
114 void main(){ | |
115 Snippet011CustomTooltips.main( null ); | |
116 } | |
117 |