Beispiel #1
0
  @Override
  public Promise<Void> promise(final ActionEvent event) {
    final CurrentProject currentProject = appContext.getCurrentProject();

    if (currentProject == null) {
      return Promises.reject(JsPromiseError.create(localization.noOpenedProject()));
    }

    final Call<Void, Throwable> call =
        new Call<Void, Throwable>() {

          private HandlerRegistration handlerRegistration;

          @Override
          public void makeCall(final Callback<Void, Throwable> callback) {
            actionCompletedCallBack = callback;

            handlerRegistration =
                eventBus.addHandler(
                    NodeExpandedEvent.TYPE,
                    new NodeExpandedEventHandler() {
                      @Override
                      public void onNodeExpanded() {
                        handlerRegistration.removeHandler();
                        callback.onSuccess(null);
                      }
                    });

            actionPerformed(event);
          }
        };

    return createFromCallback(call);
  }
  @Override
  public Promise<Void> promise(final ActionEvent event) {
    if (event.getParameters() == null
        || event.getParameters().get(SHOW_HIDDEN_FILES_PARAM_ID) == null) {
      return Promises.reject(
          JsPromiseError.create(
              "Mandatory parameter" + SHOW_HIDDEN_FILES_PARAM_ID + " is not specified"));
    }

    final String showHiddenFilesKey = event.getParameters().get(SHOW_HIDDEN_FILES_PARAM_ID);
    final boolean isShowHiddenFiles = Boolean.valueOf(showHiddenFilesKey);

    final CallbackPromiseHelper.Call<Void, Throwable> call =
        new CallbackPromiseHelper.Call<Void, Throwable>() {

          @Override
          public void makeCall(final Callback<Void, Throwable> callback) {
            projectExplorerPresenter.showHiddenFiles(isShowHiddenFiles);

            callback.onSuccess(null);
          }
        };

    return createFromCallback(call);
  }
  @Override
  public void onSaveClicked() {
    for (PreferencePagePresenter preference : preferences) {
      if (preference.isDirty()) {
        preference.storeChanges();
      }
    }

    Promise<Void> promise = Promises.resolve(null);
    final List<PromiseError> promiseErrorList = new ArrayList<>();

    for (final PreferencesManager preferencesManager : managers) {
      promise =
          promise.thenPromise(
              new Function<Void, Promise<Void>>() {
                @Override
                public Promise<Void> apply(Void arg) throws FunctionException {
                  return preferencesManager
                      .flushPreferences()
                      .catchError(
                          new Operation<PromiseError>() {
                            @Override
                            public void apply(PromiseError error) throws OperationException {
                              notificationManagerProvider
                                  .get()
                                  .notify(
                                      locale.unableToSavePreference(),
                                      error.getMessage(),
                                      FAIL,
                                      true);
                              promiseErrorList.add(error);
                            }
                          });
                }
              });
    }

    promise.then(
        new Operation<Void>() {
          @Override
          public void apply(Void aVoid) throws OperationException {
            if (promiseErrorList.isEmpty()) {
              view.enableSaveButton(false);
            }
          }
        });
  }
  @Override
  public void onRefreshClicked() {
    Promise<Map<String, String>> promise = Promises.resolve(null);
    for (final PreferencesManager preferencesManager : managers) {
      promise =
          promise.thenPromise(
              new Function<Map<String, String>, Promise<Map<String, String>>>() {
                @Override
                public Promise<Map<String, String>> apply(Map<String, String> arg)
                    throws FunctionException {
                  return preferencesManager
                      .loadPreferences()
                      .catchError(
                          new Operation<PromiseError>() {
                            @Override
                            public void apply(PromiseError error) throws OperationException {
                              notificationManagerProvider
                                  .get()
                                  .notify(
                                      locale.unableToLoadPreference(),
                                      error.getMessage(),
                                      FAIL,
                                      true);
                            }
                          });
                }
              });
    }

    /** Revert changes on every preference page */
    promise.then(
        new Operation<Map<String, String>>() {
          @Override
          public void apply(Map<String, String> arg) throws OperationException {
            for (PreferencePagePresenter p : PreferencesPresenter.this.preferences) {
              p.revertChanges();
            }
          }
        });
  }
 @Override
 public Promise<List<Node>> intercept(Node parent, List<Node> children) {
   Iterable<Node> nodes = Iterables.transform(children, intercept(parent));
   List<Node> nodeList = Lists.newArrayList(nodes);
   return Promises.resolve(nodeList);
 }
  @Override
  public void onDeployClicked() {
    Promise<Project> projectPromise;
    view.showLoader(true);
    switch (view.getMode()) {
      case CREATE_NEW_PROJECT:
        String osProjectName = view.getOpenShiftProjectName();
        String osProjectDisplayName = view.getOpenShiftProjectDisplayName();
        String osProjectDescription = view.getOpenShiftProjectDescription();
        // create new project
        ProjectRequest request =
            newDto(ProjectRequest.class)
                .withApiVersion(API_VERSION)
                .withDisplayName(osProjectDisplayName)
                .withDescription(osProjectDescription)
                .withMetadata(newDto(ObjectMeta.class).withName(osProjectName));
        projectPromise = osService.createProject(request);
        break;
      case SELECT_EXISTING_PROJECT:
      default:
        Project osSelectedProject = view.getOpenShiftSelectedProject();
        projectPromise = Promises.resolve(osSelectedProject);
    }

    projectPromise
        .then(
            new Operation<Project>() {
              @Override
              public void apply(final Project project) throws OperationException {
                final Map<String, String> labels = new HashMap<>();
                labels.put("generatedby", "Che");
                labels.put("application", osAppName);

                for (KeyValue label : view.getLabels()) {
                  labels.put(label.getKey(), label.getValue());
                }

                final DockerImageMetadata imageMetadata =
                    osActiveStreamTag.getImage().getDockerImageMetadata();
                Object exposedPorts =
                    (imageMetadata.getConfig() != null)
                        ? imageMetadata.getConfig().getExposedPorts()
                        : imageMetadata.getContainerConfig().getExposedPorts();
                List<ContainerPort> ports = parsePorts(exposedPorts);

                String namespace = project.getMetadata().getName();
                List<Promise<?>> promises = new ArrayList<>();
                promises.add(osService.createImageStream(generateImageStream(namespace, labels)));
                promises.add(osService.createBuildConfig(generateBuildConfig(namespace, labels)));
                promises.add(
                    osService.createDeploymentConfig(generateDeploymentConfig(namespace, labels)));
                promises.add(osService.createRoute(generateRoute(namespace, labels)));

                if (!ports.isEmpty()) {
                  promises.add(
                      osService.createService(
                          generateService(namespace, getFirstPort(ports), labels)));
                }

                Promises.all(promises.toArray(new Promise[promises.size()]))
                    .then(
                        new Operation<JsArrayMixed>() {
                          @Override
                          public void apply(JsArrayMixed arg) throws OperationException {
                            view.showLoader(false);
                            view.hide();
                            notificationManager.notify(
                                locale.deployProjectSuccess(
                                    appContext.getCurrentProject().getRootProject().getName()),
                                SUCCESS,
                                true);
                            setupMixin(project);
                          }
                        })
                    .catchError(
                        new Operation<PromiseError>() {
                          @Override
                          public void apply(PromiseError arg) throws OperationException {
                            handleError(arg);
                          }
                        });
              }
            })
        .catchError(
            new Operation<PromiseError>() {
              @Override
              public void apply(PromiseError arg) throws OperationException {
                handleError(arg);
              }
            });
  }