List of usage examples for com.vaadin.ui AbstractField setCaption
@Override public void setCaption(String caption)
From source file:fi.semantum.strategia.Utils.java
License:Open Source License
public static void setUserMeter(final Main main, final Base base, final Meter m) { final Database database = main.getDatabase(); final Window subwindow = new Window("Aseta mittarin arvo", new VerticalLayout()); subwindow.setModal(true);// w w w . j a v a 2 s.c om subwindow.setWidth("350px"); subwindow.setResizable(false); final VerticalLayout winLayout = (VerticalLayout) subwindow.getContent(); winLayout.setMargin(true); winLayout.setSpacing(true); String caption = m.getCaption(database); if (caption != null && !caption.isEmpty()) { final Label header = new Label(caption); header.addStyleName(ValoTheme.LABEL_LARGE); winLayout.addComponent(header); } final Indicator indicator = m.getPossibleIndicator(database); if (indicator == null) return; Datatype dt = indicator.getDatatype(database); if (!(dt instanceof EnumerationDatatype)) return; final Label l = new Label("Selite: " + indicator.getValueShortComment()); AbstractField<?> forecastField = dt.getEditor(main, base, indicator, true, new CommentCallback() { @Override public void runWithComment(String shortComment, String comment) { l.setValue("Selite: " + indicator.getValueShortComment()); } @Override public void canceled() { } }); forecastField.setWidth("100%"); forecastField.setCaption("Ennuste"); winLayout.addComponent(forecastField); AbstractField<?> currentField = dt.getEditor(main, base, indicator, false, new CommentCallback() { @Override public void runWithComment(String shortComment, String comment) { l.setValue("Selite: " + indicator.getValueShortComment()); } @Override public void canceled() { } }); currentField.setWidth("100%"); currentField.setCaption("Toteuma"); winLayout.addComponent(currentField); winLayout.addComponent(l); l.setWidth("100%"); winLayout.setComponentAlignment(l, Alignment.BOTTOM_CENTER); HorizontalLayout hl = new HorizontalLayout(); winLayout.addComponent(hl); winLayout.setComponentAlignment(hl, Alignment.BOTTOM_CENTER); Button ok = new Button("Sulje", new Button.ClickListener() { private static final long serialVersionUID = 1364802814012491490L; public void buttonClick(ClickEvent event) { main.removeWindow(subwindow); } }); Button define = new Button("Mrit", new Button.ClickListener() { private static final long serialVersionUID = 1364802814012491490L; public void buttonClick(ClickEvent event) { Meter.editMeter(main, base, m); } }); hl.addComponent(ok); hl.setComponentAlignment(ok, Alignment.BOTTOM_LEFT); hl.addComponent(define); hl.setComponentAlignment(define, Alignment.BOTTOM_LEFT); main.addWindow(subwindow); }
From source file:nz.co.senanque.vaadinsupport.HintsImpl.java
License:Apache License
public void setCommonProperties(final AbstractField ret, final MaduraPropertyWrapper property, final MessageSource messageSource) { ret.setWidth(getWidth());//from w w w . j a v a2 s . c o m ret.setReadThrough(true); ret.setPropertyDataSource(property); ret.setCaption(property.getLabel()); ret.setRequired(property.isRequired()); if (property.isRequired()) { ret.setInvalidCommitted(true); } if (property.isReadOnly()) { ret.setReadOnly(true); } ret.setEnabled(property.isEnabled()); ret.setVisible(property.isVisible()); ret.setImmediate(m_forceImmediate); ret.setLocale(LocaleContextHolder.getLocale()); MessageSourceAccessor messageSourceAccessor = new MessageSourceAccessor(messageSource); ret.setDescription( messageSourceAccessor.getMessage(property.getDescription(), null, property.getDescription())); if (property.isNumeric()) { ret.addStyleName("v-textfield-align-right"); } ret.setErrorHandler(new ComponentErrorHandler() { private static final long serialVersionUID = -1393935533100204195L; public boolean handleComponentError(ComponentErrorEvent event) { Throwable t = event.getThrowable(); while (t != null) { if (t instanceof ValidationException) { ret.setComponentError(new UserError(((ValidationException) t).getMessage())); return true; } t = t.getCause(); } return false; } }); }
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); }//from w ww . j a v a 2s. com }
From source file:nz.co.senanque.vaadinsupport.TouchkitHintsImpl.java
License:Apache License
public void setCommonProperties(final AbstractField ret, final MaduraPropertyWrapper property, final MessageSource messageSource) { ret.setWidth(getWidth());//w ww .ja v a 2 s. c o m ret.setReadThrough(true); ret.setPropertyDataSource(property); ret.setCaption(property.getLabel()); ret.setRequired(property.isRequired()); if (property.isRequired()) { ret.setInvalidCommitted(true); } ret.setReadOnly(property.isReadOnly()); ret.setEnabled(property.isEnabled()); ret.setVisible(property.isVisible()); ret.setImmediate(m_forceImmediate); ret.setLocale(LocaleContextHolder.getLocale()); MessageSourceAccessor messageSourceAccessor = new MessageSourceAccessor(messageSource); ret.setDescription( messageSourceAccessor.getMessage(property.getDescription(), null, property.getDescription())); if (property.isNumeric()) { ret.addStyleName("v-textfield-align-right"); } ret.setErrorHandler(new ComponentErrorHandler() { private static final long serialVersionUID = -1393935533100204195L; public boolean handleComponentError(ComponentErrorEvent event) { Throwable t = event.getThrowable(); while (t != null) { if (t instanceof ValidationException) { ret.setComponentError(new UserError(((ValidationException) t).getMessage())); return true; } t = t.getCause(); } return false; } }); }
From source file:org.opencms.ui.apps.scheduler.CmsJobEditView.java
License:Open Source License
/** * Binds the given component to the given bean property.<p> * * @param field the component//from w ww . j a va 2 s .c o m * @param property the bean property */ void bindField(AbstractField<?> field, String property) { m_group.bind(field, property); field.setCaption(CmsVaadinUtils.getMessageText("label." + property)); field.setDescription(CmsVaadinUtils.getMessageText("label." + property + ".help")); }
From source file:uk.q3c.krail.core.option.DefaultOptionPopup.java
License:Apache License
private void setFieldMetaData(OptionKey<?> key, AbstractField<?> uiField) { uiField.setCaption(translate.from(key.getKey())); uiField.setDescription(translate.from(key.getDescriptionKey())); // Optional<String> optionKeyName = Optional.of(((Enum) key.getKey()).name()); // uiField.setId(ID.getId(optionKeyName, this, uiField)); // log.debug("Component id for '{}' set to: '{}'", uiField.getCaption(), uiField.getId()); }
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. ja v a 2s . 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; }