}
@Override
protected void addMenuItems() {
add(new H2HConsoleMenuItem("Add File") {
protected boolean checkPreconditions() {
return createRootDirectory();
}
protected void execute() throws Hive2HiveException, InterruptedException {
File file = askForFile(true);
if (file == null) {
return;
}
IProcessComponent addFileProcess = menus.getNodeMenu().getNode().getFileManager().add(file);
executeBlocking(addFileProcess, displayText);
}
});
add(new H2HConsoleMenuItem("Update File") {
protected boolean checkPreconditions() {
return createRootDirectory();
}
protected void execute() throws Hive2HiveException, InterruptedException {
File file = askForFile(true);
if (file == null) {
return;
}
IProcessComponent updateFileProcess = menus.getNodeMenu().getNode().getFileManager().update(file);
executeBlocking(updateFileProcess, displayText);
}
});
add(new H2HConsoleMenuItem("Move File") {
protected boolean checkPreconditions() {
return createRootDirectory();
}
protected void execute() throws Hive2HiveException, InterruptedException {
File source = askForFile("Specify the relative path of the source file to the root directory '%s'.", true);
if (source == null) {
return;
}
File destination = askForFile(
"Specify the relative path of the destination file to the root directory '%s'.", false);
if (destination == null) {
return;
}
IProcessComponent moveFileProcess = menus.getNodeMenu().getNode().getFileManager().move(source, destination);
executeBlocking(moveFileProcess, displayText);
}
});
add(new H2HConsoleMenuItem("Delete File") {
protected boolean checkPreconditions() {
return createRootDirectory();
}
protected void execute() throws Hive2HiveException, InterruptedException {
File file = askForFile(true);
if (file == null) {
return;
}
IProcessComponent deleteFileProcess = menus.getNodeMenu().getNode().getFileManager().delete(file);
executeBlocking(deleteFileProcess, displayText);
}
});
add(new H2HConsoleMenuItem("Recover File") {
protected boolean checkPreconditions() {
return createRootDirectory();
}
protected void execute() throws Hive2HiveException, FileNotFoundException, IllegalArgumentException,
InterruptedException {
File file = askForFile(true);
if (file == null) {
return;
}
IVersionSelector versionSelector = new IVersionSelector() {
public IFileVersion selectVersion(List<IFileVersion> availableVersions) {
return new SelectionMenu<IFileVersion>(availableVersions, "Choose the version you want to recover.")
.openAndSelect();
}
public String getRecoveredFileName(String fullName, String name, String extension) {
print(String
.format("Specify the new name for the recovered file '%s' or enter 'default' to take the default values:",
fullName));
String input = awaitStringParameter();
if ("default".equalsIgnoreCase(input)) {
return null;
} else {
return input;
}
}
};
IProcessComponent recoverFileProcess = menus.getNodeMenu().getNode().getFileManager()
.recover(file, versionSelector);
executeBlocking(recoverFileProcess, displayText);
}
});
add(new H2HConsoleMenuItem("Share File") {
protected boolean checkPreconditions() {
return createRootDirectory();
}
protected void execute() throws NoSessionException, NoPeerConnectionException, InvalidProcessStateException,
InterruptedException {
File folderToShare = askForFolder(
"Specify the relative path of the folder you want to share to the root directory '%s'.", true);
if (folderToShare == null) {
return;
}
print("Specify the user ID of the user you want to share with.");
String friendID = awaitStringParameter();
PermissionType permission = askForPermission(folderToShare.getAbsolutePath(), friendID);
if (permission == null) {
return;
}
IProcessComponent shareProcess;
try {
shareProcess = menus.getNodeMenu().getNode().getFileManager().share(folderToShare, friendID, permission);
} catch (IllegalFileLocation | IllegalArgumentException e) {
printError(e.getMessage());
return;
}
executeBlocking(shareProcess, displayText);
}
});
add(new H2HConsoleMenuItem("Print File List") {
@Override
protected void execute() throws Exception {
IResultProcessComponent<List<FileTaste>> fileListProcess = menus.getNodeMenu().getNode().getFileManager()
.getFileList();
executeBlocking(fileListProcess, displayText);
if (!fileListProcess.getResult().isEmpty()) {
for (FileTaste fileTaste : fileListProcess.getResult()) {
print("* " + fileTaste);
}
} else {
print("The file list is empty.");
}
}
});
add(new H2HConsoleMenuItem("File Observer") {
protected boolean checkPreconditions() {
return createRootDirectory();
}
protected void execute() throws Exception {