com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy Java Examples

The following examples show how to use com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TemplateUploadWizard.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * 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
 */
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("355px");
  templateCellList.setVisible(true);
  templateCellList.getElement().getStyle().setOverflowY(Style.Overflow.SCROLL);

  // 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;
}
 
Example #2
Source File: CellTreeNodeView.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Fire an event to the {@link com.google.gwt.cell.client.AbstractCell}.
 *
 * @param event the native event
 */
@SuppressWarnings("unchecked")
protected void fireEventToCell(NativeEvent event) {
  if (parentNodeInfo == null) {
    return;
  }

  Cell<T> parentCell = parentNodeInfo.getCell();
  String eventType = event.getType();
  Element cellParent = getCellParent();
  Object key = getValueKey();
  Context context = new Context(getIndex(), 0, key);
  boolean cellWasEditing = parentCell.isEditing(context, cellParent, value);

  // Update selection.
  boolean isSelectionHandled = parentCell.handlesSelection() || KeyboardSelectionPolicy.BOUND_TO_SELECTION == tree.getKeyboardSelectionPolicy();
  HasData<T> display = (HasData<T>)parentNode.listView;
  CellPreviewEvent<T> previewEvent = CellPreviewEvent.fire(display, event, display, context, value, cellWasEditing, isSelectionHandled);

  // Forward the event to the cell.
  if (previewEvent.isCanceled() || !cellParent.isOrHasChild(Element.as(event.getEventTarget()))) {
    return;
  }
  Set<String> consumedEvents = parentCell.getConsumedEvents();
  if (consumedEvents != null && consumedEvents.contains(eventType)) {
    parentCell.onBrowserEvent(context, cellParent, value, event, parentNodeInfo.getValueUpdater());
    tree.cellIsEditing = parentCell.isEditing(context, cellParent, value);
    if (cellWasEditing && !tree.cellIsEditing) {
      CellBasedWidgetImpl.get().resetFocus(new Scheduler.ScheduledCommand() {
        @Override
        public void execute() {
          tree.setFocus(true);
        }
      });
    }
  }
}
 
Example #3
Source File: CellTreeNodeView.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Select or deselect this node with the keyboard.
 *
 * @param selected   true if selected, false if not
 * @param stealFocus true to steal focus
 */
void setKeyboardSelected(boolean selected, boolean stealFocus) {
  if (tree.isKeyboardSelectionDisabled()) {
    return;
  }

  // Apply the selected style.
  if (!selected || tree.isFocused || stealFocus) {
    setKeyboardSelectedStyle(selected);
  }

  // Make the node focusable or not.
  Element cellParent = getCellParent();
  if (!selected) {
    // Chrome: Elements remain focusable after removing the tabIndex, so set
    // it to -1 first.
    cellParent.setTabIndex(-1);
    cellParent.removeAttribute("tabIndex");
    cellParent.removeAttribute("accessKey");
  }
  else {
    FocusImpl focusImpl = FocusImpl.getFocusImplForWidget();
    focusImpl.setTabIndex(cellParent, tree.getTabIndex());
    char accessKey = tree.getAccessKey();
    if (accessKey != 0) {
      focusImpl.setAccessKey(cellParent, accessKey);
    }
    if (stealFocus && !tree.cellIsEditing) {
      cellParent.focus();
    }
  }

  // Update the selection model.
  if (KeyboardSelectionPolicy.BOUND_TO_SELECTION == tree.getKeyboardSelectionPolicy()) {
    setSelected(selected);
  }
}
 
Example #4
Source File: ToDoView.java    From blog with MIT License 5 votes vote down vote up
public ToDoView() {
	initWidget(uiBinder.createAndBindUi(this));

	// removes the yellow highlight
	todoTable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);

	// add IDs to the elements that have ui:field attributes. This is required because the UiBinder
	// does not permit the addition of ID attributes to elements marked with ui:field.
	// *SIGH*
	mainSection.setId("main");
	clearCompleted.getElement().setId("clear-completed");
	taskText.getElement().setId("new-todo");
	todoStatsContainer.setId("footer");
	toggleAll.setId("toggle-all");
}