Changes between Version 33 and Version 34 of mvc


Ignore:
Timestamp:
11/20/23 10:11:17 (12 months ago)
Author:
wouter
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • mvc

    v33 v34  
    3434
    3535=== The notification mechanism
    36 As 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
    37 * When setValue (or equivalent functions) receive a value that is unacceptable, eg because it's out of range, or because some parent model has an issue with it, an IllegalArgumentException is thrown immediately
    38 * 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
     36As 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 {{{Unacceptable}}} is thrown whenever the change in the model can not be accepted. This works as follows
     37* When setValue (or equivalent functions) receive a value that is unacceptable, eg because it's out of range, or because some parent model has an issue with it, an {{{Unacceptable}}} is thrown immediately
     38* 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. Let's assume this check is done on the Person level. The Person model listens 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
    3939{{{
    40  public void setValue(newval)
     40 public void setValue(newval) {
     41  now=time.tick(); // see note below
     42  history.put(newval);
    4143  oldval=this.val1;
    4244  this.val1=newval;
    4345  try {
    44     check();
    45     notifyListeners();
    46   } catch (IllegalStateException e) {
     46    notifyListeners(new Changed(this, null));
     47  } catch (Unacceptable e) {
    4748    log(e.getMessage());
    48     this.val1=oldval;
    49     notifyListeners();
     49    time.set(time.now() - 1);
     50    notifyListeners(new Changed(this, null));
    5051  }
    5152}
    5253}}}
    5354
    54 Also 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.
     55time.tick() will increase the current time which will trigger our own time event listener.
     56
     57Any issues are pushed into the log system. This allows the GUI implementation to show any logged issues in a proper way to the user.
     58
     59The recording of the message is part of the job of the setValue function, as this is the top of the event chain.
    5560
    5661=== Basic Models