List of usage examples for com.vaadin.ui AbstractField getValue
public V getValue();
From source file:org.escidoc.browser.ui.listeners.StartButtonListener.java
License:Open Source License
private String buildMessage(final AbstractField escidocUriField) { StringBuilder builder = new StringBuilder(); builder.append("Can not connect to: ").append(escidocUriField.getValue()); if (responseMessage != null) { builder.append(", cause: ").append(responseMessage); }//from ww w . ja va 2s. c o m String message = builder.toString(); return message; }
From source file:org.escidoc.browser.ui.listeners.StartButtonListener.java
License:Open Source License
private boolean validateConnection(final AbstractField escidocUriField) { final String strUrl = (String) escidocUriField.getValue(); URLConnection connection;// w w w. j a v a 2s . c o m try { connection = new URL(strUrl).openConnection(); connection.setConnectTimeout(FIVE_SECONDS); connection.connect(); final int responseCode = ((HttpURLConnection) connection).getResponseCode(); responseMessage = ((HttpURLConnection) connection).getResponseMessage(); return responseCode == 200; } catch (final IllegalArgumentException e) { LOG.warn("Malformed URL: " + e); return false; } catch (final MalformedURLException e) { LOG.warn("Malformed URL: " + e); return false; } catch (final IOException e) { LOG.warn("IOException: " + e); return false; } }
From source file:org.jdal.vaadin.ui.bind.FieldAccessor.java
License:Apache License
/** * {@inheritDoc}// ww w .j ava 2s.c om */ public Object getControlValue() { AbstractField<?> field = (AbstractField<?>) getControl(); return field.getValue(); }
From source file:org.opennms.features.vaadin.dashboard.config.ui.editors.CriteriaRestrictionComponent.java
License:Open Source License
/** * Returns the {@link String} representation of this restriction. * * @return the restriction/*from w ww. jav a 2 s . c om*/ */ public String getRestriction() { CriteriaRestriction criteriaRestriction = CriteriaRestriction .valueOf(String.valueOf(m_restrictionSelect.getValue())); String criteria = criteriaRestriction.name() + "("; boolean first = true; for (AbstractField<?> abstractField : m_componentList) { if (!first) { criteria += ","; } criteria += abstractField.getValue(); first = false; } criteria += ")"; return criteria; }
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 *///w w w . j ava 2 s. c o m @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. 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; }