]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Make defaults to work & remove apply button in dynamic visualisations 84/3284/1
authorjsimomaa <jani.simomaa@gmail.com>
Thu, 26 Sep 2019 09:57:00 +0000 (12:57 +0300)
committerjsimomaa <jani.simomaa@gmail.com>
Thu, 26 Sep 2019 09:57:00 +0000 (12:57 +0300)
gitlab #59

Change-Id: I47a836eb0d45616f475240511031fc1361d186e6

org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java
org.simantics.district.network/src/org/simantics/district/network/DistrictNetworkUtil.java
org.simantics.district.network/src/org/simantics/district/network/profile/ActiveDynamicVisualisationsRequest.java
org.simantics.district.network/src/org/simantics/district/network/profile/DNElementColorStyle.java
org.simantics.district.network/src/org/simantics/district/network/profile/DNElementSizeStyle.java
org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicVisualisation.java

index 14a8f00fa61c0646d84e60107674f78dd1a0cb26..c5be0451242f8fafccbe0fd3f4cdf1eb4626c997 100644 (file)
@@ -18,6 +18,12 @@ 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.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.widgets.Button;
@@ -28,6 +34,7 @@ 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.swt.widgets.Widget;
 import org.simantics.Simantics;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
@@ -85,8 +92,6 @@ public class DynamicVisualisationsUI extends Composite {
 
     private Button removeVisualisationTemplateButton;
 
-       private Button applyButton;
-
     public DynamicVisualisationsUI(Composite parent, int style) {
         super(parent, style);
 //        ScrolledComposite scrolledComposite = new ScrolledComposite(this, SWT.V_SCROLL);
@@ -174,22 +179,6 @@ public class DynamicVisualisationsUI extends Composite {
             }
         });
         
-        applyButton = new Button(buttonBarsComposite, SWT.NONE);
-        applyButton.setText("Apply");
-        applyButton.setEnabled(visualisation != null);
-        applyButton.addSelectionListener(new SelectionAdapter() {
-            
-            @Override
-            public void widgetSelected(SelectionEvent e) {
-               try {
-                    persistVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource()));
-                } catch (Exception e1) {
-                    LOGGER.error("Could not persist visualisation template", e1);
-                    ShowError.showError("Could not persist visualisation template", e1.getMessage(), e1);
-                }
-            }
-        });
-        
         removeVisualisationTemplateButton = new Button(buttonBarsComposite, SWT.NONE);
         removeVisualisationTemplateButton.setText("Remove");
         removeVisualisationTemplateButton.setEnabled(visualisation != null && visualisation.getVisualisationResource() != null);
