]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Sync git svn branch with SVN repository r33219.
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 26 Sep 2016 10:30:21 +0000 (13:30 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 26 Sep 2016 10:30:21 +0000 (13:30 +0300)
refs #6706
refs #6704
refs #6702
refs #6701

bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/pdf/PDFExportPage.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/subsumption/SubSolver.java
bundles/org.simantics.scl.db/scl/Simantics/DB.scl
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/CellValueVisitor.java
bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/color/ColorGradientComposite.java

index ac6dd5d7cebf02910b8a9d6582eed2d1960c6346..8920decfed1b11f768f3efc259c79c7107c1b221 100644 (file)
@@ -403,7 +403,7 @@ public class PDFExportPage extends WizardPage {
             exportLocationListener = new ModifyListener() {\r
                 @Override\r
                 public void modifyText(ModifyEvent e) {\r
-                    System.out.println("export location changed by user");\r
+                    //System.out.println("export location changed by user");\r
                     exportLocationTouchedByUser = true;\r
                     validatePage();\r
                 }\r
index 70adf524b501592229f21d1f8ed201149f9f7e72..f9b5efc3bd3eb7eb3e68dc148f9f4d0496648a3f 100644 (file)
@@ -49,7 +49,7 @@ public class SubSolver {
         reduceChains();\r
         propagateUpperBounds();\r
         checkLowerBounds();\r
-        errorFromUnsolvedEquations();\r
+        //errorFromUnsolvedEquations();\r
         //System.out.println("--");\r
         //print();\r
     }\r
index ac50e3e73525dab3bd2f5afb71c59a0ab97800ed..02396067875b83abb5c4fc25e44b4841bb7e47e6 100644 (file)
@@ -455,4 +455,28 @@ lift2Write f x y = syncWrite (\_ -> f x y)
 \r
 @inline\r
 lift3Write :: (a -> b -> c -> <WriteGraph,Proc> d) -> (a -> b -> c -> <Proc> d)\r
-lift3Write f x y z = syncWrite (\_ -> f x y z)
\ No newline at end of file
+lift3Write f x y z = syncWrite (\_ -> f x y z)\r
+\r
+"""\r
+Returns a child Browsable of the specified parent that has that is the child\r
+of the specified parent with the specified name path.\r
+"""\r
+childWithPath :: Browsable a => a -> [String] -> <ReadGraph> a\r
+childWithPath parent path = \r
+    foldl (\r name -> match possibleChild r name with\r
+              Just c -> c\r
+              Nothing -> fail ("Didn't find " + name + ".") \r
+          ) \r
+          parent path\r
+\r
+"""\r
+Like `childWithPath` but returns Maybe a which will be `Nothing` if no child\r
+was found.\r
+"""\r
+possibleChildWithPath :: Browsable a => a -> [String] -> <ReadGraph> Maybe a\r
+possibleChildWithPath parent path = \r
+    foldl (\r name -> match r with\r
+              Just c -> possibleChild c name\r
+              Nothing -> Nothing \r
+          ) \r
+          (Just parent) path\r
index 385af993847c9d2b44393cdbc92386c19c0c18aa..022326248c39bacdf395e484f06de8220410893a 100644 (file)
@@ -189,7 +189,8 @@ public class CellValueVisitor implements AstValueVisitor<Object> {
                        String rightString = (rightResult.toString()).toLowerCase();\r
                        if("<".equals(astRelation.op.trim())) return leftString.compareTo(rightString) < 0;\r
                        else if(">".equals(astRelation.op.trim())) return leftString.compareTo(rightString) > 0;\r
-                       else if("=".equals(astRelation.op.trim())) return leftString.compareTo(rightString) == 0;\r
+                       // empty string should equal zero (TODO: this is a hack, the proper fix should be somewhere earlier so other cases would work as well)\r
+                       else if("=".equals(astRelation.op.trim())) return leftString.compareTo(rightString) == 0 || emptyAndZero(leftString, rightString) || emptyAndZero(rightString, leftString);\r
                        else if("<>".equals(astRelation.op.trim())) return leftString.compareTo(rightString) != 0 ;\r
                        else if("<=".equals(astRelation.op.trim())) return leftString.compareTo(rightString) <= 0 ;\r
                        else if(">=".equals(astRelation.op.trim())) return leftString.compareTo(rightString) >= 0 ;\r
@@ -207,6 +208,15 @@ public class CellValueVisitor implements AstValueVisitor<Object> {
                }\r
        }\r
        \r
+       private static boolean emptyAndZero(String a, String b) {\r
+           try {\r
+               return a.isEmpty() && (Double.parseDouble(b) == 0);\r
+           }\r
+           catch (NumberFormatException e) {\r
+               return false;\r
+           }\r
+       }\r
+       \r
        Object leftValueWithPrefix(Object result, AstValue value, String prefix, boolean forceNumber) {\r
                if(result == null) {\r
                        Object obj = value.accept(this);\r
index 3b434942f99d38a8b49af33dfff10653804ebc3c..f8a52bc70f9997d13495834eeb147699c78cd502 100644 (file)
@@ -16,6 +16,7 @@ import java.util.ArrayList;
 import java.util.Collections;\r
 import java.util.HashMap;\r
 \r
+import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.util.IPropertyChangeListener;\r
 import org.eclipse.jface.util.PropertyChangeEvent;\r
 import org.eclipse.jface.viewers.CellEditor;\r
@@ -28,6 +29,7 @@ import org.eclipse.jface.viewers.IStructuredContentProvider;
 import org.eclipse.jface.viewers.IStructuredSelection;\r
 import org.eclipse.jface.viewers.ITableLabelProvider;\r
 import org.eclipse.jface.viewers.SelectionChangedEvent;\r
+import org.eclipse.jface.viewers.StructuredSelection;\r
 import org.eclipse.jface.viewers.TableViewer;\r
 import org.eclipse.jface.viewers.TextCellEditor;\r
 import org.eclipse.jface.viewers.Viewer;\r
@@ -37,14 +39,11 @@ import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.graphics.Image;\r
 import org.eclipse.swt.graphics.RGB;\r
 import org.eclipse.swt.layout.FillLayout;\r
-import org.eclipse.swt.layout.FormAttachment;\r
-import org.eclipse.swt.layout.FormData;\r
-import org.eclipse.swt.layout.FormLayout;\r
+import org.eclipse.swt.layout.GridLayout;\r
 import org.eclipse.swt.widgets.Button;\r
 import org.eclipse.swt.widgets.ColorDialog;\r
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.Group;\r
-import org.eclipse.swt.widgets.Label;\r
 import org.eclipse.swt.widgets.Table;\r
 import org.eclipse.swt.widgets.TableColumn;\r
 import org.eclipse.swt.widgets.TableItem;\r
@@ -64,7 +63,6 @@ public class ColorGradientComposite extends Composite implements ISelectionChang
        \r
        \r
        private ColorGradientCanvas gradientComposite;\r
-       //private Table table;\r
        private TableViewer viewer;\r
        private Button addButton;\r
        private Button editButton;\r
@@ -74,24 +72,21 @@ public class ColorGradientComposite extends Composite implements ISelectionChang
        private int type = ColorGradient.RGB;\r
        \r
        private ArrayList<ColorValue> values = new ArrayList<ColorValue>();\r
-       //private ArrayList<Image> images = new ArrayList<Image>();\r
-       //private HashMap<TableItem,ColorValue> items = new HashMap<TableItem,ColorValue>();\r
        private HashMap<ColorValue,Image> images = new HashMap<ColorValue,Image>();\r
        \r
-       \r
-       \r
        public ColorGradientComposite(Composite parent, int style) {\r
                super(parent,style);\r
-           FormLayout layout = new FormLayout();\r
+               GridLayout layout = new GridLayout(2,false);\r
            this.setLayout(layout);\r
            gradientComposite = new ColorGradientCanvas(this,SWT.HORIZONTAL);\r
            \r
-           Group typeComposite = new Group(this,SWT.NONE);\r
-           typeComposite.setText("Color interpolation type");\r
+          \r
+           \r
+//         Group typeComposite = new Group(this,SWT.NONE);\r
+//         typeComposite.setText("Interpolation");\r
+           Composite typeComposite = new Composite(this, SWT.NONE);\r
            \r
-           typeComposite.setLayout(new FillLayout(SWT.HORIZONTAL));\r
-           Label rgbLabel = new Label(typeComposite,SWT.NONE);\r
-           rgbLabel.setText("RGB");\r
+           typeComposite.setLayout(new GridLayout(1,false));\r
            rgbButton = new Button(typeComposite,SWT.RADIO);\r
            rgbButton.setSelection(true);\r
            rgbButton.addSelectionListener(new SelectionListener() {\r
@@ -105,8 +100,7 @@ public class ColorGradientComposite extends Composite implements ISelectionChang
                        gradientComposite.setGradient(new ColorGradient(values,type));\r
                }\r
            });\r
-           Label hsvLabel = new Label(typeComposite,SWT.NONE);\r
-           hsvLabel.setText("HSV");\r
+           rgbButton.setText("RGB");\r
            hsvButton = new Button(typeComposite,SWT.RADIO);\r
            hsvButton.addSelectionListener(new SelectionListener() {\r
                public void widgetDefaultSelected(SelectionEvent e) {\r
@@ -119,9 +113,11 @@ public class ColorGradientComposite extends Composite implements ISelectionChang
                        gradientComposite.setGradient(new ColorGradient(values,type));\r
                }\r
            });\r
+           hsvButton.setText("HSV");\r
+          \r
            viewer = new TableViewer(this,SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);\r
-           //table = new Table(this,SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);\r
            final Table table = viewer.getTable();\r
+           \r
            table.setLinesVisible(true);\r
            table.setHeaderVisible(true);\r
            \r
@@ -130,7 +126,7 @@ public class ColorGradientComposite extends Composite implements ISelectionChang
            \r
            TableColumn column = new TableColumn(table,SWT.RIGHT);\r
            column.setText("Color");\r
-           column.setWidth(40);\r
+           column.setWidth(60);\r
            column.setMoveable(false);\r
            column.setResizable(false);\r
            column = new TableColumn(table,SWT.LEFT);\r
@@ -153,11 +149,9 @@ public class ColorGradientComposite extends Composite implements ISelectionChang
            \r
            viewer.setCellModifier(new TableCellEditorModifier());    \r
            \r
-           \r
            Composite buttonComposite = new Composite(this,SWT.NONE);\r
-           \r
-           \r
-           buttonComposite.setLayout(new FillLayout(SWT.HORIZONTAL));\r
+\r
+           buttonComposite.setLayout(new FillLayout(SWT.VERTICAL));\r
            \r
            addButton = new Button(buttonComposite,SWT.PUSH);\r
            addButton.setText("Add new color");\r
@@ -174,10 +168,32 @@ public class ColorGradientComposite extends Composite implements ISelectionChang
                     } else if (values.size() == 1) {\r
                        value = 100.0;\r
                     } else {\r
-                       // FIXME : insert some logic here\r
-                       value = 100.0 * Math.random();\r
+                       StructuredSelection selection = (StructuredSelection)viewer.getSelection();\r
+                       if (selection.size() == 1) {\r
+                               // add new color next to the selection\r
+                               ColorValue v = (ColorValue)selection.getFirstElement();\r
+                               int index = values.indexOf(v);\r
+                               if (index == values.size() -1) {\r
+                                       index--;\r
+                               }\r
+                               value = (values.get(index+1).getValue()-values.get(index).getValue())*0.5;\r
+                               value += values.get(index).getValue();\r
+                       } else {\r
+                               // add new color to largest gap\r
+                               int index = 0;\r
+                               double r = 0.0;\r
+                               for (int i = 0; i < values.size() -1; i++) {\r
+                                       double v1 = values.get(i).getValue();\r
+                                       double v2 = values.get(i+1).getValue();\r
+                                       double vr = v2 -v1;\r
+                                       if (vr > r) {\r
+                                               r=vr;\r
+                                               index = i;\r
+                                       }\r
+                               }\r
+                               value = values.get(index).getValue() + r *0.5;\r
+                       }\r
                     }\r
-                    \r
                     addColor(c,value);\r
                 }\r
             }\r
@@ -222,67 +238,21 @@ public class ColorGradientComposite extends Composite implements ISelectionChang
         });\r
            removeButton.setEnabled(false);\r
            \r
