Example usage for com.vaadin.ui VerticalLayout setSpacing

List of usage examples for com.vaadin.ui VerticalLayout setSpacing

Introduction

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

Prototype

@Override
    public void setSpacing(boolean spacing) 

Source Link

Usage

From source file:de.uni_tuebingen.qbic.qbicmainportlet.PatientView.java

License:Open Source License

/**
 * //from   w  w  w .ja  v a  2  s.com
 * @param statusValues
 * @return
 */
public VerticalLayout initProjectStatus() {
    status = new VerticalLayout();
    status.setWidth(100.0f, Unit.PERCENTAGE);

    status.setMargin(new MarginInfo(true, false, true, true));
    status.setSpacing(true);
    // status.setCaption("Project Status");
    // status.setIcon(FontAwesome.CHECK_SQUARE);
    status.setSizeFull();

    VerticalLayout projectStatus = new VerticalLayout();
    projectStatus.setCaption("Status");
    projectStatus.setMargin(new MarginInfo(true, false, true, true));
    projectStatus.setSpacing(true);

    experiments = new Grid();
    experiments.setReadOnly(true);
    experiments.setWidth(100.0f, Unit.PERCENTAGE);
    status.addComponent(experiments);

    ProgressBar progressBar = new ProgressBar();
    progressBar.setValue(0f);
    status.addComponent(progressBar);

    projectStatus.addComponent(status);

    return projectStatus;
}

From source file:de.uni_tuebingen.qbic.qbicmainportlet.PatientView.java

License:Open Source License

/**
 * for both graphs//from   ww w  . j  a v a  2  s  .  com
 * 
 * @return the tablayout containing both graphs
 */
Component initGraphs() {
    TabSheet graphTab = new TabSheet();
    graphTab.setCaption("Project Graph");

    VerticalLayout graphSection = new VerticalLayout();
    graphSectionContent = new VerticalLayout();

    graphSection.setCaption("Project Graph");

    graphSectionContent.setMargin(new MarginInfo(true, false, true, true));
    // graphSection.setMargin(new MarginInfo(true, false, true, true));
    graphSection.setMargin(true);
    graphSection.setSpacing(true);
    graphSection.setWidth("100%");
    graphSectionContent.setWidth("100%");

    OpenBisClient openbis = datahandler.getOpenBisClient();
    Map<String, String> taxMap = openbis.getVocabCodesAndLabelsForVocab("Q_NCBI_TAXONOMY");
    Map<String, String> tissueMap = openbis.getVocabCodesAndLabelsForVocab("Q_PRIMARY_TISSUES");
    newGraphContent = new GraphPage(taxMap, tissueMap);

    graphSection.addComponent(graphSectionContent);
    graphTab.addTab(graphSection, "Sample Graph");
    graphTab.addTab(newGraphContent, "Sample Graph v2 (beta)");
    return graphTab;
}

From source file:de.uni_tuebingen.qbic.qbicmainportlet.ProjectView.java

License:Open Source License

/**
 * initializes the description layout/*from w ww .  ja  v  a 2s. co  m*/
 * 
 * @return
 */
VerticalLayout initDescription() {
    VerticalLayout projDescription = new VerticalLayout();
    projDescriptionContent = new VerticalLayout();

    projDescription.setCaption("");

    // String desc = currentBean.getDescription();
    // if (!desc.isEmpty()) {
    // descContent.setValue(desc);
    // }
    descContent = new Label("");
    // contact.setValue("<a
    // href=\"mailto:info@qbic.uni-tuebingen.de?subject=Question%20concerning%20project%20"
    // + currentBean.getId()
    // + "\" style=\"color: #0068AA; text-decoration: none\">Send question regarding project "
    // + currentBean.getId() + "</a>");
    contact = new Label("", ContentMode.HTML);
    projDescriptionContent.addComponent(descContent);
    projDescriptionContent.addComponent(contact);
    projDescriptionContent.setMargin(new MarginInfo(true, false, true, true));
    // projDescriptionContent.setCaption("Description");
    // projDescriptionContent.setIcon(FontAwesome.FILE_TEXT_O);

    projDescription.addComponent(projDescriptionContent);
    projDescriptionContent.setSpacing(true);
    projDescription.setMargin(new MarginInfo(true, false, true, true));
    projDescription.setWidth("100%");
    projDescription.setSpacing(true);
    projDescription.addComponent(projectInformation);

    return projDescription;
}

