Changes between Version 7 and Version 8 of mvc


Ignore:
Timestamp:
06/13/22 11:23:48 (2 years ago)
Author:
wouter
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • mvc

    v7 v8  
    2828* Selected: a model (eg in a list) just got selected
    2929
     30=== The notification mechanism
     31As mentioned the Model notifies all listeners when something in the model changes. The convention we try to stick to (but can not enforce) is that {{{IllegalStateException}}} is thrown whenever the change in the model can not be accepted. This works as follows
     32* When setValue (or equivalent functions) receive a value that is unacceptable, eg because it's out of range, an IllegalArgumentException is thrown immediately
     33* In the case of a compound object, the problem may not arise immediately but only indirectly. For instance suppose that Parsons with a name starting with "A" can not be older than 100 years. This check can not be done on the submodels containing the name or the age, but has to be done on the Person level. The Person model has to listen to changes to name and age, and this listener will throw if there is a conflict. This throw will then end up in the event notifier of the name or age model where the offending change will have to be reverted. Therefore the event notification in general is of the type ThrowingListenable and changes need to be reverted in case of conflicts. The notification mechanism generally will look like this
     34{{{
     35 public void setValue(newval)
     36  oldval=this.val1;
     37  this.val1=newval;
     38  try {
     39    check();
     40    notifyListeners();
     41  } catch (IllegalStateException e) {
     42    log(e.getMessage());
     43    this.val1=oldval;
     44    notifyListeners();
     45  }
     46}
     47}}}
     48
     49Also note that any issues are pushed into the log system. This allows the GUI implementation to show any logged issues in a proper way to the user.
     50
    3051=== Basic Models
    3152* BasicModel is a generic implementation of Model ment to store primitive objects eg String or numbers. It introduces a getValue and setValue function. There also is a check() function. The intention of the check() function is that a Model throws an exception if the value passed into setValue does not meet additional requirements.
    3253* StringModel is a BasicModel containing  a String
    3354* NumberModel is a BasicModel containing  a Number. Actually it contains a BigDecimal, which allows arbitrary precision numbers to be entered and manipulated without loss of precision or rounding.
     55* RestrictedNumberModel is a NumberModel with a minimum and maximum value.
    3456
    3557=== ListModel