]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Merge remote-tracking branch 'origin/master' into release/1.35.2
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 10 Sep 2019 12:40:31 +0000 (15:40 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 10 Sep 2019 12:40:31 +0000 (15:40 +0300)
Change-Id: I4046dc85e90f0eb637d997e481c9d1aabe55eae2

org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElement.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DynamicVisualisationContributionsNode.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java
org.simantics.district.network/src/org/simantics/district/network/profile/ThrottledStyleBase.java

index f0305fad2ce9ca663a10feab158abf90d2bb5b87..ffa48d36bee6c0e351ccc632fbec1a9b29f06af2 100644 (file)
@@ -182,30 +182,38 @@ public class DistrictDiagramViewer extends DiagramViewer {
 
     
     private void queueColoringObjectsChangeEvent(Map<String, DynamicColorContribution> result) {
-        if (result != null) {
+        if (result != null && !canvasContext.isDisposed()) {
             canvasContext.getDefaultHintContext().setHint(KEY_MAP_COLORING_OBJECTS, result);
             canvasContext.getEventQueue().queueEvent(new CommandEvent(canvasContext, System.currentTimeMillis(), MAP_COLORING_OBJECTS_CHANGE));
+        } else {
+            LOGGER.info("Result is either null or canvasContext is disposed", String.valueOf(result));
         }
     }
     
     private void queueColorBarOptionsChangeEvent(ColorBarOptions result) {
-        if (result != null) {
+        if (result != null && !canvasContext.isDisposed()) {
             canvasContext.getDefaultHintContext().setHint(KEY_MAP_COLOR_BAR_OPTIONS, result);
             canvasContext.getEventQueue().queueEvent(new CommandEvent(canvasContext, System.currentTimeMillis(), MAP_COLOR_BAR_OPTIONS_CHANGE));
+        } else {
+            LOGGER.info("Result is either null or canvasContext is disposed", String.valueOf(result));
         }
     }
 
     private void queueSizingObjectsChangeEvent(Map<String, DynamicSizeContribution> result) {
-        if (result != null) {
+        if (result != null && !canvasContext.isDisposed()) {
             canvasContext.getDefaultHintContext().setHint(KEY_MAP_SIZING_OBJECTS, result);
             canvasContext.getEventQueue().queueEvent(new CommandEvent(canvasContext, System.currentTimeMillis(), MAP_SIZING_OBJECTS_CHANGE));
+        } else {
+            LOGGER.info("Result is either null or canvasContext is disposed", String.valueOf(result));
         }
     }
     
     private void queueSizeBarOptionsChangeEvent(SizeBarOptions result) {
-        if (result != null) {
+        if (result != null && !canvasContext.isDisposed()) {
             canvasContext.getDefaultHintContext().setHint(KEY_MAP_SIZE_BAR_OPTIONS, result);
             canvasContext.getEventQueue().queueEvent(new CommandEvent(canvasContext, System.currentTimeMillis(), MAP_SIZE_BAR_OPTIONS_CHANGE));
+        } else {
+            LOGGER.info("Result is either null or canvasContext is disposed", String.valueOf(result));
         }
     }
     
index ef2e21fed709518ca5c7c21075018526f0474dc6..8fb105d8870f8f077b9f67407440e3c3b5bd89a7 100644 (file)
@@ -102,13 +102,17 @@ public class DistrictNetworkEdgeElement {
 
         public static final DNEdgeInternalSize INSTANCE = new DNEdgeInternalSize();
 
+        private ThreadLocal<Path2D> path = new ThreadLocal<Path2D>() {
+            protected Path2D initialValue() { return new Path2D.Double(); }
+        };
+
         @Override
         public Rectangle2D getBounds(IElement e, Rectangle2D size) {
             DistrictNetworkEdge edge = e.getHint(KEY_DN_EDGE);
             if (size == null)
                 size = new Rectangle2D.Double();
             if (edge != null)
-                size.setFrame(DistrictNetworkEdgeNode.calculatePath(edge, null, false).getBounds2D());
+                size.setFrame(DistrictNetworkEdgeNode.calculatePath(edge, path.get(), false).getBounds2D());
             else
                 LOGGER.debug("Element {} does not have edge!", e);
 
index 53d7862c854115115cb77d2e89f3da8f5a911010..7705a201e12e2bc1e97980975acf47245232387d 100644 (file)
@@ -119,25 +119,33 @@ public class DynamicVisualisationContributionsNode extends G2DNode {
                 
                 Font rulerFont = new Font("Tahoma", Font.PLAIN, DPIUtil.upscale(9));
                 g2d.setFont(rulerFont);
-                g2d.setColor(Color.BLACK);
-                
-                String str = Double.toString(max);
-                g2d.drawString(str, (int)(colorBarBoxLeft + colorBarBoxWidth - 30), (int)(colorBarBoxTop  + colorBarBoxHeight));
-                
-                str = Double.toString(min);
-                g2d.drawString(str, (int)colorBarBoxLeft + 1, (int)(colorBarBoxTop + colorBarBoxHeight));
                 
+                double interval = (max - min) / intensities.size();
                 
-                for (RGBIntensity intensity : intensities) {
+                for (int j = 0; j < intensities.size(); j++) {
+                    
+                    RGBIntensity intensity = intensities.get(j);
                     
                     g2d.setColor(new Color((float)intensity.getRed(), (float)intensity.getGreen(), (float)intensity.getBlue(), 1f));
                     Rectangle2D colorVertical = new Rectangle2D.Double(colorVerticalLeft, colorVerticalTop, colorVerticalWidth, colorVerticalHeigth);
                     g2d.fill(colorVertical);
+                    
+                    double value = min + j * interval;
+                    String str = Double.toString(value);
+                    if (str.length() > 4) {
+                        str = str.substring(0, 3);
+                    }
+                    g2d.setColor(Color.BLACK);
+                    g2d.drawString(str, (float)(colorVerticalLeft - 8), (float)(colorBarBoxTop + colorBarBoxHeight));
                     colorVerticalLeft = colorVerticalLeft + colorVerticalWidth;
                 }
                 g2d.setColor(Color.BLACK);
+                
+                String str = Double.toString(max);
+                g2d.drawString(str, (float)(colorVerticalLeft - 8), (float)(colorBarBoxTop  + colorBarBoxHeight));
+                
                 str = object.getKey() + " - " + label + " [" + unit + "]";
-                g2d.drawString(str, (int)colorBarBoxLeft + 5, (int)colorBarBoxTop + 10);
+                g2d.drawString(str, (float)colorBarBoxLeft + 5, (float)colorBarBoxTop + 10);
             }
         }
     }
@@ -223,12 +231,7 @@ public class DynamicVisualisationContributionsNode extends G2DNode {
             
             double sizeBarBoxTop = (sizeBarBoxTopInitial + (colorBarBoxHeight * i));
             i++;
-//                double backgroundBoxPaddingRight = 20;
-//                double backgroundBoxHeight = 50;
-//                double backgroundBoxWidth = 300;
-//                double backgroundBoxRight = bounds.getMaxX() - backgroundBoxPaddingRight;
-//                double backgroundBoxLeft = backgroundBoxRight - backgroundBoxWidth;
-//                double backgroundBoxTop = bounds.getMaxY();// + (initialPosition + (position * i));
+
             g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
             g2d.setColor(new Color(0.9f, 0.9f, 0.9f, 0.95f));
             
@@ -243,24 +246,33 @@ public class DynamicVisualisationContributionsNode extends G2DNode {
             
             Font rulerFont = new Font("Tahoma", Font.PLAIN, DPIUtil.upscale(9));
             g2d.setFont(rulerFont);
-            g2d.setColor(Color.BLACK);
-            
-            String str = Double.toString(max);
-            g2d.drawString(str, (int)(sizeBarBoxLeft + sizeBarBoxWidth - 30), (int)(sizeBarBoxTop + sizeBarBoxHeight));
-            
-            str = Double.toString(min);
-            g2d.drawString(str, (int)sizeBarBoxLeft + 1, (int)(sizeBarBoxTop + sizeBarBoxHeight));
-            
+
+            double interval = (max - min) / sizes.size();
             
-            g2d.setColor(new Color((float)0, (float)0, (float)0.8, 0.8f));
-            for (Double size: sizes) {
+            for (int j = 0; j < sizes.size(); j++) {
+                
+                Double size = sizes.get(j);
+                
+                g2d.setColor(new Color((float)0, (float)0, (float)0.8, 0.8f));
+                double sizedWidth = (size / 5) * sizeVerticalHeigth;
+                Rectangle2D rect = new Rectangle2D.Double(sizeVerticalLeft, (sizeVerticalTop), sizedWidth, sizeVerticalHeigth);
+                g2d.fill(rect);
                 
-                Ellipse2D ellipse = new Ellipse2D.Double(sizeVerticalLeft + sizeVerticalWidth / 2, (sizeVerticalTop), size * sizeVerticalHeigth, size * sizeVerticalHeigth);
-                g2d.fill(ellipse);
+                double value = min + j * interval;
+                String str = Double.toString(value);
+                if (str.length() > 4) {
+                    str = str.substring(0, 3);
+                }
+                g2d.setColor(Color.BLACK);
+                g2d.drawString(str, (float)(sizeVerticalLeft - 8), (float)(sizeBarBoxTop + sizeBarBoxHeight));
                 
                 sizeVerticalLeft = sizeVerticalLeft + sizeVerticalWidth;
             }
             g2d.setColor(Color.BLACK);
+            
+            String str = Double.toString(max);
+            g2d.drawString(str, (int)(sizeBarBoxLeft + sizeBarBoxWidth - 30), (int)(sizeBarBoxTop + sizeBarBoxHeight));
+            
             str = object.getKey() + " - " + label + " [" + unit + "]";
             g2d.drawString(str, (int)sizeBarBoxLeft + 5, (int)sizeBarBoxTop + 10);
         }
index 031e502963f544b057c14e71c09a277c191d3d97..8ed98fad19bcd070c0837d25be90e960851fb6c2 100644 (file)
@@ -28,7 +28,6 @@ import org.eclipse.swt.widgets.Group;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.IEditorPart;
 import org.simantics.Simantics;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
@@ -37,6 +36,7 @@ import org.simantics.db.common.NamedResource;
 import org.simantics.db.common.request.UniqueRead;
 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.ontology.DistrictNetworkResource;
@@ -56,9 +56,7 @@ import org.simantics.district.network.visualisations.model.DynamicVisualisation;
 import org.simantics.district.network.visualisations.model.SizeBarOptions;
 import org.simantics.district.network.visualisations.model.SizeBarOptions.SizeBarsLocation;
 import org.simantics.district.network.visualisations.model.SizeBarOptions.SizeBarsSize;
-import org.simantics.ui.workbench.IResourceEditorPart;
 import org.simantics.utils.datastructures.Pair;
-import org.simantics.utils.ui.workbench.WorkbenchUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -83,17 +81,35 @@ public class DynamicVisualisationsUI extends Composite {
 
     private List<Supplier<Pair<String, DynamicColorContribution>>> colorSuppliers;
 
+    private Button removeVisualisationTemplateButton;
+
+       private Button applyButton;
+
     public DynamicVisualisationsUI(Composite parent, int style) {
         super(parent, style);
-
-        defaultInitializeUI();
+//        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);
+        
+//        scrolledComposite.setContent(firstContent);
+//        scrolledComposite.setExpandHorizontal(true);
+//        scrolledComposite.setExpandVertical(true);
+//        scrolledComposite.setMinSize(firstContent.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+        
     }
 
-    private void defaultInitializeUI() {
-        GridDataFactory.fillDefaults().grab(true, true).applyTo(this);
-        GridLayoutFactory.fillDefaults().numColumns(1).margins(5, 5).applyTo(this);
+    private void defaultInitializeUI(Composite parent) {
         
-        Composite selectionComposite = new Composite(this, SWT.NONE);
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(parent);
+        GridLayoutFactory.fillDefaults().numColumns(1).margins(5, 5).applyTo(parent);
+        
+        Composite selectionComposite = new Composite(parent, SWT.NONE);
         GridDataFactory.fillDefaults().grab(true, false).applyTo(selectionComposite);
         GridLayoutFactory.fillDefaults().numColumns(2).margins(5, 5).applyTo(selectionComposite);
         
@@ -121,49 +137,77 @@ public class DynamicVisualisationsUI extends Composite {
             }
         });
         
-        Composite coloringObjectsComposite = new Composite(this, SWT.NONE);
+        Composite coloringObjectsComposite = new Composite(parent, SWT.NONE);
         GridDataFactory.fillDefaults().grab(true, false).applyTo(coloringObjectsComposite);
         GridLayoutFactory.fillDefaults().numColumns(1).applyTo(coloringObjectsComposite);
         initializeColoringObjects(coloringObjectsComposite);
         
-        Composite colorBarsComposite = new Composite(this, SWT.NONE);
+        Composite colorBarsComposite = new Composite(parent, SWT.NONE);
         GridDataFactory.fillDefaults().grab(true, false).applyTo(colorBarsComposite);
         GridLayoutFactory.fillDefaults().numColumns(1).applyTo(colorBarsComposite);
         initializeColorBars(colorBarsComposite);
         
-        Composite objectSizesComposite = new Composite(this, SWT.NONE);
+        Composite objectSizesComposite = new Composite(parent, SWT.NONE);
         GridDataFactory.fillDefaults().grab(true, false).applyTo(objectSizesComposite);
         GridLayoutFactory.fillDefaults().numColumns(1).applyTo(objectSizesComposite);
         initializeObjectSizes(objectSizesComposite);
         
-        Composite sizeBarsComposite = new Composite(this, SWT.NONE);
+        Composite sizeBarsComposite = new Composite(parent, SWT.NONE);
         GridDataFactory.fillDefaults().grab(true, false).applyTo(sizeBarsComposite);
         GridLayoutFactory.fillDefaults().numColumns(1).applyTo(sizeBarsComposite);
         initializeSizeBars(sizeBarsComposite);
         
-        Button saveVisualisationTemplateButton = new Button(this, SWT.NONE);
-        saveVisualisationTemplateButton.setText("Save");
-        saveVisualisationTemplateButton.setEnabled(visualisation == null || visualisation.getVisualisationResource() != null);
-        saveVisualisationTemplateButton.addSelectionListener(new SelectionAdapter() {
+        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.setText("Save as visualisation template");
+        saveVisualisationTemplateAsButton.addSelectionListener(new SelectionAdapter() {
             
             @Override
             public void widgetSelected(SelectionEvent e) {
-                persistVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource()));
+                showSaveVisualisationTemplateDialog(e.widget.getDisplay().getActiveShell());
             }
         });
         
-        Button saveVisualisationTemplateAsButton = new Button(this, SWT.NONE);
-        saveVisualisationTemplateAsButton.setText("Save as visualisation template");
-        saveVisualisationTemplateAsButton.addSelectionListener(new SelectionAdapter() {
+        applyButton = new Button(buttonBarsComposite, SWT.NONE);
+        applyButton.setText("Apply");
+        applyButton.setEnabled(visualisation != null);
+        applyButton.addSelectionListener(new SelectionAdapter() {
             
             @Override
             public void widgetSelected(SelectionEvent e) {
-                showSaveVisualisationTemplateDialog(e.widget.getDisplay().getActiveShell());
+               persistVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource()));
+            }
+        });
+        
+        removeVisualisationTemplateButton = new Button(buttonBarsComposite, SWT.NONE);
+        removeVisualisationTemplateButton.setText("Remove");
+        removeVisualisationTemplateButton.setEnabled(visualisation != null && visualisation.getVisualisationResource() != null);
+        removeVisualisationTemplateButton.addSelectionListener(new SelectionAdapter() {
+            
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                removeVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource()));
             }
         });
         
     }
     
+    protected void removeVisualisationTemplate(String name, Optional<Resource> of) {
+        if (of.isPresent()) {
+            Resource visualisation = of.get();
+            Simantics.getSession().asyncRequest(new WriteRequest() {
+                
+                @Override
+                public void perform(WriteGraph graph) throws DatabaseException {
+                    RemoverUtil.remove(graph, visualisation);
+                }
+            });
+        }
+    }
+
     private void showSaveVisualisationTemplateDialog(Shell shell) {
         
         InputDialog dialog = new InputDialog(shell, "Save visualisation template", "Give template a name", "", new IInputValidator() {
@@ -255,24 +299,6 @@ public class DynamicVisualisationsUI extends Composite {
                 LOGGER.error("Could not create coloring objecst", e);
             }
         }
-        {
-            Button applyButton = new Button(group, SWT.NONE);
-            applyButton.setText("Apply");
-            applyButton.addSelectionListener(new SelectionAdapter() {
-                
-                @Override
-                public void widgetSelected(SelectionEvent e) {
-                    List<Pair<String, DynamicColorContribution>> collect = colorSuppliers.stream().map(s -> s.get()).filter(Objects::nonNull).collect(Collectors.toList());
-                    Simantics.getSession().asyncRequest(new WriteRequest() {
-                        
-                        @Override
-                        public void perform(WriteGraph graph) throws DatabaseException {
-                            DistrictNetworkUtil.setColorContributions(graph, visualisation.getVisualisationResource(), collect);
-                        }
-                    });
-                }
-            });
-        }
     }
     
     private void createColoringObjectHeaderRow(Composite parent) {
@@ -422,6 +448,12 @@ public class DynamicVisualisationsUI extends Composite {
 //                    break;
 //                }
 //            }
+            usedButton.setSelection(sizeContribution.isUsed());
+            defaultButton.setSelection(sizeContribution.isUseDefault());
+            
+            minText.setEnabled(!sizeContribution.isUseDefault());
+            maxText.setEnabled(!sizeContribution.isUseDefault());
+            sizeMapCombo.setEnabled(!sizeContribution.isUseDefault());
         }
     }
 
@@ -672,7 +704,7 @@ public class DynamicVisualisationsUI extends Composite {
         Group group = new Group(parent, SWT.NONE);
         group.setText("Color Bars");
         GridDataFactory.fillDefaults().grab(true, false).applyTo(group);
-        GridLayoutFactory.fillDefaults().numColumns(2).margins(5, 5).applyTo(group);
+        GridLayoutFactory.fillDefaults().numColumns(6).margins(5, 5).applyTo(group);
         
         createColorBars(group);
     }
@@ -694,37 +726,6 @@ public class DynamicVisualisationsUI extends Composite {
         label.setText("Size");
         colorSizeCombo = new Combo(parent, SWT.READ_ONLY);
         colorSizeCombo.setItems(Stream.of(ColorBarsSize.values()).map(size -> size.toString()).toArray(String[]::new));
-        
-        Button applyButton = new Button(parent, SWT.NONE);
-        applyButton.setText("Apply");
-        
-        applyButton.addSelectionListener(new SelectionAdapter() {
-            
-            @Override
-            public void widgetSelected(SelectionEvent e) {
-                // persist changes
-                IEditorPart activeEditor = WorkbenchUtils.getActiveEditor();
-                if (activeEditor instanceof IResourceEditorPart) {
-                    
-                    String colorLocation = colorLocationCombo.getItem(colorLocationCombo.getSelectionIndex());
-                    String colorSize = colorSizeCombo.getItem(colorSizeCombo.getSelectionIndex());
-                    
-                    ColorBarOptions options = new ColorBarOptions()
-                            .showColorBars(showColorButton.getSelection())
-                            .showColorBarsTicks(colorTicksButton.getSelection())
-                            .withLocation(ColorBarsLocation.valueOf(colorLocation))
-                            .withSize(ColorBarsSize.valueOf(colorSize));
-
-                    Simantics.getSession().asyncRequest(new WriteRequest() {
-                        
-                        @Override
-                        public void perform(WriteGraph graph) throws DatabaseException {
-                            DistrictNetworkUtil.setColorBarOptions(graph, visualisation.getVisualisationResource(), options);
-                        }
-                    });
-                }
-            }
-        });
     }
 
     private void initializeObjectSizes(Composite parent) {
@@ -757,32 +758,13 @@ public class DynamicVisualisationsUI extends Composite {
         } catch (DatabaseException e) {
             LOGGER.error("Could not create object sizes", e);
         }
-        
-        {
-            Button applyButton = new Button(parent, SWT.NONE);
-            applyButton.setText("Apply");
-            applyButton.addSelectionListener(new SelectionAdapter() {
-                
-                @Override
-                public void widgetSelected(SelectionEvent e) {
-                    List<Pair<String, DynamicSizeContribution>> collect = sizeSuppliers.stream().map(s -> s.get()).filter(Objects::nonNull).collect(Collectors.toList());
-                    Simantics.getSession().asyncRequest(new WriteRequest() {
-                        
-                        @Override
-                        public void perform(WriteGraph graph) throws DatabaseException {
-                            DistrictNetworkUtil.setSizeContributions(graph, visualisation.getVisualisationResource(), collect);
-                        }
-                    });
-                }
-            });
-        }
     }
 
     private void initializeSizeBars(Composite parent) {
         Group group = new Group(parent, SWT.NONE);
         group.setText("Size Bars");
         GridDataFactory.fillDefaults().grab(true, false).applyTo(group);
-        GridLayoutFactory.fillDefaults().numColumns(2).margins(5, 5).applyTo(group);
+        GridLayoutFactory.fillDefaults().numColumns(6).margins(5, 5).applyTo(group);
         
         createSizeBars(group);
     }
@@ -803,37 +785,6 @@ public class DynamicVisualisationsUI extends Composite {
         label.setText("Size");
         sizeSizeCombo = new Combo(parent, SWT.READ_ONLY);
         sizeSizeCombo.setItems(Stream.of(SizeBarsSize.values()).map(size -> size.toString()).toArray(String[]::new));
-        
-        Button applyButton = new Button(parent, SWT.READ_ONLY);
-        applyButton.setText("Apply");
-        
-        applyButton.addSelectionListener(new SelectionAdapter() {
-            
-            @Override
-            public void widgetSelected(SelectionEvent e) {
-                // persist changes
-                IEditorPart activeEditor = WorkbenchUtils.getActiveEditor();
-                if (activeEditor instanceof IResourceEditorPart) {
-                    
-                    String sizeLocation = sizeLocationCombo.getItem(sizeLocationCombo.getSelectionIndex());
-                    String sizeSize = sizeSizeCombo.getItem(sizeSizeCombo.getSelectionIndex());
-                    
-                    SizeBarOptions options = new SizeBarOptions()
-                            .showSizeBars(showSizeButton.getSelection())
-                            .showSizeBarsTicks(sizeTicksButton.getSelection())
-                            .withLocation(SizeBarsLocation.valueOf(sizeLocation))
-                            .withSize(SizeBarsSize.valueOf(sizeSize));
-
-                    Simantics.getSession().asyncRequest(new WriteRequest() {
-                        
-                        @Override
-                        public void perform(WriteGraph graph) throws DatabaseException {
-                            DistrictNetworkUtil.setSizeBarOptions(graph, visualisation.getVisualisationResource(), options);
-                        }
-                    });
-                }
-            }
-        });
     }
 
     public void setDiagramResource(Resource diagramResource) {
@@ -924,6 +875,7 @@ public class DynamicVisualisationsUI extends Composite {
                 if (getParent().isDisposed())
                     return;
                 
+                applyButton.setEnabled(visualisation != null);
                 
                 String[] items = templateSelectionCombo.getItems();
                 for (int i = 0; i < items.length; i++) {
@@ -992,6 +944,9 @@ public class DynamicVisualisationsUI extends Composite {
                         break;
                     }
                 }
+
+                
+                removeVisualisationTemplateButton.setEnabled(visualisation != null && visualisation.getVisualisationResource() != null);
             });
         }
     }
@@ -1003,6 +958,17 @@ public class DynamicVisualisationsUI extends Composite {
             if (getParent().isDisposed())
                 return;
             templateSelectionCombo.setItems(visualisations.stream().map(NamedResource::getName).collect(Collectors.toList()).toArray(new String[visualisations.size()]));
+            
+            if (visualisation != null) {
+                String[] items = templateSelectionCombo.getItems();
+                for (int i = 0; i < items.length; i++) {
+                    if (visualisation.getName().equals(items[i])) {
+                        templateSelectionCombo.select(i);
+                        break;
+                    }
+                }
+            }
+            
         });
     }
 }
index 93af11c4fa633e73dbc8ca4e885fe2e4a45ad599..f820c9222a121537742df253be60889d7a3ee685 100644 (file)
@@ -14,7 +14,6 @@ package org.simantics.district.network.profile;
 import java.util.Optional;
 import java.util.concurrent.atomic.AtomicLong;
 
-import org.simantics.Simantics;
 import org.simantics.databoard.Bindings;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
@@ -44,23 +43,7 @@ public abstract class ThrottledStyleBase<Result> extends StyleBase<Optional<Resu
 
     @Override
     protected Read<Optional<Result>> getStyleCalculationRequest(Resource runtimeDiagram, Resource entry, Resource item) {
-        Simantics.getSession().asyncRequest(new ProfileUpdateIntervalRead(runtimeDiagram), new Listener<Long>() {
-
-            @Override
-            public void execute(Long result) {
-                interval.set(result);
-            }
-
-            @Override
-            public void exception(Throwable t) {
-                LOGGER.error("Could not listen interval from runtime diagram {}", runtimeDiagram, t);
-            }
-
-            @Override
-            public boolean isDisposed() {
-                return resultListener.isDisposed();
-            }
-        });
+        //Simantics.getSession().asyncRequest(new ProfileUpdateIntervalRead(runtimeDiagram), new ProfileUpdateIntervalListener(runtimeDiagram, entry, item)); 
         return super.getStyleCalculationRequest(runtimeDiagram, entry, item);
     }
 
@@ -115,4 +98,77 @@ public abstract class ThrottledStyleBase<Result> extends StyleBase<Optional<Resu
             return interval != null ? interval : DEFAULT_INTERVAL;
         }
     }