From source file:de.uni_tuebingen.qbic.qbicmainportlet.ProjectView.java

License:Open Source License

/**
 * /*from www  . j a  va2s  .  c om*/
 * @return
 * 
 */
VerticalLayout initStatistics() {
    VerticalLayout statistics = new VerticalLayout();
    statistics.setCaption("Status");

    statContent = new HorizontalLayout();
    statContent.addComponent(new Label(""));

    statContent.setMargin(new MarginInfo(true, false, false, true));
    statContent.setSpacing(true);

    statistics.addComponent(statContent);
    statistics.setMargin(new MarginInfo(true, false, false, true));
    statistics.setSpacing(true);

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

    statistics.addComponent(status);
    return statistics;
}

From source file:de.uni_tuebingen.qbic.qbicmainportlet.ProjInformationComponent.java

License:Open Source License

/**
 * Precondition: {DatasetView#table} has to be initialized. e.g. with
 * {DatasetView#buildFilterTable} If it is not, strange behaviour has to be expected. builds the
 * Layout of this view.// ww w . j a  va 2s  .co  m
 */
private void buildLayout(Boolean dataAvailable, String projectType) {
    vert.removeAllComponents();

    // Table (containing datasets) section
    VerticalLayout tableSection = new VerticalLayout();
    HorizontalLayout tableSectionContent = new HorizontalLayout();

    VerticalLayout projDescription = new VerticalLayout();
    VerticalLayout projDescriptionContent = new VerticalLayout();

    tableSectionContent.setMargin(new MarginInfo(false, false, false, false));
    projDescriptionContent.setMargin(new MarginInfo(false, false, false, false));

    descHorz.addComponent(descContent);
    descHorz.addComponent(descEdit);
    descHorz.setComponentAlignment(descEdit, Alignment.TOP_RIGHT);
    descHorz.setExpandRatio(descContent, 0.9f);
    descHorz.setExpandRatio(descEdit, 0.1f);

    projDescriptionContent.addComponent(descHorz);
    projDescriptionContent.addComponent(peopleInCharge);
    // descContent.setWidth("80%");
    projDescriptionContent.addComponent(descriptionPanel);
    projDescriptionContent.addComponent(statusPanel);
    // longDescription.setWidth("80%");
    // projDescriptionContent.addComponent(experimentLabel);
    // projDescriptionContent.addComponent(statusContent);

    // statusContent.setSpacing(true);
    // statusContent.setMargin(new MarginInfo(false, false, false, true));

    if (projectType.equals("patient")) {
        String patientInfo = "";
        Boolean available = false;

        SearchCriteria sampleSc = new SearchCriteria();
        sampleSc.addMatchClause(
                MatchClause.createAttributeMatch(MatchClauseAttribute.TYPE, "Q_BIOLOGICAL_ENTITY"));
        SearchCriteria projectSc = new SearchCriteria();
        projectSc.addMatchClause(
                MatchClause.createAttributeMatch(MatchClauseAttribute.PROJECT, projectBean.getCode()));
        sampleSc.addSubCriteria(SearchSubCriteria.createExperimentCriteria(projectSc));

        SearchCriteria experimentSc = new SearchCriteria();
        experimentSc.addMatchClause(MatchClause.createAttributeMatch(MatchClauseAttribute.TYPE,
                model.ExperimentType.Q_EXPERIMENTAL_DESIGN.name()));
        sampleSc.addSubCriteria(SearchSubCriteria.createExperimentCriteria(experimentSc));
        List<ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Sample> samples = datahandler.getOpenBisClient()
                .getFacade().searchForSamples(sampleSc);
        for (ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Sample sample : samples) {
            if (sample.getProperties().get("Q_ADDITIONAL_INFO") != null) {
                available = true;
                String[] splitted = sample.getProperties().get("Q_ADDITIONAL_INFO").split(";");
                for (String s : splitted) {
                    String[] splitted2 = s.split(":");
                    patientInfo += String.format("<p><u>%s</u>: %s </p> ", splitted2[0], splitted2[1]);
                }
            }
        }

        if (available) {
            patientInformation.setValue(patientInfo);
        } else {
            patientInformation.setValue("No patient information provided.");
        }

        updateHLALayout();
        projDescriptionContent.addComponent(patientInformation);
        projDescriptionContent.addComponent(hlaTypeLabel);

        // Vaccine Designer

        /*
         * Button vaccineDesigner = new Button("Vaccine Designer");
         * vaccineDesigner.setStyleName(ValoTheme.BUTTON_PRIMARY);
         * vaccineDesigner.setIcon(FontAwesome.CUBES);
         * 
         * vaccineDesigner.addClickListener(new ClickListener() {
         * 
         * @Override public void buttonClick(ClickEvent event) {
         * 
         * ArrayList<String> message = new ArrayList<String>(); message.add("clicked"); StringBuilder
         * sb = new StringBuilder("type="); sb.append("vaccinedesign"); sb.append("&");
         * sb.append("id="); sb.append(projectBean.getId()); message.add(sb.toString());
         * message.add(VaccineDesignerView.navigateToLabel); state.notifyObservers(message);
         */
        // UI.getCurrent().getNavigator()
        // .navigateTo(String.format(VaccineDesignerView.navigateToLabel));
        // }
        // });

        // projDescriptionContent.addComponent(vaccineDesigner);

    }

    projDescriptionContent.addComponent(tsvDownloadContent);

    projDescription.addComponent(projDescriptionContent);

    projDescriptionContent.setSpacing(true);
    projDescription.setMargin(new MarginInfo(false, false, true, true));
    projDescription.setWidth("100%");
    projDescription.setSpacing(true);

    // descriptionLabel.setWidth("100%");
    // tableSection.addComponent(descriptionLabel);
    tableSectionContent.addComponent(this.datasetTable);

    projDescriptionContent.addComponent(contact);

    tableSection.setMargin(new MarginInfo(true, false, false, true));
    tableSection.setSpacing(true);

    tableSection.addComponent(tableSectionContent);

    this.vert.addComponent(projDescription);

    datasetTable.setWidth("100%");
    tableSection.setWidth("100%");
    tableSectionContent.setWidth("100%");

    // this.table.setSizeFull();

    HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setMargin(new MarginInfo(false, false, true, false));
    buttonLayout.setHeight(null);
    // buttonLayout.setWidth("100%");
    buttonLayout.setSpacing(true);

    this.download.setEnabled(false);
    buttonLayout.setSpacing(true);

    Button checkAll = new Button("Select all datasets");
    checkAll.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            for (Object itemId : datasetTable.getItemIds()) {
                ((CheckBox) datasetTable.getItem(itemId).getItemProperty("Select").getValue()).setValue(true);
            }
        }
    });

    Button uncheckAll = new Button("Unselect all datasets");
    uncheckAll.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            for (Object itemId : datasetTable.getItemIds()) {
                ((CheckBox) datasetTable.getItem(itemId).getItemProperty("Select").getValue()).setValue(false);
            }
        }
    });

    buttonLayout.addComponent(checkAll);
    buttonLayout.addComponent(uncheckAll);

    buttonLayout.addComponent(checkAll);
    buttonLayout.addComponent(uncheckAll);
    buttonLayout.addComponent(this.download);
    /**
     * prepare download.
     */
    download.setResource(new ExternalResource("javascript:"));
    download.setEnabled(false);

    for (final Object itemId : this.datasetTable.getItemIds()) {
        setCheckedBox(itemId, (String) this.datasetTable.getItem(itemId).getItemProperty("CODE").getValue());
    }

    /*
     * Send message that in datasetview the following was selected. WorkflowViews get those messages
     * and save them, if it is valid information for them.
     */
    this.datasetTable.addValueChangeListener(new ValueChangeListener() {
        /**
         * 
         */
        private static final long serialVersionUID = -3554627008191389648L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            // Nothing selected or more than one selected.
            Set<Object> selectedValues = (Set<Object>) event.getProperty().getValue();
            State state = (State) UI.getCurrent().getSession().getAttribute("state");
            ArrayList<String> message = new ArrayList<String>();
            message.add("DataSetView");
            if (selectedValues != null && selectedValues.size() == 1) {
                Iterator<Object> iterator = selectedValues.iterator();
                Object next = iterator.next();
                String datasetType = (String) datasetTable.getItem(next).getItemProperty("Dataset Type")
                        .getValue();
                message.add(datasetType);
                String project = (String) datasetTable.getItem(next).getItemProperty("Project").getValue();

                String space = datahandler.getOpenBisClient().getProjectByCode(project).getSpaceCode();// .getIdentifier().split("/")[1];
                message.add(project);
                message.add((String) datasetTable.getItem(next).getItemProperty("Sample").getValue());
                // message.add((String) table.getItem(next).getItemProperty("Sample Type").getValue());
                message.add((String) datasetTable.getItem(next).getItemProperty("dl_link").getValue());
                message.add((String) datasetTable.getItem(next).getItemProperty("File Name").getValue());
                message.add(space);
                // state.notifyObservers(message);
            } else {
                message.add("null");
            } // TODO
              // state.notifyObservers(message);

        }
    });

    this.datasetTable.addItemClickListener(new ItemClickListener() {
        @Override
        public void itemClick(ItemClickEvent event) {
            if (!event.isDoubleClick()) {
                String datasetCode = (String) datasetTable.getItem(event.getItemId()).getItemProperty("CODE")
                        .getValue();
                String datasetFileName = (String) datasetTable.getItem(event.getItemId())
                        .getItemProperty("File Name").getValue();
                URL url;
                try {
                    Resource res = null;
                    Object parent = datasetTable.getParent(event.getItemId());
                    if (parent != null) {
                        String parentDatasetFileName = (String) datasetTable.getItem(parent)
                                .getItemProperty("File Name").getValue();
                        url = datahandler.getOpenBisClient().getUrlForDataset(datasetCode,
                                parentDatasetFileName + "/" + datasetFileName);
                    } else {
                        url = datahandler.getOpenBisClient().getUrlForDataset(datasetCode, datasetFileName);
                    }

                    Window subWindow = new Window();
                    VerticalLayout subContent = new VerticalLayout();
                    subContent.setMargin(true);
                    subWindow.setContent(subContent);
                    QbicmainportletUI ui = (QbicmainportletUI) UI.getCurrent();
                    Boolean visualize = false;

                    if (datasetFileName.endsWith(".pdf")) {
                        QcMlOpenbisSource re = new QcMlOpenbisSource(url);
                        StreamResource streamres = new StreamResource(re, datasetFileName);
                        streamres.setMIMEType("application/pdf");
                        res = streamres;
                        visualize = true;
                    }

                    if (visualize) {
                        LOGGER.debug("Is resource null?: " + String.valueOf(res == null));
                        BrowserFrame frame = new BrowserFrame("", res);

                        frame.setSizeFull();
                        subContent.addComponent(frame);

                        // Center it in the browser window
                        subWindow.center();
                        subWindow.setModal(true);
                        subWindow.setSizeFull();

                        frame.setHeight((int) (ui.getPage().getBrowserWindowHeight() * 0.9), Unit.PIXELS);

                        // Open it in the UI
                        ui.addWindow(subWindow);
                    }

                } catch (MalformedURLException e) {
                    LOGGER.error(String.format("Visualization failed because of malformedURL for dataset: %s",
                            datasetCode));
                    Notification.show(
                            "Given dataset has no file attached to it!! Please Contact your project manager. Or check whether it already has some data",
                            Notification.Type.ERROR_MESSAGE);
                }
            }
        }
    });

    // this.vert.addComponent(buttonLayout);
    if (dataAvailable) {
        this.vert.addComponent(tableSection);
        tableSection.addComponent(buttonLayout);
        projDescription.setMargin(new MarginInfo(false, false, false, true));
    }
}