-           FormData gradientData = new FormData();\r
-           gradientData.top = new FormAttachment(0,0);\r
-           gradientData.left = new FormAttachment(0,0);\r
-           gradientData.right = new FormAttachment(100,0);\r
-           gradientData.height = 40;\r
-           gradientComposite.setLayoutData(gradientData);\r
-              \r
-           FormData typeData = new FormData();     \r
-           typeData.left = new FormAttachment(0,0);\r
-           typeData.right = new FormAttachment(100,0);\r
-           typeData.top = new FormAttachment(gradientComposite,0,SWT.BOTTOM);\r
-           typeData.height = 20;\r
-           typeComposite.setLayoutData(typeData);\r
-           \r
-           FormData buttonData = new FormData();           \r
-           buttonData.left = new FormAttachment(0,0);\r
-           buttonData.right = new FormAttachment(100,0);\r
-           buttonData.bottom = new FormAttachment(100,0);\r
-           buttonData.height = 30;\r
-           buttonComposite.setLayoutData(buttonData);\r
+           GridDataFactory.fillDefaults().span(1, 1).grab(true, false).align(SWT.FILL, SWT.CENTER).hint(SWT.DEFAULT, 32).applyTo(gradientComposite);\r
+           GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).hint(SWT.DEFAULT, 100).applyTo(table);\r
+           GridDataFactory.fillDefaults().grab(false, true).align(SWT.LEFT, SWT.FILL).applyTo(typeComposite);\r
+           GridDataFactory.fillDefaults().span(1, 1).grab(true, false).align(SWT.FILL, SWT.TOP).applyTo(buttonComposite);\r
            \r