@@ -474,17 +463,21 @@ public class DynamicVisualisationsUI extends Composite {
         
         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(colorContributions.keySet().toArray(new String[colorContributions.size()]));
+        addSelectionListener(variableCombo);
         
         GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(variableCombo);
         
         Text minText = new Text(parent, SWT.BORDER);
         GridDataFactory.fillDefaults().grab(true, false).hint(150, SWT.DEFAULT).align(SWT.CENTER, SWT.CENTER).applyTo(minText);
+        addSelectionListener(minText);
         
         Text maxText = new Text(parent, SWT.BORDER);
         GridDataFactory.fillDefaults().grab(true, false).hint(150, SWT.DEFAULT).align(SWT.CENTER, SWT.CENTER).applyTo(maxText);
+        addSelectionListener(maxText);
         
         Text unit = new Text(parent, SWT.READ_ONLY);
         GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(unit);
@@ -492,9 +485,11 @@ public class DynamicVisualisationsUI extends Composite {
         Combo colorMapCombo = new Combo(parent, SWT.READ_ONLY);
         GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(colorMapCombo);
         colorMapCombo.setItems(colorMaps.keySet().toArray(new String[colorMaps.keySet().size()]));
+        addSelectionListener(colorMapCombo);
         
         Button defaultButton = new Button(parent, SWT.CHECK);
         GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(defaultButton);
+        addSelectionListener(defaultButton);
         defaultButton.addSelectionListener(new SelectionAdapter() {
             
             @Override
@@ -637,17 +632,21 @@ public class DynamicVisualisationsUI extends Composite {
         
         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(sizeContributions.keySet().toArray(new String[sizeContributions.size()]));
+        addSelectionListener(variableCombo);
         
         GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(variableCombo);
         
         Text minText = new Text(parent, SWT.BORDER);
         GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(minText);
+        addSelectionListener(minText);
         
         Text maxText = new Text(parent, SWT.BORDER);
         GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(maxText);
+        addSelectionListener(maxText);
         
         Label unit = new Label(parent, SWT.NONE);
         GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(unit);
@@ -655,9 +654,11 @@ public class DynamicVisualisationsUI extends Composite {
         Combo sizeMapCombo = new Combo(parent, SWT.READ_ONLY);
         GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(sizeMapCombo);
         sizeMapCombo.setItems(sizeMaps.keySet().toArray(new String[sizeMaps.keySet().size()]));
+        addSelectionListener(sizeMapCombo);
         
         Button defaultButton = new Button(parent, SWT.CHECK);
         GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(defaultButton);
+        addSelectionListener(defaultButton);
         defaultButton.addSelectionListener(new SelectionAdapter() {
             
             @Override
@@ -766,12 +767,15 @@ public class DynamicVisualisationsUI extends Composite {
         
         showColorButton = new Button(parent, SWT.CHECK);
         showColorButton.setText("Show");
+        addSelectionListener(showColorButton);
         
         colorTicksButton = new Button(parent, SWT.CHECK);
         colorTicksButton.setText("Ticks");
+        addSelectionListener(colorTicksButton);
         
         colorGradientButton = new Button(parent, SWT.CHECK);
         colorGradientButton.setText("Gradients");
+        addSelectionListener(colorGradientButton);
         
         Label label = new Label(parent, SWT.NONE);
         label.setText("Location");
@@ -781,6 +785,7 @@ public class DynamicVisualisationsUI extends Composite {
         if (colorLocationItems.length > 0) {
             colorLocationCombo.select(0);
         }
+        addSelectionListener(colorLocationCombo);
         
         label = new Label(parent, SWT.NONE);
         label.setText("Size");
@@ -790,6 +795,7 @@ public class DynamicVisualisationsUI extends Composite {
         if (colorSizeItems.length > 0) {
             colorSizeCombo.select(0);
         }
+        addSelectionListener(colorSizeCombo);
     }
 
     private void initializeObjectSizes(Composite parent) {
@@ -837,12 +843,15 @@ public class DynamicVisualisationsUI extends Composite {
     private void createSizeBars(Composite parent) {
         showSizeButton = new Button(parent, SWT.CHECK);
         showSizeButton.setText("Show");
+        addSelectionListener(showSizeButton);
         
         sizeTicksButton = new Button(parent, SWT.CHECK);
         sizeTicksButton.setText("Ticks");
+        addSelectionListener(sizeTicksButton);
         
         sizeGradientButton = new Button(parent, SWT.CHECK);
         sizeGradientButton.setText("Gradient");
+        addSelectionListener(sizeGradientButton);
         
         Label label = new Label(parent, SWT.NONE);
         label.setText("Location");
@@ -852,6 +861,7 @@ public class DynamicVisualisationsUI extends Composite {
         if (sizeLocationItems.length > 0) {
             sizeLocationCombo.select(0);
         }
+        addSelectionListener(sizeLocationCombo);
         
         label = new Label(parent, SWT.NONE);
         label.setText("Size");
@@ -861,6 +871,64 @@ public class DynamicVisualisationsUI extends Composite {
         if (sizeSizeItems.length > 0) {
             sizeSizeCombo.select(0);
         }
+        addSelectionListener(sizeSizeCombo);
+    }
+
+    private void addSelectionListener(Widget widget) {
+        if (widget instanceof Button) {
+            ((Button) widget).addSelectionListener(new SelectionAdapter() {
+
+                @Override
+                public void widgetSelected(SelectionEvent e) {
+                    try {
+                        persistVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource()));
+                    } catch (Exception e1) {
+                        LOGGER.error("Could not persist visualisation template", e1);
+                        ShowError.showError("Could not persist visualisation template", e1.getMessage(), e1);
+                    }
+                }
+            });
+        } else if (widget instanceof Combo) {
+            ((Combo) widget).addSelectionListener(new SelectionAdapter() {
+
+                @Override
+                public void widgetSelected(SelectionEvent e) {
+                    try {
+                        persistVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource()));
+                    } catch (Exception e1) {
+                        LOGGER.error("Could not persist visualisation template", e1);
+                        ShowError.showError("Could not persist visualisation template", e1.getMessage(), e1);
+                    }
+                }
+            });
+        } else if (widget instanceof Text) {
+            ((Text) widget).addFocusListener(new FocusAdapter() {
+                
+                @Override
+                public void focusLost(FocusEvent e) {
+                    try {
+                        persistVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource()));
+                    } catch (Exception e1) {
+                        LOGGER.error("Could not persist visualisation template", e1);
+                        ShowError.showError("Could not persist visualisation template", e1.getMessage(), e1);
+                    }
+                }
+            });
+            ((Text) widget).addKeyListener(new KeyAdapter() {
+                
+                @Override
+                public void keyReleased(KeyEvent e) {
+                    if(e.keyCode == SWT.CR || e.keyCode == SWT.LF) {
+                        try {
+                            persistVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource()));
+                        } catch (Exception e1) {
+                            LOGGER.error("Could not persist visualisation template", e1);
+                            ShowError.showError("Could not persist visualisation template", e1.getMessage(), e1);
+                        }
+                    }
+                }
+            });
+        }
     }
 
     public void setParentResource(Resource parentResource) {
@@ -950,7 +1018,6 @@ public class DynamicVisualisationsUI extends Composite {
             if (getParent().isDisposed())
                 return;
             
-            applyButton.setEnabled(visualisation != null && visualisation.getVisualisationResource() != null);
             removeVisualisationTemplateButton.setEnabled(visualisation != null && visualisation.getVisualisationResource() != null);
             
             if (visualisation != null) {
index 54d3a595cc9ead222f7a0f92d3091e9252573937..e3fbac6dd325fcb8bbd4538f122d83190eb307df 100644 (file)
@@ -535,18 +535,18 @@ public class DistrictNetworkUtil {
             graph.claimLiteral(colorContribution, L0.HasName, coll.first);
             
             DynamicColorContribution contr = coll.second;
-            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionContributorName, coll.first);
-            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionLabel, contr.getLabel());
-            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionModuleName, contr.getModuleName());
-            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionModuleAttribute, contr.getAttributeName());
-            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionUnit, contr.getUnit());
-            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionVariableGain, contr.getVariableGain());
-            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionVariableBias, contr.getVariableBias());
-            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionDefaultColorMap, contr.getDefaultColorMap().getLabel());
-            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionDefaultMin, contr.getDefaultMin());
-            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionDefaultMax, contr.getDefaultMax());
-            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionUsed, contr.isUsed());
-            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionUseDefault, contr.isUseDefault());
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionContributorName, coll.first, Bindings.STRING);
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionLabel, contr.getLabel(), Bindings.STRING);
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionModuleName, contr.getModuleName(), Bindings.STRING);
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionModuleAttribute, contr.getAttributeName(), Bindings.STRING);
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionUnit, contr.getUnit(), Bindings.STRING);
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionVariableGain, contr.getVariableGain(), Bindings.DOUBLE);
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionVariableBias, contr.getVariableBias(), Bindings.DOUBLE);
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionDefaultColorMap, contr.getDefaultColorMap().getLabel(), Bindings.STRING);
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionDefaultMin, contr.getDefaultMin(), Bindings.DOUBLE);
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionDefaultMax, contr.getDefaultMax(), Bindings.DOUBLE);
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionUsed, contr.isUsed(), Bindings.BOOLEAN);
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionUseDefault, contr.isUseDefault(), Bindings.BOOLEAN);
             
             graph.claim(visualisation, DN.Diagram_Visualisations_colorContributions, colorContribution);
         }
