Java Code Examples for com.vaadin.client.WidgetUtil#setTextSelectionEnabled()

The following examples show how to use com.vaadin.client.WidgetUtil#setTextSelectionEnabled() . 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: ShiftCtrlClickSelectionHandler.java    From GridExtensionPack with Apache License 2.0 6 votes vote down vote up
@Override
protected void ctrlClickSelect(SelectionModel<JsonObject> model, CellReference<JsonObject> cell, GridClickEvent e) {
	// Plain control click, or no previously selected.
	if (!e.isShiftKeyDown() || previous < 0) {
		super.ctrlClickSelect(model, cell, e);
		previous = cell.getRowIndex();
		return;
	}

	// Stop selecting text for now.
	WidgetUtil.setTextSelectionEnabled(grid.getElement(), false);
	WidgetUtil.clearTextSelection();

	// This works on the premise that grid fires the data available event to
	// any newly added handlers.
	boolean ctrlOrMeta = e.isControlKeyDown() || e.isMetaKeyDown();
	handler = grid.addDataAvailableHandler(new ShiftSelector(cell, model, ctrlOrMeta));
}
 
Example 2
Source File: ShiftCtrlClickSelectionHandler.java    From GridExtensionPack with Apache License 2.0 5 votes vote down vote up
@Override
public void onDataAvailable(DataAvailableEvent event) {

	// Perform shift selection

	int current = cell.getRowIndex();
	int min = Math.min(current, previous);
	int max = Math.max(current, previous);

	// TODO: Fix batching.

	if (!ctrlOrMeta) {
		model.deselectAll();
	}

	Range dataAvailable = event.getAvailableRows();

	Range selected = Range.between(min, max + 1);
	Range[] partition = selected.partitionWith(dataAvailable);

	for (int i = partition[1].getStart(); i < partition[1].getEnd(); ++i) {
		model.select(grid.getDataSource().getRow(i));
	}

	// TODO: Batch end

	rpc.selectRange(partition[0].getStart(), partition[0].length());
	rpc.selectRange(partition[2].getStart(), partition[2].length());

	if (handler != null) {
		handler.removeHandler();
	}

	WidgetUtil.setTextSelectionEnabled(grid.getElement(), true);
}