Example usage for com.vaadin.ui HorizontalLayout setExpandRatio

List of usage examples for com.vaadin.ui HorizontalLayout setExpandRatio

Introduction

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

Prototype

public void setExpandRatio(Component component, float ratio) 

Source Link

Document

This method is used to control how excess space in layout is distributed among components.

Usage

From source file:com.mycompany.project.views.GroupsView.java

public GroupsView() {

    VerticalLayout mainVLayout = new VerticalLayout();
    mainVLayout.setMargin(true);/*from   w ww .j a  v  a2s.co m*/
    mainVLayout.setSpacing(true);

    setContent(mainVLayout);

    // view header
    Label header = new Label("<div align=\"center\" style=\"font-size:12pt;\">Grupos</div>");
    header.setContentMode(ContentMode.HTML);

    mainVLayout.addComponent(header);

    // set window properties
    window.setWidth("400px");
    window.setCaption("New Group");
    window.setModal(true);
    window.setContent(newGroupForm);

    // add new cotact button
    Button btnNew = new Button("Add New Group");
    mainVLayout.addComponent(btnNew);

    // clicking the button should display the NewContactForm
    btnNew.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (window.getParent() == null) {
                getUI().addWindow(window);
            }

        }
    });

    //add a horozontal layout - left has a table, right has a ContactDetail component
    HorizontalLayout hLayout = new HorizontalLayout();
    hLayout.setSizeFull();
    hLayout.setSpacing(true);

    mainVLayout.addComponent(hLayout);

    //add a table

    table.setWidth("600px");
    table.setImmediate(true);
    hLayout.addComponent(table);

    // how does table get its data
    beanContainer.setBeanIdProperty("id");
    table.setContainerDataSource(beanContainer);

    //set columns
    final Object[] NATURAL_COL_ORDER = new Object[] { "name" };
    final String[] COL_HEADERS_ENGLISH = new String[] { "Name" };

    table.setSelectable(true);
    table.setColumnCollapsingAllowed(true);
    table.setRowHeaderMode(RowHeaderMode.INDEX);
    table.setVisibleColumns(NATURAL_COL_ORDER);
    table.setColumnHeaders(COL_HEADERS_ENGLISH);

    // selecting a table row should enable/disale the ContactDetails component
    table.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            String groupId = (String) table.getValue();
            groupDetails.setGroupId(groupId);
        }
    });

    //add a ContactDetails component

    //        contactDetails.setWidth("500px");
    hLayout.addComponent(groupDetails);

    // let the table fill the entire remaining width
    hLayout.setExpandRatio(groupDetails, 1);
}

From source file:com.naoset.framework.frontend.view.window.Window.java

private HorizontalLayout buildFooter() {
    HorizontalLayout layout = new HorizontalLayout();
    layout.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);
    layout.setWidth(100.0f, Unit.PERCENTAGE);

    //Si el objeto a mostrar hereda de Widget, mostraremos su cabecera con el men en la ventana.
    if (Widget.class.isInstance(body)) {
        //if (details.getClass().isInstance(Widget.class)) {
        Widget aux = (Widget) body;//from w w w.j  a  v a2  s  .co  m
        HorizontalLayout header = aux.getHeader();
        header.setWidth(100.0f, Unit.PERCENTAGE);
        layout.addComponent(header);
        //layout.setComponentAlignment(header, Alignment.TOP_LEFT);
        layout.setExpandRatio(header, 1);
    }

    Button ok = new Button("Cerrar");
    ok.addStyleName(ValoTheme.BUTTON_PRIMARY);
    ok.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(final Button.ClickEvent event) {
            Boolean canClose = true;
            if (Widget.class.isInstance(body)) {
                Widget aux = (Widget) body;
                canClose = !aux.isModified();
            }
            if (canClose) {
                close();
            } else {

                buildConfirmCloseDialog();

            }

        }
    });
    ok.focus();
    layout.addComponent(ok);
    layout.setComponentAlignment(ok, Alignment.TOP_RIGHT);
    return layout;
}

From source file:com.neatresults.mgnltweaks.neatu2b.ui.form.field.U2BField.java

License:Open Source License

/**
 * Create a single element.<br>/*from  www . ja v  a2 s. co m*/
 * This single element is composed of:<br>
 * - a configured field <br>
 * - a remove Button<br>
 */