@@ -594,18 +594,18 @@ public class DistrictNetworkUtil {
             graph.claimLiteral(sizeContribution, L0.HasName, coll.first);
             
             DynamicSizeContribution contr = coll.second;
-            graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionContributorName, coll.first);
-            graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionLabel, contr.getLabel());
-            graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionModuleName, contr.getModuleName());
-            graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionModuleAttribute, contr.getAttributeName());
-            graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionUnit, contr.getUnit());
-            graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionVariableGain, contr.getVariableGain());
-            graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionVariableBias, contr.getVariableBias());
-            graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionDefaultSizeMap, contr.getDefaultSizeMap().getLabel());
-            graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionDefaultMin, contr.getDefaultMin());
-            graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionDefaultMax, contr.getDefaultMax());
-            graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionUsed, contr.isUsed());
-            graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionUseDefault, contr.isUseDefault());
+            graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionContributorName, coll.first, Bindings.STRING);
+            graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionLabel, contr.getLabel(), Bindings.STRING);
+            graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionModuleName, contr.getModuleName(), Bindings.STRING);
+            graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionModuleAttribute, contr.getAttributeName(), Bindings.STRING);
+            graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionUnit, contr.getUnit(), Bindings.STRING);
+            graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionVariableGain, contr.getVariableGain(), Bindings.DOUBLE);
+            graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionVariableBias, contr.getVariableBias(), Bindings.DOUBLE);
+            graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionDefaultSizeMap, contr.getDefaultSizeMap().getLabel(), Bindings.STRING);
+            graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionDefaultMin, contr.getDefaultMin(), Bindings.DOUBLE);
+            graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionDefaultMax, contr.getDefaultMax(), Bindings.DOUBLE);
+            graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionUsed, contr.isUsed(), Bindings.BOOLEAN);
+            graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionUseDefault, contr.isUseDefault(), Bindings.BOOLEAN);
             
             graph.claim(visualisation, DN.Diagram_Visualisations_sizeContributions, sizeContribution);
         }
