/**
  * Does the event target this popup?
  *
  * @param event the native event
  * @return true if the event targets the popup
  */
 private boolean eventTargetsPopup(NativeEvent event) {
   EventTarget target = event.getEventTarget();
   if (Element.is(target)) {
     return getElement().isOrHasChild(Element.as(target));
   }
   return false;
 }
  /**
   * Called when an event occurs in a rendered instance of this Cell. The parent element refers to
   * the element that contains the rendered cell, NOT to the outermost element that the Cell
   * rendered.
   */
  @Override
  public void onBrowserEvent(
      final Context context,
      final Element parent,
      final List<FlashCardDto> flashCardList,
      final NativeEvent event,
      final ValueUpdater<List<FlashCardDto>> valueUpdater) {
    // Let AbstractCell handle the keydown event.
    super.onBrowserEvent(context, parent, flashCardList, event, valueUpdater);

    // Handle the click event.
    if ("click".equals(event.getType())) {
      // Ignore clicks that occur outside of the outermost element.
      EventTarget eventTarget = event.getEventTarget();

      if (parent.isOrHasChild(Element.as(eventTarget))) {
        // use this to get the selected element!!
        Element el = Element.as(eventTarget);

        // check if we really click on the image
        if (el.getParentElement().getNodeName().equalsIgnoreCase("DIV")) {
          doAction(el.getParentElement().getAttribute("name"), valueUpdater);
        }
      }
    }
  }
Exemple #3
0
 /**
  * Detecting the element on which the the event is happening may be problematic during drag and
  * drop operation. This is especially the case if a drag image (often called also drag proxy) is
  * kept under the mouse cursor (see {@link #createDragImage(Element, boolean)}. Drag and drop
  * event handlers (like the one provided by {@link VDragAndDropManager} ) should set elmentOver
  * field to reflect the the actual element on which the pointer currently is (drag image
  * excluded). {@link VDropHandler}s can then more easily react properly on drag events by reading
  * the element via this method.
  *
  * @return the element in {@link VDropHandler} on which mouse cursor is on
  */
 public com.google.gwt.user.client.Element getElementOver() {
   if (elementOver != null) {
     return DOM.asOld(elementOver);
   } else if (currentGwtEvent != null) {
     return currentGwtEvent.getEventTarget().cast();
   }
   return null;
 }
Exemple #4
0
 private static PatchSetsBox getRevisionBox(NativeEvent event) {
   Element e = event.getEventTarget().cast();
   for (e = DOM.getParent(e); e != null; e = DOM.getParent(e)) {
     EventListener l = DOM.getEventListener(e);
     if (l instanceof PatchSetsBox) {
       return (PatchSetsBox) l;
     }
   }
   return null;
 }
  /**
   * Called when an event occurs in a rendered instance of this Cell. The parent element refers to
   * the element that contains the rendered cell, NOT to the outermost element that the Cell
   * rendered.
   */
  @Override
  public void onBrowserEvent(
      com.google.gwt.cell.client.Cell.Context context,
      Element parent,
      String value,
      NativeEvent event,
      com.google.gwt.cell.client.ValueUpdater<String> valueUpdater) {

    // Let AbstractCell handle the keydown event.
    super.onBrowserEvent(context, parent, value, event, valueUpdater);

    // Handle the click event.
    if ("click".equals(event.getType())) {

      // Ignore clicks that occur outside of the outermost element.
      EventTarget eventTarget = event.getEventTarget();

      if (parent.isOrHasChild(Element.as(eventTarget))) {
        // if (parent.getFirstChildElement().isOrHasChild(
        // Element.as(eventTarget))) {

        // use this to get the selected element!!
        Element el = Element.as(eventTarget);

        // check if we really click on the image
        if (callback != null && el.getNodeName().equalsIgnoreCase("IMG")) {
          final String s = el.getParentElement().getAttribute("name");
          final KieContainer container = containersProvider.getContainer(value);
          final boolean isUp = SharedUtils.getContainerStatus(container);
          final boolean isKieApp =
              container.getType() != null
                  && KieImageCategory.KIEAPP.equals(container.getType().getCategory());
          if (ContainerActionsCell.PLAY.equals(s) && !isUp) {
            callback.onStart(container);
          } else if (ContainerActionsCell.STOP.equals(s) && isUp) {
            callback.onStop(container);
          } else if (ContainerActionsCell.RELOAD.equals(s) && isUp) {
            callback.onRestart(container);
          } else if (ContainerActionsCell.REMOVE.equals(s)) {
            callback.onRemove(container);
          } else if (ContainerActionsCell.VIEW_LOGS.equals(s)) {
            callback.onViewLogs(container);
          } else if (ContainerActionsCell.VIEW_DETAILS.equals(s) && isUp && isKieApp) {
            callback.onViewDetails(container);
          } else if (ContainerActionsCell.NAVIGATE.equals(s) && isUp && isKieApp) {
            callback.onNavigate(container);
          }
        }
      }
    }
  };
  /**
   * Does the event target one of the partner elements?
   *
   * @param event the native event
   * @return true if the event targets a partner
   */
  private boolean eventTargetsPartner(NativeEvent event) {
    if (autoHidePartners == null) {
      return false;
    }

    EventTarget target = event.getEventTarget();
    if (Element.is(target)) {
      for (Element elem : autoHidePartners) {
        if (elem.isOrHasChild(Element.as(target))) {
          return true;
        }
      }
    }
    return false;
  }
