Example usage for com.google.gwt.view.client SelectionModel setSelected

List of usage examples for com.google.gwt.view.client SelectionModel setSelected

Introduction

In this page you can find the example usage for com.google.gwt.view.client SelectionModel setSelected.

Prototype

void setSelected(T object, boolean selected);

Source Link

Document

Set the selected state of an object and fire a SelectionChangeEvent if the selection has changed.

Usage

From source file:com.chinarewards.gwt.license.client.user.view.UserSearchWidget.java

private void initTableColumns(final SelectionModel<UserVo> selectionModel) {
    Column<UserVo, Boolean> checkColumn = new Column<UserVo, Boolean>(new CheckboxCell()) {
        @Override/*w  w  w .  jav a  2s .  co  m*/
        public Boolean getValue(UserVo o) {
            return selectionModel.isSelected(o);
        }
    };
    users = new HashMap<String, UserVo>();
    checkColumn.setFieldUpdater(new FieldUpdater<UserVo, Boolean>() {
        @Override
        public void update(int index, UserVo o, Boolean value) {
            if (value) {
                users.put(o.getId(), o);
            } else {
                users.remove(o.getId());
            }
            selectionModel.setSelected(o, value);
        }
    });
    resultTable.addColumn(checkColumn, "");

    resultTable.addColumn(new TextColumn<UserVo>() {

        @Override
        public String getValue(UserVo o) {
            return o.getName();
        }
    }, "???");

    resultTable.addColumn(new TextColumn<UserVo>() {

        @Override
        public String getValue(UserVo o) {
            return o.getEnterpriseName();
        }
    }, "????");

    resultTable.addColumn(new TextColumn<UserVo>() {

        @Override
        public String getValue(UserVo o) {
            return o.getMobile();
        }
    }, "");

    resultTable.addColumn(new TextColumn<UserVo>() {

        @Override
        public String getValue(UserVo o) {
            return o.getEmail();
        }
    }, "");

    resultTable.addColumn(new TextColumn<UserVo>() {

        @Override
        public String getValue(UserVo o) {
            return o.getCreatedAt() != null ? dateFormat.format(o.getCreatedAt()) : "";
        }
    }, "?");

    resultTable.addColumn(new TextColumn<UserVo>() {

        @Override
        public String getValue(UserVo o) {
            return o.getStatus();
        }
    }, "?");
    resultTable.addColumn(new TextColumn<UserVo>() {

        @Override
        public String getValue(UserVo o) {
            return o.getBalance() + "";
        }
    }, "");

    resultTable.addColumn("?", new HyperLinkCell(), new GetValue<UserVo, String>() {
        @Override
        public String getValue(UserVo userVo) {
            return "";
        }
    }, new FieldUpdater<UserVo, String>() {

        @Override
        public void update(int index, UserVo o, String value) {
            users.put(o.getId(), o);
        }

    });
}

From source file:com.google.gwt.examples.view.KeyProviderExample.java

License:Apache License

public void onModuleLoad() {
    /*//w  w  w.j a v a2 s.c o  m
     * Define a key provider for a Contact. We use the unique ID as the key,
     * which allows to maintain selection even if the name changes.
     */
    ProvidesKey<Contact> keyProvider = new ProvidesKey<Contact>() {
        public Object getKey(Contact item) {
            // Always do a null check.
            return (item == null) ? null : item.id;
        }
    };

    // Create a CellList using the keyProvider.
    CellList<Contact> cellList = new CellList<Contact>(new ContactCell(), keyProvider);

    // Push data into the CellList.
    cellList.setRowCount(CONTACTS.size(), true);
    cellList.setRowData(0, CONTACTS);

    // Add a selection model using the same keyProvider.
    SelectionModel<Contact> selectionModel = new SingleSelectionModel<Contact>(keyProvider);
    cellList.setSelectionModel(selectionModel);

    /*
     * Select a contact. The selectionModel will select based on the ID because
     * we used a keyProvider.
     */
    Contact sarah = CONTACTS.get(3);
    selectionModel.setSelected(sarah, true);

    // Modify the name of the contact.
    sarah.name = "Sara";

    /*
     * Redraw the CellList. Sarah/Sara will still be selected because we
     * identify her by ID. If we did not use a keyProvider, Sara would not be
     * selected.
     */
    cellList.redraw();

    // Add the widgets to the root panel.
    RootPanel.get().add(cellList);
}

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

