Example usage for com.vaadin.ui HorizontalLayout addComponent

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

Introduction

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

Prototype

@Override
public void addComponent(Component c) 

Source Link

Document

Add a component into this container.

Usage

From source file:com.example.tomeevaadin.ui.BookUI.java

private HorizontalLayout addInputFields() {
    HorizontalLayout hl = new HorizontalLayout();
    hl.addComponent(new Label("Enter a book"));
    TextField field = new TextField(stringModel);
    Button button = new Button("press this to save");
    button.addClickListener(new Button.ClickListener() {

        @Override/*from  w w  w. ja v a 2  s . c  o  m*/
        public void buttonClick(Button.ClickEvent event) {
            if (bookService == null) {
                System.out.println("uho, ejb is null");
            }
            Notification.show("button is pressed " + stringModel.getValue());
            Book book = new Book();
            book.setBookTitle(stringModel.getValue());
            bookService.addBook(book);
            updateBeanContainer();

        }
    });
    hl.addComponent(field);
    hl.addComponent(button);
    return hl;
}

From source file:com.example.vaadindemo.AddItemPanel.java

public HorizontalLayout draw(BeanItemContainer<ShoppingList> container) {
    final HorizontalLayout x = new HorizontalLayout();
    x.setId("addItemPanel");
    Button persistNewItemButton = new Button("Dodaj");
    final Item item = new Item();
    BeanItem<Item> personBean = new BeanItem<Item>(item);

    final FormLayout formLayout = new FormLayout();

    final FieldGroup form = new FieldGroup(); //new name: form

    form.setItemDataSource(personBean);//from   w  w  w  .  j ava 2s. c  o m
    form.setBuffered(true);

    Field imieField = form.buildAndBind("Name", "firstName");
    imieField.setRequired(true);
    imieField.addValidator(new StringLengthValidator("bad length", 2, 5, false));
    formLayout.addComponent(imieField);

    //Container
    final BeanItemContainer<Item> beanContainer = new BeanItemContainer<Item>(Item.class);
    //beanContainer.addBean(new Item();
    //beanContainer.addBean(new Item("Bolek"));
    //beanContainer.addBean(new Person("Lolek", 1933));

    // Put some example data in it
    container.addItem(new ShoppingList("Mercury", null, null));
    //container.addItem(new Planet(2, "Venus"));
    //container.addItem(new Planet(3, "Earth"));
    //container.addItem(new Planet(4, "Mars"));

    // Create a selection component bound to the container
    final ComboBox select = new ComboBox("Planets", container);

    // Set the caption mode to read the caption directly
    // from the 'name' property of the bean
    select.setItemCaptionMode(ItemCaptionMode.PROPERTY);
    select.setItemCaptionPropertyId("name");
    select.setImmediate(true);
    final Label ldd = new Label();

    x.addComponent(select);
    x.addComponent(formLayout);
    x.addComponent(persistNewItemButton);
    x.addComponent(ldd);
    persistNewItemButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            Label l = new Label("jsdcbsc");
            x.addComponent(l);
            //ldd.setValue(select.getItem(item.firstName).toString());
        }
    });

    select.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {

            ldd.setValue(select.getItemCaption(event.getProperty().getValue()));
        }
    });
    return x;
}

From source file:com.example.vaadindemo.MenuPanel.java

public HorizontalLayout draw() {

    HorizontalLayout menu = new HorizontalLayout();
    addItemButton = new Button("Dodaj do listy");
    addListButton = new Button("Dodaj list");
    Label appTitle = new Label("Organizator zakupw");
    appTitle.setId("appTitle");

    menu.addComponent(appTitle);
    menu.addComponent(addItemButton);/*from  w  ww .ja v  a2 s .c  o  m*/
    menu.addComponent(addListButton);
    return menu;
}

From source file:com.expressui.core.view.entityselect.EntitySelectResults.java

License:Open Source License

@PostConstruct
@Override//www.  jav a 2  s  .  c  om
public void postConstruct() {
    super.postConstruct();
    addSelectionChangedListener(this, "selectionChanged");

    HorizontalLayout crudButtons = new HorizontalLayout();
    setDebugId(crudButtons, "crudButtons");
    crudButtons.setMargin(false);
    crudButtons.setSpacing(true);

    selectButton = new Button(uiMessageSource.getMessage("results.select"));
    selectButton.setDescription(uiMessageSource.getToolTip("results.select.toolTip"));
    selectButton.setEnabled(false);
    selectButton.addStyleName("small default");
    crudButtons.addComponent(selectButton);

    getCrudButtons().addComponent(crudButtons, 0);
    getCrudButtons().setComponentAlignment(crudButtons, Alignment.MIDDLE_LEFT);

    getEntityQuery().setPageSize(applicationProperties.getDefaultSelectPageSize());

    addCodePopupButtonIfEnabled(EntitySelectResults.class);
}

