]> 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 bc0551527590a5aa7793cf0a5125f4de29340fec..c4afb80e5090be6f69b85521fbfe808cb2ceedb3 100644 (file)
@@ -18,14 +18,15 @@ import org.eclipse.jface.dialogs.InputDialog;
 import org.eclipse.jface.layout.GridDataFactory;
 import org.eclipse.jface.layout.GridLayoutFactory;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.ScrolledComposite;
 import org.eclipse.swt.events.FocusAdapter;
 import org.eclipse.swt.events.FocusEvent;
 import org.eclipse.swt.events.KeyAdapter;
 import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Combo;
 import org.eclipse.swt.widgets.Composite;
@@ -45,15 +46,17 @@ import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.util.RemoverUtil;
 import org.simantics.db.procedure.Listener;
-import org.simantics.district.network.DistrictNetworkUtil;
 import org.simantics.district.network.profile.ActiveDynamicVisualisationsRequest;
 import org.simantics.district.network.profile.DynamicVisualisationsRequest;
+import org.simantics.district.network.visualisations.DynamicVisualisations;
 import org.simantics.district.network.visualisations.DynamicVisualisationsContributions;
+import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicArrowObject;
 import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicColoringObject;
 import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicSizingObject;
 import org.simantics.district.network.visualisations.model.ColorBarOptions;
 import org.simantics.district.network.visualisations.model.ColorBarOptions.ColorBarsLocation;
 import org.simantics.district.network.visualisations.model.ColorBarOptions.ColorBarsSize;
+import org.simantics.district.network.visualisations.model.DynamicArrowContribution;
 import org.simantics.district.network.visualisations.model.DynamicColorContribution;
 import org.simantics.district.network.visualisations.model.DynamicColorMap;
 import org.simantics.district.network.visualisations.model.DynamicSizeContribution;
@@ -67,7 +70,7 @@ import org.simantics.utils.ui.dialogs.ShowError;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class DynamicVisualisationsUI extends Composite {
+public class DynamicVisualisationsUI {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(DynamicVisualisationsUI.class);
 
@@ -92,23 +95,48 @@ public class DynamicVisualisationsUI extends Composite {
 
     private Button removeVisualisationTemplateButton;
 
-    public DynamicVisualisationsUI(Composite parent, int style) {
-        super(parent, style);
-//        ScrolledComposite scrolledComposite = new ScrolledComposite(this, SWT.V_SCROLL);
-//        scrolledComposite.setLayout(new GridLayout(1, false));
-//        scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-//
-//        Composite firstContent = new Composite(scrolledComposite, SWT.NONE);
-//        firstContent.setLayout(new GridLayout(1, false));
-//        firstContent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-        
-        defaultInitializeUI(this);
+    private Composite parent;
+
+    private Button disableUpdatesButton;
+
+    private List<Supplier<Pair<String, DynamicArrowContribution>>> edgeArrowSuppliers;
+
+    private Button saveVisualisationTemplateAsButton;
+
+    private Button hideEdgesButton;
+    private Button hidePointsButton;
+    private Button hideConsumersButton;
+    private Button hideProducersButton;
+    private Button hideValvesButton;
+    private Button hidePumpingStationsButton;
+
+    private Button networkBranchesStaticPropertiesButton;
+    private Button pointsStaticPropertiesButton;
+    private Button consumersStaticPropertiesButton;
+    
+    private Button dynamicSymbolsEdgesButton;
+    private Button dynamicSymbolsProducersButton;
+    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);
+        scrolledComposite.setLayout(new GridLayout(1, false));
+        scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+        Composite firstContent = new Composite(scrolledComposite, SWT.NONE);
+        firstContent.setLayout(new GridLayout(1, false));
+        firstContent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
         
-//        scrolledComposite.setContent(firstContent);
-//        scrolledComposite.setExpandHorizontal(true);
-//        scrolledComposite.setExpandVertical(true);
-//        scrolledComposite.setMinSize(firstContent.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+        defaultInitializeUI(firstContent);
         
+        scrolledComposite.setContent(firstContent);
+        scrolledComposite.setExpandHorizontal(true);
+        scrolledComposite.setExpandVertical(true);
+        scrolledComposite.setMinSize(firstContent.computeSize(SWT.DEFAULT, SWT.DEFAULT));
     }
 
     private void defaultInitializeUI(Composite parent) {
@@ -135,8 +163,8 @@ public class DynamicVisualisationsUI extends Composite {
                             
                             @Override
                             public void perform(WriteGraph graph) throws DatabaseException {
-                                Resource vf = DistrictNetworkUtil.getVisualisationFolder(graph, parentResource);
-                                DistrictNetworkUtil.setActiveVisualisation(graph, vf, template.getResource());
+                                Resource vf = DynamicVisualisations.getVisualisationFolder(graph, parentResource);
+                                DynamicVisualisations.setActiveVisualisation(graph, vf, template.getResource());
                             }
                         });
                         break;
@@ -145,6 +173,26 @@ public class DynamicVisualisationsUI extends Composite {
             }
         });
         
