From: Leif Åstrand Date: Thu, 30 Aug 2012 13:24:12 +0000 (+0300) Subject: Remove user handling in Application (#9402) X-Git-Tag: 7.0.0.beta1~209^2~2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cf9ab5aea84d2be1686c5f46edd9522cd0750baf;p=vaadin-framework.git Remove user handling in Application (#9402) --- diff --git a/server/src/com/vaadin/Application.java b/server/src/com/vaadin/Application.java index 5f7260e350..fb2691c6d3 100644 --- a/server/src/com/vaadin/Application.java +++ b/server/src/com/vaadin/Application.java @@ -26,7 +26,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; -import java.util.EventListener; import java.util.EventObject; import java.util.HashMap; import java.util.HashSet; @@ -429,11 +428,6 @@ public class Application implements Terminal.ErrorListener, Serializable { */ private DeploymentConfiguration configuration; - /** - * The current user or null if no user has logged in. - */ - private Object user; - /** * The application's URL. */ @@ -449,11 +443,6 @@ public class Application implements Terminal.ErrorListener, Serializable { */ private Locale locale; - /** - * List of listeners listening user changes. - */ - private LinkedList userChangeListeners = null; - /** * URL where the user is redirected to on application close, or null if * application is just closed without redirection. @@ -500,59 +489,6 @@ public class Application implements Terminal.ErrorListener, Serializable { private GlobalResourceHandler globalResourceHandler; - /** - * Gets the user of the application. - * - *

- * Vaadin doesn't define of use user object in any way - it only provides - * this getter and setter methods for convenience. The user is any object - * that has been stored to the application with {@link #setUser(Object)}. - *

- * - * @return the User of the application. - */ - public Object getUser() { - return user; - } - - /** - *

- * Sets the user of the application instance. An application instance may - * have a user associated to it. This can be set in login procedure or - * application initialization. - *

- *

- * A component performing the user login procedure can assign the user - * property of the application and make the user object available to other - * components of the application. - *

- *

- * Vaadin doesn't define of use user object in any way - it only provides - * getter and setter methods for convenience. The user reference stored to - * the application can be read with {@link #getUser()}. - *

- * - * @param user - * the new user. - */ - public void setUser(Object user) { - final Object prevUser = this.user; - if (user == prevUser || (user != null && user.equals(prevUser))) { - return; - } - - this.user = user; - if (userChangeListeners != null) { - final Object[] listeners = userChangeListeners.toArray(); - final UserChangeEvent event = new UserChangeEvent(this, user, - prevUser); - for (int i = 0; i < listeners.length; i++) { - ((UserChangeListener) listeners[i]) - .applicationUserChanged(event); - } - } - } - /** * Gets the URL of the application. * @@ -714,142 +650,6 @@ public class Application implements Terminal.ErrorListener, Serializable { this.locale = locale; } - /** - *

- * An event that characterizes a change in the current selection. - *

- * Application user change event sent when the setUser is called to change - * the current user of the application. - * - * @since 3.0 - */ - public class UserChangeEvent extends java.util.EventObject { - - /** - * New user of the application. - */ - private final Object newUser; - - /** - * Previous user of the application. - */ - private final Object prevUser; - - /** - * Constructor for user change event. - * - * @param source - * the application source. - * @param newUser - * the new User. - * @param prevUser - * the previous User. - */ - public UserChangeEvent(Application source, Object newUser, - Object prevUser) { - super(source); - this.newUser = newUser; - this.prevUser = prevUser; - } - - /** - * Gets the new user of the application. - * - * @return the new User. - */ - public Object getNewUser() { - return newUser; - } - - /** - * Gets the previous user of the application. - * - * @return the previous Vaadin user, if user has not changed ever on - * application it returns null - */ - public Object getPreviousUser() { - return prevUser; - } - - /** - * Gets the application where the user change occurred. - * - * @return the Application. - */ - public Application getApplication() { - return (Application) getSource(); - } - } - - /** - * The UserChangeListener interface for listening application - * user changes. - * - * @since 3.0 - */ - public interface UserChangeListener extends EventListener, Serializable { - - /** - * The applicationUserChanged method Invoked when the - * application user has changed. - * - * @param event - * the change event. - */ - public void applicationUserChanged(Application.UserChangeEvent event); - } - - /** - * Adds the user change listener. - * - * This allows one to get notification each time {@link #setUser(Object)} is - * called. - * - * @param listener - * the user change listener to add. - */ - public void addUserChangeListener(UserChangeListener listener) { - if (userChangeListeners == null) { - userChangeListeners = new LinkedList(); - } - userChangeListeners.add(listener); - } - - /** - * @deprecated Since 7.0, replaced by - * {@link #addUserChangeListener(UserChangeListener)} - **/ - @Deprecated - public void addListener(UserChangeListener listener) { - addUserChangeListener(listener); - } - - /** - * Removes the user change listener. - * - * @param listener - * the user change listener to remove. - */ - - public void removeUserChangeListener(UserChangeListener listener) { - if (userChangeListeners == null) { - return; - } - userChangeListeners.remove(listener); - if (userChangeListeners.isEmpty()) { - userChangeListeners = null; - } - } - - /** - * @deprecated Since 7.0, replaced by - * {@link #removeUserChangeListener(UserChangeListener)} - **/ - @Deprecated - public void removeListener(UserChangeListener listener) { - removeUserChangeListener(listener); - } - /** * Window detach event. * diff --git a/uitest/src/com/vaadin/tests/UpgradingSample.java b/uitest/src/com/vaadin/tests/UpgradingSample.java deleted file mode 100644 index 48e2222d7e..0000000000 --- a/uitest/src/com/vaadin/tests/UpgradingSample.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * 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; - -// -// Millstone imports were replaced -// -// import org.millstone.base.Application; -// import org.millstone.base.ui.*; -// import org.millstone.base.data.*; -// -import com.vaadin.Application; -import com.vaadin.data.Property; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.CustomComponent; -import com.vaadin.ui.GridLayout; -import com.vaadin.ui.Label; -import com.vaadin.ui.Panel; -import com.vaadin.ui.UI.LegacyWindow; -import com.vaadin.ui.TextField; -import com.vaadin.ui.Tree; -import com.vaadin.ui.VerticalLayout; - -/** - *

- * Example application demonstrating simple user login. This example is from - * MillStone 3.1.1 examples section. Upgrading from 3.1.1 to 4.0.0 was done by - * updating imports, also setTheme("corporate") call was added to application - * init method. - *

- * - * @since 3.1.1 - * @author Vaadin Ltd. - */ -public class UpgradingSample extends Application.LegacyApplication implements - Property.ValueChangeListener { - - /* Menu for navigating inside the application. */ - private final Tree menu = new Tree(); - - /* Contents of the website */ - private final String[][] pages = { - { "Welcome", "Welcome to our website..." }, - { "Products", "Public product information." }, - { "Contact", "Public contact information." }, - { "CRM", "CRM Database requiring login." }, - { "Intranet", "Internal information database." } }; - - /* Application layout */ - private final GridLayout layout = new GridLayout(2, 1); - - /* Initialize the application */ - @Override - public void init() { - - // Create the main window of the application - final LegacyWindow main = new LegacyWindow("Login example", layout); - setMainWindow(main); - - // Add menu and loginbox to the application - final VerticalLayout l = new VerticalLayout(); - layout.addComponent(l, 0, 0); - l.addComponent(menu); - l.addComponent(new LoginBox()); - - // Setup menu - menu.setStyleName("menu"); - menu.addListener(this); - menu.setImmediate(true); - addToMenu(new String[] { "Welcome", "Products", "Contact" }); - } - - // Overriding usetUser method is a simple way of updating application - // privileges when the user is changed - @Override - public void setUser(Object user) { - super.setUser(user); - if (user != null) { - addToMenu(new String[] { "CRM", "Intranet" }); - } - } - - public void addToMenu(String[] items) { - for (int i = 0; i < items.length; i++) { - menu.addItem(items[i]); - menu.setChildrenAllowed(items[i], false); - } - if (menu.getValue() == null) { - menu.setValue(items[0]); - } - } - - // Handle menu selection and update visible page - @Override - public void valueChange(Property.ValueChangeEvent event) { - layout.removeComponent(1, 0); - final String title = (String) menu.getValue(); - for (int i = 0; i < pages.length; i++) { - if (pages[i][0].equals(title)) { - final Panel p = new Panel(pages[i][0]); - p.addComponent(new Label(pages[i][1])); - p.setStyleName("strong"); - layout.addComponent(p, 1, 0); - } - } - } - - // Simple loginbox component for the application - public class LoginBox extends CustomComponent implements - Application.UserChangeListener { - - // The components this loginbox is composed of - private final TextField loginName = new TextField("Name"); - - private final Button loginButton = new Button("Enter", - new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - login(); - } - }); - - private final Panel loginPanel = new Panel("Login"); - - private final Panel statusPanel = new Panel(); - - private final Button logoutButton = new Button("Logout", - new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - close(); - } - }); - - private final Label statusLabel = new Label(); - - // Initialize login component - public LoginBox() { - - // Initialize the component - loginPanel.addComponent(loginName); - loginPanel.addComponent(loginButton); - loginPanel.setStyleName("strong"); - loginName.setColumns(8); - statusPanel.addComponent(statusLabel); - statusPanel.addComponent(logoutButton); - - // Set the status of the loginbox and show correct - // components - updateStatus(); - - // Listen application user change events - UpgradingSample.this.addListener(this); - } - - // Login into application - public void login() { - final String name = loginName.getValue(); - if (name != null && name.length() > 0) { - setUser(name); - } - loginName.setValue(""); - } - - // Update login status on application user change events - @Override - public void applicationUserChanged(Application.UserChangeEvent event) { - updateStatus(); - } - - // Update login status of the component by exposing correct - // components - private void updateStatus() { - statusLabel.setValue("User: " + getUser()); - if (getUser() != null) { - setCompositionRoot(statusPanel); - } else { - setCompositionRoot(loginPanel); - } - } - } -} diff --git a/uitest/src/com/vaadin/tests/application/ErrorInUnloadEvent.java b/uitest/src/com/vaadin/tests/application/ErrorInUnloadEvent.java index d7e9155ded..1278032f3c 100644 --- a/uitest/src/com/vaadin/tests/application/ErrorInUnloadEvent.java +++ b/uitest/src/com/vaadin/tests/application/ErrorInUnloadEvent.java @@ -10,17 +10,18 @@ import com.vaadin.ui.FormLayout; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; import com.vaadin.ui.PasswordField; -import com.vaadin.ui.UI.LegacyWindow; import com.vaadin.ui.TextField; +import com.vaadin.ui.UI.LegacyWindow; import com.vaadin.ui.VerticalLayout; public class ErrorInUnloadEvent extends AbstractTestCase { private LegacyWindow mainWindow; + private Object user = null; @Override public void init() { - if (getUser() == null) { + if (user == null) { showLoginWindow(); } else { showMainWindow(); @@ -55,7 +56,7 @@ public class ErrorInUnloadEvent extends AbstractTestCase { String username = userField.getValue(); String password = passwordField.getValue(); - setUser(username); + user = username; showMainWindow(); } }); @@ -84,7 +85,7 @@ public class ErrorInUnloadEvent extends AbstractTestCase { logout.addListener(new ClickListener() { @Override public void buttonClick(final ClickEvent event) { - setUser(null); + user = null; showLoginWindow(); }