Example usage for com.vaadin.ui VerticalLayout setWidth

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

Introduction

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

Prototype

@Override
    public void setWidth(String width) 

Source Link

Usage

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

License:Open Source License

/**
 * for both graphs/* w  w w.j a  v a 2 s.c  om*/
 * 
 * @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.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.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.//from  ww w  .ja  v  a  2 s  .c o 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

VerticalLayout initTable() {
    this.table = this.buildFilterTable();
    VerticalLayout tableSection = new VerticalLayout();
    VerticalLayout tableSectionContent = new VerticalLayout();

    tableSection.setCaption("Experiments");
    // tableSectionContent.setCaption("Registered Experiments");
    // tableSectionContent.setIcon(FontAwesome.FLASK);
    tableSectionContent.addComponent(this.table);

    tableSectionContent.setMargin(new MarginInfo(true, false, false, true));
    tableSection.setMargin(new MarginInfo(true, false, false, true));
    this.table.setWidth("100%");
    // tableSection.setWidth(Page.getCurrent().getBrowserWindowWidth() * 0.8f, Unit.PIXELS);
    tableSectionContent.setWidth("100%");

    tableSection.addComponent(tableSectionContent);

    this.export = new Button("Export as TSV");
    buttonLayoutSection = new VerticalLayout();
    HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setHeight(null);//from www . j  ava2  s .  c o  m
    buttonLayout.setWidth("100%");
    buttonLayout.addComponent(this.export);
    buttonLayout.setMargin(new MarginInfo(false, false, true, false));
    buttonLayoutSection.addComponent(buttonLayout);
    buttonLayoutSection.setSpacing(true);
    buttonLayoutSection.setMargin(new MarginInfo(false, false, true, true));

    tableSection.addComponent(buttonLayoutSection);

    return tableSection;
}

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);//  w  w w. ja  v a 2  s.co m
    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();

        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:dhbw.clippinggorilla.userinterface.views.ArchiveView.java

public void createClippingViewByProfile(Clipping clipping) {
    clippingArticlesLayout.removeAllComponents();
    if (clipping.getArticles().keySet().isEmpty() && clipping.getArticlesFromGroup().keySet().isEmpty()) {
        Label labelNoProfile = new Label();
        Language.setCustom(Word.NO_PROFILE_PRESENT, s -> labelNoProfile.setValue(s));
        labelNoProfile.addStyleName(ValoTheme.LABEL_H2);
        clippingArticlesLayout.addComponent(labelNoProfile);
    } else {/*from   w w  w.j  a  v  a 2  s  . c  o m*/
        clipping.getArticles().entrySet().stream().forEach(p -> {
            VerticalLayout layoutProfile = new VerticalLayout();
            layoutProfile.setSpacing(true);
            layoutProfile.setMargin(true);
            layoutProfile.addStyleName("tags");
            layoutProfile.setWidth("100%");
            if (p.getValue().isEmpty()) {
                Label labelNoArticles = new Label();
                Language.setCustom(Word.NO_ARTICLES_PRESENT, s -> labelNoArticles.setValue(s));
                labelNoArticles.addStyleName(ValoTheme.LABEL_H3);
                layoutProfile.addComponent(labelNoArticles);
            } else {
                p.getValue().forEach(a -> layoutProfile.addComponent(createClippingRow(a)));
            }
            Panel panelProfile = new Panel(p.getKey().getName(), layoutProfile);
            clippingArticlesLayout.addComponent(panelProfile);
        });
        clipping.getArticlesFromGroup().entrySet().stream().forEach(p -> {
            VerticalLayout layoutProfile = new VerticalLayout();
            layoutProfile.setSpacing(true);
            layoutProfile.setMargin(true);
            layoutProfile.addStyleName("tags");
            layoutProfile.setWidth("100%");
            if (p.getValue().isEmpty()) {
                Label labelNoArticles = new Label();
                Language.setCustom(Word.NO_ARTICLES_PRESENT, s -> labelNoArticles.setValue(s));
                labelNoArticles.addStyleName(ValoTheme.LABEL_H3);
                layoutProfile.addComponent(labelNoArticles);
            } else {
                p.getValue().forEach(a -> layoutProfile.addComponent(createClippingRow(a)));
            }
            Panel panelProfile = new Panel(Language.get(Word.GROUP) + " " + p.getKey().getGroup().getName()
                    + ": " + p.getKey().getName(), layoutProfile);
            Language.setCustom(Word.GROUP, s -> panelProfile
                    .setCaption(s + " " + p.getKey().getGroup().getName() + ": " + p.getKey().getName()));
            clippingArticlesLayout.addComponent(panelProfile);
        });
    }
}

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