+        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);
+        initializeHideElements(hideElementsComposite);
+        
+        Composite staticPropertiesComposite = new Composite(parent, SWT.NONE);
+        GridDataFactory.fillDefaults().grab(true, false).applyTo(staticPropertiesComposite);
+        GridLayoutFactory.fillDefaults().numColumns(1).applyTo(staticPropertiesComposite);
+        initializeStaticProperties(staticPropertiesComposite);
+
+        Composite dynamicSymbolsComposite = new Composite(parent, SWT.NONE);
+        GridDataFactory.fillDefaults().grab(true, false).applyTo(dynamicSymbolsComposite);
+        GridLayoutFactory.fillDefaults().numColumns(1).applyTo(dynamicSymbolsComposite);
+        initializeDynamicSymbols(dynamicSymbolsComposite);
+
         Composite coloringObjectsComposite = new Composite(parent, SWT.NONE);
         GridDataFactory.fillDefaults().grab(true, false).applyTo(coloringObjectsComposite);
         GridLayoutFactory.fillDefaults().numColumns(1).applyTo(coloringObjectsComposite);
@@ -165,11 +213,16 @@ public class DynamicVisualisationsUI extends Composite {
         GridLayoutFactory.fillDefaults().numColumns(1).applyTo(sizeBarsComposite);
         initializeSizeBars(sizeBarsComposite);
         
+        Composite edgeArrowsComposite = new Composite(parent, SWT.NONE);
+        GridDataFactory.fillDefaults().grab(true, false).applyTo(edgeArrowsComposite);
+        GridLayoutFactory.fillDefaults().numColumns(1).applyTo(edgeArrowsComposite);
+        initializeEdgeArrows(edgeArrowsComposite);
+        
         Composite buttonBarsComposite = new Composite(parent, SWT.NONE);
         GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonBarsComposite);
         GridLayoutFactory.fillDefaults().numColumns(3).applyTo(buttonBarsComposite);
         
