]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Misc. changes to support Selection View in modelled documents
authorAntti Villberg <antti.villberg@semantum.fi>
Fri, 24 Feb 2017 12:47:17 +0000 (14:47 +0200)
committerjsimomaa <jani.simomaa@gmail.com>
Fri, 28 Apr 2017 13:15:54 +0000 (16:15 +0300)
refs #7050

Change-Id: Ia088db3d75c8d9963d0e513d1e6042a63b13e6c8

14 files changed:
bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/labeldecorators/ConstantLabelDecorationRule.java
bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/ITreeTableCell.java
bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/JSONObjectUtils.java
bundles/org.simantics.document.server/scl/Document/All.scl
bundles/org.simantics.modeling.ui/scl/Simantics/Testing/ActionBrowseContext.scl
bundles/org.simantics.modeling.ui/scl/Simantics/Testing/BrowseContext.scl
bundles/org.simantics.selectionview.ontology/graph.tg
bundles/org.simantics.selectionview.ontology/graph/Selectionview.pgraph
bundles/org.simantics.selectionview.ui.ontology/graph.tg
bundles/org.simantics.selectionview.ui.ontology/graph/SelectionViewUi.pgraph
bundles/org.simantics.selectionview.ui.ontology/graph/scl/SCLMain.scl [new file with mode: 0644]
bundles/org.simantics.selectionview.ui.ontology/src/org/simantics/selectionview/ui/ontology/SelectionViewUIResources.java
bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/common/TreeTableCell.java
bundles/org.simantics.spreadsheet.graph/scl/Spreadsheet/All.scl

index 3bb2db942095c6a34390377a2d69488c57d2c094..494c0a8198b88685025e84c7e2abd4829e91d94f 100644 (file)
@@ -13,7 +13,9 @@ package org.simantics.browsing.ui.model.labeldecorators;
 
 import org.eclipse.jface.resource.ColorDescriptor;
 import org.eclipse.jface.resource.FontDescriptor;
+import org.eclipse.jface.resource.JFaceResources;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Font;
 import org.eclipse.swt.graphics.RGB;
 import org.simantics.browsing.ui.content.LabelDecorator;
 import org.simantics.databoard.Bindings;
@@ -133,6 +135,7 @@ public class ConstantLabelDecorationRule extends AbstractLabelDecorator implemen
             return font;
         else {
             FontDescriptor desc = (FontDescriptor)font;
+            if(desc == null) desc = FontDescriptor.createFrom(JFaceResources.getDialogFont().getFontData());
             return (Font)desc.withStyle(style);
         }
     }
index 7a59a14610284d988378e633c1e5773063ff2f6b..9bf10fb3a67d4ad2c1dc7fb23a4bc56b81be9652 100644 (file)
@@ -3,4 +3,9 @@ package org.simantics.document.server.io;
 public interface ITreeTableCell extends ITableCell {
     
        int getParent();
+       
+        Object getData();
+
+     boolean isEditable();
+     
 }
index 8913645a9946c3f4884fd4e8c5ae9f028afaea1a..558ee320459e519823852eac43d654763e90906f 100644 (file)
@@ -13,6 +13,7 @@
 package org.simantics.document.server.io;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
@@ -343,4 +344,72 @@ public class JSONObjectUtils {
         else
             return Collections.<IListItem>emptyList();
     }
+    
+    @SuppressWarnings("unchecked")
+    public static Collection<ITreeTableCell> getTreeTableCell(IJSONObject object) {
+        try {
+            Object treeTableCells = object.getValue("tableCells");
+            if (treeTableCells instanceof String) {
+                String tableCellsS = (String) treeTableCells;
+                if (tableCellsS.length() == 0)
+                    return Collections.emptyList();
+            }
+            if (treeTableCells != null) {
+                return (List<ITreeTableCell>) treeTableCells;
+            } else {
+                return Collections.emptyList();
+            }
+        } catch (ClassCastException e) {
+            e.printStackTrace();
+        }
+        return Collections.emptyList();
+    }
+
+    public static final boolean equalObjects(Object oldValue, Object newValue) {
+       if (newValue != null) {
+               if (newValue.getClass().isArray()) {
+                       return arrayEquals(newValue, oldValue);
+               } else {
+                       return newValue.equals(oldValue);
+               }
+       } else
+               return oldValue == null;
+    }
+
+    
+       /**
+        * @param av1 an array (guaranteed)
+        * @param av2 any object
+        * @return <code>true</code> if the two arrays are equal
+        */
+       private static final boolean arrayEquals(Object av1, Object av2) {
+               if (av2 == null)
+                       return false;
+               Class<?> c1 = av1.getClass().getComponentType();
+               Class<?> c2 = av2.getClass().getComponentType();
+               if (c2 == null || !c1.equals(c2))
+                       return false;
+               boolean p1 = c1.isPrimitive();
+               boolean p2 = c2.isPrimitive();
+               if (p1 != p2)
+                       return false;
+               if (!p1)
+                       return Arrays.equals((Object[]) av1, (Object[]) av2);
+               if (boolean.class.equals(c1))
+                       return Arrays.equals((boolean[]) av1, (boolean[]) av2);
+               else if (byte.class.equals(c1))
+                       return Arrays.equals((byte[]) av1, (byte[]) av2);
+               else if (int.class.equals(c1))
+                       return Arrays.equals((int[]) av1, (int[]) av2);
+               else if (long.class.equals(c1))
+                       return Arrays.equals((long[]) av1, (long[]) av2);
+               else if (float.class.equals(c1))
+                       return Arrays.equals((float[]) av1, (float[]) av2);
+               else if (double.class.equals(c1))
+                       return Arrays.equals((double[]) av1, (double[]) av2);
+               throw new RuntimeException("Unsupported objects for equality testing ." + av1 + " vs. " + av2);
+               
+       }
+    
+    
 }
