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:cimav.client.view.catalogos.tabulador.NivelesUi.java

private void buildGrid() {
    // super.onLoad(); //To change body of generated methods, choose Tools | Templates.

    /*//  w ww.j  a v a2  s . c om
     * Set a key provider that provides a unique key for each contact. If key is
     * used to identify contacts when fields (such as the name and address)
     * change.
     */
    dataGrid = new CellTable<>(NivelesProvider.get().getDataProvider());
    //cellTable.setWidth("100%");
    //cellTable.setHeight("100%");

    /*
     * Do not refresh the headers every time the data is updated. The footer
     * depends on the current data, so we do not disable auto refresh on the
     * footer.
     */
    dataGrid.setAutoHeaderRefreshDisabled(true);

    // Set the message to display when the table is empty.
    dataGrid.setEmptyTableWidget(new Label("No hay Niveles"));

    // Attach a column sort handler to the ListDataProvider to sort the list.
    ColumnSortEvent.ListHandler<Tabulador> sortHandler = new ColumnSortEvent.ListHandler<>(
            NivelesProvider.get().getDataProvider().getList());
    dataGrid.addColumnSortHandler(sortHandler);

    // Create a Pager to control the table.
    SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
    pager = new SimplePager(SimplePager.TextLocation.CENTER, pagerResources, false, 0, true);
    pager.setDisplay(dataGrid);

    dataGrid.setPageSize(50);

    // Add a selection model so we can select cells.
    final SelectionModel<Tabulador> selectionModel = new SingleSelectionModel<>(
            NivelesProvider.get().getDataProvider());
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        @Override
        public void onSelectionChange(SelectionChangeEvent event) {
            //System.out.println("123> " + event.getSource() + " - " + event.getAssociatedType());
            if (event.getSource() instanceof SingleSelectionModel) {

                SingleSelectionModel selecter = (SingleSelectionModel) event.getSource();
                Tabulador sel = (Tabulador) selecter.getSelectedObject();

                GWT.log("Sel>> " + sel);
            }
        }
    });
    dataGrid.setSelectionModel(selectionModel);

    dataGrid.addDomHandler(new DoubleClickHandler() {
        @SuppressWarnings("unchecked")
        @Override
        public void onDoubleClick(DoubleClickEvent event) {
            //                DataGrid<Departamento> grid = (DataGrid<Departamento>) event.getSource();
            //                int row = grid.getKeyboardSelectedRow();
            //                Departamento item = grid.getVisibleItem(row);
        }
    }, DoubleClickEvent.getType());

    initTableColumns(sortHandler);

    // Add the CellList to the adapter in the database.
    NivelesProvider.get().getDataProvider().addDataDisplay(dataGrid);

}

From source file:com.Administration.client.Administration.java

License:Apache License

/**
 * ?   UI/*from  www  . j a  v a 2s  .c om*/
 */
public void onModuleLoad() {

    label = new HTML(); //   ?  ?  
    label.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

    loginLabel = new HTML(); //   ?  ?    
    loginLabel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

    dialog = new PasswordDialog(); //   
    list = new LinkedList<>(); //  ? ? 

    ProvidesKey<LinkData> KEY_PROVIDER = new ProvidesKey<LinkData>() { //    -   ??   
        @Override
        public Object getKey(LinkData item) {
            return item == null ? null : item.getId();
        }
    };
    cellTable = new CellTable<>(KEY_PROVIDER); //  ? 

    dataProvider = new ListDataProvider<>(); //    
    dataProvider.addDataDisplay(cellTable); // ?,   ????   ? 

    sortHandler = new ListHandler<>(list); //  ?
    cellTable.addColumnSortHandler(sortHandler); //  ?   

    SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
    pager = new SimplePager(SimplePager.TextLocation.CENTER, pagerResources, false, 0, true); //  pager -  ?
    pager.setDisplay(cellTable); // ?,  pager ?  ? 

    initTable(); //   ? 
    cellTable.setWidth("100%");
    cellTable.setHeight("80%");
    cellTable.setAutoHeaderRefreshDisabled(true);
    cellTable.setAutoFooterRefreshDisabled(true);

    //  ?  
    VerticalPanel VP = new VerticalPanel();
    VP.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    VP.add(cellTable);
    VP.add(pager);

    logoutButton = new Button("Logout");

    //  ? 
    HorizontalPanel loginHP = new HorizontalPanel();
    loginHP.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    loginHP.setSpacing(5);
    loginHP.add(loginLabel);
    loginHP.add(logoutButton);

    logoutButton.addClickHandler(new ClickHandler() { //  
        @Override
        public void onClick(ClickEvent event) { //  

            Cookies.removeCookie(cookieName); // ?   

            //  ?  ???
            loginLabel.setHTML("");
            loginLabel.setVisible(false);
            label.setHTML("");
            cellTable.setVisible(false);
            pager.setVisible(false);
            logoutButton.setVisible(false);

            dataProvider.getList().clear(); // ? 

            dialog.show(); //   
            dialog.center();

        }
    });
    logoutButton.setVisible(false);

    //  
    RootPanel.get("Login").add(loginHP);
    RootPanel.get("Data").add(VP);
    RootPanel.get("Data").add(label);

    //    ? 
    cellTable.setVisible(false);
    pager.setVisible(false);

    dialog.Login();
}

