Example usage for com.google.gwt.view.client SingleSelectionModel getSelectedObject

List of usage examples for com.google.gwt.view.client SingleSelectionModel getSelectedObject

Introduction

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

Prototype

public T getSelectedObject() 

Source Link

Document

Gets the currently-selected object.

Usage

From source file:cc.alcina.framework.gwt.client.widget.SelectWithSearch.java

License:Apache License

private void updateItemsCellList(String filterText, HasWidgets itemHolder) {
    emptyItems = true;//from  w w w .  jav a 2s  .com
    Cell<T> cell = new AbstractCell<T>() {
        @Override
        public void render(com.google.gwt.cell.client.Cell.Context context, T value, SafeHtmlBuilder sb) {
            sb.appendEscaped((String) renderer.apply(value));
        }
    };
    CellList<T> cellList = new CellList<T>(cell);
    cellList.setPageSize(9999);
    cellList.setKeyboardPagingPolicy(KeyboardPagingPolicy.INCREASE_RANGE);
    cellList.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
    // Add a selection model so we can select cells.
    final SingleSelectionModel<T> selectionModel = new SingleSelectionModel<T>(new SimpleKeyProvider<T>());
    cellList.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        @Override
        public void onSelectionChange(SelectionChangeEvent event) {
            itemSelected(selectionModel.getSelectedObject());
        }
    });
    List<T> items = new ArrayList<>();
    for (G c : keys) {
        if (!itemMap.containsKey(c)) {
            continue;
        }
        for (T item : itemMap.get(c)) {
            String filterable = CommonUtils.nullToEmpty(((String) renderer.apply(item))).toLowerCase();
            if (itemFilter.allow(item, filterable, filterText) && !selectedItems.contains(item)) {
                items.add(item);
            }
        }
    }
    ListDataProvider<T> dataProvider = new ListDataProvider<T>();
    dataProvider.getList().addAll(items);
    dataProvider.addDataDisplay(cellList);
    emptyItems = items.isEmpty();
    itemHolder.clear();
    itemHolder.add(cellList);
    afterUpdateItems(emptyItems);
}

From source file:cc.kune.gspace.client.i18n.I18nCellList.java

License:Apache License

/**
 * Instantiates a new i18n cell list./*from w  ww .j a  v  a2 s .  c om*/
 * 
 * @param data
 *          the data
 * @param i18n
 *          the i18n
 * @param saver
 *          the saver
 */
@Inject
public I18nCellList(final I18nTranslationDataProvider data, final I18nUITranslationService i18n,
        final I18nTranslatorSaver saver) {
    this.data = data;

    final TranslationCell cell = new TranslationCell();

    // Set a key provider that provides a unique key for each contact. If key is
    // used to identify translations when fields change.
    cellList = new CellList<I18nTranslationDTO>(cell, I18nTranslationDTO.KEY_PROVIDER);
    cellList.setPageSize(30);
    cellList.setEmptyListMessage(SafeHtmlUtils
            .fromTrustedString("<span style='padding: 10px; font-style: italic;'>Empty list</span>"));
    cellList.setKeyboardPagingPolicy(KeyboardPagingPolicy.INCREASE_RANGE);
    cellList.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.BOUND_TO_SELECTION);
    final SingleSelectionModel<I18nTranslationDTO> selectionModel = new SingleSelectionModel<I18nTranslationDTO>(
            I18nTranslationDTO.KEY_PROVIDER);
    // Add a selection model so we can select cells.

    cellList.setSelectionModel(selectionModel);

    // Create the UiBinder.
    final Binder uiBinder = GWT.create(Binder.class);
    initWidget(uiBinder.createAndBindUi(this));
    translatorForm.init(data, i18n, saver);
    cellList.setValueUpdater(new ValueUpdater<I18nTranslationDTO>() {

        @Override
        public void update(final I18nTranslationDTO value) {
            // save(value);
        }
    });
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        @Override
        public void onSelectionChange(final SelectionChangeEvent event) {
            translatorForm.setInfo(selectionModel.getSelectedObject());
            Scheduler.get().scheduleEntry(new ScheduledCommand() {
                @Override
                public void execute() {
                    translatorForm.focusToTranslate();
                }
            });
        }
    });
    // cellList.sinkEvents(com.google.gwt.user.client.Event.KEYEVENTS);
    data.addDataDisplay(cellList);
    data.setSelectionMode(selectionModel);
    data.setLoadCallback(new SimpleCallback() {
        @Override
        public void onCallback() {
            translatorForm.focusToTranslate();
            NotifyUser.hideProgress();
        }
    });

    // Set the cellList as the display of the pagers.
    // pagerPanel is a scrollable pager that extends the range when the
    // user scrolls to the bottom. rangeLabelPager is a pager that displays the
    // current range, but does not have any controls to change the range.
    pagerPanel.setDisplay(cellList);
    // pagerPanel.setStyleName("k-i18n-trans-list");
    rangeLabelPager.setDisplay(cellList);
}

