List of usage examples for com.google.gwt.view.client SingleSelectionModel SingleSelectionModel
public SingleSelectionModel()
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 w w w. j av a 2s .co m */ 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.java 2s. c o m 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); }
From source file:com.dawg6.gwt.client.widgets.AbstractSearchable.java
License:Open Source License
protected AbstractSearchable(ValueFactory<T> factory, Comparator<T> sorter) { captionPanel = new CaptionPanel("Caption"); initWidget(captionPanel);/*from w w w . j av a2 s . co m*/ VerticalPanel verticalPanel_5 = new VerticalPanel(); captionPanel.setContentWidget(verticalPanel_5); verticalPanel_5.setSize("5cm", "3cm"); HorizontalPanel row = new HorizontalPanel(); row.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); row.setSpacing(5); verticalPanel_5.add(row); Label label = new Label("Filter:"); row.add(label); suggestBox = new TextBox(); row.add(suggestBox); suggestBox.setVisibleLength(20); suggestBox.addKeyUpHandler(new KeyUpHandler() { @Override public void onKeyUp(KeyUpEvent event) { setFilter(); } }); Button button = new Button("Clear"); row.add(button); button.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { suggestBox.setText(""); setFilter(); } }); listBox = new CellList<T>(getCell()); scroll = new ScrollPanel(); scroll.setWidget(listBox); this.list = new Vector<T>(); this.dataProvider = new ListDataProvider<T>(); this.dataProvider.addDataDisplay(listBox); verticalPanel_5.add(scroll); listBox.setPageSize(Integer.MAX_VALUE); listBox.setSize("300px", "300px"); selectionModel = new SingleSelectionModel<T>(); listBox.setSelectionModel(selectionModel); selectionModel.addSelectionChangeHandler(new Handler() { @Override public void onSelectionChange(SelectionChangeEvent event) { selectionChanged(getSelectedValue()); } }); this.factory = factory; this.sorter = sorter; }
From source file:com.dingziran.effective.client.Showcase.java
License:Apache License
/** * This is the entry point method.//ww w . j a v a 2s . com */ public void onModuleLoad() { factory = GWT.create(Factory.class); eventBus = new SimpleEventBus(); factory.initialize(eventBus); // Inject global styles. injectThemeStyleSheet(); images.css().ensureInjected(); // Initialize the constants. ShowcaseConstants constants = GWT.create(ShowcaseConstants.class); // Create the application shell. final SingleSelectionModel<ContentWidget> selectionModel = new SingleSelectionModel<ContentWidget>(); final MainMenuTreeViewModel treeModel = new MainMenuTreeViewModel(constants, selectionModel); Set<ContentWidget> contentWidgets = treeModel.getAllContentWidgets(); shell = new ShowcaseShell(treeModel); RootLayoutPanel.get().add(shell); final CellTree mainMenu = shell.getMainMenu(); /* // Prefetch examples when opening the Category tree nodes. final List<Category> prefetched = new ArrayList<Category>(); mainMenu.addOpenHandler(new OpenHandler<TreeNode>() { public void onOpen(OpenEvent<TreeNode> event) { Object value = event.getTarget().getValue(); if (!(value instanceof Category)) { return; } Category category = (Category) value; if (!prefetched.contains(category)) { prefetched.add(category); Prefetcher.prefetch(category.getSplitPoints()); } } }); // Always prefetch. Prefetcher.start(); */ // Change the history token when a main menu item is selected. selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { public void onSelectionChange(SelectionChangeEvent event) { ContentWidget selected = selectionModel.getSelectedObject(); if (selected != null) { History.newItem(getContentWidgetToken(selected), true); } } }); // Setup a history handler to reselect the associate menu item. final ValueChangeHandler<String> historyHandler = new ValueChangeHandler<String>() { public void onValueChange(ValueChangeEvent<String> event) { // Get the content widget associated with the history token. ContentWidget contentWidget = treeModel.getContentWidgetForToken(event.getValue()); if (contentWidget == null) { return; } // Expand the tree node associated with the content. Category category = treeModel.getCategoryForContentWidget(contentWidget); TreeNode node = mainMenu.getRootTreeNode(); int childCount = node.getChildCount(); for (int i = 0; i < childCount; i++) { if (node.getChildValue(i) == category) { node.setChildOpen(i, true, true); break; } } // Select the node in the tree. selectionModel.setSelected(contentWidget, true); // Display the content widget. displayContentWidget(contentWidget); } }; History.addValueChangeHandler(historyHandler); // Show the initial example. if (History.getToken().length() > 0) { History.fireCurrentHistoryState(); } else { // Use the first token available. TreeNode root = mainMenu.getRootTreeNode(); TreeNode category = root.setChildOpen(0, true); ContentWidget content = (ContentWidget) category.getChildValue(0); selectionModel.setSelected(content, true); } // Generate a site map. createSiteMap(contentWidgets); }
From source file:com.github.gwt.sample.showcase.client.Showcase.java
License:Apache License
public void onModuleLoad() { final SingleSelectionModel<Widget> selectionModel = new SingleSelectionModel<Widget>(); final LeftMenuTreeViewModel treeModel = new LeftMenuTreeViewModel(selectionModel); showCase = new WidgetsShowCase(treeModel); RootLayoutPanel.get().add(showCase); bindHistory(selectionModel, treeModel); showInitialExample(selectionModel);/*from w w w.j a v a 2 s. co m*/ }
From source file:com.github.gwtbootstrap.showcase.client.CellTables.java
License:Apache License
private void initTable(AbstractCellTable<Person> exampleTable, final SimplePager pager, final Pagination pagination) { exampleTable.setEmptyTableWidget(new Label("Please add data.")); TextColumn<Person> idCol = new TextColumn<Person>() { @Override//from w w w . j a v a2 s.c o m public String getValue(Person object) { return String.valueOf(object.getId()); } }; idCol.setSortable(true); exampleTable.addColumn(idCol, "#"); ListHandler<Person> idColHandler = new ListHandler<Person>(dataProvider.getList()); idColHandler.setComparator(idCol, new Comparator<Person>() { @Override public int compare(Person o1, Person o2) { return o1.getId().compareTo(o2.getId()); } }); exampleTable.addColumnSortHandler(idColHandler); exampleTable.getColumnSortList().push(idCol); TextColumn<Person> userNameCol = new TextColumn<Person>() { @Override public String getValue(Person object) { return object.getUserName(); } }; userNameCol.setSortable(true); exampleTable.addColumn(userNameCol, "User Name"); ListHandler<Person> userNameColHandler = new ListHandler<Person>(dataProvider.getList()); userNameColHandler.setComparator(userNameCol, new Comparator<Person>() { @Override public int compare(Person o1, Person o2) { return o1.getUserName().compareTo(o2.getUserName()); } }); exampleTable.addColumnSortHandler(userNameColHandler); TextColumn<Person> ageCol = new TextColumn<Person>() { @Override public String getValue(Person object) { return object.getAge() != null ? String.valueOf(object.getAge()) : ""; } }; ageCol.setSortable(true); exampleTable.addColumn(ageCol, "Age"); ListHandler<Person> ageColHandler = new ListHandler<Person>(dataProvider.getList()); ageColHandler.setComparator(ageCol, new Comparator<Person>() { @Override public int compare(Person o1, Person o2) { if (o2.getAge() == null) { return 1; } if (o1.getAge() == null) { return -1; } return o1.getAge().compareTo(o2.getAge()); } }); exampleTable.addColumnSortHandler(ageColHandler); TextColumn<Person> birthDayCol = new TextColumn<Person>() { @Override public String getValue(Person object) { if (object.getBirthDay() != null) { return DateTimeFormat.getFormat("dd/MM/yyyy").format(object.getBirthDay()); } else { return ""; } } }; exampleTable.addColumn(birthDayCol, "Birth Day"); birthDayCol.setSortable(true); ListHandler<Person> birthDayColHandler = new ListHandler<Person>(dataProvider.getList()); birthDayColHandler.setComparator(birthDayCol, new Comparator<Person>() { @Override public int compare(Person o1, Person o2) { if (o2.getBirthDay() == null) { return 1; } if (o1.getBirthDay() == null) { return -1; } return o1.getBirthDay().compareTo(o2.getBirthDay()); } }); exampleTable.addColumnSortHandler(birthDayColHandler); TextColumn<Person> favoriteCol = new TextColumn<Person>() { @Override public String getValue(Person object) { return object.getFavorite().getDisplayLabel(); } }; favoriteCol.setSortable(true); exampleTable.addColumn(favoriteCol, "Favorite"); ListHandler<Person> favoriteColHandler = new ListHandler<Person>(dataProvider.getList()); favoriteColHandler.setComparator(favoriteCol, new Comparator<Person>() { @Override public int compare(Person o1, Person o2) { return o1.getFavorite().compareTo(o2.getFavorite()); } }); exampleTable.addColumnSortHandler(favoriteColHandler); exampleTable.addRangeChangeHandler(new RangeChangeEvent.Handler() { @Override public void onRangeChange(RangeChangeEvent event) { rebuildPager(pagination, pager); } }); ButtonCell buttonCell = new ButtonCell(IconType.REMOVE, ButtonType.DANGER); final TooltipCellDecorator<String> decorator = new TooltipCellDecorator<String>(buttonCell); decorator.setText("delete row, if click"); Column<Person, String> buttonCol = new Column<Person, String>(decorator) { @Override public String getValue(Person object) { return "delete"; } }; buttonCol.setFieldUpdater(new FieldUpdater<Person, String>() { @Override public void update(int index, Person object, String value) { dataProvider.getList().remove(object); dataProvider.flush(); dataProvider.refresh(); rebuildPager(pagination, pager); rebuildPager(dataGridPagination, dataGridPager); } }); exampleTable.addColumn(buttonCol); final SingleSelectionModel<Person> selectionModel = new SingleSelectionModel<Person>(); selectionModel.addSelectionChangeHandler(new Handler() { @Override public void onSelectionChange(SelectionChangeEvent event) { Person person = selectionModel.getSelectedObject(); CellTables.this.driver.edit(person); } }); exampleTable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.BOUND_TO_SELECTION); exampleTable.setSelectionModel(selectionModel); pager.setDisplay(exampleTable); pagination.clear(); dataProvider.addDataDisplay(exampleTable); }
From source file:com.google.appinventor.client.wizards.ComponentImportWizard.java
License:Open Source License
private CellTable createCompTable() { final SingleSelectionModel<Component> selectionModel = new SingleSelectionModel<Component>(); CellTable<Component> compTable = new CellTable<Component>(); compTable.setSelectionModel(selectionModel); Column<Component, Boolean> checkColumn = new Column<Component, Boolean>(new CheckboxCell(true, false)) { @Override//from w ww . jav a 2 s. c o m public Boolean getValue(Component comp) { return selectionModel.isSelected(comp); } }; Column<Component, String> nameColumn = new Column<Component, String>(new TextCell()) { @Override public String getValue(Component comp) { return comp.getName(); } }; Column<Component, Number> versionColumn = new Column<Component, Number>(new NumberCell()) { @Override public Number getValue(Component comp) { return comp.getVersion(); } }; compTable.addColumn(checkColumn); compTable.addColumn(nameColumn, "Component"); compTable.addColumn(versionColumn, "Version"); return compTable; }
From source file:com.google.gwt.examples.cellview.CellListExample.java
License:Apache License
public void onModuleLoad() { // Create a cell to render each value. TextCell textCell = new TextCell(); // Create a CellList that uses the cell. CellList<String> cellList = new CellList<String>(textCell); cellList.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); // Add a selection model to handle user selection. final SingleSelectionModel<String> selectionModel = new SingleSelectionModel<String>(); cellList.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 w w w . j a va2 s . c o m*/ } }); // 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. cellList.setRowCount(DAYS.size(), true); // Push the data into the widget. cellList.setRowData(0, DAYS); // Add it to the root panel. RootPanel.get().add(cellList); }
From source file:com.google.gwt.examples.cellview.CellTableExample.java
License:Apache License
public void onModuleLoad() { // Create a CellTable. CellTable<Contact> table = new CellTable<Contact>(); table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); // Add a text column to show the name. TextColumn<Contact> nameColumn = new TextColumn<Contact>() { @Override//from w w w .j av a 2s .c o m public String getValue(Contact object) { return object.name; } }; table.addColumn(nameColumn, "Name"); // Add a date column to show the birthday. DateCell dateCell = new DateCell(); Column<Contact, Date> dateColumn = new Column<Contact, Date>(dateCell) { @Override public Date getValue(Contact object) { return object.birthday; } }; table.addColumn(dateColumn, "Birthday"); // 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"); // Add a selection model to handle user selection. final SingleSelectionModel<Contact> selectionModel = new SingleSelectionModel<Contact>(); table.setSelectionModel(selectionModel); selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { public void onSelectionChange(SelectionChangeEvent event) { Contact selected = selectionModel.getSelectedObject(); if (selected != null) { Window.alert("You selected: " + selected.name); } } }); // 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.mobilewebapp.client.desktop.MobileWebAppShellDesktop.java
License:Apache License
/** * Construct a new {@link MobileWebAppShellDesktop}. *//*ww w .j a va 2s. co m*/ public MobileWebAppShellDesktop(EventBus bus, TaskChartPresenter pieChart, final PlaceController placeController, TaskListView taskListView, TaskEditView taskEditView, TaskReadView taskReadView) { // Initialize the main menu. Resources resources = GWT.create(Resources.class); mainMenu = new CellList<MainMenuItem>(new MainMenuItem.Cell(), resources); mainMenu.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED); // We don't expect to have more than 30 menu items. mainMenu.setVisibleRange(0, 30); // Add items to the main menu. final List<MainMenuItem> menuItems = new ArrayList<MainMenuItem>(); menuItems.add(new MainMenuItem("Task List", new TaskListPlace(false)) { @Override public boolean mapsToPlace(Place p) { // Map to all TaskListPlace instances. return p instanceof TaskListPlace; } }); menuItems.add(new MainMenuItem("Add Task", TaskPlace.getTaskCreatePlace())); mainMenu.setRowData(menuItems); // Choose a place when a menu item is selected. final SingleSelectionModel<MainMenuItem> selectionModel = new SingleSelectionModel<MainMenuItem>(); selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { public void onSelectionChange(SelectionChangeEvent event) { MainMenuItem selected = selectionModel.getSelectedObject(); if (selected != null && !selected.mapsToPlace(placeController.getWhere())) { placeController.goTo(selected.getPlace()); } } }); mainMenu.setSelectionModel(selectionModel); // Update selection based on the current place. bus.addHandler(PlaceChangeEvent.TYPE, new PlaceChangeEvent.Handler() { public void onPlaceChange(PlaceChangeEvent event) { Place place = event.getNewPlace(); for (MainMenuItem menuItem : menuItems) { if (menuItem.mapsToPlace(place)) { // We found a match in the main menu. selectionModel.setSelected(menuItem, true); return; } } // We didn't find a match in the main menu. selectionModel.setSelected(null, true); } }); // Initialize this widget. initWidget(uiBinder.createAndBindUi(this)); // Initialize the pie chart. String chartUrlValue = Window.Location.getParameter(CHART_URL_ATTRIBUTE); if (chartUrlValue != null && chartUrlValue.startsWith("f")) { // Chart manually disabled. leftNav.remove(1); // Pie Chart. leftNav.remove(0); // Pie chart legend. } else if (pieChart == null) { // Chart not supported. pieChartContainer.setWidget(new Label("Try upgrading to a modern browser to enable charts.")); } else { // Chart supported. Widget pieWidget = pieChart.asWidget(); pieWidget.setWidth("90%"); pieWidget.setHeight("90%"); pieWidget.getElement().getStyle().setMarginLeft(5.0, Unit.PCT); pieWidget.getElement().getStyle().setMarginTop(5.0, Unit.PCT); pieChartContainer.setWidget(pieChart); } /* * Add all views to the DeckLayoutPanel so we can animate between them. * Using a DeckLayoutPanel here works because we only have a few views, and * we always know that the task views should animate in from the right side * of the screen. A more complex app will require more complex logic to * figure out which direction to animate. */ contentContainer.add(taskListView); contentContainer.add(taskReadView); contentContainer.add(taskEditView); contentContainer.setAnimationDuration(800); // Show a tutorial when the help link is clicked. helpLink.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { showTutorial(); } }); }