From source file:de.uni_tuebingen.qbic.qbicmainportlet.SampleView.java

License:Open Source License

/**
 * initializes the description layout//w w  w . j a va  2 s .c  o m
 * 
 * @return
 */
VerticalLayout initDescription() {
    VerticalLayout sampleDescription = new VerticalLayout();
    VerticalLayout sampleDescriptionContent = new VerticalLayout();

    // sampleDescriptionContent.setMargin(true);
    sampleDescription.setCaption("");

    // sampleDescriptionContent.setIcon(FontAwesome.FILE_TEXT_O);
    sampleTypeLabel = new Label("");
    sampleParentLabel = new Label("", ContentMode.HTML);

    parentButton = new Button("");
    parentButton.setStyleName(ValoTheme.BUTTON_LINK);
    parentButton.setIcon(FontAwesome.ARROW_CIRCLE_RIGHT);

    // Navigate to parent sample given by caption of button
    parentButton.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            State state = (State) UI.getCurrent().getSession().getAttribute("state");
            ArrayList<String> message = new ArrayList<String>();
            message.add("clicked");
            message.add(currentBean.getParents().get(0).getIdentifier());
            message.add("sample");
            state.notifyObservers(message);
        }
    });

    numberOfDatasetsLabel = new Label("");
    lastChangedDatasetLabel = new Label("");
    propertiesLabel = new Label("", ContentMode.HTML);
    propertiesLabel.setCaption("Properties");
    experimentalFactorLabel = new Label("", ContentMode.HTML);

    sampleDescriptionContent.addComponent(sampleTypeLabel);
    sampleDescriptionContent.addComponent(sampleParentLabel);
    sampleDescriptionContent.addComponent(parentButton);
    // sampleDescriptionContent.addComponent(numberOfDatasetsLabel);
    // sampleDescriptionContent.addComponent(lastChangedDatasetLabel);
    sampleDescriptionContent.addComponent(propertiesLabel);
    sampleDescriptionContent.addComponent(experimentalFactorLabel);
    sampleDescriptionContent.setSpacing(true);

    sampleDescriptionContent.setMargin(new MarginInfo(true, false, true, true));
    sampleDescription.addComponent(sampleDescriptionContent);
    sampleDescription.setMargin(new MarginInfo(true, false, true, true));
    return sampleDescription;
}