From source file:com.google.gwt.examples.cellview.CellTableFieldUpdaterExample.java

License:Apache License

@Override
public void onModuleLoad() {
    // Create a CellTable with a key provider.
    final CellTable<Contact> table = new CellTable<Contact>(KEY_PROVIDER);

    // Add a text input column to edit the name.
    final TextInputCell nameCell = new TextInputCell();
    Column<Contact, String> nameColumn = new Column<Contact, String>(nameCell) {
        @Override/*  ww w .j  a  v a 2s .com*/
        public String getValue(Contact object) {
            // Return the name as the value of this column.
            return object.name;
        }
    };
    table.addColumn(nameColumn, "Name");

    // Add a field updater to be notified when the user enters a new name.
    nameColumn.setFieldUpdater(new FieldUpdater<Contact, String>() {
        @Override
        public void update(int index, Contact object, String value) {
            // Inform the user of the change.
            Window.alert("You changed the name of " + object.name + " to " + value);

            // Push the changes into the Contact. At this point, you could send an
            // asynchronous request to the server to update the database.
            object.name = value;

            // Redraw the table with the new data.
            table.redraw();
        }
    });

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

    // Add it to the root panel.
    RootPanel.get().add(table);
}

From source file:com.google.gwt.examples.cellview.CellTableFieldUpdaterExampleComplex.java

License:Apache License

@Override
public void onModuleLoad() {
    // Create a CellTable with a key provider.
    final CellTable<Contact> table = new CellTable<Contact>(KEY_PROVIDER);
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);

    // Add a text input column to edit the name.
    final TextInputCell nameCell = new TextInputCell();
    Column<Contact, String> nameColumn = new Column<Contact, String>(nameCell) {
        @Override/*from   ww  w.  j a  va 2 s.  c  o  m*/
        public String getValue(Contact object) {
            return object.name;
        }
    };
    table.addColumn(nameColumn, "Name");

    // Add a field updater to be notified when the user enters a new name.
    nameColumn.setFieldUpdater(new FieldUpdater<Contact, String>() {
        @Override
        public void update(int index, Contact object, String value) {
            // Validate the data.
            if (value.length() < 3) {
                Window.alert("Names must be at least three characters long.");

                /*
                 * Clear the view data. The view data contains the pending change and
                 * allows the table to render with the pending value until the data is
                 * committed. If the data is committed into the object, the view data
                 * is automatically cleared out. If the data is not committed because
                 * it is invalid, you must delete.
                 */
                nameCell.clearViewData(KEY_PROVIDER.getKey(object));

                // Redraw the table.
                table.redraw();
                return;
            }

            // Inform the user of the change.
            Window.alert("You changed the name of " + object.name + " to " + value);

            // Push the changes into the Contact. At this point, you could send an
            // asynchronous request to the server to update the database.
            object.name = value;

            // Redraw the table with the new data.
            table.redraw();
        }
    });

    // Add a date column to show the birthday.
    Column<Contact, Date> dateColumn = new Column<Contact, Date>(new DatePickerCell()) {
        @Override
        public Date getValue(Contact object) {
            return object.birthday;
        }
    };
    table.addColumn(dateColumn, "Birthday");

    // Add a field updater to be notified when the user enters a new birthday.
    dateColumn.setFieldUpdater(new FieldUpdater<Contact, Date>() {
        @Override
        public void update(int index, Contact object, Date value) {
            Window.alert("You changed the birthday of " + object.name + " to "
                    + DateTimeFormat.getFormat(PredefinedFormat.DATE_LONG).format(value));

            // Push the changes into the Contact.
            object.birthday = value;

            // Redraw the table with the new data.
            table.redraw();
        }
    });
    // Add a text column to show the address.
    TextColumn<Contact> addressColumn = new TextColumn<Contact>() {
        @Override
        public String getValue(Contact object) {
            return object.address;
        }
    };
    table.addColumn(addressColumn, "Address");

    // Set the total row count. This isn't strictly necessary, but it affects
    // paging calculations, so its good habit to keep the row count up to date.
    table.setRowCount(CONTACTS.size(), true);

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

    // Add it to the root panel.
    RootPanel.get().add(table);
}