public Component createClippingRow(Article a) {
    Image imageNewsImage = new Image();
    String url = a.getUrlToImage();
    if (url == null || url.isEmpty()) {
        url = a.getSourceAsSource().getLogo().toExternalForm();
    }/*  w  w  w. j av a  2 s  .c om*/
    imageNewsImage.setSource(new ExternalResource(url));
    imageNewsImage.addStyleName("articleimage");

    VerticalLayout layoutNewsImage = new VerticalLayout(imageNewsImage);
    layoutNewsImage.setMargin(false);
    layoutNewsImage.setSpacing(false);
    layoutNewsImage.setWidth("200px");
    layoutNewsImage.setHeight("150px");
    layoutNewsImage.setComponentAlignment(imageNewsImage, Alignment.MIDDLE_CENTER);

    Label labelHeadLine = new Label(a.getTitle(), ContentMode.HTML);
    labelHeadLine.addStyleName(ValoTheme.LABEL_H2);
    labelHeadLine.addStyleName(ValoTheme.LABEL_NO_MARGIN);
    labelHeadLine.setWidth("100%");

    Label labelDescription = new Label(a.getDescription(), ContentMode.HTML);
    labelDescription.setWidth("100%");

    Image imageSource = new Image();
    Source s = a.getSourceAsSource();
    URL logo;
    if (s != null) {
        logo = s.getLogo();
    } else {
        Log.error("Source is null: " + a.getSource());
        return new Label("INTERNAL ERROR");
    }
    if (logo != null) {
        imageSource.setSource(new ExternalResource(logo));
    } else {
        Log.error("Sourcelogo is null: " + s.getName());
    }
    imageSource.setHeight("30px");
    Label labelSource = new Label(a.getSourceAsSource().getName());
    labelSource.addStyleName(ValoTheme.LABEL_SMALL);

    LocalDateTime time = a.getPublishedAtAsLocalDateTime();
    DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG);
    formatter.withZone(ZoneId.of("Europe/Berlin"));
    Label labelDate = new Label(time.format(formatter));
    labelDate.addStyleName(ValoTheme.LABEL_SMALL);

    Label labelAuthor = new Label();
    labelAuthor.addStyleName(ValoTheme.LABEL_SMALL);
    labelAuthor.setWidth("100%");
    if (a.getAuthor() != null && !a.getAuthor().isEmpty()) {
        labelAuthor.setValue(a.getAuthor());
    }

    Button openWebsite = new Button(VaadinIcons.EXTERNAL_LINK);
    openWebsite.addClickListener(e -> UI.getCurrent().getPage().open(a.getUrl(), "_blank", false));

    HorizontalLayout layoutArticleOptions = new HorizontalLayout();
    layoutArticleOptions.setWidth("100%");
    layoutArticleOptions.addComponents(imageSource, labelSource, labelDate, labelAuthor, openWebsite);
    layoutArticleOptions.setComponentAlignment(imageSource, Alignment.MIDDLE_CENTER);
    layoutArticleOptions.setComponentAlignment(labelSource, Alignment.MIDDLE_CENTER);
    layoutArticleOptions.setComponentAlignment(labelDate, Alignment.MIDDLE_CENTER);
    layoutArticleOptions.setComponentAlignment(labelAuthor, Alignment.MIDDLE_LEFT);
    layoutArticleOptions.setComponentAlignment(openWebsite, Alignment.MIDDLE_CENTER);
    layoutArticleOptions.setExpandRatio(labelAuthor, 5);

    VerticalLayout layoutNewsText = new VerticalLayout(labelHeadLine, labelDescription, layoutArticleOptions);
    layoutNewsText.setMargin(false);
    layoutNewsText.setWidth("100%");

    HorizontalLayout layoutClipping = new HorizontalLayout();
    layoutClipping.setWidth("100%");
    layoutClipping.setMargin(true);
    layoutClipping.addComponents(layoutNewsImage, layoutNewsText);
    layoutClipping.setComponentAlignment(layoutNewsImage, Alignment.MIDDLE_CENTER);
    layoutClipping.setExpandRatio(layoutNewsText, 5);
    layoutClipping.addStyleName(ValoTheme.LAYOUT_CARD);
    layoutClipping.addStyleName("tags");
    return layoutClipping;
}

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