From source file:de.uni_tuebingen.qbic.qbicmainportlet.SampleView.java

License:Open Source License

/**
 * //  w ww  .j a va  2s. c  om
 * @return
 * 
 */
VerticalLayout initStatistics() {

    // Statistics of sample
    VerticalLayout statistics = new VerticalLayout();
    HorizontalLayout statContent = new HorizontalLayout();
    statistics.setCaption("Statistics");
    // statContent.setIcon(FontAwesome.BAR_CHART_O);
    numberOfDatasetsLabel = new Label("");
    statContent.addComponent(numberOfDatasetsLabel);
    lastChangedDatasetLabel = new Label("");
    statContent.addComponent(lastChangedDatasetLabel);
    statContent.setMargin(new MarginInfo(true, false, false, true));
    statContent.setSpacing(true);
    // statContent.setMargin(true);
    // statContent.setSpacing(true);

    statistics.addComponent(statContent);
    // statistics.setMargin(true);

    // Properties of sample
    VerticalLayout properties = new VerticalLayout();
    VerticalLayout propertiesContent = new VerticalLayout();
    // propertiesContent.setCaption("Properties");
    // propertiesContent.setIcon(FontAwesome.LIST_UL);
    propertiesLabel = new Label("", ContentMode.HTML);

    propertiesContent.addComponent(propertiesLabel);
    propertiesContent.setMargin(new MarginInfo(true, false, false, true));

    properties.addComponent(propertiesContent);
    // properties.setMargin(true);
    statistics.addComponent(properties);

    // Experimental factors of sample
    VerticalLayout experimentalFactors = new VerticalLayout();
    VerticalLayout experimentalFactorsContent = new VerticalLayout();
    // experimentalFactorsContent.setCaption("Experimental Factors");
    // experimentalFactorsContent.setIcon(FontAwesome.TH);
    experimentalFactorLabel = new Label("", ContentMode.HTML);
    experimentalFactorsContent.addComponent(experimentalFactorLabel);
    experimentalFactorsContent.setMargin(new MarginInfo(true, false, true, true));

    experimentalFactors.addComponent(experimentalFactorsContent);
    statistics.addComponent(experimentalFactors);
    statistics.setSpacing(true);
    statistics.setMargin(new MarginInfo(true, false, true, true));

    return statistics;
}