License:Apache License

private void initTableColumns(final SelectionModel<ContactInfo> selectionModel,
        CellTableSorting<ContactInfo> cellTable) {

    // This table will uses a checkbox column for selection.
    // Alternatively, you can call cellTable.setSelectionEnabled(true) to
    // enable mouse selection.
    Column<ContactInfo, Boolean> checkColumn = new Column<ContactInfo, Boolean>(new CheckboxCell(true, true)) {
        @Override/*  ww w  .j  a  v a2s.c o  m*/
        public Boolean getValue(ContactInfo object) {
            // Get the value from the selection model.
            return selectionModel.isSelected(object);
        }
    };
    checkColumn.setFieldUpdater(new FieldUpdater<ContactInfo, Boolean>() {
        public void update(int index, ContactInfo object, Boolean value) {
            // Called when the user clicks on a checkbox.
            selectionModel.setSelected(object, value);
        }
    });
    cellTable.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br>"));

    cellTable.addColumn("First name", new TextCell(), new GetValue<ContactInfo, String>() {
        public String getValue(ContactInfo object) {
            return object.getFirstName();
        }
    }, new SortHeader("First name"));

    // Last name.
    Column<ContactInfo, String> lastNameColumn = new Column<ContactInfo, String>(new EditTextCell()) {
        @Override
        public String getValue(ContactInfo object) {
            return object.getLastName();
        }
    };

    cellTable.addColumn(lastNameColumn, "Last name");
    lastNameColumn.setFieldUpdater(new FieldUpdater<ContactInfo, String>() {
        public void update(int index, ContactInfo object, String value) {
            // Called when the user changes the value.
            object.setLastName(value);
            ContactDatabase.get().refreshDisplays();
        }
    });

    // Category.
    final Category[] categories = ContactDatabase.get().queryCategories();
    List<String> categoryNames = new ArrayList<String>();
    for (Category category : categories) {
        categoryNames.add(category.getDisplayName());
    }
    SelectionCell categoryCell = new SelectionCell(categoryNames);
    Column<ContactInfo, String> categoryColumn = new Column<ContactInfo, String>(categoryCell) {
        @Override
        public String getValue(ContactInfo object) {
            return object.getCategory().getDisplayName();
        }
    };
    cellTable.addColumn(categoryColumn, "Category");
    categoryColumn.setFieldUpdater(new FieldUpdater<ContactInfo, String>() {
        public void update(int index, ContactInfo object, String value) {
            for (Category category : categories) {
                if (category.getDisplayName().equals(value)) {
                    object.setCategory(category);
                }
            }
            ContactDatabase.get().refreshDisplays();
        }
    });

    // Address.
    cellTable.addColumn("Address", new TextCell(), new GetValue<ContactInfo, String>() {
        public String getValue(ContactInfo object) {
            return object.getAddress();
        }
    }, new SortHeader("Address"));

    cellTable.addColumn("Birthday", new DateCell(), new GetValue<ContactInfo, Date>() {
        public Date getValue(ContactInfo object) {
            return object.getBirthday();
        }
    }, new SortHeader("Birthday"));
}

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

License:Apache License

/**
 * Add the columns to the table.//ww w  .jav  a  2s .  c  o  m
 */