From source file:com.google.gwt.sample.showcase.client.content.cell.CwCellTable.java

License:Apache License

/**
 * Initialize this example./*from   ww  w .  j ava  2 s . c o  m*/
 */
@ShowcaseSource
@Override
public Widget onInitialize() {
    // Create a CellTable.

    // Set a key provider that provides a unique key for each contact. If key is
    // used to identify contacts when fields (such as the name and address)
    // change.
    cellTable = new CellTable<ContactInfo>(ContactDatabase.ContactInfo.KEY_PROVIDER);
    cellTable.setWidth("100%", true);

    // Attach a column sort handler to the ListDataProvider to sort the list.
    ListHandler<ContactInfo> sortHandler = new ListHandler<ContactInfo>(
            ContactDatabase.get().getDataProvider().getList());
    cellTable.addColumnSortHandler(sortHandler);

    // Create a Pager to control the table.
    SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
    pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0, true);
    pager.setDisplay(cellTable);

    // Add a selection model so we can select cells.
    final SelectionModel<ContactInfo> selectionModel = new MultiSelectionModel<ContactInfo>(
            ContactDatabase.ContactInfo.KEY_PROVIDER);
    cellTable.setSelectionModel(selectionModel,
            DefaultSelectionEventManager.<ContactInfo>createCheckboxManager());

    // Initialize the columns.
    initTableColumns(selectionModel, sortHandler);

    // Add the CellList to the adapter in the database.
    ContactDatabase.get().addDataDisplay(cellTable);

    // Create the UiBinder.
    Binder uiBinder = GWT.create(Binder.class);
    Widget widget = uiBinder.createAndBindUi(this);

    return widget;
}

From source file:com.gwt2go.dev.client.ui.CellTableViewImpl.java

License:Apache License

public CellTableViewImpl(/* String firstName */) {
    // Create a CellTable.

    // Set a key provider that provides a unique key for each contact. If
    // key is//from  w  w w  .j  a  v  a 2  s  .  c  o m
    // used to identify contacts when fields (such as the name and address)
    // change.
    cellTable = new CellTable<ContactDatabase.ContactInfo>(ContactDatabase.ContactInfo.KEY_PROVIDER);

    // Create a Pager to control the table.
    SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
    pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0, true);
    pager.setDisplay(cellTable);

    // Add a selection model so we can select cells.
    final SingleSelectionModel<ContactInfo> selectionModel = new SingleSelectionModel<ContactInfo>(
            ContactInfo.KEY_PROVIDER);
    cellTable.setSelectionModel(selectionModel);

    // Initialize the columns.
    initTableColumns(selectionModel);

    // Add the CellList to the adapter in the database.
    ContactDatabase.get().addDataDisplay(cellTable);

    initWidget(uiBinder.createAndBindUi(this));

    String firstname = "John";
    String lastname = "Familyguy";
    Date age = new Date(); // get's the current date/time

    DemoUser myuser = new DemoUser(firstname, lastname, age);

    CalendarUtil.addDaysToDate(age, 2);

    mytextbox.setText(myuser.getAge().toString());

    CalendarUtil.addDaysToDate(myuser.getAge(), 5);

    mytextbox.setText(myuser.getAge().toString());

    button.setText("Click me to go to the new sortable table example");
    button2.setText("CustomPlaces");
    dialogBox.setText("Open DialogBox");

}

