Java Code Examples for com.google.gwt.user.client.Event

The following examples show how to use com.google.gwt.user.client.Event. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@Override
protected void onDetach() {
  super.onDetach();

  enablePopup(getTarget());
  getSource().resetContainerPeer();
  getTarget().removeClassName(CSS.rootContainer());

  myContent.removeFromParent();
  myLineHighlight1.removeFromParent();
  myLineHighlight2.removeFromParent();

  $(getTarget()).unbind(Event.KEYEVENTS | Event.MOUSEEVENTS);

  myWindowReg.removeHandler();
}
 
Example 2
Source Project: consulo   Source File: CellBrowser.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onBrowserEvent2(Event event) {
  super.onBrowserEvent2(event);

  // Handle keyboard navigation between lists.
  String eventType = event.getType();
  if (BrowserEvents.KEYDOWN.equals(eventType) && !isKeyboardNavigationSuppressed()) {
    int keyCode = event.getKeyCode();
    boolean isRtl = LocaleInfo.getCurrentLocale().isRTL();
    keyCode = KeyCodes.maybeSwapArrowKeysForRtl(keyCode, isRtl);
    switch (keyCode) {
      case KeyCodes.KEY_LEFT:
        keyboardNavigateShallow();
        return;
      case KeyCodes.KEY_RIGHT:
        keyboardNavigateDeep();
        return;
    }
  }
}
 
Example 3
Source Project: appinventor-extensions   Source File: MockComponent.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Sets the components widget representation and initializes its properties.
 *
 * <p>To be called from implementing constructor.
 *
 * @param widget  components visual representation in designer
 */
void initComponent(Widget widget) {
  // Widget needs to be initialized before the component itself so that the component properties
  // can be reflected by the widget
  initWidget(widget);

  // Capture mouse and click events in onBrowserEvent(Event)
  sinkEvents(Event.MOUSEEVENTS | Event.ONCLICK | Event.TOUCHEVENTS);

  // Add the special name property and set the tooltip
  String name = componentName();
  setTitle(name);
  addProperty(PROPERTY_NAME_NAME, name, null, new TextPropertyEditor());

  // TODO(user): Ensure this value is unique within the project using a list of
  // already used UUIDs
  // Set the component's UUID
  // The default value here can be anything except 0, because YoungAndroidProjectServce
  // creates forms with an initial Uuid of 0, and Properties.java doesn't encode
  // default values when it generates JSON for a component.
  addProperty(PROPERTY_NAME_UUID, "-1", null, new TextPropertyEditor());
  changeProperty(PROPERTY_NAME_UUID, "" + Random.nextInt());

  editor.getComponentPalettePanel().configureComponent(this);
}
 
Example 4
Source Project: dashbuilder   Source File: PerspectivesExplorerView.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void addPerspective(String name, Command onClicked) {
    AnchorElement anchor = Document.get().createAnchorElement();
    anchor.getStyle().setCursor(Style.Cursor.POINTER);
    anchor.getStyle().setColor("black");
    anchor.getStyle().setProperty("fontSize", "larger");
    anchor.setInnerText(name);

    Event.sinkEvents(anchor, Event.ONCLICK);
    Event.setEventListener(anchor, event -> {
        if(Event.ONCLICK == event.getTypeInt()) {
            onClicked.execute();
        }
    });

    SpanElement icon = Document.get().createSpanElement();
    icon.getStyle().setMarginRight(10, Style.Unit.PX);
    icon.setClassName("pficon-virtual-machine");
    icon.getStyle().setProperty("fontSize", "larger");

    DivElement gi = createItemDiv(new Element[] {icon, anchor});
    perspectivesDiv.appendChild((Node) gi);
}
 
Example 5
Source Project: cuba   Source File: TableEmptyState.java    License: Apache License 2.0 6 votes vote down vote up
public TableEmptyState() {
    container = Document.get().createDivElement();
    container.setClassName("c-table-empty-state");

    messageBox = Document.get().createDivElement();
    messageBox.setClassName("c-table-empty-state-message-box");

    messageLabel = Document.get().createDivElement();
    messageLabel.setClassName("c-table-empty-state-message");

    linkMessageLabel = Document.get().createSpanElement();
    linkMessageLabel.setClassName("c-table-empty-state-link-message v-button-link");

    container.appendChild(messageBox);

    Event.sinkEvents(container, Event.ONCLICK);
    Event.setEventListener(container, this);
}
 
