Example usage for com.vaadin.ui Label setWidth

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

Introduction

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

Prototype

@Override
    public void setWidth(String width) 

Source Link

Usage

From source file:dhbw.clippinggorilla.userinterface.windows.GroupProfileWindow.java

public Component getSources(GroupInterestProfile profile, boolean isAdmin) {
    VerticalLayout windowLayout = new VerticalLayout();
    windowLayout.setWidth("100%");
    VerticalLayout sourcesLayout = new VerticalLayout();
    sourcesLayout.setWidth("100%");
    Panel sourcesPanel = new Panel(sourcesLayout);

    List<CheckBox> checkBoxes = new ArrayList<>();
    HashMap<String, GridLayout> sourceLayouts = new HashMap<>();
    profile.getSources().entrySet().stream()
            .sorted((e1, e2) -> e1.getKey().getName().compareToIgnoreCase(e2.getKey().getName())).forEach(e -> {
                Source source = e.getKey();
                boolean enabled = e.getValue();
                GridLayout sourceLayout = new GridLayout(5, 1);
                sourceLayout.setSizeFull();

                CheckBox sourceSelected = new CheckBox();
                sourceSelected.setValue(enabled);
                sourceSelected.addStyleName(ValoTheme.CHECKBOX_LARGE);
                sourceSelected.addValueChangeListener(v -> profile.getSources().replace(source, v.getValue()));
                sourceSelected.setEnabled(isAdmin);
                checkBoxes.add(sourceSelected);

                Image sourceLogo = new Image();
                sourceLogo.addStyleName("logosmall");
                sourceLogo.setSource(new ExternalResource(source.getLogo()));
                if (isAdmin) {
                    sourceLogo.addClickListener(c -> {
                        sourceSelected.setValue(!sourceSelected.getValue());
                        profile.getSources().replace(source, sourceSelected.getValue());
                    });// www.j  av  a  2 s.c  o  m
                }
                VerticalLayout layoutLogo = new VerticalLayout(sourceLogo);
                layoutLogo.setWidth("150px");
                layoutLogo.setHeight("50px");
                layoutLogo.setMargin(false);
                layoutLogo.setSpacing(false);
                layoutLogo.setComponentAlignment(sourceLogo, Alignment.MIDDLE_LEFT);

                Label labelHeadLine = new Label(
                        source.getCategory().getIcon().getHtml() + "  " + source.getName(), ContentMode.HTML);
                labelHeadLine.addStyleName(ValoTheme.LABEL_H3);

                Label labelDescription = new Label(source.getDescription(), ContentMode.HTML);
                labelDescription.setWidth("300px");
                PopupView popup = new PopupView(null, labelDescription);

                Button buttonDescription = new Button(VaadinIcons.INFO_CIRCLE_O);
                buttonDescription.addClickListener(ce -> {
                    popup.setPopupVisible(true);
                });

                sourceLayout.addComponents(sourceSelected, layoutLogo, labelHeadLine, popup, buttonDescription);
                sourceLayout.setComponentAlignment(sourceSelected, Alignment.MIDDLE_CENTER);
                sourceLayout.setComponentAlignment(layoutLogo, Alignment.MIDDLE_CENTER);
                sourceLayout.setColumnExpandRatio(2, 5);
                sourceLayout.setSpacing(true);

                sourceLayouts.put(source.getName().toLowerCase().replaceAll(" ", "").replaceAll("-", "")
                        .replaceAll("_", ""), sourceLayout);
                sourcesLayout.addComponent(sourceLayout);
            });

    sourcesPanel.setContent(sourcesLayout);
    sourcesPanel.setHeight("100%");
    sourcesPanel.setCaption(Language.get(Word.SOURCES));
    Language.setCustom(Word.SOURCES, s -> sourcesPanel.setCaption(s));
    windowLayout.addComponent(sourcesPanel);
    windowLayout.setExpandRatio(sourcesPanel, 1);
    windowLayout.setSpacing(false);
    windowLayout.setMargin(false);

    CheckBox checkBoxSelectAll = new CheckBox();
    Language.setCustom(Word.SELECT_ALL, s -> checkBoxSelectAll.setCaption(s));
    checkBoxSelectAll.setWidth("100%");
    checkBoxSelectAll.addValueChangeListener(e -> {
        profile.getSources().replaceAll((c, enabled) -> checkBoxSelectAll.getValue());
        checkBoxes.forEach(c -> c.setValue(checkBoxSelectAll.getValue()));
    });
    checkBoxSelectAll.setEnabled(isAdmin);

    TextField textFieldSearch = new TextField();
    Language.setCustom(Word.SEARCH, s -> textFieldSearch.setPlaceholder(s));
    textFieldSearch.setWidth("100%");
    textFieldSearch.setMaxLength(255);
    textFieldSearch.setPlaceholder(Language.get(Word.SEARCH));
    textFieldSearch.addValueChangeListener(searchValue -> {
        sourceLayouts.forEach((sourceName, sourceLayout) -> {
            if (!sourceName.contains(searchValue.getValue().toLowerCase().replaceAll(" ", "")
                    .replaceAll("-", "").replaceAll("_", ""))) {
                sourcesLayout.removeComponent(sourceLayout);
            } else {
                sourcesLayout.addComponent(sourceLayout);
            }
        });
    });

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

    GridLayout footer = new GridLayout(3, 1);
    footer.setSpacing(true);
    footer.setMargin(new MarginInfo(true, false, false, false));
    footer.addStyleName("menubar");
    footer.setWidth("100%");
    footer.addComponents(checkBoxSelectAll, textFieldSearch, placeholder);
    footer.setComponentAlignment(checkBoxSelectAll, Alignment.MIDDLE_LEFT);
    footer.setComponentAlignment(textFieldSearch, Alignment.MIDDLE_CENTER);

    windowLayout.addComponent(footer);
    windowLayout.setHeight("350px");
    return windowLayout;
}

From source file:dhbw.clippinggorilla.userinterface.windows.GroupProfileWindow.java

