From: Jani Laakso Date: Mon, 3 Dec 2007 19:14:00 +0000 (+0000) Subject: Packaging fixes X-Git-Tag: 6.7.0.beta1~5312 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=362efe6fdf7c3a627e3bb7e63c33d21228619e6c;p=vaadin-framework.git Packaging fixes Added open source license and 3rd party licenses Building new package svn changeset:3129/svn branch:trunk --- diff --git a/WebContent/index.html b/WebContent/index.html index 7e1a73c860..b33c84564c 100644 --- a/WebContent/index.html +++ b/WebContent/index.html @@ -224,8 +224,7 @@
Library
-

Contains all you need to start a new Toolkit project (binaries, sources, default - themes and widgetsets). Toolkit JAR

+

WEB-INF/lib/itmill-toolkit-.jar contains all you need to start a new Toolkit project.

diff --git a/WebContent/release-notes.html b/WebContent/release-notes.html index 780e19fd83..15ad8b9a07 100644 --- a/WebContent/release-notes.html +++ b/WebContent/release-notes.html @@ -30,75 +30,78 @@ This document is under construction.


-

Known issues in

+

Abbreviations

+

IE = Internet Explorer, FF = Firefox, SA = Safari, OP = Opera -
+

+

Known issues in

+

Starting any demo may take long time (5 seconds) on some environments. Should not affect on "real" environments. -
+

Table component makes extra requests when disabling/enabling the table (FF only) -
+

Window: moving / dragging windows should be more usable -
+

Embedded / Window: embedded (Flash) are rendered through window -
+

Panel: setComponentError, setIcon, setDescription do not work -
+

Select: setEnabled(false) still can be edited -
+

TabSheet: container area width is different to tabs -
+

setReadOnly(true): issues on multiple components -
+

Tabsheet: setComponentError, setIcon, setDescription do not work -
+

Calendar: jumpy, buttons change position -
+

Select has thin red lines (other widgets are seen through) -
+

Window / RichTextArea: whole scrolls / jumps up when bold is clicked -
+

Session: When server is restarted, application hangs (Safari) -
+

RichTextEditor: setEnabled(false) still can be edited -
+

SplitPanel: implement spacing -
+

Form two-columns GridLayout breaks captions. -
+

Add setMaxLength() to TextField -
+

Cancelling (big) uploads should be possible -
+

(Sub-) Window closing should be possible -
+

QueryContainer must implement Sortable -
+

QueryContainer should implement Container.Filterable -
+

QueryContainer should support preparedstatements-type API -
+

Creating minimized/optimized widgetset still contains default theme (css files) -
+

Select: when opening selection div it always starts from top even though currently selected value is elsewhere -
+

Window resize: if mouse hits scrollbar when dragging, cursor dragging state is lost on (SA) -
+

Tree don't support icons -
+

Container.Hierarchical.setParent() should be setItemParent() (etc) -
+

CustomComponent: setVisible(false) does not hide it, setEnabled(false) does not disable it -
+

RichTextArea performance issues (FF) -
+

RichTextArea extra scrollbars issues on some layouts (SA) -
+

DateField.setLocale floods to other components aswell -
+

Table column selector div may be positioned randomly wrong (IE) -
+

Error message in Button is not shown (FF) -
+