private void initTableColumns(final SelectionModel<ContactInfo> selectionModel) {
    // This table will uses a checkbox column for selection.
    // Alternatively, you can call cellTable.setSelectionEnabled(true) to
    // enable mouse selection.
    Column<ContactInfo, Boolean> checkColumn = new Column<ContactInfo, Boolean>(new CheckboxCell(true, true)) {
        @Override
        public Boolean getValue(ContactInfo object) {
            // Get the value from the selection model.
            return selectionModel.isSelected(object);
        }
    };
    checkColumn.setFieldUpdater(new FieldUpdater<ContactInfo, Boolean>() {
        public void update(int index, ContactInfo object, Boolean value) {
            // Called when the user clicks on a checkbox.
            selectionModel.setSelected(object, value);
        }
    });
    cellTable.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br>"));

    // First name.
    // Column<ContactInfo, String> firstNameColumn = new Column<ContactInfo,
    // String>(
    // new EditTextCell()) {
    // @Override
    // public String getValue(ContactInfo object) {
    // return object.getFirstName();
    // }
    // };

    // TextHeader firstNameHeader = new TextHeader("First name");
    // firstNameHeader.setUpdater(new ValueUpdater<String>() {
    // @Override
    // public void update(String value) {
    // Window.alert("Update the header");
    // }
    // });
    //
    // cellTable.addColumn(firstNameColumn, firstNameHeader);
    //
    // firstNameColumn
    // .setFieldUpdater(new FieldUpdater<ContactInfo, String>() {
    // public void update(int index, ContactInfo object,
    // String value) {
    // // Called when the user changes the value.
    // object.setFirstName(value);
    // ContactDatabase.get().refreshDisplays();
    // }
    // });

    addColumn("First name", new TextCell(), new GetValue<ContactInfo, String>() {
        public String getValue(ContactInfo object) {
            return object.getFirstName();
        }
    });

    // Last name.
    Column<ContactInfo, String> lastNameColumn = new Column<ContactInfo, String>(new EditTextCell()) {
        @Override
        public String getValue(ContactInfo object) {
            return object.getLastName();
        }
    };
    cellTable.addColumn(lastNameColumn, "Last name");
    lastNameColumn.setFieldUpdater(new FieldUpdater<ContactInfo, String>() {
        public void update(int index, ContactInfo object, String value) {
            // Called when the user changes the value.
            object.setLastName(value);
            ContactDatabase.get().refreshDisplays();
        }
    });

    // Category.
    final Category[] categories = ContactDatabase.get().queryCategories();
    List<String> categoryNames = new ArrayList<String>();
    for (Category category : categories) {
        categoryNames.add(category.getDisplayName());
    }
    SelectionCell categoryCell = new SelectionCell(categoryNames);
    Column<ContactInfo, String> categoryColumn = new Column<ContactInfo, String>(categoryCell) {
        @Override
        public String getValue(ContactInfo object) {
            return object.getCategory().getDisplayName();
        }
    };
    cellTable.addColumn(categoryColumn, "Category");
    categoryColumn.setFieldUpdater(new FieldUpdater<ContactInfo, String>() {
        public void update(int index, ContactInfo object, String value) {
            for (Category category : categories) {
                if (category.getDisplayName().equals(value)) {
                    object.setCategory(category);
                }
            }
            ContactDatabase.get().refreshDisplays();
        }
    });

    // Address.
    addColumn("Address", new TextCell(), new GetValue<ContactInfo, String>() {
        public String getValue(ContactInfo object) {
            return object.getAddress();
        }
    });

    // cellTable.addColumn(new Column<ContactInfo, String>(new TextCell()) {
    // @Override
    // public String getValue(ContactInfo object) {
    // return object.getAddress();
    // }
    // }, "Address");
}

From source file:gwtquery.plugins.droppable.client.celltablesample.CellTableSample.java

License:Apache License

/**
 * Add the columns to the table.//from  ww w  .  j a  v a2 s . c om
 * 
 * Use {@link DragAndDropColumn} instead of {@link Column}
 * @param sortHandler 
 */