Exemple #7
0
 @Override
 public void onBrowserEvent(
     Context context, Element parent, C value, NativeEvent event, ValueUpdater<C> valueUpdater) {
   super.onBrowserEvent(context, parent, value, event, valueUpdater);
   if (CLICK.equals(event.getType())) {
     EventTarget eventTarget = event.getEventTarget();
     if (!Element.is(eventTarget)) {
       return;
     }
     if (parent.getFirstChildElement().isOrHasChild(Element.as(eventTarget))) {
       // Ignore clicks that occur outside of the main element.
       onEnterKeyDown(context, parent, value, event, valueUpdater);
     }
   }
 }
 private void editEvent(
     Context context,
     Element parent,
     String value,
     ViewData viewData,
     NativeEvent event,
     ValueUpdater<String> valueUpdater) {
   String type = event.getType();
   boolean keyUp = KEYUP.equals(type);
   boolean keyDown = KEYDOWN.equals(type);
   if (keyUp || keyDown) {
     int keyCode = event.getKeyCode();
     if (keyUp
         && keyCode == KeyCodes.KEY_ENTER
         && (event.getCtrlKey() || event.getAltKey() || event.getShiftKey())) {
       // Commit the change.
       commit(context, parent, viewData, valueUpdater);
     } else if (keyUp && keyCode == KeyCodes.KEY_ESCAPE) {
       // Cancel edit mode.
       String originalText = viewData.getOriginal();
       if (viewData.isEditingAgain()) {
         viewData.setText(originalText);
         viewData.setEditing(false);
       } else {
         setViewData(context.getKey(), null);
       }
       cancel(context, parent, value);
     } else {
       // Update the text in the view data on each key.
       updateViewData(parent, viewData, true);
     }
   } else if (BLUR.equals(type)) {
     // Commit the change. Ensure that we are blurring the input element and
     // not the parent element itself.
     EventTarget eventTarget = event.getEventTarget();
     if (Element.is(eventTarget)) {
       Element target = Element.as(eventTarget);
       if ("input".equals(target.getTagName().toLowerCase())) {
         commit(context, parent, viewData, valueUpdater);
       }
     }
   }
 }
 @Override
 public void onBrowserEvent(
     com.google.gwt.cell.client.Cell.Context context,
     Element parent,
     SummaryDTO value,
     NativeEvent event,
     ValueUpdater<SummaryDTO> valueUpdater) {
   super.onBrowserEvent(context, parent, value, event, valueUpdater);
   EventTarget eventTarget = event.getEventTarget();
   if (Element.is(eventTarget)) {
     Element src = Element.as(eventTarget);
     String id = src.getId();
     if (id.startsWith(SEE_METADATA)) {
       presenter.displayMetadata(value.getUuid());
     }
     if (id.startsWith(PDF_METADATA)) {
       presenter.displayMetadataPDF(value.getUuid());
     }
   }
 }
Exemple #10
0
  public void displayChunkOptions(AceEditor editor, NativeEvent event) {
    // Translate the 'pageX' + 'pageY' position to document position
    int pageX = event.getClientX();
    int pageY = event.getClientY();

    Renderer renderer = editor.getWidget().getEditor().getRenderer();
    Position position = renderer.screenToTextCoordinates(pageX, pageY);

    if (optionsPanel_ != null) optionsPanel_ = null;

    Element el = event.getEventTarget().cast();
    if (el.hasClassName(RES.styles().setupChunk()))
      optionsPanel_ = new SetupChunkOptionsPopupPanel();
    else optionsPanel_ = new DefaultChunkOptionsPopupPanel();

    optionsPanel_.init(editor.getWidget(), position);
    optionsPanel_.show();
    optionsPanel_.focus();
    PopupPositioner.setPopupPosition(optionsPanel_, pageX, pageY, 10);
  }
