Package org.hive2hive.client.console

Examples of org.hive2hive.client.console.H2HConsoleMenuItem


  }
 
  @Override
  protected void addMenuItems() {
   
    add(new H2HConsoleMenuItem("Basic Mode (Recommended)") {
      @Override
      protected void execute() throws Exception {
        menus.getRootMenu().open(false);
      }
    });
    add(new H2HConsoleMenuItem("Expert Mode") {
      @Override
      protected void execute() throws Exception {
        menus.getRootMenu().open(true);
      }
    });
View Full Code Here


    super(menus);
  }

  @Override
  protected void createItems() {
    CreateRootDirectory = new H2HConsoleMenuItem("Create Root Directory") {
      protected void execute() throws Exception {

        rootDirectory = new File(FileUtils.getUserDirectory(), "H2H_"
            + menus.getUserMenu().getUserCredentials().getUserId() + "_" + System.currentTimeMillis());
View Full Code Here

  }

  @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 {
View Full Code Here

    super(menus);
  }

  @Override
  protected void addMenuItems() {
    add(new H2HConsoleMenuItem("Connect") {
      protected void execute() {
        menus.getNodeMenu().open(isExpertMode);
      }
    });

    add(new H2HConsoleMenuItem("Login") {
      protected boolean checkPreconditions() throws NoPeerConnectionException,
          InvalidProcessStateException, InterruptedException {
        if (!menus.getNodeMenu().createNetwork()) {
          printAbortion(displayText, "Node not connected.");
          return false;
        }
        if (!menus.getUserMenu().createUserCredentials()) {
          printAbortion(displayText, "User credentials not specified.");
          return false;
        }
        if (!menus.getFileMenu().createRootDirectory()) {
          printAbortion(displayText, "Root directory not specified.");
          return false;
        }
        if (!register()) {
          printAbortion(displayText, "Registering failed.");
          return false;
        }
        return true;
      }

      protected void execute() throws NoPeerConnectionException, InterruptedException,
          InvalidProcessStateException {

        IProcessComponent loginProcess = menus
            .getNodeMenu()
            .getNode()
            .getUserManager()
            .login(menus.getUserMenu().getUserCredentials(),
                menus.getFileMenu().getRootDirectory().toPath());

        boolean success = executeBlocking(loginProcess, displayText);
        // reset user configs as they might be wrong
        if (!success) {
          menus.getUserMenu().reset();
          menus.getFileMenu().reset();
        }
      }
    });

    add(new H2HConsoleMenuItem("Logout") {
      protected boolean checkPreconditions() throws Exception {
        return checkLogin();
      }

      protected void execute() throws Exception {

        IProcessComponent logoutProcess = menus.getNodeMenu().getNode().getUserManager().logout();
        executeBlocking(logoutProcess, displayText);
      }
    });

    add(new H2HConsoleMenuItem("File Menu") {
      @Override
      protected boolean checkPreconditions() throws Exception {
        return checkLogin();
      }
View Full Code Here

    super(menus);
  }

  @Override
  protected void createItems() {
    CreateUserCredentials = new H2HConsoleMenuItem("Create User Credentials") {
      protected void execute() throws Exception {
        userCredentials = new UserCredentials(askUsedId(), askPassword(), askPin());
        exit();
      }
    };
View Full Code Here

    super(menus);
  }

  @Override
  protected void createItems() {
    CreateNetworkMenuItem = new H2HConsoleMenuItem("Create New Network") {
      protected void execute() {

        buildNode(NetworkConfiguration.create(askNodeID()));
        connectNode();
      }
    };

    ConnectToExistingNetworkItem = new H2HConsoleMenuItem("Connect to Existing Network") {
      protected void execute() throws UnknownHostException {

        String nodeID = askNodeID();

        print("Specify Bootstrap Address:");
View Full Code Here

  @Override
  protected void addMenuItems() {

    if (isExpertMode) {
      add(new H2HConsoleMenuItem("Set MaxFileSize") {

        protected void execute() {
          print("Specify MaxFileSize:");
          maxFileSize = BigInteger.valueOf(awaitIntParameter());
        }
      });

      add(new H2HConsoleMenuItem("Set MaxNumOfVersions") {
        protected void execute() {
          print("Specify MaxNumOfVersions:");
          maxNumOfVersions = awaitIntParameter();
        }
      });

      add(new H2HConsoleMenuItem("Set MaxSizeAllVersions") {
        protected void execute() {
          print("Specify MaxSizeAllVersions:");
          maxSizeAllVersions = BigInteger.valueOf(awaitIntParameter());
        }
      });

      add(new H2HConsoleMenuItem("Set ChunkSize") {
        protected void execute() {
          print("Specify ChunkSize:");
          chunkSize = awaitIntParameter();
        }
      });

      add(new H2HConsoleMenuItem("Open Utils") {
        protected void execute() {
          new UtilMenu().open();
        }
      });
    }
View Full Code Here

  @Override
  protected void addMenuItems() {

    if (isExpertMode) {
      add(new H2HConsoleMenuItem("Set Interval") {
        // TODO restart observer
        protected void execute() {
          System.out.println("Specify the observation interval (ms):");
          interval = awaitIntParameter();
        }
      });
    }

    add(new H2HConsoleMenuItem("Start File Observer") {
      protected boolean checkPreconditions() {
        if (menus.getNodeMenu().createNetwork()) {
          return menus.getFileMenu().createRootDirectory();
        } else {
          return false;
        }
      }

      protected void execute() throws Exception {

        fileObserver = new H2HFileObserver(menus.getFileMenu().getRootDirectory(), interval);

        IFileObserverListener listener = new H2HFileObserverListener(menus.getNodeMenu().getNode().getFileManager());

        fileObserver.addFileObserverListener(listener);

        fileObserver.start();
        exit();
      }
    });

    add(new H2HConsoleMenuItem("Stop File Observer") {
      protected void execute() throws Exception {
        if (fileObserver != null) {
          fileObserver.stop();
        }
        exit();
View Full Code Here

public class UtilMenu extends ConsoleMenu {

  @Override
  protected void addMenuItems() {

    add(new H2HConsoleMenuItem("Show Local Network Interfaces & IP Addresses") {

      @Override
      protected void execute() throws Exception {

        Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
View Full Code Here

public class LoggerMenu extends ConsoleMenu {

  @Override
  protected void addMenuItems() {

    add(new H2HConsoleMenuItem("Yes") {
      protected void execute() throws Exception {
        String logFileName = createRootLogger();
        print(String.format("Log file '%s' has been created.", logFileName));
        exit();
      }
    });
    add(new H2HConsoleMenuItem("No") {
      protected void execute() throws Exception {
        // logback.xml defines nothing by default
        LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
        loggerContext.reset();
        exit();
View Full Code Here

TOP

Related Classes of org.hive2hive.client.console.H2HConsoleMenuItem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.