Example usage for com.vaadin.ui Component getCaption

List of usage examples for com.vaadin.ui Component getCaption

Introduction

In this page you can find the example usage for com.vaadin.ui Component getCaption.

Prototype

public String getCaption();

Source Link

Document

Gets the caption of the component.

Usage

From source file:at.peppol.webgui.app.components.PartyDetailForm.java

License:Mozilla Public License

private void initElements() {

    setCaption(party + " Party");
    //setStyleName("light");

    final VerticalLayout outerLayout = new VerticalLayout();
    outerLayout.setSpacing(true);//from w  w  w .ja v a 2 s. co m
    outerLayout.setMargin(true);

    hiddenContent = new VerticalLayout();
    hiddenContent.setSpacing(true);
    hiddenContent.setMargin(true);

    PropertysetItem partyItemSet = new PropertysetItem();

    PartyIdentificationType supplierPartyID;
    if (partyBean.getPartyIdentification().size() == 0) {
        supplierPartyID = new PartyIdentificationType();
        supplierPartyID.setID(new IDType());
        partyBean.getPartyIdentification().add(supplierPartyID);
    } else {
        supplierPartyID = partyBean.getPartyIdentification().get(0);
    }

    partyItemSet.addItemProperty("Party ID", new NestedMethodProperty(supplierPartyID, "ID.value"));

    EndpointIDType endPointID;
    if (partyBean.getEndpointID() == null) {
        endPointID = new EndpointIDType();
        partyBean.setEndpointID(endPointID);
    } else {
        endPointID = partyBean.getEndpointID();
    }
    partyItemSet.addItemProperty("Endpoint ID", new NestedMethodProperty(endPointID, "SchemeAgencyID"));

    PartyNameType partyName;
    if (partyBean.getPartyName().size() == 0) {
        partyName = new PartyNameType();
        partyName.setName(new NameType());
        partyBean.getPartyName().add(partyName);
    } else {
        partyName = partyBean.getPartyName().get(0);
    }
    partyItemSet.addItemProperty("Party Name", new NestedMethodProperty(partyName, "name.value"));

    /*        partyItemSet.addItemProperty("Agency Name", 
        new NestedMethodProperty(supplierPartyID, "ID.SchemeAgencyID") );
    */
    /*
    final AddressType partyrAddress = new AddressType();
            
    partyBean.setPostalAddress(partyrAddress);
    partyrAddress.setStreetName(new StreetNameType());
    partyrAddress.setCityName(new CityNameType());
    partyrAddress.setPostalZone(new PostalZoneType());
    partyrAddress.setCountry(new CountryType());
            
    partyrAddress.getCountry().setIdentificationCode(new IdentificationCodeType());
            
    partyItemSet.addItemProperty("Street Name",
                    new NestedMethodProperty(partyrAddress, "streetName.value"));
    partyItemSet.addItemProperty("City",
                    new NestedMethodProperty(partyrAddress, "cityName.value"));
    partyItemSet.addItemProperty("Postal Zone",
                    new NestedMethodProperty(partyrAddress, "postalZone.value"));
    partyItemSet.addItemProperty("Country",
                    new NestedMethodProperty(partyrAddress, "country.identificationCode.value"));
    */
    AddressDetailForm partyAddressForm;
    AddressType address;
    if (partyBean.getPostalAddress() == null) {
        address = new AddressType();
    } else {
        address = partyBean.getPostalAddress();
    }
    partyAddressForm = new AddressDetailForm(party, address);
    partyBean.setPostalAddress(address);

    PartyTaxSchemeType taxScheme;
    if (partyBean.getPartyTaxScheme().size() == 0) {
        taxScheme = new PartyTaxSchemeType();
        taxScheme.setCompanyID(new CompanyIDType());

        //partyItemSet.addItemProperty(taxSchemeCompanyID,
        //        new NestedMethodProperty(taxScheme.getCompanyID(),"value"));

        // TODO: Hardcoded ShemeID etc for TaxScheme. Should be from a codelist?
        taxScheme.setTaxScheme(new TaxSchemeType());
        taxScheme.getTaxScheme().setID(new IDType());
        taxScheme.getTaxScheme().getID().setValue("VAT");
        taxScheme.getTaxScheme().getID().setSchemeID("UN/ECE 5153");
        taxScheme.getTaxScheme().getID().setSchemeAgencyID("6");

        partyBean.getPartyTaxScheme().add(taxScheme);
    } else {
        taxScheme = partyBean.getPartyTaxScheme().get(0);
    }

    partyItemSet.addItemProperty(taxSchemeCompanyID,
            new NestedMethodProperty(taxScheme.getCompanyID(), "value"));

    partyItemSet.addItemProperty(taxSchemeID,
            new NestedMethodProperty(taxScheme.getTaxScheme().getID(), "value"));

    final Form partyForm = new Form();
    partyForm.setFormFieldFactory(new PartyFieldFactory());
    partyForm.setItemDataSource(partyItemSet);
    partyForm.setImmediate(true);

    final Button addLegalEntityBtn = new Button("Add Legal Entity");
    final Button removeLegalEntityBtn = new Button("Remove Legal Entity");
    //removeLegalEntityBtn.setVisible(false);

    addLegalEntityBtn.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            //add the legal entity component
            Panel panel = createLegalEntityPanel(removeLegalEntityBtn);
            outerLayout.addComponent(panel);
            panel.setWidth("90%");
            addLegalEntityBtn.setVisible(false);
            //removeLegalEntityBtn.setVisible(true);
            //outerLayout.replaceComponent(removeLegalEntityBtn, panel);
        }
    });

    removeLegalEntityBtn.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            //remove the legal entity component
            for (int i = 0; i < outerLayout.getComponentCount(); i++) {
                Component c = outerLayout.getComponent(i);
                if (c instanceof Panel) {
                    if (c.getCaption().equals("Legal Entity")) {
                        outerLayout.removeComponent(c);
                        if (partyBean.getPartyLegalEntity().size() > 0) {
                            partyBean.getPartyLegalEntity().clear();
                            ValidatorsList.removeListeners(Utils.getFieldListeners(legalEntityForm));
                        }
                    }
                }
            }
            //removeLegalEntityBtn.setVisible(false);
            addLegalEntityBtn.setVisible(true);
        }
    });

    outerLayout.addComponent(partyForm);
    partyForm.setWidth("90%");
    outerLayout.addComponent(partyAddressForm);
    partyAddressForm.setWidth("90%");
    outerLayout.addComponent(addLegalEntityBtn);
    if (partyBean.getPartyLegalEntity().size() > 0)
        addLegalEntityBtn.click();
    //outerLayout.addComponent(removeLegalEntityBtn);
    //outerLayout.addComponent(createLegalEntityPanel());

    setContent(outerLayout);
}