private void addRow(GroupInterestProfile profile, boolean included, String value, boolean isAdmin) {
    GridLayout tagLayout = new GridLayout(2, 1);
    tagLayout.setWidth("100%");

    Label labelTagName = new Label(value, ContentMode.HTML);
    labelTagName.setWidth("100%");
    labelTagName.addStyleName(ValoTheme.LABEL_H3);
    labelTagName.addStyleName(ValoTheme.LABEL_NO_MARGIN);
    tagLayout.addComponent(labelTagName);
    tagLayout.setComponentAlignment(labelTagName, Alignment.MIDDLE_LEFT);

    if (isAdmin) {
        Button buttonDeleteTag = new Button(VaadinIcons.TRASH);
        buttonDeleteTag.addStyleName(ValoTheme.BUTTON_DANGER);
        buttonDeleteTag.addClickListener(ev -> {
            profile.getTags().remove(value);
            if (included) {
                includedTagsLayouts.get(profile).removeComponent(tagLayout);
            } else {
                excludedTagsLayouts.get(profile).removeComponent(tagLayout);
            }/* w ww  .j a  v  a2s  . c o  m*/
        });
        tagLayout.addComponent(buttonDeleteTag);
        tagLayout.setComponentAlignment(buttonDeleteTag, Alignment.MIDDLE_RIGHT);
    }

    tagLayout.setWidth("100%");
    tagLayout.setColumnExpandRatio(0, 5);
    tagLayout.setSpacing(true);
    tagLayout.setMargin(false);

    if (included) {
        if (isAdmin) {
            includedTagsLayouts.get(profile).addComponent(tagLayout, 2);
        } else {
            includedTagsLayouts.get(profile).addComponent(tagLayout, 1);
        }
    } else {
        if (isAdmin) {
            excludedTagsLayouts.get(profile).addComponent(tagLayout, 2);
        } else {
            excludedTagsLayouts.get(profile).addComponent(tagLayout, 1);
        }
    }
}

From source file:dhbw.clippinggorilla.userinterface.windows.ManageSourcesWindow.java

public void refreshSources() {
    sourcesLayout.removeAllComponents();
    SourceUtils.getSources().stream().sorted((s1, s2) -> s1.getName().compareToIgnoreCase(s2.getName()))
            .forEach(source -> {/*from   w  w w  .j a  v a  2 s .  c  o  m*/
                try {
                    GridLayout sourceLayout = new GridLayout(4, 1);
                    sourceLayout.setSizeFull();

                    Image sourceLogo = new Image();
                    URL url = source.getLogo();
                    if (url != null) {
                        sourceLogo.setSource(new ExternalResource(url));
                    }
                    sourceLogo.setWidth("150px");

                    VerticalLayout sourceText = new VerticalLayout();
                    sourceText.setSizeFull();

                    Label labelHeadLine = new Label(
                            source.getCategory().getIcon().getHtml() + "  " + source.getName(),
                            ContentMode.HTML);
                    labelHeadLine.addStyleName(ValoTheme.LABEL_H2);

                    Label labelDescription = new Label(source.getDescription(), ContentMode.HTML);
                    labelDescription.addStyleName(ValoTheme.LABEL_SMALL);
                    labelDescription.setWidth("100%");

                    sourceText.setMargin(false);
                    sourceText.addComponents(labelHeadLine, labelDescription);

                    Button buttonEdit = new Button(VaadinIcons.EDIT);
                    buttonEdit.addStyleName(ValoTheme.BUTTON_PRIMARY);
                    buttonEdit.addClickListener(
                            ce -> UI.getCurrent().addWindow(NewSourceWindow.createEditMode(source)));

                    Button buttonDelete = new Button(VaadinIcons.TRASH);
                    buttonDelete.addStyleName(ValoTheme.BUTTON_DANGER);
                    buttonDelete.addClickListener(ce -> {
                        sourcesLayout.removeComponent(sourceLayout);
                        sourceLayouts.remove(source.getName().toLowerCase().replaceAll(" ", "")
                                .replaceAll("-", "").replaceAll("_", ""));
                        SourceUtils.removeSource(source);
                    });

                    sourceLayout.addComponents(sourceLogo, sourceText, buttonEdit, buttonDelete);
                    sourceLayout.setComponentAlignment(sourceLogo, Alignment.MIDDLE_CENTER);
                    sourceLayout.setComponentAlignment(buttonEdit, Alignment.MIDDLE_CENTER);
                    sourceLayout.setComponentAlignment(buttonDelete, Alignment.MIDDLE_CENTER);
                    sourceLayout.setColumnExpandRatio(1, 5);
                    sourceLayout.setSpacing(true);

                    sourceLayouts.put(source.getName().toLowerCase().replaceAll(" ", "").replaceAll("-", "")
                            .replaceAll("_", ""), sourceLayout);
                    sourcesLayout.addComponent(sourceLayout);
                } catch (Exception e) {
                    Log.error("Skipping Source! ", e);
                }
            });
}

From source file:dhbw.clippinggorilla.userinterface.windows.NewSourceWindow.java

