]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java
Dynamic visualisations interval and disable support
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / visualisations / DynamicVisualisationsUI.java
index 46bea63f2a14032bff8e708aa424c44cf9025a02..c4afb80e5090be6f69b85521fbfe808cb2ceedb3 100644 (file)
@@ -119,6 +119,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);
@@ -171,6 +173,11 @@ public class DynamicVisualisationsUI {
             }
         });
         
+        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 +242,28 @@ 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(4).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);
+
     }
     
     private void initializeHideElements(Composite parent) {
@@ -410,7 +429,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 +442,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 +459,7 @@ public class DynamicVisualisationsUI {
                 }
             }
         });
+        addSelectionListener(defaultButton);
         
         variableCombo.addSelectionListener(new SelectionAdapter() {
             
@@ -461,6 +479,7 @@ public class DynamicVisualisationsUI {
                 defaultButton.setSelection(true);
             }
         });
+        addSelectionListener(variableCombo);
         
         arrowRows.put(object.getArrowObject().getName(), new ArrowObjectRow(label, usedButton, variableCombo, gainText, biasText, defaultButton));
         
@@ -498,10 +517,6 @@ public class DynamicVisualisationsUI {
         };
     }
 
-    protected void disableUpdates() {
-        
-    }
-
     protected void removeVisualisationTemplate(String name, Optional<Resource> of) {
         if (of.isPresent()) {
             Resource visualisation = of.get();
@@ -595,6 +610,16 @@ public class DynamicVisualisationsUI {
         boolean dynamicSymbolsValves = dynamicSymbolsValvesButton.getSelection();
         boolean dynamicSymbolsPumpingStations = dynamicSymbolsPumpingStationsButton.getSelection();
         
+        boolean disabled = disableUpdatesButton.getSelection();
+        Long interval;
+        try {
+            interval = Long.parseLong(intervalText.getText());
+        } catch (NumberFormatException e) {
+            // ignore
+            interval = 2000L;
+        }
+        long ii = interval;
+        
         Simantics.getSession().asyncRequest(new WriteRequest() {
             
             @Override
@@ -605,6 +630,7 @@ public class DynamicVisualisationsUI {
                 } else {
                     exist = DynamicVisualisations.createVisualisation(graph, parentResource, templateName);
                 }
+                DynamicVisualisations.setIntervalAndDisabled(graph, exist, ii, disabled);
                 DynamicVisualisations.setColorContributions(graph, exist, colorCollect);
                 DynamicVisualisations.setColorBarOptions(graph, exist, colorBarOptions);
                 DynamicVisualisations.setSizeContributions(graph, exist, sizeCollect);
@@ -866,7 +892,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 +913,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 +940,7 @@ public class DynamicVisualisationsUI {
                 }
             }
         });
+        addSelectionListener(defaultButton);
         
         variableCombo.addSelectionListener(new SelectionAdapter() {
             
@@ -948,6 +973,7 @@ public class DynamicVisualisationsUI {
                 }
             }
         });
+        addSelectionListener(variableCombo);
         
         coloringRows.put(object.getColoringObject().getName(), new ColoringObjectRow(label, usedButton, variableCombo, minText, maxText, unit, colorMapCombo, defaultButton));
 
@@ -960,26 +986,20 @@ public class DynamicVisualisationsUI {
                     String key = variableCombo.getItem(selectionIndex);
                     DynamicColorContribution cont = colorContributions.get(key);
                     if (cont != null) {
-                        String colorMap = colorMapCombo.getItem(colorMapCombo.getSelectionIndex());
-                        try {
-                            Map<String, DynamicColorMap> colorMaps = Simantics.getSession().syncRequest(new UniqueRead<Map<String, DynamicColorMap>>() {
-        
-                                @Override
-                                public Map<String, DynamicColorMap> perform(ReadGraph graph) throws DatabaseException {
-                                    return DynamicVisualisationsContributions.dynamicColorMaps(graph);
-                                }
-                            });
+                        
+                        String label = variableCombo.getItem(variableCombo.getSelectionIndex());
+                        DynamicColorContribution dcc;
+                        if (colorMapCombo.getSelectionIndex() > -1) {
+                            String colorMap = colorMapCombo.getItem(colorMapCombo.getSelectionIndex());
                             DynamicColorMap dColorMap = colorMaps.get(colorMap);
-                            String label = variableCombo.getItem(variableCombo.getSelectionIndex());
-                            
-                            DynamicColorContribution dcc = new DynamicColorContribution(label, cont.getModuleName(), cont.getAttributeName(), unit.getText(), cont.getVariableGain(), cont.getVariableBias(), dColorMap, Double.parseDouble(minText.getText()), Double.parseDouble(maxText.getText()));
-                            dcc.setUsed(usedButton.getSelection());
-                            dcc.setUseDefault(defaultButton.getSelection());
-                            
-                            return Pair.make(object.getColoringObject().getName(), dcc);
-                        } catch (DatabaseException e) {
-                            LOGGER.error("Could not get DynamicColorContribution", e);
+                            dcc = new DynamicColorContribution(label, cont.getModuleName(), cont.getAttributeName(), unit.getText(), cont.getVariableGain(), cont.getVariableBias(), dColorMap, Double.parseDouble(minText.getText()), Double.parseDouble(maxText.getText()));
+                        } else {
+                            dcc = colorContributions.get(label);
                         }
+                        dcc.setUsed(usedButton.getSelection());
+                        dcc.setUseDefault(defaultButton.getSelection());
+                        
+                        return Pair.make(object.getColoringObject().getName(), dcc);
                     }
                 }
                 return null;
@@ -1035,7 +1055,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);
         
@@ -1057,7 +1076,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
@@ -1085,6 +1103,7 @@ public class DynamicVisualisationsUI {
                 }
             }
         });