Example 6
@Override
public void onBrowserEvent(Event event) {
	super.onBrowserEvent(event);
	boolean mustKillEvent = false;
	if (DOM.eventGetType(event) == Event.ONKEYDOWN) {
		switch (event.getKeyCode()) {
			case KeyCodes.KEY_TAB:
			case KeyCodes.KEY_ESCAPE:
				this.getDropdown().close();
				break;
			default:
				break;
		}
	}
	if (mustKillEvent) {
		event.preventDefault();
		event.stopPropagation();
	}
}
 
Example 7
/**
 * ForumScrollTable
 */
public ForumScrollTable(FixedWidthGrid dataTable, FixedWidthFlexTable headerTable,
                        ScrollTableImages scrollTableImages, ForumController controller) {
	super(dataTable, headerTable, scrollTableImages);
	this.dataTable = dataTable;
	this.controller = controller;

	setResizePolicy(ResizePolicy.UNCONSTRAINED);
	setScrollPolicy(ScrollPolicy.BOTH);
	dataTable.setSelectionEnabled(false); // Disables selection

	dataTable.setColumnSorter(new ExtendedColumnSorter());

	// Sets some events
	DOM.sinkEvents(getDataWrapper(), Event.ONDBLCLICK | Event.ONMOUSEDOWN);
}
 
Example 8
/**
 * Ensure that new keybindings are used after changing them in the editor.
 */
public void testReregistrationKeyBinding() {
  KeyBindingRegistry bindings = new KeyBindingRegistry();
  callTracker = 0;
  EditorAction testAction = new EditorAction() {
    public void execute(EditorContext context) {
      callTracker++;
    }
  };
  bindings.registerAction(KeyCombo.ORDER_G, testAction);

  EditorImpl editor = createEditor(bindings);
  Event rawEvent = Document.get().createKeyPressEvent(
      true, false, false, false, G_CODE, G_CODE).cast();
  editor.onJavaScriptEvent("keypress", rawEvent);
  // callTracker should be 1 assuming the test above passes

  bindings.removeAction(KeyCombo.ORDER_G);
  initEditor(editor, Editor.ROOT_REGISTRIES, bindings);
  editor.onJavaScriptEvent("keypress", rawEvent);
  assertEquals("Callback action called on deregistered keypress", callTracker, 1);
}
 
Example 9
/**
 * Method originally copied from HTMLTable superclass where it was defined private
 * Now implemented differently to only return target cell if it'spart of 'this' table
 */
private Element getMouseEventTargetCell(Event event) {
	Element td = DOM.eventGetTarget(event);
	//locate enclosing td element
	while (!DOM.getElementProperty(td, "tagName").equalsIgnoreCase("td")) {
		// If we run out of elements, or run into the table itself, then give up.
		if ((td == null) || td == getElement())
			return null;
		td = DOM.getParent(td);
	}
	//test if the td is actually from this table
	Element tr = DOM.getParent(td);
	Element body = DOM.getParent(tr);
	if (body == this.getBodyElement()) {
		return td;
	}
	//Didn't find appropriate cell
	return null;
}
 
Example 10
@Override
protected void endConstruct() {
	this.getElement().appendChild(this.backgroundBar);
	StyleUtils.addStyle(this.backgroundBar, InputSlider.STYLE_BACKGROUNG);
	this.contentPanel.setWidget(this.handleWidget);

	this.popover.add(this.handleWidget);
	this.popover.setTrigger(Trigger.FOCUS);

	this.handleWidget.addKeyDownHandler(this.keyHandler);

	this.addValueChangeHandler(this);

	this.sinkEvents(Event.MOUSEEVENTS | Event.ONMOUSEWHEEL | Event.TOUCHEVENTS);

	super.endConstruct();
}
 
Example 11
/**
 * Method originally copied from HTMLTable superclass where it was defined private
 * Now implemented differently to only return target cell if it'spart of 'this' table
 */
private Element getMouseEventTargetCell(Event event) {
	Element td = DOM.eventGetTarget(event);
	//locate enclosing td element
	while (!DOM.getElementProperty(td, "tagName").equalsIgnoreCase("td")) {
		// If we run out of elements, or run into the table itself, then give up.
		if ((td == null) || td == getElement())
			return null;
		td = DOM.getParent(td);
	}
	//test if the td is actually from this table
	Element tr = DOM.getParent(td);
	Element body = DOM.getParent(tr);
	if (body == this.getBodyElement()) {
		return td;
	}
	//Didn't find appropriate cell
	return null;
}
 