From source file:cimav.client.view.catalogos.tabulador.NivelesUi.java

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

    /*//from  w w  w . ja v a  2 s  .  com
     * 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.agnie.gwt.common.client.widget.SuggestionBox.java

License:Open Source License

public SuggestionBox() {
    container = (HTMLPanel) uiBinder.createAndBindUi(this);
    initWidget(container);//from  w  w w .  j  a  v  a2  s .  co  m
    list.setVisible(false);

    Label label = new Label(I18.messages.noData());
    list.setEmptyListWidget(label);

    dp.addDataDisplay(list);

    search.addKeyPressHandler(new KeyPressHandler() {

        @Override
        public void onKeyPress(KeyPressEvent event) {
            list.setVisible(true);
        }
    });

    list.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);

    // Add a selection model to handle user selection.
    final SingleSelectionModel<String> selectionModel = new SingleSelectionModel<String>();
    list.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        public void onSelectionChange(SelectionChangeEvent event) {
            String selected = selectionModel.getSelectedObject();
            if (selected != null) {
                Window.alert("You selected: " + selected);
            }
        }
    });

}

From source file:com.codenvy.ide.client.propertiespanel.common.namespace.NameSpaceEditorViewImpl.java

License:Open Source License

private CellTable<NameSpace> createTable(@Nonnull CellTableResources resource) {
    CellTable<NameSpace> table = new CellTable<>(0, resource);

    Column<NameSpace, String> nameSpace = new Column<NameSpace, String>(new TextCell()) {
        @Override/*from www  .j  a va  2s .  c  o m*/
        public String getValue(NameSpace object) {
            return object.toString();
        }
    };

    table.setLoadingIndicator(null);

    table.addColumn(nameSpace);
    table.setColumnWidth(nameSpace, 570, Style.Unit.PX);

    final SingleSelectionModel<NameSpace> selectionModel = new SingleSelectionModel<>();
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        @Override
        public void onSelectionChange(SelectionChangeEvent event) {
            delegate.onSelectedNameSpace(selectionModel.getSelectedObject());
        }
    });
    table.setSelectionModel(selectionModel);

    return table;
}

From source file:com.codenvy.ide.client.propertiespanel.common.propertyconfig.PropertyConfigViewImpl.java

License:Open Source License

/**
 * Returns cell table entity. Adds column names and values to table. Sets selection model to table.
 *
 * @param localizationConstant//w w w  .j av  a2  s.  c  om
 *         localization constant which contains special names of element in current table
 */
private CellTable<Property> createTable(@Nonnull final WSO2EditorLocalizationConstant localizationConstant,
        @Nonnull CellTableResources resource) {

    final CellTable<Property> table = new CellTable<>(0, resource);

    final SingleSelectionModel<Property> selectionModel = new SingleSelectionModel<>();
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        @Override
        public void onSelectionChange(SelectionChangeEvent event) {
            delegate.onSelectedProperty(selectionModel.getSelectedObject());
        }
    });
    table.setSelectionModel(selectionModel);

    TextColumn<Property> name = new TextColumn<Property>() {
        @Override
        public String getValue(Property property) {
            String name = property.getProperty(NAME);

            return name == null ? "" : name;
        }
    };

    TextColumn<Property> expression = new TextColumn<Property>() {
        @Override
        public String getValue(Property property) {
            String value = property.getProperty(VALUE);

            return value == null ? "" : value;
        }
    };

    TextColumn<Property> type = new TextColumn<Property>() {
        @Override
        public String getValue(Property property) {
            ValueType type = property.getProperty(TYPE);

            return type == null ? "" : type.name();
        }
    };

    table.addColumn(name, localizationConstant.columnName());
    table.addColumn(type, localizationConstant.columnType());
    table.addColumn(expression, localizationConstant.columnExpression());

    table.setColumnWidth(name, 210, Style.Unit.PX);
    table.setColumnWidth(type, 120, Style.Unit.PX);
    table.setColumnWidth(expression, 210, Style.Unit.PX);

    table.setLoadingIndicator(null);

    return table;
}

