]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Dynamic visualisations UI - check for NPE's 61/3561/1
authorjsimomaa <jani.simomaa@gmail.com>
Sat, 16 Nov 2019 05:14:48 +0000 (07:14 +0200)
committerJani Simomaa <jani.simomaa@semantum.fi>
Tue, 19 Nov 2019 05:52:39 +0000 (05:52 +0000)
gitlab #59

Change-Id: I21d1ab3375e5c462bab07a6001a907ee8ae8841b
(cherry picked from commit acf514530798b148ab9f0781ce3f78c1c09da4c4)

org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java

index bb608eaad11b3bc5ce9cd07cd14eef0b46cb7b46..055b503a37c2934504e13befadebb7b5a2544c6a 100644 (file)
@@ -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<Collection<NamedResource>> {