Example 12
Source Project: dashbuilder   Source File: TargetPerspectiveEditorView.java    License: Apache License 2.0 6 votes vote down vote up
private void addItem(UnorderedList unorderedList, String name, boolean selected, Command onSelect) {
    AnchorElement anchor = Document.get().createAnchorElement();
    anchor.setInnerText(name);

    LIElement li = Document.get().createLIElement();
    li.getStyle().setCursor(Style.Cursor.POINTER);
    li.appendChild(anchor);
    li.setClassName(selected ? "selected" : "");
    unorderedList.appendChild((Node) li);

    Event.sinkEvents(anchor, Event.ONCLICK);
    Event.setEventListener(anchor, event -> {
        if(Event.ONCLICK == event.getTypeInt()) {
            onSelect.execute();
        }
    });
}
 
Example 13
Source Project: djvu-html5   Source File: DataStore.java    License: GNU General Public License v2.0 6 votes vote down vote up
private CanvasElement prepareMissingTileImage() {
	int tileSize = DjvuContext.getTileSize();
	CanvasElement canvas = createImage(tileSize, tileSize);
	Context2d context2d = canvas.getContext2d();
	context2d.setFillStyle("white");
	context2d.fillRect(0, 0, canvas.getWidth(), canvas.getHeight());
	Image image = new Image();
	final ImageElement imageElement = image.getElement().cast();
	imageElement.getStyle().setProperty("visibility", "hidden");
	Event.setEventListener(imageElement, event -> {
		if (Event.ONLOAD == event.getTypeInt()) {
			missingTileImage.getContext2d().drawImage(imageElement, 0, 0);
			RootPanel.get().getElement().removeChild(imageElement);
		}
	});
	RootPanel.get().getElement().appendChild(imageElement);
	image.setUrl(getBlankImageUrl());
	return canvas;
}
 
Example 14
Source Project: unitime   Source File: UniTimeTable.java    License: Apache License 2.0 5 votes vote down vote up
public TableEvent(Event sourceEvent, int row, int col, Element tr, Element td, T data) {
	iRow = row;
	iCol = col;
	iTR = tr;
	iTD = td;
	iData = data;
	iSourceEvent = sourceEvent;
}
 
Example 15
@Override
protected void onPreviewNativeEvent(Event.NativePreviewEvent event) {
    if (Event.ONKEYDOWN == event.getTypeInt()) {
        if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) {
            // Dismiss when escape is pressed
            hide();
        }
    }
}
 
Example 16
Source Project: core   Source File: OffPageSelector.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void onPreviewNativeEvent(Event.NativePreviewEvent event) {
    if (Event.ONKEYDOWN == event.getTypeInt()) {
        if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) {
            // Dismiss when escape is pressed
            hide();
        }
    }
}
 
Example 17
private boolean eventTargetsLabelOrChild(DomEvent<?> event) {
	Event nativeEvent = Event.as(event.getNativeEvent());
	EventTarget target = nativeEvent.getEventTarget();
	if (Element.is(target)) {
		return this.labelElement.isOrHasChild(Element.as(target));
	}
	return false;
}
 
Example 18
Source Project: swellrt   Source File: MyDoodad.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onActivated(final ContentElement element) {
  Helper.registerJsHandler(
      element, element.getImplNodelet(), "click", new JavaScriptEventListener() {
        @Override
        public void onJavaScriptEvent(String name, Event event) {
          promptNewRef(element);
        }
      });
}
 
Example 19
Source Project: cuba   Source File: CubaScrollTableWidget.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    super.onBrowserEvent(event);

    if (isEnabled() && event.getTypeInt() == Event.ONCONTEXTMENU) {
        if (getStyleName().contains("-header-sortable")) {
            _delegate.showSortMenu(td, cid);
        }

        event.preventDefault();
        event.stopPropagation();
    }
}
 
Example 20
Source Project: unitime   Source File: StudentSchedule.java    License: Apache License 2.0 5 votes vote down vote up
public void checkAccessKeys(NativePreviewEvent event) {
	if (event.getTypeInt() == Event.ONKEYUP && (event.getNativeEvent().getAltKey() || event.getNativeEvent().getCtrlKey())) {
		for (Map.Entry<Character, Integer> entry: iTabAccessKeys.entrySet())
			if (event.getNativeEvent().getKeyCode() == Character.toLowerCase(entry.getKey()) || event.getNativeEvent().getKeyCode()  == Character.toUpperCase(entry.getKey())) {
				iTabs.selectTab(entry.getValue());
			}
	}
}
 
Example 21
Source Project: cuba   Source File: Tools.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onPreviewNativeEvent(Event.NativePreviewEvent event) {
    super.onPreviewNativeEvent(event);

    NativeEvent nativeEvent = event.getNativeEvent();
    Element target = Element.as(nativeEvent.getEventTarget());

    if (Event.ONCLICK == event.getTypeInt()) {
        if (getElement().isOrHasChild(target)) {
            Scheduler.get().scheduleDeferred(this::hide);
        }
    }

    previewTableContextMenuEvent(event);
}
 