From source file:com.plr.hanzi.client.view.dictionnary.ZwCharBrowser.java

License:Apache License

public ZwCharBrowser() {

    cellTable = new CellTable<ZhongWenCharacter>(CardData.KEY_PROVIDER);

    // Create rank column.
    TextColumn<ZhongWenCharacter> rankColumn = new TextColumn<ZhongWenCharacter>() {
        @Override/*from   ww w.ja  v  a 2s  .  c o m*/
        public String getValue(ZhongWenCharacter zwChar) {
            return "" + zwChar.getId();
        }
    };

    TextColumn<ZhongWenCharacter> zhCharColumn = new TextColumn<ZhongWenCharacter>() {
        @Override
        public String getValue(ZhongWenCharacter zwChar) {
            return zwChar.getSimplifiedCharacter();
        }
    };

    cellTable.addColumn(rankColumn, "Rank");
    cellTable.addColumn(zhCharColumn, "Simplified");

    cellTable.setPageSize(getPageSize());
    cellTable.setKeyboardPagingPolicy(KeyboardPagingPolicy.CHANGE_PAGE);
    cellTable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.BOUND_TO_SELECTION);

    // // Create a Pager to control the table.
    SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
    pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0, true);
    pager.setDisplay(cellTable);

    // Add a selection model so we can select cells.
    final SingleSelectionModel<ZhongWenCharacter> selectionModel = new SingleSelectionModel<ZhongWenCharacter>(
            CardData.KEY_PROVIDER);
    cellTable.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {

        @Override
        public void onSelectionChange(SelectionChangeEvent event) {
            ZhongWenCharacter zwChar = selectionModel.getSelectedObject();
            History.newItem(ApplicationConst.CHARARCTER + "/" + zwChar.getId());
        }
    });

    // Add the CellList to the data provider in the database.
    DataControler.get().addDataDisplay(cellTable);

    cellTable.addRangeChangeHandler(new RangeChangeEvent.Handler() {
        @Override
        public void onRangeChange(RangeChangeEvent event) {
            lastAccessedRange = event.getNewRange();
        }
    });

    if (lastAccessedRange != null) {
        cellTable.setVisibleRange(lastAccessedRange);
    }

    initWidget(uiBinder.createAndBindUi(this));
}

From source file:com.spshop.admin.client.sample.CwCellTable.java

License:Apache License

/**
 * Initialize this example.//from w ww .java 2 s . c  o  m
 */
@Override
public Widget onInitialize() {
    // Create a CellTable.

    // Set a key provider that provides a unique key for each contact. If key is
    // used to identify contacts when fields (such as the name and address)
    // change.
    cellTable = new CellTable<ContactInfo>(ContactDatabase.ContactInfo.KEY_PROVIDER);
    cellTable.setWidth("100%", true);

    // Attach a column sort handler to the ListDataProvider to sort the list.
    ListHandler<ContactInfo> sortHandler = new ListHandler<ContactInfo>(
            ContactDatabase.get().getDataProvider().getList());
    cellTable.addColumnSortHandler(sortHandler);

    // Create a Pager to control the table.
    SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
    pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0, true);
    pager.setDisplay(cellTable);

    // Add a selection model so we can select cells.
    final SelectionModel<ContactInfo> selectionModel = new MultiSelectionModel<ContactInfo>(
            ContactDatabase.ContactInfo.KEY_PROVIDER);
    cellTable.setSelectionModel(selectionModel,
            DefaultSelectionEventManager.<ContactInfo>createCheckboxManager());

    // Initialize the columns.
    initTableColumns(selectionModel, sortHandler);

    // Add the CellList to the adapter in the database.
    ContactDatabase.get().addDataDisplay(cellTable);

    // Create the UiBinder.
    Binder uiBinder = GWT.create(Binder.class);
    Widget widget = uiBinder.createAndBindUi(this);

    return widget;
}