public Component getThirdStage(Source s) {
    Label header = new Label(Language.get(Word.CRAWLER));
    header.addStyleName(ValoTheme.LABEL_H1);

    Crawler crawler;/* w w w . j  a v a  2s  .co  m*/
    if (s.getCrawler() != null) {
        crawler = s.getCrawler();
    } else {
        crawler = new Crawler(s);
        s.setCrawler(crawler);
    }

    GridLayout mainGrid = new GridLayout(2, 2);
    mainGrid.setSizeFull();
    mainGrid.setSpacing(true);

    FormLayout layoutForms = new FormLayout();

    //Exclude or Include
    RadioButtonGroup<Boolean> radios = new RadioButtonGroup<>();
    radios.setItems(true, false);
    radios.setItemCaptionGenerator(b -> b ? Language.get(Word.INCLUDE_TAGS) : Language.get(Word.EXCLUDE_TAGS));
    radios.setItemIconGenerator(b -> b ? VaadinIcons.CHECK : VaadinIcons.CLOSE);
    radios.setSelectedItem(true);
    radios.addValueChangeListener(event -> include = event.getValue());

    //By Class
    CssLayout addByClassGroup = new CssLayout();
    addByClassGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
    TextField textFieldAddByClass = new TextField();
    textFieldAddByClass.setWidth("465px");
    Button buttonAddByClass = new Button(VaadinIcons.PLUS);
    buttonAddByClass.addClickListener(e -> {
        crawler.addByClass(textFieldAddByClass.getValue(), include);
        refreshList(mainGrid, crawler);
        textFieldAddByClass.clear();
    });
    addByClassGroup.addComponents(textFieldAddByClass, buttonAddByClass);
    addByClassGroup.setCaption(Language.get(Word.BYCLASS));

    //ByTag
    CssLayout addByTagGroup = new CssLayout();
    addByTagGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
    TextField textFieldAddByTag = new TextField();
    Button buttonAddByTag = new Button(VaadinIcons.PLUS);
    textFieldAddByTag.setWidth("465px");
    buttonAddByTag.addClickListener(e -> {
        crawler.addByTag(textFieldAddByTag.getValue(), include);
        refreshList(mainGrid, crawler);
        textFieldAddByTag.clear();
    });
    addByTagGroup.addComponents(textFieldAddByTag, buttonAddByTag);
    addByTagGroup.setCaption(Language.get(Word.BYTAG));

    //ByID
    CssLayout addByIDGroup = new CssLayout();
    addByIDGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
    TextField textFieldAddByID = new TextField();
    textFieldAddByID.setWidth("465px");
    Button buttonAddByID = new Button(VaadinIcons.PLUS);
    buttonAddByID.addClickListener(e -> {
        crawler.addByID(textFieldAddByID.getValue(), include);
        refreshList(mainGrid, crawler);
        textFieldAddByID.clear();
    });
    addByIDGroup.addComponents(textFieldAddByID, buttonAddByID);
    addByIDGroup.setCaption(Language.get(Word.BYID));

    //ByAttribute
    CssLayout addByAttributeGroup = new CssLayout();
    addByAttributeGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
    TextField textFieldAddByAttributeKey = new TextField();
    textFieldAddByAttributeKey.setWidth("233px");
    TextField textFieldAddByAttributeValue = new TextField();
    textFieldAddByAttributeValue.setWidth("232px");
    Button buttonAddByAttribute = new Button(VaadinIcons.PLUS);
    buttonAddByAttribute.addClickListener(e -> {
        crawler.addByAttribute(textFieldAddByAttributeKey.getValue(), textFieldAddByAttributeValue.getValue(),
                include);
        refreshList(mainGrid, crawler);
        textFieldAddByAttributeKey.clear();
        textFieldAddByAttributeValue.clear();
    });
    addByAttributeGroup.addComponents(textFieldAddByAttributeKey, textFieldAddByAttributeValue,
            buttonAddByAttribute);
    addByAttributeGroup.setCaption(Language.get(Word.BYATTRIBUTEVALUE));

    layoutForms.addComponents(radios, addByClassGroup, addByTagGroup, addByIDGroup, addByAttributeGroup);
    mainGrid.addComponent(layoutForms);

    Label labelResult = new Label();
    Panel panelResult = new Panel(labelResult);
    labelResult.setWidth("100%");
    panelResult.setWidth("100%");
    panelResult.setHeight("175px");
    mainGrid.addComponent(panelResult, 0, 1, 1, 1);

    Button buttonTestURL = new Button();
    buttonTestURL.setIcon(VaadinIcons.EXTERNAL_LINK);
    buttonTestURL.setCaption(Language.get(Word.OPEN_LINK));

    Button buttonTest = new Button(Language.get(Word.TEST), VaadinIcons.CLIPBOARD_CHECK);
    buttonTest.addClickListener(ce -> {
        Article a = CrawlerUtils.executeRandom(crawler);
        labelResult.setValue(a.getBody());
        if (reg != null) {
            reg.remove();
        }
        reg = buttonTestURL
                .addClickListener(cev -> UI.getCurrent().getPage().open(a.getUrl(), "_blank", false));
    });

    refreshList(mainGrid, crawler);

    Runnable cancel = () -> close();
    Runnable next = () -> validateThirdStage(s);

    VerticalLayout windowLayout = new VerticalLayout();
    windowLayout.addComponents(header, mainGrid, getFooter(cancel, next, buttonTest, buttonTestURL));
    windowLayout.setComponentAlignment(header, Alignment.MIDDLE_CENTER);
    windowLayout.setExpandRatio(mainGrid, 5);
    windowLayout.setWidth("1250px");
    return windowLayout;
}

From source file:dhbw.ka.mwi.businesshorizon2.ui.initialscreen.projectlist.ProjectListViewImpl.java

License:Open Source License

/**
 * Konkrete Ausprogrammierung der Darstellung eines einzelnen Projekts.
 * Ein Projekt wird durch ein VerticalLayout dargestellt, das ein Label
 * mit dem Projektname enthlt. Auerdem bekommt es einen ClickListener,
 * um ein Projekt als selektiert zu kennzeichnen und die Details zum Projekt
 * anzuzeigen.//from   w w w .j a va  2 s  . c o m
 * 
 * @author Christian Scherer, Mirko Gpfrich, Marco Glaser
 * @param project
 *            das darzustellende Projekt und der aktuelle Index der Liste
 * @param i
 *            der Index der zu erstellenden Komponente (besonders fuer den
 *            Loeschbutton relevant)
 * @return ein VerticalLayout Objekt, das zur Eingliederung in das UI dient
 */
private VerticalLayout generateSingleProjectUI(Project project, int i) {

    final Project proj = project;
    final int a = i;
    //erzeugt eine Panel fr ein Projekt
    singleProject = new VerticalLayout();
    HorizontalLayout container = new HorizontalLayout();
    container.setSizeFull();
    if (i == 0) {
        singleProject.setStyleName("singleProjectSelected");
        presenter.projectSelected(project);
    } else {
        singleProject.setStyleName("singleProject");
    }
    Embedded icon = new Embedded(null,
            new ThemeResource("./images/icons/newIcons/1418828714_editor_open_folder-128.png"));
    icon.setHeight(40, UNITS_PIXELS);
    icon.setWidth(40, UNITS_PIXELS);
    Label gap1 = new Label();
    Label gap2 = new Label();
    Label gap3 = new Label();
    gap1.setWidth("15px");
    gap2.setWidth("15px");
    gap3.setSizeFull();
    Label projectName = new Label(project.getName());
    projectName.setWidth(Sizeable.SIZE_UNDEFINED, 0);
    projectName.setHeight(Sizeable.SIZE_UNDEFINED, 0);
    projectName.setStyleName("projectName");

    //Legt ein Layout fr das Projekt-Panel fest
    //panelContent.setSizeFull();
    container.addComponent(gap1);
    container.addComponent(icon);
    container.addComponent(gap2);
    container.addComponent(projectName);
    container.addComponent(gap3);
    container.setExpandRatio(gap3, 1.0f);

    singleProject.addComponent(container);
    singleProject.setWidth(100, UNITS_PERCENTAGE);
    singleProject.setHeight(70, UNITS_PIXELS);
    container.setComponentAlignment(icon, Alignment.MIDDLE_CENTER);
    container.setComponentAlignment(projectName, Alignment.MIDDLE_CENTER);

    singleProject.addListener(new LayoutClickListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void layoutClick(LayoutClickEvent event) {
            presenter.projectSelected(proj);
            switchProjectsStyle(a);

            eventBus.fireEvent(new SelectProjectEvent());
        }

    });

    //      singleProject.addListener(this);
    //      projectListPanel.addComponent(singleProject);
    logger.debug("Einzelnes Projektelement erzeugt");

    return singleProject;
}

From source file:edu.kit.dama.ui.admin.AdminUIMainView.java

License:Apache License