From source file:com.expressui.core.view.export.ExportForm.java

License:Open Source License

@Override
protected void createFooterButtons(HorizontalLayout footerLayout) {
    footerLayout.setSpacing(true);//from   w  w  w  .j  a v  a 2  s  . c o  m
    footerLayout.setMargin(true);

    Button closeButton = new Button(uiMessageSource.getMessage("exportForm.close"), this, "close");
    closeButton.setDescription(uiMessageSource.getToolTip("exportForm.close.toolTip"));
    closeButton.setIcon(new ThemeResource("../expressui/icons/16/delete.png"));
    closeButton.addStyleName("small default");
    footerLayout.addComponent(closeButton);

    exportButton = new Button(uiMessageSource.getMessage("exportForm.export"));
    exportButton.setDescription(uiMessageSource.getToolTip("exportForm.export.toolTip"));
    exportButton.setIcon(new ThemeResource("../expressui/icons/16/excel.bmp"));
    exportButton.addStyleName("small default");
    footerLayout.addComponent(exportButton);
}

From source file:com.expressui.core.view.field.SelectField.java

License:Open Source License

private void initialize() {
    setSizeUndefined();//from w  ww  . j a  va 2s . c  o  m
    field = new TextField();
    FormField.initAbstractFieldDefaults(field);
    FormField.initTextFieldDefaults(field);
    field.setReadOnly(true);

    HorizontalLayout selectFieldLayout = new HorizontalLayout();
    String id = StringUtil.generateDebugId("e", this, selectFieldLayout, "selectFieldLayout");
    selectFieldLayout.setDebugId(id);
    selectFieldLayout.addComponent(field);

    searchButton = new Button();
    searchButton.setDescription(uiMessageSource.getToolTip("selectField.search.toolTip"));
    searchButton.setSizeUndefined();
    searchButton.addStyleName("borderless");
    searchButton.setIcon(new ThemeResource("../chameleon/img/magnifier.png"));
    searchButton.addListener(new Button.ClickListener() {
        public void buttonClick(Button.ClickEvent event) {
            entitySelect.open();
        }
    });
    selectFieldLayout.addComponent(searchButton);

    clearButton = new Button();
    clearButton.setDescription(uiMessageSource.getToolTip("selectField.clear.toolTip"));
    clearButton.setSizeUndefined();
    clearButton.addStyleName("borderless");
    clearButton.setIcon(new ThemeResource("../runo/icons/16/cancel.png"));
    selectFieldLayout.addComponent(clearButton);

    entitySelect.getResults().addSelectActionListener(this, "itemSelected");
    clearButton.addListener(Button.ClickEvent.class, this, "itemCleared");

    setCompositionRoot(selectFieldLayout);
}

From source file:com.expressui.core.view.form.EntityForm.java

License:Open Source License

@PostConstruct
@Override/*from  w w w .java  2  s .c o  m*/
public void postConstruct() {
    super.postConstruct();

    String typeName = domainMessageSource.getMessage(getType().getName(), getType().getSimpleName());
    labelRegistry.putTypeLabel(getType().getName(), typeName);

    List<ToManyRelationship> toManyRelationships = getViewableToManyRelationships();
    if (toManyRelationships.size() > 0) {
        toManyRelationshipTabs = new TabSheet();
        setDebugId(toManyRelationshipTabs, "toManyRelationshipTabs");
        toManyRelationshipTabs.setSizeUndefined();
        for (ToManyRelationship toManyRelationship : toManyRelationships) {
            toManyRelationshipTabs.addTab(toManyRelationship);
            toManyRelationship.getResultsTable().addExecuteQueryListener(this, "requestRepaintAll");
            labelRegistry.putFieldLabel(getType().getName(), toManyRelationship.getChildPropertyId(),
                    "Relationship", toManyRelationship.getTypeCaption());
        }

        HorizontalLayout toManyRelationshipLayout = new HorizontalLayout();
        setDebugId(toManyRelationshipLayout, "toManyRelationshipLayout");
        toManyRelationshipLayout.setSizeUndefined();
        Label label = new Label("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", Label.CONTENT_XHTML);
        toManyRelationshipLayout.addComponent(label);
        toManyRelationshipLayout.addComponent(toManyRelationshipTabs);
        addComponent(toManyRelationshipLayout);
    }

    addCodePopupButtonIfEnabled(Alignment.MIDDLE_RIGHT, EntityForm.class);
}

From source file:com.expressui.core.view.form.EntityForm.java

