]> gerrit.simantics Code Review - simantics/district.git/blob
6bdf00378fb726728b0e58e4279cbd386ec8cd8b
[simantics/district.git] /
1 package org.simantics.district.network.ui.visualisations;
2
3 import javax.annotation.PostConstruct;
4 import javax.annotation.PreDestroy;
5
6 import org.eclipse.swt.widgets.Composite;
7 import org.simantics.Simantics;
8 import org.simantics.db.AsyncReadGraph;
9 import org.simantics.db.Resource;
10 import org.simantics.db.common.procedure.adapter.AsyncListenerAdapter;
11 import org.simantics.db.layer0.request.PossibleActiveModel;
12
13 public class DynamicVisualisationsView {
14
15     private DynamicVisualisationsUI ui;
16
17     @PostConstruct
18     public void postConstruct(Composite parent) {
19         ui = new DynamicVisualisationsUI(parent, 0);
20         
21         Simantics.getSession().asyncRequest(new PossibleActiveModel(Simantics.getProjectResource()), new AsyncListenerAdapter<Resource>() {
22
23             @Override
24             public void execute(AsyncReadGraph graph, Resource result) {
25                 if (ui != null && !ui.isDisposed()) {
26                     ui.getDisplay().asyncExec(() -> {
27                         ui.setParentResource(result);
28                     });
29                 }
30             }
31
32             @Override
33             public boolean isDisposed() {
34                 return ui != null ? ui.isDisposed() : true;
35             }
36         });
37     }
38
39     @PreDestroy
40     public void dispose() {
41         ui.dispose();
42         ui = null;
43     }
44
45 }