index 58499db07e91b6061691bddd38b6a489ead24ba3..f8f4b9aa34ee2e85b18309048160ec6ed881b9ca 100644 (file)
@@ -1,6 +1,8 @@
 package org.simantics.district.network.profile;
 
+import java.util.Collection;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
@@ -8,6 +10,9 @@ import org.simantics.db.common.request.ResourceRead;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.district.network.DistrictNetworkUtil;
 import org.simantics.district.network.ontology.DistrictNetworkResource;
+import org.simantics.district.network.visualisations.DynamicVisualisationsContributions;
+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.DynamicColorContribution;
 import org.simantics.district.network.visualisations.model.DynamicSizeContribution;
@@ -32,11 +37,18 @@ public class ActiveDynamicVisualisationsRequest extends ResourceRead<DynamicVisu
             Resource visualisationResource = graph.getPossibleObject(visualisationFolder, DN.Diagram_hasActiveVisualisation);
             if (visualisationResource != null) {
                 String name = graph.getRelatedValue(visualisationResource, Layer0.getInstance(graph).HasName);
+                
+                Collection<DynamicColoringObject> dynamicColoringObjects = DynamicVisualisationsContributions.dynamicColoringObjects(graph);
+                Map<String, DynamicColoringObject> defaultColoringObjects = dynamicColoringObjects.stream().collect(Collectors.toMap(dcc -> dcc.getColoringObject().getName(), dcc -> dcc));
+                
+                Collection<DynamicSizingObject> dynamicSizingObjects = DynamicVisualisationsContributions.dynamicSizingObjects(graph);
+                Map<String, DynamicSizingObject> defaultSizingObjects = dynamicSizingObjects.stream().collect(Collectors.toMap(dcc -> dcc.getSizingObject().getName(), dcc -> dcc));
+                
                 Map<String, DynamicColorContribution> colorContributions = DistrictNetworkUtil.colorContributions(graph, visualisationResource);
                 ColorBarOptions colorBarOptions = DistrictNetworkUtil.colorBarOptions(graph, visualisationResource);
                 Map<String, DynamicSizeContribution> sizeContributions = DistrictNetworkUtil.sizeContributions(graph, visualisationResource);
                 SizeBarOptions sizeBarOptions = DistrictNetworkUtil.sizeBarOptions(graph, visualisationResource);
-                DynamicVisualisation visualisation = new DynamicVisualisation(name, visualisationResource, colorContributions, colorBarOptions, sizeContributions, sizeBarOptions);
+                DynamicVisualisation visualisation = new DynamicVisualisation(name, visualisationResource, colorContributions, defaultColoringObjects, colorBarOptions, sizeContributions, defaultSizingObjects, sizeBarOptions);
                 return visualisation; 
             }
         }
