@Override public void cancel() { if (isInitialised()) { setChanged(false); } }
@Override public boolean isChanged() { return isInitialised() && panel.isChanged(); }
@Override public JComponent getComponent(Lookup lookup) { if (!isInitialised()) { initialize(); } return panel.getComponent(); }
/** * Create a panel that allows the user to set the parameters in the given {@link BindingContext}. Clients that want * to create their own panel representation on the given properties need to overwrite this method. * * @param context The {@link BindingContext} for the panel. * * @return A JPanel instance for the given {@link BindingContext}, never {@code null}. */ protected JPanel createPanel(BindingContext context) { Assert.state(isInitialised()); return new PreferencesPanel(null, bindingContext).getComponent(); }
@Override public void applyChanges() { if (isInitialised()) { HashSet<Preferences> set = new HashSet<>(); for (Property property : bindingContext.getPropertySet().getProperties()) { String key = property.getDescriptor().getAttribute("key").toString(); String value = property.getValueAsText(); Preferences preferences = getPreferences(property.getDescriptor()); preferences.put(key, value); set.add(preferences); SystemUtils.LOG.fine(String.format("Preferences value change: %s = %s", key, preferences.get(key, null))); } for (Preferences preferences : set) { try { preferences.flush(); } catch (BackingStoreException e) { SnapApp.getDefault().handleError("Failed to store user preferences.", e); } } setChanged(false); } }
@Override public void update() { if (isInitialised()) { for (Property property : bindingContext.getPropertySet().getProperties()) { String key = property.getDescriptor().getAttribute("key").toString(); String preferencesValue = getPreferences(property.getDescriptor()).get(key, null); if (preferencesValue != null) { try { property.setValueFromText(preferencesValue); SystemUtils.LOG.fine(String.format("Bean property value change: %s = %s", property.getName(), property.getValueAsText())); } catch (ValidationException e) { SystemUtils.LOG.severe("Failed to set bean value from preferences: " + e.getMessage()); } } } } }
@Override public boolean isValid() { if (!isInitialised()) { return false; } for (Property property : bindingContext.getPropertySet().getProperties()) { Validator validator = (Validator) property.getDescriptor().getAttribute("propertyValidator"); try { validator.validateValue(property, property.getValue()); } catch (ValidationException e) { return false; } } return true; }