diff options
author | Henri Sara <henri.sara@itmill.com> | 2009-03-25 07:33:58 +0000 |
---|---|---|
committer | Henri Sara <henri.sara@itmill.com> | 2009-03-25 07:33:58 +0000 |
commit | 2b04235d71fb31140f687e0ef80208b731fab1d8 (patch) | |
tree | 01129a8ad558d843fbf1dad97c387ba32d25772d /src/com/itmill/toolkit/tests/TestBench.java | |
parent | 9004b0df409cc2fa4700d05eaa356f4ecc9efe7e (diff) | |
download | vaadin-framework-2b04235d71fb31140f687e0ef80208b731fab1d8.tar.gz vaadin-framework-2b04235d71fb31140f687e0ef80208b731fab1d8.zip |
Merge from 5.3 to 6.0:
[7128] Fixes to merge tool.
[7129] Merge from branches/manual_2009_03 to versions/5.3 (multiple changesets)
[7131] Fixed language problems in the section on layout cell spacing.
[7132] Use 24 hour format instead of 12 hour for Eclipse Manual plugin timestamp.
svn changeset:7169/svn branch:6.0
Diffstat (limited to 'src/com/itmill/toolkit/tests/TestBench.java')
-rw-r--r-- | src/com/itmill/toolkit/tests/TestBench.java | 574 |
1 files changed, 287 insertions, 287 deletions
diff --git a/src/com/itmill/toolkit/tests/TestBench.java b/src/com/itmill/toolkit/tests/TestBench.java index 99e770f487..1ea727a8a3 100644 --- a/src/com/itmill/toolkit/tests/TestBench.java +++ b/src/com/itmill/toolkit/tests/TestBench.java @@ -41,292 +41,292 @@ import com.itmill.toolkit.ui.UriFragmentUtility.FragmentChangedEvent; * */ 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", - "com.itmill.toolkit.tests.tickets" }; - - 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(); - - @Override - public void init() { - - // Add testable classes to hierarchical container - for (int p = 0; p < testablePackages.length; p++) { - testables.addItem(testablePackages[p]); - try { - final List testableClasses = getTestableClassesForPackage(testablePackages[p]); - for (final Iterator it = testableClasses.iterator(); it - .hasNext();) { - final 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]); - testables.setChildrenAllowed(t, false); - continue; - } catch (final Exception e) { - try { - testables.addItem(t); - itemCaptions.put(t, t.getName()); - testables.setParent(t, testablePackages[p]); - testables.setChildrenAllowed(t, false); - continue; - } catch (final Exception e1) { - e1.printStackTrace(); - } - } - } - } catch (final Exception e) { - e.printStackTrace(); - } - } - - menu = new Tree("Testables", testables); - - for (final Iterator i = itemCaptions.keySet().iterator(); i.hasNext();) { - final Class testable = (Class) i.next(); - // simplify captions - final String name = testable.getName().substring( - testable.getName().lastIndexOf('.') + 1); - menu.setItemCaption(testable, name); - } - // expand all root items - for (final Iterator i = menu.rootItemIds().iterator(); i.hasNext();) { - menu.expandItemsRecursively(i.next()); - } - - menu.addListener(this); - menu.setImmediate(true); - menu.setNullSelectionAllowed(false); - VerticalLayout lo = new VerticalLayout(); - lo.addComponent(menu); - - UriFragmentUtility uri = new UriFragmentUtility(); - lo.addComponent(uri); - - uri.addListener(new UriFragmentUtility.FragmentChangedListener() { - public void fragmentChanged(FragmentChangedEvent source) { - String fragment = source.getUriFragmentUtility().getFragment(); - if (fragment != null && !"".equals(fragment)) { - // try to find a proper test class - - // exact match - Iterator iterator = menu.getItemIds().iterator(); - while (iterator.hasNext()) { - Object next = iterator.next(); - if (next instanceof Class) { - Class c = (Class) next; - String string = c.getName(); - if (string.equals(fragment)) { - menu.setValue(c); - mainLayout.setSplitPosition(0); - return; - } - } - } - - // simple name match - iterator = menu.getItemIds().iterator(); - while (iterator.hasNext()) { - Object next = iterator.next(); - if (next instanceof Class) { - Class c = (Class) next; - String string = c.getSimpleName(); - if (string.equals(fragment)) { - menu.setValue(c); - mainLayout.setSplitPosition(0); - return; - } - } - } - // ticket match - iterator = menu.getItemIds().iterator(); - while (iterator.hasNext()) { - Object next = iterator.next(); - if (next instanceof Class) { - Class c = (Class) next; - String string = c.getSimpleName(); - if (string.startsWith("Ticket" + fragment)) { - menu.setValue(c); - mainLayout.setSplitPosition(0); - return; - } - } - } - - // just partly mach lowercase - iterator = menu.getItemIds().iterator(); - while (iterator.hasNext()) { - Object next = iterator.next(); - if (next instanceof Class) { - Class c = (Class) next; - String string = c.getSimpleName(); - if (string.toLowerCase().contains( - fragment.toLowerCase())) { - menu.setValue(c); - mainLayout.setSplitPosition(0); - return; - } - } - } - - getMainWindow().showNotification( - "No potential matc for #" + fragment); - - } - - } - }); - - mainLayout.addComponent(lo); - - bodyLayout.addStyleName("light"); - bodyLayout.setSizeFull(); - bodyLayout.setLayout(new ExpandLayout()); - - mainLayout.addComponent(bodyLayout); - - mainLayout.setSplitPosition(30); - - mainWindow.setLayout(mainLayout); - - setMainWindow(mainWindow); - } - - private Component createTestable(Class c) { - try { - final Application app = (Application) c.newInstance(); - app.init(); - Layout lo = app.getMainWindow().getLayout(); - lo.setParent(null); - return lo; - } catch (final Exception e) { - try { - final CustomComponent cc = (CustomComponent) c.newInstance(); - cc.setSizeFull(); - return cc; - } catch (final Exception e1) { - e1.printStackTrace(); - VerticalLayout lo = new VerticalLayout(); - lo.addComponent(new Label( - "Cannot create application / custom component: " - + e1.toString())); - - Link l = new Link("Try opening via app runner", - new ExternalResource("../run/" + c.getName())); - lo.addComponent(l); - - return lo; - } - } - } - - // Handle menu selection and update body - public void valueChange(Property.ValueChangeEvent event) { - bodyLayout.removeAllComponents(); - bodyLayout.setCaption(null); - - final Object o = menu.getValue(); - if (o != null && o instanceof Class) { - final Class c = (Class) o; - final String title = c.getName(); - bodyLayout.setCaption(title); - bodyLayout.addComponent(createTestable(c)); - } else { - // NOP node selected or deselected tree item - } - } - - /** - * 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 { - final ArrayList directories = new ArrayList(); - try { - final ClassLoader cld = Thread.currentThread() - .getContextClassLoader(); - if (cld == null) { - throw new ClassNotFoundException("Can't get class loader."); - } - final String path = packageName.replace('.', '/'); - // Ask for all resources for the path - final Enumeration resources = cld.getResources(path); - while (resources.hasMoreElements()) { - final URL url = (URL) resources.nextElement(); - directories.add(new File(url.getFile())); - } - } catch (final Exception x) { - throw new Exception(packageName - + " does not appear to be a valid package."); - } - - final ArrayList classes = new ArrayList(); - // For every directory identified capture all the .class files - for (final Iterator it = directories.iterator(); it.hasNext();) { - final File directory = (File) it.next(); - if (directory.exists()) { - // Get the list of the files contained in the package - final 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 - final String p = packageName + '.' - + files[j].substring(0, files[j].length() - 6); - final 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", + "com.itmill.toolkit.tests.tickets", "com.itmill.toolkit.tests.book" }; + + 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(); + + @Override + public void init() { + + // Add testable classes to hierarchical container + for (int p = 0; p < testablePackages.length; p++) { + testables.addItem(testablePackages[p]); + try { + final List testableClasses = getTestableClassesForPackage(testablePackages[p]); + for (final Iterator it = testableClasses.iterator(); it + .hasNext();) { + final 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]); + testables.setChildrenAllowed(t, false); + continue; + } catch (final Exception e) { + try { + testables.addItem(t); + itemCaptions.put(t, t.getName()); + testables.setParent(t, testablePackages[p]); + testables.setChildrenAllowed(t, false); + continue; + } catch (final Exception e1) { + e1.printStackTrace(); + } + } + } + } catch (final Exception e) { + e.printStackTrace(); + } + } + + menu = new Tree("Testables", testables); + + for (final Iterator i = itemCaptions.keySet().iterator(); i.hasNext();) { + final Class testable = (Class) i.next(); + // simplify captions + final String name = testable.getName().substring( + testable.getName().lastIndexOf('.') + 1); + menu.setItemCaption(testable, name); + } + // expand all root items + for (final Iterator i = menu.rootItemIds().iterator(); i.hasNext();) { + menu.expandItemsRecursively(i.next()); + } + + menu.addListener(this); + menu.setImmediate(true); + menu.setNullSelectionAllowed(false); + VerticalLayout lo = new VerticalLayout(); + lo.addComponent(menu); + + UriFragmentUtility uri = new UriFragmentUtility(); + lo.addComponent(uri); + + uri.addListener(new UriFragmentUtility.FragmentChangedListener() { + public void fragmentChanged(FragmentChangedEvent source) { + String fragment = source.getUriFragmentUtility().getFragment(); + if (fragment != null && !"".equals(fragment)) { + // try to find a proper test class + + // exact match + Iterator iterator = menu.getItemIds().iterator(); + while (iterator.hasNext()) { + Object next = iterator.next(); + if (next instanceof Class) { + Class c = (Class) next; + String string = c.getName(); + if (string.equals(fragment)) { + menu.setValue(c); + mainLayout.setSplitPosition(0); + return; + } + } + } + + // simple name match + iterator = menu.getItemIds().iterator(); + while (iterator.hasNext()) { + Object next = iterator.next(); + if (next instanceof Class) { + Class c = (Class) next; + String string = c.getSimpleName(); + if (string.equals(fragment)) { + menu.setValue(c); + mainLayout.setSplitPosition(0); + return; + } + } + } + // ticket match + iterator = menu.getItemIds().iterator(); + while (iterator.hasNext()) { + Object next = iterator.next(); + if (next instanceof Class) { + Class c = (Class) next; + String string = c.getSimpleName(); + if (string.startsWith("Ticket" + fragment)) { + menu.setValue(c); + mainLayout.setSplitPosition(0); + return; + } + } + } + + // just partly mach lowercase + iterator = menu.getItemIds().iterator(); + while (iterator.hasNext()) { + Object next = iterator.next(); + if (next instanceof Class) { + Class c = (Class) next; + String string = c.getSimpleName(); + if (string.toLowerCase().contains( + fragment.toLowerCase())) { + menu.setValue(c); + mainLayout.setSplitPosition(0); + return; + } + } + } + + getMainWindow().showNotification( + "No potential matc for #" + fragment); + + } + + } + }); + + mainLayout.addComponent(lo); + + bodyLayout.addStyleName("light"); + bodyLayout.setSizeFull(); + bodyLayout.setLayout(new ExpandLayout()); + + mainLayout.addComponent(bodyLayout); + + mainLayout.setSplitPosition(30); + + mainWindow.setLayout(mainLayout); + + setMainWindow(mainWindow); + } + + private Component createTestable(Class c) { + try { + final Application app = (Application) c.newInstance(); + app.init(); + Layout lo = app.getMainWindow().getLayout(); + lo.setParent(null); + return lo; + } catch (final Exception e) { + try { + final CustomComponent cc = (CustomComponent) c.newInstance(); + cc.setSizeFull(); + return cc; + } catch (final Exception e1) { + e1.printStackTrace(); + VerticalLayout lo = new VerticalLayout(); + lo.addComponent(new Label( + "Cannot create application / custom component: " + + e1.toString())); + + Link l = new Link("Try opening via app runner", + new ExternalResource("../run/" + c.getName())); + lo.addComponent(l); + + return lo; + } + } + } + + // Handle menu selection and update body + public void valueChange(Property.ValueChangeEvent event) { + bodyLayout.removeAllComponents(); + bodyLayout.setCaption(null); + + final Object o = menu.getValue(); + if (o != null && o instanceof Class) { + final Class c = (Class) o; + final String title = c.getName(); + bodyLayout.setCaption(title); + bodyLayout.addComponent(createTestable(c)); + } else { + // NOP node selected or deselected tree item + } + } + + /** + * 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 { + final ArrayList directories = new ArrayList(); + try { + final ClassLoader cld = Thread.currentThread() + .getContextClassLoader(); + if (cld == null) { + throw new ClassNotFoundException("Can't get class loader."); + } + final String path = packageName.replace('.', '/'); + // Ask for all resources for the path + final Enumeration resources = cld.getResources(path); + while (resources.hasMoreElements()) { + final URL url = (URL) resources.nextElement(); + directories.add(new File(url.getFile())); + } + } catch (final Exception x) { + throw new Exception(packageName + + " does not appear to be a valid package."); + } + + final ArrayList classes = new ArrayList(); + // For every directory identified capture all the .class files + for (final Iterator it = directories.iterator(); it.hasNext();) { + final File directory = (File) it.next(); + if (directory.exists()) { + // Get the list of the files contained in the package + final 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 + final String p = packageName + '.' + + files[j].substring(0, files[j].length() - 6); + final 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; + } } |