Example usage for com.vaadin.ui AbstractField getCaption

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

Introduction

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

Prototype

@Override
    public String getCaption() 

Source Link

Usage

From source file:nz.co.senanque.vaadinsupport.I18n.I18nCaptionHelper.java

License:Apache License

private static void switchCaption(AbstractField field, MessageSourceAccessor messageSourceAccessor) {
    String newCaption = getTranslatedCaption(field.getCaption(), messageSourceAccessor);
    if (newCaption != null) {
        field.setCaption(newCaption);/*w w w.  j ava2  s.  c  o  m*/
    }
}

From source file:uk.q3c.krail.core.option.DefaultOptionPopup.java

License:Apache License

/**
 * The context is scanned for {@link OptionKey} instances.  If none are found a message is displayed saying there are no options.  A context is loaded
 * only once - the {@link OptionKey} instances are cached. The {@link DefaultOptionBinder} binds a UI Field with an {@link Option} value, combined with a {@link Converter} instance to enable conversion to and from the type needed for presentation (usually String).  <p>
 * Options are displayed in a grid of 2 columns, the first column containing a Vaadin component to display the option value and the second a button to
 * reset the value to default. The component and button are each wrapped in a FormLayout to position the caption to the left of the value<p>
 * A value change listener is attached to the Vaadin component to change the option value in response to the user changing the value ion the component.
 *
 * @param context       the context to take the options from
 * @param windowCaption the I18NKey to provide a window caption
 *//* ww w. j a  v a  2  s. c  om*/
@Override
public void popup(OptionContext context, I18NKey windowCaption) {

    // changing context, so we need to re-read the context fields
    if (context != activeContext) {
        contextKeys = contextKeys(context);
    }

    Option option = context.optionInstance();
    if (window != null) {
        window.close();
    }
    window = new Window();

    window.setCaption(windowCaption(windowCaption));

    int rows = contextKeys.size() > 0 ? contextKeys.size() : 1;
    GridLayout baseLayout = new GridLayout(2, rows);
    baseLayout.setSizeUndefined();

    if (contextKeys.isEmpty()) {
        Label label = new Label(translate.from(LabelKey.No_Options_to_Show));
        baseLayout.addComponent(label, 0, 0);
    } else {
        calculateWindowSize(window);
        int row = 0;
        for (OptionKey<?> key : contextKeys.keySet()) {
            AbstractField<?> field = fieldForKey(key);
            optionBinder.bindOption(key, field);
            setFieldMetaData(key, field);
            log.debug("option field {} value is at {}", field.getCaption(), field.getValue());
            Button defaultsButton = new Button(translate.from(LabelKey.Reset_to_Default));
            Optional<String> optionKeyName = Optional.of(((Enum) key.getKey()).name());
            defaultsButton.addClickListener((event -> {
                // reset to previous level by removing entry for user
                option.delete(key, 0);
                // reset the binding - the option value may be different
                optionBinder.bindOption(key, field);
            }));
            baseLayout.addComponent(new FormLayout(field), 0, row);
            baseLayout.addComponent(new FormLayout(defaultsButton), 1, row);
            row++;
        }
    }
    window.setClosable(true);
    //use panel to scroll
    window.setContent(new Panel(baseLayout));
    window.center();
    UI.getCurrent().addWindow(window);
    this.activeContext = context;
}

From source file:uk.q3c.krail.core.user.opt.DefaultOptionPopup.java

License:Apache License

@Override
public void popup(@Nonnull OptionContext context, I18NKey windowCaption) {

    // changing context, so we need to clear the context fields
    if (context != activeContext) {
        contextFields = null;/*from w w  w.  j a v  a  2  s .com*/
        if (window != null) {
            window.close();
        }
    }

    Option option = context.getOption();
    window = new Window();

    window.setCaption(windowCaption(windowCaption));

    Map<OptionKey, Class<?>> keys = contextKeys(context);
    GridLayout baseLayout = new GridLayout(2, keys.size());
    baseLayout.setSizeUndefined();

    if (keys.size() == 0) {

        Label label = new Label(translate.from(LabelKey.No_Options_to_Show));
        baseLayout.addComponent(label, 0, 0);
    } else {
        calculateWindowSize(window, keys.size());
        int row = 0;
        for (OptionKey key : keys.keySet()) {
            Object value = option.get(key);
            AbstractField uiField = dataTypeToUI.componentFor(value);
            uiField.setCaption(translate.from(key.getKey()));
            uiField.setDescription(translate.from(key.getDescriptionKey()));
            uiField.setId(ID.getId(Optional.of(((Enum) key.getKey()).name()), this, uiField));
            log.debug("Component id for '{}' set to: '{}'", uiField.getCaption(), uiField.getId());
            //noinspection unchecked
            uiField.setValue(value);
            uiField.addValueChangeListener(event -> {
                option.set(uiField.getValue(), key);
                context.optionValueChanged(event);
            });

            Button defaultsButton = new Button(translate.from(LabelKey.Reset_to_Default));
            defaultsButton.setId(ID.getId(Optional.of(((Enum) key.getKey()).name()), this, defaultsButton));
            defaultsButton.addClickListener((event -> {
                option.delete(0, key);
                //we create an event to represent the field which whose value will be affected by this change
                AbstractField.ValueChangeEvent changeEvent = new AbstractField.ValueChangeEvent(uiField);
                context.optionValueChanged(changeEvent);
                //update the value of the field - it may have changed
                uiField.setValue(option.get(key));
            }));
            baseLayout.addComponent(new FormLayout(uiField), 0, row);
            baseLayout.addComponent(new FormLayout(defaultsButton), 1, row);
            row++;
        }
    }
    window.setId(ID.getId(Optional.empty(), context, this, window));
    window.setClosable(true);
    window.setContent(baseLayout);
    window.center();
    UI.getCurrent().addWindow(window);
    this.activeContext = context;
}