From source file:com.codenvy.ide.client.propertiespanel.endpoints.address.property.PropertyViewImpl.java

License:Open Source License

/** Adds columns names and values to table. Sets selection model to table. */
private CellTable<Property> createTable(@Nonnull CellTableResources resource) {
    CellTable<Property> table = new CellTable<>(0, resource);

    final SingleSelectionModel<Property> selectionModel = new SingleSelectionModel<>();
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        @Override/*  ww  w .  ja va2s  .  co m*/
        public void onSelectionChange(SelectionChangeEvent event) {
            delegate.onPropertySelected(selectionModel.getSelectedObject());
        }
    });
    table.setSelectionModel(selectionModel);

    TextColumn<Property> name = new TextColumn<Property>() {
        @Override
        public String getValue(Property property) {
            return property.getProperty(NAME);
        }
    };

    TextColumn<Property> value = new TextColumn<Property>() {
        @Override
        public String getValue(Property property) {
            if (ValueType.LITERAL.equals(property.getProperty(TYPE))) {
                return property.getProperty(VALUE);
            }

            return property.getProperty(EXPRESSION);
        }
    };

    TextColumn<Property> type = new TextColumn<Property>() {
        @Override
        public String getValue(Property property) {
            ValueType type = property.getProperty(TYPE);

            if (type == null) {
                return "";
            }

            return type.name();
        }
    };

    TextColumn<Property> scope = new TextColumn<Property>() {
        @Override
        public String getValue(Property property) {
            Property.Scope scope = property.getProperty(SCOPE);

            if (scope == null) {
                return "";
            }

            return scope.getValue();
        }
    };

    table.addColumn(name, locale.columnName());
    table.addColumn(value, locale.columnValue());
    table.addColumn(type, locale.columnType());
    table.addColumn(scope, locale.columnScope());

    table.setColumnWidth(name, 150, Style.Unit.PX);
    table.setColumnWidth(value, 150, Style.Unit.PX);
    table.setColumnWidth(type, 60, Style.Unit.PX);
    table.setColumnWidth(scope, 100, Style.Unit.PX);

    table.setLoadingIndicator(null);

    return table;
}

From source file:com.codenvy.ide.client.propertiespanel.mediators.arguments.ArgumentsConfigViewImpl.java

License:Open Source License

private CellTable<Arg> createTable(@Nonnull final WSO2EditorLocalizationConstant localizationConstant,
        @Nonnull CellTableResources resource) {

    final CellTable<Arg> table = new CellTable<>(0, resource);

    final SingleSelectionModel<Arg> selectionModel = new SingleSelectionModel<>();
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        @Override// w w  w  . ja v  a  2 s.  co  m
        public void onSelectionChange(SelectionChangeEvent event) {
            delegate.onSelectedArg(selectionModel.getSelectedObject());
        }
    });
    table.setSelectionModel(selectionModel);

    TextColumn<Arg> value = new TextColumn<Arg>() {
        @Override
        public String getValue(Arg object) {
            return object.getProperty(ARG_VALUE);
        }
    };

    TextColumn<Arg> type = new TextColumn<Arg>() {
        @Override
        public String getValue(Arg arg) {
            ArgType argType = arg.getProperty(ARG_TYPE);

            return argType == null ? "" : argType.getValue();
        }
    };

    TextColumn<Arg> evaluator = new TextColumn<Arg>() {
        @Override
        public String getValue(Arg arg) {
            Evaluator evaluator = arg.getProperty(ARG_EVALUATOR);

            return evaluator == null ? "" : evaluator.getValue();
        }
    };

    table.addColumn(type, localizationConstant.columnType());
    table.addColumn(value, localizationConstant.columnValue());
    table.addColumn(evaluator, localizationConstant.columnEvaluator());

    table.setColumnWidth(type, 120, PX);
    table.setColumnWidth(value, 210, PX);
    table.setColumnWidth(evaluator, 120, PX);

    table.setLoadingIndicator(null);

    return table;
}

