Example usage for com.google.gwt.user.cellview.client CellTable CellTable

List of usage examples for com.google.gwt.user.cellview.client CellTable CellTable

Introduction

In this page you can find the example usage for com.google.gwt.user.cellview.client CellTable CellTable.

Prototype

public CellTable(ProvidesKey<T> keyProvider) 

Source Link

Document

Constructs a table with a default page size of 15, and the given ProvidesKey key provider .

Usage

From source file:tn.spindox.client.ui.CellTableFieldUpdaterExample.java

License:Apache License

public CellTable<Person> getTable() {

    // Create a CellTable with a key provider.
    final CellTable<Person> table = new CellTable<Person>(KEY_PROVIDER);
    table.setWidth("100%", false);

    // Add a date column to show the birthday.
    CheckboxCell checkBoxCell = new CheckboxCell();
    Column<Person, Boolean> SelectedColumn = new Column<Person, Boolean>(checkBoxCell) {
        @Override//from  w  ww.  j a v  a  2  s .  c o  m
        public Boolean getValue(Person object) {
            return object.selected;
        }
    };

    TextColumn<Person> firstNameColumn = new TextColumn<Person>() {
        @Override
        public String getValue(Person object) {
            // Return the name as the value of this column.
            return object.firstName;
        }
    };
    TextColumn<Person> lastNameColumn = new TextColumn<Person>() {
        @Override
        public String getValue(Person object) {
            // Return the name as the value of this column.
            return object.lastName;
        }
    };
    TextColumn<Person> birthDateColumn = new TextColumn<Person>() {
        @Override
        public String getValue(Person object) {
            // Return the name as the value of this column.
            return object.birthDate;
        }
    };
    TextColumn<Person> RegionColumn = new TextColumn<Person>() {
        @Override
        public String getValue(Person object) {
            // Return the name as the value of this column.
            return object.region;
        }
    };
    TextColumn<Person> emailColumn = new TextColumn<Person>() {
        @Override
        public String getValue(Person object) {
            // Return the name as the value of this column.
            return object.email;
        }
    };

    // Add a field updater to be notified when the user enters a new name.
    SelectedColumn.setFieldUpdater(new FieldUpdater<Person, Boolean>() {

        @Override
        public void update(int index, Person person, Boolean value) {

            if (value) {
                person.selected = true;
            } else {
                person.selected = false;
            }
        }

    });

    ButtonCell editCell = new ButtonCell();
    Column<Person, String> editColumn = new Column<Person, String>(editCell) {
        @Override
        public String getValue(Person object) {
            return "edit";
        }
    };

    editColumn.setFieldUpdater(new FieldUpdater<Person, String>() {

        @Override
        public void update(int index, Person object, String value) {

            System.out.println("-----------> clicked");

            callLoginDialogBox();
        }

        protected void callLoginDialogBox() {
            EditPersonBox editPersonBox = new EditPersonBox();

            editPersonBox.show();
        }

    });

    ButtonCell deleteCell = new ButtonCell();
    Column<Person, String> deleteColumn = new Column<Person, String>(deleteCell) {
        @Override
        public String getValue(Person object) {
            return "delete";
        }
    };

    deleteColumn.setFieldUpdater(new FieldUpdater<Person, String>() {

        @Override
        public void update(int index, Person person, String value) {

            System.out.println("-----------> delete clicked");

            Employee e = new Employee();
            e.setId_pers(person.id);
            e.setFirstName(person.firstName);
            e.setLastName(person.lastName);
            e.setBirthDate(person.birthDate);
            e.setRegion(person.region);
            e.setEmail(person.email);

            serverPerson.delete(e, new AsyncCallback<Void>() {

                @Override
                public void onFailure(Throwable caught) {
                    System.out.println("---> Error while deleting employee");
                }

                @Override
                public void onSuccess(Void result) {
                    System.out.println("---> deleting success !!! ");
                    table.redraw();
                }

            });

        }

    });

    table.addColumn(SelectedColumn, "");
    table.addColumn(firstNameColumn, "First Name");
    table.addColumn(lastNameColumn, "Last Name");
    table.addColumn(birthDateColumn, "Birth Date");
    table.addColumn(RegionColumn, "Region");
    table.addColumn(emailColumn, "Email");
    table.addColumn(editColumn, "");
    table.addColumn(deleteColumn, "");

    // Push the data into the widget.
    // table.setRowData(CONTACTS);

    final EmployeeServiceAsync server = GWT.create(EmployeeService.class);
    server.getListEmployees(new AsyncCallback<List<Employee>>() {

        @Override
        public void onFailure(Throwable caught) {
            System.out.println("---> Pb in retrieveing persons...");

        }

        @Override
        public void onSuccess(List<Employee> result) {

            List<Person> persons = new ArrayList<Person>();

            for (Employee e : result) {
                Person contact = new Person(false, e.getId_pers(), e.getLastName(), e.getFirstName(),
                        e.getBirthDate(), e.getRegion(), e.getEmail());
                persons.add(contact);
            }
            // Push the data into the widget.
            table.setRowData(persons);
        }

    });

    return table;
}