package org.simantics.district.network.ui.visualisations; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import org.eclipse.swt.widgets.Composite; import org.simantics.Simantics; import org.simantics.db.AsyncReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.procedure.adapter.AsyncListenerAdapter; import org.simantics.db.layer0.request.PossibleActiveModel; public class DynamicVisualisationsView { private DynamicVisualisationsUI ui; @PostConstruct public void postConstruct(Composite parent) { ui = new DynamicVisualisationsUI(parent); Simantics.getSession().asyncRequest(new PossibleActiveModel(Simantics.getProjectResource()), new AsyncListenerAdapter() { @Override public void execute(AsyncReadGraph graph, Resource result) { if (ui != null && !ui.getParent().isDisposed()) { ui.getParent().getDisplay().asyncExec(() -> { ui.setParentResource(result); }); } } @Override public boolean isDisposed() { return ui != null ? ui.getParent().isDisposed() : true; } }); } @PreDestroy public void dispose() { ui.getParent().dispose(); ui = null; } }