com.jcommerce.gwt.client.panels.NewUsers.java Source code

Java tutorial

Introduction

Here is the source code for com.jcommerce.gwt.client.panels.NewUsers.java

Source

/*
 * Copyright 2008 Google Inc.
 * 
 * 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.jcommerce.gwt.client.panels;

import java.util.Map;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.jcommerce.gwt.client.ContentWidget;
import com.jcommerce.gwt.client.ModelNames;
import com.jcommerce.gwt.client.model.BeanObject;
import com.jcommerce.gwt.client.model.IUser;
import com.jcommerce.gwt.client.panels.leontest.PageState;
import com.jcommerce.gwt.client.service.CreateService;
import com.jcommerce.gwt.client.widgets.ColumnPanel;
import com.jcommerce.gwt.client.widgets.DateWidget;
import com.jcommerce.gwt.client.widgets.ValueSelector;

/**
 * Example file.
 */
public class NewUsers extends ContentWidget {

    ColumnPanel contentPanel = new ColumnPanel();

    Button btnOK = new Button();
    Button btnCancel = new Button();

    // leon to integrate with history-based page navigation mechnism. 
    // State should contain all info needed to render this page.
    // This is a minimum skeleton, more fields may be added, see leontest.Attribute
    public static class State extends PageState {
        public String getPageClassName() {
            return NewUsers.class.getName();
        }

        public String getMenuDisplayName() {
            return "";
        }
    }

    private State curState = new State();

    public State getCurState() {
        return curState;
    }

    public void setCurState(State curState) {
        this.curState = curState;
    }
    // end of block

    public String getDescription() {
        return "cwBasicTextDescription";
    }

    public String getName() {
        return "";
    }

    /**
     * Initialize this example.
     */
    public NewUsers() {
        add(contentPanel);
        contentPanel.createPanel(IUser.NAME, "??:", new TextBox());
        //        createPanel(SN, "SN:", new TextBox());

        contentPanel.createPanel(IUser.EMAIL, "?:", new TextBox());
        contentPanel.createPanel(IUser.PASSWORD, "?:", new PasswordTextBox());
        contentPanel.createPanel(null, "?:", new PasswordTextBox());
        ValueSelector selector = new ValueSelector();
        selector.setBean(ModelNames.USERRANK);
        selector.setCaption("Select RANK");
        selector.setMessage("Select RANK");
        contentPanel.createPanel(IUser.RANK, ":", selector);
        ListBox listsex = new ListBox();
        listsex.addItem("?", "0");
        listsex.addItem("", "1");
        listsex.addItem("", "2");
        contentPanel.createPanel(IUser.SEX, ":", listsex);
        contentPanel.createPanel(IUser.BIRTHDAY, ":", new DateWidget());
        contentPanel.createPanel(IUser.CREDITLINE, "?:", new TextBox());
        contentPanel.createPanel(IUser.MSN, "MSN:", new TextBox());
        contentPanel.createPanel(IUser.QQ, "QQ:", new TextBox());
        contentPanel.createPanel(IUser.OFFICEPHONE, "?:", new TextBox());
        contentPanel.createPanel(IUser.HOMEPHONE, "?:", new TextBox());
        contentPanel.createPanel(IUser.MOBILEPHONE, ":", new TextBox());

        HorizontalPanel panel = new HorizontalPanel();
        panel.setSpacing(10);
        btnOK.setText("");
        btnCancel.setText("?");
        panel.add(btnOK);
        panel.add(btnCancel);
        contentPanel.createPanel(null, null, panel);

        btnOK.addClickListener(new ClickListener() {
            public void onClick(Widget sender) {
                Map<String, Object> args = contentPanel.getValues();
                new CreateService().createBean(new BeanObject(ModelNames.USER, args), null);
            }
        });

        btnCancel.addClickListener(new ClickListener() {
            public void onClick(Widget sender) {
                contentPanel.clearValues();
            }
        });
    }
}