Exemple #11
0
  @Override
  public void onBrowserEvent(
      Cell.Context context,
      Element parent,
      MetadataTemplateInfo value,
      NativeEvent event,
      ValueUpdater<MetadataTemplateInfo> valueUpdater) {
    if (value == null) {
      return;
    }

    Element eventTarget = Element.as(event.getEventTarget());
    Element child = findAppNameElement(parent);
    if (child != null && child.isOrHasChild(eventTarget)) {
      switch (Event.as(event).getTypeInt()) {
        case Event.ONCLICK:
          doOnClick(eventTarget, value);
          break;
        default:
          break;
      }
    }
  }
 @Override
 public boolean onBrowserEvent(
     Cell.Context context,
     Element parent,
     C value,
     NativeEvent event,
     ValueUpdater<C> cValueUpdater) {
   resizer = cell.getResizeElement().cast();
   if (event.getEventTarget().equals(resizer)) {
     String eventType = event.getType();
     if (BrowserEvents.MOUSEDOWN.equals(eventType)) {
       startPosition = positionController.getPosition(Event.getCurrentEvent());
       int events =
           Event.getTypeInt(BrowserEvents.MOUSEMOVE) | Event.getTypeInt(BrowserEvents.MOUSEUP);
       DOM.setEventListener(resizer, eventListener);
       DOM.sinkEvents(resizer, events);
       DOM.setCapture(resizer);
       startSize = cell.getSize(parent);
       event.preventDefault();
       return true;
     }
   }
   return false;
 }
