Source Code Cross Referenced for EditorTestHelper.java in  » IDE-Eclipse » ui » org » eclipse » ui » tests » navigator » 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.tests.navigator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2006 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.tests.navigator;
011:
012:        import java.util.ArrayList;
013:        import java.util.List;
014:        import java.util.logging.Logger;
015:
016:        import org.eclipse.core.resources.IContainer;
017:        import org.eclipse.core.resources.IFile;
018:        import org.eclipse.core.resources.IResource;
019:        import org.eclipse.core.resources.ResourcesPlugin;
020:        import org.eclipse.core.runtime.CoreException;
021:        import org.eclipse.core.runtime.Platform;
022:        import org.eclipse.core.runtime.jobs.IJobManager;
023:        import org.eclipse.core.runtime.jobs.Job;
024:        import org.eclipse.swt.widgets.Display;
025:        import org.eclipse.swt.widgets.Shell;
026:        import org.eclipse.ui.IEditorPart;
027:        import org.eclipse.ui.IEditorReference;
028:        import org.eclipse.ui.IViewReference;
029:        import org.eclipse.ui.IWorkbench;
030:        import org.eclipse.ui.IWorkbenchPage;
031:        import org.eclipse.ui.IWorkbenchPart;
032:        import org.eclipse.ui.IWorkbenchPartSite;
033:        import org.eclipse.ui.IWorkbenchWindow;
034:        import org.eclipse.ui.PartInitException;
035:        import org.eclipse.ui.PlatformUI;
036:        import org.eclipse.ui.WorkbenchException;
037:
038:        /**
039:         * @since 3.1
040:         */
041:        public class EditorTestHelper {
042:
043:            public static final String TEXT_EDITOR_ID = "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$
044:
045:            public static final String COMPILATION_UNIT_EDITOR_ID = "org.eclipse.jdt.ui.CompilationUnitEditor"; //$NON-NLS-1$
046:
047:            public static final String RESOURCE_PERSPECTIVE_ID = "org.eclipse.ui.resourcePerspective"; //$NON-NLS-1$
048:
049:            public static final String JAVA_PERSPECTIVE_ID = "org.eclipse.jdt.ui.JavaPerspective"; //$NON-NLS-1$
050:
051:            public static final String OUTLINE_VIEW_ID = "org.eclipse.ui.views.ContentOutline"; //$NON-NLS-1$
052:
053:            public static final String PACKAGE_EXPLORER_VIEW_ID = "org.eclipse.jdt.ui.PackageExplorer"; //$NON-NLS-1$
054:
055:            public static final String NAVIGATOR_VIEW_ID = "org.eclipse.ui.views.ResourceNavigator"; //$NON-NLS-1$
056:
057:            public static final String INTRO_VIEW_ID = "org.eclipse.ui.internal.introview"; //$NON-NLS-1$
058:
059:            public static void closeEditor(IEditorPart editor) {
060:                IWorkbenchPartSite site;
061:                IWorkbenchPage page;
062:                if (editor != null && (site = editor.getSite()) != null
063:                        && (page = site.getPage()) != null)
064:                    page.closeEditor(editor, false);
065:            }
066:
067:            public static void closeAllEditors() {
068:                IWorkbenchWindow[] windows = PlatformUI.getWorkbench()
069:                        .getWorkbenchWindows();
070:                for (int i = 0; i < windows.length; i++) {
071:                    IWorkbenchPage[] pages = windows[i].getPages();
072:                    for (int j = 0; j < pages.length; j++) {
073:                        IEditorReference[] editorReferences = pages[j]
074:                                .getEditorReferences();
075:                        for (int k = 0; k < editorReferences.length; k++)
076:                            closeEditor(editorReferences[k].getEditor(false));
077:                    }
078:                }
079:            }
080:
081:            /**
082:             * Runs the event queue on the current display until it is empty.
083:             */
084:            public static void runEventQueue() {
085:                IWorkbenchWindow window = getActiveWorkbenchWindow();
086:                if (window != null)
087:                    runEventQueue(window.getShell());
088:            }
089:
090:            public static void runEventQueue(IWorkbenchPart part) {
091:                runEventQueue(part.getSite().getShell());
092:            }
093:
094:            public static void runEventQueue(Shell shell) {
095:                runEventQueue(shell.getDisplay());
096:            }
097:
098:            public static void runEventQueue(Display display) {
099:                while (display.readAndDispatch()) {
100:                    // do nothing
101:                }
102:            }
103:
104:            /**
105:             * Runs the event queue on the current display and lets it sleep until the
106:             * timeout elapses.
107:             * 
108:             * @param millis the timeout in milliseconds
109:             */
110:            public static void runEventQueue(long millis) {
111:                runEventQueue(getActiveDisplay(), millis);
112:            }
113:
114:            public static void runEventQueue(IWorkbenchPart part, long millis) {
115:                runEventQueue(part.getSite().getShell(), millis);
116:            }
117:
118:            public static void runEventQueue(Shell shell, long millis) {
119:                runEventQueue(shell.getDisplay(), millis);
120:            }
121:
122:            public static void runEventQueue(Display display, long minTime) {
123:                if (display != null) {
124:                    DisplayHelper.sleep(display, minTime);
125:                } else {
126:                    sleep((int) minTime);
127:                }
128:            }
129:
130:            public static IWorkbenchWindow getActiveWorkbenchWindow() {
131:                return PlatformUI.getWorkbench().getActiveWorkbenchWindow();
132:            }
133:
134:            public static void forceFocus() {
135:                IWorkbenchWindow window = getActiveWorkbenchWindow();
136:                if (window == null) {
137:                    IWorkbenchWindow[] wbWindows = PlatformUI.getWorkbench()
138:                            .getWorkbenchWindows();
139:                    if (wbWindows.length == 0)
140:                        return;
141:                    window = wbWindows[0];
142:                }
143:                Shell shell = window.getShell();
144:                if (shell != null && !shell.isDisposed()) {
145:                    shell.forceActive();
146:                    shell.forceFocus();
147:                }
148:            }
149:
150:            public static IWorkbenchPage getActivePage() {
151:                IWorkbenchWindow window = getActiveWorkbenchWindow();
152:                return window != null ? window.getActivePage() : null;
153:            }
154:
155:            public static Display getActiveDisplay() {
156:                IWorkbenchWindow window = getActiveWorkbenchWindow();
157:                return window != null ? window.getShell().getDisplay() : null;
158:            }
159:
160:            public static void joinBackgroundActivities() throws CoreException {
161:                // Join Building
162:                Logger.global.entering(
163:                        "EditorTestHelper", "joinBackgroundActivities"); //$NON-NLS-1$ //$NON-NLS-2$
164:                Logger.global.finer("join builder"); //$NON-NLS-1$
165:                boolean interrupted = true;
166:                while (interrupted) {
167:                    try {
168:                        Platform.getJobManager().join(
169:                                ResourcesPlugin.FAMILY_AUTO_BUILD, null);
170:                        interrupted = false;
171:                    } catch (InterruptedException e) {
172:                        interrupted = true;
173:                    }
174:                }
175:                // Join jobs
176:                joinJobs(0, 0, 500);
177:                Logger.global.exiting(
178:                        "EditorTestHelper", "joinBackgroundActivities"); //$NON-NLS-1$ //$NON-NLS-2$
179:            }
180:
181:            public static boolean joinJobs(long minTime, long maxTime,
182:                    long intervalTime) {
183:                Logger.global.entering("EditorTestHelper", "joinJobs"); //$NON-NLS-1$ //$NON-NLS-2$
184:                runEventQueue(minTime);
185:
186:                DisplayHelper helper = new DisplayHelper() {
187:                    public boolean condition() {
188:                        return allJobsQuiet();
189:                    }
190:                };
191:                boolean quiet = helper.waitForCondition(getActiveDisplay(),
192:                        maxTime > 0 ? maxTime : Long.MAX_VALUE, intervalTime);
193:                Logger.global.exiting(
194:                        "EditorTestHelper", "joinJobs", new Boolean(quiet)); //$NON-NLS-1$ //$NON-NLS-2$
195:                return quiet;
196:            }
197:
198:            public static void sleep(int intervalTime) {
199:                try {
200:                    Thread.sleep(intervalTime);
201:                } catch (InterruptedException e) {
202:                    e.printStackTrace();
203:                }
204:            }
205:
206:            public static boolean allJobsQuiet() {
207:                IJobManager jobManager = Platform.getJobManager();
208:                Job[] jobs = jobManager.find(null);
209:                for (int i = 0; i < jobs.length; i++) {
210:                    Job job = jobs[i];
211:                    int state = job.getState();
212:                    if (state == Job.RUNNING || state == Job.WAITING) {
213:                        Logger.global.finest(job.getName());
214:                        return false;
215:                    }
216:                }
217:                return true;
218:            }
219:
220:            public static boolean isViewShown(String viewId) {
221:                return getActivePage().findViewReference(viewId) != null;
222:            }
223:
224:            public static boolean showView(String viewId, boolean show)
225:                    throws PartInitException {
226:                IWorkbenchPage activePage = getActivePage();
227:                IViewReference view = activePage.findViewReference(viewId);
228:                boolean shown = view != null;
229:                if (shown != show)
230:                    if (show)
231:                        activePage.showView(viewId);
232:                    else
233:                        activePage.hideView(view);
234:                return shown;
235:            }
236:
237:            public static void bringToTop() {
238:                getActiveWorkbenchWindow().getShell().forceActive();
239:            }
240:
241:            public static String showPerspective(String perspective)
242:                    throws WorkbenchException {
243:                String shownPerspective = getActivePage().getPerspective()
244:                        .getId();
245:                if (!perspective.equals(shownPerspective)) {
246:                    IWorkbench workbench = PlatformUI.getWorkbench();
247:                    IWorkbenchWindow activeWindow = workbench
248:                            .getActiveWorkbenchWindow();
249:                    workbench.showPerspective(perspective, activeWindow);
250:                }
251:                return shownPerspective;
252:            }
253:
254:            public static IFile[] findFiles(IResource resource)
255:                    throws CoreException {
256:                List files = new ArrayList();
257:                findFiles(resource, files);
258:                return (IFile[]) files.toArray(new IFile[files.size()]);
259:            }
260:
261:            private static void findFiles(IResource resource, List files)
262:                    throws CoreException {
263:                if (resource instanceof  IFile) {
264:                    files.add(resource);
265:                    return;
266:                }
267:                if (resource instanceof  IContainer) {
268:                    IResource[] resources = ((IContainer) resource).members();
269:                    for (int i = 0; i < resources.length; i++)
270:                        findFiles(resources[i], files);
271:                }
272:            }
273:
274:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.