Source Code Cross Referenced for DialogCheck.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 junit.framework.Assert;
013:
014:        import org.eclipse.jface.dialogs.Dialog;
015:        import org.eclipse.jface.dialogs.IDialogConstants;
016:        import org.eclipse.swt.SWT;
017:        import org.eclipse.swt.graphics.Point;
018:        import org.eclipse.swt.widgets.Button;
019:        import org.eclipse.swt.widgets.Composite;
020:        import org.eclipse.swt.widgets.Control;
021:        import org.eclipse.swt.widgets.Label;
022:        import org.eclipse.swt.widgets.Shell;
023:        import org.eclipse.swt.widgets.TabFolder;
024:        import org.eclipse.ui.internal.WorkbenchPlugin;
025:        import org.eclipse.ui.tests.internal.util.VerifyDialog;
026:
027:        /**
028:         * A <code>DialogCheck</code> is used test a dialog in
029:         * various ways. 
030:         * <p>
031:         * For interactive tests use <code>assertDialog</code>.
032:         * For automated tests use <code>assert DialogTexts</code>.
033:         * </p> 
034:         */
035:        public class DialogCheck {
036:            private DialogCheck() {
037:            }
038:
039:            private static VerifyDialog _verifyDialog;
040:
041:            /**
042:             * Asserts that a given dialog is not null and that it passes
043:             * certain visual tests.  These tests will be verified manually
044:             * by the tester using an input dialog.  Use this assert method
045:             * to verify a dialog's sizing, initial focus, or accessiblity.
046:             * To ensure that both the input dialog and the test dialog are
047:             * accessible by the tester, the getShell() method should be used
048:             * when creating the test dialog.
049:             * 
050:             * Example usage:
051:             * <code>Dialog dialog = new AboutDialog( DialogCheck.getShell() );
052:             * DialogCheck.assertDialog(dialog, this);</code>
053:             * 
054:             * @param dialog the test dialog to be verified.
055:             * @param assert this is the test case object, assertions will be
056:             * executed on this object.
057:             */
058:            public static void assertDialog(Dialog dialog, Assert assertion) {
059:                Assert.assertNotNull(dialog);
060:                if (_verifyDialog.getShell() == null) {
061:                    //force the creation of the verify dialog
062:                    getShell();
063:                }
064:                if (_verifyDialog.open(dialog) == IDialogConstants.NO_ID) {
065:                    Assert.assertTrue(_verifyDialog.getFailureText(), false);
066:                }
067:            }
068:
069:            /**
070:             * Automated test that checks all the labels and buttons of a dialog
071:             * to make sure there is enough room to display all the text.  Any
072:             * text that wraps is only approximated and is currently not accurate.
073:             * 
074:             * @param dialog the test dialog to be verified.
075:             * @param assert this is the test case object, assertions will be
076:             * executed on this object.
077:             */
078:            public static void assertDialogTexts(Dialog dialog, Assert assertion) {
079:                Assert.assertNotNull(dialog);
080:                dialog.setBlockOnOpen(false);
081:                dialog.open();
082:                Shell shell = dialog.getShell();
083:                verifyCompositeText(shell, assertion);
084:                dialog.close();
085:            }
086:
087:            /**
088:             * This method should be called when creating dialogs to test.  This
089:             * ensures that the dialog's parent shell will be that of the
090:             * verification dialog.
091:             * 
092:             * @return Shell The shell of the verification dialog to be used as
093:             * the parent shell of the test dialog.
094:             */
095:            public static Shell getShell() {
096:                Shell shell = WorkbenchPlugin.getDefault().getWorkbench()
097:                        .getActiveWorkbenchWindow().getShell();
098:                _verifyDialog = new VerifyDialog(shell);
099:                _verifyDialog.create();
100:                return _verifyDialog.getShell();
101:            }
102:
103:            /*
104:             * Looks at all the child widgets of a given composite and
105:             * verifies the text on all labels and widgets.
106:             * @param composite The composite to look through
107:             * @param assert The object to invoke assertions on.
108:             */
109:            private static void verifyCompositeText(Composite composite,
110:                    Assert assertion) {
111:                Control children[] = composite.getChildren();
112:                for (int i = 0; i < children.length; i++) {
113:                    Control child = children[i];
114:                    if (child instanceof  TabFolder) {
115:                        TabFolder folder = (TabFolder) child;
116:                        int numPages = folder.getItemCount();
117:                        for (int j = 0; j < numPages; j++) {
118:                            folder.setSelection(j);
119:                        }
120:                    } else if (child instanceof  Button) {
121:                        //verify the text if the child is a button
122:                        verifyButtonText((Button) child, assertion);
123:                    } else if (child instanceof  Label) {
124:                        //child is not a button, maybe a label
125:                        verifyLabelText((Label) child, assertion);
126:                    } else if (child instanceof  Composite) {
127:                        //child is not a label, make a recursive call if it is a composite
128:                        verifyCompositeText((Composite) child, assertion);
129:                    }
130:                }
131:            }
132:
133:            /*
134:             * Verifies that a given button is large enough to display its text.
135:             * @param button The button to verify,
136:             * @param assert The object to invoke assertions on.
137:             */
138:            private static void verifyButtonText(Button button, Assert assertion) {
139:                String widget = button.toString();
140:                Point size = button.getSize();
141:
142:                //compute the size with no line wrapping
143:                Point preferred = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
144:                //if (size.y/preferred.y) == X, then label spans X lines, so divide
145:                //the calculated value of preferred.x by X
146:                if (preferred.y * size.y > 0) {
147:                    preferred.y /= countLines(button.getText()); //check for '\n\'
148:                    if (size.y / preferred.y > 1) {
149:                        preferred.x /= (size.y / preferred.y);
150:                    }
151:                }
152:
153:                String message = new StringBuffer("Warning: ").append(widget)
154:                        .append("\n\tActual Width -> ").append(size.x).append(
155:                                "\n\tRecommended Width -> ")
156:                        .append(preferred.x).toString();
157:                if (preferred.x > size.x) {
158:                    //close the dialog
159:                    button.getShell().dispose();
160:                    Assert.assertTrue(message.toString(), false);
161:                }
162:            }
163:
164:            /*
165:             * Verifies that a given label is large enough to display its text.
166:             * @param label The label to verify,
167:             * @param assert The object to invoke assertions on.
168:             */
169:            private static void verifyLabelText(Label label, Assert assertion) {
170:                String widget = label.toString();
171:                Point size = label.getSize();
172:
173:                //compute the size with no line wrapping
174:                Point preferred = label.computeSize(SWT.DEFAULT, SWT.DEFAULT);
175:                //if (size.y/preferred.y) == X, then label spans X lines, so divide
176:                //the calculated value of preferred.x by X
177:                if (preferred.y * size.y > 0) {
178:                    preferred.y /= countLines(label.getText());
179:                    if (size.y / preferred.y > 1) {
180:                        preferred.x /= (size.y / preferred.y);
181:                    }
182:                }
183:                String message = new StringBuffer("Warning: ").append(widget)
184:                        .append("\n\tActual Width -> ").append(size.x).append(
185:                                "\n\tRecommended Width -> ")
186:                        .append(preferred.x).toString();
187:                if (preferred.x > size.x) {
188:                    //close the dialog
189:                    label.getShell().dispose();
190:                    Assert.assertTrue(message.toString(), false);
191:                }
192:            }
193:
194:            /*
195:             * Counts the number of lines in a given String.
196:             * For example, if a string contains one (1) newline character,
197:             * a value of two (2) would be returned.
198:             * @param text The string to look through.
199:             * @return int the number of lines in text.
200:             */
201:            private static int countLines(String text) {
202:                int newLines = 1;
203:                for (int i = 0; i < text.length(); i++) {
204:                    if (text.charAt(i) == '\n') {
205:                        newLines++;
206:                    }
207:                }
208:                return newLines;
209:            }
210:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.