From source file:com.cavisson.gui.dashboard.components.controls.ValoThemeUI.java

License:Apache License

@Override
protected void init(final VaadinRequest request) {
    if (request.getParameter("test") != null) {
        testMode = true;/* w  w w  .  ja v a 2s  .c o  m*/

        if (browserCantRenderFontsConsistently()) {
            getPage().getStyles().add(".v-app.v-app.v-app {font-family: Sans-Serif;}");
        }
    }

    if (getPage().getWebBrowser().isIE() && getPage().getWebBrowser().getBrowserMajorVersion() == 9) {
        menu.setWidth("320px");
    }
    // Show .v-app-loading valo-menu-badge
    // try {
    // Thread.sleep(2000);
    // } catch (InterruptedException e) {
    // e.printStackTrace();
    // }

    if (!testMode) {
        Responsive.makeResponsive(this);
    }

    getPage().setTitle("Valo Theme Test");
    setContent(root);
    root.setWidth("100%");

    root.addMenu(buildMenu());

    navigator = new Navigator(this, viewDisplay);

    navigator.addView("common", CommonParts.class);
    navigator.addView("labels", Labels.class);
    navigator.addView("buttons-and-links", ButtonsAndLinks.class);
    navigator.addView("textfields", TextFields.class);
    navigator.addView("datefields", DateFields.class);
    navigator.addView("comboboxes", ComboBoxes.class);
    navigator.addView("checkboxes", CheckBoxes.class);
    navigator.addView("sliders", Sliders.class);
    navigator.addView("menubars", MenuBars.class);
    navigator.addView("panels", Panels.class);
    navigator.addView("trees", Trees.class);
    navigator.addView("tables", Tables.class);
    navigator.addView("splitpanels", SplitPanels.class);
    navigator.addView("tabs", Tabsheets.class);
    navigator.addView("accordions", Accordions.class);
    navigator.addView("colorpickers", ColorPickers.class);
    navigator.addView("selects", NativeSelects.class);
    navigator.addView("calendar", CalendarTest.class);
    navigator.addView("forms", Forms.class);
    navigator.addView("popupviews", PopupViews.class);
    navigator.addView("dragging", Dragging.class);

    final String f = Page.getCurrent().getUriFragment();
    if (f == null || f.equals("")) {
        navigator.navigateTo("common");
    }

    navigator.setErrorView(CommonParts.class);

    navigator.addViewChangeListener(new ViewChangeListener() {

        @Override
        public boolean beforeViewChange(final ViewChangeEvent event) {
            return true;
        }

        @Override
        public void afterViewChange(final ViewChangeEvent event) {
            for (final Iterator<Component> it = menuItemsLayout.iterator(); it.hasNext();) {
                it.next().removeStyleName("selected");
            }
            for (final Entry<String, String> item : menuItems.entrySet()) {
                if (event.getViewName().equals(item.getKey())) {
                    for (final Iterator<Component> it = menuItemsLayout.iterator(); it.hasNext();) {
                        final Component c = it.next();
                        if (c.getCaption() != null && c.getCaption().startsWith(item.getValue())) {
                            c.addStyleName("selected");
                            break;
                        }
                    }
                    break;
                }
            }
            menu.removeStyleName("valo-menu-visible");
        }
    });

}