index 23896814224bdeed738e03fb32723c466fc5d367..fa83a224acfc2d7076af4417e2f2e181680e93e7 100644 (file)
@@ -21,6 +21,13 @@ importJava "org.simantics.document.server.io.ITreeTableCell" where
 
 importJava "org.simantics.document.server.io.IFont" where
     data IFont
+    
+    @JavaName getFamily
+    fontFamily :: IFont -> <Proc> Maybe String
+    @JavaName getStyle
+    fontStyle :: IFont -> <Proc> Maybe String
+    @JavaName getHeight
+    fontHeight :: IFont -> <Proc> Integer
 
 importJava "org.simantics.document.server.io.IColor" where
     data IColor
index ecacf009097034cbc6dd9c43bdc40d4df0aa5a00..b821fcc03f10b5105ff5de01d4ce45dd3aed102a 100644 (file)
@@ -123,7 +123,9 @@ printActionDetails action = do
 @private
 decorateLabelStub :: LabelDecorator -> String -> String -> <Proc> ()
 decorateLabelStub decorator key value = do
-    fontti = decorateFont decorator getDefaultFontDescriptor key 0
+    fontti = match decorateFont decorator (Just getDefaultFontDescriptor) key 0 with
+      Nothing -> ""
+      Just font -> ""
     fontti = decorateBackground decorator Nothing key 0
     fontti = decorateForeground decorator Nothing key 0
     laabeli = decorateLabel decorator value key 0
index a4b06495a4b6f155b1a4abd73170e960e1e1cde1..d3890192e711495363cff0b7ac6517cdc191f8f1 100644 (file)
@@ -96,7 +96,7 @@ importJava "org.simantics.browsing.ui.content.LabelDecorator" where
     decorateLabel :: LabelDecorator -> String -> String -> Integer -> <Proc> String
     decorateForeground :: LabelDecorator -> a -> String -> Integer -> <Proc> a
     decorateBackground :: LabelDecorator -> a -> String -> Integer -> <Proc> a
-    decorateFont :: LabelDecorator -> a -> String -> Integer -> <Proc> a
+    decorateFont :: LabelDecorator -> Maybe a -> String -> Integer -> <Proc> Maybe a
 
 importJava "org.simantics.browsing.ui.CheckedState" where
     data CheckedState
@@ -105,7 +105,8 @@ importJava "org.simantics.browsing.ui.content.Labeler$Modifier" where
     data Modifier
     
     getValue :: Modifier -> <Proc> String
-    isValid :: Modifier -> String -> <Proc> String
+    isValid :: Modifier -> String -> <Proc> Maybe String
+    modify :: Modifier -> String -> <Proc> ()
 
 importJava "org.simantics.browsing.ui.model.browsecontexts.BrowseContexts" where
     toBrowseContextG :: Vector String -> <ReadGraph> BrowseContext
@@ -118,3 +119,6 @@ createBrowseContext :: [Resource] -> <ReadGraph> BrowseContext
 createBrowseContext resource = do
     create resource
 
+importJava "org.simantics.browsing.ui.common.NodeContextBuilder" where
+    buildWithInput :: a -> <Proc> NodeContext
+
index 62f5bc7921cb706b62d10cbbe0cce38d6ca1abb4..7aa0ecdb2244680407b97f78fd5742e2878df419 100644 (file)
Binary files a/bundles/org.simantics.selectionview.ontology/graph.tg and b/bundles/org.simantics.selectionview.ontology/graph.tg differ
index 962de11c5f31bc5b385a92ec4508f26298e08f06..383459e628f5bc647df1cb2b39685873b01d8623 100644 (file)
@@ -137,7 +137,7 @@ SEL.CategoryHidden : SEL.StandardPropertyInfo
   SEL.StandardPropertyInfo.CategorySortingName ""
   SEL.StandardPropertyInfo.IsHidden true
 
