/** Need to remove failed uploaded keys from local storage if they can't be uploaded to github */
  private void getFailedKey(final String host) {
    service.getAllKeys(
        new AsyncRequestCallback<Array<KeyItem>>(
            dtoUnmarshallerFactory.newArrayUnmarshaller(KeyItem.class)) {
          @Override
          public void onSuccess(Array<KeyItem> result) {
            loader.hide(constant.loaderGetSshKeysMessage());
            for (int i = 0; i < result.size(); i++) {
              KeyItem key = result.get(i);
              if (key.getHost().equals(host)) {
                removeFailedKey(key);
                return;
              }
            }
            refreshKeys();
          }

          @Override
          public void onFailure(Throwable exception) {
            loader.hide(constant.loaderGetSshKeysMessage());
            refreshKeys();
            notificationManager.showError(exception.getMessage());
            eventBus.fireEvent(new ExceptionThrownEvent(exception));
          }
        });
  }
  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);
          }
        });
  }
 @Override
 public Promise<WorkspaceDto> update(String wsId, WorkspaceDto workspaceDto) {
   final String url = baseHttpUrl + '/' + wsId;
   return asyncRequestFactory
       .createPutRequest(url, workspaceDto)
       .send(dtoUnmarshallerFactory.newUnmarshaller(WorkspaceDto.class));
 }
