List of usage examples for com.google.gwt.view.client CellPreviewEvent setCanceled
public void setCanceled(boolean cancel)
From source file:com.google.gwt.sample.showcase.client.content.cell.CustomKeyboardHandler.java
void cancelEvent(CellPreviewEvent<ContactInfo> event) { event.setCanceled(true); event.getNativeEvent().preventDefault(); }
From source file:org.gss_project.gss.web.client.GSSSelectionEventManager.java
License:Open Source License
/** * Handle an event that could cause a value to be selected for a * {@link MultiSelectionModel}. This overloaded method adds support for both * the control and shift keys. If the shift key is held down, all rows between * the previous selected row and the current row are selected. * /* w ww . ja v a2 s . c o m*/ * @param event the {@link CellPreviewEvent} that triggered selection * @param action the action to handle * @param selectionModel the {@link SelectionModel} to update */ protected void handleMultiSelectionEvent(CellPreviewEvent<T> event, SelectAction action, MultiSelectionModel<? super T> selectionModel) { NativeEvent nativeEvent = event.getNativeEvent(); String type = nativeEvent.getType(); boolean rightclick = "mousedown".equals(type) && nativeEvent.getButton() == NativeEvent.BUTTON_RIGHT; if (rightclick) { boolean shift = nativeEvent.getShiftKey(); boolean ctrlOrMeta = nativeEvent.getCtrlKey() || nativeEvent.getMetaKey(); boolean clearOthers = (translator == null) ? !ctrlOrMeta : translator.clearCurrentSelection(event); if (action == null || action == SelectAction.DEFAULT) { action = ctrlOrMeta ? SelectAction.TOGGLE : SelectAction.SELECT; } //if the row is selected then do nothing if (selectionModel.isSelected(event.getValue())) { return; } doMultiSelection(selectionModel, event.getDisplay(), event.getIndex(), event.getValue(), action, shift, clearOthers); } else if ("click".equals(type)) { /* * Update selection on click. Selection is toggled only if the user * presses the ctrl key. If the user does not press the control key, * selection is additive. */ boolean shift = nativeEvent.getShiftKey(); boolean ctrlOrMeta = nativeEvent.getCtrlKey() || nativeEvent.getMetaKey(); boolean clearOthers = (translator == null) ? !ctrlOrMeta : translator.clearCurrentSelection(event); if (action == null || action == SelectAction.DEFAULT) { action = ctrlOrMeta ? SelectAction.TOGGLE : SelectAction.SELECT; } doMultiSelection(selectionModel, event.getDisplay(), event.getIndex(), event.getValue(), action, shift, clearOthers); if (ctrlOrMeta) { event.setCanceled(true); } } else if ("keyup".equals(type)) { int keyCode = nativeEvent.getKeyCode(); if (keyCode == 32) { /* * Update selection when the space bar is pressed. The spacebar always * toggles selection, regardless of whether the control key is pressed. */ boolean shift = nativeEvent.getShiftKey(); boolean clearOthers = (translator == null) ? false : translator.clearCurrentSelection(event); if (action == null || action == SelectAction.DEFAULT) { action = SelectAction.TOGGLE; } doMultiSelection(selectionModel, event.getDisplay(), event.getIndex(), event.getValue(), action, shift, clearOthers); } } }
From source file:org.rstudio.studio.client.workbench.views.source.editors.explorer.view.ObjectExplorerDataGrid.java
License:Open Source License
@Override public void onCellPreview(CellPreviewEvent<Data> preview) { Event event = Event.getCurrentEvent(); int code = event.getKeyCode(); int type = event.getTypeInt(); int row = getKeyboardSelectedRow(); boolean isDefault = false; if (type == Event.ONKEYDOWN || type == Event.ONKEYPRESS) { switch (code) { case KeyCodes.KEY_UP: selectRowRelative(-1);//from ww w . j av a 2 s .c o m break; case KeyCodes.KEY_DOWN: selectRowRelative(+1); break; case KeyCodes.KEY_PAGEUP: selectRowRelative(-10); break; case KeyCodes.KEY_PAGEDOWN: selectRowRelative(+10); break; case KeyCodes.KEY_LEFT: selectParentOrClose(row); break; case KeyCodes.KEY_RIGHT: selectChildOrOpen(row); break; default: isDefault = true; break; } } else if (type == Event.ONKEYUP) { switch (code) { case KeyCodes.KEY_ENTER: case KeyCodes.KEY_SPACE: toggleExpansion(row); break; default: isDefault = true; break; } } else { isDefault = true; } // eat any non-default handled events if (!isDefault) { preview.setCanceled(true); event.stopPropagation(); event.preventDefault(); } }
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);/* w w w. j a v a2 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); } } }); */ }