diff --git a/build/VERSION.properties b/build/VERSION.properties index 3caf922fbf..a33a51ed2d 100644 --- a/build/VERSION.properties +++ b/build/VERSION.properties @@ -1 +1 @@ -version=5.0.0-alpha-20 +version=5.0.0-alpha-21 diff --git a/build/build.xml b/build/build.xml index bf6061780a..590a2e16e2 100644 --- a/build/build.xml +++ b/build/build.xml @@ -298,6 +298,41 @@ Adding platform specific files for ${package-platform} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -375,6 +410,10 @@ + + + + @@ -385,12 +424,12 @@ - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -498,6 +502,18 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> + + + + + + + + + + + + Adding demo sources to WebContent/WEB-INF/src diff --git a/build/package/Start IT Mill Toolkit.scpt b/build/package/Start IT Mill Toolkit.scpt new file mode 100644 index 0000000000..2804df49d0 Binary files /dev/null and b/build/package/Start IT Mill Toolkit.scpt differ diff --git a/build/package/linux-readme.txt b/build/package/linux-readme.txt index cf8f63e7d3..ce4574fc70 100644 --- a/build/package/linux-readme.txt +++ b/build/package/linux-readme.txt @@ -2,25 +2,30 @@ How to Start? -Open shell and execute "sh start.sh". IT Mill Toolkit webpage guides you forward. +Open shell and execute "sh start.sh". This starts IT Mill Toolkit +web application which guides your forward. What's Inside the IT Mill Toolkit Package? -You should explore package through the provided webpage within the package, -see 'How to Start?' above. Package is an web application itself and directly -importable to Eclipse IDE. +You should start exploring IT Mill Toolkit through the provided web application +within this package, see 'How to Start?' above. WebContent contains demos, +documentation and other useful information to get started with IT Mill Toolkit. -Here are few important locations and files: +This directory is directly importable to Eclipse IDE using +"File / Import / Existing Projects into Workspace" selection from Eclipse main +menu. -start.sh -- start exploring IT Mill Toolkit by executing this script +Below is a list of most important locations and files: -WebContent/License -- license files +Start IT Mill Toolkit +- start exploring IT Mill Toolkit by double-clicking this icon + +COPYING +- license file WebContent/WEB-INF/lib/itmill-toolkit-.jar -- IT Mill Toolkit library containing sources and compiled files +- IT Mill Toolkit library containing Java source and compiled files WebContent/demo/itmill-toolkit.war - deployable demo application for your application server @@ -52,3 +57,7 @@ build-widgetsets.xml WebContent/ITMILL - widgetsets and themes + +gwt +- Google Web Toolkit is required for building new widgetsets + diff --git a/build/package/mac-Start-icon_script.zip b/build/package/mac-Start-icon_script.zip new file mode 100644 index 0000000000..9de5a208d4 Binary files /dev/null and b/build/package/mac-Start-icon_script.zip differ diff --git a/build/package/mac-readme.txt b/build/package/mac-readme.txt index dd9bddc3c9..d96a123ab0 100644 --- a/build/package/mac-readme.txt +++ b/build/package/mac-readme.txt @@ -2,27 +2,32 @@ How to Start? -Just double-click Start icon. IT Mill Toolkit webpage guides you forward. -If for some reason Start icon fails in your environment, another option is -to open shell and execute "sh start.sh". +Just double-click Start IT Mill Toolkit icon. This starts IT Mill Toolkit +web application which guides your forward. If for some reason start icon +fails in your environment, another option is to open shell and execute +"sh start.sh". What's Inside the IT Mill Toolkit Package? -You should explore package through the provided webpage within the package, -see 'How to Start?' above. Package is an web application itself and directly -importable to Eclipse IDE. +You should start exploring IT Mill Toolkit through the provided web application +within this package, see 'How to Start?' above. WebContent contains demos, +documentation and other useful information to get started with IT Mill Toolkit. -Here are few important locations and files: +This directory is directly importable to Eclipse IDE using +"File / Import / Existing Projects into Workspace" selection from Eclipse main +menu. -Start +Below is a list of most important locations and files: + +Start IT Mill Toolkit - start exploring IT Mill Toolkit by double-clicking this icon -WebContent/License -- license files +COPYING +- license file WebContent/WEB-INF/lib/itmill-toolkit-.jar -- IT Mill Toolkit library containing sources and compiled files +- IT Mill Toolkit library containing Java source and compiled files WebContent/demo/itmill-toolkit.war - deployable demo application for your application server @@ -54,3 +59,7 @@ build-widgetsets.xml WebContent/ITMILL - widgetsets and themes + +gwt +- Google Web Toolkit is required for building new widgetsets + diff --git a/build/package/win-readme.txt b/build/package/win-readme.txt deleted file mode 100644 index 5e7d2cccf9..0000000000 --- a/build/package/win-readme.txt +++ /dev/null @@ -1,54 +0,0 @@ -== IT Mill Toolkit Readme == - -How to Start? - -Double-click start.bat. IT Mill Toolkit webpage guides you forward. - - -What's Inside the IT Mill Toolkit Package? - -You should explore package through the provided webpage within the package, -see 'How to Start?' above. Package is an web application itself and directly -importable to Eclipse IDE. - -Here are few important locations and files: - -start.bat -- start exploring IT Mill Toolkit by double-clicking this icon - -WebContent/License -- license files - -WebContent/WEB-INF/lib/itmill-toolkit-.jar -- IT Mill Toolkit library containing sources and compiled files - -WebContent/demo/itmill-toolkit.war -- deployable demo application for your application server - -WebContent/doc/manual.pdf -- manual in PDF format - -WebContent/doc/manual/index.html -- manual in HTML format - -WebContent/doc/api/index.html -- JavaDocs - -WebContent/WEB-INF/src -- demo source code, compiled into WebContent/WEB-INF/classes - -WebContent/doc/example-source -- example source in HTML format - -WebContent/demo -- files required by demos - -IT Mill Toolkit Hosted Mode.launch -IT Mill Toolkit Web Mode.launch -- launch configurations for Eclipse workspace - -build-widgetsets.xml -- builds GWT widgetsets for IT Mill Toolkit applications - -WebContent/ITMILL -- widgetsets and themes diff --git a/build/package/windows-readme.txt b/build/package/windows-readme.txt index 5e7d2cccf9..3250ba4813 100644 --- a/build/package/windows-readme.txt +++ b/build/package/windows-readme.txt @@ -2,25 +2,30 @@ How to Start? -Double-click start.bat. IT Mill Toolkit webpage guides you forward. +Just double-click start.bat icon. This starts IT Mill Toolkit web application +which guides your forward. What's Inside the IT Mill Toolkit Package? -You should explore package through the provided webpage within the package, -see 'How to Start?' above. Package is an web application itself and directly -importable to Eclipse IDE. +You should start exploring IT Mill Toolkit through the provided web application +within this package, see 'How to Start?' above. WebContent contains demos, +documentation and other useful information to get started with IT Mill Toolkit. -Here are few important locations and files: +This directory is directly importable to Eclipse IDE using +"File / Import / Existing Projects into Workspace" selection from Eclipse main +menu. -start.bat +Below is a list of most important locations and files: + +Start IT Mill Toolkit - start exploring IT Mill Toolkit by double-clicking this icon -WebContent/License -- license files +COPYING +- license file WebContent/WEB-INF/lib/itmill-toolkit-.jar -- IT Mill Toolkit library containing sources and compiled files +- IT Mill Toolkit library containing Java source and compiled files WebContent/demo/itmill-toolkit.war - deployable demo application for your application server @@ -52,3 +57,7 @@ build-widgetsets.xml WebContent/ITMILL - widgetsets and themes + +gwt +- Google Web Toolkit is required for building new widgetsets + diff --git a/src/com/itmill/toolkit/demo/testbench/TestBench.java b/src/com/itmill/toolkit/demo/testbench/TestBench.java deleted file mode 100644 index bec73a9aed..0000000000 --- a/src/com/itmill/toolkit/demo/testbench/TestBench.java +++ /dev/null @@ -1,209 +0,0 @@ -package com.itmill.toolkit.demo.testbench; - -import java.io.File; -import java.net.URL; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Iterator; -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; -import com.itmill.toolkit.ui.Label; -import com.itmill.toolkit.ui.Panel; -import com.itmill.toolkit.ui.SplitPanel; -import com.itmill.toolkit.ui.Tree; -import com.itmill.toolkit.ui.Window; - -/** - * TestBench finds out testable classes within given java packages and adds them - * to menu from where they can be executed. Class is considered testable if it - * is of class CustomComponent. - * - * Note: edit TestBench.testablePackages array - * - * @author IT Mill Ltd. - * - */ -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.demo.testbench" }; - - 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); - for (Iterator i = itemCaptions.keySet().iterator(); i.hasNext();) { - Class testable = (Class) i.next(); - // simplify captions - String name = testable.getName().substring( - testable.getName().lastIndexOf('.') + 1); - menu.setItemCaption(testable, name); - } - // expand all root items - for (Iterator i = menu.rootItemIds().iterator(); i.hasNext();) { - menu.expandItemsRecursively(i.next()); - } - - 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 custom component: " - + e1.toString()); - } - } - } - - // Handle menu selection and update body - public void valueChange(Property.ValueChangeEvent event) { - bodyLayout.removeAllComponents(); - bodyLayout.setCaption(null); - - Object o = menu.getValue(); - if (o != null && o instanceof Class) { - Class c = (Class) o; - 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 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.ui.CustomComponent.class))) { - classes.add(c); - } - } - } - } - } - } - - return classes; - } - -} diff --git a/src/com/itmill/toolkit/demo/testbench/TestForAlignments.java b/src/com/itmill/toolkit/demo/testbench/TestForAlignments.java deleted file mode 100644 index 2fe53445ad..0000000000 --- a/src/com/itmill/toolkit/demo/testbench/TestForAlignments.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.itmill.toolkit.demo.testbench; - -import com.itmill.toolkit.ui.Button; -import com.itmill.toolkit.ui.CustomComponent; -import com.itmill.toolkit.ui.DateField; -import com.itmill.toolkit.ui.OrderedLayout; -import com.itmill.toolkit.ui.TextField; - -public class TestForAlignments extends CustomComponent { - - public TestForAlignments() { - - OrderedLayout main = new OrderedLayout(); - - Button b1 = new Button("Right"); - Button b2 = new Button("Left"); - Button b3 = new Button("Bottom"); - Button b4 = new Button("Top"); - TextField t1 = new TextField("Right aligned"); - TextField t2 = new TextField("Bottom aligned"); - DateField d1 = new DateField("Center aligned"); - DateField d2 = new DateField("Center aligned"); - - OrderedLayout vert = new OrderedLayout(); - vert.addComponent(b1); - vert.addComponent(b2); - vert.addComponent(t1); - vert.addComponent(d1); - vert.setWidth(500); - vert.setComponentAlignment(b1, OrderedLayout.ALIGNMENT_RIGHT, - OrderedLayout.ALIGNMENT_TOP); - vert.setComponentAlignment(b2, OrderedLayout.ALIGNMENT_LEFT, - OrderedLayout.ALIGNMENT_TOP); - vert.setComponentAlignment(t1, OrderedLayout.ALIGNMENT_RIGHT, - OrderedLayout.ALIGNMENT_TOP); - vert.setComponentAlignment(d1, - OrderedLayout.ALIGNMENT_HORIZONTAL_CENTER, - OrderedLayout.ALIGNMENT_TOP); - OrderedLayout hori = new OrderedLayout( - OrderedLayout.ORIENTATION_HORIZONTAL); - hori.addComponent(b3); - hori.addComponent(b4); - hori.addComponent(t2); - hori.addComponent(d2); - hori.setHeight(200); - hori.setComponentAlignment(b3, OrderedLayout.ALIGNMENT_LEFT, - OrderedLayout.ALIGNMENT_BOTTOM); - hori.setComponentAlignment(b4, OrderedLayout.ALIGNMENT_LEFT, - OrderedLayout.ALIGNMENT_TOP); - hori.setComponentAlignment(t2, OrderedLayout.ALIGNMENT_LEFT, - OrderedLayout.ALIGNMENT_BOTTOM); - hori.setComponentAlignment(d2, OrderedLayout.ALIGNMENT_LEFT, - OrderedLayout.ALIGNMENT_VERTICAL_CENTER); - - main.addComponent(vert); - main.addComponent(hori); - - setCompositionRoot(main); - - } - -} diff --git a/src/com/itmill/toolkit/demo/testbench/TestForBasicApplicationLayout.java b/src/com/itmill/toolkit/demo/testbench/TestForBasicApplicationLayout.java deleted file mode 100644 index 19de0d4c8c..0000000000 --- a/src/com/itmill/toolkit/demo/testbench/TestForBasicApplicationLayout.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.itmill.toolkit.demo.testbench; - -import java.sql.SQLException; -import java.util.Locale; - -import com.itmill.toolkit.data.util.QueryContainer; -import com.itmill.toolkit.demo.util.SampleDatabase; -import com.itmill.toolkit.terminal.Sizeable; -import com.itmill.toolkit.ui.Button; -import com.itmill.toolkit.ui.CustomComponent; -import com.itmill.toolkit.ui.DateField; -import com.itmill.toolkit.ui.ExpandLayout; -import com.itmill.toolkit.ui.Label; -import com.itmill.toolkit.ui.OrderedLayout; -import com.itmill.toolkit.ui.Panel; -import com.itmill.toolkit.ui.SplitPanel; -import com.itmill.toolkit.ui.TabSheet; -import com.itmill.toolkit.ui.Table; -import com.itmill.toolkit.ui.Button.ClickEvent; -import com.itmill.toolkit.ui.Button.ClickListener; - -public class TestForBasicApplicationLayout extends CustomComponent { - - private Button click; - private Button click2; - private TabSheet tab; - - // Database provided with sample data - private SampleDatabase sampleDatabase; - - public TestForBasicApplicationLayout() { - - click = new Button("Set height -1", new ClickListener() { - - public void buttonClick(ClickEvent event) { - tab.setHeight(-1); - } - - }); - - click2 = new Button("Set height 100%", new ClickListener() { - - public void buttonClick(ClickEvent event) { - tab.setHeight(100); - tab.setHeightUnits(Sizeable.UNITS_PERCENTAGE); - } - - }); - - SplitPanel sp = new SplitPanel(SplitPanel.ORIENTATION_HORIZONTAL); - sp.setSplitPosition(290, Sizeable.UNITS_PIXELS); - - SplitPanel sp2 = new SplitPanel(SplitPanel.ORIENTATION_VERTICAL); - sp2.setSplitPosition(255, Sizeable.UNITS_PIXELS); - - Panel p = new Panel("Accordion Panel"); - p.setSizeFull(); - - tab = new TabSheet(); - tab.setSizeFull(); - - Panel report = new Panel("Monthly Program Runs", new ExpandLayout()); - OrderedLayout controls = new OrderedLayout(); - controls.setMargin(true); - controls.addComponent(new Label("Report tab")); - controls.addComponent(click); - controls.addComponent(click2); - report.addComponent(controls); - DateField cal = new DateField(); - cal.setResolution(DateField.RESOLUTION_DAY); - cal.setLocale(new Locale("en", "US")); - report.addComponent(cal); - ((ExpandLayout) report.getLayout()).expand(controls); - report.addStyleName(Panel.STYLE_LIGHT); - report.setHeight(100); - report.setHeightUnits(Sizeable.UNITS_PERCENTAGE); - - sp2.setFirstComponent(report); - - Table table = new Table(); - // populate Toolkit table component with test SQL table rows - try { - sampleDatabase = new SampleDatabase(); - QueryContainer qc = new QueryContainer("SELECT * FROM employee", - sampleDatabase.getConnection()); - table.setContainerDataSource(qc); - } catch (SQLException e) { - e.printStackTrace(); - } - // define which columns should be visible on Table component - table.setVisibleColumns(new Object[] { "FIRSTNAME", "LASTNAME", - "TITLE", "UNIT" }); - table.setItemCaptionPropertyId("ID"); - table.setPageLength(15); - table.setSelectable(true); - table.setRowHeaderMode(Table.ROW_HEADER_MODE_INDEX); - table.setColumnCollapsingAllowed(true); - table.setColumnReorderingAllowed(true); - table.setSortDisabled(false); - table.setSizeFull(); - table.addStyleName("table-inline"); - sp2.setSecondComponent(table); - - tab.addTab(new Label("Tab1"), "Summary", null); - tab.addTab(sp2, "Reports", null); - tab.addTab(new Label("Tab 3"), "Statistics", null); - tab.addTab(new Label("Tab 4"), "Error Tracking", null); - tab.setSelectedTab(sp2); - - sp.setFirstComponent(p); - sp.setSecondComponent(tab); - - setCompositionRoot(sp); - } - -} diff --git a/src/com/itmill/toolkit/demo/testbench/TestForContainerFilterable.java b/src/com/itmill/toolkit/demo/testbench/TestForContainerFilterable.java deleted file mode 100644 index 1db20eb8c4..0000000000 --- a/src/com/itmill/toolkit/demo/testbench/TestForContainerFilterable.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.itmill.toolkit.demo.testbench; - -import com.itmill.toolkit.data.util.IndexedContainer; -import com.itmill.toolkit.terminal.Sizeable; -import com.itmill.toolkit.ui.Button; -import com.itmill.toolkit.ui.CustomComponent; -import com.itmill.toolkit.ui.Label; -import com.itmill.toolkit.ui.OrderedLayout; -import com.itmill.toolkit.ui.Panel; -import com.itmill.toolkit.ui.Table; -import com.itmill.toolkit.ui.TextField; -import com.itmill.toolkit.ui.Button.ClickEvent; - -public class TestForContainerFilterable extends CustomComponent { - - OrderedLayout lo = new OrderedLayout(); - IndexedContainer ic = new IndexedContainer(); - Table t = new Table(); - private static String parts[] = { "Neo", "Sa", "rem", "the", "adi", "za", - "tre", "day", "Ca", "re", "cen", "ter", "mi", "nal" }; - TextField firstFilter = new TextField("first-filter"); - TextField secondFilter = new TextField("second-filter"); - Button filterButton = new Button("Filter"); - Label count = new Label(); - - public TestForContainerFilterable() { - setCompositionRoot(lo); - - // Init datasource - ic.addContainerProperty("first", String.class, ""); - ic.addContainerProperty("second", String.class, ""); - for (int i = 0; i < 1000; i++) { - Object id = ic.addItem(); - ic.getContainerProperty(id, "first").setValue(randomWord()); - ic.getContainerProperty(id, "second").setValue(randomWord()); - } - - // Init filtering view - Panel filterPanel = new Panel("Filter", new OrderedLayout( - OrderedLayout.ORIENTATION_HORIZONTAL)); - filterPanel.setWidth(100); - filterPanel.setWidthUnits(Sizeable.UNITS_PERCENTAGE); - lo.addComponent(filterPanel); - filterPanel.addComponent(firstFilter); - filterPanel.addComponent(secondFilter); - filterPanel.addComponent(filterButton); - firstFilter - .setDescription("Filters first column in case-sensitive contains manner."); - secondFilter - .setDescription("Filters second column in case-insensitive prefix manner."); - filterPanel.addComponent(count); - - // Table - lo.addComponent(t); - t.setPageLength(12); - t.setWidth(100); - t.setWidthUnits(Sizeable.UNITS_PERCENTAGE); - t.setContainerDataSource(ic); - - // Handler - filterButton.addListener(new Button.ClickListener() { - public void buttonClick(ClickEvent event) { - ic.removeAllContainerFilters(); - if (firstFilter.toString().length() > 0) { - ic.addContainerFilter("first", firstFilter.toString(), false, - false); - } - if (secondFilter.toString().length() > 0) { - ic.addContainerFilter("second", secondFilter.toString(), true, - true); - } - count.setValue("Rows in table: " + ic.size()); - } - }); - - // Resetbutton - lo.addComponent(new Button("Rebind table datasource", - new Button.ClickListener() { - public void buttonClick(ClickEvent event) { - t.setContainerDataSource(ic); - } - })); - } - - private String randomWord() { - int len = (int) (Math.random() * 4); - StringBuffer buf = new StringBuffer(); - while (len-- >= 0) { - buf.append(parts[(int) (Math.random() * parts.length)]); - } - return buf.toString(); - } -} diff --git a/src/com/itmill/toolkit/demo/testbench/TestForMultipleStyleNames.java b/src/com/itmill/toolkit/demo/testbench/TestForMultipleStyleNames.java deleted file mode 100644 index d8f8649965..0000000000 --- a/src/com/itmill/toolkit/demo/testbench/TestForMultipleStyleNames.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.itmill.toolkit.demo.testbench; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; - -import com.itmill.toolkit.data.Property.ValueChangeEvent; -import com.itmill.toolkit.data.Property.ValueChangeListener; -import com.itmill.toolkit.data.util.IndexedContainer; -import com.itmill.toolkit.ui.CustomComponent; -import com.itmill.toolkit.ui.Label; -import com.itmill.toolkit.ui.OrderedLayout; -import com.itmill.toolkit.ui.TwinColSelect; - -/** - * TODO: Note you need to add Theme under WebContent/ITMILL/Themes/mytheme in - * order to see actual visible results on the browser. Currently changes are - * visible only by inspecting DOM. - * - * @author IT Mill Ltd. - */ -public class TestForMultipleStyleNames extends CustomComponent implements - ValueChangeListener { - - private final OrderedLayout main = new OrderedLayout(); - - private Label l; - - private final TwinColSelect s = new TwinColSelect(); - - private ArrayList styleNames2; - - public TestForMultipleStyleNames() { - setCompositionRoot(main); - createNewView(); - } - - public void createNewView() { - main.removeAllComponents(); - main.addComponent(new Label( - "TK5 supports multiple stylenames for components.")); - main.addComponent(new Label("Note you need to add Theme under" - + " WebContent/ITMILL/Themes/mytheme" - + " in order to see actual visible results" - + " on the browser. Currently changes are" - + " visible only by inspecting DOM.")); - - styleNames2 = new ArrayList(); - - styleNames2.add("red"); - styleNames2.add("bold"); - styleNames2.add("italic"); - - s.setContainerDataSource(new IndexedContainer(styleNames2)); - s.addListener(this); - s.setImmediate(true); - main.addComponent(s); - - l = new Label("Test labele"); - main.addComponent(l); - - } - - public void valueChange(ValueChangeEvent event) { - - String currentStyle = l.getStyle(); - String[] tmp = currentStyle.split(" "); - ArrayList curStyles = new ArrayList(); - for (int i = 0; i < tmp.length; i++) { - if (tmp[i] != "") { - curStyles.add(tmp[i]); - } - } - - Collection styles = (Collection) s.getValue(); - - for (Iterator iterator = styles.iterator(); iterator.hasNext();) { - String styleName = (String) iterator.next(); - if (curStyles.contains(styleName)) { - // already added - curStyles.remove(styleName); - } else { - l.addStyleName(styleName); - } - } - for (Iterator iterator2 = curStyles.iterator(); iterator2.hasNext();) { - String object = (String) iterator2.next(); - l.removeStyleName(object); - } - } - -} diff --git a/src/com/itmill/toolkit/demo/testbench/TestForPreconfiguredComponents.java b/src/com/itmill/toolkit/demo/testbench/TestForPreconfiguredComponents.java deleted file mode 100644 index e3d21eed2a..0000000000 --- a/src/com/itmill/toolkit/demo/testbench/TestForPreconfiguredComponents.java +++ /dev/null @@ -1,182 +0,0 @@ -package com.itmill.toolkit.demo.testbench; - -import com.itmill.toolkit.event.Action; -import com.itmill.toolkit.event.Action.Handler; -import com.itmill.toolkit.ui.AbstractSelect; -import com.itmill.toolkit.ui.Button; -import com.itmill.toolkit.ui.CheckBox; -import com.itmill.toolkit.ui.Component; -import com.itmill.toolkit.ui.CustomComponent; -import com.itmill.toolkit.ui.Label; -import com.itmill.toolkit.ui.NativeSelect; -import com.itmill.toolkit.ui.OptionGroup; -import com.itmill.toolkit.ui.OrderedLayout; -import com.itmill.toolkit.ui.Panel; -import com.itmill.toolkit.ui.Tree; -import com.itmill.toolkit.ui.TwinColSelect; -import com.itmill.toolkit.ui.Button.ClickEvent; -import com.itmill.toolkit.ui.Button.ClickListener; - -/** - * @author IT Mill Ltd. - */ -public class TestForPreconfiguredComponents extends CustomComponent implements - Handler { - - private static final String[] firstnames = new String[] { "John", "Mary", - "Joe", "Sarah", "Jeff", "Jane", "Peter", "Marc", "Josie", "Linus" }; - - private static final String[] lastnames = new String[] { "Torvalds", - "Smith", "Jones", "Beck", "Sheridan", "Picard", "Hill", "Fielding", - "Einstein" }; - - private final OrderedLayout main = new OrderedLayout(); - - private final Action[] actions = new Action[] { new Action("edit"), - new Action("delete") }; - - private Panel al; - - private Tree contextTree; - - public TestForPreconfiguredComponents() { - - setCompositionRoot(main); - createNewView(); - } - - public void createNewView() { - main.removeAllComponents(); - main - .addComponent(new Label( - "In Toolkit 5 we introduce new componens. Previously we" - + " usually used setStyle or some other methods on possibly " - + "multiple steps to configure component for ones needs. These new " - + "server side components are mostly just classes that in constructor " - + "set base class to state that programmer wants.")); - - main.addComponent(new Button("commit")); - - Panel test = createTestBench(new CheckBox()); - test.setCaption("CheckBox (configured from button)"); - main.addComponent(test); - - AbstractSelect s = new TwinColSelect(); - fillSelect(s, 20); - test = createTestBench(s); - test.setCaption("TwinColSelect (configured from select)"); - main.addComponent(test); - - s = new NativeSelect(); - fillSelect(s, 20); - test = createTestBench(s); - test.setCaption("Native (configured from select)"); - main.addComponent(test); - - s = new OptionGroup(); - fillSelect(s, 20); - test = createTestBench(s); - test.setCaption("OptionGroup (configured from select)"); - main.addComponent(test); - - s = new OptionGroup(); - fillSelect(s, 20); - s.setMultiSelect(true); - test = createTestBench(s); - test - .setCaption("OptionGroup + multiselect manually (configured from select)"); - main.addComponent(test); - - Button b = new Button("refresh view", this, "createNewView"); - main.addComponent(b); - - } - - public static void fillSelect(AbstractSelect s, int items) { - for (int i = 0; i < items; i++) { - String name = firstnames[(int) (Math.random() * (firstnames.length - 1))] - + " " - + lastnames[(int) (Math.random() * (lastnames.length - 1))]; - s.addItem(name); - } - } - - public Tree createTestTree() { - Tree t = new Tree("Tree"); - String[] names = new String[100]; - for (int i = 0; i < names.length; i++) { - names[i] = firstnames[(int) (Math.random() * (firstnames.length - 1))] - + " " - + lastnames[(int) (Math.random() * (lastnames.length - 1))]; - } - - // Create tree - t = new Tree("Organization Structure"); - for (int i = 0; i < 100; i++) { - t.addItem(names[i]); - String parent = names[(int) (Math.random() * (names.length - 1))]; - if (t.containsId(parent)) { - t.setParent(names[i], parent); - } - } - - // Forbid childless people to have children (makes them leaves) - for (int i = 0; i < 100; i++) { - if (!t.hasChildren(names[i])) { - t.setChildrenAllowed(names[i], false); - } - } - return t; - } - - public Panel createTestBench(Component t) { - Panel ol = new Panel(); - ol.setLayout(new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL)); - - ol.addComponent(t); - - final OrderedLayout ol2 = new OrderedLayout( - OrderedLayout.ORIENTATION_HORIZONTAL); - final Panel status = new Panel("Events"); - final Button clear = new Button("clear event log"); - clear.addListener(new ClickListener() { - public void buttonClick(ClickEvent event) { - status.removeAllComponents(); - status.addComponent(ol2); - } - }); - ol2.addComponent(clear); - final Button commit = new Button("commit changes"); - ol2.addComponent(commit); - status.addComponent(ol2); - - status.setHeight(300); - status.setWidth(400); - - ol.addComponent(status); - - t.addListener(new Listener() { - public void componentEvent(Event event) { - status.addComponent(new Label(event.getClass().getName())); - status.addComponent(new Label("selected: " - + event.getSource().toString())); - } - }); - - return ol; - } - - public Action[] getActions(Object target, Object sender) { - return actions; - } - - public void handleAction(Action action, Object sender, Object target) { - if (action == actions[1]) { - al.addComponent(new Label("Delete selected on " + target)); - contextTree.removeItem(target); - - } else { - al.addComponent(new Label("Edit selected on " + target)); - } - } -} diff --git a/src/com/itmill/toolkit/demo/testbench/TestForRichTextEditor.java b/src/com/itmill/toolkit/demo/testbench/TestForRichTextEditor.java deleted file mode 100644 index bf7b7e7afd..0000000000 --- a/src/com/itmill/toolkit/demo/testbench/TestForRichTextEditor.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.itmill.toolkit.demo.testbench; - -import com.itmill.toolkit.data.Property.ValueChangeEvent; -import com.itmill.toolkit.data.Property.ValueChangeListener; -import com.itmill.toolkit.ui.Button; -import com.itmill.toolkit.ui.CustomComponent; -import com.itmill.toolkit.ui.Label; -import com.itmill.toolkit.ui.OrderedLayout; -import com.itmill.toolkit.ui.RichTextArea; - -/** - * - * @author IT Mill Ltd. - */ -public class TestForRichTextEditor extends CustomComponent implements - ValueChangeListener { - - private OrderedLayout main = new OrderedLayout(); - - private Label l; - - private RichTextArea rte; - - public TestForRichTextEditor() { - - setCompositionRoot(main); - createNewView(); - } - - public void createNewView() { - main.removeAllComponents(); - main.addComponent(new Label( - "RTE uses google richtextArea and their examples toolbar.")); - - rte = new RichTextArea(); - rte.addListener(this); - - rte.setEnabled(false); - - main.addComponent(rte); - - main.addComponent(new Button("commit content to label below")); - - l = new Label("", Label.CONTENT_XHTML); - main.addComponent(l); - - } - - public void valueChange(ValueChangeEvent event) { - l.setValue(rte.getValue()); - } - -} diff --git a/src/com/itmill/toolkit/demo/testbench/TestForTrees.java b/src/com/itmill/toolkit/demo/testbench/TestForTrees.java deleted file mode 100644 index a13cf4d4a4..0000000000 --- a/src/com/itmill/toolkit/demo/testbench/TestForTrees.java +++ /dev/null @@ -1,162 +0,0 @@ -package com.itmill.toolkit.demo.testbench; - -import com.itmill.toolkit.event.Action; -import com.itmill.toolkit.event.Action.Handler; -import com.itmill.toolkit.ui.Button; -import com.itmill.toolkit.ui.Component; -import com.itmill.toolkit.ui.CustomComponent; -import com.itmill.toolkit.ui.Label; -import com.itmill.toolkit.ui.OrderedLayout; -import com.itmill.toolkit.ui.Panel; -import com.itmill.toolkit.ui.Tree; -import com.itmill.toolkit.ui.Button.ClickEvent; -import com.itmill.toolkit.ui.Button.ClickListener; - -/** - * Some test cases for trees. Events panel logs events that happen server side. - * - * @author IT Mill Ltd. - */ -public class TestForTrees extends CustomComponent implements Handler { - - private static final String[] firstnames = new String[] { "John", "Mary", - "Joe", "Sarah", "Jeff", "Jane", "Peter", "Marc", "Josie", "Linus" }; - - private static final String[] lastnames = new String[] { "Torvalds", - "Smith", "Jones", "Beck", "Sheridan", "Picard", "Hill", "Fielding", - "Einstein" }; - - private OrderedLayout main = new OrderedLayout(); - - private Action[] actions = new Action[] { new Action("edit"), - new Action("delete") }; - - private Panel al; - - private Tree contextTree; - - public TestForTrees() { - - setCompositionRoot(main); - createNewView(); - } - - public void createNewView() { - main.removeAllComponents(); - main - .addComponent(new Label( - "Some test cases for trees. Events panel logs events that happen server side.")); - - main.addComponent(new Button("commit")); - - Tree t; - - t = createTestTree(); - t.setCaption("Default settings"); - main.addComponent(createTestBench(t)); - - t = createTestTree(); - t.setCaption("Multiselect settings"); - t.setMultiSelect(true); - main.addComponent(createTestBench(t)); - - t = createTestTree(); - t.setCaption("Multiselect and immediate"); - t.setImmediate(true); - t.setMultiSelect(true); - main.addComponent(createTestBench(t)); - - t = createTestTree(); - t.setCaption("immediate"); - t.setImmediate(true); - main.addComponent(createTestBench(t)); - - t = createTestTree(); - t.setCaption("with actions"); - t.setImmediate(true); - t.addActionHandler(this); - OrderedLayout ol = (OrderedLayout) createTestBench(t); - al = new Panel("action log"); - ol.addComponent(al); - main.addComponent(ol); - contextTree = t; - - Button b = new Button("refresh view", this, "createNewView"); - main.addComponent(b); - - } - - public Tree createTestTree() { - Tree t = new Tree("Tree"); - String[] names = new String[100]; - for (int i = 0; i < names.length; i++) { - names[i] = firstnames[(int) (Math.random() * (firstnames.length - 1))] - + " " - + lastnames[(int) (Math.random() * (lastnames.length - 1))]; - } - - // Create tree - t = new Tree("Organization Structure"); - for (int i = 0; i < 100; i++) { - t.addItem(names[i]); - String parent = names[(int) (Math.random() * (names.length - 1))]; - if (t.containsId(parent)) { - t.setParent(names[i], parent); - } - } - - // Forbid childless people to have children (makes them leaves) - for (int i = 0; i < 100; i++) { - if (!t.hasChildren(names[i])) { - t.setChildrenAllowed(names[i], false); - } - } - return t; - } - - public Component createTestBench(Tree t) { - OrderedLayout ol = new OrderedLayout(); - ol.setOrientation(OrderedLayout.ORIENTATION_HORIZONTAL); - - ol.addComponent(t); - - final Panel status = new Panel("Events"); - final Button clear = new Button("c"); - clear.addListener(new ClickListener() { - public void buttonClick(ClickEvent event) { - status.removeAllComponents(); - status.addComponent(clear); - } - }); - status.addComponent(clear); - - status.setHeight(300); - status.setWidth(400); - - ol.addComponent(status); - - t.addListener(new Listener() { - public void componentEvent(Event event) { - status.addComponent(new Label(event.getClass().getName())); - status.addComponent(new Label("selected: " - + event.getSource().toString())); - } - }); - - return ol; - } - - public Action[] getActions(Object target, Object sender) { - return actions; - } - - public void handleAction(Action action, Object sender, Object target) { - if (action == actions[1]) { - al.addComponent(new Label("Delete selected on " + target)); - contextTree.removeItem(target); - - } else { - al.addComponent(new Label("Edit selected on " + target)); - } - } -} diff --git a/src/com/itmill/toolkit/demo/testbench/TestForUpload.java b/src/com/itmill/toolkit/demo/testbench/TestForUpload.java deleted file mode 100644 index 56a381ce66..0000000000 --- a/src/com/itmill/toolkit/demo/testbench/TestForUpload.java +++ /dev/null @@ -1,345 +0,0 @@ -package com.itmill.toolkit.demo.testbench; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import com.itmill.toolkit.data.Property.ValueChangeEvent; -import com.itmill.toolkit.terminal.StreamResource; -import com.itmill.toolkit.ui.AbstractField; -import com.itmill.toolkit.ui.Button; -import com.itmill.toolkit.ui.CustomComponent; -import com.itmill.toolkit.ui.Label; -import com.itmill.toolkit.ui.Layout; -import com.itmill.toolkit.ui.Link; -import com.itmill.toolkit.ui.OrderedLayout; -import com.itmill.toolkit.ui.Panel; -import com.itmill.toolkit.ui.ProgressIndicator; -import com.itmill.toolkit.ui.Select; -import com.itmill.toolkit.ui.Upload; -import com.itmill.toolkit.ui.Button.ClickEvent; -import com.itmill.toolkit.ui.Upload.FailedEvent; -import com.itmill.toolkit.ui.Upload.FailedListener; -import com.itmill.toolkit.ui.Upload.FinishedEvent; -import com.itmill.toolkit.ui.Upload.FinishedListener; -import com.itmill.toolkit.ui.Upload.StartedEvent; -import com.itmill.toolkit.ui.Upload.StartedListener; -import com.itmill.toolkit.ui.Upload.SucceededEvent; -import com.itmill.toolkit.ui.Upload.SucceededListener; - -public class TestForUpload extends CustomComponent implements - Upload.FinishedListener, FailedListener, SucceededListener, - Upload.ProgressListener, StartedListener { - - Layout main = new OrderedLayout(); - - Buffer buffer = new MemoryBuffer(); - - Panel status = new Panel("Uploaded file:"); - - private final Upload up; - - private final Label l; - - private final ProgressIndicator pi = new ProgressIndicator(); - - private final Label memoryStatus; - - private final Select uploadBufferSelector; - - public TestForUpload() { - setCompositionRoot(main); - main.addComponent(new Label( - "This is a simple test for upload application. " - + "Upload should work with big files and concurrent " - + "requests should not be blocked. Button 'b' reads " - + "current state into label below it. Memory receiver " - + "streams upload contents into memory. You may track" - + "consumption." - + "tempfile receiver writes upload to file and " - + "should have low memory consumption.")); - - main - .addComponent(new Label( - "Clicking on button b updates information about upload components status or same with garbage collector.")); - - up = new Upload("Upload", buffer); - up.setImmediate(true); - up.addListener((FinishedListener) this); - up.addListener((FailedListener) this); - up.addListener((SucceededListener) this); - up.addListener((StartedListener) this); - - up.setProgressListener(this); - - Button b = new Button("b", this, "readState"); - - Button c = new Button("b with gc", this, "gc"); - - main.addComponent(b); - main.addComponent(c); - - uploadBufferSelector = new Select("Receiver type"); - uploadBufferSelector.setImmediate(true); - uploadBufferSelector.addItem("memory"); - uploadBufferSelector.setValue("memory"); - uploadBufferSelector.addItem("tempfile"); - uploadBufferSelector - .addListener(new AbstractField.ValueChangeListener() { - public void valueChange(ValueChangeEvent event) { - setBuffer(); - } - }); - main.addComponent(uploadBufferSelector); - - main.addComponent(up); - l = new Label("Idle"); - main.addComponent(l); - - pi.setVisible(false); - pi.setPollingInterval(1000); - main.addComponent(pi); - - memoryStatus = new Label(); - main.addComponent(memoryStatus); - - status.setVisible(false); - main.addComponent(status); - - Button restart = new Button("R"); - restart.addListener(new Button.ClickListener() { - - public void buttonClick(ClickEvent event) { - getApplication().close(); - } - }); - main.addComponent(restart); - - } - - private void setBuffer() { - String id = (String) uploadBufferSelector.getValue(); - if ("memory".equals(id)) { - buffer = new MemoryBuffer(); - } else if ("tempfile".equals(id)) { - buffer = new TmpFileBuffer(); - } - up.setReceiver(buffer); - } - - public void gc() { - Runtime.getRuntime().gc(); - readState(); - } - - public void readState() { - StringBuffer sb = new StringBuffer(); - - if (up.isUploading()) { - sb.append("Uploading..."); - sb.append(up.getBytesRead()); - sb.append("/"); - sb.append(up.getUploadSize()); - sb.append(" "); - sb.append(Math.round(100 * up.getBytesRead() - / (double) up.getUploadSize())); - sb.append("%"); - } else { - sb.append("Idle"); - } - l.setValue(sb.toString()); - refreshMemUsage(); - } - - public void uploadFinished(FinishedEvent event) { - status.removeAllComponents(); - InputStream stream = buffer.getStream(); - if (stream == null) { - status.addComponent(new Label( - "Upload finished, but output buffer is null!!")); - } else { - status - .addComponent(new Label("Name: " - + event.getFilename(), Label.CONTENT_XHTML)); - status.addComponent(new Label("Mimetype: " - + event.getMIMEType(), Label.CONTENT_XHTML)); - status.addComponent(new Label("Size: " + event.getLength() - + " bytes.", Label.CONTENT_XHTML)); - - status.addComponent(new Link("Download " + buffer.getFileName(), - new StreamResource(buffer, buffer.getFileName(), - getApplication()))); - - status.setVisible(true); - } - } - - public interface Buffer extends StreamResource.StreamSource, - Upload.Receiver { - - String getFileName(); - } - - public class MemoryBuffer implements Buffer { - ByteArrayOutputStream outputBuffer = null; - - String mimeType; - - String fileName; - - public MemoryBuffer() { - - } - - public InputStream getStream() { - if (outputBuffer == null) { - return null; - } - return new ByteArrayInputStream(outputBuffer.toByteArray()); - } - - /** - * @see com.itmill.toolkit.ui.Upload.Receiver#receiveUpload(String, - * String) - */ - public OutputStream receiveUpload(String filename, String MIMEType) { - fileName = filename; - mimeType = MIMEType; - outputBuffer = new ByteArrayOutputStream(); - return outputBuffer; - } - - /** - * Returns the fileName. - * - * @return String - */ - public String getFileName() { - return fileName; - } - - /** - * Returns the mimeType. - * - * @return String - */ - public String getMimeType() { - return mimeType; - } - - } - - public class TmpFileBuffer implements Buffer { - String mimeType; - - String fileName; - - private File file; - - private FileInputStream stream; - - public TmpFileBuffer() { - String tempFileName = "upload_tmpfile_" - + System.currentTimeMillis(); - try { - file = File.createTempFile(tempFileName, null); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - - public InputStream getStream() { - if (file == null) { - return null; - } - try { - return new FileInputStream(file); - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return null; - } - - /** - * @see com.itmill.toolkit.ui.Upload.Receiver#receiveUpload(String, - * String) - */ - public OutputStream receiveUpload(String filename, String MIMEType) { - fileName = filename; - mimeType = MIMEType; - try { - return new FileOutputStream(file); - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return null; - } - - /** - * Returns the fileName. - * - * @return String - */ - public String getFileName() { - return fileName; - } - - /** - * Returns the mimeType. - * - * @return String - */ - public String getMimeType() { - return mimeType; - } - - } - - public void uploadFailed(FailedEvent event) { - System.out.println(event); - - System.out.println(event.getSource()); - - } - - public void uploadSucceeded(SucceededEvent event) { - pi.setVisible(false); - l.setValue("Finished upload, idle"); - System.out.println(event); - setBuffer(); - } - - public void updateProgress(long readBytes, long contentLenght) { - pi.setValue(new Float(readBytes / (float) contentLenght)); - - refreshMemUsage(); - } - - private void refreshMemUsage() { - memoryStatus.setValue("Not available in Java 1.4"); - /* - * StringBuffer mem = new StringBuffer(); MemoryMXBean mmBean = - * ManagementFactory.getMemoryMXBean(); mem.append("Heap (M):"); - * mem.append(mmBean.getHeapMemoryUsage().getUsed() / 1048576); - * mem.append(" |�Non-Heap (M):"); - * mem.append(mmBean.getNonHeapMemoryUsage().getUsed() / 1048576); - * memoryStatus.setValue(mem.toString()); - */ - } - - public void uploadStarted(StartedEvent event) { - pi.setVisible(true); - l.setValue("Started uploading file " + event.getFilename()); - } - -} diff --git a/src/com/itmill/toolkit/demo/testbench/TestForWindowOpen.java b/src/com/itmill/toolkit/demo/testbench/TestForWindowOpen.java deleted file mode 100644 index 4c1546285d..0000000000 --- a/src/com/itmill/toolkit/demo/testbench/TestForWindowOpen.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.itmill.toolkit.demo.testbench; - -import com.itmill.toolkit.terminal.ExternalResource; -import com.itmill.toolkit.ui.Button; -import com.itmill.toolkit.ui.CustomComponent; -import com.itmill.toolkit.ui.OrderedLayout; -import com.itmill.toolkit.ui.Button.ClickEvent; - -public class TestForWindowOpen extends CustomComponent { - - public TestForWindowOpen() { - - OrderedLayout main = new OrderedLayout(); - setCompositionRoot(main); - - main.addComponent(new Button("Open in this window", - new Button.ClickListener() { - - public void buttonClick(ClickEvent event) { - ExternalResource r = new ExternalResource( - "http://www.google.com"); - getApplication().getMainWindow().open(r); - - } - - })); - - main.addComponent(new Button("Open in target \"mytarget\"", - new Button.ClickListener() { - - public void buttonClick(ClickEvent event) { - ExternalResource r = new ExternalResource( - "http://www.google.com"); - getApplication().getMainWindow().open(r, "mytarget"); - - } - - })); - - main.addComponent(new Button("Open in target \"secondtarget\"", - new Button.ClickListener() { - - public void buttonClick(ClickEvent event) { - ExternalResource r = new ExternalResource( - "http://www.google.com"); - getApplication().getMainWindow() - .open(r, "secondtarget"); - - } - - })); - - } - -} diff --git a/src/com/itmill/toolkit/demo/testbench/TestForWindowing.java b/src/com/itmill/toolkit/demo/testbench/TestForWindowing.java deleted file mode 100644 index 41b1b03516..0000000000 --- a/src/com/itmill/toolkit/demo/testbench/TestForWindowing.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.itmill.toolkit.demo.testbench; - -import com.itmill.toolkit.data.Property.ValueChangeEvent; -import com.itmill.toolkit.data.Property.ValueChangeListener; -import com.itmill.toolkit.ui.AbstractSelect; -import com.itmill.toolkit.ui.Button; -import com.itmill.toolkit.ui.CustomComponent; -import com.itmill.toolkit.ui.Label; -import com.itmill.toolkit.ui.OptionGroup; -import com.itmill.toolkit.ui.OrderedLayout; -import com.itmill.toolkit.ui.Select; -import com.itmill.toolkit.ui.Slider; -import com.itmill.toolkit.ui.Window; -import com.itmill.toolkit.ui.Button.ClickEvent; -import com.itmill.toolkit.ui.Button.ClickListener; - -public class TestForWindowing extends CustomComponent { - - private Select s2; - - public TestForWindowing() { - - OrderedLayout main = new OrderedLayout(); - - main.addComponent(new Label( - "Click the button to create a new inline window.")); - - Button create = new Button("Create a new window", new ClickListener() { - - public void buttonClick(ClickEvent event) { - Window w = new Window("Testing Window"); - - AbstractSelect s1 = new OptionGroup(); - s1.setCaption("1. Select output format"); - s1.addItem("Excel sheet"); - s1.addItem("CSV plain text"); - s1.setValue("Excel sheet"); - - s2 = new Select(); - s2.addItem("Separate by comma (,)"); - s2.addItem("Separate by colon (:)"); - s2.addItem("Separate by semicolon (;)"); - s2.setEnabled(false); - - s1.addListener(new ValueChangeListener() { - - public void valueChange(ValueChangeEvent event) { - String v = (String) event.getProperty().getValue(); - if (v.equals("CSV plain text")) { - s2.setEnabled(true); - } else { - s2.setEnabled(false); - } - } - - }); - - w.addComponent(s1); - w.addComponent(s2); - - Slider s = new Slider(); - s.setCaption("Volume"); - s.setMax(13); - s.setMin(12); - s.setResolution(2); - s.setImmediate(true); - // s.setOrientation(Slider.ORIENTATION_VERTICAL); - // s.setArrows(false); - - w.addComponent(s); - - getApplication().getMainWindow().addWindow(w); - - } - - }); - - main.addComponent(create); - - setCompositionRoot(main); - - } - -} diff --git a/src/com/itmill/toolkit/demo/testbench/TestSetVisibleAndCaching.java b/src/com/itmill/toolkit/demo/testbench/TestSetVisibleAndCaching.java deleted file mode 100644 index 037e3f3c82..0000000000 --- a/src/com/itmill/toolkit/demo/testbench/TestSetVisibleAndCaching.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.itmill.toolkit.demo.testbench; - -import com.itmill.toolkit.ui.Button; -import com.itmill.toolkit.ui.Label; -import com.itmill.toolkit.ui.Panel; -import com.itmill.toolkit.ui.Window; -import com.itmill.toolkit.ui.Button.ClickEvent; -import com.itmill.toolkit.ui.Button.ClickListener; - -public class TestSetVisibleAndCaching extends com.itmill.toolkit.Application { - - Panel panelA = new Panel("Panel A"); - Panel panelB = new Panel("Panel B"); - Panel panelC = new Panel("Panel C"); - - Button buttonNextPanel = new Button("Show next panel"); - - int selectedPanel = 0; - - public void init() { - Window mainWindow = new Window("TestSetVisibleAndCaching"); - setMainWindow(mainWindow); - - panelA.addComponent(new Label( - "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")); - panelB.addComponent(new Label( - "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB")); - panelC.addComponent(new Label( - "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC")); - - mainWindow - .addComponent(new Label( - "Inspect transfered data from server to " - + "client using firebug (http request / response cycles)." - + " See how widgets are re-used," - + " after each panel is once shown in GUI then" - + " their contents are not resend.")); - mainWindow.addComponent(buttonNextPanel); - mainWindow.addComponent(panelA); - mainWindow.addComponent(panelB); - mainWindow.addComponent(panelC); - - selectPanel(selectedPanel); - - buttonNextPanel.addListener(new ClickListener() { - public void buttonClick(ClickEvent event) { - selectedPanel++; - if (selectedPanel > 2) { - selectedPanel = 0; - } - selectPanel(selectedPanel); - } - }); - - } - - private void selectPanel(int selectedPanel) { - System.err.println("Selecting panel " + selectedPanel); - switch (selectedPanel) { - case 0: - panelA.setVisible(true); - panelB.setVisible(false); - panelC.setVisible(false); - break; - case 1: - panelA.setVisible(false); - panelB.setVisible(true); - panelC.setVisible(false); - break; - case 2: - panelA.setVisible(false); - panelB.setVisible(false); - panelC.setVisible(true); - break; - } - } -} diff --git a/src/com/itmill/toolkit/demo/testbench/TestSplitPanel.java b/src/com/itmill/toolkit/demo/testbench/TestSplitPanel.java deleted file mode 100644 index 7493d0fd07..0000000000 --- a/src/com/itmill/toolkit/demo/testbench/TestSplitPanel.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.itmill.toolkit.demo.testbench; - -import com.itmill.toolkit.ui.Label; -import com.itmill.toolkit.ui.SplitPanel; -import com.itmill.toolkit.ui.Window; - -public class TestSplitPanel extends com.itmill.toolkit.Application { - - SplitPanel verticalSplit = new SplitPanel(SplitPanel.ORIENTATION_VERTICAL); - - public void init() { - Window mainWindow = new Window("Feature Browser"); - setMainWindow(mainWindow); - - verticalSplit.setFirstComponent(new Label("vertical first")); - verticalSplit.setSecondComponent(new Label("vertical second")); - - mainWindow.setLayout(verticalSplit); - - } - -} diff --git a/src/com/itmill/toolkit/tests/testbench/TestBench.java b/src/com/itmill/toolkit/tests/testbench/TestBench.java new file mode 100644 index 0000000000..35373cfabb --- /dev/null +++ b/src/com/itmill/toolkit/tests/testbench/TestBench.java @@ -0,0 +1,209 @@ +package com.itmill.toolkit.tests.testbench; + +import java.io.File; +import java.net.URL; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Iterator; +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; +import com.itmill.toolkit.ui.Label; +import com.itmill.toolkit.ui.Panel; +import com.itmill.toolkit.ui.SplitPanel; +import com.itmill.toolkit.ui.Tree; +import com.itmill.toolkit.ui.Window; + +/** + * TestBench finds out testable classes within given java packages and adds them + * to menu from where they can be executed. Class is considered testable if it + * is of class CustomComponent. + * + * Note: edit TestBench.testablePackages array + * + * @author IT Mill Ltd. + * + */ +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.demo.testbench" }; + + 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); + for (Iterator i = itemCaptions.keySet().iterator(); i.hasNext();) { + Class testable = (Class) i.next(); + // simplify captions + String name = testable.getName().substring( + testable.getName().lastIndexOf('.') + 1); + menu.setItemCaption(testable, name); + } + // expand all root items + for (Iterator i = menu.rootItemIds().iterator(); i.hasNext();) { + menu.expandItemsRecursively(i.next()); + } + + 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 custom component: " + + e1.toString()); + } + } + } + + // Handle menu selection and update body + public void valueChange(Property.ValueChangeEvent event) { + bodyLayout.removeAllComponents(); + bodyLayout.setCaption(null); + + Object o = menu.getValue(); + if (o != null && o instanceof Class) { + Class c = (Class) o; + 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 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.ui.CustomComponent.class))) { + classes.add(c); + } + } + } + } + } + } + + return classes; + } + +} diff --git a/src/com/itmill/toolkit/tests/testbench/TestForAlignments.java b/src/com/itmill/toolkit/tests/testbench/TestForAlignments.java new file mode 100644 index 0000000000..858ddaa29b --- /dev/null +++ b/src/com/itmill/toolkit/tests/testbench/TestForAlignments.java @@ -0,0 +1,62 @@ +package com.itmill.toolkit.tests.testbench; + +import com.itmill.toolkit.ui.Button; +import com.itmill.toolkit.ui.CustomComponent; +import com.itmill.toolkit.ui.DateField; +import com.itmill.toolkit.ui.OrderedLayout; +import com.itmill.toolkit.ui.TextField; + +public class TestForAlignments extends CustomComponent { + + public TestForAlignments() { + + OrderedLayout main = new OrderedLayout(); + + Button b1 = new Button("Right"); + Button b2 = new Button("Left"); + Button b3 = new Button("Bottom"); + Button b4 = new Button("Top"); + TextField t1 = new TextField("Right aligned"); + TextField t2 = new TextField("Bottom aligned"); + DateField d1 = new DateField("Center aligned"); + DateField d2 = new DateField("Center aligned"); + + OrderedLayout vert = new OrderedLayout(); + vert.addComponent(b1); + vert.addComponent(b2); + vert.addComponent(t1); + vert.addComponent(d1); + vert.setWidth(500); + vert.setComponentAlignment(b1, OrderedLayout.ALIGNMENT_RIGHT, + OrderedLayout.ALIGNMENT_TOP); + vert.setComponentAlignment(b2, OrderedLayout.ALIGNMENT_LEFT, + OrderedLayout.ALIGNMENT_TOP); + vert.setComponentAlignment(t1, OrderedLayout.ALIGNMENT_RIGHT, + OrderedLayout.ALIGNMENT_TOP); + vert.setComponentAlignment(d1, + OrderedLayout.ALIGNMENT_HORIZONTAL_CENTER, + OrderedLayout.ALIGNMENT_TOP); + OrderedLayout hori = new OrderedLayout( + OrderedLayout.ORIENTATION_HORIZONTAL); + hori.addComponent(b3); + hori.addComponent(b4); + hori.addComponent(t2); + hori.addComponent(d2); + hori.setHeight(200); + hori.setComponentAlignment(b3, OrderedLayout.ALIGNMENT_LEFT, + OrderedLayout.ALIGNMENT_BOTTOM); + hori.setComponentAlignment(b4, OrderedLayout.ALIGNMENT_LEFT, + OrderedLayout.ALIGNMENT_TOP); + hori.setComponentAlignment(t2, OrderedLayout.ALIGNMENT_LEFT, + OrderedLayout.ALIGNMENT_BOTTOM); + hori.setComponentAlignment(d2, OrderedLayout.ALIGNMENT_LEFT, + OrderedLayout.ALIGNMENT_VERTICAL_CENTER); + + main.addComponent(vert); + main.addComponent(hori); + + setCompositionRoot(main); + + } + +} diff --git a/src/com/itmill/toolkit/tests/testbench/TestForBasicApplicationLayout.java b/src/com/itmill/toolkit/tests/testbench/TestForBasicApplicationLayout.java new file mode 100644 index 0000000000..822c408be1 --- /dev/null +++ b/src/com/itmill/toolkit/tests/testbench/TestForBasicApplicationLayout.java @@ -0,0 +1,116 @@ +package com.itmill.toolkit.tests.testbench; + +import java.sql.SQLException; +import java.util.Locale; + +import com.itmill.toolkit.data.util.QueryContainer; +import com.itmill.toolkit.demo.util.SampleDatabase; +import com.itmill.toolkit.terminal.Sizeable; +import com.itmill.toolkit.ui.Button; +import com.itmill.toolkit.ui.CustomComponent; +import com.itmill.toolkit.ui.DateField; +import com.itmill.toolkit.ui.ExpandLayout; +import com.itmill.toolkit.ui.Label; +import com.itmill.toolkit.ui.OrderedLayout; +import com.itmill.toolkit.ui.Panel; +import com.itmill.toolkit.ui.SplitPanel; +import com.itmill.toolkit.ui.TabSheet; +import com.itmill.toolkit.ui.Table; +import com.itmill.toolkit.ui.Button.ClickEvent; +import com.itmill.toolkit.ui.Button.ClickListener; + +public class TestForBasicApplicationLayout extends CustomComponent { + + private Button click; + private Button click2; + private TabSheet tab; + + // Database provided with sample data + private SampleDatabase sampleDatabase; + + public TestForBasicApplicationLayout() { + + click = new Button("Set height -1", new ClickListener() { + + public void buttonClick(ClickEvent event) { + tab.setHeight(-1); + } + + }); + + click2 = new Button("Set height 100%", new ClickListener() { + + public void buttonClick(ClickEvent event) { + tab.setHeight(100); + tab.setHeightUnits(Sizeable.UNITS_PERCENTAGE); + } + + }); + + SplitPanel sp = new SplitPanel(SplitPanel.ORIENTATION_HORIZONTAL); + sp.setSplitPosition(290, Sizeable.UNITS_PIXELS); + + SplitPanel sp2 = new SplitPanel(SplitPanel.ORIENTATION_VERTICAL); + sp2.setSplitPosition(255, Sizeable.UNITS_PIXELS); + + Panel p = new Panel("Accordion Panel"); + p.setSizeFull(); + + tab = new TabSheet(); + tab.setSizeFull(); + + Panel report = new Panel("Monthly Program Runs", new ExpandLayout()); + OrderedLayout controls = new OrderedLayout(); + controls.setMargin(true); + controls.addComponent(new Label("Report tab")); + controls.addComponent(click); + controls.addComponent(click2); + report.addComponent(controls); + DateField cal = new DateField(); + cal.setResolution(DateField.RESOLUTION_DAY); + cal.setLocale(new Locale("en", "US")); + report.addComponent(cal); + ((ExpandLayout) report.getLayout()).expand(controls); + report.addStyleName(Panel.STYLE_LIGHT); + report.setHeight(100); + report.setHeightUnits(Sizeable.UNITS_PERCENTAGE); + + sp2.setFirstComponent(report); + + Table table = new Table(); + // populate Toolkit table component with test SQL table rows + try { + sampleDatabase = new SampleDatabase(); + QueryContainer qc = new QueryContainer("SELECT * FROM employee", + sampleDatabase.getConnection()); + table.setContainerDataSource(qc); + } catch (SQLException e) { + e.printStackTrace(); + } + // define which columns should be visible on Table component + table.setVisibleColumns(new Object[] { "FIRSTNAME", "LASTNAME", + "TITLE", "UNIT" }); + table.setItemCaptionPropertyId("ID"); + table.setPageLength(15); + table.setSelectable(true); + table.setRowHeaderMode(Table.ROW_HEADER_MODE_INDEX); + table.setColumnCollapsingAllowed(true); + table.setColumnReorderingAllowed(true); + table.setSortDisabled(false); + table.setSizeFull(); + table.addStyleName("table-inline"); + sp2.setSecondComponent(table); + + tab.addTab(new Label("Tab1"), "Summary", null); + tab.addTab(sp2, "Reports", null); + tab.addTab(new Label("Tab 3"), "Statistics", null); + tab.addTab(new Label("Tab 4"), "Error Tracking", null); + tab.setSelectedTab(sp2); + + sp.setFirstComponent(p); + sp.setSecondComponent(tab); + + setCompositionRoot(sp); + } + +} diff --git a/src/com/itmill/toolkit/tests/testbench/TestForContainerFilterable.java b/src/com/itmill/toolkit/tests/testbench/TestForContainerFilterable.java new file mode 100644 index 0000000000..93320ee0d8 --- /dev/null +++ b/src/com/itmill/toolkit/tests/testbench/TestForContainerFilterable.java @@ -0,0 +1,93 @@ +package com.itmill.toolkit.tests.testbench; + +import com.itmill.toolkit.data.util.IndexedContainer; +import com.itmill.toolkit.terminal.Sizeable; +import com.itmill.toolkit.ui.Button; +import com.itmill.toolkit.ui.CustomComponent; +import com.itmill.toolkit.ui.Label; +import com.itmill.toolkit.ui.OrderedLayout; +import com.itmill.toolkit.ui.Panel; +import com.itmill.toolkit.ui.Table; +import com.itmill.toolkit.ui.TextField; +import com.itmill.toolkit.ui.Button.ClickEvent; + +public class TestForContainerFilterable extends CustomComponent { + + OrderedLayout lo = new OrderedLayout(); + IndexedContainer ic = new IndexedContainer(); + Table t = new Table(); + private static String parts[] = { "Neo", "Sa", "rem", "the", "adi", "za", + "tre", "day", "Ca", "re", "cen", "ter", "mi", "nal" }; + TextField firstFilter = new TextField("first-filter"); + TextField secondFilter = new TextField("second-filter"); + Button filterButton = new Button("Filter"); + Label count = new Label(); + + public TestForContainerFilterable() { + setCompositionRoot(lo); + + // Init datasource + ic.addContainerProperty("first", String.class, ""); + ic.addContainerProperty("second", String.class, ""); + for (int i = 0; i < 1000; i++) { + Object id = ic.addItem(); + ic.getContainerProperty(id, "first").setValue(randomWord()); + ic.getContainerProperty(id, "second").setValue(randomWord()); + } + + // Init filtering view + Panel filterPanel = new Panel("Filter", new OrderedLayout( + OrderedLayout.ORIENTATION_HORIZONTAL)); + filterPanel.setWidth(100); + filterPanel.setWidthUnits(Sizeable.UNITS_PERCENTAGE); + lo.addComponent(filterPanel); + filterPanel.addComponent(firstFilter); + filterPanel.addComponent(secondFilter); + filterPanel.addComponent(filterButton); + firstFilter + .setDescription("Filters first column in case-sensitive contains manner."); + secondFilter + .setDescription("Filters second column in case-insensitive prefix manner."); + filterPanel.addComponent(count); + + // Table + lo.addComponent(t); + t.setPageLength(12); + t.setWidth(100); + t.setWidthUnits(Sizeable.UNITS_PERCENTAGE); + t.setContainerDataSource(ic); + + // Handler + filterButton.addListener(new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + ic.removeAllContainerFilters(); + if (firstFilter.toString().length() > 0) { + ic.addContainerFilter("first", firstFilter.toString(), false, + false); + } + if (secondFilter.toString().length() > 0) { + ic.addContainerFilter("second", secondFilter.toString(), true, + true); + } + count.setValue("Rows in table: " + ic.size()); + } + }); + + // Resetbutton + lo.addComponent(new Button("Rebind table datasource", + new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + t.setContainerDataSource(ic); + } + })); + } + + private String randomWord() { + int len = (int) (Math.random() * 4); + StringBuffer buf = new StringBuffer(); + while (len-- >= 0) { + buf.append(parts[(int) (Math.random() * parts.length)]); + } + return buf.toString(); + } +} diff --git a/src/com/itmill/toolkit/tests/testbench/TestForMultipleStyleNames.java b/src/com/itmill/toolkit/tests/testbench/TestForMultipleStyleNames.java new file mode 100644 index 0000000000..a4649bbb18 --- /dev/null +++ b/src/com/itmill/toolkit/tests/testbench/TestForMultipleStyleNames.java @@ -0,0 +1,92 @@ +package com.itmill.toolkit.tests.testbench; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; + +import com.itmill.toolkit.data.Property.ValueChangeEvent; +import com.itmill.toolkit.data.Property.ValueChangeListener; +import com.itmill.toolkit.data.util.IndexedContainer; +import com.itmill.toolkit.ui.CustomComponent; +import com.itmill.toolkit.ui.Label; +import com.itmill.toolkit.ui.OrderedLayout; +import com.itmill.toolkit.ui.TwinColSelect; + +/** + * TODO: Note you need to add Theme under WebContent/ITMILL/Themes/mytheme in + * order to see actual visible results on the browser. Currently changes are + * visible only by inspecting DOM. + * + * @author IT Mill Ltd. + */ +public class TestForMultipleStyleNames extends CustomComponent implements + ValueChangeListener { + + private final OrderedLayout main = new OrderedLayout(); + + private Label l; + + private final TwinColSelect s = new TwinColSelect(); + + private ArrayList styleNames2; + + public TestForMultipleStyleNames() { + setCompositionRoot(main); + createNewView(); + } + + public void createNewView() { + main.removeAllComponents(); + main.addComponent(new Label( + "TK5 supports multiple stylenames for components.")); + main.addComponent(new Label("Note you need to add Theme under" + + " WebContent/ITMILL/Themes/mytheme" + + " in order to see actual visible results" + + " on the browser. Currently changes are" + + " visible only by inspecting DOM.")); + + styleNames2 = new ArrayList(); + + styleNames2.add("red"); + styleNames2.add("bold"); + styleNames2.add("italic"); + + s.setContainerDataSource(new IndexedContainer(styleNames2)); + s.addListener(this); + s.setImmediate(true); + main.addComponent(s); + + l = new Label("Test labele"); + main.addComponent(l); + + } + + public void valueChange(ValueChangeEvent event) { + + String currentStyle = l.getStyle(); + String[] tmp = currentStyle.split(" "); + ArrayList curStyles = new ArrayList(); + for (int i = 0; i < tmp.length; i++) { + if (tmp[i] != "") { + curStyles.add(tmp[i]); + } + } + + Collection styles = (Collection) s.getValue(); + + for (Iterator iterator = styles.iterator(); iterator.hasNext();) { + String styleName = (String) iterator.next(); + if (curStyles.contains(styleName)) { + // already added + curStyles.remove(styleName); + } else { + l.addStyleName(styleName); + } + } + for (Iterator iterator2 = curStyles.iterator(); iterator2.hasNext();) { + String object = (String) iterator2.next(); + l.removeStyleName(object); + } + } + +} diff --git a/src/com/itmill/toolkit/tests/testbench/TestForPreconfiguredComponents.java b/src/com/itmill/toolkit/tests/testbench/TestForPreconfiguredComponents.java new file mode 100644 index 0000000000..99ca0e3089 --- /dev/null +++ b/src/com/itmill/toolkit/tests/testbench/TestForPreconfiguredComponents.java @@ -0,0 +1,182 @@ +package com.itmill.toolkit.tests.testbench; + +import com.itmill.toolkit.event.Action; +import com.itmill.toolkit.event.Action.Handler; +import com.itmill.toolkit.ui.AbstractSelect; +import com.itmill.toolkit.ui.Button; +import com.itmill.toolkit.ui.CheckBox; +import com.itmill.toolkit.ui.Component; +import com.itmill.toolkit.ui.CustomComponent; +import com.itmill.toolkit.ui.Label; +import com.itmill.toolkit.ui.NativeSelect; +import com.itmill.toolkit.ui.OptionGroup; +import com.itmill.toolkit.ui.OrderedLayout; +import com.itmill.toolkit.ui.Panel; +import com.itmill.toolkit.ui.Tree; +import com.itmill.toolkit.ui.TwinColSelect; +import com.itmill.toolkit.ui.Button.ClickEvent; +import com.itmill.toolkit.ui.Button.ClickListener; + +/** + * @author IT Mill Ltd. + */ +public class TestForPreconfiguredComponents extends CustomComponent implements + Handler { + + private static final String[] firstnames = new String[] { "John", "Mary", + "Joe", "Sarah", "Jeff", "Jane", "Peter", "Marc", "Josie", "Linus" }; + + private static final String[] lastnames = new String[] { "Torvalds", + "Smith", "Jones", "Beck", "Sheridan", "Picard", "Hill", "Fielding", + "Einstein" }; + + private final OrderedLayout main = new OrderedLayout(); + + private final Action[] actions = new Action[] { new Action("edit"), + new Action("delete") }; + + private Panel al; + + private Tree contextTree; + + public TestForPreconfiguredComponents() { + + setCompositionRoot(main); + createNewView(); + } + + public void createNewView() { + main.removeAllComponents(); + main + .addComponent(new Label( + "In Toolkit 5 we introduce new componens. Previously we" + + " usually used setStyle or some other methods on possibly " + + "multiple steps to configure component for ones needs. These new " + + "server side components are mostly just classes that in constructor " + + "set base class to state that programmer wants.")); + + main.addComponent(new Button("commit")); + + Panel test = createTestBench(new CheckBox()); + test.setCaption("CheckBox (configured from button)"); + main.addComponent(test); + + AbstractSelect s = new TwinColSelect(); + fillSelect(s, 20); + test = createTestBench(s); + test.setCaption("TwinColSelect (configured from select)"); + main.addComponent(test); + + s = new NativeSelect(); + fillSelect(s, 20); + test = createTestBench(s); + test.setCaption("Native (configured from select)"); + main.addComponent(test); + + s = new OptionGroup(); + fillSelect(s, 20); + test = createTestBench(s); + test.setCaption("OptionGroup (configured from select)"); + main.addComponent(test); + + s = new OptionGroup(); + fillSelect(s, 20); + s.setMultiSelect(true); + test = createTestBench(s); + test + .setCaption("OptionGroup + multiselect manually (configured from select)"); + main.addComponent(test); + + Button b = new Button("refresh view", this, "createNewView"); + main.addComponent(b); + + } + + public static void fillSelect(AbstractSelect s, int items) { + for (int i = 0; i < items; i++) { + String name = firstnames[(int) (Math.random() * (firstnames.length - 1))] + + " " + + lastnames[(int) (Math.random() * (lastnames.length - 1))]; + s.addItem(name); + } + } + + public Tree createTestTree() { + Tree t = new Tree("Tree"); + String[] names = new String[100]; + for (int i = 0; i < names.length; i++) { + names[i] = firstnames[(int) (Math.random() * (firstnames.length - 1))] + + " " + + lastnames[(int) (Math.random() * (lastnames.length - 1))]; + } + + // Create tree + t = new Tree("Organization Structure"); + for (int i = 0; i < 100; i++) { + t.addItem(names[i]); + String parent = names[(int) (Math.random() * (names.length - 1))]; + if (t.containsId(parent)) { + t.setParent(names[i], parent); + } + } + + // Forbid childless people to have children (makes them leaves) + for (int i = 0; i < 100; i++) { + if (!t.hasChildren(names[i])) { + t.setChildrenAllowed(names[i], false); + } + } + return t; + } + + public Panel createTestBench(Component t) { + Panel ol = new Panel(); + ol.setLayout(new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL)); + + ol.addComponent(t); + + final OrderedLayout ol2 = new OrderedLayout( + OrderedLayout.ORIENTATION_HORIZONTAL); + final Panel status = new Panel("Events"); + final Button clear = new Button("clear event log"); + clear.addListener(new ClickListener() { + public void buttonClick(ClickEvent event) { + status.removeAllComponents(); + status.addComponent(ol2); + } + }); + ol2.addComponent(clear); + final Button commit = new Button("commit changes"); + ol2.addComponent(commit); + status.addComponent(ol2); + + status.setHeight(300); + status.setWidth(400); + + ol.addComponent(status); + + t.addListener(new Listener() { + public void componentEvent(Event event) { + status.addComponent(new Label(event.getClass().getName())); + status.addComponent(new Label("selected: " + + event.getSource().toString())); + } + }); + + return ol; + } + + public Action[] getActions(Object target, Object sender) { + return actions; + } + + public void handleAction(Action action, Object sender, Object target) { + if (action == actions[1]) { + al.addComponent(new Label("Delete selected on " + target)); + contextTree.removeItem(target); + + } else { + al.addComponent(new Label("Edit selected on " + target)); + } + } +} diff --git a/src/com/itmill/toolkit/tests/testbench/TestForRichTextEditor.java b/src/com/itmill/toolkit/tests/testbench/TestForRichTextEditor.java new file mode 100644 index 0000000000..ebefb888c9 --- /dev/null +++ b/src/com/itmill/toolkit/tests/testbench/TestForRichTextEditor.java @@ -0,0 +1,53 @@ +package com.itmill.toolkit.tests.testbench; + +import com.itmill.toolkit.data.Property.ValueChangeEvent; +import com.itmill.toolkit.data.Property.ValueChangeListener; +import com.itmill.toolkit.ui.Button; +import com.itmill.toolkit.ui.CustomComponent; +import com.itmill.toolkit.ui.Label; +import com.itmill.toolkit.ui.OrderedLayout; +import com.itmill.toolkit.ui.RichTextArea; + +/** + * + * @author IT Mill Ltd. + */ +public class TestForRichTextEditor extends CustomComponent implements + ValueChangeListener { + + private OrderedLayout main = new OrderedLayout(); + + private Label l; + + private RichTextArea rte; + + public TestForRichTextEditor() { + + setCompositionRoot(main); + createNewView(); + } + + public void createNewView() { + main.removeAllComponents(); + main.addComponent(new Label( + "RTE uses google richtextArea and their examples toolbar.")); + + rte = new RichTextArea(); + rte.addListener(this); + + rte.setEnabled(false); + + main.addComponent(rte); + + main.addComponent(new Button("commit content to label below")); + + l = new Label("", Label.CONTENT_XHTML); + main.addComponent(l); + + } + + public void valueChange(ValueChangeEvent event) { + l.setValue(rte.getValue()); + } + +} diff --git a/src/com/itmill/toolkit/tests/testbench/TestForTrees.java b/src/com/itmill/toolkit/tests/testbench/TestForTrees.java new file mode 100644 index 0000000000..cf89b2c27b --- /dev/null +++ b/src/com/itmill/toolkit/tests/testbench/TestForTrees.java @@ -0,0 +1,162 @@ +package com.itmill.toolkit.tests.testbench; + +import com.itmill.toolkit.event.Action; +import com.itmill.toolkit.event.Action.Handler; +import com.itmill.toolkit.ui.Button; +import com.itmill.toolkit.ui.Component; +import com.itmill.toolkit.ui.CustomComponent; +import com.itmill.toolkit.ui.Label; +import com.itmill.toolkit.ui.OrderedLayout; +import com.itmill.toolkit.ui.Panel; +import com.itmill.toolkit.ui.Tree; +import com.itmill.toolkit.ui.Button.ClickEvent; +import com.itmill.toolkit.ui.Button.ClickListener; + +/** + * Some test cases for trees. Events panel logs events that happen server side. + * + * @author IT Mill Ltd. + */ +public class TestForTrees extends CustomComponent implements Handler { + + private static final String[] firstnames = new String[] { "John", "Mary", + "Joe", "Sarah", "Jeff", "Jane", "Peter", "Marc", "Josie", "Linus" }; + + private static final String[] lastnames = new String[] { "Torvalds", + "Smith", "Jones", "Beck", "Sheridan", "Picard", "Hill", "Fielding", + "Einstein" }; + + private OrderedLayout main = new OrderedLayout(); + + private Action[] actions = new Action[] { new Action("edit"), + new Action("delete") }; + + private Panel al; + + private Tree contextTree; + + public TestForTrees() { + + setCompositionRoot(main); + createNewView(); + } + + public void createNewView() { + main.removeAllComponents(); + main + .addComponent(new Label( + "Some test cases for trees. Events panel logs events that happen server side.")); + + main.addComponent(new Button("commit")); + + Tree t; + + t = createTestTree(); + t.setCaption("Default settings"); + main.addComponent(createTestBench(t)); + + t = createTestTree(); + t.setCaption("Multiselect settings"); + t.setMultiSelect(true); + main.addComponent(createTestBench(t)); + + t = createTestTree(); + t.setCaption("Multiselect and immediate"); + t.setImmediate(true); + t.setMultiSelect(true); + main.addComponent(createTestBench(t)); + + t = createTestTree(); + t.setCaption("immediate"); + t.setImmediate(true); + main.addComponent(createTestBench(t)); + + t = createTestTree(); + t.setCaption("with actions"); + t.setImmediate(true); + t.addActionHandler(this); + OrderedLayout ol = (OrderedLayout) createTestBench(t); + al = new Panel("action log"); + ol.addComponent(al); + main.addComponent(ol); + contextTree = t; + + Button b = new Button("refresh view", this, "createNewView"); + main.addComponent(b); + + } + + public Tree createTestTree() { + Tree t = new Tree("Tree"); + String[] names = new String[100]; + for (int i = 0; i < names.length; i++) { + names[i] = firstnames[(int) (Math.random() * (firstnames.length - 1))] + + " " + + lastnames[(int) (Math.random() * (lastnames.length - 1))]; + } + + // Create tree + t = new Tree("Organization Structure"); + for (int i = 0; i < 100; i++) { + t.addItem(names[i]); + String parent = names[(int) (Math.random() * (names.length - 1))]; + if (t.containsId(parent)) { + t.setParent(names[i], parent); + } + } + + // Forbid childless people to have children (makes them leaves) + for (int i = 0; i < 100; i++) { + if (!t.hasChildren(names[i])) { + t.setChildrenAllowed(names[i], false); + } + } + return t; + } + + public Component createTestBench(Tree t) { + OrderedLayout ol = new OrderedLayout(); + ol.setOrientation(OrderedLayout.ORIENTATION_HORIZONTAL); + + ol.addComponent(t); + + final Panel status = new Panel("Events"); + final Button clear = new Button("c"); + clear.addListener(new ClickListener() { + public void buttonClick(ClickEvent event) { + status.removeAllComponents(); + status.addComponent(clear); + } + }); + status.addComponent(clear); + + status.setHeight(300); + status.setWidth(400); + + ol.addComponent(status); + + t.addListener(new Listener() { + public void componentEvent(Event event) { + status.addComponent(new Label(event.getClass().getName())); + status.addComponent(new Label("selected: " + + event.getSource().toString())); + } + }); + + return ol; + } + + public Action[] getActions(Object target, Object sender) { + return actions; + } + + public void handleAction(Action action, Object sender, Object target) { + if (action == actions[1]) { + al.addComponent(new Label("Delete selected on " + target)); + contextTree.removeItem(target); + + } else { + al.addComponent(new Label("Edit selected on " + target)); + } + } +} diff --git a/src/com/itmill/toolkit/tests/testbench/TestForUpload.java b/src/com/itmill/toolkit/tests/testbench/TestForUpload.java new file mode 100644 index 0000000000..2e6c5d4e29 --- /dev/null +++ b/src/com/itmill/toolkit/tests/testbench/TestForUpload.java @@ -0,0 +1,345 @@ +package com.itmill.toolkit.tests.testbench; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import com.itmill.toolkit.data.Property.ValueChangeEvent; +import com.itmill.toolkit.terminal.StreamResource; +import com.itmill.toolkit.ui.AbstractField; +import com.itmill.toolkit.ui.Button; +import com.itmill.toolkit.ui.CustomComponent; +import com.itmill.toolkit.ui.Label; +import com.itmill.toolkit.ui.Layout; +import com.itmill.toolkit.ui.Link; +import com.itmill.toolkit.ui.OrderedLayout; +import com.itmill.toolkit.ui.Panel; +import com.itmill.toolkit.ui.ProgressIndicator; +import com.itmill.toolkit.ui.Select; +import com.itmill.toolkit.ui.Upload; +import com.itmill.toolkit.ui.Button.ClickEvent; +import com.itmill.toolkit.ui.Upload.FailedEvent; +import com.itmill.toolkit.ui.Upload.FailedListener; +import com.itmill.toolkit.ui.Upload.FinishedEvent; +import com.itmill.toolkit.ui.Upload.FinishedListener; +import com.itmill.toolkit.ui.Upload.StartedEvent; +import com.itmill.toolkit.ui.Upload.StartedListener; +import com.itmill.toolkit.ui.Upload.SucceededEvent; +import com.itmill.toolkit.ui.Upload.SucceededListener; + +public class TestForUpload extends CustomComponent implements + Upload.FinishedListener, FailedListener, SucceededListener, + Upload.ProgressListener, StartedListener { + + Layout main = new OrderedLayout(); + + Buffer buffer = new MemoryBuffer(); + + Panel status = new Panel("Uploaded file:"); + + private final Upload up; + + private final Label l; + + private final ProgressIndicator pi = new ProgressIndicator(); + + private final Label memoryStatus; + + private final Select uploadBufferSelector; + + public TestForUpload() { + setCompositionRoot(main); + main.addComponent(new Label( + "This is a simple test for upload application. " + + "Upload should work with big files and concurrent " + + "requests should not be blocked. Button 'b' reads " + + "current state into label below it. Memory receiver " + + "streams upload contents into memory. You may track" + + "consumption." + + "tempfile receiver writes upload to file and " + + "should have low memory consumption.")); + + main + .addComponent(new Label( + "Clicking on button b updates information about upload components status or same with garbage collector.")); + + up = new Upload("Upload", buffer); + up.setImmediate(true); + up.addListener((FinishedListener) this); + up.addListener((FailedListener) this); + up.addListener((SucceededListener) this); + up.addListener((StartedListener) this); + + up.setProgressListener(this); + + Button b = new Button("b", this, "readState"); + + Button c = new Button("b with gc", this, "gc"); + + main.addComponent(b); + main.addComponent(c); + + uploadBufferSelector = new Select("Receiver type"); + uploadBufferSelector.setImmediate(true); + uploadBufferSelector.addItem("memory"); + uploadBufferSelector.setValue("memory"); + uploadBufferSelector.addItem("tempfile"); + uploadBufferSelector + .addListener(new AbstractField.ValueChangeListener() { + public void valueChange(ValueChangeEvent event) { + setBuffer(); + } + }); + main.addComponent(uploadBufferSelector); + + main.addComponent(up); + l = new Label("Idle"); + main.addComponent(l); + + pi.setVisible(false); + pi.setPollingInterval(1000); + main.addComponent(pi); + + memoryStatus = new Label(); + main.addComponent(memoryStatus); + + status.setVisible(false); + main.addComponent(status); + + Button restart = new Button("R"); + restart.addListener(new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + getApplication().close(); + } + }); + main.addComponent(restart); + + } + + private void setBuffer() { + String id = (String) uploadBufferSelector.getValue(); + if ("memory".equals(id)) { + buffer = new MemoryBuffer(); + } else if ("tempfile".equals(id)) { + buffer = new TmpFileBuffer(); + } + up.setReceiver(buffer); + } + + public void gc() { + Runtime.getRuntime().gc(); + readState(); + } + + public void readState() { + StringBuffer sb = new StringBuffer(); + + if (up.isUploading()) { + sb.append("Uploading..."); + sb.append(up.getBytesRead()); + sb.append("/"); + sb.append(up.getUploadSize()); + sb.append(" "); + sb.append(Math.round(100 * up.getBytesRead() + / (double) up.getUploadSize())); + sb.append("%"); + } else { + sb.append("Idle"); + } + l.setValue(sb.toString()); + refreshMemUsage(); + } + + public void uploadFinished(FinishedEvent event) { + status.removeAllComponents(); + InputStream stream = buffer.getStream(); + if (stream == null) { + status.addComponent(new Label( + "Upload finished, but output buffer is null!!")); + } else { + status + .addComponent(new Label("Name: " + + event.getFilename(), Label.CONTENT_XHTML)); + status.addComponent(new Label("Mimetype: " + + event.getMIMEType(), Label.CONTENT_XHTML)); + status.addComponent(new Label("Size: " + event.getLength() + + " bytes.", Label.CONTENT_XHTML)); + + status.addComponent(new Link("Download " + buffer.getFileName(), + new StreamResource(buffer, buffer.getFileName(), + getApplication()))); + + status.setVisible(true); + } + } + + public interface Buffer extends StreamResource.StreamSource, + Upload.Receiver { + + String getFileName(); + } + + public class MemoryBuffer implements Buffer { + ByteArrayOutputStream outputBuffer = null; + + String mimeType; + + String fileName; + + public MemoryBuffer() { + + } + + public InputStream getStream() { + if (outputBuffer == null) { + return null; + } + return new ByteArrayInputStream(outputBuffer.toByteArray()); + } + + /** + * @see com.itmill.toolkit.ui.Upload.Receiver#receiveUpload(String, + * String) + */ + public OutputStream receiveUpload(String filename, String MIMEType) { + fileName = filename; + mimeType = MIMEType; + outputBuffer = new ByteArrayOutputStream(); + return outputBuffer; + } + + /** + * Returns the fileName. + * + * @return String + */ + public String getFileName() { + return fileName; + } + + /** + * Returns the mimeType. + * + * @return String + */ + public String getMimeType() { + return mimeType; + } + + } + + public class TmpFileBuffer implements Buffer { + String mimeType; + + String fileName; + + private File file; + + private FileInputStream stream; + + public TmpFileBuffer() { + String tempFileName = "upload_tmpfile_" + + System.currentTimeMillis(); + try { + file = File.createTempFile(tempFileName, null); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + public InputStream getStream() { + if (file == null) { + return null; + } + try { + return new FileInputStream(file); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + /** + * @see com.itmill.toolkit.ui.Upload.Receiver#receiveUpload(String, + * String) + */ + public OutputStream receiveUpload(String filename, String MIMEType) { + fileName = filename; + mimeType = MIMEType; + try { + return new FileOutputStream(file); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + /** + * Returns the fileName. + * + * @return String + */ + public String getFileName() { + return fileName; + } + + /** + * Returns the mimeType. + * + * @return String + */ + public String getMimeType() { + return mimeType; + } + + } + + public void uploadFailed(FailedEvent event) { + System.out.println(event); + + System.out.println(event.getSource()); + + } + + public void uploadSucceeded(SucceededEvent event) { + pi.setVisible(false); + l.setValue("Finished upload, idle"); + System.out.println(event); + setBuffer(); + } + + public void updateProgress(long readBytes, long contentLenght) { + pi.setValue(new Float(readBytes / (float) contentLenght)); + + refreshMemUsage(); + } + + private void refreshMemUsage() { + memoryStatus.setValue("Not available in Java 1.4"); + /* + * StringBuffer mem = new StringBuffer(); MemoryMXBean mmBean = + * ManagementFactory.getMemoryMXBean(); mem.append("Heap (M):"); + * mem.append(mmBean.getHeapMemoryUsage().getUsed() / 1048576); + * mem.append(" |�Non-Heap (M):"); + * mem.append(mmBean.getNonHeapMemoryUsage().getUsed() / 1048576); + * memoryStatus.setValue(mem.toString()); + */ + } + + public void uploadStarted(StartedEvent event) { + pi.setVisible(true); + l.setValue("Started uploading file " + event.getFilename()); + } + +} diff --git a/src/com/itmill/toolkit/tests/testbench/TestForWindowOpen.java b/src/com/itmill/toolkit/tests/testbench/TestForWindowOpen.java new file mode 100644 index 0000000000..b8f94e13d7 --- /dev/null +++ b/src/com/itmill/toolkit/tests/testbench/TestForWindowOpen.java @@ -0,0 +1,55 @@ +package com.itmill.toolkit.tests.testbench; + +import com.itmill.toolkit.terminal.ExternalResource; +import com.itmill.toolkit.ui.Button; +import com.itmill.toolkit.ui.CustomComponent; +import com.itmill.toolkit.ui.OrderedLayout; +import com.itmill.toolkit.ui.Button.ClickEvent; + +public class TestForWindowOpen extends CustomComponent { + + public TestForWindowOpen() { + + OrderedLayout main = new OrderedLayout(); + setCompositionRoot(main); + + main.addComponent(new Button("Open in this window", + new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + ExternalResource r = new ExternalResource( + "http://www.google.com"); + getApplication().getMainWindow().open(r); + + } + + })); + + main.addComponent(new Button("Open in target \"mytarget\"", + new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + ExternalResource r = new ExternalResource( + "http://www.google.com"); + getApplication().getMainWindow().open(r, "mytarget"); + + } + + })); + + main.addComponent(new Button("Open in target \"secondtarget\"", + new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + ExternalResource r = new ExternalResource( + "http://www.google.com"); + getApplication().getMainWindow() + .open(r, "secondtarget"); + + } + + })); + + } + +} diff --git a/src/com/itmill/toolkit/tests/testbench/TestForWindowing.java b/src/com/itmill/toolkit/tests/testbench/TestForWindowing.java new file mode 100644 index 0000000000..eec366b578 --- /dev/null +++ b/src/com/itmill/toolkit/tests/testbench/TestForWindowing.java @@ -0,0 +1,84 @@ +package com.itmill.toolkit.tests.testbench; + +import com.itmill.toolkit.data.Property.ValueChangeEvent; +import com.itmill.toolkit.data.Property.ValueChangeListener; +import com.itmill.toolkit.ui.AbstractSelect; +import com.itmill.toolkit.ui.Button; +import com.itmill.toolkit.ui.CustomComponent; +import com.itmill.toolkit.ui.Label; +import com.itmill.toolkit.ui.OptionGroup; +import com.itmill.toolkit.ui.OrderedLayout; +import com.itmill.toolkit.ui.Select; +import com.itmill.toolkit.ui.Slider; +import com.itmill.toolkit.ui.Window; +import com.itmill.toolkit.ui.Button.ClickEvent; +import com.itmill.toolkit.ui.Button.ClickListener; + +public class TestForWindowing extends CustomComponent { + + private Select s2; + + public TestForWindowing() { + + OrderedLayout main = new OrderedLayout(); + + main.addComponent(new Label( + "Click the button to create a new inline window.")); + + Button create = new Button("Create a new window", new ClickListener() { + + public void buttonClick(ClickEvent event) { + Window w = new Window("Testing Window"); + + AbstractSelect s1 = new OptionGroup(); + s1.setCaption("1. Select output format"); + s1.addItem("Excel sheet"); + s1.addItem("CSV plain text"); + s1.setValue("Excel sheet"); + + s2 = new Select(); + s2.addItem("Separate by comma (,)"); + s2.addItem("Separate by colon (:)"); + s2.addItem("Separate by semicolon (;)"); + s2.setEnabled(false); + + s1.addListener(new ValueChangeListener() { + + public void valueChange(ValueChangeEvent event) { + String v = (String) event.getProperty().getValue(); + if (v.equals("CSV plain text")) { + s2.setEnabled(true); + } else { + s2.setEnabled(false); + } + } + + }); + + w.addComponent(s1); + w.addComponent(s2); + + Slider s = new Slider(); + s.setCaption("Volume"); + s.setMax(13); + s.setMin(12); + s.setResolution(2); + s.setImmediate(true); + // s.setOrientation(Slider.ORIENTATION_VERTICAL); + // s.setArrows(false); + + w.addComponent(s); + + getApplication().getMainWindow().addWindow(w); + + } + + }); + + main.addComponent(create); + + setCompositionRoot(main); + + } + +} diff --git a/src/com/itmill/toolkit/tests/testbench/TestSetVisibleAndCaching.java b/src/com/itmill/toolkit/tests/testbench/TestSetVisibleAndCaching.java new file mode 100644 index 0000000000..2c6da7a26a --- /dev/null +++ b/src/com/itmill/toolkit/tests/testbench/TestSetVisibleAndCaching.java @@ -0,0 +1,77 @@ +package com.itmill.toolkit.tests.testbench; + +import com.itmill.toolkit.ui.Button; +import com.itmill.toolkit.ui.Label; +import com.itmill.toolkit.ui.Panel; +import com.itmill.toolkit.ui.Window; +import com.itmill.toolkit.ui.Button.ClickEvent; +import com.itmill.toolkit.ui.Button.ClickListener; + +public class TestSetVisibleAndCaching extends com.itmill.toolkit.Application { + + Panel panelA = new Panel("Panel A"); + Panel panelB = new Panel("Panel B"); + Panel panelC = new Panel("Panel C"); + + Button buttonNextPanel = new Button("Show next panel"); + + int selectedPanel = 0; + + public void init() { + Window mainWindow = new Window("TestSetVisibleAndCaching"); + setMainWindow(mainWindow); + + panelA.addComponent(new Label( + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")); + panelB.addComponent(new Label( + "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB")); + panelC.addComponent(new Label( + "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC")); + + mainWindow + .addComponent(new Label( + "Inspect transfered data from server to " + + "client using firebug (http request / response cycles)." + + " See how widgets are re-used," + + " after each panel is once shown in GUI then" + + " their contents are not resend.")); + mainWindow.addComponent(buttonNextPanel); + mainWindow.addComponent(panelA); + mainWindow.addComponent(panelB); + mainWindow.addComponent(panelC); + + selectPanel(selectedPanel); + + buttonNextPanel.addListener(new ClickListener() { + public void buttonClick(ClickEvent event) { + selectedPanel++; + if (selectedPanel > 2) { + selectedPanel = 0; + } + selectPanel(selectedPanel); + } + }); + + } + + private void selectPanel(int selectedPanel) { + System.err.println("Selecting panel " + selectedPanel); + switch (selectedPanel) { + case 0: + panelA.setVisible(true); + panelB.setVisible(false); + panelC.setVisible(false); + break; + case 1: + panelA.setVisible(false); + panelB.setVisible(true); + panelC.setVisible(false); + break; + case 2: + panelA.setVisible(false); + panelB.setVisible(false); + panelC.setVisible(true); + break; + } + } +} diff --git a/src/com/itmill/toolkit/tests/testbench/TestSplitPanel.java b/src/com/itmill/toolkit/tests/testbench/TestSplitPanel.java new file mode 100644 index 0000000000..a4234cdcf5 --- /dev/null +++ b/src/com/itmill/toolkit/tests/testbench/TestSplitPanel.java @@ -0,0 +1,22 @@ +package com.itmill.toolkit.tests.testbench; + +import com.itmill.toolkit.ui.Label; +import com.itmill.toolkit.ui.SplitPanel; +import com.itmill.toolkit.ui.Window; + +public class TestSplitPanel extends com.itmill.toolkit.Application { + + SplitPanel verticalSplit = new SplitPanel(SplitPanel.ORIENTATION_VERTICAL); + + public void init() { + Window mainWindow = new Window("Feature Browser"); + setMainWindow(mainWindow); + + verticalSplit.setFirstComponent(new Label("vertical first")); + verticalSplit.setSecondComponent(new Label("vertical second")); + + mainWindow.setLayout(verticalSplit); + + } + +}