From source file:eu.europeana.uim.gui.cp.client.europeanawidgets.ImportResourcesWidget.java

License:EUPL

@Override
public Widget onInitialize() {

    searchPanel = new VerticalPanel();
    searchPanel.setSpacing(8);/*from   ww w. j a  va 2s.co  m*/
    searchPanel.setWidth("32em");
    searchPanel.add(createAdvancedForm());

    impResultsTable = new FlexTable();
    FlexCellFormatter cellFormatter = impResultsTable.getFlexCellFormatter();
    impResultsTable.addStyleName("cw-FlexTable");
    impResultsTable.setWidth("32em");
    impResultsTable.setCellSpacing(5);
    impResultsTable.setCellPadding(3);

    // Add some text
    cellFormatter.setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_LEFT);

    cellFormatter.setColSpan(0, 0, 2);

    importDialog = createImportDialog();
    searchDialog = createSearchDialogBox();

    // Create a CellTable.

    // Set a key provider that provides a unique key for each contact. If
    // key is
    // used to identify contacts when fields (such as the name and address)
    // change.

    cellTable = new CellTable<SugarCRMRecordDTO>(KEY_PROVIDER);
    cellTable.setWidth("100%", true);

    // Attach a column sort handler to the ListDataProvider to sort the
    // list.
    ListHandler<SugarCRMRecordDTO> sortHandler = new ListHandler<SugarCRMRecordDTO>(dataProvider.getList());
    cellTable.addColumnSortHandler(sortHandler);

    // Create a Pager to control the table.
    SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
    pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0, true);
    pager.setDisplay(cellTable);

    // Add a selection model so we can select cells.
    final SelectionModel<SugarCRMRecordDTO> selectionModel = new MultiSelectionModel<SugarCRMRecordDTO>(
            KEY_PROVIDER);
    cellTable.setSelectionModel(selectionModel,
            DefaultSelectionEventManager.<SugarCRMRecordDTO>createCheckboxManager());

    // Initialize the columns.
    initTableColumns(selectionModel, sortHandler);

    // Add the CellList to the adapter in the database.
    dataProvider.addDataDisplay(cellTable);

    // Create the UiBinder.

    Binder uiBinder = GWT.create(Binder.class);
    Widget widget = (Widget) uiBinder.createAndBindUi(this);

    return widget;

}

From source file:eu.zeigermann.gwt.demo.client.item.DefaultItemView.java

License:Apache License

private void initTable(AsyncDataProvider<ItemDto> dataProvider) {
    final ProvidesKey<ItemDto> keyProvider = new ProvidesKey<ItemDto>() {
        public Object getKey(ItemDto list) {
            return list == null ? null : list.getId();
        }/*from w w  w  .  ja v a 2s  .c  o m*/
    };
    cellTable = new CellTable<ItemDto>(keyProvider);
    dataProvider.addDataDisplay(cellTable);
    cellTable.setPageSize(5);

    cellTable.sinkEvents(Event.ONDBLCLICK);
    final MultiSelectionModel<ItemDto> selectionModel = new MultiSelectionModel<ItemDto>(keyProvider);
    cellTable.setSelectionModel(selectionModel, new CellPreviewEvent.Handler<ItemDto>() {

        @Override
        public void onCellPreview(CellPreviewEvent<ItemDto> event) {
            int eventType = Event.getTypeInt(event.getNativeEvent().getType());
            if (eventType == Event.ONDBLCLICK) {
                ItemDto list = event.getValue();
                presenter.edit(list);
            }
        }
    });

    // styles

    // bootstrap
    cellTable.addStyleName("table");
    cellTable.addStyleName("table-bordered");
    // makes selection invisible on every even row
    // cellTable.addStyleName("table-striped");

    AsyncHandler columnSortHandler = new AsyncHandler(cellTable);

    // columns
    addShopColumn(columnSortHandler);
    addNameColumn();
    addCheckedColumn();
    addEditColumn();
    addDeleteColumn();
}