Example #1
0
  @Override
  public void actionPerformed(ActionEvent event) {
    final CurrentProject currentProject = appContext.getCurrentProject();

    if (currentProject == null || currentProject.getRootProject() == null) {
      return;
    }

    final ProjectDescriptor activeProject = currentProject.getRootProject();

    if (event.getParameters() == null) {
      Log.error(getClass(), localization.canNotOpenNodeWithoutParams());
      return;
    }

    final String path = event.getParameters().get(NODE_PARAM_ID);
    if (path == null || path.equals("")) {
      Log.error(getClass(), localization.nodeToOpenIsNotSpecified());
      return;
    }

    String nodePathToOpen =
        activeProject.getPath() + (!path.startsWith("/") ? "/".concat(path) : path);

    openNodeByPath(nodePathToOpen, currentProject, event);
  }
  public void openDeclaration() {
    EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
    if (activeEditor == null) {
      return;
    }

    if (!(activeEditor instanceof EmbeddedTextEditorPresenter)) {
      Log.error(getClass(), "Open Declaration support only EmbeddedTextEditorPresenter as editor");
      return;
    }
    EmbeddedTextEditorPresenter editor = ((EmbeddedTextEditorPresenter) activeEditor);
    int offset = editor.getCursorOffset();
    final VirtualFile file = editor.getEditorInput().getFile();
    Unmarshallable<OpenDeclarationDescriptor> unmarshaller =
        factory.newUnmarshaller(OpenDeclarationDescriptor.class);
    navigationService.findDeclaration(
        file.getProject().getProjectConfig().getPath(),
        JavaSourceFolderUtil.getFQNForFile(file),
        offset,
        new AsyncRequestCallback<OpenDeclarationDescriptor>(unmarshaller) {
          @Override
          protected void onSuccess(OpenDeclarationDescriptor result) {
            if (result != null) {
              handleDescriptor(result);
            }
          }

          @Override
          protected void onFailure(Throwable exception) {
            Log.error(OpenDeclarationFinder.class, exception);
          }
        });
  }
  public void handle(String endpointId, JsonRpcParams params) throws JsonRpcException {
    checkNotNull(endpointId, "Endpoint ID must not be null");
    checkArgument(!endpointId.isEmpty(), "Endpoint ID must not be empty");
    checkNotNull(params, "Params must not be null");

    Log.debug(getClass(), "Handling notification from: " + endpointId + ", with params: " + params);

    biOperation.apply(endpointId, params.getAs(paramsClass));
  }
 public void showMessage(final String message) {
   final CMDialogOptionsOverlay options = JavaScriptObject.createObject().cast();
   options.setBottom(true);
   final CMDialogOverlay dialog = this.editorOverlay.getDialog();
   if (dialog != null) {
     dialog.openNotification(message, options);
   } else {
     Log.info(CodeMirrorEditorWidget.class, message);
   }
 }
  /**
   * Define a function to be applied
   *
   * @param function function
   */
  public void withFunction(JsonRpcRequestBiFunction<P, R> function) {
    checkNotNull(function, "Request function must not be null");

    Log.debug(
        getClass(),
        "Configuring incoming request binary function for "
            + "method: "
            + method
            + ", "
            + "params object class: "
            + pClass
            + ", "
            + "result object class: "
            + rClass);

    RequestHandler handler = new RequestHandlerOneToOne<>(pClass, function, factory);
    registry.register(method, handler);
  }
  private void openFile(VirtualFile result, final OpenDeclarationDescriptor descriptor) {
    final Map<String, EditorPartPresenter> openedEditors = editorAgent.getOpenedEditors();
    Log.info(getClass(), result.getPath());
    if (openedEditors.containsKey(result.getPath())) {
      EditorPartPresenter editorPartPresenter = openedEditors.get(result.getPath());
      editorAgent.activateEditor(editorPartPresenter);
      fileOpened(editorPartPresenter, descriptor.getOffset());
    } else {
      editorAgent.openEditor(
          result,
          new EditorAgent.OpenEditorCallback() {
            @Override
            public void onEditorOpened(EditorPartPresenter editor) {
              fileOpened(editor, descriptor.getOffset());
            }

            @Override
            public void onEditorActivated(EditorPartPresenter editor) {}
          });
    }
  }
 private void selectKeymap(final Keymap keymap) {
   resetKeymap();
   Keymap usedKeymap = keymap;
   if (usedKeymap == null) {
     usedKeymap = CodeMirrorKeymaps.DEFAULT;
     selectDefaultKeymap();
   } else if (CodeMirrorKeymaps.DEFAULT.equals(usedKeymap)) {
     selectDefaultKeymap();
   } else if (CodeMirrorKeymaps.EMACS.equals(usedKeymap)) {
     selectEmacsKeymap();
   } else if (CodeMirrorKeymaps.VIM.equals(usedKeymap)) {
     selectVimKeymap();
   } else if (CodeMirrorKeymaps.SUBLIME.equals(usedKeymap)) {
     selectSublimeKeymap();
   } else {
     usedKeymap = CodeMirrorKeymaps.DEFAULT;
     selectDefaultKeymap();
     Log.error(
         CodeMirrorEditorWidget.class,
         "Unknown keymap: " + keymap + " - replacing by default one.");
   }
   this.keymap = usedKeymap;
 }
  /**
   * Adds command node to process tree and displays command output
   *
   * @param machineId id of machine in which the command will be executed
   * @param outputConsole the console for command output
   */
  public void addCommandOutput(@NotNull String machineId, @NotNull OutputConsole outputConsole) {
    ProcessTreeNode machineTreeNode = findProcessTreeNodeById(machineId);
    if (machineTreeNode == null) {
      notificationManager.notify(
          localizationConstant.failedToExecuteCommand(),
          localizationConstant.machineNotFound(machineId),
          FAIL,
          FLOAT_MODE);
      Log.error(getClass(), localizationConstant.machineNotFound(machineId));
      return;
    }

    String commandId;
    String outputConsoleTitle = outputConsole.getTitle();
    ProcessTreeNode processTreeNode = getProcessTreeNodeByName(outputConsoleTitle, machineTreeNode);
    if (processTreeNode != null && isCommandStopped(processTreeNode.getId())) {
      commandId = processTreeNode.getId();
      view.hideProcessOutput(commandId);
    } else {
      ProcessTreeNode commandNode =
          new ProcessTreeNode(
              COMMAND_NODE,
              machineTreeNode,
              outputConsoleTitle,
              outputConsole.getTitleIcon(),
              null);
      commandId = commandNode.getId();
      view.addProcessNode(commandNode);
      addChildToMachineNode(commandNode, machineTreeNode);
    }

    updateCommandOutput(commandId, outputConsole);

    resfreshStopButtonState(commandId);
    workspaceAgent.setActivePart(this);
  }