/**
 * Setup the login form including its logic.
 *//*from   w w  w .  j a  v a 2s .c o m*/
private void setupLoginForm(AbstractLoginComponent.AUTH_MODE type, String pendingAuth, VaadinRequest request) {
    ComboBox authSelection = new ComboBox();
    authSelection.setWidth("400px");
    authSelection.setNullSelectionAllowed(false);
    authSelection.setStyleName("auth_selection");
    Label spacer = new Label("<br/>", ContentMode.HTML);
    spacer.setWidth("400px");

    String orcidClientId = DataManagerSettings.getSingleton()
            .getStringProperty(OrcidLoginComponent.ORCID_CLIENT_ID_PROPERTY, null);
    String orcidClientSecret = DataManagerSettings.getSingleton()
            .getStringProperty(OrcidLoginComponent.ORCID_CLIENT_SECRET_PROPERTY, null);

    /// String b2AccessClientId = DataManagerSettings.getSingleton().getStringProperty(B2AccessLoginComponent.B2ACCESS_CLIENT_ID_PROPERTY, null);
    // String b2AccessClientSecret = DataManagerSettings.getSingleton().getStringProperty(B2AccessLoginComponent.B2ACCESS_CLIENT_SECRET_PROPERTY, null);
    List<AbstractLoginComponent> components = new ArrayList<>();

    if (orcidClientId != null && !orcidClientId.equals("ORCID_CLIENT_ID") && orcidClientSecret != null
            && !orcidClientSecret.equals("ORCID_CLIENT_SECRET")) {
        components.add(new OrcidLoginComponent());
    }

    /*B2Access is currently not supported. 
    if (b2AccessClientId != null && b2AccessClientSecret != null) {
    components.add(new B2AccessLoginComponent());
    }*/
    components.add(new EmailPasswordLoginComponent());

    loginComponents = components.toArray(new AbstractLoginComponent[] {});

    //default login component has index 0
    loginComponent = loginComponents[0];
    for (AbstractLoginComponent component : loginComponents) {
        //add new login component
        authSelection.addItem(component.getLoginIdentifier());
        authSelection.setItemCaption(component.getLoginIdentifier(), component.getLoginLabel());

        if (pendingAuth != null && pendingAuth.equals(component.getLoginIdentifier())) {
            //login or registration process in pending, continue process
            loginComponent = component;
            try {
                switch (type) {
                case REGISTRATION:
                    loginComponent.doRegistration(request);
                    break;
                default:
                    loginComponent.doLogin(request);
                    break;
                }

            } catch (UnauthorizedAccessAttemptException ex) {
                //failed to continue auth...cancel.
                String message = "Failed to continue pending "
                        + (AbstractLoginComponent.AUTH_MODE.LOGIN.equals(type) ? "login" : "registration")
                        + " for authentication #" + pendingAuth + ".";
                LOGGER.error(message, ex);
                UIComponentTools.showError(message);
                VaadinSession.getCurrent().setAttribute("auth_pending", null);
                VaadinSession.getCurrent().setAttribute("registration_pending", null);
                loginComponent.reset();
            }
        }
    }

    authSelection.select(loginComponent.getLoginIdentifier());

    authSelection.addValueChangeListener((Property.ValueChangeEvent event) -> {
        String value = (String) event.getProperty().getValue();
        if (value != null) {
            for (AbstractLoginComponent component : loginComponents) {
                if (value.equals(component.getLoginIdentifier())) {
                    loginForm.replaceComponent(loginComponent, component);
                    loginComponent = component;
                }
            }
        }
    });

    loginForm = new VerticalLayout(authSelection, spacer, loginComponent);
    loginForm.setComponentAlignment(authSelection, Alignment.TOP_CENTER);
    loginForm.setComponentAlignment(spacer, Alignment.TOP_CENTER);
    loginForm.setComponentAlignment(loginComponent, Alignment.TOP_CENTER);
}

From source file:edu.kit.dama.ui.admin.wizard.FirstStartWizard.java

License:Apache License

private void buildMainLayout() {
    stepLayout = new VerticalLayout();

    back.setEnabled(false);//  w w  w  .  java2  s .  c o m
    stepLayout.addComponent(stepList[currentStep]);
    stepLayout.setComponentAlignment(stepList[currentStep], Alignment.TOP_RIGHT);
    stepLayout.setSpacing(false);
    stepLayout.setMargin(false);
    stepLayout.setWidth("100%");
    stepLayout.setHeight("500px");

    final VerticalLayout stepLabels = new VerticalLayout();
    for (WizardStep step : stepList) {
        Label stepLabel = new Label(step.getStepName());
        stepLabel.setWidth("250px");
        stepLabels.addComponent(stepLabel);
        stepLabels.setComponentAlignment(stepLabel, Alignment.TOP_LEFT);
    }

    //make introduction label bold
    stepLabels.getComponent(0).addStyleName("myboldcaption");

    Label spacer = new Label();
    stepLabels.addComponent(spacer);
    stepLabels.setExpandRatio(spacer, 1.0f);
    stepLabels.setWidth("275px");
    stepLabels.setHeight("550px");
    stepLabels.setSpacing(true);

    UIUtils7.GridLayoutBuilder builder = new UIUtils7.GridLayoutBuilder(2, 2);

    HorizontalLayout buttonLayout = new HorizontalLayout(back, next);
    buttonLayout.setSizeFull();
    buttonLayout.setComponentAlignment(back, Alignment.BOTTOM_RIGHT);
    buttonLayout.setComponentAlignment(next, Alignment.BOTTOM_RIGHT);
    buttonLayout.setExpandRatio(back, 1.0f);

    next.addClickListener((event) -> {
        if ("Go To Login".equals(next.getCaption())) {
            Page.getCurrent().reload();
        } else if ("Finish".equals(next.getCaption())) {
            //do finish
            WizardPersistHelper helper = new WizardPersistHelper();
            if (helper.persist(properties)) {
                UIUtils7.showInformation("Success",
                        "All information have been successfully stored into the database. For details, please refer to the log output above.\n"
                                + "You may now dismiss this message and click 'Go To Login' in order to access the login page.\n"
                                + "From there you can to login using your administrator account or create a personalized user account.",
                        3000);
                back.setVisible(false);
                next.setCaption("Go To Login");
            } else {
                UIUtils7.showError("Failed to store collected information in database.\n"
                        + "Please refer to the log output above.");
            }
            ((WizardSummary) stepList[currentStep]).setSummary(helper.getMessages());
        } else {
            if (currentStep + 1 <= stepList.length - 1) {
                if (stepList[currentStep].validate()) {
                    stepList[currentStep].collectProperties(properties);
                    currentStep++;
                    stepLayout.replaceComponent(stepList[currentStep - 1], stepList[currentStep]);
                    Label currentLabel = (Label) stepLabels.getComponent(currentStep);
                    Label prevLabel = (Label) stepLabels.getComponent(currentStep - 1);
                    currentLabel.addStyleName("myboldcaption");
                    prevLabel.removeStyleName("myboldcaption");

                    if (stepList[currentStep] instanceof WizardSummary) {
                        StringBuilder summary = new StringBuilder();
                        for (WizardStep step : stepList) {
                            summary.append(step.getSummary()).append("\n");
                        }
                        ((WizardSummary) stepList[currentStep]).setSummary(summary.toString());
                    }
                }
            }

            if (currentStep == stepList.length - 1) {
                //finish
                next.setCaption("Finish");
            } else {
                next.setCaption("Next");
            }

            back.setEnabled(true);
        }
    });

    back.addClickListener((event) -> {
        if (currentStep - 1 >= 0) {
            stepList[currentStep].collectProperties(properties);
            currentStep--;
            stepLayout.replaceComponent(stepList[currentStep + 1], stepList[currentStep]);
            Label currentLabel = (Label) stepLabels.getComponent(currentStep);
            Label prevLabel = (Label) stepLabels.getComponent(currentStep + 1);
            currentLabel.addStyleName("myboldcaption");
            prevLabel.removeStyleName("myboldcaption");
        }
        next.setEnabled(true);
        back.setEnabled(currentStep > 0);
        next.setCaption("Next");
    });

    builder.addComponent(stepLabels, Alignment.TOP_LEFT, 0, 0, 1, 2);
    builder.addComponent(stepLayout, Alignment.TOP_LEFT, 1, 0, 1, 1);
    builder.addComponent(buttonLayout, Alignment.BOTTOM_LEFT, 1, 1, 1, 1);

    mainLayout = builder.getLayout();
    mainLayout.setMargin(true);
    mainLayout.setSizeFull();

    // mainLayout.setColumnExpandRatio(0, .3f);
    mainLayout.setColumnExpandRatio(1, 1f);
    mainLayout.setRowExpandRatio(0, .95f);
    mainLayout.setRowExpandRatio(1, .05f);
}