From source file:com.foc.vaadin.FocWebVaadinWindow.java

License:Apache License

public NativeButton newButtonInHeaderBar_IfNotExist(String caption, boolean asFirst, boolean addButton) {
    NativeButton nBut = null;/*from   w w w  . j a  v a 2s.c om*/
    if (centerHeaderLayout != null) {
        for (int i = 0; i < centerHeaderLayout.getComponentCount(); i++) {
            Component comp = centerHeaderLayout.getComponent(i);
            if (comp != null && comp.getCaption() != null && comp.getCaption().compareTo(caption) == 0) {
                return null;
            }
        }

        nBut = newButtonInHeaderBar(caption, asFirst, addButton);
    }
    return nBut;
}

From source file:com.jain.addon.i18N.handlers.I18NComponentHandler.java

License:Apache License

public I18NComponentHandler(final Component component) {
    this(component.getCaption());
    provider = ((I18NUI) component.getUI()).getI18nProvider();
}

From source file:com.jain.addon.i18N.I18NHelper.java

License:Apache License

/**
 * Method to get i18N caption for given component 
 * @param {@link Component}//  ww  w .jav a2s . c  om
 * @return i18NCaption
 */
public static String getKey(Component component) {
    I18NChangeListener listener = findListener(component, false);
    if (listener != null)
        return listener.getI18NCaption(component);
    return component.getCaption();
}

From source file:com.jain.addon.i18N.I18NHelper.java

License:Apache License

/**
 * Method to get i18N caption for given component 
 * @param {@link Component}// w  w w.j  a  v a2s . c om
 * @return i18NCaption
 */
public static String getKey(Component component, Serializable serializable) {
    I18NChangeListener listener = findListener(component, false);
    if (listener != null)
        return listener.getI18NCaption(component, serializable);
    return component.getCaption();
}

From source file:com.mcparland.john.TabsURL.java

License:Apache License

/**
 * Select the appropriate tab depending on URL fragment.
 *///from  w w w .jav a  2  s  . c  om
public void selectTab() {
    final String fragment = UI.getCurrent().getPage().getUriFragment();
    if (null == fragment) {
        setSelectedTab(0);
    } else {
        Iterator<Component> compIt = iterator();
        while (compIt.hasNext()) {
            final Component tab = compIt.next();
            final String tabName = tab.getCaption();
            final String tabNameAsURLFragment = convertNameToFragment(tabName);
            // Check tab name against the URL fragment.
            if (null != tabNameAsURLFragment && StringUtils.equalsIgnoreCase(fragment, tabNameAsURLFragment)) {
                setSelectedTab(tab);
                return;
            }
        }
        // Yikes, finished the while loop and no tab selected.
        setSelectedTab(0);
    }
}

From source file:com.mymita.vaadlets.VaadletsBuilder.java

License:Apache License

private static void setComponentAttributes(final com.vaadin.ui.Component vaadinComponent,
        final com.mymita.vaadlets.core.Component c) {
    vaadinComponent.setCaption(c.getCaption());
    vaadinComponent.setEnabled(c.isEnabled());
    vaadinComponent.setReadOnly(c.isReadonly());
    vaadinComponent.setVisible(c.isVisible());
    if (c.getHeight() != null) {
        vaadinComponent.setHeight(c.getHeight());
    }/*ww  w  .  ja  v  a 2 s.co  m*/
    if (c.getWidth() != null) {
        vaadinComponent.setWidth(c.getWidth());
    }
    if (c.isSizeUndefined() != null && c.isSizeUndefined().booleanValue()) {
        vaadinComponent.setSizeUndefined();
    }
    if (c.isSizeFull() != null && c.isSizeFull().booleanValue()) {
        vaadinComponent.setSizeFull();
    }
}

