]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java
Dynamic visualisations UI - check for NPE's
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / visualisations / DynamicVisualisationsUI.java
index 343ad420524a104708bb6d39cd2d1b8f287e80b5..055b503a37c2934504e13befadebb7b5a2544c6a 100644 (file)
@@ -98,6 +98,9 @@ public class DynamicVisualisationsUI {
     private Composite parent;
 
     private Button disableUpdatesButton;
+    private Button resetVisualisationButton;
+    private Button hoveringVertexEnabledButton;
+    private Button hoveringEdgesEnabledButton;
 
     private List<Supplier<Pair<String, DynamicArrowContribution>>> edgeArrowSuppliers;
 
@@ -119,6 +122,8 @@ public class DynamicVisualisationsUI {
     private Button dynamicSymbolsValvesButton;
     private Button dynamicSymbolsPumpingStationsButton;
 
+    private Text intervalText;
+
     public DynamicVisualisationsUI(Composite parent) {
         this.parent = parent;
         ScrolledComposite scrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
@@ -157,20 +162,28 @@ 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;
+                        }
                     }
                 }
             }
         });
         
+        Composite intervalElementsComposite = new Composite(parent, SWT.NONE);
+        GridDataFactory.fillDefaults().grab(true, false).applyTo(intervalElementsComposite);
+        GridLayoutFactory.fillDefaults().numColumns(1).applyTo(intervalElementsComposite);
+        initializeIntervalElements(intervalElementsComposite);
+        
         Composite hideElementsComposite = new Composite(parent, SWT.NONE);
         GridDataFactory.fillDefaults().grab(true, false).applyTo(hideElementsComposite);
         GridLayoutFactory.fillDefaults().numColumns(1).applyTo(hideElementsComposite);
@@ -235,16 +248,39 @@ public class DynamicVisualisationsUI {
                 removeVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource()));
             }
         });
