]> gerrit.simantics Code Review - simantics/platform.git/blob
ca4adef25a280ff77bfcbbd4d1ff92184151d194
[simantics/platform.git] /
1 package org.simantics.document.server;\r
2 \r
3 import java.util.List;\r
4 \r
5 import org.simantics.Logger;\r
6 import org.simantics.db.procedure.Listener;\r
7 \r
8 public class DocumentHistoryListener implements Listener<List<JSONObject>> {\r
9 \r
10         final private DocumentHistory history;\r
11     \r
12     private boolean disposed = false;\r
13 \r
14     DocumentHistoryListener(DocumentHistory history) {\r
15         this.history = history;\r
16     }\r
17 \r
18     @Override\r
19     public void execute(List<JSONObject> result) {\r
20         \r
21         synchronized(history) {\r
22 \r
23                         history.refresh(result);\r
24                 if(!history.hasListeners()) {\r
25                         history.removeUpdater();\r
26                         disposed = true;\r
27                 }\r
28                 \r
29         }\r
30         \r
31     }\r
32 \r
33     @Override\r
34     public void exception(Throwable t) {\r
35         Logger.defaultLogError(t);\r
36     }\r
37     \r
38     @Override\r
39     public boolean isDisposed() {\r
40         if(!disposed) {\r
41                 synchronized(history) {\r
42                         if(!history.hasListeners()) {\r
43                                 history.removeUpdater();\r
44                                 disposed = true;\r
45                         }\r
46                 }\r
47         }\r
48         return disposed;\r
49     }\r
50 \r
51 }\r