/** * {@inheritDoc} */ @Override public Long getDefaultValue() { return fromString(defaultValue); }
/** * {@inheritDoc} */ @Override protected void setDefaultValue(Long defaultValue) { this.defaultValue = toString(defaultValue.longValue()); }
/** * {@inheritDoc} */ @Override protected void showDefaultValue() { text.setText(property.getDefaultValue()); }
@Test public void marshalConfigurationUpdate() throws JAXBException, PropertyValidationException { ConfigurationUpdate configurationUpdate = new ConfigurationUpdate(); SingleProperty<String> property1 = new StringProperty("title", "Define title", "properties.title", "Lorem ipsum", true, false); configurationUpdate.addPropertyUpdate(property1.createAndValidatePropertyUpdate("New value")); SingleProperty<Long> property2 = new LongProperty("speed", "Define speed", "properties.speed", 10L, true, true); configurationUpdate.addPropertyUpdate(property2.createAndValidatePropertyUpdate(1000L)); SingleProperty<Boolean> property3 = new BooleanProperty("boolean", "Define boolean", "properties.boolean", true, true, true); configurationUpdate.addPropertyUpdate(property3.createAndValidatePropertyUpdate(false)); JAXBContext context = JAXBContext.newInstance(ConfigurationUpdate.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(configurationUpdate, System.out); marshaller.marshal(configurationUpdate, f); Unmarshaller unmarshaller = context.createUnmarshaller(); Object object = unmarshaller.unmarshal(f); assertThat(object, is(instanceOf(ConfigurationUpdate.class))); assertThat((ConfigurationUpdate) object, is(equalTo(configurationUpdate))); }
@Test public void stringPropertyXmlSaveLoad() throws JAXBException { String value = RandomStringUtils.randomAlphabetic(20); StringProperty stringProperty = new StringProperty("name", "description", "logical-name", value, false, false); JAXBContext context = JAXBContext.newInstance(ByteProperty.class); Marshaller marshaller = context.createMarshaller(); Unmarshaller unmarshaller = context.createUnmarshaller(); marshaller.marshal(stringProperty, f); Object object = unmarshaller.unmarshal(f); assertThat(object, is(instanceOf(StringProperty.class))); StringProperty unmarsalled = (StringProperty) object; assertThat(unmarsalled.getDefaultValue(), is(value)); }
@Test public void longPropertyXmlSaveLoad() throws JAXBException { long value = new Random().nextLong(); LongProperty longProperty = new LongProperty("name", "description", "logical-name", Long.valueOf(value), false, false); JAXBContext context = JAXBContext.newInstance(ByteProperty.class); Marshaller marshaller = context.createMarshaller(); Unmarshaller unmarshaller = context.createUnmarshaller(); marshaller.marshal(longProperty, f); Object object = unmarshaller.unmarshal(f); assertThat(object, is(instanceOf(LongProperty.class))); LongProperty unmarsalled = (LongProperty) object; assertThat(unmarsalled.getDefaultValue(), is(Long.valueOf(value))); }
/** * {@inheritDoc} */ @Override public Control createControl(Composite parent) { int style = SWT.BORDER; if (property.isPassword()) { style |= SWT.PASSWORD; } text = new Text(parent, style); text.setText(property.getValue()); text.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { sendPropertyUpdateEvent(text.getText()); } }); text.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { String value = text.getText(); if (value.isEmpty() && (null == StringPropertyControl.super.propertyUpdate)) { text.setText(getLastCorrectValue()); } } }); return text; }
@Test public void bytePropertyXmlSaveLoad() throws JAXBException { long bytes = (10 * 1024 * 1024) + 2; // 10MBs + 2 bytes ByteProperty byteProperty = new ByteProperty("name", "description", "logical-name", Long.valueOf(bytes), false, false); JAXBContext context = JAXBContext.newInstance(ByteProperty.class); Marshaller marshaller = context.createMarshaller(); Unmarshaller unmarshaller = context.createUnmarshaller(); marshaller.marshal(byteProperty, f); Object object = unmarshaller.unmarshal(f); assertThat(object, is(instanceOf(ByteProperty.class))); ByteProperty unmarsalled = (ByteProperty) object; assertThat(unmarsalled.getDefaultValue(), is(Long.valueOf(bytes))); }
@Test public void percentagePropertyXmlSaveLoad() throws JAXBException { float value = new Random().nextInt(100); PercentageProperty floatProperty = new PercentageProperty("name", "description", "logical-name", Float.valueOf(value), false, false); JAXBContext context = JAXBContext.newInstance(ByteProperty.class); Marshaller marshaller = context.createMarshaller(); Unmarshaller unmarshaller = context.createUnmarshaller(); marshaller.marshal(floatProperty, f); Object object = unmarshaller.unmarshal(f); assertThat(object, is(instanceOf(PercentageProperty.class))); PercentageProperty unmarsalled = (PercentageProperty) object; assertThat(unmarsalled.getDefaultValue(), is(Float.valueOf(value))); }
/** * {@inheritDoc} */ @Override protected void showDefaultValue() { spinner.setSelection((int) (property.getDefaultValue().floatValue() * 100)); } }
/** * {@inheritDoc} */ @Override protected void showDefaultValue() { displayValue(property.getDefaultValue().longValue()); }
/** * {@inheritDoc} */ @Override protected void showDefaultValue() { button.setSelection(property.getDefaultValue().booleanValue()); updateText(); }
/** * {@inheritDoc} */ @Override protected void showDefaultValue() { text.setText(NumberFormatter.formatLong(property.getDefaultValue().longValue())); } }
/** * {@inheritDoc} */ @Override public Control createControl(Composite parent) { button = new Button(parent, SWT.TOGGLE); button.setSelection(property.getValue().booleanValue()); updateText(); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { updateText(); sendPropertyUpdateEvent(Boolean.valueOf(button.getSelection())); } }); return button; }
public Control createControl(Composite parent) { text = new Text(parent, SWT.BORDER | SWT.RIGHT); text.setText(NumberFormatter.formatLong(property.getValue())); text.addVerifyListener(new VerifyListener() { @Override
/** * {@inheritDoc} */ @Override protected Long getUsedValue() { if (null != usedValue) { return fromString(usedValue); } return null; }
/** * {@inheritDoc} */ @Override protected void setUsedValue(Long usedValue) { if (null != usedValue) { this.usedValue = toString(usedValue.longValue()); } else { this.usedValue = null; // NOPMD } }
/** * Gets {@link #updateValue}. * * @return {@link #updateValue} */ @Override public Long getUpdateValue() { return ByteProperty.fromString(updateValue); }
/** * Sets {@link #updateValue}. * * @param updateValue * New value for {@link #updateValue} */ @Override protected void setUpdateValue(Long updateValue) { if (null != updateValue) { this.updateValue = ByteProperty.toString(updateValue.longValue()); // NOPMD } } }
/** * {@inheritDoc} */ @Override public Long parseLiteral(String literal) { return fromString(literal); }