Пример #1
0
 @Override
 public void onBrowserEvent(
     Context context,
     Element parent,
     String value,
     NativeEvent event,
     ValueUpdater<String> valueUpdater) {
   super.onBrowserEvent(context, parent, value, event, valueUpdater);
   String type = event.getType();
   if ("change".equals(type)) {
     HasOptions key = (HasOptions) context.getKey();
     SelectElement select = parent.getFirstChild().cast();
     String newValue = null;
     if (key.hasOptions()) {
       List<String> options = key.getOptions();
       int optionsPreambleSize =
           key.getOptionsPreamble() == null ? 0 : key.getOptionsPreamble().size();
       int selectedOptionIndex = select.getSelectedIndex() - optionsPreambleSize;
       if (selectedOptionIndex >= 0) newValue = options.get(selectedOptionIndex);
     } else newValue = key.getNoOptionsString();
     setViewData(key, newValue);
     finishEditing(parent, newValue, key, valueUpdater);
     if (valueUpdater != null) {
       valueUpdater.update(newValue);
     }
   }
 }
  /**
   * 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);
        }
      }
    }
  }
Пример #3
0
 @Override
 public void onBrowserEvent(
     Context context,
     Element parent,
     String value,
     NativeEvent event,
     ValueUpdater<String> valueUpdater) {
   Object key = context.getKey();
   ViewData viewData = getViewData(key);
   if (viewData != null && viewData.isEditing()) {
     // Handle the edit event.
     editEvent(context, parent, value, viewData, event, valueUpdater);
   } else {
     String type = event.getType();
     int keyCode = event.getKeyCode();
     boolean enterPressed = KEYUP.equals(type) && keyCode == KeyCodes.KEY_ENTER;
     if (CLICK.equals(type) || enterPressed) {
       // Go into edit mode.
       if (viewData == null) {
         viewData = new ViewData(value);
         setViewData(key, viewData);
       } else {
         viewData.setEditing(true);
       }
       edit(context, parent, value);
     }
   }
 }
Пример #4
0
 @Override
 public void onPreviewNativeEvent(NativePreviewEvent e) {
   NativeEvent nativeEvent = e.getNativeEvent();
   if ("keydown".equals(nativeEvent.getType())) {
     if (nativeEvent.getKeyCode() == KeyCodes.KEY_ENTER) {
       doLogin(userBox.getText().trim(), passBox.getText(), rememberBox.getValue());
     }
   }
 }
Пример #5
0
 @Override
 public void onBrowserEvent(
     Context context,
     Element parent,
     EntityModalPresenter.VariableValueRow value,
     NativeEvent event,
     ValueUpdater<EntityModalPresenter.VariableValueRow> valueUpdater) {
   super.onBrowserEvent(context, parent, value, event, valueUpdater);
   if ("click".equals(event.getType())) {
     onEnterKeyDown(context, parent, value, event, valueUpdater);
   }
 }
  @Override
  public void onBrowserEvent(
      Context context,
      Element parent,
      RichGroup value,
      NativeEvent event,
      ValueUpdater<RichGroup> valueUpdater) {
    super.onBrowserEvent(context, parent, value, event, valueUpdater);

    if (event.getType().equals("click")) {
      valueUpdater.update(value);
    }
  }
  /**
   * 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);
          }
        }
      }
    }
  };
Пример #8
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);
     }
   }
 }
 /* (non-Javadoc)
  * @see com.google.gwt.cell.client.AbstractCell#onBrowserEvent(com.google.gwt.cell.client.Cell.Context, com.google.gwt.dom.client.Element, java.lang.Object, com.google.gwt.dom.client.NativeEvent, com.google.gwt.cell.client.ValueUpdater)
  */
 @Override
 public void onBrowserEvent(
     Context context,
     Element parent,
     CellTreeNode value,
     NativeEvent event,
     ValueUpdater<CellTreeNode> valueUpdater) {
   if (event.getType().equals(BrowserEvents.CONTEXTMENU)) {
     event.preventDefault();
     event.stopPropagation();
     if (MatContext.get().getMeasureLockService().checkForEditPermission()) {
       onRightClick(value, (Event) event, parent);
     }
   } else {
     super.onBrowserEvent(context, parent, value, event, valueUpdater);
   }
 }
Пример #10
0
 @Override
 public void onBrowserEvent(
     Context context,
     Element parent,
     String value,
     NativeEvent event,
     ValueUpdater<String> valueUpdater) {
   String type = event.getType();
   if (BrowserEvents.KEYPRESS.equals(type)) {
     int charCode = event.getCharCode();
     String newValue = getStringFromCharCode(charCode);
     if (isValidChar(newValue)) {
       startEdit(context, parent, newValue, event, valueUpdater);
       return;
     }
   }
   super.onBrowserEvent(context, parent, value, event, valueUpdater);
 }
Пример #11
0
  /**
   * Test {@link Cell#onBrowserEvent(Element, Object, Object, NativeEvent, ValueUpdater)} with the
   * specified conditions.
   *
   * @param cell the cell to use
   * @param startHtml the innerHTML of the cell before the test starts
   * @param event the event to fire
   * @param value the cell value
   * @param expectedValue the expected value passed to the value updater, or null if none expected
   * @param dispatchToFirstChild true to dispatch to the first child of the rendered parent element,
   *     if one is available
   * @return the parent element
   */
  protected Element testOnBrowserEvent(
      final Cell<T> cell,
      String startHtml,
      NativeEvent event,
      final T value,
      T expectedValue,
      boolean dispatchToFirstChild) {
    // Setup the parent element.
    final Element parent = Document.get().createDivElement();
    parent.setInnerHTML(startHtml);
    Document.get().getBody().appendChild(parent);

    // If the element has a child, use it as the event target.
    Element target = parent;
    if (dispatchToFirstChild) {
      Element child = parent.getFirstChildElement();
      target = (child == null) ? parent : child;
    }

    // Pass the event to the cell.
    final MockValueUpdater valueUpdater = new MockValueUpdater();
    Event.setEventListener(
        parent,
        new EventListener() {
          public void onBrowserEvent(Event event) {
            try {
              DOM.setEventListener(parent, null);
              Context context = new Context(0, 0, DEFAULT_KEY);
              cell.onBrowserEvent(context, parent, value, event, valueUpdater);
              parent.removeFromParent();
            } catch (Exception e) {
              // We are in an event loop, so events may not propagate out to JUnit.
              fail("An exception occured while handling the event: " + e.getMessage());
            }
          }
        });
    Event.sinkEvents(target, Event.getTypeInt(event.getType()));
    target.dispatchEvent(event);
    assertNull(DOM.getEventListener(parent));

    // Check the expected value and view data.
    valueUpdater.assertLastValue(expectedValue);
    return parent;
  }
Пример #12
0
 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(
     final Context context,
     final Element parent,
     final String value,
     final NativeEvent event,
     final ValueUpdater<String> valueUpdater) {
   super.onBrowserEvent(context, parent, value, event, valueUpdater);
   final String type = event.getType();
   if ("change".equals(type)) {
     final Object key = context.getKey();
     final SelectElement select = parent.getFirstChild().cast();
     final String newValue = options.get(select.getSelectedIndex());
     setViewData(key, newValue);
     finishEditing(parent, newValue, key, valueUpdater);
     if (valueUpdater != null) {
       valueUpdater.update(newValue);
     }
   }
 }
Пример #14
0
 @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;
 }
Пример #15
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();
  }