/** orion text setfocus */
 protected void setOrionTextFocus() {
   try {
     browserEditor.evaluate(EditorFunctionService.SET_FOCUS);
   } catch (Exception e) {
     // ignore exception
   }
 }
  /**
   * browser function call
   *
   * @param command brower command
   * @param args command argument
   */
  public void browserEvaluate(String command, String... args) {
    if (logger.isDebugEnabled()) {
      logger.debug("\t ### send command is : [command] " + command + ", [args]" + args);
    }

    try {
      browserEditor.evaluate(String.format(command, TadpoleEditorUtils.makeGrantArgs(args)));
    } catch (Exception e) {
      logger.error("browser evaluate [ " + command + " ]\r\n", e); // $NON-NLS-1$ //$NON-NLS-2$
    }
  }
  private Object evaluate(String function, Object... arguments) {
    String script = buildFunctionCall(function, arguments);
    //		for (int i = 0; i < EVALUATE_ATTEMPTS; i++) {
    //			try {
    return browser.evaluate(script);
    //			} catch (Exception ex) {
    //				logger.debug(ex.getMessage(), ex);
    //			}
    //		}

    //		throw new IllegalStateException(SCRIPT_EVALUATION_FAILED + script);
  }
  /**
   * @param command
   * @param args
   * @return
   */
  public String browserEvaluateToStr(String command, String... args) {
    if (logger.isDebugEnabled()) {
      logger.debug("\t ### send command is : " + command);
    }

    try {
      Object ret =
          browserEditor.evaluate(String.format(command, TadpoleEditorUtils.makeGrantArgs(args)));
      return ret.toString();
    } catch (Exception e) {
      logger.error("browser evaluate [ " + command + " ]\r\n", e); // $NON-NLS-1$ //$NON-NLS-2$
    }

    return "";
  }
 public String getText() {
   return (String) browser.evaluate("return getEditorContent();"); // $NON-NLS-1$
 }
示例#6
0
 @Override
 public String getText() {
   return (String) browser.evaluate("return getText();"); // $NON-NLS-1$
 }
示例#7
0
  public static void navigateToVisual(
      IEditorPart currentEditor, Browser browser, VpvVisualModel visualModel, int x, int y) {
    String stringToEvaluate = ""; // $NON-NLS-1$
    if (OS.LINUX.equals(PlatformUtil.getOs())) {
      /* outerHTML is not available with XulRunner we shipping, so <code>result</code> variable will be null
       * because we make it default browser on Linux this workaround is used
       * @see JBIDE-17454
       */
      stringToEvaluate =
          "var selected = document.elementFromPoint("
              + x
              + ", "
              + y
              + ");"
              + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
              "var temp = document.createElement('div');"
              + //$NON-NLS-1$
              "temp.appendChild(selected.cloneNode(true));"
              + //$NON-NLS-1$
              "return temp.innerHTML;"; //$NON-NLS-1$
    } else {
      stringToEvaluate =
          "return document.elementFromPoint("
              + x
              + ", "
              + y
              + ").outerHTML;"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    }
    String result = (String) browser.evaluate(stringToEvaluate);
    if (result != null) {
      String selectedElementId =
          TransformUtil.getSelectedElementId(result, "(?<=data-vpvid=\").*?(?=\")"); // $NON-NLS-1$

      Long id =
          (selectedElementId != null
                  && !selectedElementId.isEmpty()) // avoiding NumberFormatException
              ? Long.parseLong(selectedElementId)
              : null;
      NavigationUtil.outlineSelectedElement(browser, id);

      String fileExtension = EditorUtil.getFileExtensionFromEditor(currentEditor);

      if (SuitableFileExtensions.isHTML(fileExtension)) {
        try {
          Node visualNode = TransformUtil.getVisualNodeByVpvId(visualModel, selectedElementId);
          Node sourseNode = TransformUtil.getSourseNodeByVisualNode(visualModel, visualNode);

          if (sourseNode != null && sourseNode instanceof IDOMNode) {
            int startOffset = ((IDOMNode) sourseNode).getStartOffset();
            int endOffset = ((IDOMNode) sourseNode).getEndOffset();

            StructuredTextEditor editor =
                (StructuredTextEditor) currentEditor.getAdapter(StructuredTextEditor.class);
            editor.selectAndReveal(startOffset, endOffset - startOffset);
          }

        } catch (XPathExpressionException e) {
          Activator.logError(e);
        }
      }
    }
  }