List of usage examples for com.google.gwt.view.client SingleSelectionModel getSelectedObject
public T getSelectedObject()
From source file:com.dingziran.effective.client.Showcase.java
License:Apache License
/** * This is the entry point method.//from w w w .ja 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
private void bindHistory(final SingleSelectionModel<Widget> selectionModel, final LeftMenuTreeViewModel treeModel) { // Setup a history handler to reselect the associate menu item. final CellTree mainMenu = showCase.getMainMenu(); // Change the history token when a main menu item is selected. selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { public void onSelectionChange(SelectionChangeEvent event) { Widget selected = selectionModel.getSelectedObject(); if (selected != null) { History.newItem(selected.getTitle(), true); }/* www . java 2s . com*/ } }); final ValueChangeHandler<String> historyHandler = new ValueChangeHandler<String>() { public void onValueChange(ValueChangeEvent<String> event) { // Get the content widget associated with the history token. Widget contentWidget = treeModel.getWidget(event.getValue()); if (contentWidget == null) { return; } // Expand the tree node associated with the content. LeftMenuTreeViewModel.Category category = treeModel.getCategoryForWidget(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); } /** * Set the content to the {@link com.google.gwt.user.client.ui.Widget}. * * @param content the {@link com.google.gwt.user.client.ui.Widget} to display */ private void displayContentWidget(Widget content) { if (content == null) { return; } showCase.setContent(content); Window.setTitle("Showcase of Features: " + content.getTitle()); } }; History.addValueChangeHandler(historyHandler); }
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 va 2 s. c om*/ 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.goodow.web.dev.client.ui.TreeNodeListView.java
License:Apache License
@Inject TreeNodeListView(final TreeNodeFactory f, final SingleSelectionModel<TreeNodeProxy> selectionModel, final PlaceController placeController, final Provider<BasePlace> place, final TreeNodeDataProvider dtatProvider) { this.placeController = placeController; this.place = place; this.dtatProvider = dtatProvider; this.f = f;/*from w w w . ja v a 2s.com*/ grid = new DataGrid<TreeNodeProxy>(NUM_ROWS, GWT.<TableResources>create(TableResources.class)); grid.setSelectionModel(selectionModel); grid.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED); PathCol pathCol = new PathCol(); // ????? pathCol.setName("path"); pathCol.setSortable(true); grid.addColumn(pathCol, "Path"); grid.setColumnWidth(pathCol, "40ex"); NameCol nameCol = new NameCol(); nameCol.setName("name"); nameCol.setSortable(true); grid.addColumn(nameCol, "Name"); grid.setColumnWidth(nameCol, "25ex"); grid.addColumnSortHandler(new ColumnSortEvent.AsyncHandler(grid)); grid.setRowCount(NUM_ROWS, false); dtatProvider.addDataDisplay(grid); pager.setDisplay(grid); selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { @Override public void onSelectionChange(final SelectionChangeEvent event) { TreeNodeProxy proxy = selectionModel.getSelectedObject(); BasePlace newPlace = place.get().setParameter(state.getName(), f.getHistoryToken(proxy.stableId())); placeController.goTo(newPlace); } }); initWidget(binder.createAndBindUi(this)); }
From source file:com.goodow.web.ui.client.nav.TagsUi.java
License:Apache License
@Inject private TagsUi(final NavTreeViewModel treeViewModel, final SingleSelectionModel<com.goodow.web.mvp.shared.tree.TreeNodeProxy> selectionModel, final Resources resources, final PlaceController placeController, final Provider<TreeNodePlace> placeProvider) { this.placeController = placeController; logger.finest("init start"); this.treeViewModel = treeViewModel; this.selectionModel = selectionModel; this.resources = resources; // Listen for selection. We need to add this handler before the CellBrowser // adds its own handler. this.selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { @Override/*from ww w. ja va2s . c o m*/ public void onSelectionChange(final SelectionChangeEvent event) { com.goodow.web.mvp.shared.tree.TreeNodeProxy lastSelected = selectionModel.getSelectedObject(); TreeNodePlace place = placeProvider.get().setPath(lastSelected.getPath()); if (!place.equals(placeController.getWhere())) { placeController.goTo(place); } } }); initWidget(layout); if (LogConfiguration.loggingIsEnabled()) { logger.log(Level.FINEST, "init end"); } }
From source file:com.google.appinventor.client.wizards.TemplateUploadWizard.java
License:Open Source License
/** * Creates the scrollable list of cells each of which serves as a link to a template. * * @param list an ArrayList of TemplateInfo * @return A CellList widget//from w ww . java 2s. com */ public CellList<TemplateInfo> makeTemplateSelector(ArrayList<TemplateInfo> list) { TemplateCell templateCell = new TemplateCell(list.get(0), templateHostUrl); CellList<TemplateInfo> templateCellList = new CellList<TemplateInfo>(templateCell, TemplateInfo.KEY_PROVIDER); templateCellList.setPageSize(list.size() + 10); templateCellList.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); templateCellList.setWidth("250px"); templateCellList.setHeight("400px"); templateCellList.setVisible(true); // Add a selection model to handle user selection. final SingleSelectionModel<TemplateInfo> selectionModel = new SingleSelectionModel<TemplateInfo>( TemplateInfo.KEY_PROVIDER); templateCellList.setSelectionModel(selectionModel); selectionModel.setSelected(list.get(0), true); final TemplateUploadWizard wizard = this; selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { public void onSelectionChange(SelectionChangeEvent event) { TemplateInfo selected = selectionModel.getSelectedObject(); if (selected != null) { selectedTemplateNAME = selected.name; TemplateWidget.setTemplate(selected, wizard.getTemplateUrlHost()); } } }); // 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. templateCellList.setRowCount(list.size(), true); // Push the data into the widget. templateCellList.setRowData(0, list); return templateCellList; }
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 www.ja v a 2 s . co 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 a v a 2s .c om*/ 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}. *//*from w ww . ja va2 s .c om*/ 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(); } }); }
From source file:com.google.gwt.sample.showcase.client.content.cell.CwCellList.java
License:Apache License
/** * Initialize this example.//from www . j a v a2s .c o m */ @ShowcaseSource @Override public Widget onInitialize() { Images images = GWT.create(Images.class); // Create a CellList. ContactCell contactCell = new ContactCell(images.contact()); // 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. cellList = new CellList<ContactInfo>(contactCell, ContactDatabase.ContactInfo.KEY_PROVIDER); cellList.setPageSize(30); cellList.setKeyboardPagingPolicy(KeyboardPagingPolicy.INCREASE_RANGE); cellList.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.BOUND_TO_SELECTION); // Add a selection model so we can select cells. final SingleSelectionModel<ContactInfo> selectionModel = new SingleSelectionModel<ContactInfo>( ContactDatabase.ContactInfo.KEY_PROVIDER); cellList.setSelectionModel(selectionModel); selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { public void onSelectionChange(SelectionChangeEvent event) { contactForm.setContact(selectionModel.getSelectedObject()); } }); // Create the UiBinder. Binder uiBinder = GWT.create(Binder.class); Widget widget = uiBinder.createAndBindUi(this); // Add the CellList to the data provider in the database. ContactDatabase.get().addDataDisplay(cellList); // Set the cellList as the display of the pagers. This example has two // 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); rangeLabelPager.setDisplay(cellList); // Handle events from the generate button. generateButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { ContactDatabase.get().generateContacts(50); } }); return widget; }