+    
+    private class ProfileUpdateIntervalListener implements Listener<Long> {
+
+        private Resource runtimeDiagram;
+        private Resource entry;
+        private Resource item;
+
+        public ProfileUpdateIntervalListener(Resource runtimeDiagram, Resource entry, Resource item) {
+            this.runtimeDiagram = runtimeDiagram;
+            this.entry = entry;
+            this.item = item;
+        }
+
+        @Override
+        public void execute(Long result) {
+            interval.set(result);
+        }
+
+        @Override
+        public void exception(Throwable t) {
+            LOGGER.error("Could not listen interval from runtime diagram {}", runtimeDiagram, t);
+        }
+
+        @Override
+        public boolean isDisposed() {
+            return resultListener.isDisposed();
+        }
+
+        @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = 1;
+            result = prime * result + getEnclosingInstance().hashCode();
+            result = prime * result + ((entry == null) ? 0 : entry.hashCode());
+            result = prime * result + ((item == null) ? 0 : item.hashCode());
+            result = prime * result + ((runtimeDiagram == null) ? 0 : runtimeDiagram.hashCode());
+            return result;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj)
+                return true;
+            if (obj == null)
+                return false;
+            if (getClass() != obj.getClass())
+                return false;
+            ProfileUpdateIntervalListener other = (ProfileUpdateIntervalListener) obj;
+            if (!getEnclosingInstance().equals(other.getEnclosingInstance()))
+                return false;
+            if (entry == null) {
+                if (other.entry != null)
+                    return false;
+            } else if (!entry.equals(other.entry))
+                return false;
+            if (item == null) {
+                if (other.item != null)
+                    return false;
+            } else if (!item.equals(other.item))
+                return false;
+            if (runtimeDiagram == null) {
+                if (other.runtimeDiagram != null)
+                    return false;
+            } else if (!runtimeDiagram.equals(other.runtimeDiagram))
+                return false;
+            return true;
+        }
+
+        private ThrottledStyleBase<Result> getEnclosingInstance() {
+            return ThrottledStyleBase.this;
+        }
+    }
+
 }