-           FormData viewerData = new FormData();           \r
-           viewerData.top = new FormAttachment(typeComposite,0,SWT.BOTTOM);\r
-           viewerData.left = new FormAttachment(0,0);\r
-           viewerData.right = new FormAttachment(100,0);\r
-           viewerData.bottom = new FormAttachment(buttonComposite,0,SWT.TOP);\r
-           table.setLayoutData(viewerData);\r
            \r
-           \r
-       }\r
-       /*\r
-       private void addColorValueToTable(ColorValue value) {\r
-               TableItem item = new TableItem(table,SWT.NONE);\r
-               item.setText(Double.toString(value.getValue()));\r
-               Image image = ColorIconCreator.createImage(value.getColor(), 14);\r
-               item.setImage(image);\r
-               images.add(image);\r
-               items.put(item,value);\r
-       }\r
-       */\r
-       /*\r
-       private void sortItems() {\r
-               for (Image i : images)\r
-                       i.dispose();\r
-               for (TableItem item : table.getItems())\r
-                       if(!item.isDisposed())\r
-                               item.dispose();\r
-               items.clear();\r
-               Collections.sort(values,new ColorValueComparator());\r
-               for (ColorValue value : values) {\r
-                       addColorValueToTable(value);\r
-               }\r
        }\r
-       */\r
+\r
        public void addColor(Color color, double value) {\r
                addColor(new ColorValue(color,value));\r
        }\r
        \r
        public void addColor(ColorValue value) {\r
                values.add(value);\r
-               Image image = ColorIconCreator.createImage(value.getColor(), ICON_WIDTH, ICON_HEIGHT);\r
+               Image image = ColorIconCreator.createImage(value.getColor(), ICON_WIDTH, ICON_HEIGHT, SWT.BORDER);\r
                images.put(value,image);\r
                updateWidgets();\r
                //viewer.refresh(true);\r
@@ -294,36 +264,11 @@ public class ColorGradientComposite extends Composite implements ISelectionChang
                viewer.refresh();\r
                \r
        }\r