private Component createEntryComponent(String propertyId, PropertysetItem newValue) {
    String cappedId = StringUtils.capitalize(propertyId);
    final HorizontalLayout layout = new HorizontalLayout();
    layout.setWidth(100, Unit.PERCENTAGE);
    layout.setHeight(-1, Unit.PIXELS);
    TextField url = createTextField(cappedId + " Thumbnail", newValue, propertyId + "Url");
    layout.addComponent(url);

    TextField width = createTextField("Width", newValue, propertyId + "Width");
    layout.addComponent(width);
    TextField height = createTextField("Height", newValue, propertyId + "Height");
    layout.addComponent(height);
    layout.setExpandRatio(url, .7f);
    layout.setExpandRatio(width, .15f);
    layout.setExpandRatio(height, .15f);

    return layout;
}

From source file:com.nfl.dm.clubsites.cms.articles.subapp.articleeditor.tagging.TaggingViewImpl.java

License:Open Source License

private void buildCustomTagsLayout() {

    final VerticalLayout customTags = new VerticalLayout();
    customTags.setCaption("Custom Tags");

    final HorizontalLayout newTagLayout = new HorizontalLayout();
    newTagLayout.setSizeUndefined();/*from   w w w. j a va  2 s  .co m*/

    final TextField newTagTextField = new TextField();
    newTagTextField.addStyleName("new-tag-textfield");
    newTagTextField.setHeight("52px");
    newTagTextField.setWidth("320px");
    newTagTextField.setNullRepresentation("");
    newTagTextField.setInputPrompt("Add new tag");
    NativeButton addTagButton = new NativeButton("", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            addCustomTag(newTagTextField);
        }
    });
    addTagButton.addStyleName("add-tag-button");

    newTagLayout.addComponent(newTagTextField);
    newTagLayout.addComponent(addTagButton);
    newTagLayout.setExpandRatio(newTagTextField, 1f);

    /*
    NativeButton addGenerateTagsButton = new NativeButton("", new Button.ClickListener() {
    @Override
    public void buttonClick(Button.ClickEvent event) {
        // Generate Tags
    }
    });
    addGenerateTagsButton.addStyleName("generate-tags-button");
    addGenerateTagsButton.setCaption("Generate Tags");
    newTagLayout.addComponent(addGenerateTagsButton);
    */

    customTags.addComponent(newTagLayout);
    customTags.addComponent(customTagLayout);

    this.tagLayout.addComponent(customTags);
}

From source file:com.oodrive.nuage.webui.component.VvrOperationComponent.java

License:Apache License

@Override
public final AbstractComponent createComponent(final VvrModel model, final ModelCreator handler) {

    final HorizontalLayout operationLayout = new HorizontalLayout();
    operationLayout.setMargin(true);/* w  w  w . j  av  a 2 s . c om*/
    operationLayout.setSpacing(true);
    operationLayout.setWidth("100%");

    // Start and description buttons
    // START/STOP
    final Button startStop = new Button();
    startStop.setWidth(BUTTON_WIDTH);
    startStop.addStyleName(Runo.BUTTON_BIG);

    final Resource iconStartStop;
    final String description;
    if (!model.isVvrStarted()) {
        iconStartStop = WebUiResources.getStartIcon();
        description = "Start";
    } else {
        iconStartStop = WebUiResources.getStopIcon();
        description = "Stop";
    }
    startStop.setIcon(iconStartStop);
    startStop.setDescription(description);

    operationLayout.addComponent(startStop);
    operationLayout.setExpandRatio(startStop, 1f);
    operationLayout.setComponentAlignment(startStop, Alignment.MIDDLE_LEFT);

    final UUID vvrUuid = model.getItemUuid();
    startStop.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            final boolean started = model.isVvrStarted();
            // Start/Stop are done in background
            if (!started) {
                WaitingComponent.executeBackground(model, new Background() {
                    @Override
                    public void processing() {
                        model.startVvr();
                    }

                    @Override
                    public void postProcessing() {
                        startStop.setIcon(WebUiResources.getStopIcon());
                        startStop.setDescription("Stop");
                        Notification.show("VVR started ", vvrUuid.toString(),
                                Notification.Type.TRAY_NOTIFICATION);
                    }
                });
            } else {
                WaitingComponent.executeBackground(model, new Background() {
                    @Override
                    public void processing() {
                        model.stopVvr();
                    }

                    @Override
                    public void postProcessing() {
                        startStop.setIcon(WebUiResources.getStartIcon());
                        startStop.setDescription("Start");
                        Notification.show("VVR stopped ", vvrUuid.toString(),
                                Notification.Type.TRAY_NOTIFICATION);
                    }
                });
            }
        }
    });

    // ATTRIBUTES
    final Button attributes = new Button();
    attributes.addStyleName(Runo.BUTTON_BIG);
    attributes.setWidth(BUTTON_WIDTH);

    operationLayout.addComponent(attributes);
    operationLayout.setExpandRatio(attributes, 1f);
    operationLayout.setComponentAlignment(attributes, Alignment.MIDDLE_LEFT);
    attributes.setIcon(WebUiResources.getSettingsIcon());
    attributes.setDescription("Settings");

    attributes.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            try {
                final VvrAttributesWindow attributesWindow = new VvrAttributesWindow(vvrUuid);
                attributesWindow.add(model);
            } catch (final Exception e) {
                LOGGER.error("Can not get VVR attributes: ", e);
                final ErrorWindow err = new ErrorWindow("Can not display VVR Attributes: " + e.getMessage());
                err.add(model);
            }
        }
    });

    // DELETE
    final Button delete = new Button();
    delete.addStyleName(Runo.BUTTON_BIG);
    delete.setWidth(BUTTON_WIDTH);
    delete.setIcon(WebUiResources.getTrashIcon());
    delete.setDescription("Delete");

    operationLayout.addComponent(delete);
    operationLayout.setExpandRatio(delete, 12f);
    operationLayout.setComponentAlignment(delete, Alignment.MIDDLE_RIGHT);

    delete.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            try {
                final VvrDeleteWindow deleteWindow = new VvrDeleteWindow(vvrUuid);
                deleteWindow.add(vvrManagerModel);
            } catch (final Exception e) {
                LOGGER.error("Can not delete VVR: ", e);
                final ErrorWindow err = new ErrorWindow("Can not delete VVR: " + e.getMessage());
                err.add(model);
            }
        }
    });
    return operationLayout;
}