+    }
+    
+    private void initializeIntervalElements(Composite parent) {
+        Group group = new Group(parent, SWT.NONE);
+        group.setText("Interval");
+        GridDataFactory.fillDefaults().grab(true, false).applyTo(group);
+        GridLayoutFactory.fillDefaults().numColumns(6).margins(5, 5).applyTo(group);
         
-        disableUpdatesButton = new Button(buttonBarsComposite, SWT.CHECK);
+        createIntervalElements(group);
+    }
+    
+    private void createIntervalElements(Composite parent) {
+
+        Label label = new Label(parent, SWT.NONE);
+        label.setText("Generic");
+        intervalText = new Text(parent, SWT.BORDER);
+        addSelectionListener(intervalText);
+        
+        disableUpdatesButton = new Button(parent, SWT.CHECK);
         disableUpdatesButton.setText("Disable updates");
-        disableUpdatesButton.addSelectionListener(new SelectionAdapter() {
-            
-            @Override
-            public void widgetSelected(SelectionEvent e) {
-                disableUpdates();
-            }
-        });
+        addSelectionListener(disableUpdatesButton);
+
+        resetVisualisationButton = new Button(parent, SWT.CHECK);
+        resetVisualisationButton.setText("Reset Visualisation");
+        addSelectionListener(resetVisualisationButton);
+        
+        hoveringVertexEnabledButton = new Button(parent, SWT.CHECK);
+        hoveringVertexEnabledButton.setText("Vertex Key Variables on Hover");
+        addSelectionListener(hoveringVertexEnabledButton);
+        
+        hoveringEdgesEnabledButton = new Button(parent, SWT.CHECK);
+        hoveringEdgesEnabledButton.setText("Edge Key Variables on Hover");
+        addSelectionListener(hoveringEdgesEnabledButton);
     }
     
     private void initializeHideElements(Composite parent) {
@@ -410,7 +446,6 @@ public class DynamicVisualisationsUI {
         
         Combo variableCombo = new Combo(parent, SWT.READ_ONLY);
         variableCombo.setItems(arrowContributions.keySet().toArray(new String[arrowContributions.size()]));
-        addSelectionListener(variableCombo);
         
         GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(variableCombo);
         
@@ -424,7 +459,6 @@ public class DynamicVisualisationsUI {
         
         Button defaultButton = new Button(parent, SWT.CHECK);
         GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(defaultButton);
-        addSelectionListener(defaultButton);
         defaultButton.addSelectionListener(new SelectionAdapter() {
             
             @Override
@@ -442,6 +476,7 @@ public class DynamicVisualisationsUI {
                 }
             }
         });
+        addSelectionListener(defaultButton);
         
         variableCombo.addSelectionListener(new SelectionAdapter() {
             
@@ -461,6 +496,7 @@ public class DynamicVisualisationsUI {
                 defaultButton.setSelection(true);
             }
         });
+        addSelectionListener(variableCombo);
         
         arrowRows.put(object.getArrowObject().getName(), new ArrowObjectRow(label, usedButton, variableCombo, gainText, biasText, defaultButton));
         
@@ -498,10 +534,6 @@ public class DynamicVisualisationsUI {
         };
     }
 
-    protected void disableUpdates() {
-        
-    }
-
     protected void removeVisualisationTemplate(String name, Optional<Resource> of) {
         if (of.isPresent()) {
             Resource visualisation = of.get();
@@ -595,6 +627,20 @@ public class DynamicVisualisationsUI {
         boolean dynamicSymbolsValves = dynamicSymbolsValvesButton.getSelection();
         boolean dynamicSymbolsPumpingStations = dynamicSymbolsPumpingStationsButton.getSelection();
         
+        boolean disabled = disableUpdatesButton.getSelection();
+        boolean resetVisualisation = resetVisualisationButton.getSelection();
+        Long interval;
+        try {
+            interval = Long.parseLong(intervalText.getText());
+        } catch (NumberFormatException e) {
+            // ignore
+            interval = 2000L;
+        }
+        final long finalInterval = interval;
+        
+        boolean hoverVertex = hoveringVertexEnabledButton.getSelection();
+        boolean hoverEdges = hoveringEdgesEnabledButton.getSelection();
+        
         Simantics.getSession().asyncRequest(new WriteRequest() {
             
             @Override
@@ -605,6 +651,7 @@ public class DynamicVisualisationsUI {
                 } else {
                     exist = DynamicVisualisations.createVisualisation(graph, parentResource, templateName);
                 }
+                DynamicVisualisations.setIntervalAndDisabled(graph, exist, finalInterval, disabled, resetVisualisation);
                 DynamicVisualisations.setColorContributions(graph, exist, colorCollect);
                 DynamicVisualisations.setColorBarOptions(graph, exist, colorBarOptions);
                 DynamicVisualisations.setSizeContributions(graph, exist, sizeCollect);
@@ -631,6 +678,7 @@ public class DynamicVisualisationsUI {
                         dynamicSymbolsValves,
                         dynamicSymbolsPumpingStations
                     );
+                DynamicVisualisations.setKeyVariablesHover(graph, exist, hoverVertex, hoverEdges);
             }
         });
     }
@@ -866,7 +914,6 @@ public class DynamicVisualisationsUI {
         
         Combo variableCombo = new Combo(parent, SWT.READ_ONLY);
         variableCombo.setItems(colorContributions.keySet().toArray(new String[colorContributions.size()]));
-        addSelectionListener(variableCombo);
         
         GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(variableCombo);
         
@@ -888,7 +935,6 @@ public class DynamicVisualisationsUI {
         
         Button defaultButton = new Button(parent, SWT.CHECK);
         GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(defaultButton);
-        addSelectionListener(defaultButton);
         defaultButton.addSelectionListener(new SelectionAdapter() {
             
             @Override
@@ -916,6 +962,7 @@ public class DynamicVisualisationsUI {
                 }
             }
         });
+        addSelectionListener(defaultButton);
         
         variableCombo.addSelectionListener(new SelectionAdapter() {
             
@@ -948,6 +995,7 @@ public class DynamicVisualisationsUI {
                 }
             }
         });
+        addSelectionListener(variableCombo);
         
         coloringRows.put(object.getColoringObject().getName(), new ColoringObjectRow(label, usedButton, variableCombo, minText, maxText, unit, colorMapCombo, defaultButton));
 
@@ -1029,7 +1077,6 @@ public class DynamicVisualisationsUI {
         
         Combo variableCombo = new Combo(parent, SWT.READ_ONLY);
         variableCombo.setItems(sizeContributions.keySet().toArray(new String[sizeContributions.size()]));
-        addSelectionListener(variableCombo);
         
         GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(variableCombo);
         
@@ -1051,7 +1098,6 @@ public class DynamicVisualisationsUI {
         
         Button defaultButton = new Button(parent, SWT.CHECK);
         GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(defaultButton);
-        addSelectionListener(defaultButton);
         defaultButton.addSelectionListener(new SelectionAdapter() {
             
             @Override
@@ -1079,6 +1125,7 @@ public class DynamicVisualisationsUI {
                 }
             }
         });
+        addSelectionListener(defaultButton);
         
         variableCombo.addSelectionListener(new SelectionAdapter() {
             
@@ -1108,6 +1155,7 @@ public class DynamicVisualisationsUI {
                 defaultButton.setSelection(true);
             }
         });
+        addSelectionListener(variableCombo);
         
         sizingRows.put(object.getSizingObject().getName(), new SizingObjectRow(label, usedButton, variableCombo, minText, maxText, unit, sizeMapCombo, defaultButton));
         
@@ -1309,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>> {
@@ -1397,6 +1449,12 @@ public class DynamicVisualisationsUI {
                     }
                 }
                 
+                intervalText.setText(Long.toString(visualisation.getInterval()));
+                disableUpdatesButton.setSelection(visualisation.disabledUpdates());
+                
+                hoveringVertexEnabledButton.setSelection(visualisation.isKeyVariablesVertexHover());
+                hoveringEdgesEnabledButton.setSelection(visualisation.isKeyVariablesEdgesHover());
+                
                 Map<String, DynamicColorContribution> colorContributions = visualisation.getColorContributions();
                 for (Entry<String, DynamicColorContribution> entry : colorContributions.entrySet()) {