From 333eb2ecd62d958d93a622b04c48cc68a6678404 Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Sat, 16 Nov 2019 07:14:48 +0200 Subject: [PATCH] Dynamic visualisations UI - check for NPE's gitlab #59 Change-Id: I21d1ab3375e5c462bab07a6001a907ee8ae8841b (cherry picked from commit acf514530798b148ab9f0781ce3f78c1c09da4c4) --- .../DynamicVisualisationsUI.java | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) 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> { -- 2.47.1