Esempio n. 1
0
  private void handleRestoreRequest(RestoreRequest restoreRequest) {
    RestoreOperationOptions restoreOptions = new RestoreOperationOptions();

    restoreOptions.setFileHistoryId(FileHistoryId.parseFileId(restoreRequest.getFileHistoryId()));
    restoreOptions.setFileVersion(restoreRequest.getVersion());

    try {
      RestoreOperationResult restoreResult = new RestoreOperation(config, restoreOptions).execute();

      RestoreResponse restoreResponse =
          new RestoreResponse(restoreRequest.getId(), restoreResult.getTargetFile());
      eventBus.post(restoreResponse);
    } catch (Exception e) {
      logger.log(Level.WARNING, "BadRequestResponse: Cannot restore file.");
      eventBus.post(new BadRequestResponse(restoreRequest.getId(), "Cannot restore file."));
    }
  }
  private void updateRestoreStatus(
      RestoreFolderRequest restoreRequest, RestoreFolderResponse restoreResponse) {
    RestoreOperationResult restoreResult = restoreResponse.getResult();
    RestoreResultCode restoreResultCode = restoreResult.getResultCode();

    // Set labels/status
    restoreButton.setEnabled(true);
    restoreStatusIconComposite.setVisible(true);
    restoreStatusTextLabel.setVisible(true);

    if (restoreResultCode == RestoreResultCode.ACK) {
      String shortFileName = shortenFileName(restoreResult.getTargetFile().getAbsolutePath());
      logger.log(
          Level.INFO,
          "Detail panel: Restore successful, file restored to "
              + restoreResult.getTargetFile().toString());

      restoreStatusIconComposite.setImage(
          SWTResourceManager.getImage(String.format(IMAGE_RESOURCE_FORMAT, "success")));
      restoreStatusTextLabel.setText(
          I18n.getText(
              "org.syncany.gui.history.DetailPanel.label.fileRestoreSuccess", shortFileName));
      restoreStatusTextLabel.setCursor(new Cursor(Display.getDefault(), SWT.CURSOR_HAND));
      restoreStatusTextLabel.setToolTipText(restoreResult.getTargetFile().toString());

      restoredFile = restoreResult.getTargetFile();
    } else {
      logger.log(Level.WARNING, "Detail panel: Restore FAILED, error code " + restoreResultCode);

      restoreStatusIconComposite.setImage(
          SWTResourceManager.getImage(String.format(IMAGE_RESOURCE_FORMAT, "failure")));
      restoreStatusTextLabel.setText(
          I18n.getText("org.syncany.gui.history.DetailPanel.label.fileRestoreFailure"));
      restoreStatusTextLabel.setCursor(new Cursor(Display.getDefault(), SWT.CURSOR_ARROW));
      restoreStatusTextLabel.setToolTipText("");

      restoredFile = null;
    }

    layout();
  }