Package org.crsh.text.ui

Examples of org.crsh.text.ui.TableElement


  public LineRenderer renderer(Iterator<File> stream) {

    //
    List<File> files = Utils.list(stream);
    Collections.sort(files);
    TableElement table = new TableElement().overflow(Overflow.WRAP).rightCellPadding(1);
    SimpleDateFormat format = new SimpleDateFormat("MMM dd HH:mm");
    Date date = new Date();

    //
    for (File file : files) {
      String mode = (file.isDirectory() ? "d" : "-")
          + (file.canRead() ? "r" : "-")
          + (file.canWrite() ? "w" : "-")
          + (file.canExecute() ? "x" : "-")
          ;
      String length = Long.toString(file.length());
      date.setTime(file.lastModified());
      String lastModified = format.format(date);
      table.row(
        mode,
        length,
        lastModified,
        file.getName()
      );
    }

    //
    return table.renderer();
  }
View Full Code Here


    return Logger.class;
  }

  @Override
  public LineRenderer renderer(Iterator<Logger> stream) {
    TableElement table = new TableElement();

    // Header
    table.add(new RowElement().style(Decoration.bold.fg(Color.black).bg(Color.white)).add("NAME", "LEVEL"));

    //
    while (stream.hasNext()) {
      Logger logger = stream.next();

      // Determine level
      String level;
      if (logger.isLoggable(Level.FINER)) {
        level = "TRACE";
      } else if (logger.isLoggable(Level.FINE)) {
        level = "DEBUG";
      } else if (logger.isLoggable(Level.INFO)) {
        level = "INFO";
      } else if (logger.isLoggable(Level.WARNING)) {
        level = "WARN";
      else if (logger.isLoggable(Level.SEVERE)) {
        level = "ERROR";
      } else {
        level = "UNKNOWN";
      }

      //
      table.row(logger.getName(), level);
    }

    //
    return table.renderer();
  }
View Full Code Here

        }
      }
    });

    //
    TableElement table = new TableElement(1,3,2,1,1,1,1,1,1).overflow(Overflow.HIDDEN).rightCellPadding(1);

    // Header
    table.add(
      new RowElement().style(Decoration.bold.fg(Color.black).bg(Color.white)).add(
        "ID",
        "NAME",
        "GROUP",
        "PRIORITY",
        "STATE",
        "%CPU",
        "TIME",
        "INTERRUPTED",
        "DAEMON"
      )
    );

    //
    for (Thread thread : threads) {
      Color c = colorMapping.get(thread.getState());
      long seconds = times2.get(thread.getId()) / 1000000000;
      long min = seconds / 60;
      String time = min + ":" + (seconds % 60);
      long cpu = cpus.get(thread);
      ThreadGroup group = thread.getThreadGroup();
      table.row(
          new LabelElement(thread.getId()),
          new LabelElement(thread.getName()),
          new LabelElement(group == null ? "" : group.getName()),
          new LabelElement(thread.getPriority()),
          new LabelElement(thread.getState()).style(c.fg()),
          new LabelElement(cpu),
          new LabelElement(time),
          new LabelElement(thread.isInterrupted()),
          new LabelElement(thread.isDaemon())
      );
    }

    //
    return table.renderer();
  }
View Full Code Here

  }

  @Override
  public LineRenderer renderer(Iterator<BindingData> stream) {

    TableElement table = new TableElement();
    table.setRightCellPadding(1);
    RowElement header = new RowElement(true);
    header.add("NAME");
    table.add(header);

    while (stream.hasNext()) {
      BindingData binding = stream.next();

      RowElement row = new RowElement();

       row.add(binding.name);

      if (binding.verbose) {
        row.add(new LabelElement(binding.type));
        if (header.getSize() == 1) {
          header.add("CLASS");
        }
      }
     
      table.add(row);

    }

    return table.renderer();
  }
View Full Code Here

    List<ObjectName> names = Utils.list(stream);
    Collections.sort(names);

    //
    TableElement table = new TableElement().overflow(Overflow.HIDDEN).rightCellPadding(1);

    // Header
    table.add(
      new RowElement().
        style(Decoration.bold.fg(Color.black).bg(Color.white)).
        add("NAME", "CLASSNAME", "MXBEAN", "DESCRIPTION")
    );

    //
    for (ObjectName name : names) {

      String className;
      String description;
      String mxbean;
      try {
        MBeanInfo info = server.getMBeanInfo(name);
        className = info.getClassName();
        description = info.getDescription();
        Object mxbeanValue = info.getDescriptor().getFieldValue("mxbean");
        mxbean = mxbeanValue != null ? mxbeanValue.toString() : "false";
      }
      catch (JMException ignore) {
        className = "";
        description = "";
        mxbean = "";
      }

      //
      table.row("" + name, className, mxbean, description);
    }

    //
    return table.renderer();
  }
