List of usage examples for com.google.gwt.view.client SingleSelectionModel getSelectedObject
public T getSelectedObject()
From source file:com.google.gwt.sample.showcase.client.Showcase.java
License:Apache License
/** * This is the entry point method./*w w w . j a va 2s . co m*/ */ public void onModuleLoad() { // Generate the source code and css for the examples GWT.create(GeneratorInfo.class); // 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); // Prefetch examples when opening the Category tree nodes. final List<Category> prefetched = new ArrayList<Category>(); final CellTree mainMenu = shell.getMainMenu(); 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.google.gwt.sample.stockwatcher.client.Cells.java
private Widget createCellList() { TextCell textCell = new TextCell(); CellList<String> cellList = new CellList<>(textCell); final List<String> DAYS = Arrays.asList("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); /*// w w w . ja v a 2 s .c om * Selection Model */ 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() { @Override public void onSelectionChange(SelectionChangeEvent event) { String selected = selectionModel.getSelectedObject(); if (selected != null) { Window.alert("You selected: " + selected); } } }); /* * Value updater */ // cellList.setValueUpdater(new ValueUpdater<String>() { // @Override // public void update(String value) { // Window.alert("New Value: " + value); // } // }); // 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); cellList.setRowData(0, DAYS); // Create a SimplePager. SimplePager pager = new SimplePager(); // Set the cellList as the display. pager.setDisplay(cellList); // Add the pager and list to the page. VerticalPanel vPanel = new VerticalPanel(); vPanel.add(pager); vPanel.add(cellList); return vPanel; }
From source file:com.gsr.myschool.back.client.web.application.settings.popup.NiveauEtudeInfosView.java
License:Apache License
private void initializeEvents() { final SingleSelectionModel<PieceJustifProxy> pieceModel = new SingleSelectionModel<PieceJustifProxy>(); pieceJustifList.setSelectionModel(pieceModel); pieceModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { public void onSelectionChange(SelectionChangeEvent event) { pieceEditor.edit(getUiHandlers().loadPiece(pieceModel.getSelectedObject())); }//from w ww .j a v a 2 s .c om }); final SingleSelectionModel<MatiereExamenProxy> matiereModel = new SingleSelectionModel<MatiereExamenProxy>(); matiereExamenList.setSelectionModel(matiereModel); matiereModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { public void onSelectionChange(SelectionChangeEvent event) { matiereEditor.edit(getUiHandlers().loadMatiere(matiereModel.getSelectedObject())); } }); pieceEditor.initSuggestions(); matiereEditor.initSuggestions(); }
From source file:com.gwt2go.dev.client.ui.table.DataGridImpl1.java
License:Apache License
public DataGridImpl1() { // Create a CellTable. DataGrid<Contact> table = new DataGrid<Contact>(); table.setWidth("100%"); table.setHeight("100px"); // table.setRowStyles(new RowStyles<DataGridImpl1.Contact>() { // @Override // public String getStyleNames(Contact row, int rowIndex) { // return "headcol"; // }/*from www. ja v a 2 s . c om*/ // }); table.setEmptyTableWidget(new Label("No Information to show")); table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); // Add a text column to show the name. TextColumn<Contact> nameColumn = new TextColumn<Contact>() { @Override 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); // -- END TABLE // viewPanel.getElement().appendChild(nameSpan); viewPanel.add(table); viewPanel.setSize("30em", "10em"); initWidget(viewPanel); }
From source file:com.java33.vizpres.client.view.visualization.CellViz.java
License:Open Source License
/** * Create a {@link CellList} instance using a custom factory method. The custom * factory is required because a CellList must be constructed using an * instance of its cell type./*w ww .j a v a2s. c o m*/ * * @return Returns a CellList that uses {@link BarCell} for rendering values. */ @UiFactory CellList<PercentValue> makeCellList() { // Create a CellList using the custom BarCell class for rendering and interaction handling. final CellList<PercentValue> cellList = new CellList<PercentValue>(new BarCell()); cellList.setWidth(width); cellList.setHeight(height); final SingleSelectionModel<PercentValue> selectionModel = new SingleSelectionModel<PercentValue>(); cellList.setSelectionModel(selectionModel); selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { public void onSelectionChange(SelectionChangeEvent event) { final PercentValue selectedObject = selectionModel.getSelectedObject(); if (selectedObject != null) { infoLabel.setText("You selected: " + Integer.toString(selectedObject.percentage)); } } }); return cellList; }
From source file:com.moesol.gwt.maps.client.tms.TileMapServiceListView.java
License:Open Source License
public TileMapServiceListView() { initWidget(binder.createAndBindUi(this)); Cell<TileMapMetadata> cell = new AbstractCell<TileMapMetadata>() { @Override/* w ww . j ava 2 s . co m*/ public void render(com.google.gwt.cell.client.Cell.Context ctx, TileMapMetadata value, SafeHtmlBuilder sb) { sb.appendEscaped(value.getTitle()); sb.appendEscaped(" ("); sb.appendEscaped(value.getSrs()); sb.appendEscaped(", "); sb.appendEscaped(value.getTileImageFormat()); sb.appendEscaped(")"); } }; ListResources listResources = GWT.create(ListResources.class); ProvidesKey<TileMapMetadata> keyProvider = new ProvidesKey<TileMapMetadata>() { @Override public Object getKey(TileMapMetadata item) { return item.getUrl(); } }; availableList = new CellList<TileMapMetadata>(cell, listResources, keyProvider); final SingleSelectionModel<TileMapMetadata> availableSelectionModel = new SingleSelectionModel<TileMapMetadata>(); availableSelectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { @Override public void onSelectionChange(SelectionChangeEvent event) { presenter.onAvailableSelected(availableSelectionModel.getSelectedObject()); } }); availableList.setSelectionModel(availableSelectionModel); availableListData.addDataDisplay(availableList); availableList.setHeight("100%"); availableList.setWidth("200px"); leftScrollPanel.add(availableList); displayedList = new CellList<TileMapMetadata>(cell, listResources, keyProvider); displayedList.setHeight("100%"); displayedList.setWidth("200px"); final SingleSelectionModel<TileMapMetadata> displayedSelectionModel = new SingleSelectionModel<TileMapMetadata>(); displayedSelectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { @Override public void onSelectionChange(SelectionChangeEvent event) { presenter.onDisplayedSelected(displayedSelectionModel.getSelectedObject()); } }); displayedList.setSelectionModel(displayedSelectionModel); displayedListData.addDataDisplay(displayedList); rightScrollPanel.add(displayedList); }
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/*ww w . j av a2 s .com*/ 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.sensia.tools.client.swetools.editors.sensorml.panels.widgets.swe.dataarray.GenericTable.java
License:Open Source License
/** * Creates the table.// w w w.j a va 2 s.com * * @return the panel */ public Panel createTable() { if (table == null) { table = new CellTable<Property>(10, tableRes); table.setStyleName("ontology-table-result"); dataProvider.addDataDisplay(table); table.setSkipRowHoverCheck(true); table.setSkipRowHoverFloatElementCheck(true); table.setSkipRowHoverStyleUpdate(true); table.setVisibleRange(0, 100000); // Add a selection model to handle user selection. final SingleSelectionModel<Property> selectionModel = new SingleSelectionModel<Property>(); table.setSelectionModel(selectionModel); selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { public void onSelectionChange(SelectionChangeEvent event) { Property selected = selectionModel.getSelectedObject(); if (selected != null) { selectedProperty = selected; } } }); } VerticalPanel vPanel = new VerticalPanel(); final TextBox searchBox = new TextBox(); HorizontalPanel hPanel = new HorizontalPanel(); hPanel.add(new HTML("Search :" + SensorConstants.HTML_SPACE + SensorConstants.HTML_SPACE)); hPanel.add(searchBox); ScrollPanel sPanel = new ScrollPanel(); sPanel.setStyleName("ontology-table-panel"); sPanel.add(table); vPanel.add(hPanel); vPanel.add(sPanel); //add key listener on searchBox searchBox.addKeyUpHandler(new KeyUpHandler() { @Override public void onKeyUp(KeyUpEvent event) { setFilter(searchBox.getText()); } }); return vPanel; }
From source file:com.tasktop.c2c.server.profile.web.ui.client.view.components.AdminProfileView.java
License:Open Source License
private void setupList() { profileList.setPageSize(10);//from ww w . j av a 2 s . c om profileList.setKeyboardPagingPolicy(KeyboardPagingPolicy.CHANGE_PAGE); profileList.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.BOUND_TO_SELECTION); final SingleSelectionModel<Profile> selectionModel = new SingleSelectionModel<Profile>(); profileList.setSelectionModel(selectionModel); selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { public void onSelectionChange(SelectionChangeEvent event) { setSelectedProfile(selectionModel.getSelectedObject()); } }); dataProvider.addDataDisplay(profileList); pager.setDisplay(profileList); }
From source file:com.tasktop.c2c.server.tasks.client.widgets.admin.customfields.CustomFieldsMenu.java
License:Open Source License
private CustomFieldsMenu() { fieldList = new CellList<FieldDescriptor>(new FieldCell(), resources); final SingleSelectionModel<FieldDescriptor> selectionModel = new SingleSelectionModel<FieldDescriptor>(); selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { @Override/*from w ww .j a va 2 s .c o m*/ public void onSelectionChange(SelectionChangeEvent event) { if (selectionModel.getSelectedObject() != null) { presenter.edit(selectionModel.getSelectedObject()); } } }); fieldList.setSelectionModel(selectionModel); initWidget(ourUiBinder.createAndBindUi(this)); }