From source file:com.validation.manager.core.VaadinUtils.java

License:Apache License

/**
 * Change all {@code Locale} dependant properties of the
 * {@code com.vaadin.ui.Component}s within of the given component container
 * (typically an {@link UI} or other top level layout component). If the
 * specified {@code Locale} is the same as the current {@code Locale} of the
 * component container, this method does nothing. Otherwise it'll go thru
 * the components searching for it's component id. If it is in the resource
 * bundle, it'll set it's caption to the right translated string.
 *
 * <p>// www.j  ava  2s.  c  o  m
 * To use this method, do something like:
 * <pre>
 * public class MyUI extends UI {
 *
 *     {@literal @}Override
 *     public void init(final VaadinRequest request) {
 *         // ... usual code
 *         // somewhere in the UI the user can change the "Form Locale". This code must
 *         // call myUI#setLocale(newLocale);
 *     }
 *
 *     // ...
 *
 * }
 *
 *      String key = "demo.tab.message";
 *      VerticalLayout vl = new VerticalLayout();
 *      Button b = new Button(key);
 *      vl.addComponent(b);
 *      ResourceBundle rb = ResourceBundle.getBundle(
 *              "resource.bundle",
 *              new Locale("es"));
 *      VaadinUtils.updateLocale(vl, new Locale("es"), rb);
 *
 *      It also works with components implementing Property:
 *
 *      VerticalLayout vl = new VerticalLayout();
 *      Label l = new Label(key);
 *      vl.addComponent(l);
 *      ResourceBundle rb = ResourceBundle.getBundle(
 *              "resource.bundle",
 *              new Locale("es"));
 *      VaadinUtils.updateLocale(vl, new Locale("es"), rb);
 * </pre>
 *
 * @param ui The component container for which the {@code Locale} dependent
 * component properties must be changed, never {@code null}
 * @param locale The new {@code Locale}, never {@code null}
 * @param rb The {@code ResourceBundle} for the specified {@code Locale},
 * never {@code null}
 */
public static void updateLocale(final HasComponents ui, final Locale locale, final ResourceBundle rb) {

    // locale may not be null, however the current UI Locale may be null!
    if (locale.equals(ui.getLocale())) {
        return;
    }
    final long time = System.currentTimeMillis();
    walkComponentTree(ui, (Component c) -> {
        String id = c.getId();
        String caption;
        if (c instanceof Property && ((Property) c).getValue() instanceof String) {
            caption = (String) ((Property) c).getValue();
        } else {
            caption = c.getCaption();
        }
        if (id != null && !id.trim().isEmpty()) {
            if (rb.containsKey(id)) {
                try {
                    c.setCaption(new String(rb.getString(id).getBytes("ISO-8859-1"), "UTF-8"));
                } catch (UnsupportedEncodingException ex) {
                    LOG.log(Level.SEVERE, null, ex);
                }
            }
        } else if (caption != null && !caption.trim().isEmpty()) {
            /**
             * This is a more complex scenario where the caption uses more
             * than one key for translation. Sort the keys in reverse so
             * substitutions are correct.
             */
            final SortedSet<String> ss = new TreeSet<>(Collections.reverseOrder());
            for (Enumeration<String> e = rb.getKeys(); e.hasMoreElements();) {
                try {
                    String key = e.nextElement();
                    ss.add(key);
                    caption = caption.replaceAll(key,
                            new String(rb.getString(key).getBytes("ISO-8859-1"), "UTF-8"));
                } catch (UnsupportedEncodingException ex) {
                    LOG.log(Level.SEVERE, null, ex);
                }
            }
            if (c instanceof Property) {
                ((Property) c).setValue(caption);
            } else {
                c.setCaption(caption);
            }
        }
    });
    LOG.log(Level.FINE, "Locale updated: {0} -> {1} in {2} ms.",
            new Object[] { ui.getLocale(), locale, System.currentTimeMillis() - time });
}

From source file:de.escidoc.admintool.view.resource.PropertiesFieldsImpl.java

License:Open Source License

@Override
public List<Field> getAllFields() {
    final Iterator<Component> iterator = formLayout.getComponentIterator();
    while (iterator.hasNext()) {
        final Component component = iterator.next();
        if (component instanceof Field && !component.getCaption().equals("Parents")) {
            final Field field = (Field) component;
            allFields.add(field);//from   ww w .j a va2s . c o m
        }
    }
    return allFields;
}