From source file:de.uni_tuebingen.qbic.qbicmainportlet.SearchResultsView.java

License:Open Source License

void buildLayout(int browserHeight, int browserWidth, WebBrowser browser) {
    // this.setMargin(new MarginInfo(true, true, false, false));
    // clean up first
    searchResultsLayout.removeAllComponents();
    searchResultsLayout.setWidth("100%");
    // searchResultsLayout.setSpacing(true);

    searchResultsLayout.setCaption("Search results for query '" + queryString + "'");
    // Label header = new Label("Search results for query '" + queryString + "':");
    // searchResultsLayout.addComponent(header);

    // updateView(browserWidth, browserWidth, browser);

    VerticalLayout viewContent = new VerticalLayout();
    viewContent.setWidth("100%");
    viewContent.setSpacing(true);
    viewContent.setMargin(new MarginInfo(true, false, false, false));

    List<String> showOptions = datahandler.getShowOptions();

    if (showOptions.contains("Projects")) {
        projectGrid = new Grid(projBeanContainer);
        projectGrid.setCaption("Found Projects");
        projectGrid.setColumnOrder("projectID", "description");
        projectGrid.setSizeFull();//from   ww  w.j a  v  a 2s .c  om

        projectGrid.setHeightMode(HeightMode.ROW);
        projectGrid.setHeightByRows(5);
        projectGrid.setSelectionMode(SelectionMode.SINGLE);

        projectGrid.addItemClickListener(new ItemClickListener() {

            @Override
            public void itemClick(ItemClickEvent event) {
                // TODO Auto-generated method stub
                String cellType = new String(event.getPropertyId().toString());

                if (cellType.equals("projectID")) {
                    String cellContent = new String(
                            projBeanContainer.getContainerProperty(event.getItemId(), event.getPropertyId())
                                    .getValue().toString());

                    State state = (State) UI.getCurrent().getSession().getAttribute("state");
                    ArrayList<String> message = new ArrayList<String>();
                    message.add("clicked");
                    message.add(cellContent);
                    message.add("project");
                    state.notifyObservers(message);
                }
            }
        });

        if (projBeanContainer.size() == 0) {
            Label noSamples = new Label("no projects were found");
            noSamples.setCaption("Found Projects");
            viewContent.addComponent(noSamples);
        } else {
            viewContent.addComponent(projectGrid);
        }
    }

    if (showOptions.contains("Experiments")) {
        // expGrid = new Grid(expBeanContainer);
        expGrid = new Grid(expBeanContainer);
        expGrid.setCaption("Found Experiments");
        expGrid.setColumnOrder("experimentID", "experimentName", "matchedField");
        expGrid.setSizeFull();

        expGrid.getColumn("experimentID").setExpandRatio(0);
        expGrid.getColumn("experimentName").setExpandRatio(1);
        expGrid.getColumn("matchedField").setExpandRatio(1);

        expGrid.setHeightMode(HeightMode.ROW);
        expGrid.setHeightByRows(5);
        expGrid.setSelectionMode(SelectionMode.SINGLE);

        expGrid.addItemClickListener(new ItemClickListener() {
            @Override
            public void itemClick(ItemClickEvent event) {
                String cellType = new String(event.getPropertyId().toString());

                if (cellType.equals("experimentID")) {
                    String cellContent = new String(
                            expBeanContainer.getContainerProperty(event.getItemId(), event.getPropertyId())
                                    .getValue().toString());

                    State state = (State) UI.getCurrent().getSession().getAttribute("state");
                    ArrayList<String> message = new ArrayList<String>();
                    message.add("clicked");
                    message.add(cellContent);
                    message.add("experiment");
                    state.notifyObservers(message);
                }
            }
        });

        if (expBeanContainer.size() == 0) {
            Label noExps = new Label("no experiments were found");
            noExps.setCaption("Found Experiments");
            viewContent.addComponent(noExps);
        } else {
            viewContent.addComponent(expGrid);
        }

    }

    if (showOptions.contains("Samples")) {
        sampleGrid = new Grid(sampleBeanContainer);
        sampleGrid.setCaption("Found Samples");
        sampleGrid.setColumnOrder("sampleID", "sampleName", "matchedField");
        sampleGrid.setSizeFull();

        sampleGrid.getColumn("sampleID").setExpandRatio(0);
        sampleGrid.getColumn("sampleName").setExpandRatio(1);
        sampleGrid.getColumn("matchedField").setExpandRatio(1);

        sampleGrid.setHeightMode(HeightMode.ROW);
        sampleGrid.setHeightByRows(5);
        sampleGrid.setSelectionMode(SelectionMode.SINGLE);

        sampleGrid.addItemClickListener(new ItemClickListener() {
            @Override
            public void itemClick(ItemClickEvent event) {
                String cellType = new String(event.getPropertyId().toString());

                if (cellType.equals("sampleID")) {
                    String cellContent = new String(
                            sampleBeanContainer.getContainerProperty(event.getItemId(), event.getPropertyId())
                                    .getValue().toString());

                    State state = (State) UI.getCurrent().getSession().getAttribute("state");
                    ArrayList<String> message = new ArrayList<String>();
                    message.add("clicked");
                    message.add(cellContent);
                    message.add("sample");
                    state.notifyObservers(message);
                }
            }
        });

        if (sampleBeanContainer.size() == 0) {
            Label noSamples = new Label("no samples were found");
            noSamples.setCaption("Found Samples");
            viewContent.addComponent(noSamples);
        } else {
            viewContent.addComponent(sampleGrid);
        }
    }

    searchResultsLayout.addComponent(viewContent);

    this.addComponent(searchResultsLayout);
}

