/** * {@inheritDoc} */ @Override protected void showDefaultValue() { button.setSelection(property.getDefaultValue().booleanValue()); updateText(); }
/** * {@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; }
@Test public void booleanPropertyUpdateXmlSaveLoad() throws PropertyValidationException, JAXBException { boolean value = new Random().nextBoolean(); BooleanProperty booleanProperty = new BooleanProperty("name", "description", "logical-name", Boolean.valueOf(!value), false, false); AbstractPropertyUpdate<Boolean> booleanPropertyUpdate = booleanProperty.createAndValidatePropertyUpdate(Boolean.valueOf(value)); JAXBContext context = JAXBContext.newInstance(BooleanPropertyUpdate.class); Marshaller marshaller = context.createMarshaller(); Unmarshaller unmarshaller = context.createUnmarshaller(); marshaller.marshal(booleanPropertyUpdate, f); Object object = unmarshaller.unmarshal(f); assertThat(object, is(instanceOf(BooleanPropertyUpdate.class))); BooleanPropertyUpdate unmarsalled = (BooleanPropertyUpdate) object; assertThat(booleanProperty.canUpdate(unmarsalled), is(true)); booleanProperty.setValue(unmarsalled.getUpdateValue()); assertThat(booleanProperty.getValue().booleanValue(), is(value)); }
@Test public void booleanPropertyXmlSaveLoad() throws JAXBException { boolean value = new Random().nextBoolean(); BooleanProperty booleanProperty = new BooleanProperty("name", "description", "logical-name", Boolean.valueOf(value), false, false); JAXBContext context = JAXBContext.newInstance(ByteProperty.class); Marshaller marshaller = context.createMarshaller(); Unmarshaller unmarshaller = context.createUnmarshaller(); marshaller.marshal(booleanProperty, f); Object object = unmarshaller.unmarshal(f); assertThat(object, is(instanceOf(BooleanProperty.class))); BooleanProperty unmarsalled = (BooleanProperty) object; assertThat(unmarsalled.getDefaultValue(), is(Boolean.valueOf(value))); }
@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))); }