Example usage for com.vaadin.ui Grid Grid

List of usage examples for com.vaadin.ui Grid Grid

Introduction

In this page you can find the example usage for com.vaadin.ui Grid Grid.

Prototype

public Grid(DataProvider<T, ?> dataProvider) 

Source Link

Document

Creates a new Grid using the given DataProvider .

Usage

From source file:qbic.vaadincomponents.InputFilesComponent.java

License:Open Source License

public void buildForm(Set<Entry<String, Parameter>> wfparameters, BeanItemContainer<DatasetBean> datasets) {

    inputFileForm.removeAllComponents();
    inputFileForm.setSizeFull();/*w  ww  .j a  v  a2  s .c  om*/

    wfmap.clear();
    for (Map.Entry<String, Parameter> entry : wfparameters) {
        wfmap.put(entry.getKey(), entry.getValue());
        GeneratedPropertyContainer gpcontainer = null;
        Grid newGrid = new Grid(gpcontainer);

        if (entry.getValue() instanceof FileParameter) {
            FileParameter fileParam = (FileParameter) entry.getValue();
            List<String> associatedDataTypes = fileParam.getRange();
            // String associatedDataType = fileParam.getTitle();

            if (associatedDataTypes.contains("fasta") || associatedDataTypes.contains("gtf")) {
                // if (associatedDataType.toLowerCase().equals("fasta")) {
                BeanItemContainer<FastaBean> subContainer = new BeanItemContainer<FastaBean>(FastaBean.class);
                FastaDB db = new FastaDB();
                subContainer.addAll(db.getAll());
                gpcontainer = new GeneratedPropertyContainer(subContainer);
                gpcontainer.addGeneratedProperty("Type", new PropertyValueGenerator<String>() {
                    @Override
                    public Class<String> getType() {
                        return String.class;
                    }

                    @Override
                    public String getValue(Item item, Object itemId, Object propertyId) {
                        String detailedType = item.getItemProperty("detailedType").getValue().toString();
                        return detailedType;
                    }
                });
                gpcontainer.removeContainerProperty("path");
                gpcontainer.removeContainerProperty("detailedType");

            }

            else {
                BeanItemContainer<DatasetBean> subContainer = new BeanItemContainer<DatasetBean>(
                        DatasetBean.class);

                for (java.util.Iterator<DatasetBean> i = datasets.getItemIds().iterator(); i.hasNext();) {
                    DatasetBean dataset = i.next();

                    if (associatedDataTypes.contains(dataset.getFileType().toLowerCase())) {

                        // if (associatedDataType.toLowerCase().equals(dataset.getFileType().toLowerCase())) {
                        subContainer.addBean(dataset);
                    }
                }

                gpcontainer = new GeneratedPropertyContainer(subContainer);
                gpcontainer.removeContainerProperty("fullPath");
                gpcontainer.removeContainerProperty("openbisCode");

            }
            newGrid.setContainerDataSource(gpcontainer);
            newGrid.setSelectionMode(SelectionMode.SINGLE);
        }

        else if (entry.getValue() instanceof FileListParameter) {
            FileListParameter fileParam = (FileListParameter) entry.getValue();
            List<String> associatedDataTypes = fileParam.getRange();

            BeanItemContainer<DatasetBean> subContainer = new BeanItemContainer<DatasetBean>(DatasetBean.class);

            for (java.util.Iterator<DatasetBean> i = datasets.getItemIds().iterator(); i.hasNext();) {
                DatasetBean dataset = i.next();

                if (associatedDataTypes.contains(dataset.getFileType().toLowerCase())) {
                    subContainer.addBean(dataset);
                }
            }

            gpcontainer = new GeneratedPropertyContainer(subContainer);
            gpcontainer.removeContainerProperty("fullPath");
            gpcontainer.removeContainerProperty("openbisCode");

            newGrid.setContainerDataSource(gpcontainer);
            newGrid.setSelectionMode(SelectionMode.MULTI);
        }

        else {
            helpers.Utils.Notification("Invalid Inputfile Parameter",
                    "Invalid inputfile parameter has been selected: " + entry.getKey(), "error");
        }

        HorizontalLayout layout = new HorizontalLayout();
        layout.setMargin(new MarginInfo(true, true, true, true));
        layout.setSizeFull();

        newGrid.setWidth("100%");
        layout.addComponent(newGrid);

        // if (newGrid.getContainerDataSource().size() == 0) {
        // helpers.Utils
        // .Notification(
        // "Missing Dataset Type",
        // String
        // .format(
        // "Workflow submission might not be possible because no dataset of type %s is available in
        // this project",
        // entry.getKey()), "warning");
        // Notification.show(
        // String.format("No dataset of type %s available in this project!", entry.getKey()),
        // Type.WARNING_MESSAGE);
        layout.addComponent(newGrid);
        // }

        inputFileForm.addTab(layout, entry.getKey());
    }
}

From source file:qbic.vaadincomponents.SelectFileComponent.java

License:Open Source License

public SelectFileComponent(String mainCaption, String info, String sourceCaption, String destinationCaption,
        BeanItemContainer<?> source, BeanItemContainer<?> destination) {
    setCaption(mainCaption);//from   w  ww  .  j a  v  a 2s  .c  om

    VerticalLayout files = new VerticalLayout();
    files.setSpacing(true);

    // info label
    Label rawFilesInfo = new Label(info);
    rawFilesInfo.addStyleName(ValoTheme.LABEL_COLORED);
    files.addComponent(rawFilesInfo);
    files.setWidth("100%");

    // available files in openbis
    available = new Grid(source);
    available.setCaption(sourceCaption);
    available.setSelectionMode(SelectionMode.MULTI);

    // selected files for anaylsis
    selected = new Grid(destination);

    if (mainCaption.equals("Raw files")) {
        available.removeColumn("fullPath");
        available.removeColumn("openbisCode");
    }

    else if (mainCaption.equals("")) {
        available.removeColumn("name");
        available.removeColumn("path");
        selected.removeColumn("name");
        selected.removeColumn("path");
    }

    selected.setCaption(destinationCaption);
    selected.setSelectionMode(SelectionMode.MULTI);

    for (Grid.Column col : available.getColumns()) {
        col.setWidthUndefined();
    }

    // selectedFiles.set
    // buttons to add or remove files
    VerticalLayout buttons = new VerticalLayout();
    toLeft = new Button();
    toLeft.setIcon(FontAwesome.ARROW_LEFT);

    toRight = new Button();
    toRight.setIcon(FontAwesome.ARROW_RIGHT);
    buttons.addComponent(toRight);
    buttons.addComponent(toLeft);

    GridLayout grids = new GridLayout(3, 1);
    grids.setWidth("100%");

    // grids.setSpacing(true);
    grids.addComponent(available, 0, 0);

    available.setWidth("100%");
    grids.addComponent(buttons, 1, 0);
    grids.addComponent(selected, 2, 0);
    grids.setColumnExpandRatio(0, 0.45f);
    grids.setColumnExpandRatio(1, 0.029f);
    grids.setColumnExpandRatio(2, 0.45f);
    grids.setSpacing(false);
    grids.setComponentAlignment(buttons, com.vaadin.ui.Alignment.MIDDLE_CENTER);

    selected.setWidth("100%");

    files.addComponent(grids);

    this.setCompositionRoot(files);
    files.setMargin(new MarginInfo(true, true, true, false));
    this.setWidth("100%");

}