Search in sources :

Example 1 with BeanItemContainer

use of com.vaadin.data.util.BeanItemContainer in project ANNIS by korpling.

the class DocBrowserTable method generateInfoButtonCell.

public Button generateInfoButtonCell(final String docName) {
    Button btn = new Button();
    btn.setStyleName(ChameleonTheme.BUTTON_BORDERLESS);
    btn.setIcon(INFO_ICON);
    btn.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            try {
                List<Annotation> annos = getDocMetaData(docName);
                /**
                 * Transforms to a list of key value pairs. The values concates the
                 * namespace and ordinary value. Namespaces "NULL" are ignored.
                 */
                // create datasource and bind it to a table
                BeanItemContainer<Annotation> metaContainer = new BeanItemContainer<>(Annotation.class);
                metaContainer.addAll(annos);
                metaContainer.sort(new Object[] { "namespace", "name" }, new boolean[] { true, true });
                Table metaTable = new Table();
                metaTable.setContainerDataSource(metaContainer);
                metaTable.addGeneratedColumn("genname", new MetaDataPanel.MetaTableNameGenerator(metaContainer));
                metaTable.addGeneratedColumn("genvalue", new MetaDataPanel.MetaTableValueGenerator(metaContainer));
                metaTable.setVisibleColumns("genname", "genvalue");
                metaTable.setColumnHeaders(new String[] { "Name", "Value" });
                metaTable.setSizeFull();
                metaTable.setColumnWidth("genname", -1);
                metaTable.setColumnExpandRatio("genvalue", 1.0f);
                metaTable.addStyleName(ChameleonTheme.TABLE_STRIPED);
                // create and style the extra window for the metadata table
                Window metaWin = new Window();
                metaWin.setContent(metaTable);
                metaWin.setCaption("metadata doc " + docName);
                metaWin.center();
                metaWin.setWidth(400, Unit.PIXELS);
                metaWin.setHeight(400, Unit.PIXELS);
                // paint the window
                docBrowserPanel.getUI().addWindow(metaWin);
            } catch (UniformInterfaceException ex) {
                log.error("can not retrieve metadata for document " + docName, ex);
            }
        }
    });
    return btn;
}
Also used : Window(com.vaadin.ui.Window) Table(com.vaadin.ui.Table) BeanItemContainer(com.vaadin.data.util.BeanItemContainer) Annotation(annis.model.Annotation) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) Button(com.vaadin.ui.Button) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Aggregations

Annotation (annis.model.Annotation)1 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)1 BeanItemContainer (com.vaadin.data.util.BeanItemContainer)1 Button (com.vaadin.ui.Button)1 Table (com.vaadin.ui.Table)1 Window (com.vaadin.ui.Window)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1