@Override
    public void onFinish(IUploader uploader) {

      String serverResponse = uploader.getServerInfo().message;
      if (serverResponse != null && !serverResponse.isEmpty()) {
        serverResponse = serverResponse.replaceAll("\n", "<br>");
        messagePresenter.showMessage("File Manager", serverResponse);
      }

      if (uploader.getStatus() == Status.SUCCESS) {
        uploader.getStatusWidget().setFileName("Done uploading.");
        fileTreePresenter.refresh(fileFilter);
      }

      // only needed when MultiUploader is used instead of SingleUploader. There somewhat of a new
      // instance of MultiUploader
      // is created for each additional upload.
      // try to avoid MultiUploader, it will create a new HTML element for each uploader making it
      // complex to style
      // also MultiUploader is not needed, in comparison to SingleUploader it only allows to append
      // additional uploads once
      // a previous upload is still running. It doesn't mean multiple files, this can also be done
      // with SingleUploader
      /*IFileInput ctrl = display.getUploader().getFileInput();
      DOM.setElementProperty(((UIObject) ctrl).getElement(), "multiple", "multiple");*/

      uploader.setServletPath(defaultServletPath);
      enableManagement();
    }
Example #2
0
  private boolean controleUpload(IUploader uploader, final StringBuilder messageToReturn) {

    // controle
    String baseName = uploader.getBasename();
    baseName = (baseName == null) ? null : baseName.trim().toLowerCase();
    log.config("baseName: " + baseName);
    if (baseName == null
        || baseName.length() == 0
        || !(baseName.endsWith(Constantes.EXTENSION_ZIP)
            || baseName.endsWith(Constantes.EXTENSION_JAR))) {
      log.severe("annulation du téléchargement!");
      uploader.cancel();
      messageToReturn.append(
          "Le fichier choisi n'existe pas ou bien n'est pas une archive zip ou jar!");
      return false;
    }

    log.config("File url " + uploader.fileUrl());

    // The server sends useful information to the client by default
    UploadedInfo info = uploader.getServerInfo();
    if (info != null) {
      log.config("File name " + info.name);
      log.config("File content-type " + info.ctype);
      log.config("File size " + info.size);
    }
    return true;
  }
Example #3
0
  @Override
  public void onFinish(IUploader uploader) {

    if (uploader.getStatus().equals(Status.SUCCESS)) {

      UploadedInfo info = uploader.getServerInfo();
      if (info != null && info.message != null && !info.message.equals("noid")) {
        String entityId = info.message;

        BinaryRequest binaryRequest = requestFactory.binaryRequest();
        Request<BinaryProxy> binaryFileRequest = binaryRequest.getBinary(entityId);

        binaryFileRequest.fire(
            new Receiver<BinaryProxy>() {
              @Override
              public void onSuccess(BinaryProxy response) {
                value = response;
                uploading = false;
              }

              @Override
              public void onFailure(ServerFailure error) {
                Window.alert("Error retrieving the Binary Description");
                super.onFailure(error);
              }
            });

        if (thumbnail != null && info.ctype.contains("image")) {
          // Attach thumbnail
          OnLoadPreloadedImageHandler showImage =
              new OnLoadPreloadedImageHandler() {
                public void onLoad(PreloadedImage image) {
                  thumbnail.setUrl(image.getUrl());
                }
              };
          new PreloadedImage("servlet.gupld?show=" + entityId, showImage);
        }
      }
    }
    if (uploader.getStatus().equals(Status.CANCELED)) {
      setNew();
    }
  }
Example #4
0
  private void getDataFromServer(
      final Action action, final ActionState state, final Object object) {

    if (log.isLoggable(Level.INFO)) {
      log.info(
          "getDataFromServer: action "
              + action
              + " - state: "
              + state
              + ((object == null) ? "" : " - object: " + object.toString()));
    }
    AppController.getInstance().done(Action.clearStatus);

    switch (action) {
      case uploadContent:
        switch (state) {
          case done:
            AppController.getInstance().reinit();
            getDataFromServer(Action.buildApplicationFromContent);
            this._projectName = object.toString();
            this.displayPanels();
            break;
        }
        break;

      case uploadZip:

        // controle
        IUploader uploader = null;
        if (state != ActionState.error && object != null && object instanceof IUploader) {
          uploader = (IUploader) object;
          final StringBuilder errorMessage = new StringBuilder();
          if (!controleUpload(uploader, errorMessage)) {
            getDataFromServer(Action.uploadZip, ActionState.error, errorMessage.toString());
            break;
          }
        }

        switch (state) {
          case start:
            _projectName = null;
            AppController.getInstance().reinit();
            AppController.getInstance().inProgress(action);
            break;

          case done:
            if (uploader.getStatus() == Status.SUCCESS) {

              AppController.getInstance().done(action);
              _projectName = uploader.getServerInfo().name;
              displayPanels();

              // You can send any customized message and parse it
              log.config("Server message " + uploader.getServerInfo().message);

              getDataFromServer(Action.buildApplication);
            }
            break;

          case cancel:
            AppController.getInstance().done(Action.uploadZip, "Interruption par l'utilisateur");
            _projectName = null;
            displayPanels();
            break;

          case error:
            AppController.getInstance()
                .error(Action.uploadZip, (object == null) ? "erreur inconnue!" : object.toString());
            break;
        }

        break;

      case loadModules:
        AppController.getInstance().inProgress(action);
        AppController.getService()
            .loadModules(
                new ServiceCallback<List<ModuleLightDto>>(action) {

                  @Override
                  public void onSuccess(List<ModuleLightDto> result) {
                    _tableModules.populateGrid(result);
                    AppController.getInstance().done(action);
                  }
                });
        break;

      case buildApplication:
        {
          AppController.getInstance().inProgress(action);
          AppController.getService()
              .buildApplication(
                  this.getSourceDir(),
                  new ServiceCallback<Boolean>(action) {

                    @Override
                    public void onSuccess(Boolean result) {
                      AppController.getInstance().done(action);
                      getDataFromServer(Action.loadModules);
                    }
                  });
          break;
        }

      case buildApplicationFromContent:
        {
          AppController.getInstance().inProgress(action);
          AppController.getInstance().inProgress(action);
          AppController.getService()
              .buildApplicationFromMapContent(
                  this.getSourceDir(),
                  new ServiceCallback<Boolean>(action) {

                    @Override
                    public void onSuccess(Boolean result) {
                      AppController.getInstance().done(action);
                      getDataFromServer(Action.loadModules);
                    }
                  });
          break;
        }

      case buildDemo:
        _projectName = "démo";

        AppController.getInstance().reinit();
        AppController.getInstance().inProgress(action);
        AppController.getService()
            .buildDemo(
                new ServiceCallback<Boolean>(action) {

                  @Override
                  public void onSuccess(Boolean result) {
                    AppController.getInstance().done(action);
                    displayPanels();
                    getDataFromServer(Action.loadModules);
                  }
                });
        break;
    }
  }