summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2012-10-18 12:47:06 +0300
committerLeif Åstrand <leif@vaadin.com>2012-10-18 12:47:06 +0300
commit8545d39358d57c1503023ed6c890a8ef4f8033fc (patch)
tree152c8b15551b96b9247d52c46eb1aec71f6863a5 /uitest
parentc6902a01e2f1bd7adbcd74a60e92bdcddbec84e8 (diff)
downloadvaadin-framework-8545d39358d57c1503023ed6c890a8ef4f8033fc.tar.gz
vaadin-framework-8545d39358d57c1503023ed6c890a8ef4f8033fc.zip
Update mini tutorial code
Change-Id: Ib8114efc793f6df412cefddfcf7627d4812b1228
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/com/vaadin/tests/minitutorials/v7a3/RefresherTestUI.java11
-rw-r--r--uitest/src/com/vaadin/tests/minitutorials/v7b5/HandlingLogout.java64
-rw-r--r--uitest/src/com/vaadin/tests/minitutorials/v7b5/SettingReadingSessionAttributesUI.java84
-rw-r--r--uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a3/RefresherState.java2
4 files changed, 159 insertions, 2 deletions
diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a3/RefresherTestUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7a3/RefresherTestUI.java
index 430da55fa1..c849cdce36 100644
--- a/uitest/src/com/vaadin/tests/minitutorials/v7a3/RefresherTestUI.java
+++ b/uitest/src/com/vaadin/tests/minitutorials/v7a3/RefresherTestUI.java
@@ -21,20 +21,29 @@ import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.tests.minitutorials.v7a3.Refresher.RefreshListener;
import com.vaadin.tests.widgetset.TestingWidgetSet;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
@Widgetset(TestingWidgetSet.NAME)
public class RefresherTestUI extends AbstractTestUI {
@Override
protected void setup(VaadinRequest request) {
- Refresher refresher = new Refresher();
+ final Refresher refresher = new Refresher();
refresher.extend(this);
+ refresher.setInterval(1000);
refresher.addListener(new RefreshListener() {
@Override
public void refresh(Refresher source) {
System.out.println("Got refresh");
}
});
+ addComponent(new Button("Remove refresher", new Button.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ removeExtension(refresher);
+ }
+ }));
}
@Override
diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7b5/HandlingLogout.java b/uitest/src/com/vaadin/tests/minitutorials/v7b5/HandlingLogout.java
new file mode 100644
index 0000000000..0356b4c5a8
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/minitutorials/v7b5/HandlingLogout.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2012 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.minitutorials.v7b5;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.server.VaadinServletService;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+
+public class HandlingLogout extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ addComponent(new Button("Logout", new Button.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ logout();
+ }
+ }));
+ }
+
+ private void logout() {
+ // Close the VaadinServiceSession
+ getUI().getSession().close();
+
+ // Invalidate underlying session instead if login info is stored there
+ // VaadinService.getCurrentRequest().getWrappedSession().invalidate();
+
+ // Redirect to avoid keeping the removed UI open in the browser
+ getUI().getPage().setLocation(getLogoutPageLocation());
+ }
+
+ protected String getLogoutPageLocation() {
+ return VaadinServletService.getCurrentRequest().getContextPath()
+ + "logout.html";
+ }
+
+ @Override
+ protected String getTestDescription() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return Integer.valueOf(9646);
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7b5/SettingReadingSessionAttributesUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7b5/SettingReadingSessionAttributesUI.java
new file mode 100644
index 0000000000..bc96152880
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/minitutorials/v7b5/SettingReadingSessionAttributesUI.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2012 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.minitutorials.v7b5;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.server.VaadinService;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.UI;
+import com.vaadin.ui.VerticalLayout;
+
+//Remove comment to preserve UI value when reloading
+//@PreserveOnRefresh
+public class SettingReadingSessionAttributesUI extends UI {
+
+ private String value;
+
+ private VerticalLayout statusHolder = new VerticalLayout();
+ private TextField textField = new TextField();
+
+ @Override
+ protected void init(VaadinRequest request) {
+ addComponent(statusHolder);
+ addComponent(textField);
+ addComponent(new Button("Set new values", new Button.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ String value = textField.getValue();
+
+ saveValue(SettingReadingSessionAttributesUI.this, value);
+ }
+ }));
+ addComponent(new Button("Reload page", new Button.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ getPage().setLocation(getPage().getLocation());
+ }
+ }));
+
+ showValue(this);
+ }
+
+ private static void saveValue(SettingReadingSessionAttributesUI ui,
+ String value) {
+ // Save to UI instance
+ ui.value = value;
+ // Save to VaadinServiceSession
+ ui.getSession().setAttribute("myValue", value);
+ // Save to HttpSession
+ VaadinService.getCurrentRequest().getWrappedSession()
+ .setAttribute("myValue", value);
+
+ // Show new values
+ showValue(ui);
+ }
+
+ private static void showValue(SettingReadingSessionAttributesUI ui) {
+ ui.statusHolder.removeAllComponents();
+ ui.statusHolder.addComponent(new Label("Value in UI: " + ui.value));
+ ui.statusHolder.addComponent(new Label(
+ "Value in VaadinServiceSession: "
+ + ui.getSession().getAttribute("myValue")));
+ ui.statusHolder.addComponent(new Label("Value in HttpSession: "
+ + VaadinService.getCurrentRequest().getWrappedSession()
+ .getAttribute("myValue")));
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a3/RefresherState.java b/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a3/RefresherState.java
index 769f6330a9..13e8d8bc1d 100644
--- a/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a3/RefresherState.java
+++ b/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a3/RefresherState.java
@@ -3,5 +3,5 @@ package com.vaadin.tests.widgetset.client.minitutorials.v7a3;
import com.vaadin.shared.communication.SharedState;
public class RefresherState extends SharedState {
- public int interval = 1000;
+ public int interval;
} \ No newline at end of file