Package org.vaadin.console

Examples of org.vaadin.console.Console$Command


    /**
     * Create an instance of {@link Command }
     *
     */
    public Command createCommand() {
        return new Command();
    }
View Full Code Here


   * Builds the Console
   * @param NULL
   */
  public int buildKonsole()
  {
    console = new Console();
    console.setPs("~$ ");
    console.setRows(20);
    console.setCols(70);
    console.setGreeting("Welcome to Decisia Konsole\nType 'help' for more information");
    console.focus();
View Full Code Here

                        "Type 'help' to list all available commands and 'help <command>' to get parameter help.'"));

        // # 1

        // Create a console
        final Console console = new Console();
        mainWindow.addComponent(console);

        // Size and greeting
        console.setPs("}> ");
        console.setCols(80);
        console.setRows(24);
        console.setMaxBufferSize(24);
        console.setGreeting("Welcome to Vaadin console demo.");
        console.reset();
        console.focus();

        // Publish the methods in the Console class itself for testing purposes.
        console.addCommandProvider(inspector = new ObjectInspector(console));

        // Add help command
        Command helpCommand = new Console.Command() {
            private static final long serialVersionUID = 2838665604270727844L;

            public String getUsage(Console console, String[] argv) {
                return argv[0] + " <command>";
            }

            public Object execute(Console console, String[] argv)
                    throws Exception {
                if (argv.length == 2) {
                    Command hc = console.getCommand(argv[1]);
                    ArrayList<String> cmdArgv = new ArrayList<String>(Arrays
                            .asList(argv));
                    cmdArgv.remove(0);
                    return "Usage: "
                            + hc.getUsage(console, cmdArgv
                                    .toArray(new String[] {}));
                }
                return listAvailableCommands();
            }
        };

        // Bind the same command with multiple names
        console.addCommand("help", helpCommand);
        console.addCommand("info", helpCommand);
        console.addCommand("man", helpCommand);
        // #

        // # 2
        Command systemCommand = new Command() {
            private static final long serialVersionUID = -5733237166568671987L;

            public Object execute(Console console, String[] argv)
                    throws Exception {
                Process p = Runtime.getRuntime().exec(argv);
                InputStream in = p.getInputStream();
                StringBuilder o = new StringBuilder();
                InputStreamReader r = new InputStreamReader(in);
                int c = -1;
                try {
                    while ((c = r.read()) != -1) {
                        o.append((char) c);
                    }
                } catch (IOException e) {
                    o.append("[truncated]");
                }
                return o.toString();
            }

            public String getUsage(Console console, String[] argv) {
                // TODO Auto-generated method stub
                return null;
            }
        };

        // #
        console.addCommand("ls", systemCommand);

        // Add sample command
        DummyCmd dummy = new DummyCmd();
        console.addCommand("dir", dummy);
        console.addCommand("cd", dummy);
        console.addCommand("mkdir", dummy);
        console.addCommand("rm", dummy);
        console.addCommand("pwd", dummy);
        console.addCommand("more", dummy);
        console.addCommand("less", dummy);
        console.addCommand("exit", dummy);

        HorizontalLayout pl = new HorizontalLayout();
        pl.setSpacing(true);
        mainWindow.addComponent(pl);
        final TextField input = new TextField(null, "print this");
        pl.addComponent(input);
        pl.addComponent(new Button("print", new Button.ClickListener() {
            private static final long serialVersionUID = 1L;

            public void buttonClick(ClickEvent event) {
                console.print("" + input.getValue());
            }
        }));

        pl.addComponent(new Button("println", new Button.ClickListener() {
            private static final long serialVersionUID = 1L;

            public void buttonClick(ClickEvent event) {
                console.println("" + input.getValue());
            }
        }));

    }
