List of usage examples for com.google.gwt.dom.client BrowserEvents MOUSEDOWN
String MOUSEDOWN
To view the source code for com.google.gwt.dom.client BrowserEvents MOUSEDOWN.
Click Source Link
From source file:com.bearsoft.gwt.ui.widgets.grid.cells.TreeExpandableCell.java
@Override public Set<String> getConsumedEvents() { if (visible) { if (treeProvider != null) { Set<String> consumed = new HashSet<>(); consumed.addAll(cell.getConsumedEvents()); consumed.add(BrowserEvents.MOUSEDOWN); return consumed; } else {/*from w w w . j ava2 s . c o m*/ return cell.getConsumedEvents(); } } else { return null; } }
From source file:com.bearsoft.gwt.ui.widgets.grid.cells.TreeExpandableCell.java
@Override protected void onNonCellBrowserEvent(Cell.Context context, Element parent, C value, NativeEvent event, ValueUpdater<C> valueUpdater) { if (treeProvider != null) { if (BrowserEvents.MOUSEDOWN.equals(event.getType())) { T toBeToggled = treeProvider.getList().get(context.getIndex()); treeProvider.getList().set(context.getIndex(), toBeToggled); if (isExpanded(context)) { treeProvider.collapse(toBeToggled); } else { treeProvider.expand(toBeToggled); }//from w ww .j a v a 2 s . co m } else if (cell.getConsumedEvents().contains(event.getType())) { cell.onBrowserEvent(context, getCellParent(parent), value, event, valueUpdater); } } }
From source file:com.vaadin.client.widget.grid.selection.MultiSelectionRenderer.java
License:Apache License
@Override public CheckBox createWidget() { final CheckBox checkBox = GWT.create(CheckBox.class); checkBox.setStylePrimaryName(grid.getStylePrimaryName() + SELECTION_CHECKBOX_CLASSNAME); CheckBoxEventHandler handler = new CheckBoxEventHandler(checkBox); // Sink events checkBox.sinkBitlessEvent(BrowserEvents.MOUSEDOWN); checkBox.sinkBitlessEvent(BrowserEvents.TOUCHSTART); checkBox.sinkBitlessEvent(BrowserEvents.CLICK); // Add handlers checkBox.addMouseDownHandler(handler); checkBox.addTouchStartHandler(handler); checkBox.addClickHandler(handler);//from ww w . j a v a 2 s . c om return checkBox; }
From source file:com.vaadin.client.widget.grid.selection.MultiSelectionRenderer.java
License:Apache License
@Override public Collection<String> getConsumedEvents() { final HashSet<String> events = new HashSet<String>(); /*/*from w w w.jav a2 s . co m*/ * this column's first interest is only to attach a NativePreventHandler * that does all the magic. These events are the beginning of that * cycle. */ events.add(BrowserEvents.MOUSEDOWN); events.add(BrowserEvents.TOUCHSTART); return events; }
From source file:com.vaadin.client.widget.grid.selection.MultiSelectionRenderer.java
License:Apache License
@Override public boolean onBrowserEvent(final CellReference<?> cell, final NativeEvent event) { if (BrowserEvents.TOUCHSTART.equals(event.getType()) || (BrowserEvents.MOUSEDOWN.equals(event.getType()) && event.getButton() == NativeEvent.BUTTON_LEFT)) { startDragSelect(event, Element.as(event.getEventTarget())); return true; } else {/*from w w w . j a v a 2 s. co m*/ throw new IllegalStateException("received unexpected event: " + event.getType()); } }
From source file:com.vaadin.client.widgets.Grid.java
License:Apache License
/** * Creates a new instance./*from w w w .jav a 2 s. c om*/ */ public Grid() { initWidget(escalator); getElement().setTabIndex(0); cellFocusHandler = new CellFocusHandler(); setStylePrimaryName(STYLE_NAME); escalator.getHeader().setEscalatorUpdater(createHeaderUpdater()); escalator.getBody().setEscalatorUpdater(createBodyUpdater()); escalator.getFooter().setEscalatorUpdater(createFooterUpdater()); header.setGrid(this); HeaderRow defaultRow = header.appendRow(); header.setDefaultRow(defaultRow); footer.setGrid(this); editor.setGrid(this); setSelectionMode(SelectionMode.SINGLE); escalator.getBody().setSpacerUpdater(gridSpacerUpdater); escalator.addScrollHandler(new ScrollHandler() { @Override public void onScroll(ScrollEvent event) { fireEvent(new ScrollEvent()); } }); escalator.addRowVisibilityChangeHandler(new RowVisibilityChangeHandler() { @Override public void onRowVisibilityChange(RowVisibilityChangeEvent event) { if (dataSource != null && dataSource.size() != 0) { dataIsBeingFetched = true; dataSource.ensureAvailability(event.getFirstVisibleRow(), event.getVisibleRowCount()); } } }); // Default action on SelectionEvents. Refresh the body so changed // become visible. addSelectionHandler(new SelectionHandler<T>() { @Override public void onSelect(SelectionEvent<T> event) { refreshBody(); } }); // Sink header events and key events sinkEvents(getHeader().getConsumedEvents()); sinkEvents(Arrays.asList(BrowserEvents.KEYDOWN, BrowserEvents.KEYUP, BrowserEvents.KEYPRESS, BrowserEvents.DBLCLICK, BrowserEvents.MOUSEDOWN, BrowserEvents.CLICK)); // Make ENTER and SHIFT+ENTER in the header perform sorting addHeaderKeyUpHandler(new HeaderKeyUpHandler() { @Override public void onKeyUp(GridKeyUpEvent event) { if (event.getNativeKeyCode() != KeyCodes.KEY_ENTER) { return; } if (getHeader().getRow(event.getFocusedCell().getRowIndex()).isDefault()) { // Only sort for enter on the default header sorter.sort(event.getFocusedCell().getColumn(), event.isShiftKeyDown()); } } }); addDataAvailableHandler(new DataAvailableHandler() { @Override public void onDataAvailable(DataAvailableEvent event) { dataIsBeingFetched = false; } }); }
From source file:com.vaadin.client.widgets.Grid.java
License:Apache License
@Override public void onBrowserEvent(Event event) { if (!isEnabled()) { return;/*from w ww. jav a2s . c o m*/ } String eventType = event.getType(); if (eventType.equals(BrowserEvents.FOCUS) || eventType.equals(BrowserEvents.BLUR)) { super.onBrowserEvent(event); return; } EventTarget target = event.getEventTarget(); if (!Element.is(target) || isOrContainsInSpacer(Element.as(target))) { return; } Element e = Element.as(target); RowContainer container = escalator.findRowContainer(e); Cell cell; if (container == null) { if (eventType.equals(BrowserEvents.KEYDOWN) || eventType.equals(BrowserEvents.KEYUP) || eventType.equals(BrowserEvents.KEYPRESS)) { cell = cellFocusHandler.getFocusedCell(); container = cellFocusHandler.containerWithFocus; } else { // Click might be in an editor cell, should still map. if (editor.editorOverlay != null && editor.editorOverlay.isOrHasChild(e)) { container = escalator.getBody(); int rowIndex = editor.getRow(); int colIndex = editor.getElementColumn(e); if (colIndex < 0) { // Click in editor, but not for any column. return; } TableCellElement cellElement = container.getRowElement(rowIndex).getCells().getItem(colIndex); cell = new Cell(rowIndex, colIndex, cellElement); } else { if (escalator.getElement().isOrHasChild(e)) { eventCell.set(new Cell(-1, -1, null), Section.BODY); // Fire native events. super.onBrowserEvent(event); } return; } } } else { cell = container.getCell(e); if (eventType.equals(BrowserEvents.MOUSEDOWN)) { cellOnPrevMouseDown = cell; } else if (cell == null && eventType.equals(BrowserEvents.CLICK)) { /* * Chrome has an interesting idea on click targets (see * cellOnPrevMouseDown javadoc). Firefox, on the other hand, has * the mousedown target as the click target. */ cell = cellOnPrevMouseDown; } } assert cell != null : "received " + eventType + "-event with a null cell target"; eventCell.set(cell, getSectionFromContainer(container)); // Editor can steal focus from Grid and is still handled if (isEditorEnabled() && handleEditorEvent(event, container)) { return; } // Fire GridKeyEvents and GridClickEvents. Pass the event to escalator. super.onBrowserEvent(event); if (!isElementInChildWidget(e)) { if (handleHeaderCellDragStartEvent(event, container)) { return; } // Sorting through header Click / KeyUp if (handleHeaderDefaultRowEvent(event, container)) { return; } if (handleRendererEvent(event, container)) { return; } if (handleCellFocusEvent(event, container)) { return; } } }
From source file:com.vaadin.client.widgets.Grid.java
License:Apache License
private boolean handleHeaderDefaultRowEvent(Event event, RowContainer container) { if (container != escalator.getHeader()) { return false; }//from w ww .j av a2 s . c o m if (!getHeader().getRow(eventCell.getRowIndex()).isDefault()) { return false; } if (!eventCell.getColumn().isSortable()) { // Only handle sorting events if the column is sortable return false; } if (BrowserEvents.MOUSEDOWN.equals(event.getType()) && event.getShiftKey()) { // Don't select text when shift clicking on a header. event.preventDefault(); } if (BrowserEvents.TOUCHSTART.equals(event.getType())) { if (event.getTouches().length() > 1) { return false; } event.preventDefault(); Touch touch = event.getChangedTouches().get(0); rowEventTouchStartingPoint = new Point(touch.getClientX(), touch.getClientY()); sorter.sortAfterDelay(GridConstants.LONG_TAP_DELAY, true); return true; } else if (BrowserEvents.TOUCHMOVE.equals(event.getType())) { if (event.getTouches().length() > 1) { return false; } event.preventDefault(); Touch touch = event.getChangedTouches().get(0); double diffX = Math.abs(touch.getClientX() - rowEventTouchStartingPoint.getX()); double diffY = Math.abs(touch.getClientY() - rowEventTouchStartingPoint.getY()); // Cancel long tap if finger strays too far from // starting point if (diffX > GridConstants.LONG_TAP_THRESHOLD || diffY > GridConstants.LONG_TAP_THRESHOLD) { sorter.cancelDelayedSort(); } return true; } else if (BrowserEvents.TOUCHEND.equals(event.getType())) { if (event.getTouches().length() > 1) { return false; } if (sorter.isDelayedSortScheduled()) { // Not a long tap yet, perform single sort sorter.cancelDelayedSort(); sorter.sort(eventCell.getColumn(), false); } return true; } else if (BrowserEvents.TOUCHCANCEL.equals(event.getType())) { if (event.getTouches().length() > 1) { return false; } sorter.cancelDelayedSort(); return true; } else if (BrowserEvents.CLICK.equals(event.getType())) { sorter.sort(eventCell.getColumn(), event.getShiftKey()); // Click events should go onward to cell focus logic return false; } else { return false; } }
From source file:com.vaadin.v7.client.widget.grid.selection.MultiSelectionRenderer.java
License:Apache License
@Override public CheckBox createWidget() { final CheckBox checkBox = GWT.create(CheckBox.class); checkBox.setStylePrimaryName(grid.getStylePrimaryName() + SELECTION_CHECKBOX_CLASSNAME); CheckBoxEventHandler handler = new CheckBoxEventHandler(checkBox); // Sink events checkBox.sinkBitlessEvent(BrowserEvents.MOUSEDOWN); checkBox.sinkBitlessEvent(BrowserEvents.TOUCHSTART); checkBox.sinkBitlessEvent(BrowserEvents.CLICK); // Add handlers checkBox.addMouseDownHandler(handler); checkBox.addTouchStartHandler(handler); checkBox.addClickHandler(handler);/*w w w . j a v a2 s . c o m*/ grid.addHandler(handler, GridEnabledEvent.TYPE); checkBox.setEnabled(grid.isEnabled()); return checkBox; }
From source file:com.vaadin.v7.client.widgets.Grid.java
License:Apache License
/** * Creates a new instance.// w ww . ja va2 s. com */ public Grid() { initWidget(escalator); getElement().setTabIndex(0); cellFocusHandler = new CellFocusHandler(); setStylePrimaryName(STYLE_NAME); escalator.getHeader().setEscalatorUpdater(createHeaderUpdater()); escalator.getBody().setEscalatorUpdater(createBodyUpdater()); escalator.getFooter().setEscalatorUpdater(createFooterUpdater()); header.setGrid(this); HeaderRow defaultRow = header.appendRow(); header.setDefaultRow(defaultRow); footer.setGrid(this); editor.setGrid(this); setSelectionMode(SelectionMode.SINGLE); escalator.getBody().setSpacerUpdater(gridSpacerUpdater); escalator.addScrollHandler(new ScrollHandler() { @Override public void onScroll(ScrollEvent event) { fireEvent(new ScrollEvent()); } }); escalator.addRowVisibilityChangeHandler(new RowVisibilityChangeHandler() { @Override public void onRowVisibilityChange(RowVisibilityChangeEvent event) { if (dataSource != null && dataSource.size() != 0) { dataSource.ensureAvailability(event.getFirstVisibleRow(), event.getVisibleRowCount()); } } }); // Default action on SelectionEvents. Refresh the body so changed // become visible. addSelectionHandler(new SelectionHandler<T>() { @Override public void onSelect(SelectionEvent<T> event) { refreshBody(); } }); // Sink header events and key events sinkEvents(getHeader().getConsumedEvents()); sinkEvents(Arrays.asList(BrowserEvents.KEYDOWN, BrowserEvents.KEYUP, BrowserEvents.KEYPRESS, BrowserEvents.DBLCLICK, BrowserEvents.MOUSEDOWN, BrowserEvents.CLICK)); // Make ENTER and SHIFT+ENTER in the header perform sorting addHeaderKeyUpHandler(new HeaderKeyUpHandler() { @Override public void onKeyUp(GridKeyUpEvent event) { if (event.getNativeKeyCode() != KeyCodes.KEY_ENTER) { return; } if (getHeader().getRow(event.getFocusedCell().getRowIndex()).isDefault()) { // Only sort for enter on the default header sorter.sort(event.getFocusedCell().getColumn(), event.isShiftKeyDown()); } } }); browserEventHandlers.addAll(Arrays.asList( // Opening, closing and navigating in the editor new EditorEventHandler(), // Keyboard and click handlers, Escalator events new SuperEventHandler(), // Column reordering via header drag&drop new HeaderCellDragStartHandler(), // Column sorting via header click new HeaderDefaultRowEventHandler(), // Invoking event-aware renderers new RendererEventHandler(), // Moving cell focus by keyboard or mouse new CellFocusEventHandler())); }