List of usage examples for com.vaadin.ui FormLayout FormLayout
public FormLayout(Component... children)
From source file:com.wcs.wcslib.vaadin.widget.recaptcha.demo.ConfigComponent.java
License:Apache License
private Layout createLangconfLayout() throws FieldGroup.BindException { VerticalLayout langLayout = new VerticalLayout(); langField = new TextField("lang"); langLayout.addComponent(new FormLayout(langField)); final FormLayout translationsLayout = new FormLayout(); translationsLayout.setSpacing(false); useTranslations = new CheckBox("use translations below"); langLayout.addComponent(useTranslations); useTranslations.addValueChangeListener(new Property.ValueChangeListener() { @Override/*from w ww . j a v a 2 s . c o m*/ public void valueChange(Property.ValueChangeEvent event) { Boolean checked = useTranslations.getValue(); for (Component c : translationsLayout) { c.setEnabled(checked); } } }); translations = new CustomTranslationsBean(); BeanFieldGroup<CustomTranslationsBean> translationsFieldGroup = new BeanFieldGroup<CustomTranslationsBean>( CustomTranslationsBean.class); translationsFieldGroup.setItemDataSource((CustomTranslationsBean) translations); Collection<Object> propertyIds = translationsFieldGroup.getUnboundPropertyIds(); translationsFieldGroup.setBuffered(false); for (Object property : propertyIds) { Field<?> field = translationsFieldGroup.buildAndBind(property); ((TextField) field).setNullRepresentation(""); field.setCaption(field.getCaption().toLowerCase()); field.setEnabled(false); translationsLayout.addComponent(field); } langLayout.addComponent(translationsLayout); return langLayout; }
From source file:org.opencms.ui.editors.messagebundle.CmsMessageBundleEditorOptions.java
License:Open Source License
/** * Initializes the lower right component {@link #m_lowerRightComponent}, with all its components, i.e., * the "Add key" input field {@link #m_addKeyInput} and the "Add key" button. *//*from ww w . j a va2s . co m*/ private void initLowerRightComponent() { initAddKeyInput(); Component addKeyButton = createAddKeyButton(); HorizontalLayout addKeyWrapper = new HorizontalLayout(addKeyButton); addKeyWrapper.setComponentAlignment(addKeyButton, Alignment.MIDDLE_CENTER); addKeyWrapper.setHeight("100%"); addKeyWrapper.setWidth(CmsMessageBundleEditorTypes.OPTION_COLUMN_WIDTH_PX); FormLayout inputForm = new FormLayout(m_addKeyInput); inputForm.setWidth("100%"); HorizontalLayout lowerRight = new HorizontalLayout(); lowerRight.setWidth("100%"); lowerRight.addComponent(inputForm); lowerRight.addComponent(addKeyWrapper); lowerRight.setExpandRatio(inputForm, 1f); m_lowerRightComponent = lowerRight; }
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 *///from w w 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;/*ww w . ja v a2 s .c om*/ 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; }