View Full Code Here

  }

  @Override
  public LineRenderer renderer(Iterator<Map<?, ?>> stream) {

    TableElement table = new TableElement();
    LinkedHashSet<String> current = new LinkedHashSet<String>();
    LinkedHashSet<String> bilto = new LinkedHashSet<String>();

    ArrayList<LineRenderer> renderers = new ArrayList<LineRenderer>();

    while (stream.hasNext()) {

      Map<?, ?> row = stream.next();

      if (row.size() 0) {

        bilto.clear();
        for (Map.Entry<?, ?> entry : row.entrySet()) {
          bilto.add(String.valueOf(entry.getKey()));
        }

        // Create a new table if needed
        if (!current.equals(bilto)) {
          if (table.getRows().size() > 0) {
            renderers.add(table.renderer());
          }
          table = new TableElement().rightCellPadding(1);
          RowElement header = new RowElement(true);
          header.style(Decoration.bold.fg(Color.black).bg(Color.white));
          for (String s : bilto) {
            header.add(s);
          }
          table.add(header);
          current = bilto;
        }

        //
        RowElement r = new RowElement();
        for (String s : bilto) {
          r.add(String.valueOf(row.get(s)));
        }
        table.add(r);
      }
    }

    //
    if (table.getRows().size() > 0) {
      renderers.add(table.renderer());
    }

    //
    return LineRenderer.vertical(renderers);
  }
View Full Code Here

      //
      TreeElement root = new TreeElement(info.getClassName());

      // Descriptor
      TableElement descriptor = new TableElement().
          overflow(Overflow.HIDDEN).
          rightCellPadding(1);
      Descriptor descriptorInfo = info.getDescriptor();
      if (descriptorInfo != null) {
        for (String fieldName : descriptorInfo.getFieldNames()) {
          String fieldValue = String.valueOf(descriptorInfo.getFieldValue(fieldName));
          descriptor.row(fieldName, fieldValue);
        }
      }

      // Attributes
      TableElement attributes = new TableElement().
          overflow(Overflow.HIDDEN).
          rightCellPadding(1).
          add(new RowElement().style(Decoration.bold.fg(Color.black).bg(Color.white)).add("NAME", "TYPE", "DESCRIPTION"));
      for (MBeanAttributeInfo attributeInfo : info.getAttributes()) {
        attributes.row(attributeInfo.getName(), attributeInfo.getType(), attributeInfo.getDescription());
      }

      // Operations
      TreeElement operations = new TreeElement("Operations");
      for (MBeanOperationInfo operationInfo : info.getOperations()) {
        TableElement signature = new TableElement().
            overflow(Overflow.HIDDEN).
            rightCellPadding(1);
        MBeanParameterInfo[] parameterInfos = operationInfo.getSignature();
        for (MBeanParameterInfo parameterInfo : parameterInfos) {
          signature.row(parameterInfo.getName(), parameterInfo.getType(), parameterInfo.getDescription());
        }
        TreeElement operation = new TreeElement(operationInfo.getName());
        String impact;
        switch (operationInfo.getImpact()) {
          case MBeanOperationInfo.ACTION:
            impact = "ACTION";
            break;
          case MBeanOperationInfo.INFO:
            impact = "INFO";
            break;
          case MBeanOperationInfo.ACTION_INFO:
            impact = "ACTION_INFO";
            break;
          default:
            impact = "UNKNOWN";
        }
        operation.addChild(new TableElement().
            add(
                new RowElement().add("Type: ", operationInfo.getReturnType()),
                new RowElement().add("Description: ", operationInfo.getDescription()),
                new RowElement().add("Impact: ", impact),
                new RowElement().add(new LabelElement("Signature: "), signature)
            )
        );

        operations.addChild(operation);
      }

      //
      root.addChild(
        new TableElement().leftCellPadding(1).overflow(Overflow.HIDDEN).
          row("ClassName", info.getClassName()).
          row("Description", info.getDescription()
        )
      );
      root.addChild(new TreeElement("Descriptor").addChild(descriptor));
View Full Code Here

          repls.put(repl, lang.isActive());
        }
      }

      //
      TableElement table = new TableElement().rightCellPadding(1);
      table.row(
        new LabelElement("NAME").style(Style.style(Decoration.bold)),
        new LabelElement("DISPLAY NAME"),
        new LabelElement("DESCRIPTION"),
        new LabelElement("ACTIVE")
      );
      for (Map.Entry<Repl, Boolean> entry : repls.entrySet()) {
        Boolean active = entry.getValue();
        String langDescription = entry.getKey().getDescription();
        String langDisplayName = entry.getKey().getLanguage().getDisplayName();
        String langName = entry.getKey().getLanguage().getName();
        table.row(
          new LabelElement(langName).style(Style.style(Color.red)),
          new LabelElement(langDisplayName != null ? langDisplayName : ""),
          new LabelElement(langDescription != null ? langDescription : ""),
          new LabelElement(active)
        );
View Full Code Here

  @Usage("provides basic help")
  @Command
  public void main(InvocationContext<Object> context) throws Exception {

    //
    TableElement table = new TableElement().rightCellPadding(1);
    table.row(
      new LabelElement("NAME").style(Style.style(Decoration.bold)),
      new LabelElement("DESCRIPTION")
    );

    //
    CRaSH crash = (CRaSH)context.getSession().get("crash");
    for (Map.Entry<String, String> command : crash.getCommands()) {
      try {
        String desc = command.getValue();
        if (desc == null) {
          desc = "";
        }
        table.row(
          new LabelElement(command.getKey()).style(Style.style(Color.red)),
          new LabelElement(desc));
      } catch (Exception ignore) {
        //
      }
View Full Code Here

TOP

Related Classes of org.crsh.text.ui.TableElement

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.