Example usage for com.vaadin.ui AbstractOrderedLayout addComponent

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

Introduction

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

Prototype

@Override
public void addComponent(Component c) 

Source Link

Document

Add a component into this container.

Usage

From source file:com.blogspot.markogronroos.MainUI.java

License:GNU General Public License

protected void jpaContTable(AbstractOrderedLayout main) {
    final VerticalLayout layout = new VerticalLayout();
    main.addComponent(layout);
    show(layout, "Please notice table rows are selectable, column order movable, column sort order adjustable");

    // Create a persistent person container
    JPAContainer<Trip> trips = JPAContainerFactory.make(Trip.class, "source.jpa");
    // You can add entities to the container as well
    trips.addEntity(new Trip("Riga", "Brussels", 5.0F));
    trips.addEntity(new Trip("London", "Riga", 101.0F));

    // Bind it to a component
    Table personTable = new Table("Past Trips", trips);

    personTable.setSizeUndefined();/*from   w w  w  . j  a  va 2 s.  c o m*/
    personTable.setSelectable(true);
    personTable.setMultiSelect(false);
    personTable.setImmediate(true);
    personTable.setColumnReorderingAllowed(true);
    personTable.setColumnCollapsingAllowed(true);

    personTable.setVisibleColumns(new String[] { "id", "price", "startLocation", "finishLocation" });
    layout.addComponent(personTable);

    Button button = new Button("Clear");
    button.addClickListener(new Button.ClickListener() {
        public void buttonClick(Button.ClickEvent event) {
            //layout.addComponent(new Label("Thank you for clicking"));
            layout.removeAllComponents();
        }
    });
    layout.addComponent(button);
}

From source file:com.blogspot.markogronroos.MainUI.java

License:GNU General Public License

protected void jpaContTable2(AbstractOrderedLayout main) {
    final VerticalLayout layout = new VerticalLayout();
    main.addComponent(layout);
    show(layout, "This is same as above but EntityManager is created explicitly");

    EntityManager em = JPAContainerFactory.createEntityManagerForPersistenceUnit("source.jpa");
    /*/*ww  w. jav a  2 s .  c o  m*/
            
       Notice that if you use update the persistent data with an entity manager outside a JPAContainer bound to the 
       data, you need to refresh the container as described in Section 19.4.2, Creating and Accessing Entities?.
            
    Refreshing JPAContainer
            
    In cases where you change JPAContainer items outside the container, for example by through an EntityManager, 
    or when they change in the database, you need to refresh the container.
    The EntityContainer interface implemented by JPAContainer provides two methods to refresh a container. The 
    refresh() discards all container caches and buffers and refreshes all loaded items in the container. All 
    changes made to items provided by the container are discarded. The refreshItem() refreshes a single item.
            
    */
    // Create a persistent person container
    JPAContainer<Trip> trips = JPAContainerFactory.make(Trip.class, em);

    // You can add entities to the container as well
    trips.addEntity(new Trip("Riga", "Brussels", 5.0F));
    trips.addEntity(new Trip("London", "Riga", 101.0F));

    // Bind it to a component
    Table personTable = new Table("Past Trips", trips);

    personTable.setSizeUndefined();
    personTable.setSelectable(true);
    personTable.setMultiSelect(false);
    personTable.setImmediate(true);
    personTable.setColumnReorderingAllowed(true);
    personTable.setColumnCollapsingAllowed(true);

    personTable.setVisibleColumns(new String[] { "id", "price", "startLocation", "finishLocation" });
    layout.addComponent(personTable);

    Button button = new Button("Clear");
    button.addClickListener(new Button.ClickListener() {
        public void buttonClick(Button.ClickEvent event) {
            //layout.addComponent(new Label("Thank you for clicking"));
            layout.removeAllComponents();
        }
    });
    layout.addComponent(button);
}

From source file:com.blogspot.markogronroos.MainUI.java

License:GNU General Public License