View Full Code Here

        } else {
          throw new IOException("Unexpected character");
        }
      }
      try {
        out.add(new Command(bytes));
      } finally {
        bytes = null;
        arguments = 0;
      }
    } else if (in.readByte() == '*') {
      long l = readLong(in);
      if (l > Integer.MAX_VALUE) {
        throw new IllegalArgumentException("Java only supports arrays up to " + Integer.MAX_VALUE + " in size");
      }
      int numArgs = (int) l;
      if (numArgs < 0) {
        throw new RedisException("Invalid size: " + numArgs);
      }
      bytes = new byte[numArgs][];
      checkpoint();
      decode(ctx, in, out);
    } else {
      // Go backwards one
      in.readerIndex(in.readerIndex() - 1);
      // Read command -- can't be interupted
      byte[][] b = new byte[1][];
      b[0] = in.readBytes(in.bytesBefore((byte) '\r')).array();
      in.skipBytes(2);
      out.add(new Command(b, true));
    }
  }
View Full Code Here

        boolean isOff = _hasTrueInput(off);
        boolean isOn = _hasTrueInput(on);

        if ((brightLevel >= 0) && (brightLevel <= 100)) {
            _transmit(new Command((_destination), x10.Command.BRIGHT,
                    brightLevel));
        }

        if ((dimLevel >= 0) && (dimLevel <= 100)) {
            _transmit(new Command((_destination), x10.Command.DIM, dimLevel));
        }

        if (isOn) {
            _transmit(new Command((_destination), x10.Command.ON));
        }

        if (isOff) {
            _transmit(new Command((_destination), x10.Command.OFF));
        }
    }
View Full Code Here

    public void fire() throws IllegalActionException {
        super.fire();

        // Check whether a command is ready.
        if (_commandReady()) {
            Command command = _getCommand();
            receivedCommand.send(0, new StringToken(_commandToString(command)));
        } else {
            receivedCommand.send(0, _EMPTY_STRING);
        }
    }
View Full Code Here

    public void fire() throws IllegalActionException {
        super.fire();

        // Check whether a command is ready
        if (_commandReady()) {
            Command sensedCommand = _getCommand();
            byte function = sensedCommand.getFunctionByte();
            byte functionOfInterest = Command.BRIGHT;
            String commandValue = command.stringValue();

            if (!commandValue.equals("BRIGHT")) {
                functionOfInterest = Command.DIM;
            }

            String sensedHouseCode = "" + sensedCommand.getHouseCode();
            int sensedUnitCode = sensedCommand.getUnitCode();

            String houseCodeValue = houseCode.stringValue();
            int unitCodeValue = ((IntToken) unitCode.getToken()).intValue();

            if (sensedHouseCode.equals(houseCodeValue)
                    && (sensedUnitCode == unitCodeValue)
                    && (function == functionOfInterest)) {
                level.send(0, new IntToken(sensedCommand.getLevel()));
            } else {
                level.send(0, _NO_COMMAND_TOKEN);
            }
        } else {
            level.send(0, _NO_COMMAND_TOKEN);
View Full Code Here

        boolean isOn = _hasTrueInput(on);
        boolean isOff = _hasTrueInput(off);

        if (isOn) {
            _transmit(new Command((_destination), x10.Command.ON));
        }

        if (isOff) {
            _transmit(new Command((_destination), x10.Command.OFF));
        }
    }
View Full Code Here

    public void fire() throws IllegalActionException {
        super.fire();

        // Check whether a command is ready
        if (_commandReady()) {
            Command sensedCommand = _getCommand();
            byte function = sensedCommand.getFunctionByte();
            byte functionOfInterest = Command.ON;
            String commandValue = command.stringValue();

            if (commandValue.equals("OFF")) {
                functionOfInterest = Command.OFF;
            } else if (commandValue.equals("ALL_LIGHTS_ON")) {
                functionOfInterest = Command.ALL_LIGHTS_ON;
            } else if (commandValue.equals("ALL_LIGHTS_OFF")) {
                functionOfInterest = Command.ALL_LIGHTS_OFF;
            } else if (commandValue.equals("ALL_UNITS_OFF")) {
                functionOfInterest = Command.ALL_UNITS_OFF;
            }

            String sensedHouseCode = "" + sensedCommand.getHouseCode();
            int sensedUnitCode = sensedCommand.getUnitCode();

            String houseCodeValue = houseCode.stringValue();
            int unitCodeValue = ((IntToken) unitCode.getToken()).intValue();

            if (sensedHouseCode.equals(houseCodeValue)
View Full Code Here

TOP

Related Classes of org.vaadin.console.Console$Command

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.