-SEL.getSpecialCategory ==> "Resource -> <ReadGraph> Resource" <R L0.HasProperty : L0.FunctionalRelation
+SEL.getSpecialCategory ==> "Resource -> <ReadGraph> Maybe Resource" <R L0.HasProperty : L0.FunctionalRelation
 
 SEL.ColorParameterType <T SEL.GenericParameterType
   @L0.assert SEL.HasDisplayValue
index a0f65152b08e65a3f0c9dc9bf89a485673d0f9a6..5b19d1986a7d3a12f16d25ee3d05102b5a0cd867 100644 (file)
Binary files a/bundles/org.simantics.selectionview.ui.ontology/graph.tg and b/bundles/org.simantics.selectionview.ui.ontology/graph.tg differ
index 0fb82a9aff0c9dccd806b234e201a957dcd3ef81..704e7430c417a7541255b2cd8d3e6f3242c9f02e 100644 (file)
@@ -10,6 +10,10 @@ SEL = <http://www.simantics.org/SelectionViewUI-1.1> : L0.Ontology
     @L0.new
     L0.HasResourceClass "org.simantics.selectionview.ui.ontology.SelectionViewUIResources"
 
+SEL.SCLMain : L0.SCLModule
+    L0.SCLModule.definition _ : L0.String
+      @L0.loadString "scl/SCLMain.scl"
+
 SEL.CategoryNode : VP.NodeType
   VP.HasContentType "org.simantics.selectionview.CategoryNode"
   VP.HasBundle "org.simantics.selectionview"
@@ -83,11 +87,17 @@ SEL.StandardProperties.BrowseContextStandardChildren <T SEL.StandardProperties.B
       VP.ChildContribution.HasChildNodeType SEL.CategoryNode
       VP.ChildContribution.HasRule 
         SEL.StandardProperties.BrowseContextStandardChildren.Cat : SEL.VariablePropertyCategoryRule
+          @MOD.scl SEL_BASE.getSpecialCategory "layer0Categories" "Resource -> <ReadGraph> Maybe Resource"
   @L0.assert VP.BrowseContext.HasVisualsContribution
     _ : VP.VisualsContribution
       VP.VisualsContribution.HasNodeType MOD.ModelingBrowseContext.Variable
       VP.VisualsContribution.HasRule
         SEL.StandardProperties.BrowseContextStandardChildren.Sorter : SEL.StandardPropertySorterRuleType
+          @MOD.scl SEL_BASE.getSpecialCategory "layer0Categories" "Resource -> <ReadGraph> Maybe Resource"
+  @L0.assert  VP.BrowseContext.HasVisualsContribution
+    _ : VP.VisualsContribution
+      VP.VisualsContribution.HasNodeType MOD.ModelingBrowseContext.Variable
+      VP.VisualsContribution.HasRule VP.DescriptionTooltipRule
 
 SEL.StandardProperties.BrowseContextWithoutChildren <T VP.BrowseContext
   @L0.assert VP.BrowseContext.HasVisualsContribution