From source file:edu.kit.dama.ui.commons.util.PaginationLayout.java

License:Apache License

/**
 * Update the layout. This method is either called internally when scrolling
 * or/* w  ww .  j av a2 s .  c o m*/
 */
public final void update() {
    //remove all components (old result page and navigation)
    removeAllComponents();

    //add current results
    renderPage();

    //build pagination
    int pages = overallEntries / entriesPerPage;
    if (overallEntries % entriesPerPage > 0) {
        pages++;
    }

    final int overallPages = pages;
    HorizontalLayout navigation = new HorizontalLayout();
    //add "JumpToFirstPage" button
    final NativeButton first = new NativeButton();
    first.setIcon(firstIcon);
    if (firstIcon == null) {
        first.setCaption("<<");
    }
    first.setDescription("First Page");
    first.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            currentPage = 0;
            update();
        }
    });
    //add "PreviousPage" button
    final NativeButton prev = new NativeButton();
    prev.setIcon(prevIcon);
    if (prevIcon == null) {
        prev.setCaption("<");
    }
    prev.setDescription("Previous Page");
    prev.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (currentPage > 0) {
                currentPage--;
                update();
            }
        }
    });
    //add "NextPage" button
    final NativeButton next = new NativeButton();
    next.setIcon(nextIcon);
    if (nextIcon == null) {
        next.setCaption(">");
    }
    next.setDescription("Next Page");
    next.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (currentPage + 1 < overallPages) {
                currentPage++;
                update();
            }
        }
    });
    //add "JumpToLastPage" button
    final NativeButton last = new NativeButton();
    last.setIcon(endIcon);
    if (endIcon == null) {
        next.setCaption(">>");
    }
    last.setDescription("Last Page");
    last.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            currentPage = overallPages - 1;
            update();
        }
    });

    //enable/disable buttons depending on the current page
    if (overallPages == 0) {
        first.setEnabled(false);
        prev.setEnabled(false);
        next.setEnabled(false);
        last.setEnabled(false);
    } else {
        first.setEnabled(!(currentPage == 0) || !(overallPages < 2));
        prev.setEnabled(!(currentPage == 0) || !(overallPages < 2));
        next.setEnabled(!(currentPage == overallPages - 1) || !(overallPages < 2));
        last.setEnabled(!(currentPage == overallPages - 1) || !(overallPages < 2));
    }

    //at first, put the page size selection box into the navigation
    final ComboBox entriesPerPageBox = new ComboBox();
    entriesPerPageBox.setItemCaptionPropertyId("name");
    entriesPerPageBox.addContainerProperty("name", String.class, null);
    entriesPerPageBox.addItem(5);
    entriesPerPageBox.getContainerProperty(5, "name").setValue("5 Entries / Page");
    entriesPerPageBox.addItem(10);
    entriesPerPageBox.getContainerProperty(10, "name").setValue("10 Entries / Page");
    entriesPerPageBox.addItem(15);
    entriesPerPageBox.getContainerProperty(15, "name").setValue("15 Entries / Page");
    entriesPerPageBox.addItem(20);
    entriesPerPageBox.getContainerProperty(20, "name").setValue("20 Entries / Page");

    entriesPerPageBox.setValue(entriesPerPage);
    entriesPerPageBox.setNullSelectionAllowed(false);
    entriesPerPageBox.setImmediate(true);

    entriesPerPageBox.addListener(new Property.ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            entriesPerPage = (Integer) entriesPerPageBox.getValue();
            update();
        }
    });

    navigation.addComponent(entriesPerPageBox);

    //filler labels are added to the beginning and to the end to keep the navigation in the middle
    Label leftFiller = new Label();
    leftFiller.setWidth("25px");
    navigation.addComponent(leftFiller);
    navigation.addComponent(first);
    navigation.addComponent(prev);

    //Show max. 10 pages at once for performance and layout reasons.
    //If there are more than 10 pages, "move" the to show 10 pages based on the current page.
    int start = currentPage - 5;
    start = (start < 0) ? 0 : start;
    int end = start + 10;
    end = (end > pages) ? pages : end;

    if (end - start < 10 && pages > 10) {
        start = end - 10;
    }

    if (overallPages == 0) {
        Label noEntryLabel = new Label("<i>No entries</i>", Label.CONTENT_XHTML);
        //noEntryLabel.setWidth("80px");
        noEntryLabel.setSizeUndefined();
        navigation.addComponent(noEntryLabel);
        navigation.setComponentAlignment(noEntryLabel, Alignment.MIDDLE_CENTER);
    }
    //build the actual page entries
    for (int i = start; i < end; i++) {
        if (i == currentPage) {
            //the current page is marked with a special style
            Label pageLink = new Label("<b>" + Integer.toString(i + 1) + "</b>", Label.CONTENT_XHTML);
            pageLink.setStyleName("currentpage");
            pageLink.setWidth("15px");
            navigation.addComponent(pageLink);
            navigation.setComponentAlignment(pageLink, Alignment.MIDDLE_CENTER);
        } else {
            //otherwise normal links are added, click-events are handled via LayoutClickListener 
            Link pageLink = new Link(Integer.toString(i + 1), null);
            navigation.addComponent(pageLink);
            navigation.setComponentAlignment(pageLink, Alignment.MIDDLE_CENTER);
        }
    }
    //add right navigation buttons
    navigation.addComponent(next);
    navigation.addComponent(last);
    //...and fill the remaining space 
    Label rightFiller = new Label();
    navigation.addComponent(rightFiller);
    //  navigation.setExpandRatio(leftFiller, 1.0f);
    navigation.setExpandRatio(rightFiller, 1.0f);
    navigation.setSpacing(true);

    //put everything ot the middle
    navigation.setComponentAlignment(first, Alignment.MIDDLE_CENTER);
    navigation.setComponentAlignment(prev, Alignment.MIDDLE_CENTER);
    navigation.setComponentAlignment(next, Alignment.MIDDLE_CENTER);
    navigation.setComponentAlignment(last, Alignment.MIDDLE_CENTER);

    //add layout click listener to be able to navigate by clicking the single pages
    navigation.addListener(new LayoutEvents.LayoutClickListener() {
        @Override
        public void layoutClick(LayoutEvents.LayoutClickEvent event) {

            // Get the child component which was clicked
            Component child = event.getChildComponent();

            if (child == null) {
                // Not over any child component
            } else {
                // Over a child component
                if (child instanceof Link) {
                    // Over a valid child element
                    currentPage = Integer.parseInt(((Link) child).getCaption()) - 1;
                    update();
                }
            }
        }
    });

    //finalize
    navigation.setWidth("100%");
    navigation.setHeight("25px");

    //add navigation and align it right below the result page
    addComponent(page);
    setExpandRatio(page, 1f);
    if (overallEntries > 0) {
        addComponent(navigation);
        setComponentAlignment(navigation, Alignment.BOTTOM_CENTER);
        setExpandRatio(navigation, .05f);
    }
    requestRepaint();
}