Example 22
Source Project: incubator-retired-wave   Source File: EventWrapper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Wrapper for GWT's get[Key Char]Code() that conflates the two values. If
 * there is no keyCode present, it returns charCode instead. This matches the
 * values in {{@link #keyMap} above.
 */
public static int getKeyCode(Event evt) {
  int keyCode = evt.getKeyCode();
  if (keyCode == 0) {
    keyCode = evt.getCharCode();
  }
  return keyCode;
}
 
Example 23
Source Project: unitime   Source File: UniTimeTable.java    License: Apache License 2.0 5 votes vote down vote up
public UniTimeTable() {
	setCellPadding(2);
	setCellSpacing(0);
	sinkEvents(Event.ONMOUSEOVER);
	sinkEvents(Event.ONMOUSEOUT);
	sinkEvents(Event.ONCLICK);
	sinkEvents(Event.ONKEYDOWN);
	sinkEvents(Event.ONDBLCLICK);
	setStylePrimaryName("unitime-MainTable");
	iHintPanel = new PopupPanel();
	iHintPanel.setStyleName("unitime-PopupHint");
	Roles.getGridRole().set(getElement());
}
 
Example 24
/**
 * Default constructor.
 */
public VComboBoxMultiselect() {
	this.tb = createTextBox();
	this.suggestionPopup = createSuggestionPopup();

	this.popupOpener.addMouseDownHandler(VComboBoxMultiselect.this);
	Roles.getButtonRole()
		.setAriaHiddenState(this.popupOpener.getElement(), true);
	Roles.getButtonRole()
		.set(this.popupOpener.getElement());

	this.panel.add(this.tb);
	this.panel.add(this.popupOpener);
	initWidget(this.panel);
	Roles.getComboboxRole()
		.set(this.panel.getElement());

	this.tb.addKeyDownHandler(this);
	this.tb.addKeyUpHandler(this);

	this.tb.addFocusHandler(this);
	this.tb.addBlurHandler(this);

	this.panel.addDomHandler(this, ClickEvent.getType());

	setStyleName(CLASSNAME);

	sinkEvents(Event.ONPASTE);
}
 
Example 25
@Override
public void onBrowserEvent(Event event) {
	super.onBrowserEvent(event);

	if (event.getTypeInt() == Event.ONPASTE) {
		if (this.textInputEnabled) {
			filterOptions(this.currentPage);
		}
	}
}
 
Example 26
@Override
public void onBrowserEvent(Event event) {
  super.onBrowserEvent(event);

  // We don't want anything outside the popup to receive events
  event.stopPropagation();
}
 
Example 27
Source Project: core   Source File: DefaultPopup.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void onPreviewNativeEvent(Event.NativePreviewEvent event) {
    if (Event.ONKEYDOWN == event.getTypeInt()) {
        if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) {
            // Dismiss when escape is pressed
            hide();
        }
    }
}
 
Example 28
@Override
public void onBrowserEvent(Event event) {
	super.onBrowserEvent(event);
	boolean mustKillEvent = false;
	switch (DOM.eventGetType(event)) {
		case Event.ONKEYDOWN:
			switch (event.getKeyCode()) {
				case KeyCodes.KEY_HOME:
					this.selectionHandler.onHomeKeyDown();
					mustKillEvent = true;
					break;
				case KeyCodes.KEY_END:
					this.selectionHandler.onEndKeyDown();
					mustKillEvent = true;
					break;
				case KeyCodes.KEY_UP:
					this.selectionHandler.onUpKeyDown();
					mustKillEvent = true;
					break;
				case KeyCodes.KEY_DOWN:
					this.selectionHandler.onDownKeyDown();
					mustKillEvent = true;
					break;
				default:
					break;
			}
			break;
		case Event.ONKEYPRESS:
			this.keyPressHandler.handleKeyPress(event.getCharCode());
			break;
		default:
			break;
	}

	if (mustKillEvent) {
		event.preventDefault();
		event.stopPropagation();
	}
}
 
Example 29
@Override
public void onBrowserEvent(Event event) {
  if (event.getTypeInt() == Event.ONCLICK && event.getTarget() == shadow) {
    hideCommand.execute();
  } else {
    super.onBrowserEvent(event);
  }
}
 
Example 30
Source Project: unitime   Source File: SingleDateSelector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	switch (DOM.eventGetType(event)) {
    case Event.ONMOUSEDOWN:
    	MouseDownEvent.fireNativeEvent(event, this);
    	event.stopPropagation();
    	event.preventDefault();
    	break;
	}
}