Source Code Cross Referenced for ActionUtil.java in  » IDE-Eclipse » ui » org » eclipse » ui » tests » harness » 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.tests.harness.util 
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.harness.util;
011:
012:        import java.lang.reflect.Method;
013:
014:        import junit.framework.Assert;
015:        import junit.framework.TestCase;
016:
017:        import org.eclipse.jface.action.ActionContributionItem;
018:        import org.eclipse.jface.action.IAction;
019:        import org.eclipse.jface.action.IContributionItem;
020:        import org.eclipse.jface.action.IMenuManager;
021:        import org.eclipse.jface.action.MenuManager;
022:        import org.eclipse.jface.action.SubContributionItem;
023:        import org.eclipse.ui.IWorkbenchWindow;
024:        import org.eclipse.ui.internal.WorkbenchWindow;
025:
026:        /**
027:         * <code>ActionUtil</code> contains methods to run actions
028:         * in the workbench.
029:         */
030:        public class ActionUtil {
031:
032:            /**
033:             * Runs an action contribution.
034:             * 
035:             * @param test the current test case
036:             * @param item an action contribution item
037:             */
038:            public static void runAction(TestCase test, IContributionItem item) {
039:                Assert.assertTrue(item instanceof  ActionContributionItem);
040:                ((ActionContributionItem) item).getAction().run();
041:            }
042:
043:            /**
044:             * Runs the first action found in a menu manager with a
045:             * particular label. 
046:             *
047:             * @param test the current test case
048:             * @param mgr the containing menu manager
049:             * @param label the action label
050:             */
051:            public static void runActionWithLabel(TestCase test,
052:                    IMenuManager mgr, String label) {
053:                IContributionItem[] items = mgr.getItems();
054:                for (int nX = 0; nX < items.length; nX++) {
055:                    IContributionItem item = items[nX];
056:                    if (item instanceof  SubContributionItem)
057:                        item = ((SubContributionItem) item).getInnerItem();
058:                    if (item instanceof  ActionContributionItem) {
059:                        IAction action = ((ActionContributionItem) item)
060:                                .getAction();
061:                        if (label.equals(action.getText())) {
062:                            action.run();
063:                            return;
064:                        }
065:                    }
066:                }
067:                Assert.fail("Unable to find action: " + label);
068:            }
069:
070:            /**
071:             * Runs the first action found in a window with a
072:             * particular label. 
073:             * 
074:             * @param test the current test case
075:             * @param win the containing window
076:             * @param label the action label
077:             */
078:            public static void runActionWithLabel(TestCase test,
079:                    IWorkbenchWindow win, String label) {
080:                WorkbenchWindow realWin = (WorkbenchWindow) win;
081:                IMenuManager mgr = realWin.getMenuManager();
082:                runActionWithLabel(test, mgr, label);
083:            }
084:
085:            /**
086:             * Runs an action identified by an id path in a 
087:             * menu manager.
088:             * 
089:             * @param test the current test case
090:             * @param mgr the containing menu manager
091:             * @param label the action label
092:             */
093:            public static void runActionUsingPath(TestCase test,
094:                    IMenuManager mgr, String idPath) {
095:                IContributionItem item = mgr.findUsingPath(idPath);
096:                Assert.assertNotNull(item);
097:                runAction(test, item);
098:            }
099:
100:            /**
101:             * Runs an action identified by an id path in a 
102:             * window.
103:             * 
104:             * @param test the current test case
105:             * @param win the containing window
106:             * @param label the action label
107:             */
108:            public static void runActionUsingPath(TestCase test,
109:                    IWorkbenchWindow win, String idPath) {
110:                WorkbenchWindow realWin = (WorkbenchWindow) win;
111:                IMenuManager mgr = realWin.getMenuManager();
112:                runActionUsingPath(test, mgr, idPath);
113:            }
114:
115:            /**
116:             * Returns the first action found in a menu manager with a
117:             * particular label. 
118:             *
119:             * @param mgr the containing menu manager
120:             * @param label the action label
121:             * @return the first action with the label, or <code>null</code>
122:             * 		if it is not found.
123:             */
124:            public static IAction getActionWithLabel(IMenuManager mgr,
125:                    String label) {
126:                IContributionItem[] items = mgr.getItems();
127:                for (int nX = 0; nX < items.length; nX++) {
128:                    IContributionItem item = items[nX];
129:                    if (item instanceof  SubContributionItem)
130:                        item = ((SubContributionItem) item).getInnerItem();
131:                    if (item instanceof  ActionContributionItem) {
132:                        IAction action = ((ActionContributionItem) item)
133:                                .getAction();
134:                        if (label.equals(action.getText())) {
135:                            return action;
136:                        }
137:                    }
138:                }
139:                return null;
140:            }
141:
142:            /**
143:             * Fire the "handleAboutToShow" method in a menu manager.
144:             * This triggers the same behavior as when a user opens a menu.
145:             * The menu to be populated with actions and those 
146:             * actions to be enacted in SWT widgets.
147:             * 
148:             * @param mgr the menu manager to open
149:             */
150:            public static void fireAboutToShow(MenuManager mgr)
151:                    throws Throwable {
152:                Class clazz = mgr.getClass();
153:                Method method = clazz.getDeclaredMethod("handleAboutToShow",
154:                        new Class[0]);
155:                method.setAccessible(true);
156:                method.invoke(mgr, new Object[0]);
157:            }
158:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.