-        Button saveVisualisationTemplateAsButton = new Button(buttonBarsComposite, SWT.NONE);
+        saveVisualisationTemplateAsButton = new Button(buttonBarsComposite, SWT.NONE);
         saveVisualisationTemplateAsButton.setText("Save as visualisation template");
         saveVisualisationTemplateAsButton.addSelectionListener(new SelectionAdapter() {
             
@@ -189,9 +242,281 @@ public class DynamicVisualisationsUI extends Composite {
                 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);
+        
+        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");
+        addSelectionListener(disableUpdatesButton);
+
+    }
+    
+    private void initializeHideElements(Composite parent) {
+        Group group = new Group(parent, SWT.NONE);
+        group.setText("Hide Elements");
+        GridDataFactory.fillDefaults().grab(true, false).applyTo(group);
+        GridLayoutFactory.fillDefaults().numColumns(8).margins(5, 5).applyTo(group);
+        
+        createHideElements(group);
+    }
+    
+    private void createHideElements(Composite parent) {
+        
+        hideEdgesButton = new Button(parent, SWT.CHECK);
+        hideEdgesButton.setText("Edges");
+        addSelectionListener(hideEdgesButton);
+        
+        hidePointsButton = new Button(parent, SWT.CHECK);
+        hidePointsButton.setText("Points");
+        addSelectionListener(hidePointsButton);
+        
+        hideConsumersButton = new Button(parent, SWT.CHECK);
+        hideConsumersButton.setText("Consumers");
+        addSelectionListener(hideConsumersButton);
+        
+        hideProducersButton = new Button(parent, SWT.CHECK);
+        hideProducersButton.setText("Producers");
+        addSelectionListener(hideProducersButton);
+        
+        hideValvesButton = new Button(parent, SWT.CHECK);
+        hideValvesButton.setText("Valves");
+        addSelectionListener(hideValvesButton);
+
+        hidePumpingStationsButton = new Button(parent, SWT.CHECK);
+        hidePumpingStationsButton.setText("Pumping Stations");
+        addSelectionListener(hidePumpingStationsButton);
+    }
+
+    private void initializeStaticProperties(Composite parent) {
+        Group group = new Group(parent, SWT.NONE);
+        group.setText("Static Properties");
+        GridDataFactory.fillDefaults().grab(true, false).applyTo(group);
+        GridLayoutFactory.fillDefaults().numColumns(8).margins(5, 5).applyTo(group);
+        
+        createStaticProperties(group);
+    }
+    
+    private void createStaticProperties(Composite parent) {
+        
+        networkBranchesStaticPropertiesButton = new Button(parent, SWT.CHECK);
+        networkBranchesStaticPropertiesButton.setText("Network Branches");
+        addSelectionListener(networkBranchesStaticPropertiesButton);
+        
+        pointsStaticPropertiesButton = new Button(parent, SWT.CHECK);
+        pointsStaticPropertiesButton.setText("Points");
+        addSelectionListener(pointsStaticPropertiesButton);
+        
+        consumersStaticPropertiesButton = new Button(parent, SWT.CHECK);
+        consumersStaticPropertiesButton.setText("Consumers");
+        addSelectionListener(consumersStaticPropertiesButton);
+
+    }
+
+    private void initializeDynamicSymbols(Composite parent) {
+        Group group = new Group(parent, SWT.NONE);
+        group.setText("Dynamic Symbols");
+        GridDataFactory.fillDefaults().grab(true, false).applyTo(group);
+        GridLayoutFactory.fillDefaults().numColumns(8).margins(5, 5).applyTo(group);
         
+        createDynamicSymbols(group);
     }
     
+    private void createDynamicSymbols(Composite parent) {
+        
+        dynamicSymbolsEdgesButton = new Button(parent, SWT.CHECK);
+        dynamicSymbolsEdgesButton.setText("Shutoff Valves in Pipes");
+        addSelectionListener(dynamicSymbolsEdgesButton);
+        
+        dynamicSymbolsProducersButton = new Button(parent, SWT.CHECK);
+        dynamicSymbolsProducersButton.setText("Producers");
+        addSelectionListener(dynamicSymbolsProducersButton);
+        
+        dynamicSymbolsValvesButton = new Button(parent, SWT.CHECK);
+        dynamicSymbolsValvesButton.setText("Valves");
+        addSelectionListener(dynamicSymbolsValvesButton);
+
+        dynamicSymbolsPumpingStationsButton = new Button(parent, SWT.CHECK);
+        dynamicSymbolsPumpingStationsButton.setText("Pumping Stations");
+        addSelectionListener(dynamicSymbolsPumpingStationsButton);
+    }
+
+    private void initializeEdgeArrows(Composite parent) {
+        Group group = new Group(parent, SWT.NONE);
+        group.setText("Edge Arrows");
+        GridDataFactory.fillDefaults().grab(true, false).applyTo(group);
+        GridLayoutFactory.fillDefaults().numColumns(6).margins(5, 5).applyTo(group);
+        
+        createEdgeArrowsHeaderRow(group);
+        
+        edgeArrowSuppliers = new ArrayList<>();
+        {
+            try {
+                Collection<DynamicArrowObject> result = Simantics.getSession().syncRequest(new UniqueRead<Collection<DynamicArrowObject>>() {
+
+                    @Override
+                    public Collection<DynamicArrowObject> perform(ReadGraph graph) throws DatabaseException {
+                        return DynamicVisualisationsContributions.dynamicEdgeArrowObjects(graph);
+                    }
+                });
+                
+                for (DynamicArrowObject object : result) {
+                    edgeArrowSuppliers.add(createEdgeArrowRow(group, object));
+                }
+            } catch (DatabaseException e) {
+                LOGGER.error("Could not create coloring objecst", e);
+            }
+        }
+    }
+
+    
+    private void createEdgeArrowsHeaderRow(Composite parent) {
+
+        Label label = new Label(parent, SWT.NONE);
+        label.setText("Label");
+        GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+        
+        label = new Label(parent, SWT.NONE);
+        label.setText("Used");
+        GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+        
+        label = new Label(parent, SWT.NONE);
+        label.setText("Variable");
+        GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+        
+        label = new Label(parent, SWT.NONE);
+        label.setText("Gain");
+        GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+        
+        label = new Label(parent, SWT.NONE);
+        label.setText("Bias");
+        GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+
+        label = new Label(parent, SWT.NONE);
+        label.setText("Default");
+        GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+    }
+    
+    private Supplier<Pair<String, DynamicArrowContribution>> createEdgeArrowRow(Composite parent, DynamicArrowObject object) {
+
+        Map<String, DynamicArrowContribution> arrowContributions = object.getArrowContributions();
+        if (arrowContributions.isEmpty()) {
+            // ok, no point in showing empty combo boxes
+            return null;
+        }
+        
+        Label label = new Label(parent, SWT.NONE);
+        label.setText(object.getArrowObject().getName());
+        GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(label);
+        
+        Button usedButton = new Button(parent, SWT.CHECK);
+        GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(usedButton);
+        addSelectionListener(usedButton);
+        
+        Combo variableCombo = new Combo(parent, SWT.READ_ONLY);
+        variableCombo.setItems(arrowContributions.keySet().toArray(new String[arrowContributions.size()]));
+        
+        GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(variableCombo);
+        
+        Text gainText = new Text(parent, SWT.BORDER);
+        GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(gainText);
+        addSelectionListener(gainText);
+        
+        Text biasText = new Text(parent, SWT.BORDER);
+        GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(biasText);
+        addSelectionListener(biasText);
+        
+        Button defaultButton = new Button(parent, SWT.CHECK);
+        GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(defaultButton);
+        defaultButton.addSelectionListener(new SelectionAdapter() {
+            
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                int index = variableCombo.getSelectionIndex();
+                if (index >= 0) {
+                    String key = variableCombo.getItem(index);
+                    DynamicArrowContribution cont = arrowContributions.get(key);
+                    
+                    gainText.setText(Double.toString(cont.getDefaultGain()));
+                    gainText.setEnabled(!defaultButton.getSelection());
+                    biasText.setText(Double.toString(cont.getDefaultBias()));
+                    biasText.setEnabled(!defaultButton.getSelection());
+                    
+                }
+            }
+        });
+        addSelectionListener(defaultButton);
+        
+        variableCombo.addSelectionListener(new SelectionAdapter() {
+            
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                // handle update for others
+                String key = variableCombo.getItem(variableCombo.getSelectionIndex());
+                DynamicArrowContribution cont = arrowContributions.get(key);
+                
+                if (gainText.getText().isEmpty()) {
+                    gainText.setText(Double.toString(cont.getDefaultGain()));
+                }
+                if (biasText.getText().isEmpty()) {
+                    biasText.setText(Double.toString(cont.getDefaultBias()));
+                }
+                
+                defaultButton.setSelection(true);
+            }
+        });
+        addSelectionListener(variableCombo);
+        
+        arrowRows.put(object.getArrowObject().getName(), new ArrowObjectRow(label, usedButton, variableCombo, gainText, biasText, defaultButton));
+        
+        return new Supplier<Pair<String, DynamicArrowContribution>>() {
+
+            @Override
+            public Pair<String, DynamicArrowContribution> get() {
+                int selectionIndex = variableCombo.getSelectionIndex();
+                if (selectionIndex >= 0) {
+                    String key = variableCombo.getItem(selectionIndex);
+                    DynamicArrowContribution cont = arrowContributions.get(key);
+                    if (cont != null) {
+                        String label = variableCombo.getItem(variableCombo.getSelectionIndex());
+                        
+                        double gain = cont.getDefaultGain();
+                        String gainS = gainText.getText();
+                        if (gainS != null && !gainS.isEmpty()) {
+                            gain = Double.parseDouble(gainS);
+                        }
+                        double bias = cont.getDefaultBias();
+                        String biasS = biasText.getText();
+                        if (biasS != null && !biasS.isEmpty()) {
+                            bias = Double.parseDouble(biasText.getText());
+                        }
+                        
+                        DynamicArrowContribution dsc = new DynamicArrowContribution(label, cont.getModuleName(), cont.getAttributeName(), gain, bias);
+                        dsc.setUsed(usedButton.getSelection());
+                        dsc.setUseDefault(defaultButton.getSelection());
+                        
+                        return Pair.make(object.getArrowObject().getName(), dsc);
+                    }
+                }
+                return null;
+            }
+        };
+    }
+
     protected void removeVisualisationTemplate(String name, Optional<Resource> of) {
         if (of.isPresent()) {
             Resource visualisation = of.get();
@@ -243,7 +568,7 @@ public class DynamicVisualisationsUI extends Composite {
     
     private void persistVisualisationTemplate(String templateName, Optional<Resource> existing) throws Exception {
         
-        List<Pair<String, DynamicColorContribution>> colorCollect = colorSuppliers.stream().map(s -> s.get()).filter(Objects::nonNull).collect(Collectors.toList());
+        List<Pair<String, DynamicColorContribution>> colorCollect = colorSuppliers.stream().filter(Objects::nonNull).map(s -> s.get()).filter(Objects::nonNull).collect(Collectors.toList());
 
         String colorLocation = colorLocationCombo.getItem(colorLocationCombo.getSelectionIndex());
         String colorSize = colorSizeCombo.getItem(colorSizeCombo.getSelectionIndex());
@@ -255,18 +580,46 @@ public class DynamicVisualisationsUI extends Composite {
                 .withLocation(ColorBarsLocation.valueOf(colorLocation))
                 .withSize(ColorBarsSize.valueOf(colorSize));
         
-        List<Pair<String, DynamicSizeContribution>> sizeCollect = sizeSuppliers.stream().map(s -> s.get()).filter(Objects::nonNull).collect(Collectors.toList());
+        List<Pair<String, DynamicSizeContribution>> sizeCollect = sizeSuppliers.stream().filter(Objects::nonNull).map(s -> s.get()).filter(Objects::nonNull).collect(Collectors.toList());
         
         String sizeLocation = sizeLocationCombo.getItem(sizeLocationCombo.getSelectionIndex());
         String sizeSize = sizeSizeCombo.getItem(sizeSizeCombo.getSelectionIndex());
         
-        SizeBarOptions sizeBarOptions = new SizeBarOptions()
+        final SizeBarOptions sizeBarOptions = new SizeBarOptions()
                 .showSizeBars(showSizeButton.getSelection())
                 .showSizeBarsTicks(sizeTicksButton.getSelection())
                 .useGradients(sizeGradientButton.getSelection())
                 .withLocation(SizeBarsLocation.valueOf(sizeLocation))
                 .withSize(SizeBarsSize.valueOf(sizeSize));
         
+        List<Pair<String, DynamicArrowContribution>> edgeArrowCollect = edgeArrowSuppliers.stream().filter(Objects::nonNull).map(s -> s.get()).filter(Objects::nonNull).collect(Collectors.toList());
+        
+        boolean hideEdges = hideEdgesButton.getSelection();
+        boolean hidePoints = hidePointsButton.getSelection();
+        boolean hideConsumers = hideConsumersButton.getSelection();
+        boolean hideProducers = hideProducersButton.getSelection();
+        boolean hideValves = hideValvesButton.getSelection();
+        boolean hidePumpingStations = hidePumpingStationsButton.getSelection();
+        
+        boolean networkBranchesStaticProperties = networkBranchesStaticPropertiesButton.getSelection();
+        boolean pointsStaticProperties = pointsStaticPropertiesButton.getSelection();
+        boolean consumersStaticProperties = consumersStaticPropertiesButton.getSelection();
+        
+        boolean dynamicSymbolsEdges = dynamicSymbolsEdgesButton.getSelection();
+        boolean dynamicSymbolsProducers = dynamicSymbolsProducersButton.getSelection();
+        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
@@ -275,14 +628,35 @@ public class DynamicVisualisationsUI extends Composite {
                 if (existing.isPresent()) {
                     exist = existing.get();
                 } else {
-                    exist = DistrictNetworkUtil.createVisualisation(graph, parentResource, templateName);
+                    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);
+                DynamicVisualisations.setSizeBarOptions(graph, exist, sizeBarOptions);
+                DynamicVisualisations.setEdgeArrowContributions(graph, exist, edgeArrowCollect);
+                DynamicVisualisations.setHideElements(graph, exist,
+                        hideEdges,
+                        hidePoints,
+                        hideConsumers,
+                        hideProducers,
+                        hideValves,
+                        hidePumpingStations
+                    );
                 
-                DistrictNetworkUtil.setColorContributions(graph, exist, colorCollect);
+                DynamicVisualisations.setStaticProperties(graph, exist,
+                        networkBranchesStaticProperties,
+                        pointsStaticProperties,
+                        consumersStaticProperties
+                    );
                 
-                DistrictNetworkUtil.setColorBarOptions(graph, exist, colorBarOptions);
-                DistrictNetworkUtil.setSizeContributions(graph, exist, sizeCollect);
-                DistrictNetworkUtil.setSizeBarOptions(graph, exist, sizeBarOptions);
+                DynamicVisualisations.setDynamicSymbols(graph, exist,
+                        dynamicSymbolsEdges,
+                        dynamicSymbolsProducers,
+                        dynamicSymbolsValves,
+                        dynamicSymbolsPumpingStations
+                    );
             }
         });
     }
@@ -355,6 +729,7 @@ public class DynamicVisualisationsUI extends Composite {
 
     private Map<String, ColoringObjectRow> coloringRows = new HashMap<>();
     private Map<String, SizingObjectRow> sizingRows = new HashMap<>();
+    private Map<String, ArrowObjectRow> arrowRows = new HashMap<>();
 
     private VisualisationsListener visualisationsListener;
 
@@ -467,6 +842,43 @@ public class DynamicVisualisationsUI extends Composite {
         }
     }
 
+    private static class ArrowObjectRow {
+        
+        private final Label label;
+        private final Button usedButton;
+        private final Combo variableCombo;
+        private final Text gainText;
+        private final Text biasText;
+        private final Button defaultButton;
+        
+        public ArrowObjectRow(Label label, Button usedButton, Combo variableCombo, Text gainText, Text biasText, Button defaultButton) {
+            this.label = label;
+            this.usedButton = usedButton;
+            this.variableCombo = variableCombo;
+            this.gainText = gainText;
+            this.biasText = biasText;
+            this.defaultButton = defaultButton;
+        }
+
+        public void update(DynamicColorContribution colorContribution) {
+            String[] items = variableCombo.getItems();
+            for (int i = 0; i < items.length; i++) {
+                if (colorContribution.getLabel().equals(items[i])) {
+                    variableCombo.select(i);
+                    break;
+                }
+            }
+            gainText.setText(Double.toString(colorContribution.getDefaultMin()));
+            biasText.setText(Double.toString(colorContribution.getDefaultMax()));
+            
+            usedButton.setSelection(colorContribution.isUsed());
+            defaultButton.setSelection(colorContribution.isUseDefault());
+            
+            gainText.setEnabled(!colorContribution.isUseDefault());
+            biasText.setEnabled(!colorContribution.isUseDefault());
+        }
+    }
+
     private Supplier<Pair<String, DynamicColorContribution>> createColoringObjectRow(Composite parent, DynamicColoringObject object, Map<String, DynamicColorMap> colorMaps) {
         Label label = new Label(parent, SWT.NONE);
         label.setText(object.getColoringObject().getName());
@@ -480,7 +892,6 @@ public class DynamicVisualisationsUI extends Composite {
         
         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);
         
@@ -502,7 +913,6 @@ public class DynamicVisualisationsUI extends Composite {
         
         Button defaultButton = new Button(parent, SWT.CHECK);
         GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(defaultButton);
-        addSelectionListener(defaultButton);
         defaultButton.addSelectionListener(new SelectionAdapter() {
             
             @Override
@@ -530,6 +940,7 @@ public class DynamicVisualisationsUI extends Composite {
                 }
             }
         });
+        addSelectionListener(defaultButton);
         
         variableCombo.addSelectionListener(new SelectionAdapter() {
             
@@ -562,6 +973,7 @@ public class DynamicVisualisationsUI extends Composite {
                 }
             }
         });
+        addSelectionListener(variableCombo);
         
         coloringRows.put(object.getColoringObject().getName(), new ColoringObjectRow(label, usedButton, variableCombo, minText, maxText, unit, colorMapCombo, defaultButton));
 
@@ -574,26 +986,20 @@ public class DynamicVisualisationsUI extends Composite {
                     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;
@@ -649,7 +1055,6 @@ public class DynamicVisualisationsUI extends Composite {
         
         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);
         
@@ -671,7 +1076,6 @@ public class DynamicVisualisationsUI extends Composite {
         
         Button defaultButton = new Button(parent, SWT.CHECK);
         GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(defaultButton);
-        addSelectionListener(defaultButton);
         defaultButton.addSelectionListener(new SelectionAdapter() {
             
             @Override
@@ -699,6 +1103,7 @@ public class DynamicVisualisationsUI extends Composite {
                 }
             }
         });
+        addSelectionListener(defaultButton);
         
         variableCombo.addSelectionListener(new SelectionAdapter() {
             
@@ -728,6 +1133,7 @@ public class DynamicVisualisationsUI extends Composite {
                 defaultButton.setSelection(true);
             }
         });
+        addSelectionListener(variableCombo);
         
         sizingRows.put(object.getSizingObject().getName(), new SizingObjectRow(label, usedButton, variableCombo, minText, maxText, unit, sizeMapCombo, defaultButton));
         
@@ -740,26 +1146,20 @@ public class DynamicVisualisationsUI extends Composite {
                     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;
@@ -929,6 +1329,7 @@ public class DynamicVisualisationsUI extends Composite {
             this.parentResource = parentResource;
             updateListening();
         }
+        saveVisualisationTemplateAsButton.setEnabled(parentResource != null);
     }
 
     private void updateListening() {
@@ -966,7 +1367,7 @@ public class DynamicVisualisationsUI extends Composite {
 
         @Override
         public boolean isDisposed() {
-            return disposed || ui.isDisposed();
+            return disposed || ui.getParent().isDisposed();
         }
 
         public void dispose() {
@@ -997,7 +1398,7 @@ public class DynamicVisualisationsUI extends Composite {
 
         @Override
         public boolean isDisposed() {
-            return disposed || ui.isDisposed();
+            return disposed ||ui.getParent().isDisposed();
         }
 
         public void dispose() {
@@ -1022,6 +1423,9 @@ public class DynamicVisualisationsUI extends Composite {
                     }
                 }
                 
+                intervalText.setText(Long.toString(visualisation.getInterval()));
+                disableUpdatesButton.setSelection(visualisation.disabled());
+                
                 Map<String, DynamicColorContribution> colorContributions = visualisation.getColorContributions();
                 for (Entry<String, DynamicColorContribution> entry : colorContributions.entrySet()) {
                     
@@ -1107,4 +1511,8 @@ public class DynamicVisualisationsUI extends Composite {
             
         });
     }
+    
+    public Composite getParent() {
+        return parent;
+    }
 }