diff --git a/bundles/org.simantics.selectionview.ui.ontology/graph/scl/SCLMain.scl b/bundles/org.simantics.selectionview.ui.ontology/graph/scl/SCLMain.scl
new file mode 100644 (file)
index 0000000..2184c61
--- /dev/null
@@ -0,0 +1,7 @@
+include "Simantics/All"
+
+layer0Categories :: Resource -> <ReadGraph> Maybe Resource
+layer0Categories predicate = match predicate with
+  L0.HasName -> Just MOD.SystemPropertyInfo
+  _ -> Nothing
+  
\ No newline at end of file
index cdf0fa26fec940ee1d71406f381f8dafc8ea9512..b3b474592924db6526f71d61d4ecbdca4092f763 100644 (file)
@@ -14,6 +14,7 @@ public class SelectionViewUIResources {
     public final Resource CategoryNode;
     public final Resource CategoryNodeLabelRule;
     public final Resource PropertyColumn;
+    public final Resource SCLMain;
     public final Resource StandardProperties;
     public final Resource StandardPropertiesBase;
     public final Resource StandardPropertiesBase_BrowseContext;
@@ -37,6 +38,7 @@ public class SelectionViewUIResources {
         public static final String CategoryNode = "http://www.simantics.org/SelectionViewUI-1.1/CategoryNode";
         public static final String CategoryNodeLabelRule = "http://www.simantics.org/SelectionViewUI-1.1/CategoryNodeLabelRule";
         public static final String PropertyColumn = "http://www.simantics.org/SelectionViewUI-1.1/PropertyColumn";
+        public static final String SCLMain = "http://www.simantics.org/SelectionViewUI-1.1/SCLMain";
         public static final String StandardProperties = "http://www.simantics.org/SelectionViewUI-1.1/StandardProperties";
         public static final String StandardPropertiesBase = "http://www.simantics.org/SelectionViewUI-1.1/StandardPropertiesBase";
         public static final String StandardPropertiesBase_BrowseContext = "http://www.simantics.org/SelectionViewUI-1.1/StandardPropertiesBase/BrowseContext";
@@ -70,6 +72,7 @@ public class SelectionViewUIResources {
         CategoryNode = getResourceOrNull(graph, URIs.CategoryNode);
         CategoryNodeLabelRule = getResourceOrNull(graph, URIs.CategoryNodeLabelRule);
         PropertyColumn = getResourceOrNull(graph, URIs.PropertyColumn);
+        SCLMain = getResourceOrNull(graph, URIs.SCLMain);
         StandardProperties = getResourceOrNull(graph, URIs.StandardProperties);
         StandardPropertiesBase = getResourceOrNull(graph, URIs.StandardPropertiesBase);
         StandardPropertiesBase_BrowseContext = getResourceOrNull(graph, URIs.StandardPropertiesBase_BrowseContext);
index 2face448f40973faf7135e6575e99776ead55a4e..fb80d07605493f42119f05af20f38d5d8ae766fa 100644 (file)
  *******************************************************************************/
 package org.simantics.spreadsheet.common;
 
+import org.eclipse.jface.resource.FontDescriptor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.FontData;
+import org.simantics.document.server.io.IFont;
 import org.simantics.document.server.io.ITreeTableCell;
+import org.simantics.document.server.io.SimpleFont;
 
 public class TreeTableCell extends TableCell implements ITreeTableCell {       
        
        private int parent = -1;
+       
+       private boolean editable = true;
+       private Object data;
 
        public TreeTableCell() {
        }
        
+       public TreeTableCell(String text, Object data, Object font, int parent, int row, int column, boolean editable) {
+               super(column, row, 0, 0, text, (IFont)font, null, null, false, 1, 1);
+               this.editable = editable;
+               this.parent = parent;
+               this.data = data;
+       }
+       
+       public static TreeTableCell createTreeTableCell(String text, Object data, Object font, int parent, int row, int column, boolean editable) {
+               return new TreeTableCell(text, data, extractIFont(font), parent, row, column, editable);
+       }
+       
+       private static IFont extractIFont(Object font) {
+               if(font instanceof FontDescriptor) {
+                       FontDescriptor descriptor = (FontDescriptor)font;
+                       String family = "";
+                       String style = "";
+                       int size = 12;
+                       for(FontData d : descriptor.getFontData()) {
+                               System.err.println("data: " + d);
+                               family = d.getName();
+                               if((d.getStyle() & SWT.ITALIC) != 0) style += "Italic";
+                               if((d.getStyle() & SWT.BOLD) != 0) style += "Bold";
+                               size = d.getHeight();
+                       }
+                       return new SimpleFont(family, style, size);
+               }
+               return null;
+       }
+       
        public void setParent(int parent) {
                this.parent = parent;
        }
@@ -30,4 +67,14 @@ public class TreeTableCell extends TableCell implements ITreeTableCell {
                return parent;
        }
 
+       @Override
+       public Object getData() {
+               return data;
+       }
+
+       @Override
+       public boolean isEditable() {
+               return editable;
+       }
+
 }
index ddfd3bef027adc184773dc43efe6cac5316c94ad..532331e55eec36fab7f7c36a3fbb4cc643eb354d 100644 (file)
@@ -10,6 +10,20 @@ importJava "org.simantics.spreadsheet.common.TableCell" where
 importJava "org.simantics.spreadsheet.common.TreeTableCell" where
     data TreeTableCell
 
+    @JavaName getData
+    getTreeTableCellData :: TreeTableCell -> <Proc> a
+    
+    createTreeTableCell :: String -> a -> Maybe b -> Integer -> Integer -> Integer -> Boolean -> <Proc> TreeTableCell
+    
+    @JavaName getText
+    treeTableCellText :: TreeTableCell -> <Proc> String
+    @JavaName getFont
+    treeTableCellFont :: TreeTableCell -> <Proc> Maybe IFont
+    @JavaName getRow
+    treeTableCellRow :: TreeTableCell -> <Proc> Integer
+    @JavaName getColumn
+    treeTableCellColumn :: TreeTableCell -> <Proc> Integer
+    
 importJava "org.simantics.spreadsheet.common.SpreadsheetCell" where
     data SpreadsheetCell