protected void jpaContForm1(AbstractOrderedLayout main) {
    final VerticalLayout layout = new VerticalLayout();
    main.addComponent(layout);
    show(layout, "JPAContainer Form Example enterd!");

    // Have a persistent container
    final JPAContainer<Trip> trips = JPAContainerFactory.make(Trip.class, "source.jpa");
    // For selecting an item to edit
    // Country Editor
    final Form tripForm = new Form();
    tripForm.setCaption("Trip form");

    tripForm.setWidth("420px");
    tripForm.setBuffered(true);//from w  w w  .  ja va2s  . co  m
    tripForm.setEnabled(false);
    Object itemId = trips.getIdByIndex(0);
    if (itemId == null)
        show(layout, "Sorry no item retrieved!");
    else {
        show(layout, " choosen item: " + itemId); //+" class: "+itemId.getClass().getName());
        Item tripItem = trips.getItem(itemId);
        show(layout, " Item found :" + tripItem);
        layout.addComponent(tripForm);

        // Use a JPAContainer field factory
        //  - no configuration is needed here
        final FieldFactory fieldFactory = new FieldFactory();
        //fieldFactory.
        tripForm.setFormFieldFactory(fieldFactory);
        // Edit the item in the form
        tripForm.setItemDataSource(tripItem);
        tripForm.setEnabled(true);

        tripForm.setVisibleItemProperties(new String[] { "startLocation", "finishLocation", "status" });
        //tripForm.getField("name").setCaption("name new caption");

        // Handle saves on the form
        final Button save = new Button("Save");
        tripForm.getFooter().addComponent(save);
        save.addClickListener(new ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                try {
                    tripForm.commit();
                    tripForm.setEnabled(false);
                } catch (InvalidValueException e) {
                    e.printStackTrace();
                }
            }
        });

    }

}

From source file:com.blogspot.markogronroos.MainUI.java

License:GNU General Public License

protected void pureJPAExample(AbstractOrderedLayout main) {
    final VerticalLayout layout = new VerticalLayout();
    main.addComponent(layout);
    show(layout, "Entering pureJPAExample");
    EntityManager em = JPAContainerFactory.createEntityManagerForPersistenceUnit("source.jpa");
    em.getTransaction().begin();/*ww  w . jav a2s  . co m*/
    em.createQuery("DELETE FROM Trip t").executeUpdate();
    show(layout, "Rows deleted!");
    em.persist(new Trip("Istambul", "Mumbai", 555.0F));
    em.persist(new Trip("Mumbai", "Brussels", 125.0F));
    show(layout, "2 rows added!");
    em.getTransaction().commit();
    show(layout, "Commit completed!");

}

From source file:com.blogspot.markogronroos.MainUI.java

License:GNU General Public License

void show(AbstractOrderedLayout l, String text) {
    l.addComponent(new Label(text));

}

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

License:Open Source License

/**
 * Makes the component collapsible by wrapping it with a layout and button for toggling
 * the component's visibility. This allows the user to expand/collapse the given component in order
 * to free space for viewing other components.
 *
 * @param component         component to show/hide
 * @param useVerticalLayout true if toggle button should be laid out vertically next to animated component
 * @return the newly created layout that contains the toggle button and animated component
 *///www . ja va  2s.  c o m
protected Component makeCollapsible(String caption, Component component, boolean useVerticalLayout) {
    formAnimator = new Animator(component);
    formAnimator.setSizeUndefined();

    AbstractOrderedLayout animatorLayout;
    if (useVerticalLayout) {
        animatorLayout = new VerticalLayout();
    } else {
        animatorLayout = new HorizontalLayout();
    }
    setDebugId(animatorLayout, "animatorLayout");

    animatorLayout.setMargin(false, false, false, false);
    animatorLayout.setSpacing(false);

    toggleFormCollapseButton = new Button(null, new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            setFormVisible(!isFormVisible());
        }
    });
    toggleFormCollapseButton.setDescription(uiMessageSource.getToolTip("typedForm.toggleSearchForm.toolTip"));
    toggleFormCollapseButton.setIcon(new ThemeResource("../expressui/icons/collapse-icon.png"));
    toggleFormCollapseButton.addStyleName("borderless");

    if (useVerticalLayout) {
        HorizontalLayout toggleFormButtonAndCaption = new HorizontalLayout();
        setDebugId(toggleFormButtonAndCaption, "toggleFormButtonAndCaption");
        toggleFormButtonAndCaption.setSizeUndefined();
        toggleFormButtonAndCaption.addComponent(toggleFormCollapseButton);
        Label label = new Label(caption);
        label.setSizeUndefined();
        toggleFormButtonAndCaption.addComponent(label);
        animatorLayout.addComponent(toggleFormButtonAndCaption);
        animatorLayout.addComponent(formAnimator);
    } else {
        animatorLayout.addComponent(toggleFormCollapseButton);
        animatorLayout.addComponent(formAnimator);
    }

    return animatorLayout;
}

From source file:com.expressui.core.view.menu.LayoutContextMenu.java

License:Open Source License

/**
 * Constructs this context menu on given layout.
 *
 * @param layout layout for adding the context menu to
 *//*from www .j  av a  2 s .c  o  m*/
public LayoutContextMenu(AbstractOrderedLayout layout) {
    super();
    layout.addListener(this);
    layout.addComponent(this);
    addListener(this);
}

From source file:com.expressui.core.view.RootComponent.java

License:Open Source License

