Example usage for com.vaadin.ui AbstractField getId

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

Introduction

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

Prototype

@Override
    public String getId() 

Source Link

Usage

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;//ww  w .ja v  a 2s  .c o m
        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;
}