private void initTableColumns(final SelectionModel<ContactInfo> selectionModel,
        ListHandler<ContactInfo> sortHandler) {

    DragAndDropColumn<ContactInfo, Boolean> checkColumn = new DragAndDropColumn<ContactInfo, Boolean>(
            new CheckboxCell(true, true)) {
        @Override
        public Boolean getValue(ContactInfo object) {
            // Get the value from the selection model.
            return selectionModel.isSelected(object);
        }
    };
    checkColumn.setFieldUpdater(new FieldUpdater<ContactInfo, Boolean>() {
        public void update(int index, ContactInfo object, Boolean value) {
            // Called when the user clicks on a checkbox.
            selectionModel.setSelected(object, value);
        }
    });
    checkColumn.setCellDraggableOnly();
    initDragOperation(checkColumn);
    cellTable.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br>"));

    // First name.
    DragAndDropColumn<ContactInfo, String> firstNameColumn = new DragAndDropColumn<ContactInfo, String>(
            new EditTextCell()) {
        @Override
        public String getValue(ContactInfo object) {
            return object.getFirstName();
        }
    };
    firstNameColumn.setCellDraggableOnly();
    firstNameColumn.setSortable(true);
    sortHandler.setComparator(firstNameColumn, new Comparator<ContactInfo>() {
        public int compare(ContactInfo o1, ContactInfo o2) {
            return o1.getFirstName().compareTo(o2.getFirstName());
        }
    });

    initDragOperation(firstNameColumn);
    cellTable.addColumn(firstNameColumn, constants.cwCellTableColumnFirstName());
    firstNameColumn.setFieldUpdater(new FieldUpdater<ContactInfo, String>() {
        public void update(int index, ContactInfo object, String value) {
            // Called when the user changes the value.
            object.setFirstName(value);
            ContactDatabase.get().refreshDisplays();
        }
    });

    // Last name.
    DragAndDropColumn<ContactInfo, String> lastNameColumn = new DragAndDropColumn<ContactInfo, String>(
            new EditTextCell()) {
        @Override
        public String getValue(ContactInfo object) {
            return object.getLastName();
        }
    };
    lastNameColumn.setCellDraggableOnly();
    lastNameColumn.setSortable(true);
    sortHandler.setComparator(lastNameColumn, new Comparator<ContactInfo>() {
        public int compare(ContactInfo o1, ContactInfo o2) {
            return o1.getLastName().compareTo(o2.getLastName());
        }
    });

    initDragOperation(lastNameColumn);
    cellTable.addColumn(lastNameColumn, constants.cwCellTableColumnLastName());
    lastNameColumn.setFieldUpdater(new FieldUpdater<ContactInfo, String>() {
        public void update(int index, ContactInfo object, String value) {
            // Called when the user changes the value.
            object.setLastName(value);
            ContactDatabase.get().refreshDisplays();
        }
    });

    // Category.
    final Category[] categories = ContactDatabase.get().queryCategories();
    List<String> categoryNames = new ArrayList<String>();
    for (Category category : categories) {
        categoryNames.add(category.getDisplayName());
    }
    SelectionCell categoryCell = new SelectionCell(categoryNames);
    DragAndDropColumn<ContactInfo, String> categoryColumn = new DragAndDropColumn<ContactInfo, String>(
            categoryCell) {
        @Override
        public String getValue(ContactInfo object) {
            return object.getCategory().getDisplayName();
        }
    };
    categoryColumn.setCellDraggableOnly();
    initDragOperation(categoryColumn);
    cellTable.addColumn(categoryColumn, constants.cwCellTableColumnCategory());
    categoryColumn.setFieldUpdater(new FieldUpdater<ContactInfo, String>() {
        public void update(int index, ContactInfo object, String value) {
            for (Category category : categories) {
                if (category.getDisplayName().equals(value)) {
                    object.setCategory(category);
                }
            }
            ContactDatabase.get().refreshDisplays();
        }
    });

    // Address.
    DragAndDropColumn<ContactInfo, String> addressColumn = new DragAndDropColumn<ContactInfo, String>(
            new TextCell()) {
        @Override
        public String getValue(ContactInfo object) {
            return object.getAddress();
        }
    };
    cellTable.addColumn(addressColumn, constants.cwCellTableColumnAddress());
    addressColumn.setCellDraggableOnly();
    initDragOperation(addressColumn);
}