+        addSelectionListener(defaultButton);
         
         variableCombo.addSelectionListener(new SelectionAdapter() {
             
@@ -1114,6 +1133,7 @@ public class DynamicVisualisationsUI {
                 defaultButton.setSelection(true);
             }
         });
+        addSelectionListener(variableCombo);
         
         sizingRows.put(object.getSizingObject().getName(), new SizingObjectRow(label, usedButton, variableCombo, minText, maxText, unit, sizeMapCombo, defaultButton));
         
@@ -1126,26 +1146,20 @@ public class DynamicVisualisationsUI {
                     String key = variableCombo.getItem(selectionIndex);
                     DynamicSizeContribution cont = sizeContributions.get(key);
                     if (cont != null) {
-                        String sizeMap = sizeMapCombo.getItem(sizeMapCombo.getSelectionIndex());
-                        try {
-                            Map<String, DynamicSizeMap> sizeMaps = Simantics.getSession().syncRequest(new UniqueRead<Map<String, DynamicSizeMap>>() {
-        
-                                @Override
-                                public Map<String, DynamicSizeMap> perform(ReadGraph graph) throws DatabaseException {
-                                    return DynamicVisualisationsContributions.dynamicSizeMaps(graph);
-                                }
-                            });
-                            DynamicSizeMap dColorMap = sizeMaps.get(sizeMap);
-                            String label = variableCombo.getItem(variableCombo.getSelectionIndex());
-                            
-                            DynamicSizeContribution dsc = new DynamicSizeContribution(label, cont.getModuleName(), cont.getAttributeName(), unit.getText(), cont.getVariableGain(), cont.getVariableBias(), dColorMap, Double.parseDouble(minText.getText()), Double.parseDouble(maxText.getText()));
-                            dsc.setUsed(usedButton.getSelection());
-                            dsc.setUseDefault(defaultButton.getSelection());
-                            
-                            return Pair.make(object.getSizingObject().getName(), dsc);
-                        } catch (DatabaseException e) {
-                            LOGGER.error("Could not get DynamicColorContribution", e);
+
+                        String label = variableCombo.getItem(variableCombo.getSelectionIndex());
+                        DynamicSizeContribution dsc;
+                        if (sizeMapCombo.getSelectionIndex() > -1) {
+                            String sizeMap = sizeMapCombo.getItem(sizeMapCombo.getSelectionIndex());
+                            DynamicSizeMap dSizeMap = sizeMaps.get(sizeMap);
+                            dsc = new DynamicSizeContribution(label, cont.getModuleName(), cont.getAttributeName(), unit.getText(), cont.getVariableGain(), cont.getVariableBias(), dSizeMap, Double.parseDouble(minText.getText()), Double.parseDouble(maxText.getText()));
+                        } else {
+                            dsc = sizeContributions.get(label);
                         }
+                        dsc.setUsed(usedButton.getSelection());
+                        dsc.setUseDefault(defaultButton.getSelection());
+                        
+                        return Pair.make(object.getSizingObject().getName(), dsc);
                     }
                 }
                 return null;
@@ -1409,6 +1423,9 @@ public class DynamicVisualisationsUI {
                     }
                 }
                 
+                intervalText.setText(Long.toString(visualisation.getInterval()));
+                disableUpdatesButton.setSelection(visualisation.disabled());
+                
                 Map<String, DynamicColorContribution> colorContributions = visualisation.getColorContributions();
                 for (Entry<String, DynamicColorContribution> entry : colorContributions.entrySet()) {