private void restoreFileVersion(FileVersion fileVersion) {
    // Set labels/status
    String shortFileName = shortenFileName(fileVersion.getPath());
    String versionStr = Long.toString(fileVersion.getVersion());

    restoreButton.setEnabled(false);
    restoreStatusIconComposite.setVisible(true);
    restoreStatusTextLabel.setVisible(true);

    restoreStatusIconComposite.setAnimatedImage(
        IMAGE_LOADING_SPINNER_RESOURCE, IMAGE_LOADING_SPINNER_FRAME_RATE);
    restoreStatusTextLabel.setText(
        I18n.getText(
            "org.syncany.gui.history.DetailPanel.label.fileRestoreOngoing",
            shortFileName,
            versionStr));
    restoreStatusTextLabel.setCursor(new Cursor(Display.getDefault(), SWT.CURSOR_ARROW));
    restoreStatusTextLabel.setToolTipText("");

    restoredFile = null;

    layout();

    // Send restore request
    RestoreOperationOptions restoreOptions = new RestoreOperationOptions();
    restoreOptions.setFileHistoryId(fileVersion.getFileHistoryId());
    restoreOptions.setFileVersion(fileVersion.getVersion().intValue());

    pendingRestoreRequest = new RestoreFolderRequest();
    pendingRestoreRequest.setRoot(historyModel.getSelectedRoot());
    pendingRestoreRequest.setOptions(restoreOptions);

    eventBus.post(pendingRestoreRequest);
  }
Esempio n. 2
0
  public static FileVersion createFileVersion(String path, FileVersion basedOnFileVersion) {
    FileVersion fileVersion = basedOnFileVersion.clone();

    fileVersion.setPath(path);
    fileVersion.setStatus(FileStatus.CHANGED);
    fileVersion.setVersion(basedOnFileVersion.getVersion() + 1);

    return fileVersion;
  }
Esempio n. 3
0
    private FileVersion createNewFileVersion(
        FileVersion lastFileVersion, FileProperties fileProperties) {
      FileVersion fileVersion = null;

      // Version
      if (lastFileVersion == null) {
        fileVersion = new FileVersion();
        fileVersion.setVersion(1L);
        fileVersion.setStatus(FileStatus.NEW);
      } else {
        fileVersion = lastFileVersion.clone();
        fileVersion.setVersion(lastFileVersion.getVersion() + 1);
      }

      // Simple attributes
      fileVersion.setPath(fileProperties.getRelativePath());
      fileVersion.setLinkTarget(fileProperties.getLinkTarget());
      fileVersion.setType(fileProperties.getType());
      fileVersion.setSize(fileProperties.getSize());
      fileVersion.setChecksum(fileProperties.getChecksum());
      fileVersion.setLastModified(new Date(fileProperties.getLastModified()));
      fileVersion.setUpdated(new Date());

      // Permissions
      if (EnvironmentUtil.isWindows()) {
        fileVersion.setDosAttributes(fileProperties.getDosAttributes());
        fileVersion.setPosixPermissions(DEFAULT_POSIX_PERMISSIONS);
      } else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
        fileVersion.setPosixPermissions(fileProperties.getPosixPermissions());
        fileVersion.setDosAttributes(DEFAULT_DOS_ATTRIBUTES);
      }

      // Status
      if (lastFileVersion != null) {
        if (fileVersion.getType() == FileType.FILE
            && FileChecksum.fileChecksumEquals(
                fileVersion.getChecksum(), lastFileVersion.getChecksum())) {
          fileVersion.setStatus(FileStatus.CHANGED);
        } else if (!fileVersion.getPath().equals(lastFileVersion.getPath())) {
          fileVersion.setStatus(FileStatus.RENAMED);
        } else {
          fileVersion.setStatus(FileStatus.CHANGED);
        }
      }

      return fileVersion;
    }
  private void selectFileVersion(FileVersion fileVersion) {
    boolean isLastVersion = fileVersion.equals(selectedFileHistory.getLastVersion());
    boolean restoreInProgress = pendingRestoreRequest != null;
    boolean restoreButtonEnabled = !isLastVersion && !restoreInProgress;

    logger.log(
        Level.INFO,
        "Detail panel: Selecting file version"
            + fileVersion.getVersion()
            + "; Restore in progress = "
            + restoreInProgress
            + "; Last/current version = "
            + isLastVersion
            + " --> Button enabled = "
            + restoreButtonEnabled);

    restoreButton.setEnabled(restoreButtonEnabled);
  }
  private FileVersion createFileVersion(
      String path, FileType type, FileVersion basedOnFileVersion) {
    if (basedOnFileVersion == null) {
      FileVersion fileVersion = new FileVersion();
      fileVersion.setPath(path);
      fileVersion.setType(type);
      fileVersion.setVersion(1L);

      return fileVersion;
    } else {
      FileVersion fileVersion = basedOnFileVersion.clone();
      fileVersion.setPath(path);
      fileVersion.setType(type);
      fileVersion.setVersion(basedOnFileVersion.getVersion() + 1);

      return fileVersion;
    }
  }
  private void updateTable(LsFolderRequest lsRequest, LsFolderResponse lsResponse) {
    logger.log(
        Level.INFO,
        "Detail panel: Updating table with "
            + lsResponse.getResult().getFileVersions().size()
            + " file versions ...");

    // Add new file version items
    List<PartialFileHistory> fileVersions =
        new ArrayList<>(lsResponse.getResult().getFileVersions().values());
    selectedFileHistory = fileVersions.get(0);

    for (FileVersion fileVersion : selectedFileHistory.getFileVersions().values()) {
      String checksumStr =
          (fileVersion.getChecksum() != null) ? fileVersion.getChecksum().toString() : "";

      TableItem tableItem = new TableItem(historyTable, SWT.NONE);

      tableItem.setData(fileVersion);
      tableItem.setImage(COLUMN_INDEX_STATUS, getStatusImage(fileVersion.getStatus()));
      tableItem.setText(COLUMN_INDEX_PATH, fileVersion.getPath());
      tableItem.setText(COLUMN_INDEX_VERSION, Long.toString(fileVersion.getVersion()));
      tableItem.setText(COLUMN_INDEX_TYPE, fileVersion.getType().toString());
      tableItem.setText(COLUMN_INDEX_SIZE, FileUtil.formatFileSize(fileVersion.getSize()));
      tableItem.setText(COLUMN_INDEX_POSIX_PERMS, fileVersion.getPosixPermissions());
      tableItem.setText(COLUMN_INDEX_DOS_ATTRS, fileVersion.getDosAttributes());
      tableItem.setText(COLUMN_INDEX_CHECKSUM, checksumStr);
      tableItem.setText(COLUMN_INDEX_LAST_MODIFIED, "" + fileVersion.getLastModified());
      tableItem.setText(COLUMN_INDEX_UPDATED, "" + fileVersion.getUpdated());
    }

    if (historyTable.getItemCount() > 0) {
      restoreButton.setEnabled(false);
      historyTable.select(historyTable.getItemCount() - 1);
    }

    resizeColumns();
  }