/**
   * 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);
        }
      }
    }
  }
 @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);
     }
   }
 }
Esempio n. 3
0
 protected SVGPoint getEventPoint(NativeEvent event) {
   SVGElement svg = m_svg.cast();
   SVGPoint p = svg.createSVGPoint();
   p.setX(event.getClientX());
   p.setY(event.getClientY());
   return p;
 }
Esempio n. 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());
     }
   }
 }
Esempio n. 5
0
 private static boolean onOpen(NativeEvent e, int idx) {
   if (link.handleAsClick(e.<Event>cast())) {
     PatchSetsBox t = getRevisionBox(e);
     if (t != null) {
       t.onOpenRow(idx);
       e.preventDefault();
       return false;
     }
   }
   return true;
 }
Esempio n. 6
0
 /**
  * Return the {@link Mouse} button given a {@link NativeEvent}
  *
  * @param evt Native event
  * @return {@link Mouse} button corresponding to the event
  */
 protected static int getMouseButton(NativeEvent evt) {
   switch (evt.getButton()) {
     case (NativeEvent.BUTTON_LEFT):
       return Mouse.BUTTON_LEFT;
     case (NativeEvent.BUTTON_MIDDLE):
       return Mouse.BUTTON_MIDDLE;
     case (NativeEvent.BUTTON_RIGHT):
       return Mouse.BUTTON_RIGHT;
     default:
       return evt.getButton();
   }
 }
  /**
   * 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);
          }
        }
      }
    }
  };
Esempio n. 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);
     }
   }
 }
Esempio n. 9
0
  private boolean handleKeyDown(NativeEvent e) {
    // Don't dispatch on bare modifier keypresses.
    if (KeyboardHelper.isModifierKey(e.getKeyCode())) return false;

    keyBuffer_.add(e);
    KeyboardShortcut shortcut = new KeyboardShortcut(keyBuffer_);

    // Check for disabled modal shortcuts if we're modal
    if (editorMode_ > 0) {
      for (KeyboardShortcut modalShortcut : modalShortcuts_) {
        if (modalShortcut.equals(shortcut) && modalShortcut.isModeDisabled(editorMode_)) {
          return false;
        }
      }
    }

    // Check for user-defined commands.
    if (userCommands_.dispatch(shortcut)) return true;

    // Check for custom bindings for RStudio AppCommands.
    if (dispatch(shortcut, customBindings_, e)) return true;

    // Check for RStudio AppCommands.
    if (dispatch(shortcut, commands_, e, maskedCommands_)) return true;

    return false;
  }
Esempio n. 10
0
 /**
  * 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;
 }
 @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);
     }
   }
 }
Esempio n. 12
0
  private boolean handleKeyDown(NativeEvent e) {
    // Don't dispatch on bare modifier keypresses.
    if (KeyboardHelper.isModifierKey(e.getKeyCode())) return false;

    keyBuffer_.add(e);
    KeyboardShortcut shortcut = new KeyboardShortcut(keyBuffer_.clone());

    // If this matches a prefix key, return false early.
    if (prefixes_.contains(shortcut.getKeySequence())) return false;

    // Clear the key buffer (we've reached a 'leaf' for the
    // key sequence chain; there may or may not be a command)
    keyBuffer_.clear();

    // Check for user-defined commands.
    if (userCommands_.dispatch(shortcut)) return true;

    // Check for custom bindings for RStudio AppCommands.
    if (dispatch(shortcut, customBindings_, e)) return true;

    // Check for RStudio AppCommands.
    if (dispatch(shortcut, commands_, e, maskedCommands_)) return true;

    return false;
  }
Esempio n. 13
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;
 }
 /* (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);
   }
 }
Esempio n. 15
0
  private void swallowEvents(Object object) {
    NativeEvent event = (NativeEvent) object;

    // Suppress save / quit events from reaching the browser
    KeyCombination keys = new KeyCombination(event);
    int keyCode = keys.getKeyCode();
    int modifiers = keys.getModifier();

    boolean isSaveQuitKey = keyCode == KeyCodes.KEY_S || keyCode == KeyCodes.KEY_W;

    boolean isSaveQuitModifier =
        BrowseCap.isMacintosh()
            ? modifiers == KeyboardShortcut.META
            : modifiers == KeyboardShortcut.CTRL;

    if (isSaveQuitKey && isSaveQuitModifier) event.preventDefault();
  }
Esempio n. 16
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);
 }
 public static boolean fire(NativeEvent event, HasHandlers target) {
   NativeKeyPressEvent evt = new NativeKeyPressEvent(event);
   target.fireEvent(evt);
   if (evt.isCanceled()) {
     event.preventDefault();
     return true;
   }
   return false;
 }
Esempio n. 18
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;
 }
Esempio n. 19
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);
  }
Esempio n. 20
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);
    }
  }
Esempio n. 22
0
  /**
   * 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;
  }
Esempio n. 23
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;
 }
Esempio n. 24
0
    public boolean shouldComplete(NativeEvent event) {
      // Never complete if there's an active selection
      Range range = getSession().getSelection().getRange();
      if (!range.isEmpty()) return false;

      // Don't consider Tab to be a completion if we're at the start of a
      // line (e.g. only zero or more whitespace characters between the
      // beginning of the line and the cursor)

      if (event != null && event.getKeyCode() != KeyCodes.KEY_TAB) return true;

      int col = range.getStart().getColumn();
      if (col == 0) return false;

      String row = getSession().getLine(range.getStart().getRow());
      return row.substring(0, col).trim().length() != 0;
    }
Esempio n. 25
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;
  }
 @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);
     }
   }
 }
 @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());
     }
   }
 }
Esempio n. 28
0
  private boolean dispatch(
      KeyboardShortcut shortcut,
      AppCommandBindings bindings,
      NativeEvent event,
      Map<AppCommand, Boolean> maskedCommandsMap) {
    KeySequence keys = shortcut.getKeySequence();

    // If the shortcut manager is disabled, bail
    if (!isEnabled()) return false;

    // If we have no binding, bail
    if (!bindings.containsKey(keys)) return false;

    AppCommand command = bindings.getCommand(keys, editorMode_, maskedCommandsMap);
    if (command == null) return false;

    event.preventDefault();
    command.executeFromShortcut();
    return true;
  }
Esempio n. 29
0
  @Override
  public void onPreviewNativeEvent(Event.NativePreviewEvent event) {
    if (allActiveDialogs_.get(allActiveDialogs_.size() - 1) != this) return;

    if (event.getTypeInt() == Event.ONKEYDOWN) {
      NativeEvent nativeEvent = event.getNativeEvent();
      switch (nativeEvent.getKeyCode()) {
        case KeyCodes.KEY_ENTER:
          ThemedButton defaultButton =
              defaultOverrideButton_ == null ? okButton_ : defaultOverrideButton_;
          if ((defaultButton != null) && defaultButton.isEnabled()) {
            nativeEvent.preventDefault();
            nativeEvent.stopPropagation();
            event.cancel();
            defaultButton.click();
          }
          break;
        case KeyCodes.KEY_ESCAPE:
          if (escapeDisabled_) break;
          if (cancelButton_ == null) {
            if ((okButton_ != null) && okButton_.isEnabled()) {
              nativeEvent.preventDefault();
              nativeEvent.stopPropagation();
              event.cancel();
              okButton_.click();
            }
          } else if (cancelButton_.isEnabled()) {
            nativeEvent.preventDefault();
            nativeEvent.stopPropagation();
            event.cancel();
            cancelButton_.click();
          }
          break;
      }
    }
  }
Esempio n. 30
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;
      }
    }
  }