index 9bcae2e5f42e907231694ca559d7b68e64184416..1e50a92ef5aba2c02b109ee8c5d6c47d8209917c 100644 (file)
@@ -11,6 +11,7 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.Variables;
 import org.simantics.district.network.ontology.DistrictNetworkResource;
+import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicColoringObject;
 import org.simantics.district.network.visualisations.model.DynamicColorContribution;
 import org.simantics.district.network.visualisations.model.DynamicColorMap;
 import org.simantics.district.network.visualisations.model.DynamicVisualisation;
@@ -20,6 +21,7 @@ import org.simantics.scenegraph.INode;
 import org.simantics.scenegraph.g2d.nodes.SingleElementNode;
 import org.simantics.scenegraph.profile.EvaluationContext;
 import org.simantics.scenegraph.profile.common.ProfileVariables;
+import org.simantics.scl.runtime.SCLContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -67,10 +69,31 @@ public class DNElementColorStyle extends ThrottledStyleBase<Color> {
                                 if (attribute != null) {
                                     Double possibleValue = attribute.getPossibleValue(graph, Bindings.DOUBLE);
                                     if (possibleValue != null) {
+                                        
+                                        double minValue;
+                                        double maxValue;
+                                        if (dcc.isUseDefault()) {
+                                            DynamicColoringObject dynamicColoringObject = dv.getDefaultColorContributions().get(mappingName);
+                                            
+                                            // This is required if ontology module needs to be compiled
+                                            Object currentGraph = SCLContext.getCurrent().get("graph");
+                                            try {
+                                                SCLContext.getCurrent().put("graph", graph);
+                                                
+                                                DynamicColorContribution ddcc = dynamicColoringObject.getColorContributions().get(dcc.getLabel());
+                                                minValue = ddcc.getDefaultMin();
+                                                maxValue = ddcc.getDefaultMax();
+                                            } finally {
+                                                SCLContext.getCurrent().put("graph", currentGraph);
+                                            }
+                                        } else {
+                                            minValue = dcc.getDefaultMin();
+                                            maxValue = dcc.getDefaultMax();
+                                        }
                                         // here we do the adjusting according to spec in #15038
                                         double adjustedValue = possibleValue.doubleValue() * dcc.getVariableGain() + dcc.getVariableBias();
                                         DynamicColorMap defaultColorMap = dcc.getDefaultColorMap();
-                                        Color color = defaultColorMap.getColor(adjustedValue, dv.getColorBarOptions().isUseGradients(), dcc.getDefaultMin(), dcc.getDefaultMax());
+                                        Color color = defaultColorMap.getColor(adjustedValue, dv.getColorBarOptions().isUseGradients(), minValue, maxValue);
                                         return color;
                                     } else {
                                         LOGGER.warn("No value for {}", attribute.getURI(graph));
index 0a454eef8f57a577a5a33f8aaee79afe37295b51..870f74578132d895dc53a850c614b2874eb9df25 100644 (file)
@@ -10,6 +10,9 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.Variables;
 import org.simantics.district.network.ontology.DistrictNetworkResource;
+import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicColoringObject;
+import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicSizingObject;
+import org.simantics.district.network.visualisations.model.DynamicColorContribution;
 import org.simantics.district.network.visualisations.model.DynamicSizeContribution;
 import org.simantics.district.network.visualisations.model.DynamicSizeMap;
 import org.simantics.district.network.visualisations.model.DynamicVisualisation;
@@ -20,6 +23,7 @@ import org.simantics.scenegraph.g2d.G2DSceneGraph;
 import org.simantics.scenegraph.g2d.nodes.SingleElementNode;
 import org.simantics.scenegraph.profile.EvaluationContext;
 import org.simantics.scenegraph.profile.common.ProfileVariables;
+import org.simantics.scl.runtime.SCLContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -68,10 +72,32 @@ public class DNElementSizeStyle extends ThrottledStyleBase<Double> {
                                 if (attribute != null) {
                                     Double possibleValue = attribute.getPossibleValue(graph, Bindings.DOUBLE);
                                     if (possibleValue != null) {
+                                        
+                                        
+                                        double minValue;
+                                        double maxValue;
+                                        if (dsc.isUseDefault()) {
+                                            DynamicSizingObject dynamicSizingObject = dv.getDefaultSizeContributions().get(mappingName);
+                                            
+                                            // This is required if ontology module needs to be compiled
+                                            Object currentGraph = SCLContext.getCurrent().get("graph");
+                                            try {
+                                                SCLContext.getCurrent().put("graph", graph);
+                                                
+                                                DynamicSizeContribution ddcc = dynamicSizingObject.getSizeContributions().get(dsc.getLabel());
+                                                minValue = ddcc.getDefaultMin();
+                                                maxValue = ddcc.getDefaultMax();
+                                            } finally {
+                                                SCLContext.getCurrent().put("graph", currentGraph);
+                                            }
+                                        } else {
+                                            minValue = dsc.getDefaultMin();
+                                            maxValue = dsc.getDefaultMax();
+                                        }
                                         // here we do the adjusting according to spec in #15038
                                         double adjustedValue = possibleValue.doubleValue() * dsc.getVariableGain() + dsc.getVariableBias();
                                         DynamicSizeMap defaultSizeMap = dsc.getDefaultSizeMap();
-                                        double size = defaultSizeMap.getSize(adjustedValue, dv.getSizeBarOptions().isUseGradients(), dsc.getDefaultMin(), dsc.getDefaultMax());
+                                        double size = defaultSizeMap.getSize(adjustedValue, dv.getSizeBarOptions().isUseGradients(), minValue, maxValue);
                                         return size;
                                     } else {
                                         LOGGER.warn("No value for {}", attribute.getURI(graph));
index 24cf9bed9a6bb2acaa97349e09eec29aaff99c4e..fa329b86e2a9b6004f3949cdc929bcc7d5ad6e8f 100644 (file)
@@ -3,6 +3,8 @@ package org.simantics.district.network.visualisations.model;
 import java.util.Map;
 
 import org.simantics.db.Resource;
+import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicColoringObject;
+import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicSizingObject;
 
 public class DynamicVisualisation {
 
@@ -10,16 +12,20 @@ public class DynamicVisualisation {
     private Resource visualisationResource;
 
     private Map<String, DynamicColorContribution> colorContributions;
+    private Map<String, DynamicColoringObject> defaultColorContributions;
     private ColorBarOptions colorBarOptions;
     private Map<String, DynamicSizeContribution> sizeContributions;
+    private Map<String, DynamicSizingObject> defaultSizeContributions;
     private SizeBarOptions sizeBarOptions;
     
-    public DynamicVisualisation(String name, Resource visualisationResource, Map<String, DynamicColorContribution> colorContributions, ColorBarOptions colorBarOptions, Map<String, DynamicSizeContribution> sizeContributions, SizeBarOptions sizeBarOptions) {
+    public DynamicVisualisation(String name, Resource visualisationResource, Map<String, DynamicColorContribution> colorContributions, Map<String, DynamicColoringObject> defaultColoringObjects, ColorBarOptions colorBarOptions, Map<String, DynamicSizeContribution> sizeContributions, Map<String, DynamicSizingObject> defaultSizingObjects, SizeBarOptions sizeBarOptions) {
         this.name = name;
         this.visualisationResource = visualisationResource;
         this.colorContributions = colorContributions;
+        this.defaultColorContributions = defaultColoringObjects;
         this.colorBarOptions = colorBarOptions;
         this.sizeContributions = sizeContributions;
+        this.defaultSizeContributions = defaultSizingObjects;
         this.sizeBarOptions = sizeBarOptions;
     }
 
@@ -34,6 +40,10 @@ public class DynamicVisualisation {
     public Map<String, DynamicColorContribution> getColorContributions() {
         return colorContributions;
     }
+    
+    public Map<String, DynamicColoringObject> getDefaultColorContributions() {
+        return defaultColorContributions;
+    }
 
     public ColorBarOptions getColorBarOptions() {
         return colorBarOptions;
@@ -42,6 +52,10 @@ public class DynamicVisualisation {
     public Map<String, DynamicSizeContribution> getSizeContributions() {
         return sizeContributions;
     }
+    
+    public Map<String, DynamicSizingObject> getDefaultSizeContributions() {
+        return defaultSizeContributions;
+    }
 
     public SizeBarOptions getSizeBarOptions() {
         return sizeBarOptions;