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;
*/
private DeploymentConfiguration configuration;
- /**
- * The current user or <code>null</code> if no user has logged in.
- */
- private Object user;
-
/**
* The application's URL.
*/
*/
private Locale locale;
- /**
- * List of listeners listening user changes.
- */
- private LinkedList<UserChangeListener> userChangeListeners = null;
-
/**
* URL where the user is redirected to on application close, or null if
* application is just closed without redirection.
private GlobalResourceHandler globalResourceHandler;
- /**
- * Gets the user of the application.
- *
- * <p>
- * 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)}.
- * </p>
- *
- * @return the User of the application.
- */
- public Object getUser() {
- return user;
- }
-
- /**
- * <p>
- * 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.
- * </p>
- * <p>
- * 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.
- * </p>
- * <p>
- * 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()}.
- * </p>
- *
- * @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.
*
this.locale = locale;
}
- /**
- * <p>
- * An event that characterizes a change in the current selection.
- * </p>
- * 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 <code>null</code>
- */
- public Object getPreviousUser() {
- return prevUser;
- }
-
- /**
- * Gets the application where the user change occurred.
- *
- * @return the Application.
- */
- public Application getApplication() {
- return (Application) getSource();
- }
- }
-
- /**
- * The <code>UserChangeListener</code> interface for listening application
- * user changes.
- *
- * @since 3.0
- */
- public interface UserChangeListener extends EventListener, Serializable {
-
- /**
- * The <code>applicationUserChanged</code> 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<UserChangeListener>();
- }
- 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.
*
+++ /dev/null
-/*
- * 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;
-
-/**
- * <p>
- * 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.
- * </p>
- *
- * @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);
- }
- }
- }
-}