From source file:gwtquery.plugins.droppable.client.datagridsample.DataGridSample.java

License:Apache License

/**
 * Add the columns to the table./* w ww .  j a  v  a2 s.com*/
 * 
 * Use {@link DragAndDropColumn} instead of {@link Column}
 * @param sortHandler 
 */
private void initTableColumns(final SelectionModel<ContactInfo> selectionModel,
        ListHandler<ContactInfo> sortHandler) {

    DragAndDropColumn<ContactInfo, Boolean> checkColumn = new DragAndDropColumn<ContactInfo, Boolean>(
            new CheckboxCell(true, true)) {
        @Override
        public Boolean getValue(ContactInfo object) {
            // Get the value from the selection model.
            return selectionModel.isSelected(object);
        }
    };
    checkColumn.setFieldUpdater(new FieldUpdater<ContactInfo, Boolean>() {
        public void update(int index, ContactInfo object, Boolean value) {
            // Called when the user clicks on a checkbox.
            selectionModel.setSelected(object, value);
        }
    });
    checkColumn.setCellDraggableOnly();
    checkColumn.setSortable(false);
    initDragOperation(checkColumn);
    dataGrid.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br>"));
    dataGrid.setColumnWidth(checkColumn, "60px");

    // First name.
    DragAndDropColumn<ContactInfo, String> firstNameColumn = new DragAndDropColumn<ContactInfo, String>(
            new EditTextCell()) {
        @Override
        public String getValue(ContactInfo object) {
            return object.getFirstName();
        }
    };
    firstNameColumn.setCellDraggableOnly();
    firstNameColumn.setSortable(true);
    sortHandler.setComparator(firstNameColumn, new Comparator<ContactInfo>() {
        public int compare(ContactInfo o1, ContactInfo o2) {
            return o1.getFirstName().compareTo(o2.getFirstName());
        }
    });

    initDragOperation(firstNameColumn);
    dataGrid.addColumn(firstNameColumn, constants.cwDataGridColumnFirstName());
    firstNameColumn.setFieldUpdater(new FieldUpdater<ContactInfo, String>() {
        public void update(int index, ContactInfo object, String value) {
            // Called when the user changes the value.
            object.setFirstName(value);
            ContactDatabase.get().refreshDisplays();
        }
    });

    // Last name.
    DragAndDropColumn<ContactInfo, String> lastNameColumn = new DragAndDropColumn<ContactInfo, String>(
            new EditTextCell()) {
        @Override
        public String getValue(ContactInfo object) {
            return object.getLastName();
        }
    };
    lastNameColumn.setCellDraggableOnly();
    lastNameColumn.setSortable(true);
    sortHandler.setComparator(lastNameColumn, new Comparator<ContactInfo>() {
        public int compare(ContactInfo o1, ContactInfo o2) {
            return o1.getLastName().compareTo(o2.getLastName());
        }
    });

    initDragOperation(lastNameColumn);
    dataGrid.addColumn(lastNameColumn, constants.cwDataGridColumnLastName());
    lastNameColumn.setFieldUpdater(new FieldUpdater<ContactInfo, String>() {
        public void update(int index, ContactInfo object, String value) {
            // Called when the user changes the value.
            object.setLastName(value);
            ContactDatabase.get().refreshDisplays();
        }
    });

    // Category.
    final Category[] categories = ContactDatabase.get().queryCategories();
    List<String> categoryNames = new ArrayList<String>();
    for (Category category : categories) {
        categoryNames.add(category.getDisplayName());
    }
    SelectionCell categoryCell = new SelectionCell(categoryNames);
    DragAndDropColumn<ContactInfo, String> categoryColumn = new DragAndDropColumn<ContactInfo, String>(
            categoryCell) {
        @Override
        public String getValue(ContactInfo object) {
            return object.getCategory().getDisplayName();
        }
    };
    categoryColumn.setCellDraggableOnly();
    initDragOperation(categoryColumn);
    dataGrid.addColumn(categoryColumn, constants.cwDataGridColumnCategory());
    categoryColumn.setFieldUpdater(new FieldUpdater<ContactInfo, String>() {
        public void update(int index, ContactInfo object, String value) {
            for (Category category : categories) {
                if (category.getDisplayName().equals(value)) {
                    object.setCategory(category);
                }
            }
            ContactDatabase.get().refreshDisplays();
        }
    });

    // Address.
    DragAndDropColumn<ContactInfo, String> addressColumn = new DragAndDropColumn<ContactInfo, String>(
            new TextCell()) {
        @Override
        public String getValue(ContactInfo object) {
            return object.getAddress();
        }
    };
    dataGrid.addColumn(addressColumn, constants.cwDataGridColumnAddress());
    addressColumn.setCellDraggableOnly();
    initDragOperation(addressColumn);
}

