Source Code Cross Referenced for Util.java in  » IDE-Eclipse » ui » org » eclipse » ui » internal » intro » impl » util » 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 » ui » org.eclipse.ui.internal.intro.impl.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2004, 2005 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:         *******************************************************************************/package org.eclipse.ui.internal.intro.impl.util;
011:
012:        import java.net.MalformedURLException;
013:        import java.net.URL;
014:
015:        import org.eclipse.core.runtime.CoreException;
016:        import org.eclipse.osgi.util.NLS;
017:        import org.eclipse.swt.SWT;
018:        import org.eclipse.swt.widgets.Control;
019:        import org.eclipse.swt.widgets.Display;
020:        import org.eclipse.swt.widgets.Event;
021:        import org.eclipse.swt.widgets.Listener;
022:        import org.eclipse.swt.widgets.Shell;
023:        import org.eclipse.ui.PartInitException;
024:        import org.eclipse.ui.PlatformUI;
025:        import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
026:
027:        public class Util {
028:
029:            /**
030:             * Handle the exception by logging to the Log. <br>
031:             * Variables are subsituted in the message.
032:             */
033:            public static void handleException(String msg, Exception e,
034:                    Object[] variables) {
035:                if (msg == null)
036:                    return;
037:                if (variables != null) {
038:                    // if variables is not null, errorId will never be null.
039:                    msg = NLS.bind(msg, variables);
040:                }
041:                Log.error(msg, e);
042:            }
043:
044:            /**
045:             * Handle the exception by displaying an Error Dialog. <br>
046:             * Also, the error is logged by the Log.
047:             */
048:            public static void handleExceptionWithPopUp(Shell parent,
049:                    String msg, Exception e) {
050:                // if it is a core exception, use ErrorDialog. If the error id is null
051:                // this translates to giving null to this dialog which is handled by
052:                // Eclipse by displaying the detyailed message directly.
053:                if (e instanceof  CoreException) {
054:                    if (parent == null)
055:                        parent = DialogUtil.getActiveShell();
056:                    DialogUtil.displayCoreErrorDialog(parent, msg,
057:                            (CoreException) e);
058:
059:                    return;
060:                }
061:
062:                // any other exception, use MessageDialog.
063:                // if errorID is null, use error message.
064:                if (msg == null)
065:                    msg = e.getMessage();
066:                if (parent == null)
067:                    parent = DialogUtil.getActiveShell();
068:                DialogUtil.displayErrorMessage(parent, msg, e);
069:            }
070:
071:            /**
072:             * Utility method that will add a debug listener to the given control. All
073:             * common events are added.
074:             * 
075:             * @param control
076:             * @return
077:             */
078:            public static Listener addDebugListener(Control control) {
079:                Listener listener = new Listener() {
080:
081:                    public void handleEvent(Event e) {
082:                        switch (e.type) {
083:                        case SWT.Selection:
084:                            System.out
085:                                    .println("Selection EVENT: " + e.toString()); //$NON-NLS-1$
086:                            break;
087:                        case SWT.Dispose:
088:                            System.out
089:                                    .println("Dispose EVENT: " + e.toString()); //$NON-NLS-1$
090:                            break;
091:                        case SWT.Paint:
092:                            System.out.println("Paint EVENT: " + e.toString()); //$NON-NLS-1$
093:                            break;
094:                        case SWT.Resize:
095:                            System.out.println("Resize EVENT: " + e.toString()); //$NON-NLS-1$
096:                            break;
097:                        case SWT.MouseDoubleClick:
098:                            System.out.println("MouseDoubleClick EVENT: " //$NON-NLS-1$
099:                                    + e.toString());
100:                            break;
101:                        case SWT.MouseDown:
102:                            System.out
103:                                    .println("MouseDown EVENT: " + e.toString()); //$NON-NLS-1$
104:                            break;
105:                        case SWT.MouseUp:
106:                            System.out
107:                                    .println("MouseUp EVENT: " + e.toString()); //$NON-NLS-1$
108:                            break;
109:                        case SWT.MouseMove:
110:                            System.out
111:                                    .println("MouseMove EVENT: " + e.toString()); //$NON-NLS-1$
112:                            break;
113:                        case SWT.MouseEnter:
114:                            System.out
115:                                    .println("MouseEnter EVENT: " + e.toString()); //$NON-NLS-1$
116:                            break;
117:                        case SWT.MouseExit:
118:                            System.out
119:                                    .println("MouseExit EVENT: " + e.toString()); //$NON-NLS-1$
120:                            break;
121:                        case SWT.MouseHover:
122:                            System.out
123:                                    .println("MouseHover EVENT: " + e.toString()); //$NON-NLS-1$
124:                            break;
125:                        case SWT.FocusIn:
126:                            System.out
127:                                    .println("FocusIn EVENT: " + e.toString()); //$NON-NLS-1$
128:                            break;
129:                        case SWT.FocusOut:
130:                            System.out
131:                                    .println("FocusOut EVENT: " + e.toString()); //$NON-NLS-1$
132:                            break;
133:                        case SWT.KeyDown:
134:                            System.out
135:                                    .println("KeyDown EVENT: " + e.toString()); //$NON-NLS-1$
136:                            break;
137:                        case SWT.KeyUp:
138:                            System.out.println("KeyUp EVENT: " + e.toString()); //$NON-NLS-1$
139:                            break;
140:                        case SWT.Traverse:
141:                            System.out
142:                                    .println("Traverse EVENT: " + e.toString()); //$NON-NLS-1$
143:                            break;
144:                        case SWT.Show:
145:                            System.out.println("Show EVENT: " + e.toString()); //$NON-NLS-1$
146:                            break;
147:                        case SWT.Hide:
148:                            System.out.println("Hide EVENT: " + e.toString()); //$NON-NLS-1$
149:                            break;
150:                        default:
151:                            System.out.println(e.toString());
152:                        }
153:                    }
154:                };
155:                int[] allEvents = new int[] { SWT.Selection, SWT.Dispose,
156:                        SWT.Paint, SWT.Resize, SWT.MouseDoubleClick,
157:                        SWT.MouseDown,
158:                        SWT.MouseUp,
159:                        // SWT.MouseMove,
160:                        SWT.MouseEnter, SWT.MouseExit, SWT.MouseHover,
161:                        SWT.FocusIn, SWT.FocusOut, SWT.KeyDown, SWT.KeyUp,
162:                        SWT.Traverse, SWT.Show, SWT.Hide };
163:                for (int i = 0; i < allEvents.length; i++) {
164:                    control.addListener(allEvents[i], listener);
165:                }
166:                return listener;
167:            }
168:
169:            public static void sleep(int delay) {
170:                try {
171:                    Thread.sleep(delay);
172:                } catch (InterruptedException e) {
173:                    // no-op
174:                }
175:            }
176:
177:            public static void highlight(Control control, int color) {
178:                control.setBackground(control.getDisplay()
179:                        .getSystemColor(color));
180:            }
181:
182:            public static void highlightFocusControl() {
183:                Control control = Display.getCurrent().getFocusControl();
184:                if (control != null)
185:                    control.setBackground(Display.getCurrent().getSystemColor(
186:                            SWT.COLOR_DARK_RED));
187:            }
188:
189:            /**
190:             * Launch an external brwoser on the given url.
191:             */
192:            public static boolean openBrowser(String href) {
193:                try {
194:                    URL url = new URL(href);
195:                    IWorkbenchBrowserSupport support = PlatformUI
196:                            .getWorkbench().getBrowserSupport();
197:                    support.getExternalBrowser().openURL(url);
198:                    return true;
199:                } catch (PartInitException e) {
200:                    Log.error("Intro failed to get Browser support.", e); //$NON-NLS-1$
201:                    return false;
202:                } catch (MalformedURLException e) {
203:                    Log.error("Intro failed to display: " + href, e); //$NON-NLS-1$
204:                    return false;
205:                }
206:            }
207:
208:            public static void logPerformanceTime(String message, long startTime) {
209:                long endTime = System.currentTimeMillis();
210:                Log
211:                        .forcedInfo("Intro Performance - " + message + (endTime - startTime) //$NON-NLS-1$
212:                                + "ms"); //$NON-NLS-1$
213:            }
214:
215:            public static void logPerformanceMessage(String message, long time) {
216:                Log
217:                        .forcedInfo("Intro Performance - " + message + " " + time + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
218:            }
219:
220:        }
w___ww__.j_a_va___2_s__.__c__om__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.