From: Marc Englund Date: Thu, 19 Feb 2009 15:24:01 +0000 (+0000) Subject: Sampler layout samples update done. For #2601, fixes #2621 X-Git-Tag: 6.7.0.beta1~3104 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d7e7ea3efe255b3989fb940a374fa0dc86448a30;p=vaadin-framework.git Sampler layout samples update done. For #2601, fixes #2621 svn changeset:6911/svn branch:trunk --- diff --git a/WebContent/ITMILL/themes/sampler/layouts/examplecustomlayout.html b/WebContent/ITMILL/themes/sampler/layouts/examplecustomlayout.html index f8ccbac660..1e139a6c9c 100644 --- a/WebContent/ITMILL/themes/sampler/layouts/examplecustomlayout.html +++ b/WebContent/ITMILL/themes/sampler/layouts/examplecustomlayout.html @@ -1,19 +1,38 @@ - - - - - - - -
- - - - - - - - - -
User name:
Password:
-
\ No newline at end of file + + + + + + + + + + + + + + + + + + +
+

Login

+
+
User name: +
+
Password: +
+
+
+
+ This + information is in the layout. + +
+ diff --git a/WebContent/ITMILL/themes/sampler/layouts/examplecustomlayout_forviewing.html b/WebContent/ITMILL/themes/sampler/layouts/examplecustomlayout_forviewing.html deleted file mode 100644 index 90803fd0f7..0000000000 --- a/WebContent/ITMILL/themes/sampler/layouts/examplecustomlayout_forviewing.html +++ /dev/null @@ -1,21 +0,0 @@ -
-<table width="100%" height="100%">
-  <tr height="100%">
-    <td>
-      <table align="center">
-        <tr>
-          <td align="right">User&nbsp;name:</td>
-          <td><div location="username"></div></td>
-        </tr>
-        <tr>
-          <td align="right">Password:</td>
-          <td><div location="password"></div></td>
-        </tr>
-      </table>
-    </td>
-  </tr>
-  <tr>
-    <td align="right" colspan="2"><div location="okbutton"></div></td>
-  </tr>
-</table>
-
\ No newline at end of file diff --git a/src/com/itmill/toolkit/demo/sampler/ExampleUtil.java b/src/com/itmill/toolkit/demo/sampler/ExampleUtil.java index 8b39a9cd52..5de67b3b63 100644 --- a/src/com/itmill/toolkit/demo/sampler/ExampleUtil.java +++ b/src/com/itmill/toolkit/demo/sampler/ExampleUtil.java @@ -10,6 +10,19 @@ import com.itmill.toolkit.terminal.Resource; import com.itmill.toolkit.terminal.ThemeResource; public final class ExampleUtil { + public static final String lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut ut massa eget erat dapibus sollicitudin. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Pellentesque a augue. Praesent non elit. Duis sapien dolor, cursus eget, pulvinar eget, eleifend a, est. Integer in nunc. Vivamus consequat ipsum id sapien. Duis eu elit vel libero posuere luctus. Aliquam ac turpis. Aenean vitae justo in sem iaculis pulvinar. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam sit amet mi. " + + "
" + + "Aenean auctor, mi sit amet ultricies pulvinar, dui urna adipiscing odio, ut faucibus odio mauris eget justo. Mauris quis magna quis augue interdum porttitor. Sed interdum, tortor laoreet tincidunt ullamcorper, metus velit hendrerit nunc, id laoreet mauris arcu vitae est. Nulla nec nisl. Mauris orci nibh, tempor nec, sollicitudin ac, venenatis sed, lorem. Quisque dignissim tempus erat. Maecenas molestie, pede ac ultrices interdum, felis neque vulputate quam, in sodales felis odio quis mi. Aliquam massa pede, pharetra quis, tincidunt quis, fringilla at, mauris. Vestibulum a massa. Vestibulum luctus odio ut quam. Maecenas congue convallis diam. Cras urna arcu, vestibulum vitae, blandit ut, laoreet id, risus. Ut condimentum, arcu sit amet placerat blandit, augue nibh pretium nunc, in tempus sem dolor non leo. Etiam fringilla mauris a odio. Nunc lorem diam, interdum eget, lacinia in, scelerisque sit amet, purus. Nam ornare. " + + "
" + + "Donec placerat dui ut orci. Phasellus quis lacus at nisl elementum cursus. Cras bibendum egestas nulla. Phasellus pulvinar ullamcorper odio. Etiam ipsum. Proin tincidunt. Aliquam aliquet. Etiam purus odio, commodo sed, feugiat volutpat, scelerisque molestie, velit. Aenean sed sem sit amet libero sodales ultrices. Donec dictum, arcu sed iaculis porttitor, est mauris pulvinar purus, sit amet porta purus neque in risus. Mauris libero. Maecenas rhoncus. Morbi quis nisl. " + + "
" + + "Vestibulum laoreet tortor eu elit. Cras euismod nulla eu sapien. Sed imperdiet. Maecenas vel sapien. Nulla at purus eu diam auctor lobortis. Donec pede eros, lacinia tincidunt, tempus eu, molestie nec, velit. Nullam ipsum odio, euismod non, aliquet nec, consequat ac, felis. Duis fermentum mauris sed justo. Suspendisse potenti. Praesent at libero sit amet ipsum imperdiet fermentum. Aliquam enim nisl, dictum id, lacinia sit amet, elementum posuere, ipsum. Integer luctus dictum libero. Pellentesque sed pede sed nisl bibendum porttitor. Phasellus tempor interdum nisi. Mauris nec magna. Phasellus massa pede, vehicula sed, ornare at, ullamcorper ut, nisl. Sed turpis nisl, hendrerit sit amet, consequat id, auctor nec, arcu. Quisque fringilla tincidunt massa. In eleifend, nulla sed mollis vestibulum, mauris orci facilisis ante, id pharetra dolor ipsum vitae sem. Integer dictum. " + + "
" + + "Nunc ut odio. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec mauris tellus, dapibus vel, hendrerit vel, sollicitudin ut, ligula. Ut justo metus, accumsan placerat, ultrices sit amet, congue at, nulla. Integer in quam. Cras sollicitudin mattis magna. Vestibulum neque eros, egestas ut, tincidunt vel, ullamcorper non, ligula. Vivamus eu lacus. Donec rhoncus metus et odio. Donec est. Nulla facilisi. Suspendisse potenti. Etiam tempor pede nec ante. Vestibulum adipiscing velit vel neque. " + + "
" + + "Quisque ornare erat rhoncus lectus. Donec vitae ante at enim mollis egestas. Mauris convallis. Fusce convallis, nisl eu sagittis suscipit, risus ligula aliquam libero, in imperdiet neque mi non risus. Aenean dictum ultricies risus. Praesent ut ligula vitae purus ornare auctor. Cras tellus mauris, adipiscing ac, dignissim auctor, faucibus in, sem. Cras mauris libero, pharetra sit amet, lacinia eu, vehicula eleifend, sapien. Donec ac tellus. Sed eros dui, vulputate vel, auctor pharetra, tincidunt at, ipsum. Duis at dolor ac leo condimentum pulvinar. Donec molestie, dolor et fringilla elementum, nibh nibh iaculis orci, eu elementum odio turpis et odio. Phasellus fermentum, justo id placerat egestas, arcu nunc molestie ante, non imperdiet ligula lectus sed erat. Quisque sed ligula. Sed ac nulla. Nullam massa. " + + "
" + + "Sed a purus. Mauris non nibh blandit neque cursus scelerisque. Quisque ultrices sem nec dolor. Donec non diam ut dui consequat venenatis. Nullam risus massa, egestas in, facilisis tristique, molestie sed, mi. Duis euismod turpis sit amet quam. Vestibulum ornare felis eget dolor. Phasellus ac urna vel sapien lacinia adipiscing. Donec egestas felis id mi. Sed erat. Vestibulum porta vulputate neque. Maecenas scelerisque, sem id sodales pretium, sem mauris rhoncus magna, at scelerisque tortor mauris nec dui. Nullam blandit rhoncus velit. Nam accumsan, enim id vestibulum feugiat, lorem nibh placerat urna, eget laoreet diam tortor at lorem. Suspendisse imperdiet consectetur dolor. "; private static final String[] iso3166 = new String[] { "AFGHANISTAN", "AF", "ÅLAND ISLANDS", "AX", "ALBANIA", "AL", "ALGERIA", "DZ", "AMERICAN SAMOA", "AS", "ANDORRA", "AD", "ANGOLA", "AO", diff --git a/src/com/itmill/toolkit/demo/sampler/FeatureSet.java b/src/com/itmill/toolkit/demo/sampler/FeatureSet.java index c9745a82b5..5e5c3747dd 100644 --- a/src/com/itmill/toolkit/demo/sampler/FeatureSet.java +++ b/src/com/itmill/toolkit/demo/sampler/FeatureSet.java @@ -235,12 +235,11 @@ public class FeatureSet extends Feature { new VerticalLayoutBasic(), // new HorizontalLayoutBasic(), // new GridLayoutBasic(), // - new LayoutAlignment(), // new ExpandingComponent(), // new SplitPanelBasic(), // - new WebLayout(), // new ApplicationLayout(), // + new WebLayout(), // new CustomLayouts(), // }); } diff --git a/src/com/itmill/toolkit/demo/sampler/features/layouts/75-ApplicationLayout.png b/src/com/itmill/toolkit/demo/sampler/features/layouts/75-ApplicationLayout.png index 3ccc44cef9..ee1d0a1c78 100644 Binary files a/src/com/itmill/toolkit/demo/sampler/features/layouts/75-ApplicationLayout.png and b/src/com/itmill/toolkit/demo/sampler/features/layouts/75-ApplicationLayout.png differ diff --git a/src/com/itmill/toolkit/demo/sampler/features/layouts/75-CustomLayouts.png b/src/com/itmill/toolkit/demo/sampler/features/layouts/75-CustomLayouts.png index 22b9062629..a37e342d9e 100644 Binary files a/src/com/itmill/toolkit/demo/sampler/features/layouts/75-CustomLayouts.png and b/src/com/itmill/toolkit/demo/sampler/features/layouts/75-CustomLayouts.png differ diff --git a/src/com/itmill/toolkit/demo/sampler/features/layouts/75-WebLayout.png b/src/com/itmill/toolkit/demo/sampler/features/layouts/75-WebLayout.png index f79fdb78a3..a9405c768c 100644 Binary files a/src/com/itmill/toolkit/demo/sampler/features/layouts/75-WebLayout.png and b/src/com/itmill/toolkit/demo/sampler/features/layouts/75-WebLayout.png differ diff --git a/src/com/itmill/toolkit/demo/sampler/features/layouts/ApplicationLayout.java b/src/com/itmill/toolkit/demo/sampler/features/layouts/ApplicationLayout.java index 1265dc76b5..1e350bc200 100644 --- a/src/com/itmill/toolkit/demo/sampler/features/layouts/ApplicationLayout.java +++ b/src/com/itmill/toolkit/demo/sampler/features/layouts/ApplicationLayout.java @@ -15,12 +15,14 @@ public class ApplicationLayout extends Feature { @Override public String getDescription() { - return "Application-style layout refers to a layout style where the" - + " Toolkit application is designed to look similar to a traditional" - + " desktop application. Basically this means that the application" - + " should usually fill the whole window with UI elements, and it" - + " should also resize gracefully and resonably." - + "
Please click the button for a demo in a new window."; + return "It can be helpful to distinguish between web-style and" + + " application-style layouting (although this is a" + + " simplification). Both styles are supported, and can be used" + + " simultaneously.
Application-style layouting uses relatively" + + " -sized components, growing dynamically with the window, and" + + " causing scrollbars to appear on well-defined areas within the" + + " window." + + "
Try resizing the window to see how the content reacts."; } @Override diff --git a/src/com/itmill/toolkit/demo/sampler/features/layouts/ApplicationLayoutExample.java b/src/com/itmill/toolkit/demo/sampler/features/layouts/ApplicationLayoutExample.java index 773437b9f3..8701e123da 100644 --- a/src/com/itmill/toolkit/demo/sampler/features/layouts/ApplicationLayoutExample.java +++ b/src/com/itmill/toolkit/demo/sampler/features/layouts/ApplicationLayoutExample.java @@ -1,137 +1,99 @@ package com.itmill.toolkit.demo.sampler.features.layouts; -import java.net.URL; +import java.util.Iterator; import com.itmill.toolkit.demo.sampler.ExampleUtil; -import com.itmill.toolkit.terminal.ExternalResource; -import com.itmill.toolkit.ui.AbstractSelect; import com.itmill.toolkit.ui.Button; import com.itmill.toolkit.ui.HorizontalLayout; import com.itmill.toolkit.ui.Label; -import com.itmill.toolkit.ui.TabSheet; +import com.itmill.toolkit.ui.Panel; +import com.itmill.toolkit.ui.Table; import com.itmill.toolkit.ui.Tree; import com.itmill.toolkit.ui.VerticalLayout; import com.itmill.toolkit.ui.Window; import com.itmill.toolkit.ui.Button.ClickEvent; +import com.itmill.toolkit.ui.Window.CloseEvent; public class ApplicationLayoutExample extends VerticalLayout { - private URL nativeWindowURL = null; - private Button b1; + Window win = new ApplicationLayoutWindow(); + Button open = new Button("Open sample in subwindow"); public ApplicationLayoutExample() { - setSpacing(true); + setMargin(true); + + // We'll open this example in a separate window, configure it + win.setWidth("70%"); + win.setHeight("70%"); + win.center(); + // Allow opening window again when closed + win.addListener(new Window.CloseListener() { + public void windowClose(CloseEvent e) { + open.setEnabled(true); + } + }); + + // 'open sample' button + addComponent(open); + open.addListener(new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + getWindow().addWindow(win); + open.setEnabled(false); + } + }); + addComponent(new Label( + ("Don't worry: the content of the window is not supposed to make sense..."))); - b1 = new Button("Open a new window with Application Layout", this, - "openButtonClick"); - addComponent(b1); - - } - - public void openButtonClick(ClickEvent event) { - if (nativeWindowURL == null) { - getApplication().addWindow(createWindow()); - } - getApplication().getMainWindow().open( - new ExternalResource(nativeWindowURL), "_blank"); } - /* - * Create new window which contains the layout obtained from - * createDemoLayout() - */ - private Window createWindow() { - // Create a new window and add it to the application - final Window w = new Window("Application Layout example"); - getApplication().addWindow(w); - // Set the window's layout to the one we get from createDemoLayout() - w.setLayout(createDemoLayout()); - // Set the layout's size full - w.getLayout().setSizeFull(); - - nativeWindowURL = w.getURL(); - return w; - } + class ApplicationLayoutWindow extends Window { + ApplicationLayoutWindow() { + // Our main layout is a horizontal layout + HorizontalLayout main = new HorizontalLayout(); + main.setSizeFull(); + setLayout(main); + + // Tree to the left + Panel treePanel = new Panel(); // for scrollbars + treePanel.setStyleName(Panel.STYLE_LIGHT); + treePanel.setHeight("100%"); + treePanel.setWidth(null); + treePanel.getLayout().setSizeUndefined(); + addComponent(treePanel); + + Tree tree = new Tree(); + tree.setContainerDataSource(ExampleUtil.getHardwareContainer()); + tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME); + for (Iterator it = tree.rootItemIds().iterator(); it.hasNext();) { + tree.expandItemsRecursively(it.next()); + } + treePanel.addComponent(tree); + + // vertically divide the right area + VerticalLayout left = new VerticalLayout(); + left.setSizeFull(); + addComponent(left); + main.setExpandRatio(left, 1.0f); // use all available space + + // table on top + Table tbl = new Table(); + tbl.setWidth("100%"); + tbl.setContainerDataSource(ExampleUtil.getISO3166Container()); + tbl.setSortDisabled(true); + tbl.setPageLength(7); + left.addComponent(tbl); + + // Label on bottom + Panel textPanel = new Panel(); // for scrollbars + textPanel.setStyleName(Panel.STYLE_LIGHT); + textPanel.setSizeFull(); + left.addComponent(textPanel); + left.setExpandRatio(textPanel, 1.0f); // use all available space + + Label text = new Label(ExampleUtil.lorem, Label.CONTENT_XHTML); + text.setWidth("500px"); // some limit is good for text + textPanel.addComponent(text); - /* - * Creates the actual Layout - */ - private HorizontalLayout createDemoLayout() { - // Create a new layout - HorizontalLayout demoLayout = new HorizontalLayout(); - // Enable spacing in the layout - demoLayout.setSpacing(true); - // Enable margins in the layout - demoLayout.setMargin(true); - - // Create an example tree component, set to full size - Tree t = new Tree("Hardware Inventory", ExampleUtil - .getHardwareContainer()); - t.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME); - t.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY); - t.setSizeFull(); - - // Expand the whole tree - int itemId = t.getContainerDataSource().size(); - for (int i = 0; i < itemId; i++) { - t.expandItemsRecursively(i); } - - // Create an example tabsheet component with some content - final TabSheet ts = new TabSheet(); - final Label l1 = new Label( - "This window shows an example of a so called" - + " Application-style layout. You probably notice that the layout" - + " is quite similar to other examples present in the Sampler." - + " These examples include e.g. SplitPanel and Expanding Components." - + " Please select one of the other tabs to find out more about" - + " application-style layouting!"); - l1.setSizeFull(); - final Label l2 = new Label( - "Typical design principles for an Application-style layout" - + " follow the design of traditional applications, e.g." - + " you should fill the whole window with your UI elements." - + " You should also make it dynamic, so it handles resizing events" - + " reasonably. In Toolkit, this is generally" - + " achieved by calling setSizeFull() for a Component." - + " In this example you may notice that sizes of all the components" - + " and layouts are set to full. Additionally, an expand ratio is set" - + " to achieve reasonable component sizes."); - l2.setSizeFull(); - final Label l3 = new Label( - "In some cases it is reasonable to set some of the" - + " sizes by hand, or at least set some limits to the sizes." - + " For example here an expand ratio of 1:4 has been set for the Tree" - + " Component and the layout containing the TabSheet component."); - l3.setSizeFull(); - - // Add tabs to TabSheet with appropriate captions - ts.addTab(l1); - ts.setTabCaption(l1, "Example of an Application-style layout"); - ts.addTab(l2); - ts.setTabCaption(l2, "Principles"); - ts.addTab(l3); - ts.setTabCaption(l3, "Exceptions"); - // Set the TabSheet to full size. - ts.setSizeFull(); - - // Create a basic label - Label commentArea = new Label("Comment area: no comments"); - - // Create an additional VerticalLayout for the TabSheet and the Label - VerticalLayout tabsAndComments = new VerticalLayout(); - tabsAndComments.setSizeFull(); - tabsAndComments.addComponent(ts); - tabsAndComments.addComponent(commentArea); - - // Add the components to the layout - demoLayout.addComponent(t); - demoLayout.addComponent(tabsAndComments); - - // Set expand ratios to the components - demoLayout.setExpandRatio(t, 1); - demoLayout.setExpandRatio(tabsAndComments, 3); - - return demoLayout; } } \ No newline at end of file diff --git a/src/com/itmill/toolkit/demo/sampler/features/layouts/CustomLayouts.java b/src/com/itmill/toolkit/demo/sampler/features/layouts/CustomLayouts.java index b9d9a2ad0a..30947ac798 100644 --- a/src/com/itmill/toolkit/demo/sampler/features/layouts/CustomLayouts.java +++ b/src/com/itmill/toolkit/demo/sampler/features/layouts/CustomLayouts.java @@ -14,15 +14,14 @@ public class CustomLayouts extends Feature { @Override public String getDescription() { - return "With the CustomLayout component, you can write your layout" - + " as a template in XHTML that provides locations of any contained" - + " components. The layout template must be included in a theme. This" - + " separation allows the layout to be designed separately from code," - + " for example using WYSIWYG web designer tools." - + "
The client-side engine of IT Mill Toolkit will replace contents" - + " of the location elements with the components. The components are" - + " bound to the location elements by the location identifier given to" - + " addComponent()."; + return "The CustomLayout allows you to make a layout in regular HTML," + + " using styles and embedding images to suit your needs." + + " You can even make the layout using a WYSIWYG editor.
" + + " Marking an area in the HTML as a named location" + + " will allow you to replace that area with a component later." + + "
HTML prototypes can often be quickly converted into a" + + " working application this way, providing a clear path from" + + " design to implementation."; } @Override @@ -38,7 +37,7 @@ public class CustomLayouts extends Feature { @Override public NamedExternalResource[] getRelatedResources() { return new NamedExternalResource[] { new NamedExternalResource( - "XHTML for the custom layout", getThemeBase() - + "layouts/examplecustomlayout_forviewing.html") }; + "Layout HTML (view source)", getThemeBase() + + "layouts/examplecustomlayout.html") }; } } diff --git a/src/com/itmill/toolkit/demo/sampler/features/layouts/CustomLayoutsExample.java b/src/com/itmill/toolkit/demo/sampler/features/layouts/CustomLayoutsExample.java index 89d06d28bc..e9ff2cd525 100644 --- a/src/com/itmill/toolkit/demo/sampler/features/layouts/CustomLayoutsExample.java +++ b/src/com/itmill/toolkit/demo/sampler/features/layouts/CustomLayoutsExample.java @@ -8,6 +8,8 @@ import com.itmill.toolkit.ui.VerticalLayout; public class CustomLayoutsExample extends VerticalLayout { public CustomLayoutsExample() { + setMargin(true); + // Create the custom layout and set it as a component in // the current layout CustomLayout custom = new CustomLayout("examplecustomlayout"); @@ -19,6 +21,7 @@ public class CustomLayoutsExample extends VerticalLayout { custom.addComponent(username, "username"); TextField password = new TextField(); + password.setSecret(true); custom.addComponent(password, "password"); Button ok = new Button("Login"); diff --git a/src/com/itmill/toolkit/demo/sampler/features/layouts/WebLayout.java b/src/com/itmill/toolkit/demo/sampler/features/layouts/WebLayout.java index fe9313d4e4..bc1241d2f9 100644 --- a/src/com/itmill/toolkit/demo/sampler/features/layouts/WebLayout.java +++ b/src/com/itmill/toolkit/demo/sampler/features/layouts/WebLayout.java @@ -15,11 +15,15 @@ public class WebLayout extends Feature { @Override public String getDescription() { - return "Web-style layout refers to a layout style where the" - + " content 'pushes' the layout to a reasonable size." - + " In some cases you should also define some limits for" - + " this 'pushing' so that the layout will stay reasonable." - + "
Please click the button for a demo in a new window."; + return "It can be helpful to distinguish between web-style and" + + " application-style layouting (although this is a" + + " simplification). Both styles are supported, and can be used" + + " simultaneously.
Web-style layouting allows the content" + + " to dictate the size of the components by \"pushing\" the" + + " size, causing scrollbars to appear for the whole window" + + " when needed. This can be achieved by not setting the size" + + " for components, or setting an absolute size (e.g 200px)." + + "
Try resizing the window to see how the content reacts."; } @Override diff --git a/src/com/itmill/toolkit/demo/sampler/features/layouts/WebLayoutExample.java b/src/com/itmill/toolkit/demo/sampler/features/layouts/WebLayoutExample.java index 47238d6f2f..5b1a5c3c26 100644 --- a/src/com/itmill/toolkit/demo/sampler/features/layouts/WebLayoutExample.java +++ b/src/com/itmill/toolkit/demo/sampler/features/layouts/WebLayoutExample.java @@ -1,129 +1,87 @@ package com.itmill.toolkit.demo.sampler.features.layouts; -import java.net.URL; +import java.util.Iterator; import com.itmill.toolkit.demo.sampler.ExampleUtil; -import com.itmill.toolkit.terminal.ExternalResource; -import com.itmill.toolkit.ui.AbstractSelect; import com.itmill.toolkit.ui.Button; import com.itmill.toolkit.ui.HorizontalLayout; import com.itmill.toolkit.ui.Label; -import com.itmill.toolkit.ui.TabSheet; +import com.itmill.toolkit.ui.Table; import com.itmill.toolkit.ui.Tree; import com.itmill.toolkit.ui.VerticalLayout; import com.itmill.toolkit.ui.Window; import com.itmill.toolkit.ui.Button.ClickEvent; +import com.itmill.toolkit.ui.Window.CloseEvent; public class WebLayoutExample extends VerticalLayout { - private URL nativeWindowURL = null; - private Button b1; + Window win = new WebLayoutWindow(); + Button open = new Button("Open sample in subwindow"); public WebLayoutExample() { - setSpacing(true); - - b1 = new Button("Open a new window with Web Layout", this, - "openButtonClick"); - addComponent(b1); + setMargin(true); + + // We'll open this example in a separate window, configure it + win.setWidth("70%"); + win.setHeight("70%"); + win.center(); + // Allow opening window again when closed + win.addListener(new Window.CloseListener() { + public void windowClose(CloseEvent e) { + open.setEnabled(true); + } + }); + + // 'open sample' button + addComponent(open); + open.addListener(new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + getWindow().addWindow(win); + open.setEnabled(false); + } + }); + + addComponent(new Label( + ("Don't worry: the content of the window is not supposed to make sense..."))); } - public void openButtonClick(ClickEvent event) { - if (nativeWindowURL == null) { - getApplication().addWindow(createWindow()); - } - getApplication().getMainWindow().open( - new ExternalResource(nativeWindowURL), "_blank"); - } + class WebLayoutWindow extends Window { + WebLayoutWindow() { + // Our main layout is a horiozontal layout + HorizontalLayout main = new HorizontalLayout(); + main.setMargin(true); + main.setSpacing(true); + setLayout(main); + + // Tree to the left + Tree tree = new Tree(); + tree.setContainerDataSource(ExampleUtil.getHardwareContainer()); + tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME); + for (Iterator it = tree.rootItemIds().iterator(); it.hasNext();) { + tree.expandItemsRecursively(it.next()); + } + addComponent(tree); + + // vertically divide the right area + VerticalLayout left = new VerticalLayout(); + left.setSpacing(true); + addComponent(left); + + // table on top + Table tbl = new Table(); + tbl.setWidth("500px"); + tbl.setContainerDataSource(ExampleUtil.getISO3166Container()); + tbl.setSortDisabled(true); + tbl.setPageLength(7); + left.addComponent(tbl); + + // Label on bottom + Label text = new Label(ExampleUtil.lorem, Label.CONTENT_XHTML); + text.setWidth("500px"); // some limit is good for text + left.addComponent(text); - /* - * Create new window which contains the layout obtained from - * createDemoLayout() - */ - private Window createWindow() { - // Create a new window and add it to the application - final Window w = new Window("Web Layout example"); - getApplication().addWindow(w); - // Set the window's layout to the one we get from createDemoLayout() - w.setLayout(createDemoLayout()); - // Set the layout's size undefined - w.getLayout().setSizeUndefined(); - - nativeWindowURL = w.getURL(); - return w; - } - - /* - * Creates the actual Layout - */ - private HorizontalLayout createDemoLayout() { - // Create a new layout - HorizontalLayout demoLayout = new HorizontalLayout(); - // Enable spacing and margins in the layout - demoLayout.setSpacing(true); - demoLayout.setMargin(true); - - // Create an example tree component, set to undefined size - Tree t = new Tree("Hardware Inventory", ExampleUtil - .getHardwareContainer()); - t.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME); - t.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY); - t.setSizeUndefined(); - - // Expand the whole tree - int itemId = t.getContainerDataSource().size(); - for (int i = 0; i < itemId; i++) { - t.expandItemsRecursively(i); } - - // Create an example tabsheet component with some content - final TabSheet ts = new TabSheet(); - final Label l1 = new Label( - "This window shows an example of a so called" - + " Web-style layout. You probably notice that the layout" - + " is quite different than the Application-style layout." - + " Please select one of the other tabs to find out more!"); - l1.setSizeUndefined(); - final Label l2 = new Label( - "Typical design principles for a Web-style layout" - + " state that the content should 'push' the layout" - + " to reach adequate proportions. In Toolkit, this is" - + " achieved by calling setSizeUndefined() for a Component." - + " In this example you may notice that the width of the Tree" - + " component is set by the content of it. Also, the width of" - + " the Tabsheet is set by the combined width of the tab captions."); - l2.setSizeUndefined(); - final Label l3 = new Label( - "In some cases it is reasonable to set some of the" - + " sizes by hand, or at least set some limits to the sizes." - + " For example here the height of the TabSheet component has" - + " been set to a fixed 200 pixels. Also, in some cases setting" - + " the base layout of the window to be of undefined size does not" - + " produce very good results."); - l3.setSizeUndefined(); - ts.addTab(l1); - ts.setTabCaption(l1, "Example of a Web-style layout"); - ts.addTab(l2); - ts.setTabCaption(l2, "Principles"); - ts.addTab(l3); - ts.setTabCaption(l3, "Exceptions"); - // Set the TabSheet width undefined. Also set a defined height. - ts.setSizeUndefined(); - ts.setHeight(200, UNITS_PIXELS); - - // Create a basic label - Label commentArea = new Label("Comment area: no comments"); - - // Create an additional VerticalLayout for the TabSheet and the Label - VerticalLayout tabsAndComments = new VerticalLayout(); - tabsAndComments.setSizeUndefined(); - tabsAndComments.addComponent(ts); - tabsAndComments.addComponent(commentArea); - - // Add the components to the layout - demoLayout.addComponent(t); - demoLayout.addComponent(tabsAndComments); - - return demoLayout; } + } \ No newline at end of file