From source file:org.dataconservancy.dcs.access.client.model.CollectionTreeViewModel.java

License:Apache License

public CollectionTreeViewModel(final SelectionModel<CollectionNode> selectionModel,
        final DatasetRelation relations, String root) {
    this.selectionModel = selectionModel;
    this.dusMap = relations.getDuAttrMap();
    this.parentMap = relations.getParentMap();
    this.root = root;

    // Construct a composite cell for contacts that includes a checkbox.
    //adding//from  w  ww.j a v a  2s .  c  o  m
    List<HasCell<CollectionNode, ?>> hasCells = new ArrayList<HasCell<CollectionNode, ?>>();
    hasCells.add(new HasCell<CollectionNode, Boolean>() {

        private CheckboxCell cell = new CheckboxCell(true, false);

        public Cell<Boolean> getCell() {
            return cell;
        }

        public Boolean getValue(CollectionNode object) {
            return selectionModel.isSelected(object);
        }

        private void updateChildNodes(CollectionNode object, Boolean value) {

            List<String> subCollections = object.getSub().get(SubType.Collection);
            if (subCollections != null)//why is this running twice?
            {
                for (int i = 0; i < subCollections.size(); i++) {
                    selectionModel.setSelected((CollectionNode) dusMap.get(subCollections.get(i)), value);
                    MediciIngestPresenter.EVENT_BUS.fireEvent(new CollectionPassiveSelectEvent(
                            (CollectionNode) dusMap.get(subCollections.get(i)), value));
                    updateChildNodes((CollectionNode) dusMap.get(subCollections.get(i)), value);
                }
            }
        }

        @Override
        public FieldUpdater<CollectionNode, Boolean> getFieldUpdater() {
            // TODO Auto-generated method stub
            //return null;
            return new FieldUpdater<CollectionNode, Boolean>() {
                public void update(int index, CollectionNode object, Boolean value) {

                    //Update child Nodes
                    /* List<String> subCollections = object.getSub().get(SubType.Collection);
                    if(subCollections!=null)//why is this running twice?
                     {
                     for(int i=0;i<subCollections.size();i++)
                        selectionModel.setSelected((CollectionNode)dusMap.get(subCollections.get(i)), value);
                     }*/

                    //Update child collection nodes
                    updateChildNodes(object, value);

                    //update the Parent Node
                    String parentCollection = parentMap.get(object.getId());
                    if (parentCollection != null) {
                        List<String> siblingCollections = dusMap.get(parentCollection).getSub()
                                .get(SubType.Collection);

                        int allSelected = 1;
                        if (value) {

                            for (String sibling : siblingCollections) {
                                if (!selectionModel.isSelected(dusMap.get(sibling))) {
                                    allSelected = 0;
                                    break;
                                }
                            }
                        }
                        if (allSelected == 1 && value) {
                            //set parent true
                            selectionModel.setSelected((CollectionNode) dusMap.get(parentCollection), true);

                        } else {
                            //set parent false
                            selectionModel.setSelected((CollectionNode) dusMap.get(parentCollection), false);
                        }

                    }
                    MediciIngestPresenter.EVENT_BUS.fireEvent(new CollectionSelectEvent(object, value));
                }
            };
        }
    });

    hasCells.add(new HasCell<CollectionNode, CollectionNode>() {

        private CollectionCell cell = new CollectionCell();

        public Cell<CollectionNode> getCell() {
            return cell;
        }

        public FieldUpdater<CollectionNode, CollectionNode> getFieldUpdater() {
            return null;
        }

        public CollectionNode getValue(CollectionNode object) {
            return object;
        }
    });

    collectionCell = new CompositeCell<CollectionNode>(hasCells) {
        @Override
        public void render(Context context, CollectionNode value, SafeHtmlBuilder sb) {
            if (value == null)
                return;
            sb.appendHtmlConstant("<table><tbody><tr>");
            super.render(context, value, sb);
            sb.appendHtmlConstant("</tr></tbody></table>");
        }

        @Override
        protected Element getContainerElement(Element parent) {
            // Return the first TR element in the table.
            return parent.getFirstChildElement().getFirstChildElement().getFirstChildElement();
        }

        @Override
        protected <X> void render(Context context, CollectionNode value, SafeHtmlBuilder sb,
                HasCell<CollectionNode, X> hasCell) {
            if (value != null) {
                Cell<X> cell = hasCell.getCell();
                sb.appendHtmlConstant("<td>");
                cell.render(context, hasCell.getValue(value), sb);
                sb.appendHtmlConstant("</td>");
            }
        }
    };

}

