From: jsimomaa Date: Sat, 16 Nov 2019 05:14:48 +0000 (+0200) Subject: Dynamic visualisations UI - check for NPE's X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F61%2F3561%2F1;p=simantics%2Fdistrict.git Dynamic visualisations UI - check for NPE's gitlab #59 Change-Id: I21d1ab3375e5c462bab07a6001a907ee8ae8841b (cherry picked from commit acf514530798b148ab9f0781ce3f78c1c09da4c4) --- diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java index bb608eaa..055b503a 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java @@ -162,15 +162,18 @@ public class DynamicVisualisationsUI { String item = templateSelectionCombo.getItem(templateSelectionCombo.getSelectionIndex()); for (NamedResource template : visualisations) { if (item.equals(template.getName())) { - Simantics.getSession().asyncRequest(new WriteRequest() { - - @Override - public void perform(WriteGraph graph) throws DatabaseException { - Resource vf = DynamicVisualisations.getVisualisationFolder(graph, parentResource); - DynamicVisualisations.setActiveVisualisation(graph, vf, template.getResource()); - } - }); - break; + if (parentResource != null) { + Resource res = parentResource; + Simantics.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Resource vf = DynamicVisualisations.getVisualisationFolder(graph, res); + DynamicVisualisations.setActiveVisualisation(graph, vf, template.getResource()); + } + }); + break; + } } } } @@ -1354,13 +1357,17 @@ public class DynamicVisualisationsUI { private void updateListening() { if (visualisationsListener != null) visualisationsListener.dispose(); - visualisationsListener = new VisualisationsListener(this); - Simantics.getSession().asyncRequest(new DynamicVisualisationsRequest(parentResource), visualisationsListener); + if (parentResource != null) { + visualisationsListener = new VisualisationsListener(this); + Simantics.getSession().asyncRequest(new DynamicVisualisationsRequest(parentResource), visualisationsListener); + } if (listener != null) listener.dispose(); - listener = new VisualisationListener(this); - Simantics.getSession().asyncRequest(new ActiveDynamicVisualisationsRequest(parentResource), listener); + if (parentResource != null) { + listener = new VisualisationListener(this); + Simantics.getSession().asyncRequest(new ActiveDynamicVisualisationsRequest(parentResource), listener); + } } private static class VisualisationsListener implements Listener> {