From source file:edu.kit.dama.ui.commons.util.PaginationLayout.java

License:Apache License

/**
 * Fill the pagination listing based on a specific query to obtain valid
 * objects./*from  w w  w  .  j  ava 2s .com*/
 */
private void renderPage() {
    //obtain the objects of this page (5 entries per page are shown)
    int start = currentPage * entriesPerPage;
    //initialize page panel and layout
    page = new Panel();
    page.setCaption(caption);
    page.setImmediate(true);
    page.setIcon(icon);
    VerticalLayout pageLayout = new VerticalLayout();
    pageLayout.setMargin(true);
    pageLayout.setImmediate(true);
    pageLayout.setSizeUndefined();
    page.setSizeFull();
    List<C> entries;

    if (overallEntries > 0) {
        AbstractComponent header = callback.renderHeader();
        if (header != null) {
            pageLayout.addComponent(header);
            pageLayout.setComponentAlignment(header, Alignment.TOP_LEFT);
        }
        entries = callback.getEntries(this, start);
        //add all objects of this page
        int objectIdx = 1;
        for (C entry : entries) {
            AbstractComponent renderedEntry = callback.renderEntry(entry, start + objectIdx);

            pageLayout.addComponent(renderedEntry);
            pageLayout.setComponentAlignment(renderedEntry, Alignment.TOP_CENTER);
            Label spacer = new Label("<hr/>", Label.CONTENT_XHTML);
            spacer.setHeight("3px");
            spacer.setWidth("100%");
            pageLayout.addComponent(spacer);
            pageLayout.setComponentAlignment(spacer, Alignment.TOP_CENTER);
            objectIdx++;
        }

        //if there are less than 'entriesPerPage' entries, add a 'filler' to keep the actual items on top of the layout
        if (objectIdx < entriesPerPage) {
            Label filler = new Label();
            pageLayout.addComponent(filler);
            pageLayout.setExpandRatio(filler, 1.0f);
        }
    } else {
        //nothing visible
        Label filler = new Label("No entries available");
        pageLayout.addComponent(filler);
        pageLayout.setExpandRatio(filler, 1.0f);
    }

    page.setContent(pageLayout);
}

From source file:edu.kit.dama.ui.repo.components.EntryRenderPanel.java

License:Apache License

/**
 * Build the main layout of the representation of one digital object.
 *
 * @param pContext The authorization context used to decide whether special
 * administrative features are available or not.
 *//*  ww  w .  j  a v  a  2s  . com*/