From source file:com.oodrive.nuage.webui.VvrManagerUi.java

License:Apache License

@Override
protected void init(final VaadinRequest request) {

    // Listener to disconnect JMX connection on exit.
    addDetachListener(new DetachListener() {
        @Override/*  w ww  .  j  av  a  2s . c  o m*/
        public void detach(final DetachEvent event) {
            jmxHandler.disconnect();
        }
    });
    setPollInterval(1000);

    final Label labelLeft = new Label("");
    final Label labelRight = new Label("");

    labelLeft.setHeight("100%");
    labelRight.setHeight("100%");

    final HorizontalLayout content = new HorizontalLayout();
    content.setSizeFull();

    rootLayout.setWidth(rootLayoutWidth);
    rootLayout.setImmediate(true);
    rootLayout.addComponent(vvrManagerLayout);
    vvrManagerLayout.setMargin(false);
    vvrManagerLayout.setSpacing(true);
    vvrManagerLayout.setWidth(rootLayoutWidth);

    content.addComponent(labelLeft);
    content.addComponent(rootLayout);
    content.addComponent(labelRight);

    content.setExpandRatio(labelLeft, 0.5f);
    content.setExpandRatio(labelRight, 0.5f);

    content.setComponentAlignment(rootLayout, Alignment.TOP_CENTER);
    setContent(content);

    // Init Jmx Handler
    try {
        jmxHandler.connect();
        // Init ui
        initVvrManagerUi(jmxHandler);
    } catch (final Exception e) {
        LOGGER.error("Can not connect to JMX", e);
    }
}

From source file:com.openhris.employee.EmployeeSummaryUI.java