/**
 * Adds code popup button next to this component to the right.
 *
 * @param alignment alignment for button
 * @param classes   classes for displaying related source code and Javadoc
 *///from  w  w  w  . j a  v  a  2  s.  c  o  m
protected void addCodePopupButtonIfEnabled(Alignment alignment, Class... classes) {
    if (isCodePopupEnabled()) {
        Component firstComponent = getCompositionRoot();
        AbstractOrderedLayout codePopupButtonLayout = new HorizontalLayout();
        codePopupButtonLayout.setMargin(false);
        setDebugId(codePopupButtonLayout, "codePopupButtonLayout");
        setCompositionRoot(codePopupButtonLayout);
        codePopupButtonLayout.addComponent(firstComponent);
        Button codePopupButton = codePopup.createPopupCodeButton(autoAddCodeClasses(classes));
        codePopupButtonLayout.addComponent(codePopupButton);
        codePopupButtonLayout.setComponentAlignment(codePopupButton, alignment);
    }
}

From source file:com.hack23.cia.web.impl.ui.application.views.admin.system.pagemode.AbstractAdminSystemPageModContentFactoryImpl.java

License:Apache License

/**
 * Creates the paging controls./*from w  ww  . j a  va  2 s.c  o m*/
 *
 * @param name
 *            the name
 * @param pageId
 *            the page id
 * @param size
 *            the size
 * @param pageNr
 *            the page nr
 * @param resultPerPage
 *            the result per page
 * @return the horizontal layout
 */
protected final void createPagingControls(final AbstractOrderedLayout content, final String name,
        final String pageId, final Long size, final int pageNr, final int resultPerPage) {
    final HorizontalLayout pagingControls = new HorizontalLayout();
    pagingControls.setSpacing(true);
    pagingControls.setMargin(true);

    final int maxPages = (int) ((size + (resultPerPage - 1)) / resultPerPage);

    final StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(PAGE_HEADER).append(pageNr).append(PAGE_SEPARATOR).append(maxPages)
            .append(PAGES_TOTAL_RESULTS).append(size).append(RESULTS_PER_PAGE).append(resultPerPage)
            .append(SHOW);
    final Label pageInfo = new Label(stringBuilder.toString());
    pagingControls.addComponent(pageInfo);
    pagingControls.setExpandRatio(pageInfo, ContentRatio.SMALL);

    if (pageNr > PAGE_ONE) {
        addPagingLink(PREVIOUS_PAGE, name, pageId, pageNr - 1, pagingControls);
    }

    if (maxPages > PAGE_ONE && pageNr < maxPages) {
        addPagingLink(NEXT_PAGE, name, pageId, pageNr + 1, pagingControls);
    }

    if (maxPages > LIMIT_FOR_DISPLAYING_START_END_LINKS && pageNr > PAGE_ONE) {
        addPagingLink(FIRST_PAGE, name, pageId, 1, pagingControls);
    }

    if (maxPages > LIMIT_FOR_DISPLAYING_START_END_LINKS && pageNr < maxPages) {
        addPagingLink(LAST_PAGE, name, pageId, maxPages, pagingControls);
    }

    content.addComponent(pagingControls);
    content.setExpandRatio(pagingControls, ContentRatio.SMALL2);

}

From source file:com.hack23.cia.web.impl.ui.application.views.common.chartfactory.impl.AbstractChartDataManagerImpl.java

License:Apache License

/**
 * Adds the chart./*from ww w  . j a va 2  s  .  c  o m*/
 *
 * @param content
 *            the content
 * @param caption
 *            the caption
 * @param chart
 *            the chart
 */
protected final void addChart(final AbstractOrderedLayout content, final String caption, final DCharts chart) {
    final HorizontalLayout horizontalLayout = new HorizontalLayout();

    final int browserWindowWidth = Page.getCurrent().getBrowserWindowWidth() - 50;
    final int browserWindowHeight = Page.getCurrent().getBrowserWindowHeight() - 200;

    horizontalLayout.setWidth(browserWindowWidth, Unit.PIXELS);
    horizontalLayout.setHeight(browserWindowHeight, Unit.PIXELS);

    final Panel formPanel = new Panel();
    formPanel.setSizeFull();
    formPanel.setContent(horizontalLayout);

    content.addComponent(formPanel);
    content.setExpandRatio(formPanel, ContentRatio.LARGE);

    chart.setWidth(browserWindowWidth - 50, Unit.PIXELS);
    chart.setHeight(browserWindowHeight - 100, Unit.PIXELS);
    chart.setMarginRight(5);
    chart.setMarginLeft(5);
    chart.setMarginBottom(5);
    chart.setMarginTop(5);

    chart.setEnableDownload(true);
    chart.setChartImageFormat(ChartImageFormat.PNG);

    horizontalLayout.addComponent(chart);
    chart.setCaption(caption);
}