edu.nrao.dss.client.widget.explorers.UserExplorer.java Source code

Java tutorial

Introduction

Here is the source code for edu.nrao.dss.client.widget.explorers.UserExplorer.java

Source

// Copyright (C) 2011 Associated Universities, Inc. Washington DC, USA.
// 
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// 
// Correspondence concerning GBT software should be addressed as follows:
//       GBT Operations
//       National Radio Astronomy Observatory
//       P. O. Box 2
//       Green Bank, WV 24944-0002 USA

package edu.nrao.dss.client.widget.explorers;

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.BasePagingLoadResult;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.KeyListener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.button.SplitButton;
import com.extjs.gxt.ui.client.widget.form.CheckBox;
import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;
import com.extjs.gxt.ui.client.widget.form.SimpleComboValue;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.toolbar.FillToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar;
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.i18n.client.NumberFormat;

import edu.nrao.dss.client.data.UserType;
import edu.nrao.dss.client.util.DynamicHttpProxy;
import edu.nrao.dss.client.widget.form.UserForm;

public class UserExplorer extends Explorer {

    // Observers
    private UserForm addInvest;

    public UserExplorer() {
        super("/scheduler/users", "", new UserType());
        initFilters();
        initLayout(initColumnModel(), true);
        //initUserToolBar();

    }

    private void initFilters() {
        filterAction = new SplitButton("Filter");
        filterAction.setMenu(initFilterMenu());
        filterAction.addSelectionListener(new SelectionListener<ButtonEvent>() {
            @Override
            public void componentSelected(ButtonEvent be) {
                String filtersURL = "?";

                SimpleComboValue<String> value;
                String[] filterNames = new String[] {};
                for (int i = 0; i < advancedFilters.size(); i++) {
                    value = advancedFilters.get(i).getValue();
                    if (value != null) {
                        filtersURL += (filtersURL.equals("?") ? filterNames[i] + "=" : "&" + filterNames[i] + "=")
                                + value.getValue();
                    }
                }

                String filterText = filter.getTextField().getValue();
                if (filterText != null) {
                    filterText = filtersURL.equals("?") ? "filterText=" + filterText : "&filterText=" + filterText;
                } else {
                    filterText = "";
                }
                String url = getRootURL() + filtersURL + filterText;
                RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
                DynamicHttpProxy<BasePagingLoadResult<BaseModelData>> proxy = getProxy();
                proxy.setBuilder(builder);
                loadData();

            }
        });
    }

    private ColumnModel initColumnModel() {
        List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

        ColumnConfig column = new ColumnConfig("username", "Username", 100);
        CellEditor editor = new CellEditor(new TextField<String>());
        column.setEditor(editor);
        configs.add(column);

        column = new ColumnConfig("first_name", "First Name", 100);
        column.setEditor(new CellEditor(new TextField<String>()));
        configs.add(column);

        column = new ColumnConfig("last_name", "Last Name", 100);
        column.setEditor(new CellEditor(new TextField<String>()));
        configs.add(column);

        column = new ColumnConfig("pst_id", "PST ID", 100);
        column.setEditor(new CellEditor(new TextField<String>()));
        column.setNumberFormat(NumberFormat.getFormat("#"));
        configs.add(column);

        column = new ColumnConfig("original_id", "Original ID", 100);
        column.setEditor(new CellEditor(new TextField<String>()));
        column.setNumberFormat(NumberFormat.getFormat("#"));
        configs.add(column);

        CheckColumnConfig checkColumn = new CheckColumnConfig("sanctioned", "Sanctioned?", 70);
        checkColumn.setEditor(new CellEditor(new CheckBox()));
        configs.add(checkColumn);
        checkBoxes.add(checkColumn);

        column = new ColumnConfig("role", "Role", 80);
        column.setEditor(initCombo(new String[] { "Administrator", "Observer", "Operator" }));
        configs.add(column);

        checkColumn = new CheckColumnConfig("staff", "Staff?", 65);
        checkColumn.setEditor(new CellEditor(new CheckBox()));
        configs.add(checkColumn);
        checkBoxes.add(checkColumn);

        column = new ColumnConfig("projects", "Projects", 800);
        editor = new CellEditor(new TextField<String>());
        editor.disable();
        column.setEditor(editor);
        configs.add(column);

        return new ColumnModel(configs);
    }

    public void registerObservers(UserForm addInvest) {
        this.addInvest = addInvest;
    }

    public void updateObservers() {
        addInvest.updateUserOptions();
    }

}