public EmployeeSummaryUI(int branchId) {
    this.branchId = branchId;

    setSizeFull();/* w  w  w  . ja va2 s . c  o m*/
    setSpacing(true);
    setMargin(new MarginInfo(true, true, false, false));

    HorizontalLayout h = new HorizontalLayout();
    h.setWidth("100%");
    h.setMargin(true);
    h.setSpacing(true);

    final ComboBox employeeStatus = new ComboBox("Status: ");
    employeeStatus.setWidth("150px");
    employeeStatus.setNullSelectionAllowed(false);
    employeeStatus.addItem("employed");
    employeeStatus.addItem("resigned");
    h.addComponent(employeeStatus);

    Button generateBtn = new Button("GENERATE EMPLOYEE SUMMARY");
    generateBtn.setWidth("250px");
    generateBtn.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (employeeStatus.getValue() == null) {
                getWindow().showNotification("Employee Status!", Window.Notification.TYPE_WARNING_MESSAGE);
                return;
            }

            tradeId = cs.getTradeIdByBranchId(getBranchId());
            corporateId = cs.getCorporateIdByTradeId(tradeId);

            summary.setContainerDataSource(
                    new EmployeeSummaryDataContainer(corporateId, employeeStatus.getValue().toString()));
        }
    });
    h.addComponent(generateBtn);
    h.setComponentAlignment(generateBtn, Alignment.BOTTOM_LEFT);

    Button exportTableToExcel = new Button("EXPORT TO EXCEL");
    exportTableToExcel.setWidth("250px");
    exportTableToExcel.addListener(new Button.ClickListener() {

        private static final long serialVersionUID = -73954695086117200L;
        private ExcelExport excelExport;

        @Override
        public void buttonClick(Button.ClickEvent event) {
            excelExport = new ExcelExport(summary, "EMPLOYEE SUMMARY");
            excelExport.excludeCollapsedColumns();
            excelExport.setReportTitle(cs.getCorporateById(corporateId).toUpperCase() + " Employee Summary");
            excelExport.setExportFileName(cs.getCorporateById(corporateId).replace(",", " ").toUpperCase()
                    + "-Employee-Summary-" + ".xls");
            excelExport.export();
        }
    });
    h.addComponent(exportTableToExcel);
    h.setComponentAlignment(exportTableToExcel, Alignment.BOTTOM_LEFT);
    h.setExpandRatio(exportTableToExcel, 3);

    addComponent(h);
    addComponent(summary);
    setExpandRatio(summary, 2);
}

From source file:com.openhris.payroll.contributions.AFLUI.java

public AFLUI(int branchId) {
    this.branchId = branchId;

    setSizeFull();//from  w  w w.ja  v a2 s. c om
    setSpacing(true);
    setMargin(new MarginInfo(true, true, false, false));

    HorizontalLayout h = new HorizontalLayout();
    h.setWidth("100%");
    h.setMargin(true);
    h.setSpacing(true);

    final PopupDateField payrollDateField = new HRISPopupDateField("Payroll Month and Year");
    payrollDateField.setWidth("200px");
    h.addComponent(payrollDateField);

    Button generateBtn = new Button("GENERATE AFL");
    generateBtn.setWidth("200px");
    generateBtn.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            tradeId = cs.getTradeIdByBranchId(getBranchId());
            corporateId = cs.getCorporateIdByTradeId(tradeId);

            afl.setContainerDataSource(new AFLContainer(corporateId,
                    util.parsingDate(util.convertDateFormat(payrollDateField.getValue().toString()))));
        }
    });
    h.addComponent(generateBtn);
    h.setComponentAlignment(generateBtn, Alignment.BOTTOM_LEFT);

    Button exportTableToExcel = new Button("EXPORT TO EXCEL");
    exportTableToExcel.setWidth("200px");
    exportTableToExcel.addListener(new Button.ClickListener() {

        private static final long serialVersionUID = -73954695086117200L;
        private ExcelExport excelExport;

        @Override
        public void buttonClick(Button.ClickEvent event) {
            excelExport = new ExcelExport(afl, "AFL Remitance");
            excelExport.excludeCollapsedColumns();
            excelExport.setReportTitle(cs.getCorporateById(corporateId).toUpperCase() + " AFL Remitances");
            excelExport.setExportFileName(
                    cs.getCorporateById(corporateId).replace(",", " ").toUpperCase() + "-AFL-Remitance-"
                            + util.convertDateFormat(payrollDateField.getValue().toString()) + ".xls");
            excelExport.export();
        }

    });
    h.addComponent(exportTableToExcel);
    h.setComponentAlignment(exportTableToExcel, Alignment.BOTTOM_LEFT);
    h.setExpandRatio(exportTableToExcel, 2);

    addComponent(h);
    addComponent(afl);
    setExpandRatio(afl, 2);
}

From source file:com.openhris.payroll.contributions.BankDebitMemoUI.java

