List of usage examples for com.google.gwt.view.client CellPreviewEvent getNativeEvent
public NativeEvent getNativeEvent()
From source file:org.rstudio.core.client.widget.ModifyKeyboardShortcutsWidget.java
License:Open Source License
private void onNameCellPreview(CellPreviewEvent<KeyboardShortcutEntry> preview) { NativeEvent event = preview.getNativeEvent(); String type = event.getType(); if (type.equals("blur")) { buffer_.clear();// w ww. j a v a2 s.co m } else if (type.equals("keydown")) { int keyCode = event.getKeyCode(); int modifiers = KeyboardShortcut.getModifierValue(event); if (keyCode == KeyCodes.KEY_ESCAPE && modifiers == 0) { event.stopPropagation(); event.preventDefault(); filterWidget_.focus(); } else if (keyCode == KeyCodes.KEY_ENTER && modifiers == 0) { event.stopPropagation(); event.preventDefault(); table_.setKeyboardSelectedColumn(1); } } }
From source file:org.rstudio.core.client.widget.ModifyKeyboardShortcutsWidget.java
License:Open Source License
private void onShortcutCellPreview(CellPreviewEvent<KeyboardShortcutEntry> preview) { NativeEvent event = preview.getNativeEvent(); String type = event.getType(); if (type.equals("keydown")) { int keyCode = event.getKeyCode(); int modifiers = KeyboardShortcut.getModifierValue(event); // Don't handle raw 'Enter' keypresses (let underlying input // widget process) if (keyCode == KeyCodes.KEY_ENTER && modifiers == 0) return; // Handle any other key events. if (modifiers != 0) swallowNextKeyUpEvent_ = true; event.stopPropagation();/*from ww w. ja va2s .c om*/ event.preventDefault(); if (KeyboardHelper.isModifierKey(event.getKeyCode())) return; if (keyCode == KeyCodes.KEY_BACKSPACE && modifiers == 0) { buffer_.pop(); } else if (keyCode == KeyCodes.KEY_DELETE && modifiers == 0) { buffer_.clear(); } else if (keyCode == KeyCodes.KEY_ESCAPE && modifiers == 0) { buffer_.set(preview.getValue().getOriginalKeySequence()); } else { buffer_.add(event); } // Sneak into the element and find the active <input>, then update it. Element el = getElement(table_, preview.getIndex(), preview.getColumn()); Element input = el.getFirstChildElement().getFirstChildElement(); if (input == null) return; assert input.getTagName().toLowerCase().equals("input") : "Failed to find <input> element in table"; String bufferString = buffer_.toString(); input.setAttribute("value", bufferString); input.setInnerHTML(bufferString); // Move the cursor to the end of the selection. DomUtils.setSelectionRange(input, bufferString.length(), bufferString.length()); } }
From source file:us.softoption.proofs.TProofDisplayCellTable.java
License:Open Source License
/************** Selection and Clicks or Touches ************************/ void addSelectionModel() { this.sinkEvents(Event.ONCLICK); //but we want click to toggle selection not require command click for multiple this.addCellPreviewHandler(new CellPreviewEvent.Handler<TProofline>() { public void onCellPreview(CellPreviewEvent<TProofline> event) { String type = event.getNativeEvent().getType(); if (type.equals("click")) { TProofline value = event.getValue(); handleClick(value);/*from ww w. jav a 2 s . c o m*/ event.setCanceled(true); // Window.alert("CLICKED " + value.fLineno); DEBUG } } }); this.setSelectionModel(fSelectionModel, DefaultSelectionEventManager.<TProofline>createCheckboxManager()); /* final Handler<TProofline> selectionEventManager = DefaultSelectionEventManager.createCheckboxManager(); this.setSelectionModel(fSelectionModel,selectionEventManager); Jan 2013 */ /*Google sample code * * // Add a selection model so we can select cells. final SelectionModel<ContactInfo> selectionModel = new MultiSelectionModel<ContactInfo>( ContactDatabase.ContactInfo.KEY_PROVIDER); cellTable.setSelectionModel(selectionModel, DefaultSelectionEventManager.<ContactInfo> createCheckboxManager()); */ // We want multiple selection // final MultiSelectionModel<TProofline> selectionModel = new MultiSelectionModel<TProofline>(); /* this.setSelectionModel(fSelectionModel); fSelectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { public void onSelectionChange(SelectionChangeEvent event) { Set <TProofline> selected = fSelectionModel.getSelectedSet(); if (selected != null) { Window.alert("You selected: " + selected.size()); } } }); */ /* this.addCellPreviewHandler(new CellPreviewEvent.Handler<TProofline>() { public void onCellPreview(CellPreviewEvent<TProofline> event) { String type = event.getNativeEvent().getType(); if (type.equals("click")) { TProofline value=event.getValue(); final Boolean state = !event.getDisplay().getSelectionModel().isSelected(value); event.getDisplay().getSelectionModel().setSelected(value, state); event.setCanceled(true); Window.alert("CLICKED"); } } }); */ /* this.addCellPreviewHandler(new Handler<T>() { @Override public void onCellPreview(final CellPreviewEvent<T> event) { if (BrowserEvents.CLICK.equals(event.getNativeEvent().getType())) { final T value = event.getValue(); final Boolean state = !event.getDisplay().getSelectionModel().isSelected(value); event.getDisplay().getSelectionModel().setSelected(value, state); event.setCanceled(true); } } }); */ }