Source Code Cross Referenced for ColumnViewerToolTipSupport.java in  » IDE-Eclipse » jface » org » eclipse » jface » viewers » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » jface » org.eclipse.jface.viewers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2006, 2007 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *     Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
011:         *     Fredy Dobler <fredy@dobler.net> - bug 159600
012:         *     Brock Janiczak <brockj@tpg.com.au> - bug 182443
013:         *******************************************************************************/package org.eclipse.jface.viewers;
014:
015:        import org.eclipse.jface.util.Policy;
016:        import org.eclipse.jface.window.DefaultToolTip;
017:        import org.eclipse.jface.window.ToolTip;
018:        import org.eclipse.swt.SWT;
019:        import org.eclipse.swt.graphics.Image;
020:        import org.eclipse.swt.graphics.Point;
021:        import org.eclipse.swt.widgets.Event;
022:
023:        /**
024:         * The ColumnViewerTooltipSupport is the class that provides tool tips for ColumnViewers.
025:         * 
026:         * @since 3.3
027:         * 
028:         */
029:        public class ColumnViewerToolTipSupport extends DefaultToolTip {
030:            private ColumnViewer viewer;
031:
032:            private static final String LABEL_PROVIDER_KEY = Policy.JFACE
033:                    + "_LABEL_PROVIDER"; //$NON-NLS-1$
034:
035:            private static final String ELEMENT_KEY = Policy.JFACE
036:                    + "_ELEMENT_KEY"; //$NON-NLS-1$
037:
038:            private static final int DEFAULT_SHIFT_X = 10;
039:
040:            private static final int DEFAULT_SHIFT_Y = 0;
041:
042:            /**
043:             * Enable ToolTip support for the viewer by creating an instance from this
044:             * class. To get all necessary informations this support class consults the
045:             * {@link CellLabelProvider}.
046:             * 
047:             * @param viewer
048:             *            the viewer the support is attached to
049:             * @param style style passed to control tool tip behavior
050:             * 
051:             * @param manualActivation
052:             *            <code>true</code> if the activation is done manually using
053:             *            {@link #show(Point)}
054:             */
055:            protected ColumnViewerToolTipSupport(ColumnViewer viewer,
056:                    int style, boolean manualActivation) {
057:                super (viewer.getControl(), style, manualActivation);
058:                this .viewer = viewer;
059:            }
060:
061:            /**
062:             * Enable ToolTip support for the viewer by creating an instance from this
063:             * class. To get all necessary informations this support class consults the
064:             * {@link CellLabelProvider}.
065:             * 
066:             * @param viewer
067:             *            the viewer the support is attached to
068:             */
069:            public static void enableFor(ColumnViewer viewer) {
070:                new ColumnViewerToolTipSupport(viewer, ToolTip.NO_RECREATE,
071:                        false);
072:            }
073:
074:            /**
075:             * Enable ToolTip support for the viewer by creating an instance from this
076:             * class. To get all necessary informations this support class consults the
077:             * {@link CellLabelProvider}.
078:             * 
079:             * @param viewer
080:             *            the viewer the support is attached to
081:             * @param style style passed to control tool tip behavior
082:             * 
083:             * @see ToolTip#RECREATE
084:             * @see ToolTip#NO_RECREATE
085:             */
086:            public static void enableFor(ColumnViewer viewer, int style) {
087:                new ColumnViewerToolTipSupport(viewer, style, false);
088:            }
089:
090:            protected Object getToolTipArea(Event event) {
091:                return viewer.getCell(new Point(event.x, event.y));
092:            }
093:
094:            protected final boolean shouldCreateToolTip(Event event) {
095:                if (!super .shouldCreateToolTip(event)) {
096:                    return false;
097:                }
098:
099:                boolean rv = false;
100:
101:                ViewerRow row = viewer
102:                        .getViewerRow(new Point(event.x, event.y));
103:
104:                viewer.getControl().setToolTipText(""); //$NON-NLS-1$
105:                Point point = new Point(event.x, event.y);
106:
107:                if (row != null) {
108:                    Object element = row.getItem().getData();
109:
110:                    ViewerColumn viewPart = viewer.getViewerColumn(row
111:                            .getColumnIndex(point));
112:
113:                    if (viewPart == null) {
114:                        return false;
115:                    }
116:
117:                    CellLabelProvider labelProvider = viewPart
118:                            .getLabelProvider();
119:                    boolean useNative = labelProvider.useNativeToolTip(element);
120:
121:                    String text = labelProvider.getToolTipText(element);
122:                    Image img = null;
123:
124:                    if (!useNative) {
125:                        img = labelProvider.getToolTipImage(element);
126:                    }
127:
128:                    if (useNative || (text == null && img == null)) {
129:                        viewer.getControl().setToolTipText(text);
130:                        rv = false;
131:                    } else {
132:                        setPopupDelay(labelProvider
133:                                .getToolTipDisplayDelayTime(element));
134:                        setHideDelay(labelProvider
135:                                .getToolTipTimeDisplayed(element));
136:
137:                        Point shift = labelProvider.getToolTipShift(element);
138:
139:                        if (shift == null) {
140:                            setShift(new Point(DEFAULT_SHIFT_X, DEFAULT_SHIFT_Y));
141:                        } else {
142:                            setShift(new Point(shift.x, shift.y));
143:                        }
144:
145:                        setData(LABEL_PROVIDER_KEY, labelProvider);
146:                        setData(ELEMENT_KEY, element);
147:
148:                        setText(text);
149:                        setImage(img);
150:                        setStyle(labelProvider.getToolTipStyle(element));
151:                        setForegroundColor(labelProvider
152:                                .getToolTipForegroundColor(element));
153:                        setBackgroundColor(labelProvider
154:                                .getToolTipBackgroundColor(element));
155:                        setFont(labelProvider.getToolTipFont(element));
156:
157:                        // Check if at least one of the values is set
158:                        rv = getText(event) != null || getImage(event) != null;
159:                    }
160:                }
161:
162:                return rv;
163:            }
164:
165:            protected void afterHideToolTip(Event event) {
166:                if (event != null && event.widget != viewer.getControl()) {
167:                    if (event.type == SWT.MouseDown) {
168:                        viewer.setSelection(new StructuredSelection());
169:                    } else {
170:                        viewer.getControl().setFocus();
171:                    }
172:                }
173:            }
174:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.