From source file:org.gss_project.gss.web.client.GSSSelectionEventManager.java

License:Open Source License

/**
 * Handle an event that could cause a value to be selected. This method works
 * for any {@link SelectionModel}. Pressing the space bar or ctrl+click will
 * toggle the selection state. Clicking selects the row if it is not selected.
 * //from  w w  w  .  ja  va 2 s .c  om
 * @param event the {@link CellPreviewEvent} that triggered selection
 * @param action the action to handle
 * @param selectionModel the {@link SelectionModel} to update
 */
protected void handleSelectionEvent(CellPreviewEvent<T> event, SelectAction action,
        SelectionModel<? super T> selectionModel) {
    // Handle selection overrides.
    T value = event.getValue();
    if (action != null) {
        switch (action) {
        case IGNORE:
            return;
        case SELECT:
            selectionModel.setSelected(value, true);
            return;
        case DESELECT:
            selectionModel.setSelected(value, false);
            return;
        case TOGGLE:
            selectionModel.setSelected(value, !selectionModel.isSelected(value));
            return;
        }
    }

    // Handle default selection.
    NativeEvent nativeEvent = event.getNativeEvent();
    String type = nativeEvent.getType();
    if ("click".equals(type)) {
        if (nativeEvent.getCtrlKey() || nativeEvent.getMetaKey()) {
            // Toggle selection on ctrl+click.
            selectionModel.setSelected(value, !selectionModel.isSelected(value));
        } else {
            // Select on click.
            selectionModel.setSelected(value, true);
        }
    } else if ("keyup".equals(type)) {
        // Toggle selection on space.
        int keyCode = nativeEvent.getKeyCode();
        if (keyCode == 32) {
            selectionModel.setSelected(value, !selectionModel.isSelected(value));
        }
    }
}

From source file:org.teiid.authoring.client.widgets.DataSourceListWidget.java

License:Apache License

public void setSelection(String dsName) {
    SelectionModel<? super DataSourcePageRow> selModel = dsList.getSelectionModel();
    for (DataSourcePageRow dSource : getData()) {
        if (dSource.getName().equals(dsName)) {
            selModel.setSelected(dSource, true);
            break;
        }//from w w  w .  j  av a2s .  c o  m
    }
}

From source file:org.teiid.webui.client.widgets.DataSourceListWidget.java

License:Apache License

public void selectFirstItem() {
    SelectionModel<? super DataSourcePageRow> selModel = dsList.getSelectionModel();
    DataSourcePageRow firstRow = getData().get(0);
    if (firstRow != null) {
        selModel.setSelected(firstRow, true);
    }/*ww w.  j a va 2  s.  c  om*/
}