public void createClippingViewByProfile(Clipping clipping) {
    clippingArticlesLayout.removeAllComponents();
    clipping.getArticles().entrySet().stream().forEach(p -> {
        VerticalLayout layoutProfile = new VerticalLayout();
        layoutProfile.setSpacing(true);/*from  ww w  .  j  a v a 2 s .  c  om*/
        layoutProfile.setMargin(true);
        layoutProfile.addStyleName("tags");
        layoutProfile.setWidth("100%");
        if (p.getValue().isEmpty()) {
            Label labelNoArticles = new Label();
            Language.setCustom(Word.NO_ARTICLES_PRESENT, s -> labelNoArticles.setValue(s));
            labelNoArticles.addStyleName(ValoTheme.LABEL_H3);
            layoutProfile.addComponent(labelNoArticles);
        } else {
            p.getValue().forEach(a -> layoutProfile.addComponent(createClippingRow(a)));
        }
        Panel panelProfile = new Panel(p.getKey().getName(), layoutProfile);
        clippingArticlesLayout.addComponent(panelProfile);
    });
    clipping.getArticlesFromGroup().entrySet().stream().forEach(p -> {
        VerticalLayout layoutProfile = new VerticalLayout();
        layoutProfile.setSpacing(true);
        layoutProfile.setMargin(true);
        layoutProfile.addStyleName("tags");
        layoutProfile.setWidth("100%");
        if (p.getValue().isEmpty()) {
            Label labelNoArticles = new Label();
            Language.setCustom(Word.NO_ARTICLES_PRESENT, s -> labelNoArticles.setValue(s));
            labelNoArticles.addStyleName(ValoTheme.LABEL_H3);
            layoutProfile.addComponent(labelNoArticles);
        } else {
            p.getValue().forEach(a -> layoutProfile.addComponent(createClippingRow(a)));
        }
        Panel panelProfile = new Panel(
                Language.get(Word.GROUP) + " " + p.getKey().getGroup().getName() + ": " + p.getKey().getName(),
                layoutProfile);
        Language.setCustom(Word.GROUP, s -> panelProfile
                .setCaption(s + " " + p.getKey().getGroup().getName() + ": " + p.getKey().getName()));
        clippingArticlesLayout.addComponent(panelProfile);
    });
}

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

public Component createClippingRow(Article a) {
    Image imageNewsImage = new Image();
    String url = a.getUrlToImage();
    if (url == null || url.isEmpty()) {
        url = a.getSourceAsSource().getLogo().toExternalForm();
    }/*from   w  w  w.  j ava  2  s.c o  m*/
    imageNewsImage.setSource(new ExternalResource(url));
    imageNewsImage.addStyleName("articleimage");

    VerticalLayout layoutNewsImage = new VerticalLayout(imageNewsImage);
    layoutNewsImage.setMargin(false);
    layoutNewsImage.setSpacing(false);
    layoutNewsImage.setWidth("200px");
    layoutNewsImage.setHeight("150px");
    layoutNewsImage.setComponentAlignment(imageNewsImage, Alignment.MIDDLE_CENTER);

    Label labelHeadLine = new Label(a.getTitle(), ContentMode.HTML);
    labelHeadLine.addStyleName(ValoTheme.LABEL_H2);
    labelHeadLine.addStyleName(ValoTheme.LABEL_NO_MARGIN);
    labelHeadLine.setWidth("100%");

    Label labelDescription = new Label(a.getDescription(), ContentMode.HTML);
    labelDescription.setWidth("100%");

    Image imageSource = new Image();
    Source s = a.getSourceAsSource();
    URL logo = null;
    if (s != null) {
        logo = s.getLogo();
    } else {
        Log.error("Source is null: " + a.getSource());
        return new Label("INTERNAL ERROR");
    }
    if (logo != null) {
        imageSource.setSource(new ExternalResource(logo));
    } else {
        Log.error("Sourcelogo is null: " + s.getName());
    }
    imageSource.setHeight("30px");
    Label labelSource = new Label(a.getSourceAsSource().getName());
    labelSource.addStyleName(ValoTheme.LABEL_SMALL);

    LocalDateTime time = a.getPublishedAtAsLocalDateTime();
    DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG);
    formatter.withZone(ZoneId.of("Europe/Berlin"));
    Label labelDate = new Label(time.format(formatter));
    labelDate.addStyleName(ValoTheme.LABEL_SMALL);

    Label labelAuthor = new Label();
    labelAuthor.addStyleName(ValoTheme.LABEL_SMALL);
    labelAuthor.setWidth("100%");
    if (a.getAuthor() != null && !a.getAuthor().isEmpty()) {
        labelAuthor.setValue(a.getAuthor());
    }

    Button openWebsite = new Button(VaadinIcons.EXTERNAL_LINK);
    openWebsite.addClickListener(e -> UI.getCurrent().getPage().open(a.getUrl(), "_blank", false));

    HorizontalLayout layoutArticleOptions = new HorizontalLayout();
    layoutArticleOptions.setWidth("100%");
    layoutArticleOptions.addComponents(imageSource, labelSource, labelDate, labelAuthor, openWebsite);
    layoutArticleOptions.setComponentAlignment(imageSource, Alignment.MIDDLE_CENTER);
    layoutArticleOptions.setComponentAlignment(labelSource, Alignment.MIDDLE_CENTER);
    layoutArticleOptions.setComponentAlignment(labelDate, Alignment.MIDDLE_CENTER);
    layoutArticleOptions.setComponentAlignment(labelAuthor, Alignment.MIDDLE_LEFT);
    layoutArticleOptions.setComponentAlignment(openWebsite, Alignment.MIDDLE_CENTER);
    layoutArticleOptions.setExpandRatio(labelAuthor, 5);

    VerticalLayout layoutNewsText = new VerticalLayout(labelHeadLine, labelDescription, layoutArticleOptions);
    layoutNewsText.setMargin(false);
    layoutNewsText.setWidth("100%");

    HorizontalLayout layoutClipping = new HorizontalLayout();
    layoutClipping.setWidth("100%");
    layoutClipping.setMargin(true);
    layoutClipping.addComponents(layoutNewsImage, layoutNewsText);
    layoutClipping.setComponentAlignment(layoutNewsImage, Alignment.MIDDLE_CENTER);
    layoutClipping.setExpandRatio(layoutNewsText, 5);
    layoutClipping.addStyleName(ValoTheme.LAYOUT_CARD);
    layoutClipping.addStyleName("tags");
    return layoutClipping;
}

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