From source file:com.codenvy.ide.ext.github.client.importer.page.GithubImporterPageViewImpl.java

License:Open Source License

/**
 * Creates table what contains list of available repositories.
 *
 * @param ideResources/*from   ww  w.  j  a  va  2 s  .  com*/
 */
private void createRepositoriesTable(@Nonnull Resources ideResources) {
    repositories = new CellTable<ProjectData>(15, ideResources);

    Column<ProjectData, ImageResource> iconColumn = new Column<ProjectData, ImageResource>(
            new ImageResourceCell()) {
        @Override
        public ImageResource getValue(ProjectData item) {
            return resources.project();
        }
    };

    Column<ProjectData, SafeHtml> repositoryColumn = new Column<ProjectData, SafeHtml>(new SafeHtmlCell()) {
        @Override
        public SafeHtml getValue(final ProjectData item) {
            return SafeHtmlUtils.fromString(item.getName());
        }
    };

    Column<ProjectData, SafeHtml> descriptionColumn = new Column<ProjectData, SafeHtml>(new SafeHtmlCell()) {
        @Override
        public SafeHtml getValue(final ProjectData item) {
            return new SafeHtmlBuilder().appendHtmlConstant("<span>").appendEscaped(item.getDescription())
                    .appendHtmlConstant("</span>").toSafeHtml();
        }
    };

    repositories.addColumn(iconColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
    repositories.setColumnWidth(iconColumn, 28, Style.Unit.PX);

    repositories.addColumn(repositoryColumn, locale.samplesListRepositoryColumn());
    repositories.addColumn(descriptionColumn, locale.samplesListDescriptionColumn());

    // don't show loading indicator
    repositories.setLoadingIndicator(null);

    final SingleSelectionModel<ProjectData> selectionModel = new SingleSelectionModel<ProjectData>();
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        @Override
        public void onSelectionChange(SelectionChangeEvent event) {
            ProjectData selectedObject = selectionModel.getSelectedObject();
            delegate.onRepositorySelected(selectedObject);
        }
    });
    repositories.setSelectionModel(selectionModel);
}

From source file:com.codenvy.ide.ext.github.client.projectimporter.importerpage.GithubImporterPageViewImpl.java

License:Open Source License

/** Creates table what contains list of available repositories.
 * @param ideResources*///from w  w w.j a  va 2 s  . c om
private void createRepositoriesTable(Resources ideResources) {
    repositories = new CellTable<ProjectData>(15, ideResources);

    Column<ProjectData, ImageResource> iconColumn = new Column<ProjectData, ImageResource>(
            new ImageResourceCell()) {
        @Override
        public ImageResource getValue(ProjectData item) {
            return resources.project();
        }
    };

    Column<ProjectData, SafeHtml> repositoryColumn = new Column<ProjectData, SafeHtml>(new SafeHtmlCell()) {
        @Override
        public SafeHtml getValue(final ProjectData item) {
            return new SafeHtml() {
                public String asString() {
                    return item.getName();
                }
            };
        }
    };

    Column<ProjectData, SafeHtml> descriptionColumn = new Column<ProjectData, SafeHtml>(new SafeHtmlCell()) {
        @Override
        public SafeHtml getValue(final ProjectData item) {
            return new SafeHtml() {
                public String asString() {
                    return "<span>" + item.getDescription() + "</span>";
                }
            };
        }
    };

    repositories.addColumn(iconColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
    repositories.setColumnWidth(iconColumn, 28, Style.Unit.PX);

    repositories.addColumn(repositoryColumn, locale.samplesListRepositoryColumn());
    repositories.addColumn(descriptionColumn, locale.samplesListDescriptionColumn());

    // don't show loading indicator
    repositories.setLoadingIndicator(null);

    final SingleSelectionModel<ProjectData> selectionModel = new SingleSelectionModel<ProjectData>();
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        @Override
        public void onSelectionChange(SelectionChangeEvent event) {
            ProjectData selectedObject = selectionModel.getSelectedObject();
            delegate.onRepositorySelected(selectedObject);
        }
    });
    repositories.setSelectionModel(selectionModel);
}