License:Open Source License

/**
 * Creates the footer buttons: cancel, refresh, save.
 *
 * @param footerLayout horizontal layout containing buttons
 *//* www  . ja v a2s  . c om*/
@Override
protected void createFooterButtons(HorizontalLayout footerLayout) {
    footerLayout.setSpacing(true);
    footerLayout.setMargin(true);

    cancelButton = new Button(uiMessageSource.getMessage("entityForm.cancel"), this, "cancel");
    cancelButton.setDescription(uiMessageSource.getToolTip("entityForm.cancel.toolTip"));
    cancelButton.setIcon(new ThemeResource("../expressui/icons/16/cancel.png"));
    cancelButton.addStyleName("small default");
    footerLayout.addComponent(cancelButton);

    refreshButton = new Button(uiMessageSource.getMessage("entityForm.refresh"), this, "refresh");
    refreshButton.setDescription(uiMessageSource.getToolTip("entityForm.refresh.toolTip"));
    refreshButton.setIcon(new ThemeResource("../expressui/icons/16/refresh.png"));
    refreshButton.addStyleName("small default");
    footerLayout.addComponent(refreshButton);

    saveAndStayOpenButton = new Button(uiMessageSource.getMessage("entityForm.saveAndStayOpen"), this,
            "saveAndStayOpen");
    saveAndStayOpenButton.setDescription(uiMessageSource.getToolTip("entityForm.saveAndStayOpen.toolTip"));
    saveAndStayOpenButton.setIcon(new ThemeResource("../expressui/icons/16/save.png"));
    saveAndStayOpenButton.addStyleName("small default");
    footerLayout.addComponent(saveAndStayOpenButton);

    saveAndCloseButton = new Button(uiMessageSource.getMessage("entityForm.saveAndClose"), this,
            "saveAndClose");
    saveAndCloseButton.setDescription(uiMessageSource.getToolTip("entityForm.saveAndClose.toolTip"));
    saveAndCloseButton.setIcon(new ThemeResource("../expressui/icons/16/save.png"));
    saveAndCloseButton.addStyleName("small default");
    footerLayout.addComponent(saveAndCloseButton);

    backupSaveButtonIcons();
}

From source file:com.expressui.core.view.form.layout.LeftLabelGridLayout.java

License:Open Source License

@Override
public void addField(FormField formField) {
    HorizontalLayout fieldLayout = (HorizontalLayout) getComponent(getFieldColumn(formField),
            getRowStart(formField));/*from  w  w  w. ja  v a2s. c  o  m*/
    if (fieldLayout == null) {
        addFieldImpl(formField);
    } else {
        if (formField.getFieldLabel().getValue() != null) {
            Label label = formField.getFieldLabel();
            fieldLayout.addComponent(label);
            Label spacer = new Label();
            spacer.setWidth("1em");
            fieldLayout.addComponent(spacer);
        }

        Field field = formField.getField();
        fieldLayout.addComponent(field);
        Label spacer = new Label();
        spacer.setWidth("1em");
        fieldLayout.addComponent(spacer);
    }
}

From source file:com.expressui.core.view.form.layout.LeftLabelGridLayout.java

License:Open Source License

private void addFieldImpl(FormField formField) {
    Label label = formField.getFieldLabel();

    HorizontalLayout fieldLayout = new HorizontalLayout();
    String id = StringUtil.generateDebugId("e", this, fieldLayout, "fieldLayout");
    fieldLayout.setDebugId(id);/*from w w w.j a  v a  2  s  .c o m*/
    fieldLayout.setSizeUndefined();
    Field field = formField.getField();
    fieldLayout.addComponent(field);

    Label spacer = new Label();
    spacer.setWidth("1em");

    if (formField.getColumnEnd() != null && formField.getRowEnd() != null) {
        addComponent(label, getLabelColumn(formField), getRowStart(formField), getLabelColumn(formField),
                getRowEnd(formField));

        addComponent(fieldLayout, getFieldColumn(formField), getRowStart(formField), getColumnEnd(formField),
                getRowEnd(formField));

        addComponent(spacer, getSpacerColumn(formField), getRowStart(formField), getSpacerColumn(formField),
                getRowEnd(formField));
    } else {
        addComponent(label, getLabelColumn(formField), getRowStart(formField));

        addComponent(fieldLayout, getFieldColumn(formField), getRowStart(formField));

        addComponent(spacer, getSpacerColumn(formField), getRowStart(formField));
    }
    setComponentAlignment(fieldLayout, Alignment.TOP_LEFT);
    setComponentAlignment(label, Alignment.TOP_RIGHT);
    setComponentAlignment(spacer, Alignment.TOP_LEFT);
}