public VerticalLayout createTab(Group g) {
    User u = UserUtils.getCurrent();//ww w .j ava2s  . c om
    VerticalLayout groupSettingsLayout = new VerticalLayout();
    groupSettingsLayouts.put(g, groupSettingsLayout);
    GridLayout tabContent;
    TextField textFieldName = new TextField();
    if (GroupUtils.isAdmin(g, u)) {
        tabContent = new GridLayout(3, 2);
        Language.set(Word.NAME, textFieldName);
        textFieldName.setWidth("100%");
        textFieldName.setValue(g.getName());
        textFieldName.setMaxLength(255);
        tabContent.addComponent(textFieldName);
        tabContent.setComponentAlignment(textFieldName, Alignment.MIDDLE_LEFT);
    } else {
        tabContent = new GridLayout(3, 1);
    }

    buttonLeave = new Button();
    Language.set(Word.LEAVE, buttonLeave);
    buttonLeave.setIcon(VaadinIcons.MINUS);
    buttonLeave.addStyleName(ValoTheme.BUTTON_DANGER);
    buttonLeave.addClickListener(ce -> {
        ConfirmationDialog.show(Language.get(Word.REALLY_LEAVE_GROUP).replace("[GROUP]", g.getName()), () -> {
            long amountAdmins = g.getUsers().entrySet().stream().filter(e -> e.getValue()).count();
            if (amountAdmins > 1 || !GroupUtils.isAdmin(g, u)) {
                GroupUtils.removeUser(g, u);
                refreshAll(g);
            } else {
                VaadinUtils.errorNotification(Language.get(Word.NOT_ENOUGH_ADMINS_IN_GROUP));
            }
        });
    });

    buttonDelete = new Button();
    Language.set(Word.DELETE, buttonDelete);
    buttonDelete.setIcon(VaadinIcons.TRASH);
    buttonDelete.addStyleName(ValoTheme.BUTTON_DANGER);
    buttonDelete.addClickListener(ce -> {
        ConfirmationDialog.show(Language.get(Word.REALLY_DELETE_GROUP).replace("[GROUP]", g.getName()), () -> {
            GroupUtils.removeGroup(g);
            refreshAll(g);
        });
    });

    Button buttonSave = new Button();
    Language.set(Word.SAVE, buttonSave);
    buttonSave.setIcon(VaadinIcons.CHECK);
    buttonSave.addStyleName(ValoTheme.BUTTON_PRIMARY);
    buttonSave.addClickListener(ce -> {
        if (GroupUtils.isAdmin(g, u)) {
            GroupUtils.changeName(g, textFieldName.getValue());
            accordion.getTab(groupSettingsLayout).setCaption(textFieldName.getValue());
        }
        VaadinUtils.infoNotification(Language.get(Word.SUCCESSFULLY_SAVED));
    });
    buttonSave.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);

    Label placeholder = new Label();
    Label placeholder2 = new Label();
    placeholder2.setWidth("100%");
    Label placeholder3 = new Label();

    GridLayout footer = new GridLayout(4, 1);
    footer.setSpacing(true);
    footer.setMargin(new MarginInfo(false, true));
    footer.setSizeUndefined();
    footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);
    footer.setWidth("100%");
    footer.addStyleName("menubar");
    if (GroupUtils.isAdmin(g, u)) {
        footer.addComponents(placeholder, buttonDelete, buttonLeave, buttonSave);
        footer.setComponentAlignment(buttonDelete, Alignment.MIDDLE_CENTER);
    } else {
        footer.addComponents(placeholder, placeholder3, buttonLeave, buttonSave);
    }
    footer.setColumnExpandRatio(0, 5);
    footer.setComponentAlignment(buttonLeave, Alignment.MIDDLE_CENTER);
    footer.setComponentAlignment(buttonSave, Alignment.MIDDLE_CENTER);

    if (GroupUtils.isAdmin(g, u)) {
        tabContent.addComponent(getProfiles(g), 0, 1, 1, 1);
        tabContent.addComponent(getMembers(g), 2, 1);
    } else {
        tabContent.addComponent(getProfiles(g), 0, 0, 1, 0);
        tabContent.addComponent(getMembers(g), 2, 0);
    }
    tabContent.setWidth("100%");
    tabContent.setSpacing(true);
    tabContent.setMargin(true);
    tabContent.addStyleName("profiles");
    groupSettingsLayout.addComponents(tabContent, footer);
    groupSettingsLayout.setMargin(false);
    groupSettingsLayout.setSpacing(false);
    groupSettingsLayout.setWidth("100%");
    return groupSettingsLayout;
}

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