From source file:dev.DevUI.java

License:Open Source License

@Override
protected void init(VaadinRequest request) {

    final VerticalLayout mainLayout = new VerticalLayout();
    mainLayout.setSpacing(true);
    mainLayout.setMargin(true);//  w w  w  .  j  a v  a2 s .  c o m

    PluploadManager mgr = createUploadManager("Manager 1");
    PluploadManager mgr2 = createUploadManager("Manager 2");
    PluploadManager mgr3 = createChunkingUploadManager("Manager 3");

    mgr.getUploader().addFilter(new PluploadFilter("music", "mp3,flac"));

    VerticalLayout dropZone = new VerticalLayout() {
        {
            addComponent(new Label("Additional drop zone for music files"));
            setId("music-drop-zone");
        }
    };

    mgr.getUploader().addDropZone(dropZone);

    mgr2.getUploader().addFilter(new PluploadFilter("images", "jpg, jpeg, png"));
    mgr2.getUploader().setImageResize(
            new PluploadImageResize().setEnabled(true).setCrop(true).setHeight(200).setWidth(400));

    mainLayout.addComponent(mgr);
    mainLayout.addComponent(dropZone);
    mainLayout.addComponent(mgr2);
    mainLayout.addComponent(mgr3);

    PluploadField<File> field = createUploadField();
    final Form form = new Form();
    form.addField("file", field);
    field.addValidator(new NullValidator("file must not be null", false));
    Button submit = new Button("commit form");
    submit.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            form.commit();
        }
    });
    mainLayout.addComponent(form);
    mainLayout.addComponent(submit);

    PluploadField<byte[]> byteField = createByteUploadField();
    mainLayout.addComponent(byteField);

    final Plupload uploader = createSimpleUploader();
    uploader.setEnabled(false);
    Button b = new Button("toggle Enabled!", new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            uploader.setEnabled(!uploader.isEnabled());
        }
    });
    mainLayout.addComponent(b);
    mainLayout.addComponent(uploader);
    final Counter c = new Counter();
    final Button.ClickListener l = new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            Window w = new Window("win");

            if (c.get() < 5) {
                w.setContent(new Button("win", this));
                c.increment();
            } else {
                Field f = createUploadField();
                w.setContent(f);
                c.reset();
            }
            w.setWidth("400px");
            w.setHeight("200px");
            getUI().addWindow(w);
        }
    };

    Button win = new Button("Win");
    win.addClickListener(l);
    mainLayout.addComponent(win);

    Button modal = new Button("modal");
    modal.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            Window w = new Window("modal");

            final PluploadField f = createUploadField();
            w.addCloseListener(new Window.CloseListener() {

                @Override
                public void windowClose(Window.CloseEvent e) {
                    Notification.show("closed modal");
                    f.getUploader().destroy();
                }
            });
            VerticalLayout lay = new VerticalLayout();
            lay.addComponent(f);
            lay.addComponent(new Button("destroy", new Button.ClickListener() {

                @Override
                public void buttonClick(Button.ClickEvent event) {
                    f.getUploader().destroy();
                }
            }));

            w.setContent(lay);
            w.setModal(true);
            getUI().addWindow(w);
        }
    });

    Accordion acc = new Accordion();
    acc.addTab(this.createUploadManager("mgr3"), "uploader");
    acc.addTab(new HorizontalLayout(), "Stub");

    mainLayout.addComponent(acc);

    mainLayout.addComponent(modal);
    this.setContent(mainLayout);

}