private void buildMainLayout(IAuthorizationContext pContext) {
    //check if the object could be obtained or not, e.g. due to missing permissions. If not, show an error message.
    if (ERROR_PLACEHOLDER.equals(object.getLabel())) {
        Label warnLabel = new Label("<h3>Failed to obtain entry with identifier '"
                + object.getDigitalObjectIdentifier() + "' from database.</h3>", ContentMode.HTML);
        final Button cleanup = new Button("Cleanup");
        cleanup.setDescription("Click to remove object from search index.");
        cleanup.addClickListener(new Button.ClickListener() {

            @Override
            public void buttonClick(Button.ClickEvent event) {
                cleanup.setEnabled(false);
                new Notification("Information", "Cleanup not implemented, yet.",
                        Notification.Type.TRAY_NOTIFICATION).show(Page.getCurrent());
            }
        });
        if (pContext.getRoleRestriction().atLeast(Role.ADMINISTRATOR)) {
            //show cleanup button
            mainLayout = new HorizontalLayout(warnLabel, cleanup);
        } else {
            //no cleanup available
            mainLayout = new HorizontalLayout(warnLabel);
        }
        mainLayout.setSizeFull();
        return;
    }

    //initialize image field
    typeImage = new Image();
    typeImage.setSizeFull();
    setImage(object);

    //initialize title label/field
    titleField = UIUtils7.factoryTextField(null, "dc:title");
    titleField.addStyleName("basic_title");
    titleLabel = new Label("dc:title");
    titleLabel.setWidth("100%");
    titleLabel.addStyleName("basic_title");

    //initialize creator label
    if (object.getUploader() != null) {
        creatorLabel = new Label(StringUtils.abbreviate(object.getUploader().getFullname(), 100));
        creatorLabel.setEnabled(true);
    } else {
        creatorLabel = new Label("dc:creator");
        creatorLabel.setEnabled(false);
    }
    creatorLabel.setWidth("100%");
    creatorLabel.addStyleName("basic_left");

    //initialize creation label
    if (object.getStartDate() != null) {
        creationLabel = new Label(new SimpleDateFormat().format(object.getStartDate()));
        creationLabel.setEnabled(true);
    } else {
        creationLabel = new Label("dc:date");
        creationLabel.setEnabled(false);
    }

    creationLabel.setWidth("100%");

    //initialize identifier label
    objectIdLabel = new Label(StringUtils.abbreviate(object.getDigitalObjectIdentifier(), 100));
    objectIdLabel.setWidth("100%");
    //initialize description label/area
    descriptionLabel = new Label("dc:description");
    descriptionArea = UIUtils7.factoryTextArea(null, "dc:description");
    descriptionArea.setHeight("50px");
    descriptionLabel.setHeight("50px");
    descriptionLabel.setWidth("100%");

    //action buttons
    downloadButton = new NativeButton("Download");
    downloadButton.setIcon(new ThemeResource("img/32x32/download.png"));
    downloadButton.setStyleName(BaseTheme.BUTTON_LINK);
    downloadButton.setDescription("Download the data of this digital object.");
    downloadButton.setWidth("100%");

    shareButton = new NativeButton("Share");
    shareButton.setIcon(new ThemeResource("img/16x16/share.png"));
    shareButton.setStyleName(BaseTheme.BUTTON_LINK);
    shareButton.setDescription("Share this digital object.");
    Role eligibleRole = Role.GUEST;
    if (parent.getParentUI().isUserLoggedIn()) {
        //obtain role only if a user is logged in and we are not in ingest mode.
        //Otherwise, the dummy context of MyVaadinUI would be used and will cause unwanted access.
        try {
            //Determine eligible role of currently logged in user
            eligibleRole = ResourceServiceLocal.getSingleton().getGrantRole(object.getSecurableResourceId(),
                    parent.getParentUI().getAuthorizationContext().getUserId(),
                    AuthorizationContext.factorySystemContext());
        } catch (EntityNotFoundException | UnauthorizedAccessAttemptException ex) {
            LOGGER.warn("Failed to determine eligable role for context "
                    + parent.getParentUI().getAuthorizationContext() + ". Continue with GUEST permissions.",
                    ex);
        }
    }

    //Update share button depending on role. Only possessing the role MANAGER (being the owner) entitles to share an object. 
    if (eligibleRole.atLeast(Role.MANAGER)) {
        shareButton.setEnabled(true);
        shareButton.addClickListener(new Button.ClickListener() {

            @Override
            public void buttonClick(Button.ClickEvent event) {
                if (parent != null) {
                    parent.showSharingPopup(object);
                }
            }
        });
    } else {
        shareButton.setEnabled(false);
        shareButton.setDescription("Only the object owner is allowed to change sharing information.");
    }

    editButton = new NativeButton("Edit Metadata");
    editButton.setIcon(new ThemeResource("img/16x16/edit.png"));
    editButton.setStyleName(BaseTheme.BUTTON_LINK);
    editButton.setDescription("Edit this digital object's metadata.");

    //Update edit button depending on role. If the object is shared with or owned by the logged in user, editing will be allowed.
    if (eligibleRole.atLeast(Role.MEMBER)) {
        editButton.setEnabled(true);
        editButton.addClickListener(new Button.ClickListener() {

            @Override
            public void buttonClick(Button.ClickEvent event) {
                switchEditMode();
            }
        });
    } else {
        editButton.setEnabled(false);
        editButton.setDescription(
                "Only the object owner and users the object is shared with are allowed to change metadata information.");
    }

    starButton = new NativeButton("Favorite");
    starButton.setImmediate(true);
    starButton.setIcon(new ThemeResource("img/16x16/unstarred.png"));
    starButton.setStyleName(BaseTheme.BUTTON_LINK);
    starButton.setDescription("Add/remove digital object to/from favorites.");

    //Update star button depending on role. If the object is shared with or owned by the logged in user, "star'ing" will be allowed.
    if (eligibleRole.atLeast(Role.MEMBER)) {
        starButton.setEnabled(true);
        starButton.addClickListener(new Button.ClickListener() {

            @Override
            public void buttonClick(Button.ClickEvent event) {
                IMetaDataManager mdm = MetaDataManagement.getMetaDataManagement().getMetaDataManager();
                mdm.setAuthorizationContext(AuthorizationContext.factorySystemContext());

                try {
                    DigitalObjectType favoriteType = mdm
                            .findSingleResult("SELECT t FROM DigitalObjectType t WHERE t.identifier='"
                                    + MyVaadinUI.FAVORITE_TYPE_IDENTIFIER + "' AND t.typeDomain='"
                                    + MyVaadinUI.FAVORITE_TYPE_DOMAIN + "'", DigitalObjectType.class);
                    if (DigitalObjectTypeHelper.isTypeAssignedToObject(object, favoriteType,
                            AuthorizationContext.factorySystemContext())) {
                        //remove favorite status
                        DigitalObjectTypeHelper.removeTypeFromObject(object, favoriteType,
                                AuthorizationContext.factorySystemContext());
                        starButton.setIcon(new ThemeResource("img/16x16/unstarred.png"));
                        new Notification("Information",
                                "Successfully removed favorite tag from object "
                                        + object.getDigitalObjectIdentifier() + ".",
                                Notification.Type.TRAY_NOTIFICATION).show(Page.getCurrent());
                    } else {
                        //assign favorite status
                        DigitalObjectTypeHelper.assignTypeToObject(object, favoriteType,
                                AuthorizationContext.factorySystemContext());
                        starButton.setIcon(new ThemeResource("img/16x16/starred.png"));
                        new Notification("Information",
                                "Successfully added favorite tag to object "
                                        + object.getDigitalObjectIdentifier() + ".",
                                Notification.Type.TRAY_NOTIFICATION).show(Page.getCurrent());
                    }
                } catch (Exception e) {
                    LOGGER.error("Failed to change 'favorite' status of digital object.", e);
                    new Notification("Warning", "Failed to update favorite status.",
                            Notification.Type.WARNING_MESSAGE).show(Page.getCurrent());
                }
            }
        });
    } else {
        starButton.setEnabled(false);
        starButton.setDescription(
                "Only the object owner and users the object is shared with are allowed to change the favorite state.");
    }

    dcLayout = new UIUtils7.GridLayoutBuilder(3, 5).addComponent(titleLabel, 0, 0, 2, 1)
            .addComponent(creationLabel, 2, 0, 1, 1).addComponent(creatorLabel, 0, 1, 3, 1)
            .addComponent(objectIdLabel, 0, 2, 3, 1).fill(descriptionLabel, 0, 3).getLayout();
    dcLayout.setSizeFull();

    Button.ClickListener saveCancelButtonListener = new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (saveEditButton.equals(event.getButton())) {
                //do save
                IMetaDataManager mdm = MetaDataManagement.getMetaDataManagement().getMetaDataManager();
                mdm.setAuthorizationContext(AuthorizationContext.factorySystemContext());
                try {
                    String title = titleField.getValue();
                    String description = descriptionArea.getValue();
                    Investigation investigation = object.getInvestigation();
                    boolean wasError = false;
                    if (description != null && description.length() <= 1024 && investigation != null) {
                        if (!description.equals(investigation.getDescription())) {
                            investigation.setDescription(description);
                            //store investigation
                            mdm.save(investigation);
                        }
                    } else {
                        LOGGER.warn(
                                "Failed to commit updated description '{}'. Either length is exceeded or investigation '{}' is null.",
                                description, investigation);
                        wasError = true;
                    }
                    //store object
                    if (title != null && title.length() >= 3 && title.length() <= 255) {
                        if (!title.equals(object.getLabel())) {
                            //store object
                            object.setLabel(title);
                            object = mdm.save(object);
                        }
                    } else {
                        LOGGER.warn("Failed to commit updated title '{}'. Length is invalid (3<=l<=255).",
                                title);
                        wasError = true;
                    }
                    if (wasError) {
                        new Notification("Warning",
                                "Failed to update title and/or description. See logfile for details.",
                                Notification.Type.WARNING_MESSAGE).show(Page.getCurrent());
                    }

                    //As there is not automatic sync between database and search index the entry has to be reindexed at this point in order
                    //to keep both systems consistent. However, changes taking place in between are lost.
                    LOGGER.debug("Object committed to database. Updating index.");
                    ElasticsearchHelper.indexEntry(object);
                } catch (UnauthorizedAccessAttemptException ex) {
                    LOGGER.error("Failed to commit changes.", ex);
                    new Notification("Warning", "Failed to commit changes. See logfile for details.",
                            Notification.Type.WARNING_MESSAGE).show(Page.getCurrent());

                } finally {
                    mdm.close();
                }
            }
            //do cancel/reload and switch back to read-mode
            reset();
            switchEditMode();
        }
    };

    //save/cancel buttons
    saveEditButton = new NativeButton("Commit Update");
    saveEditButton.setIcon(new ThemeResource("img/16x16/save.png"));
    saveEditButton.setStyleName(BaseTheme.BUTTON_LINK);
    saveEditButton.setDescription("Save changes to this digital object's metadata.");
    saveEditButton.addClickListener(saveCancelButtonListener);
    cancelEditButton = new NativeButton("Cancel Update");
    cancelEditButton.setIcon(new ThemeResource("img/16x16/cancel.png"));
    cancelEditButton.setStyleName(BaseTheme.BUTTON_LINK);
    cancelEditButton.setDescription("Withdraw all changes to this digital object's metadata.");
    cancelEditButton.addClickListener(saveCancelButtonListener);

    //default action layout
    Label spacerMiscActionLayout = new Label();
    miscActionLayout = new HorizontalLayout(editButton, shareButton, starButton, spacerMiscActionLayout);
    miscActionLayout.setWidth("100%");
    miscActionLayout.setHeight("18px");
    miscActionLayout.setSpacing(false);
    miscActionLayout.setMargin(false);
    miscActionLayout.setExpandRatio(spacerMiscActionLayout, .9f);

    //edit action layout
    Label spacerEditActionLayout = new Label();
    editActionLayout = new HorizontalLayout(saveEditButton, cancelEditButton, spacerEditActionLayout);
    editActionLayout.setWidth("100%");
    editActionLayout.setHeight("18px");
    editActionLayout.setSpacing(false);
    editActionLayout.setMargin(false);
    editActionLayout.setExpandRatio(spacerEditActionLayout, .9f);

    //divider generation
    Label dividerTop = new Label();
    dividerTop.setHeight("5px");
    dividerTop.addStyleName("horizontal-line");
    dividerTop.setWidth("90%");
    Label dividerBottom = new Label();
    dividerBottom.setHeight("5px");
    dividerBottom.addStyleName("horizontal-line");
    dividerBottom.setWidth("90%");
    Label dividerLeft = new Label();
    dividerLeft.addStyleName("vertical-line");
    dividerLeft.setWidth("5px");
    dividerLeft.setHeight("90%");
    Label dividerRight = new Label();
    dividerRight.addStyleName("vertical-line");
    dividerRight.setWidth("5px");
    dividerRight.setHeight("90%");

    //build content layout
    HorizontalLayout contentLayout = new HorizontalLayout(typeImage, dividerLeft, dcLayout, dividerRight,
            downloadButton);
    contentLayout.setSizeFull();
    contentLayout.setSpacing(true);
    contentLayout.setComponentAlignment(typeImage, Alignment.TOP_RIGHT);
    contentLayout.setComponentAlignment(dividerLeft, Alignment.MIDDLE_CENTER);
    contentLayout.setComponentAlignment(dcLayout, Alignment.MIDDLE_CENTER);
    contentLayout.setComponentAlignment(dividerRight, Alignment.MIDDLE_CENTER);
    contentLayout.setComponentAlignment(downloadButton, Alignment.BOTTOM_CENTER);
    contentLayout.setExpandRatio(typeImage, .1f);
    contentLayout.setExpandRatio(dcLayout, .8f);
    contentLayout.setExpandRatio(downloadButton, .1f);

    //build main layout
    mainLayout = new VerticalLayout(dividerTop, contentLayout, dividerBottom, miscActionLayout);
    mainLayout.setExpandRatio(dividerTop, .05f);
    mainLayout.setComponentAlignment(dividerTop, Alignment.TOP_LEFT);
    mainLayout.setExpandRatio(contentLayout, .80f);
    mainLayout.setExpandRatio(dividerBottom, .05f);
    mainLayout.setComponentAlignment(dividerBottom, Alignment.BOTTOM_RIGHT);
    mainLayout.setExpandRatio(miscActionLayout, .1f);
    mainLayout.setSpacing(true);
    mainLayout.setMargin(true);
    mainLayout.addStyleName("basic");
    mainLayout.setWidth("100%");
    mainLayout.setHeight("185px");
    //do reset to load title and description
    reset();
    LOGGER.debug("Layout successfully build up.");
}