private Component getProfiles(Group g) {
    VerticalLayout layoutRootProfiles = new VerticalLayout();
    layoutRootProfiles.setMargin(false);
    layoutRootProfiles.setWidth("100%");
    Panel panelProfiles = new Panel(Language.get(Word.PROFILES));
    Language.setCustom(Word.PROFILES, s -> panelProfiles.setCaption(s));
    panelProfiles.setWidth("100%");
    panelProfiles.setHeight("200px");

    VerticalLayout layoutProfiles = new VerticalLayout();
    mapLayoutProfiles.put(g, layoutProfiles);
    layoutProfiles.setWidth("100%");

    refreshProfiles(g, layoutProfiles);/*w  w  w.j  ava  2s. c o  m*/

    panelProfiles.setContent(layoutProfiles);
    layoutRootProfiles.addComponent(panelProfiles);

    if (GroupUtils.isAdmin(g, UserUtils.getCurrent())) {
        CssLayout addProfileGroup = new CssLayout();
        addProfileGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
        addProfileGroup.setWidth("100%");

        TextField textFieldAddProfile = new TextField();
        Language.setCustom(Word.PROFILE_NAME, s -> textFieldAddProfile.setPlaceholder(s));
        textFieldAddProfile.setMaxLength(255);
        textFieldAddProfile.setWidth("35%");
        addProfileGroup.addComponent(textFieldAddProfile);

        Button buttonAddProfile = new Button();
        buttonAddProfile.setIcon(VaadinIcons.PLUS);
        buttonAddProfile.addStyleName(ValoTheme.BUTTON_PRIMARY);
        buttonAddProfile.setWidth("15%");
        buttonAddProfile.addClickListener(e -> {
            try {
                String name = textFieldAddProfile.getValue();
                textFieldAddProfile.clear();
                Runnable onClose = () -> refreshAll(g);
                UI.getCurrent().addWindow(GroupProfileWindow.create(g, name, true, onClose));
            } catch (UserNotFoundException ex) {
                VaadinUtils.errorNotification(Language.get(Word.USER_NOT_FOUND));
            }
        });
        addProfileGroup.addComponent(buttonAddProfile);

        layoutRootProfiles.addComponent(addProfileGroup);
    }
    return layoutRootProfiles;
}