1 | from abc import ABC
|
---|
2 | from abc import abstractmethod
|
---|
3 | from typing import TypeVar, Generic, List
|
---|
4 |
|
---|
5 |
|
---|
6 | T = TypeVar('T')
|
---|
7 | class Listener(ABC,Generic[T]):
|
---|
8 | '''
|
---|
9 | Listener for changes in a {@link Listenable}.
|
---|
10 | @param <T> type of data being notified back to the caller.
|
---|
11 | '''
|
---|
12 |
|
---|
13 | @abstractmethod
|
---|
14 | def notifyChange(self, data: T):
|
---|
15 | '''
|
---|
16 | a notification call that occurs when something changed. Consult the
|
---|
17 | parent object for details about this event.
|
---|
18 |
|
---|
19 | <h1>NOTICE 1</h1> notifications run in the thread of the caller. The
|
---|
20 | caller will be blocked until this callback has been completed. It is
|
---|
21 | therfore good practice to handle callbacks quickly.
|
---|
22 |
|
---|
23 | <h1>NOTICE 2</h1> Notifications often cross a thread sarety boundary. For
|
---|
24 | example when in MVC a model (typically thread safe) calls back a panel
|
---|
25 | (not thread safe). The called side (the panel) thus must handle the
|
---|
26 | callback in a thread safe manner, e.g. using
|
---|
27 | {@link SwingUtilities#invokeLater(Runnable)}. We recommend to avoid
|
---|
28 | synchronize as this will can block indefinitely (see notice 1) which
|
---|
29 | might lead to deadlocks.
|
---|
30 |
|
---|
31 | <h1>NOTICE 3</h1>If the call to your notifyChange implementation
|
---|
32 | throws an unchecked exception, it ends up in the caller's space
|
---|
33 | where this exception can not be
|
---|
34 | properly handled because the caller does not know what the notifications
|
---|
35 | are supposed to be used for. Therefore exceptions will generally
|
---|
36 | just be logged and ignored; the caller may also un-register your
|
---|
37 | subscription in an attempt to avoid further problems.
|
---|
38 |
|
---|
39 | <h1>NOTICE 3</h1>If the call to your notifyChange implementation
|
---|
40 | throws an unchecked exception, it ends up in the caller's space
|
---|
41 | where this exception can not be
|
---|
42 | properly handled because the caller does not know what the notifications
|
---|
43 | are supposed to be used for. Therefore exceptions will generally
|
---|
44 | just be logged and ignored; the caller may also un-register your
|
---|
45 | subscription in an attempt to avoid further problems.
|
---|
46 |
|
---|
47 | @param data additional data, typically the new value associated with the
|
---|
48 | event
|
---|
49 | '''
|
---|
50 |
|
---|