Exemple #4
0
  /** Get the list of branches. */
  private void getBranches() {
    service.branchList(
        workspaceId,
        project.getRootProject(),
        LIST_ALL,
        new AsyncRequestCallback<List<Branch>>(
            dtoUnmarshallerFactory.newListUnmarshaller(Branch.class)) {
          @Override
          protected void onSuccess(List<Branch> result) {
            view.setBranches(result);
            view.showDialogIfClosed();
          }

          @Override
          protected void onFailure(Throwable exception) {
            final String errorMessage =
                (exception.getMessage() != null)
                    ? exception.getMessage()
                    : constant.branchesListFailed();
            final GitOutputConsole console =
                gitOutputConsoleFactory.create(BRANCH_LIST_COMMAND_NAME);
            console.printError(errorMessage);
            consolesPanelPresenter.addCommandOutput(appContext.getDevMachineId(), console);
            notificationManager.notify(
                constant.branchesListFailed(), FAIL, true, project.getRootProject());
          }
        });
  }
  private void setupProposals(
      final CodeAssistCallback callback,
      final TextEditor textEditor,
      final int offset,
      final List<Problem> annotations) {
    final VirtualFile file = textEditor.getEditorInput().getFile();
    final String projectPath = file.getProject().getProjectConfig().getPath();
    String fqn = JavaSourceFolderUtil.getFQNForFile(file);
    Unmarshallable<Proposals> unmarshaller = unmarshallerFactory.newUnmarshaller(Proposals.class);
    client.computeAssistProposals(
        projectPath,
        fqn,
        offset,
        annotations,
        new AsyncRequestCallback<Proposals>(unmarshaller) {
          @Override
          protected void onSuccess(Proposals proposals) {
            showProposals(callback, proposals, textEditor);
          }

          @Override
          protected void onFailure(Throwable throwable) {
            Log.error(JavaCodeAssistProcessor.class, throwable);
          }
        });
  }
 private void getWorkspaces(@NotNull AsyncCallback<List<WorkspaceDto>> callback) {
   final String url = baseHttpUrl;
   asyncRequestFactory
       .createGetRequest(url)
       .header(ACCEPT, APPLICATION_JSON)
       .loader(loaderFactory.newLoader("Getting info about workspaces..."))
       .send(
           newCallback(callback, dtoUnmarshallerFactory.newListUnmarshaller(WorkspaceDto.class)));
 }
 @Override
 public Promise<WorkspaceDto> addEnvironment(String wsId, EnvironmentDto newEnv) {
   return asyncRequestFactory
       .createPostRequest(baseHttpUrl + '/' + wsId + "/environment", newEnv)
       .header(ACCEPT, APPLICATION_JSON)
       .header(CONTENT_TYPE, APPLICATION_JSON)
       .loader(loaderFactory.newLoader("Adding environment..."))
       .send(dtoUnmarshallerFactory.newUnmarshaller(WorkspaceDto.class));
 }
 private void deleteCommand(
     @NotNull final String wsId,
     @NotNull final String commandName,
     @NotNull AsyncCallback<WorkspaceDto> callback) {
   final String url = baseHttpUrl + '/' + wsId + "/command/" + commandName;
   asyncRequestFactory
       .createDeleteRequest(url)
       .header(ACCEPT, APPLICATION_JSON)
       .loader(loaderFactory.newLoader("Deleting command..."))
       .send(newCallback(callback, dtoUnmarshallerFactory.newUnmarshaller(WorkspaceDto.class)));
 }
 private void startWorkspace(
     @NotNull WorkspaceConfigDto cfg,
     @NotNull String accountId,
     @NotNull AsyncCallback<WorkspaceDto> callback) {
   asyncRequestFactory
       .createPostRequest(baseHttpUrl + "/runtime", cfg)
       .header(ACCEPT, APPLICATION_JSON)
       .header(CONTENT_TYPE, APPLICATION_JSON)
       .loader(loaderFactory.newLoader("Creating machine from recipe..."))
       .send(newCallback(callback, dtoUnmarshallerFactory.newUnmarshaller(WorkspaceDto.class)));
 }
 private void addCommand(
     @NotNull final String wsId,
     @NotNull final CommandDto newCommand,
     @NotNull AsyncCallback<WorkspaceDto> callback) {
   final String url = baseHttpUrl + '/' + wsId + "/command";
   asyncRequestFactory
       .createPostRequest(url, newCommand)
       .header(ACCEPT, APPLICATION_JSON)
       .header(CONTENT_TYPE, APPLICATION_JSON)
       .loader(loaderFactory.newLoader("Adding command..."))
       .send(newCallback(callback, dtoUnmarshallerFactory.newUnmarshaller(WorkspaceDto.class)));
 }
 private void createMachine(
     @NotNull String wsId,
     @NotNull MachineConfigDto newMachine,
     @NotNull AsyncCallback<MachineDto> callback) {
   String url = baseHttpUrl + '/' + wsId + "/machine";
   asyncRequestFactory
       .createPostRequest(url, newMachine)
       .header(ACCEPT, APPLICATION_JSON)
       .header(CONTENT_TYPE, APPLICATION_JSON)
       .loader(loaderFactory.newLoader("Creating machine..."))
       .send(newCallback(callback, dtoUnmarshallerFactory.newUnmarshaller(MachineDto.class)));
 }
 private void updateCommand(
     @NotNull final String wsId,
     @NotNull final CommandDto commandUpdate,
     final String commandName,
     @NotNull AsyncCallback<WorkspaceDto> callback) {
   final String url = baseHttpUrl + '/' + wsId + "/command/" + commandName;
   asyncRequestFactory
       .createRequest(PUT, url, commandUpdate, false)
       .header(ACCEPT, APPLICATION_JSON)
       .header(CONTENT_TYPE, APPLICATION_JSON)
       .loader(loaderFactory.newLoader("Updating command..."))
       .send(newCallback(callback, dtoUnmarshallerFactory.newUnmarshaller(WorkspaceDto.class)));
 }
 private void startById(
     @NotNull String workspaceId,
     @Nullable String envName,
     @NotNull AsyncCallback<WorkspaceDto> callback) {
   String url = baseHttpUrl + "/" + workspaceId + "/runtime";
   if (envName != null) {
     url += "?environment=" + envName;
   }
   asyncRequestFactory
       .createPostRequest(url, null)
       .header(ACCEPT, APPLICATION_JSON)
       .header(CONTENT_TYPE, APPLICATION_JSON)
       .loader(loaderFactory.newLoader("Starting workspace..."))
       .send(newCallback(callback, dtoUnmarshallerFactory.newUnmarshaller(WorkspaceDto.class)));
 }
 private void create(
     @NotNull WorkspaceConfigDto newWorkspace,
     String accountId,
     @NotNull AsyncCallback<WorkspaceDto> callback) {
   String url = baseHttpUrl;
   if (accountId != null) {
     url += "?account=" + accountId;
   }
   asyncRequestFactory
       .createPostRequest(url, newWorkspace)
       .header(ACCEPT, APPLICATION_JSON)
       .header(CONTENT_TYPE, APPLICATION_JSON)
       .loader(loaderFactory.newLoader("Creating workspace..."))
       .send(newCallback(callback, dtoUnmarshallerFactory.newUnmarshaller(WorkspaceDto.class)));
 }
  /**
   * Updates additional information about current machine.
   *
   * @param machine machine for which need update panel
   */
  public void update(@NotNull MachineEntity machine) {

    Unmarshallable<ProfileDto> profileUnMarshaller =
        unmarshallerFactory.newUnmarshaller(ProfileDto.class);

    userProfile.getCurrentProfile(
        new AsyncRequestCallback<ProfileDto>(profileUnMarshaller) {
          @Override
          protected void onSuccess(ProfileDto result) {
            Map<String, String> attributes = result.getAttributes();

            String firstName = attributes.get(FIRST_NAME_KEY);
            String lastName = attributes.get(LAST_NAME_KEY);

            String fullName = firstName + ' ' + lastName;

            String email = attributes.get(EMAIL_KEY);

            boolean isNameExist = !firstName.equals("undefined") && !lastName.equals("<none>");

            view.setOwner(isNameExist ? fullName : email);
          }

          @Override
          protected void onFailure(Throwable exception) {
            Log.error(getClass(), exception);
          }
        });

    wsService
        .getWorkspace(machine.getWorkspaceId())
        .then(
            new Operation<WorkspaceDto>() {
              @Override
              public void apply(WorkspaceDto ws) throws OperationException {
                view.setWorkspaceName(ws.getConfig().getName());
              }
            })
        .catchError(
            new Operation<PromiseError>() {
              @Override
              public void apply(PromiseError err) throws OperationException {
                Log.error(getClass(), err.getCause());
              }
            });

    view.updateInfo(machine);
  }
  /** Refresh ssh keys. */
  private void refreshKeys() {
    service.getAllKeys(
        new AsyncRequestCallback<Array<KeyItem>>(
            dtoUnmarshallerFactory.newArrayUnmarshaller(KeyItem.class)) {
          @Override
          public void onSuccess(Array<KeyItem> result) {
            loader.hide(constant.loaderGetSshKeysMessage());
            view.setKeys(result);
          }

          @Override
          public void onFailure(Throwable exception) {
            loader.hide(constant.loaderGetSshKeysMessage());
            notificationManager.showError(exception.getMessage());
            eventBus.fireEvent(new ExceptionThrownEvent(exception));
          }
        });
  }
  /** Show dialog. */
  public void showDialog() {
    service.log(
        appContext.getDevMachine(),
        appContext.getCurrentProject().getRootProject(),
        null,
        false,
        new AsyncRequestCallback<LogResponse>(
            dtoUnmarshallerFactory.newUnmarshaller(LogResponse.class)) {
          @Override
          protected void onSuccess(LogResponse result) {
            view.setRevisions(result.getCommits());
            view.setMixMode(true);
            view.setEnableResetButton(selectedRevision != null);
            view.showDialog();
          }

          @Override
          protected void onFailure(Throwable exception) {
            if (getErrorCode(exception) == ErrorCodes.INIT_COMMIT_WAS_NOT_PERFORMED) {
              dialogFactory
                  .createMessageDialog(
                      constant.resetCommitViewTitle(), constant.initCommitWasNotPerformed(), null)
                  .show();
              return;
            }
            String errorMessage =
                (exception.getMessage() != null) ? exception.getMessage() : constant.logFailed();
            GitOutputConsole console = gitOutputConsoleFactory.create(LOG_COMMAND_NAME);
            console.printError(errorMessage);
            consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
            notificationManager.notify(
                constant.logFailed(),
                FAIL,
                FLOAT_MODE,
                appContext.getCurrentProject().getRootProject());
          }
        });
  }
  /** {@inheritDoc} */
  @Override
  public void onViewClicked(@Nonnull final KeyItem key) {
    service.getPublicKey(
        key,
        new AsyncRequestCallback<PublicKey>(
            dtoUnmarshallerFactory.newUnmarshaller(PublicKey.class)) {
          @Override
          public void onSuccess(PublicKey result) {
            loader.hide(constant.loaderGetPublicSshKeyMessage(key.getHost()));
            dialogFactory
                .createMessageDialog(
                    constant.publicSshKeyField() + key.getHost(), result.getKey(), null)
                .show();
          }

          @Override
          public void onFailure(Throwable exception) {
            loader.hide(constant.loaderGetPublicSshKeyMessage(key.getHost()));
            notificationManager.showError(
                SafeHtmlUtils.fromString(exception.getMessage()).asString());
            eventBus.fireEvent(new ExceptionThrownEvent(exception));
          }
        });
  }
Exemple #19
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));
            }
          });
    }
  }