From source file:dhbw.clippinggorilla.userinterface.views.ArchiveView.java

public ArchiveView() {
    HorizontalLayout optionsLayout = new HorizontalLayout();
    optionsLayout.setWidth("100%");

    Grid<Clipping> gridClippings = new Grid<>();
    Set<Clipping> clippings = ClippingUtils.getUserClippings(UserUtils.getCurrent(),
            LocalDate.now(ZoneId.of("Europe/Berlin")));
    gridClippings.setItems(clippings);// w  w  w  .  ja  v a  2s.c  om

    InlineDateTimeField datePicker = new InlineDateTimeField();
    datePicker.setValue(LocalDateTime.now(ZoneId.of("Europe/Berlin")));
    datePicker.setLocale(Locale.GERMANY);
    datePicker.setResolution(DateTimeResolution.DAY);
    datePicker.addValueChangeListener(date -> {
        Set<Clipping> clippingsOfDate = ClippingUtils.getUserClippings(UserUtils.getCurrent(),
                date.getValue().toLocalDate());
        gridClippings.setItems(clippingsOfDate);
        gridClippings.getDataProvider().refreshAll();
    });

    DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.MEDIUM);
    formatter.withZone(ZoneId.of("Europe/Berlin"));
    Column columnTime = gridClippings.addColumn(c -> {
        return c.getDate().format(formatter);
    });
    Language.setCustom(Word.TIME, s -> columnTime.setCaption(s));
    Column columnAmountArticles = gridClippings.addColumn(c -> {
        long amountArticles = c.getArticles().values().stream().flatMap(l -> l.stream()).count();
        amountArticles += c.getArticlesFromGroup().values().stream().flatMap(l -> l.stream()).count();
        if (amountArticles != 1) {
            return amountArticles + " " + Language.get(Word.ARTICLES);
        } else {
            return amountArticles + " " + Language.get(Word.ARTICLE);
        }
    });
    Language.setCustom(Word.ARTICLES, s -> {
        columnAmountArticles.setCaption(s);
        gridClippings.getDataProvider().refreshAll();
    });

    gridClippings.setHeight("100%");
    gridClippings.setSelectionMode(Grid.SelectionMode.SINGLE);
    gridClippings.addSelectionListener(c -> {
        if (c.getFirstSelectedItem().isPresent()) {
            currentClipping = c.getFirstSelectedItem().get();
            showClippingBy(currentClipping, currentSort);
        }
    });

    optionsLayout.addComponents(datePicker, gridClippings);
    optionsLayout.setComponentAlignment(datePicker, Alignment.BOTTOM_CENTER);
    optionsLayout.setComponentAlignment(gridClippings, Alignment.BOTTOM_RIGHT);
    optionsLayout.setExpandRatio(gridClippings, 5);

    VerticalLayout sortLayout = new VerticalLayout();

    comboBoxSortOptions = new ComboBox<>(Language.get(Word.SORT_BY));
    Language.setCustom(Word.SORT_BY, s -> {
        comboBoxSortOptions.setCaption(s);
        comboBoxSortOptions.getDataProvider().refreshAll();
    });
    comboBoxSortOptions.setItems(EnumSet.allOf(ClippingView.SortOptions.class));
    comboBoxSortOptions.setItemCaptionGenerator(s -> s.getName());
    comboBoxSortOptions.setItemIconGenerator(s -> s.getIcon());
    comboBoxSortOptions.setValue(currentSort);
    comboBoxSortOptions.setTextInputAllowed(false);
    comboBoxSortOptions.setEmptySelectionAllowed(false);
    comboBoxSortOptions.addStyleName("comboboxsort");
    comboBoxSortOptions.addValueChangeListener(e -> {
        currentSort = e.getValue();
        showClippingBy(currentClipping, currentSort);
    });
    comboBoxSortOptions.setVisible(false);

    sortLayout.setMargin(false);
    sortLayout.setSpacing(false);
    sortLayout.addComponent(comboBoxSortOptions);

    clippingArticlesLayout = new VerticalLayout();
    clippingArticlesLayout.setSpacing(true);
    clippingArticlesLayout.setMargin(false);
    clippingArticlesLayout.setSizeFull();

    addComponents(optionsLayout, sortLayout, clippingArticlesLayout);
}