Exemple #13
0
  private void handleEvent(NativeEvent e) {

    if (e.getType().equals("contextmenu")) {
      e.preventDefault();
      e.stopPropagation();
      return;
    }

    if (e.getType().equals("mousedown")) {
      if (!e.getEventTarget().equals(canvas) || touched[0]) {
        float mouseX = (int) getRelativeX(e, canvas);
        float mouseY = (int) getRelativeY(e, canvas);
        if (mouseX < 0
            || mouseX > Gdx.graphics.getWidth()
            || mouseY < 0
            || mouseY > Gdx.graphics.getHeight()) {
          hasFocus = false;
        }
        return;
      }
      hasFocus = true;
      this.justTouched = true;
      this.touched[0] = true;
      this.pressedButtons.add(getButton(e.getButton()));
      this.deltaX[0] = 0;
      this.deltaY[0] = 0;
      if (isCursorCatched()) {
        this.touchX[0] += getMovementXJSNI(e);
        this.touchY[0] += getMovementYJSNI(e);
      } else {
        this.touchX[0] = (int) getRelativeX(e, canvas);
        this.touchY[0] = (int) getRelativeY(e, canvas);
      }
      this.currentEventTimeStamp = TimeUtils.nanoTime();
      if (processor != null)
        if (processor.touchDown(touchX[0], touchY[0], 0, getButton(e.getButton()))) {
          e.preventDefault();
          e.stopPropagation();
        }
    }

    if (e.getType().equals("mousemove")) {
      if (isCursorCatched()) {
        this.deltaX[0] = (int) getMovementXJSNI(e);
        this.deltaY[0] = (int) getMovementYJSNI(e);
        this.touchX[0] += getMovementXJSNI(e);
        this.touchY[0] += getMovementYJSNI(e);
      } else {
        this.deltaX[0] = (int) getRelativeX(e, canvas) - touchX[0];
        this.deltaY[0] = (int) getRelativeY(e, canvas) - touchY[0];
        this.touchX[0] = (int) getRelativeX(e, canvas);
        this.touchY[0] = (int) getRelativeY(e, canvas);
      }
      this.currentEventTimeStamp = TimeUtils.nanoTime();
      if (processor != null) {
        if (touched[0]) processor.touchDragged(touchX[0], touchY[0], 0);
        else processor.mouseMoved(touchX[0], touchY[0]);
      }
    }

    if (e.getType().equals("mouseup")) {
      if (!touched[0]) return;
      this.pressedButtons.remove(getButton(e.getButton()));
      this.touched[0] = pressedButtons.size() > 0;
      if (isCursorCatched()) {
        this.deltaX[0] = (int) getMovementXJSNI(e);
        this.deltaY[0] = (int) getMovementYJSNI(e);
        this.touchX[0] += getMovementXJSNI(e);
        this.touchY[0] += getMovementYJSNI(e);
      } else {
        this.deltaX[0] = (int) getRelativeX(e, canvas) - touchX[0];
        this.deltaY[0] = (int) getRelativeY(e, canvas) - touchY[0];
        this.touchX[0] = (int) getRelativeX(e, canvas);
        this.touchY[0] = (int) getRelativeY(e, canvas);
      }
      this.currentEventTimeStamp = TimeUtils.nanoTime();
      this.touched[0] = false;
      if (processor != null) processor.touchUp(touchX[0], touchY[0], 0, getButton(e.getButton()));
    }

    if (e.getType().equals("keydown") && hasFocus) {
      // System.out.println("keydown");
      int code = keyForCode(e.getKeyCode());
      if (code == 67) {
        e.preventDefault();
        if (processor != null) {
          processor.keyDown(code);
          processor.keyTyped('\b');
        }
      } else {
        this.pressedKeys.add(code);
        if (processor != null) processor.keyDown(code);
      }
    }

    if (e.getType().equals("keypress") && hasFocus) {
      // System.out.println("keypress");
      char c = (char) e.getCharCode();
      if (processor != null) processor.keyTyped(c);
    }

    if (e.getType().equals("keyup") && hasFocus) {
      // System.out.println("keyup");
      int code = keyForCode(e.getKeyCode());
      this.pressedKeys.remove(code);
      if (processor != null) processor.keyUp(code);
    }

    if (e.getType().equals("touchstart")) {
      this.justTouched = true;
      JsArray<Touch> touches = e.getChangedTouches();
      for (int i = 0, j = touches.length(); i < j; i++) {
        Touch touch = touches.get(i);
        int touchId = touch.getIdentifier();
        touched[touchId] = true;
        double r = GwtGraphics.getDevicePixelRatioJSNI();
        int x = (int) (touch.getRelativeX(canvas) * r);
        int y = (int) (touch.getRelativeY(canvas) * r);
        touchX[touchId] = x;
        touchY[touchId] = y;
        deltaX[touchId] = 0;
        deltaY[touchId] = 0;
        if (processor != null) {
          processor.touchDown(touchX[touchId], touchY[touchId], touchId, Buttons.LEFT);
        }
      }
      this.currentEventTimeStamp = TimeUtils.nanoTime();
      e.preventDefault();
    }
    if (e.getType().equals("touchmove")) {
      JsArray<Touch> touches = e.getChangedTouches();
      for (int i = 0, j = touches.length(); i < j; i++) {
        Touch touch = touches.get(i);
        int touchId = touch.getIdentifier();
        double r = GwtGraphics.getDevicePixelRatioJSNI();
        int x = (int) (touch.getRelativeX(canvas) * r);
        int y = (int) (touch.getRelativeY(canvas) * r);
        deltaX[touchId] = x - touchX[touchId];
        deltaY[touchId] = y - touchY[touchId];
        touchX[touchId] = x;
        touchY[touchId] = y;
        if (processor != null) {
          processor.touchDragged(touchX[touchId], touchY[touchId], touchId);
        }
      }
      this.currentEventTimeStamp = TimeUtils.nanoTime();
      e.preventDefault();
    }
    if (e.getType().equals("touchcancel")) {
      JsArray<Touch> touches = e.getChangedTouches();
      for (int i = 0, j = touches.length(); i < j; i++) {
        Touch touch = touches.get(i);
        int touchId = touch.getIdentifier();
        touched[touchId] = false;
        double r = GwtGraphics.getDevicePixelRatioJSNI();
        int x = (int) (touch.getRelativeX(canvas) * r);
        int y = (int) (touch.getRelativeY(canvas) * r);
        deltaX[touchId] = x - touchX[touchId];
        deltaY[touchId] = y - touchY[touchId];
        touchX[touchId] = x;
        touchY[touchId] = y;
        if (processor != null) {
          processor.touchUp(touchX[touchId], touchY[touchId], touchId, Buttons.LEFT);
        }
      }
      this.currentEventTimeStamp = TimeUtils.nanoTime();
      e.preventDefault();
    }
    if (e.getType().equals("touchend")) {
      JsArray<Touch> touches = e.getChangedTouches();
      for (int i = 0, j = touches.length(); i < j; i++) {
        Touch touch = touches.get(i);
        int touchId = touch.getIdentifier();
        touched[touchId] = false;
        double r = GwtGraphics.getDevicePixelRatioJSNI();
        int x = (int) (touch.getRelativeX(canvas) * r);
        int y = (int) (touch.getRelativeY(canvas) * r);
        deltaX[touchId] = x - touchX[touchId];
        deltaY[touchId] = y - touchY[touchId];
        touchX[touchId] = x;
        touchY[touchId] = y;
        if (processor != null) {
          processor.touchUp(touchX[touchId], touchY[touchId], touchId, Buttons.LEFT);
        }
      }
      this.currentEventTimeStamp = TimeUtils.nanoTime();
      e.preventDefault();
    } else if (e.getType().equals("mousewheel") || e.getType().equals("DOMMouseScroll")) {
      float dir = getMouseWheelVelocity(e);

      if (dir != 0 && processor != null) processor.scrolled(dir > 0 ? 1 : -1);
    }
    // if(hasFocus) e.preventDefault();
  }