-       /*\r
-       public void addColor(ColorValue value) {\r
-               values.add(value);\r
-               sortItems();\r
-               // sortItem creates new menuitems, which makes selectedItem disposed\r
-               for (TableItem item : items.keySet() ) {\r
-                       if (items.get(item) == value) {\r
-                               gradientComposite.setGradient(new ColorGradient(values,type));\r
-                               return;\r
-                       }\r
-                       \r
-               }\r
-               gradientComposite.setGradient(new ColorGradient(values,type));\r
-       }\r
-       */\r
+\r
        public ColorGradient getGradient() {\r
                return new ColorGradient(values,type);\r
        }\r
-       /*\r
-       public void dispose() {\r
-               for (Image i : images)\r
-                       i.dispose();\r
-               if (!table.isDisposed()) {\r
-                       for (TableItem item : table.getItems())\r
-                               if(!item.isDisposed())\r
-                                       item.dispose();\r
-                       table.dispose();\r
-               }\r
-       }\r
-       */\r
+\r
        public void dispose() {\r
                for (Image i : images.values())\r
                        i.dispose();\r
@@ -338,15 +283,16 @@ public class ColorGradientComposite extends Composite implements ISelectionChang
                type = gradient.getType();\r
                for (ColorValue value : gradient.getColorValues())\r
                        addColor(value);\r
+               if (type == ColorGradient.HSV) {\r
+                       rgbButton.setSelection(false);\r
+                       hsvButton.setSelection(true);\r
+               } else if (type == ColorGradient.RGB) {\r
+                       hsvButton.setSelection(false);\r
+                       rgbButton.setSelection(true);\r
+               }\r
                \r
        }\r
        \r
-       \r
-//     private org.eclipse.swt.graphics.Color getSWTColor(Color color){\r
-//             org.eclipse.swt.graphics.Color swtColor = new org.eclipse.swt.graphics.Color(Display.getCurrent(), color.getR(), color.getG(), color.getB());   \r
-//             return swtColor;\r
-//     }\r
-       \r
        private RGB getRGB(Color color) {\r
                RGB rgb = new RGB(color.getR(),color.getG(),color.getB());\r
                return rgb;\r
@@ -377,7 +323,7 @@ public class ColorGradientComposite extends Composite implements ISelectionChang
                Color newColor = new Color(rgb.red,rgb.green,rgb.blue);\r
                ColorValue newCValue = new ColorValue(newColor,cValue.getValue());\r
                values.add(newCValue);\r
-               Image newImage = ColorIconCreator.createImage(newColor, ICON_WIDTH, ICON_HEIGHT);\r
+               Image newImage = ColorIconCreator.createImage(newColor, ICON_WIDTH, ICON_HEIGHT, SWT.BORDER);\r
                images.put(newCValue,newImage);\r
                updateWidgets();\r
        }\r