예제 #1
0
  private void handleDescriptor(final OpenDeclarationDescriptor descriptor) {
    Map<String, EditorPartPresenter> openedEditors = editorAgent.getOpenedEditors();
    for (String s : openedEditors.keySet()) {
      if (descriptor.getPath().equals(s)) {
        EditorPartPresenter editorPartPresenter = openedEditors.get(s);
        editorAgent.activateEditor(editorPartPresenter);
        fileOpened(editorPartPresenter, descriptor.getOffset());
        return;
      }
    }

    if (descriptor.isBinary()) {
      javaNodeManager
          .getClassNode(
              context.getCurrentProject().getProjectConfig(),
              descriptor.getLibId(),
              descriptor.getPath())
          .then(
              new Operation<Node>() {
                @Override
                public void apply(Node node) throws OperationException {
                  if (node instanceof VirtualFile) {
                    openFile((VirtualFile) node, descriptor);
                  }
                }
              });
    } else {
      projectExplorer
          .getNodeByPath(new HasStorablePath.StorablePath(descriptor.getPath()))
          .then(selectNode())
          .then(openNode(descriptor));
    }
  }
예제 #2
0
  @Override
  public void actionPerformed() {
    if (compilationUnit != null) {
      EditorPartPresenter editorPartPresenter =
          editorAgent.getOpenedEditor(Path.valueOf(compilationUnit.getPath()));
      if (editorPartPresenter != null) {
        editorAgent.activateEditor(editorPartPresenter);
        fileOpened(editorPartPresenter);
        return;
      }

      projectExplorer
          .getNodeByPath(new HasStorablePath.StorablePath(compilationUnit.getPath()))
          .then(selectNode())
          .then(openNode());
    } else if (classFile != null) {
      String className = classFile.getElementName();

      JarEntry jarEntry = dtoFactory.createDto(JarEntry.class);
      jarEntry.setName(className);
      jarEntry.setType(JarEntry.JarEntryType.CLASS_FILE);
      jarEntry.setPath(classFile.getPath());

      JarFileNode jarFileNode =
          javaNodeManager
              .getJavaNodeFactory()
              .newJarFileNode(
                  jarEntry,
                  null,
                  appContext.getCurrentProject().getProjectConfig(),
                  javaNodeManager.getJavaSettingsProvider().getSettings());
      openFile(jarFileNode);
    }
  }
예제 #3
0
  public void openFile(final String filePath, final TextRange selectionRange) {
    if (Strings.isNullOrEmpty(filePath)) {
      return;
    }

    EditorPartPresenter editorPartPresenter = editorAgent.getOpenedEditor(Path.valueOf(filePath));
    if (editorPartPresenter != null) {
      editorAgent.activateEditor(editorPartPresenter);
      fileOpened(editorPartPresenter, selectionRange);
      return;
    }

    appContext.getWorkspaceRoot().getFile(filePath).then(openNode(selectionRange));
  }
예제 #4
0
  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);
          }
        });
  }
예제 #5
0
 private void openFile(VirtualFile result, final TextRange selectionRange) {
   editorAgent.openEditor(
       result,
       new OpenEditorCallbackImpl() {
         @Override
         public void onEditorOpened(EditorPartPresenter editor) {
           fileOpened(editor, selectionRange);
         }
       });
 }
예제 #6
0
 private void openFile(VirtualFile result) {
   editorAgent.openEditor(
       result,
       new OpenEditorCallbackImpl() {
         @Override
         public void onEditorOpened(EditorPartPresenter editor) {
           fileOpened(editor);
         }
       });
 }
예제 #7
0
  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) {}
          });
    }
  }
  @Override
  public List<ActionDescriptor> getActions(String projectPath) {
    EditorAgent editorAgent = editorAgentProvider.get();
    EditorPartPresenter activeEditor = editorAgent.getActiveEditor();

    final List<ActionDescriptor> actions = new ArrayList<>();

    if (activeEditor == null) {
      return Collections.emptyList();
    }

    VirtualFile virtualFile = activeEditor.getEditorInput().getFile();

    String openNodeActionId = actionManager.getId(openFileAction);

    actions.add(
        dtoFactory
            .createDto(ActionDescriptor.class)
            .withId(openNodeActionId)
            .withParameters(Collections.singletonMap(FILE_PARAM_ID, virtualFile.getPath())));
    return actions;
  }
예제 #9
0
  private void updateOpenedFiles() {
    for (EditorPartPresenter editorPartPresenter : editorAgent.getOpenedEditors().values()) {
      final VirtualFile file = editorPartPresenter.getEditorInput().getFile();
      final String filePath = file.getPath();
      Unmarshallable<ItemReference> unmarshaller =
          dtoUnmarshallerFactory.newUnmarshaller(ItemReference.class);

      projectService.getItem(
          workspaceId,
          filePath,
          new AsyncRequestCallback<org.eclipse.che.api.project.shared.dto.ItemReference>(
              unmarshaller) {
            @Override
            protected void onSuccess(ItemReference itemReference) {
              eventBus.fireEvent(new FileContentUpdateEvent(filePath));
            }

            @Override
            protected void onFailure(Throwable throwable) {
              eventBus.fireEvent(new FileEvent(file, FileEvent.FileOperation.CLOSE));
            }
          });
    }
  }