示例#1
0
  @Invalidate
  public void stop() {
    Future<IBehaviorConnection<ICommandManager>> commandBCF =
        BEHAVIORS.getBehaviorConnection(ICommandManager.class);
    if (!commandBCF.isDone()) {
      LOG.debug("Could not unregister as registering ");
      return;
    }
    try (IBehaviorConnection<ICommandManager> commandBC = commandBCF.get()) {
      LOG.debug("Unregistering application commands.");
      ICommandManager cm = commandBC.getBehavior();

      cm.removeHandler(_quitCommand);
      cm.removeHandler(_openCommand);
      cm.removeHandler(_saveCommand);
      cm.removeHandler(_shellCommand);
    } catch (Exception e) {
      LOG.error("Couldn't stop application commands: ", e);
    }
  }
示例#2
0
  @Validate
  public void start() {
    try (IBehaviorConnection<ICommandManager> commandBC =
        BEHAVIORS.getBehaviorConnection(ICommandManager.class).get()) {
      LOG.debug("Registering application commands.");
      ICommandManager cm = commandBC.getBehavior();

      _quitCommand =
          cm.registerHandler(
              "q",
              (BufferWindow window, String[] argv) -> {
                try (IBehaviorConnection<IApplication> applicationBC =
                    BEHAVIORS.getBehaviorConnection(IApplication.class).get()) {
                  applicationBC.getBehavior().popPrimaryWindow();
                } catch (Exception e) {
                  LOG.error("Couldn't shut down gracefully.", e);
                  System.exit(-1);
                }
              });
      _openCommand = cm.registerHandler("e", new OpenFileCommand());
      _saveCommand =
          cm.registerHandler(
              "w",
              (BufferWindow window, String[] argv) -> {
                try {
                  window.getBuffer().save();
                  window.getCommandController().setCommandFeedback("Saved file.");
                } catch (Exception e) {
                  window.getCommandController().setCommandFeedback("Couldn't save.");
                }
              });
      _shellCommand = cm.registerHandler("r", new ShellCommandHandler());
    } catch (Exception e) {
      LOG.error("Couldn't start application commands: ", e);
    }
  }