diff options
author | Marc Englund <marc.englund@itmill.com> | 2007-11-19 14:03:05 +0000 |
---|---|---|
committer | Marc Englund <marc.englund@itmill.com> | 2007-11-19 14:03:05 +0000 |
commit | f2e3722df9676436680afc0f1991e91e1696fb99 (patch) | |
tree | 6f255ff78abaf96f1e71a1f2c9ecd3b66647f4a2 /src/com/itmill/toolkit/tests/TestBench.java | |
parent | 93291f532db9d545cf2a8dd98e2671f27cd197b0 (diff) | |
download | vaadin-framework-f2e3722df9676436680afc0f1991e91e1696fb99.tar.gz vaadin-framework-f2e3722df9676436680afc0f1991e91e1696fb99.zip |
MASS REFORMAT.
According to http://toolkit.intra.itmill.com/trac/itmilltoolkit/wiki/CodingConventions
svn changeset:2864/svn branch:trunk
Diffstat (limited to 'src/com/itmill/toolkit/tests/TestBench.java')
-rw-r--r-- | src/com/itmill/toolkit/tests/TestBench.java | 355 |
1 files changed, 179 insertions, 176 deletions
diff --git a/src/com/itmill/toolkit/tests/TestBench.java b/src/com/itmill/toolkit/tests/TestBench.java index a112fd7ff1..a13518f1c7 100644 --- a/src/com/itmill/toolkit/tests/TestBench.java +++ b/src/com/itmill/toolkit/tests/TestBench.java @@ -11,6 +11,7 @@ import java.util.List; import com.itmill.toolkit.Application; import com.itmill.toolkit.data.Property; import com.itmill.toolkit.data.util.HierarchicalContainer; +import com.itmill.toolkit.terminal.Sizeable; import com.itmill.toolkit.ui.Component; import com.itmill.toolkit.ui.CustomComponent; import com.itmill.toolkit.ui.ExpandLayout; @@ -31,181 +32,183 @@ import com.itmill.toolkit.ui.Window; * */ public class TestBench extends com.itmill.toolkit.Application implements - Property.ValueChangeListener { - - // Add here packages which are used for finding testable classes - String[] testablePackages = { "com.itmill.toolkit.tests", - "com.itmill.toolkit.demo", "com.itmill.toolkit.demo.colorpicker", - "com.itmill.toolkit.demo.reservation", - "com.itmill.toolkit.demo.features" }; - - HierarchicalContainer testables = new HierarchicalContainer(); - - Window mainWindow = new Window("TestBench window"); - - // Main layout consists of tree menu and body layout - SplitPanel mainLayout = new SplitPanel(SplitPanel.ORIENTATION_HORIZONTAL); - - Tree menu; - - Panel bodyLayout = new Panel(); - - HashMap itemCaptions = new HashMap(); - - public void init() { - - // Add testable classes to hierarchical container - for (int p = 0; p < testablePackages.length; p++) { - testables.addItem(testablePackages[p]); - try { - List testableClasses = this - .getTestableClassesForPackage(testablePackages[p]); - for (Iterator it = testableClasses.iterator(); it.hasNext();) { - Class t = (Class) it.next(); - // ignore TestBench itself - if (t.equals(TestBench.class)) - continue; - try { - testables.addItem(t); - itemCaptions.put(t, t.getName()); - testables.setParent(t, testablePackages[p]); - continue; - } catch (Exception e) { - try { - testables.addItem(t); - itemCaptions.put(t, t.getName()); - testables.setParent(t, testablePackages[p]); - continue; - } catch (Exception e1) { - e1.printStackTrace(); - } - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - menu = new Tree("Testables", testables); - // simplify captions - for (Iterator i = itemCaptions.keySet().iterator(); i.hasNext();) { - Class testable = (Class) i.next(); - menu.setItemCaption(testable, testable.getName()); - } - menu.addListener(this); - menu.setImmediate(true); - - mainLayout.addComponent(menu); - - bodyLayout.addStyleName("light"); - bodyLayout.setHeight(100); - bodyLayout.setHeightUnits(Panel.UNITS_PERCENTAGE); - bodyLayout.setLayout(new ExpandLayout()); - - mainLayout.addComponent(bodyLayout); - - mainLayout.setSplitPosition(30); - - mainWindow.setLayout(mainLayout); - - setMainWindow(mainWindow); - } - - private Component createTestable(Class c) { - try { - Application app = (Application) c.newInstance(); - app.init(); - return app.getMainWindow().getLayout(); - } catch (Exception e) { - try { - CustomComponent cc = (CustomComponent) c.newInstance(); - return cc; - } catch (Exception e1) { - e1.printStackTrace(); - return new Label( - "Cannot create application / custom component: " - + e1.toString()); - } - } - } - - // Handle menu selection and update body - public void valueChange(Property.ValueChangeEvent event) { - bodyLayout.removeAllComponents(); - bodyLayout.setCaption(null); - - String title = ((Class) menu.getValue()).getName(); - bodyLayout.setCaption(title); - bodyLayout.addComponent(createTestable((Class) menu.getValue())); - } - - /** - * Return all testable classes within given package. Class is considered - * testable if it's superclass is Application or CustomComponent. - * - * @param packageName - * @return - * @throws ClassNotFoundException - */ - public static List getTestableClassesForPackage(String packageName) - throws Exception { - ArrayList directories = new ArrayList(); - try { - ClassLoader cld = Thread.currentThread().getContextClassLoader(); - if (cld == null) - throw new ClassNotFoundException("Can't get class loader."); - String path = packageName.replace('.', '/'); - // Ask for all resources for the path - Enumeration resources = cld.getResources(path); - while (resources.hasMoreElements()) { - URL url = (URL) resources.nextElement(); - directories.add(new File(url.getFile())); - } - } catch (Exception x) { - throw new Exception(packageName - + " does not appear to be a valid package."); - } - - ArrayList classes = new ArrayList(); - // For every directory identified capture all the .class files - for (Iterator it = directories.iterator(); it.hasNext();) { - File directory = (File) it.next(); - if (directory.exists()) { - // Get the list of the files contained in the package - String[] files = directory.list(); - for (int j = 0; j < files.length; j++) { - // we are only interested in .class files - if (files[j].endsWith(".class")) { - // removes the .class extension - String p = packageName + '.' - + files[j].substring(0, files[j].length() - 6); - Class c = Class.forName(p); - if (c.getSuperclass() != null) - if ((c.getSuperclass() - .equals(com.itmill.toolkit.Application.class))) { - classes.add(c); - } else if ((c.getSuperclass() - .equals(com.itmill.toolkit.ui.CustomComponent.class))) { - classes.add(c); - } - - // for (int i = 0; i < c.getInterfaces().length; i++) { - // Class cc = c.getInterfaces()[i]; - // if (c.getInterfaces()[i].equals(Testable.class)) { - // // Class is testable - // classes.add(c); - // } - // } - } - } - } else { - throw new ClassNotFoundException(packageName + " (" - + directory.getPath() - + ") does not appear to be a valid package"); - } - } - - return classes; - } + Property.ValueChangeListener { + + // Add here packages which are used for finding testable classes + String[] testablePackages = { "com.itmill.toolkit.tests", + "com.itmill.toolkit.demo", "com.itmill.toolkit.demo.colorpicker", + "com.itmill.toolkit.demo.reservation", + "com.itmill.toolkit.demo.features" }; + + HierarchicalContainer testables = new HierarchicalContainer(); + + Window mainWindow = new Window("TestBench window"); + + // Main layout consists of tree menu and body layout + SplitPanel mainLayout = new SplitPanel(SplitPanel.ORIENTATION_HORIZONTAL); + + Tree menu; + + Panel bodyLayout = new Panel(); + + HashMap itemCaptions = new HashMap(); + + public void init() { + + // Add testable classes to hierarchical container + for (int p = 0; p < testablePackages.length; p++) { + testables.addItem(testablePackages[p]); + try { + List testableClasses = getTestableClassesForPackage(testablePackages[p]); + for (Iterator it = testableClasses.iterator(); it.hasNext();) { + Class t = (Class) it.next(); + // ignore TestBench itself + if (t.equals(TestBench.class)) { + continue; + } + try { + testables.addItem(t); + itemCaptions.put(t, t.getName()); + testables.setParent(t, testablePackages[p]); + continue; + } catch (Exception e) { + try { + testables.addItem(t); + itemCaptions.put(t, t.getName()); + testables.setParent(t, testablePackages[p]); + continue; + } catch (Exception e1) { + e1.printStackTrace(); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + menu = new Tree("Testables", testables); + // simplify captions + for (Iterator i = itemCaptions.keySet().iterator(); i.hasNext();) { + Class testable = (Class) i.next(); + menu.setItemCaption(testable, testable.getName()); + } + menu.addListener(this); + menu.setImmediate(true); + + mainLayout.addComponent(menu); + + bodyLayout.addStyleName("light"); + bodyLayout.setHeight(100); + bodyLayout.setHeightUnits(Sizeable.UNITS_PERCENTAGE); + bodyLayout.setLayout(new ExpandLayout()); + + mainLayout.addComponent(bodyLayout); + + mainLayout.setSplitPosition(30); + + mainWindow.setLayout(mainLayout); + + setMainWindow(mainWindow); + } + + private Component createTestable(Class c) { + try { + Application app = (Application) c.newInstance(); + app.init(); + return app.getMainWindow().getLayout(); + } catch (Exception e) { + try { + CustomComponent cc = (CustomComponent) c.newInstance(); + return cc; + } catch (Exception e1) { + e1.printStackTrace(); + return new Label( + "Cannot create application / custom component: " + + e1.toString()); + } + } + } + + // Handle menu selection and update body + public void valueChange(Property.ValueChangeEvent event) { + bodyLayout.removeAllComponents(); + bodyLayout.setCaption(null); + + String title = ((Class) menu.getValue()).getName(); + bodyLayout.setCaption(title); + bodyLayout.addComponent(createTestable((Class) menu.getValue())); + } + + /** + * Return all testable classes within given package. Class is considered + * testable if it's superclass is Application or CustomComponent. + * + * @param packageName + * @return + * @throws ClassNotFoundException + */ + public static List getTestableClassesForPackage(String packageName) + throws Exception { + ArrayList directories = new ArrayList(); + try { + ClassLoader cld = Thread.currentThread().getContextClassLoader(); + if (cld == null) { + throw new ClassNotFoundException("Can't get class loader."); + } + String path = packageName.replace('.', '/'); + // Ask for all resources for the path + Enumeration resources = cld.getResources(path); + while (resources.hasMoreElements()) { + URL url = (URL) resources.nextElement(); + directories.add(new File(url.getFile())); + } + } catch (Exception x) { + throw new Exception(packageName + + " does not appear to be a valid package."); + } + + ArrayList classes = new ArrayList(); + // For every directory identified capture all the .class files + for (Iterator it = directories.iterator(); it.hasNext();) { + File directory = (File) it.next(); + if (directory.exists()) { + // Get the list of the files contained in the package + String[] files = directory.list(); + for (int j = 0; j < files.length; j++) { + // we are only interested in .class files + if (files[j].endsWith(".class")) { + // removes the .class extension + String p = packageName + '.' + + files[j].substring(0, files[j].length() - 6); + Class c = Class.forName(p); + if (c.getSuperclass() != null) { + if ((c.getSuperclass() + .equals(com.itmill.toolkit.Application.class))) { + classes.add(c); + } else if ((c.getSuperclass() + .equals(com.itmill.toolkit.ui.CustomComponent.class))) { + classes.add(c); + } + } + + // for (int i = 0; i < c.getInterfaces().length; i++) { + // Class cc = c.getInterfaces()[i]; + // if (c.getInterfaces()[i].equals(Testable.class)) { + // // Class is testable + // classes.add(c); + // } + // } + } + } + } else { + throw new ClassNotFoundException(packageName + " (" + + directory.getPath() + + ") does not appear to be a valid package"); + } + } + + return classes; + } } |