summaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/CustomLayoutDemo.java
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-08-30 17:24:36 +0300
committerArtur Signell <artur@vaadin.com>2012-08-30 17:24:36 +0300
commit7b25b3886ea95bc6495506fbe9472e45fcbde684 (patch)
tree0b93cb65dab437feb46720659a63b8f1ef48f7f4 /uitest/src/com/vaadin/tests/CustomLayoutDemo.java
parent8941056349e302e687e40e94c13709e75f256d73 (diff)
downloadvaadin-framework-7b25b3886ea95bc6495506fbe9472e45fcbde684.tar.gz
vaadin-framework-7b25b3886ea95bc6495506fbe9472e45fcbde684.zip
Renamed tests -> uitest and tests/testbench -> uitest/src (#9299)
Diffstat (limited to 'uitest/src/com/vaadin/tests/CustomLayoutDemo.java')
-rw-r--r--uitest/src/com/vaadin/tests/CustomLayoutDemo.java162
1 files changed, 162 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/CustomLayoutDemo.java b/uitest/src/com/vaadin/tests/CustomLayoutDemo.java
new file mode 100644
index 0000000000..833340f678
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/CustomLayoutDemo.java
@@ -0,0 +1,162 @@
+/*
+ * Copyright 2011 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.tests;
+
+import com.vaadin.shared.ui.label.ContentMode;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Component.Event;
+import com.vaadin.ui.Component.Listener;
+import com.vaadin.ui.CustomLayout;
+import com.vaadin.ui.Field;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.PasswordField;
+import com.vaadin.ui.UI.LegacyWindow;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.Tree;
+
+/**
+ * This example demonstrates custom layout. All components created here are
+ * placed using custom.html file. Custom layouts may be created with any web
+ * designer tool such as Dreamweaver. To place Vaadin components into html page,
+ * use divs with location tag as an identifier for Vaadin components, see html
+ * page (themes/example/layout/custom.html) and source code below. Body panel
+ * contents are changed when menu items are clicked. Contents are HTML pages
+ * located at themes/example/layout directory.
+ *
+ * @author Vaadin Ltd.
+ * @since 4.0.0
+ *
+ */
+public class CustomLayoutDemo extends com.vaadin.Application.LegacyApplication
+ implements Listener {
+
+ private CustomLayout mainLayout = null;
+
+ private final Panel bodyPanel = new Panel();
+
+ private final TextField username = new TextField("Username");
+
+ private final PasswordField loginPwd = new PasswordField("Password");
+
+ private final Button loginButton = new Button("Login",
+ new Button.ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ loginClicked();
+ }
+ });
+
+ private final Tree menu = new Tree();
+
+ /**
+ * Initialize Application. Demo components are added to main window.
+ */
+ @Override
+ public void init() {
+ final LegacyWindow mainWindow = new LegacyWindow("CustomLayout demo");
+ setMainWindow(mainWindow);
+
+ // set the application to use example -theme
+ setTheme("tests-components");
+
+ // Create custom layout, themes/example/layout/mainLayout.html
+ mainLayout = new CustomLayout("mainLayout");
+ // wrap custom layout inside a panel
+ final Panel customLayoutPanel = new Panel(
+ "Panel containing custom layout (mainLayout.html)");
+ customLayoutPanel.addComponent(mainLayout);
+
+ // Login components
+ mainLayout.addComponent(username, "loginUser");
+ mainLayout.addComponent(loginPwd, "loginPassword");
+ mainLayout.addComponent(loginButton, "loginButton");
+
+ // Menu component, when clicked bodyPanel is updated
+ menu.addItem("Welcome");
+ menu.addItem("Products");
+ menu.addItem("Support");
+ menu.addItem("News");
+ menu.addItem("Developers");
+ menu.addItem("Contact");
+ // "this" handles all menu events, e.g. node clicked event
+ menu.addListener(this);
+ // Value changes are immediate
+ menu.setImmediate(true);
+ menu.setNullSelectionAllowed(false);
+ mainLayout.addComponent(menu, "menu");
+
+ // Body component
+ mainLayout.addComponent(bodyPanel, "body");
+
+ // Initial body are comes from Welcome.html
+ setBody("Welcome");
+
+ // Add heading label and custom layout panel to main window
+ mainWindow.addComponent(new Label("<h3>Custom layout demo</h3>",
+ ContentMode.XHTML));
+ mainWindow.addComponent(customLayoutPanel);
+ }
+
+ /**
+ * Login button clicked. Hide login components and replace username
+ * component with "Welcome user Username" message.
+ *
+ */
+ public void loginClicked() {
+ username.setVisible(false);
+ loginPwd.setVisible(false);
+ if (username.getValue().toString().length() < 1) {
+ username.setValue("Anonymous");
+ }
+ mainLayout.replaceComponent(loginButton, new Label("Welcome user <em>"
+ + username.getValue() + "</em>", ContentMode.XHTML));
+ }
+
+ /**
+ * Set body panel caption, remove all existing components and add given
+ * custom layout in it.
+ *
+ */
+ public void setBody(String customLayout) {
+ bodyPanel.setCaption(customLayout + ".html");
+ bodyPanel.removeAllComponents();
+ bodyPanel.addComponent(new CustomLayout(customLayout));
+ }
+
+ /**
+ * Handle all menu events. Updates body panel contents if menu item is
+ * clicked.
+ */
+ @Override
+ public void componentEvent(Event event) {
+ // Check if event occured at fsTree component
+ if (event.getSource() == menu) {
+ // Check if event is about changing value
+ if (event.getClass() == Field.ValueChangeEvent.class) {
+ // Update body area with selected item
+ setBody(menu.getValue().toString());
+ }
+ // here we could check for other type of events for tree
+ // component
+ }
+ // here we could check for other component's events
+ }
+
+}