Examples of ShellTable


Examples of org.apache.karaf.shell.table.ShellTable

    @Argument(index = 0, name = "context", description = "The JNDI context to display the names", required = false, multiValued = false)
    String context;

    public Object doExecute() throws Exception {
        ShellTable table = new ShellTable();

        table.column("JNDI Name");
        table.column("Class Name");

        Map<String, String> names;
        if (context == null) {
            names = this.getJndiService().names();
        } else {
            names = this.getJndiService().names(context);
        }

        for (String name : names.keySet()) {
            table.addRow().addContent(name, names.get(name));
        }

        table.print(System.out);

        return null;
    }
View Full Code Here

Examples of org.apache.karaf.shell.table.ShellTable

  }
   
    private void checkDuplicateExports() {
        Bundle[] bundles = bundleContext.getBundles();
        SortedMap<String, PackageVersion> packageVersionMap = getDuplicatePackages(bundles);
        ShellTable table = new ShellTable();
        table.column(new Col("Package Name"));
        table.column(new Col("Version"));
        table.column(new Col("Exporting bundles (ID)"));
      
        for (String key : packageVersionMap.keySet()) {
            PackageVersion pVer = packageVersionMap.get(key);
            if (pVer.getBundles().size() > 1) {
              String pBundles = getBundlesSt(pVer.getBundles());
              table.addRow().addContent(pVer.getPackageName(), pVer.getVersion().toString(), pBundles);
            }
        }
        table.print(System.out, !noFormat);
    }
View Full Code Here

Examples of org.apache.karaf.shell.table.ShellTable

    protected void printMethodList(CommandSession session, PrintStream out, SortedMap<String, String> commands) {
        Terminal term = (Terminal) session.get(".jline.terminal");
        int termWidth = term != null ? term.getWidth() : 80;
        out.println(Ansi.ansi().a(Ansi.Attribute.INTENSITY_BOLD).a("COMMANDS").a(Ansi.Attribute.RESET));
        ShellTable table = new ShellTable().noHeaders().separator(" ").size(termWidth);
        table.column(new Col("Command").maxSize(35));
        table.column(new Col("Description"));
        for (Map.Entry<String,String> entry : commands.entrySet()) {
            String key = NameScoping.getCommandNameWithoutGlobalPrefix(session, entry.getKey());
            table.addRow().addContent(key, entry.getValue());
        }
        table.print(out, true);
    }
View Full Code Here

Examples of org.apache.karaf.shell.table.ShellTable

    @Argument(index = 0, name = "datasource", description = "The JDBC datasource name", required = true, multiValued = false)
    String datasource;

    public Object doExecute() throws Exception {
        ShellTable table = new ShellTable();

        table.column("Property");
        table.column("Value");

        Map<String, String> info = this.getJdbcService().info(datasource);
        for (String property : info.keySet()) {
            table.addRow().addContent(property, info.get(property));
        }

        table.print(System.out);

        return null;
    }
View Full Code Here

Examples of org.apache.karaf.shell.table.ShellTable

    @Argument(index = 0, name = "datasource", description = "The JDBC datasource to use", required = true, multiValued = false)
    String datasource;

    public Object doExecute() throws Exception {
        ShellTable table = new ShellTable();

        Map<String, List<String>> map = this.getJdbcService().tables(datasource);
        int rowCount = 0;
        for (String column : map.keySet()) {
            table.column(column);
            rowCount = map.get(column).size();
        }

        for (int i = 0; i < rowCount; i++) {
            Row row = table.addRow();
            for (String column : map.keySet()) {
                row.addContent(map.get(column).get(i));
            }
        }

        table.print(System.out);

        return null;
    }
View Full Code Here

Examples of org.apache.karaf.shell.table.ShellTable

    @Argument(index = 1, name = "query", description = "The SQL query to execute", required = true, multiValued = false)
    String query;

    public Object doExecute() throws Exception {
        ShellTable table = new ShellTable();

        Map<String, List<String>> map = this.getJdbcService().query(datasource, query);
        int rowCount = 0;
        for (String column : map.keySet()) {
            table.column(column);
            rowCount = map.get(column).size();
        }

        for (int i = 0; i < rowCount; i++) {
            Row row = table.addRow();
            for (String column : map.keySet()) {
                row.addContent(map.get(column).get(i));
            }
        }

        table.print(System.out);

        return null;
    }
View Full Code Here

Examples of org.apache.karaf.shell.table.ShellTable

@Command(scope = "jdbc", name = "datasources", description = "List the JDBC datasources")
public class DataSourcesCommand extends JdbcCommandSupport {

    public Object doExecute() throws Exception {
        ShellTable table = new ShellTable();

        table.column("Name");
        table.column("Product");
        table.column("Version");
        table.column("URL");

        List<String> datasources = this.getJdbcService().datasources();
        for (String datasource : datasources) {
            Map<String, String> info = this.getJdbcService().info(datasource);
            table.addRow().addContent(datasource, info.get("db.product"), info.get("db.version"), info.get("url"));
        }

        table.print(System.out);

        return null;
    }
View Full Code Here

Examples of org.apache.karaf.shell.table.ShellTable


    private final IdComparator idComparator = new IdComparator();
    @Override
    protected Object doScrAction(ScrService scrService) throws Exception {
        ShellTable table = new ShellTable();
        table.column("ID");
        table.column("State");
        table.column("Component Name");

        Component[] components = scrService.getComponents();
        Arrays.sort(components, idComparator);
        for (Component component : ScrUtils.emptyIfNull(Component.class, components)) {
            if (showHidden) {
                // we display all because we are overridden
                table.addRow().addContent(component.getId(), ScrUtils.getState(component.getState()), component.getName());
            } else {
                if (ScrActionSupport.isHiddenComponent(component)) {
                    // do nothing
                } else {
                    // we aren't hidden so print it
                    table.addRow().addContent(component.getId(), ScrUtils.getState(component.getState()), component.getName());
                }
            }
        }
        return null;
    }
View Full Code Here

Examples of org.apache.karaf.shell.table.ShellTable

public class ShellTableTest {

    @Test
    public void testTable() {
        ShellTable table = new ShellTable();
        table.column(new Col("id").alignRight().maxSize(5));
        table.column(new Col("Name").maxSize(20));
        table.column(new Col("Centered").alignCenter());

        table.addRow().addContent(1, "Test", "Description");
        table.addRow().addContent(20, "My name", "Description");

        Row row = table.addRow();
        row.addContent(123456789);
        row.addContent("A very long text that should be cut");
        row.addContent("A very long text that should not be cut");

        StringWriter writer = new StringWriter();
        PrintStream out = new PrintStream(new WriterOutputStream(writer));
        table.print(out, true);
        out.flush();
        String expected =
                "   id | Name                 |                Centered                \n" +
                "----------------------------------------------------------------------\n" +
                "    1 | Test                 |               Description              \n" +
View Full Code Here

Examples of org.apache.karaf.shell.table.ShellTable

        Assert.assertEquals(expected, getString(writer));
    }

    @Test
    public void testGrow() {
        ShellTable table = new ShellTable().size(10);
        table.column(new Col("1"));
        table.column(new Col("2"));

        table.addRow().addContent("1", "2");

        StringWriter writer = new StringWriter();
        PrintStream out = new PrintStream(new WriterOutputStream(writer));
        table.print(out, true);
        out.flush();
        String expected =
                "1      | 2\n" +
            "----------\n" +
            "1      | 2\n";
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.