public BankDebitMemoUI(int branchId) {
    this.branchId = branchId;

    setSizeFull();//w w  w.  j  a  va  2  s  .co m
    setSpacing(true);
    setMargin(new MarginInfo(true, true, false, false));

    HorizontalLayout h = new HorizontalLayout();
    h.setWidth("100%");
    h.setMargin(true);
    h.setSpacing(true);

    final PopupDateField payrollDateField = new HRISPopupDateField("Payroll Month and Year");
    payrollDateField.setWidth("200px");
    h.addComponent(payrollDateField);

    Button generateBtn = new Button("GENERATE BANK DEBIT MEMO");
    generateBtn.setWidth("200px");
    generateBtn.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            tradeId = cs.getTradeIdByBranchId(getBranchId());
            corporateId = cs.getCorporateIdByTradeId(tradeId);

            Date date = util.parsingDate(util.convertDateFormat(payrollDateField.getValue().toString()));
            Calendar c = Calendar.getInstance();
            c.setTime(date);

            debitMemoTable.setContainerDataSource(
                    new BankDebitMemoContainer(corporateId, util.convertDateFormat(date.toString())));

        }
    });
    h.addComponent(generateBtn);
    h.setComponentAlignment(generateBtn, Alignment.BOTTOM_LEFT);

    Button exportTableToExcel = new Button("EXPORT TO EXCEL");
    exportTableToExcel.setWidth("200px");
    exportTableToExcel.addListener(new Button.ClickListener() {

        private static final long serialVersionUID = -73954695086117200L;
        private ExcelExport excelExport;

        @Override
        public void buttonClick(Button.ClickEvent event) {
            excelExport = new ExcelExport(debitMemoTable, "BANK DEBIT MEMO");
            excelExport.excludeCollapsedColumns();
            excelExport.setReportTitle(cs.getCorporateById(corporateId).toUpperCase() + " Bank Debit Memo");
            excelExport.setExportFileName(
                    cs.getCorporateById(corporateId).replace(",", " ").toUpperCase() + "-Bank-Debit-Memo-"
                            + util.convertDateFormat(payrollDateField.getValue().toString()) + ".xls");
            excelExport.export();
        }
    });
    h.addComponent(exportTableToExcel);
    h.setComponentAlignment(exportTableToExcel, Alignment.BOTTOM_LEFT);
    h.setExpandRatio(exportTableToExcel, 2);

    addComponent(h);
    addComponent(debitMemoTable);
    setExpandRatio(debitMemoTable, 2);
}

From source file:com.openhris.payroll.contributions.HdmfUI.java

public HdmfUI(int branchId) {
    this.branchId = branchId;

    setSizeFull();//from  w w w . j av  a 2s  .  c  o  m
    setSpacing(true);
    setMargin(new MarginInfo(true, true, false, false));

    HorizontalLayout h = new HorizontalLayout();
    h.setWidth("100%");
    h.setMargin(true);
    h.setSpacing(true);

    final PopupDateField payrollDateField = new HRISPopupDateField("Payroll Month and Year");
    payrollDateField.setWidth("200px");
    h.addComponent(payrollDateField);

    Button generateBtn = new Button("GENERATE HDMF SHARE");
    generateBtn.setWidth("200px");
    generateBtn.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            tradeId = cs.getTradeIdByBranchId(getBranchId());
            corporateId = cs.getCorporateIdByTradeId(tradeId);

            Date date = util.parsingDate(util.convertDateFormat(payrollDateField.getValue().toString()));
            Calendar c = Calendar.getInstance();
            c.setTime(date);

            hdmfTable.setContainerDataSource(
                    new HdmfDataContainer(corporateId, (1 + c.get(Calendar.MONTH)), c.get(Calendar.YEAR)));

        }
    });
    h.addComponent(generateBtn);
    h.setComponentAlignment(generateBtn, Alignment.BOTTOM_LEFT);

    Button exportTableToExcel = new Button("EXPORT TO EXCEL");
    exportTableToExcel.setWidth("200px");
    exportTableToExcel.addListener(new Button.ClickListener() {

        private static final long serialVersionUID = -73954695086117200L;
        private ExcelExport excelExport;

        @Override
        public void buttonClick(Button.ClickEvent event) {
            excelExport = new ExcelExport(hdmfTable, "HDMF Remitance");
            excelExport.excludeCollapsedColumns();
            excelExport.setReportTitle(cs.getCorporateById(corporateId).toUpperCase() + " HDMF Remitances");
            excelExport.setExportFileName(
                    cs.getCorporateById(corporateId).replace(",", " ").toUpperCase() + "-HDMF-Remitance-"
                            + util.convertDateFormat(payrollDateField.getValue().toString()) + ".xls");
            excelExport.export();
        }
    });
    h.addComponent(exportTableToExcel);
    h.setComponentAlignment(exportTableToExcel, Alignment.BOTTOM_LEFT);
    h.setExpandRatio(exportTableToExcel, 2);

    addComponent(h);
    addComponent(hdmfTable);
    setExpandRatio(hdmfTable, 2);
}