Author: [log in to unmask] Date: Mon Feb 2 19:04:37 2015 New Revision: 2028 Log: Add a couple of tweaks to how the base model works. Modified: java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/model/AbstractModel.java java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/model/Configuration.java java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/model/ConfigurationModel.java Modified: java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/model/AbstractModel.java ============================================================================= --- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/model/AbstractModel.java (original) +++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/model/AbstractModel.java Mon Feb 2 19:04:37 2015 @@ -54,9 +54,11 @@ // FIXME: This method is kind of a hack. Any other good way to do this? public void fireAllChanged() { + System.out.println("AbstractModel.fireAllChanged"); if (!listenersEnabled) return; - propertyLoop: for (String property : getPropertyNames()) { + propertyLoop: for (String property : getPropertyNames()) { + System.out.println(" prop = " + property); Method getMethod = null; for (Method method : getClass().getMethods()) { if (method.getName().equals("get" + property)) { @@ -68,12 +70,13 @@ Object value = null; try { value = getMethod.invoke(this, (Object[]) null); + System.out.println(" value = " + value); } catch (NullPointerException e) { // This means there is no get method for the property which is a throwable error. throw new RuntimeException("Property " + property + " is missing a get method.", e); } catch (InvocationTargetException e) { // Is the cause of the problem an illegal argument to the method? - System.out.println("cause: " + e.getCause().getClass().getCanonicalName()); + System.out.println("cause: " + e.getCause().getMessage()); if (e.getCause() instanceof IllegalArgumentException) { // For this error, assume that the key itself is missing from the configuration which is a warning. System.err.println("The key " + property + " is not set in the configuration."); @@ -82,18 +85,18 @@ throw new RuntimeException(e); } } - // Is the value non-null? Null values are actually okay. - //if (value != null) { - firePropertyChange(property, value, value); - for (PropertyChangeListener listener : propertyChangeSupport.getPropertyChangeListeners()) { - // FIXME: For some reason calling the propertyChangeSupport methods directly here doesn't work! - listener.propertyChange(new PropertyChangeEvent(this, property, value, value)); + if (value != null) { + firePropertyChange(property, value, value); + for (PropertyChangeListener listener : propertyChangeSupport.getPropertyChangeListeners()) { + // FIXME: For some reason calling the propertyChangeSupport methods directly here doesn't work! + listener.propertyChange(new PropertyChangeEvent(this, property, value, value)); + } } - //} } catch (IllegalAccessException | IllegalArgumentException e) { throw new RuntimeException(e); } - } + System.out.println(); + } } /** Modified: java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/model/Configuration.java ============================================================================= --- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/model/Configuration.java (original) +++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/model/Configuration.java Mon Feb 2 19:04:37 2015 @@ -85,9 +85,11 @@ */ String get(String key) { if (checkKey(key)) { + // Return the key value for properties that are set. return properties.getProperty(key); } else { - throw new IllegalArgumentException("The key " + key + " does not exist in this configuration with a valid value."); + // Return null for unset properties. + return null; } } Modified: java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/model/ConfigurationModel.java ============================================================================= --- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/model/ConfigurationModel.java (original) +++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/model/ConfigurationModel.java Mon Feb 2 19:04:37 2015 @@ -449,10 +449,12 @@ } public void remove(String property) { - Object oldValue = config.get(property); - if (oldValue != null) { - config.remove(property); - firePropertyChange(property, oldValue, null); + if (hasPropertyKey(property)) { + Object oldValue = config.get(property); + if (oldValue != null) { + config.remove(property); + firePropertyChange(property, oldValue, null); + } } }