@Override public <T> T load(final ModuleItem<T> item) { // if there is nothing to load from persistence return nothing if (!item.isPersisted()) return null; final String sValue = prefService.get(prefClass(item), prefKey(item)); // if persisted value has never been set before return null if (sValue == null) return null; return convertService.convert(sValue, item.getType()); }
@Override public <T> T load(final ModuleItem<T> item) { // if there is nothing to load from persistence return nothing if (!item.isPersisted()) return null; final String sValue = prefService.get(prefClass(item), prefKey(item)); // if persisted value has never been set before return null if (sValue == null) return null; return convertService.convert(sValue, item.getType()); }
@Override public <T> void save(final ModuleItem<T> item, final T value) { if (!item.isPersisted()) return; if (Objects.equals(item.getDefaultValue(), value)) { // NB: Do not persist the value if it is the default. // This is nice if the default value might change later, // such as when iteratively developing a script. prefService.remove(prefClass(item), prefKey(item)); return; } final String sValue = value == null ? "" : convertService.convert(value, String.class); // do not persist if object cannot be converted back from a string if (!convertService.supports(sValue, item.getType())) return; prefService.put(prefClass(item), prefKey(item), sValue); }
@Override public <T> void save(final ModuleItem<T> item, final T value) { if (!item.isPersisted()) return; if (Objects.equals(item.getDefaultValue(), value)) { // NB: Do not persist the value if it is the default. // This is nice if the default value might change later, // such as when iteratively developing a script. prefService.remove(prefClass(item), prefKey(item)); return; } final String sValue = value == null ? "" : convertService.convert(value, String.class); // do not persist if object cannot be converted back from a string if (!convertService.supports(sValue, item.getType())) return; prefService.put(prefClass(item), prefKey(item), sValue); }
/** Creates a new module item with the same values as the given item. */ public DefaultMutableModuleItem(final ModuleInfo info, final ModuleItem<T> item) { super(info); name = item.getName(); type = item.getType(); genericType = item.getGenericType(); ioType = item.getIOType(); visibility = item.getVisibility(); required = item.isRequired(); persisted = item.isPersisted(); persistKey = item.getPersistKey(); initializer = item.getInitializer(); validater = item.getValidater(); callback = item.getCallback(); widgetStyle = item.getWidgetStyle(); minimumValue = item.getMinimumValue(); maximumValue = item.getMaximumValue(); softMinimum = item.getSoftMinimum(); softMaximum = item.getSoftMaximum(); stepSize = item.getStepSize(); columnCount = item.getColumnCount(); final List<T> itemChoices = item.getChoices(); if (itemChoices != null) choices.addAll(itemChoices); label = item.getLabel(); description = item.getDescription(); }
/** Creates a new module item with the same values as the given item. */ public DefaultMutableModuleItem(final ModuleInfo info, final ModuleItem<T> item) { super(info); name = item.getName(); type = item.getType(); genericType = item.getGenericType(); ioType = item.getIOType(); visibility = item.getVisibility(); required = item.isRequired(); persisted = item.isPersisted(); persistKey = item.getPersistKey(); initializer = item.getInitializer(); validater = item.getValidater(); callback = item.getCallback(); widgetStyle = item.getWidgetStyle(); minimumValue = item.getMinimumValue(); maximumValue = item.getMaximumValue(); softMinimum = item.getSoftMinimum(); softMaximum = item.getSoftMaximum(); stepSize = item.getStepSize(); columnCount = item.getColumnCount(); final List<T> itemChoices = item.getChoices(); if (itemChoices != null) choices.addAll(itemChoices); label = item.getLabel(); description = item.getDescription(); }
private void assertItem(final String name, final Class<?> type, final String label, final ItemIO ioType, final boolean required, final boolean persist, final String persistKey, final String style, final Object value, final Object min, final Object max, final Object softMin, final Object softMax, final Number stepSize, final List<?> choices, final ModuleItem<?> item) { assertEquals(name, item.getName()); assertSame(type, item.getType()); assertEquals(label, item.getLabel()); assertSame(ioType, item.getIOType()); assertEquals(required, item.isRequired()); assertEquals(persist, item.isPersisted()); assertEquals(persistKey, item.getPersistKey()); assertEquals(style, item.getWidgetStyle()); assertEquals(value, item.getDefaultValue()); assertEquals(min, item.getMinimumValue()); assertEquals(max, item.getMaximumValue()); assertEquals(softMin, item.getSoftMinimum()); assertEquals(softMax, item.getSoftMaximum()); assertEquals(stepSize, item.getStepSize()); assertEquals(choices, item.getChoices()); }