From: Antti Villberg Date: Fri, 24 Feb 2017 12:47:17 +0000 (+0200) Subject: Misc. changes to support Selection View in modelled documents X-Git-Tag: v1.28.0~78 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F35%2F335%2F2;p=simantics%2Fplatform.git Misc. changes to support Selection View in modelled documents refs #7050 Change-Id: Ia088db3d75c8d9963d0e513d1e6042a63b13e6c8 --- diff --git a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/labeldecorators/ConstantLabelDecorationRule.java b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/labeldecorators/ConstantLabelDecorationRule.java index 3bb2db942..494c0a819 100644 --- a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/labeldecorators/ConstantLabelDecorationRule.java +++ b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/labeldecorators/ConstantLabelDecorationRule.java @@ -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); } } diff --git a/bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/ITreeTableCell.java b/bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/ITreeTableCell.java index 7a59a1461..9bf10fb3a 100644 --- a/bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/ITreeTableCell.java +++ b/bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/ITreeTableCell.java @@ -3,4 +3,9 @@ package org.simantics.document.server.io; public interface ITreeTableCell extends ITableCell { int getParent(); + + Object getData(); + + boolean isEditable(); + } diff --git a/bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/JSONObjectUtils.java b/bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/JSONObjectUtils.java index 8913645a9..558ee3204 100644 --- a/bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/JSONObjectUtils.java +++ b/bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/JSONObjectUtils.java @@ -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.emptyList(); } + + @SuppressWarnings("unchecked") + public static Collection 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) 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 true 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); + + } + + } diff --git a/bundles/org.simantics.document.server/scl/Document/All.scl b/bundles/org.simantics.document.server/scl/Document/All.scl index 238968142..fa83a224a 100644 --- a/bundles/org.simantics.document.server/scl/Document/All.scl +++ b/bundles/org.simantics.document.server/scl/Document/All.scl @@ -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 -> Maybe String + @JavaName getStyle + fontStyle :: IFont -> Maybe String + @JavaName getHeight + fontHeight :: IFont -> Integer importJava "org.simantics.document.server.io.IColor" where data IColor diff --git a/bundles/org.simantics.modeling.ui/scl/Simantics/Testing/ActionBrowseContext.scl b/bundles/org.simantics.modeling.ui/scl/Simantics/Testing/ActionBrowseContext.scl index ecacf0090..b821fcc03 100644 --- a/bundles/org.simantics.modeling.ui/scl/Simantics/Testing/ActionBrowseContext.scl +++ b/bundles/org.simantics.modeling.ui/scl/Simantics/Testing/ActionBrowseContext.scl @@ -123,7 +123,9 @@ printActionDetails action = do @private decorateLabelStub :: LabelDecorator -> String -> String -> () 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 diff --git a/bundles/org.simantics.modeling.ui/scl/Simantics/Testing/BrowseContext.scl b/bundles/org.simantics.modeling.ui/scl/Simantics/Testing/BrowseContext.scl index a4b06495a..d3890192e 100644 --- a/bundles/org.simantics.modeling.ui/scl/Simantics/Testing/BrowseContext.scl +++ b/bundles/org.simantics.modeling.ui/scl/Simantics/Testing/BrowseContext.scl @@ -96,7 +96,7 @@ importJava "org.simantics.browsing.ui.content.LabelDecorator" where decorateLabel :: LabelDecorator -> String -> String -> Integer -> String decorateForeground :: LabelDecorator -> a -> String -> Integer -> a decorateBackground :: LabelDecorator -> a -> String -> Integer -> a - decorateFont :: LabelDecorator -> a -> String -> Integer -> a + decorateFont :: LabelDecorator -> Maybe a -> String -> Integer -> 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 -> String - isValid :: Modifier -> String -> String + isValid :: Modifier -> String -> Maybe String + modify :: Modifier -> String -> () importJava "org.simantics.browsing.ui.model.browsecontexts.BrowseContexts" where toBrowseContextG :: Vector String -> BrowseContext @@ -118,3 +119,6 @@ createBrowseContext :: [Resource] -> BrowseContext createBrowseContext resource = do create resource +importJava "org.simantics.browsing.ui.common.NodeContextBuilder" where + buildWithInput :: a -> NodeContext + diff --git a/bundles/org.simantics.selectionview.ontology/graph.tg b/bundles/org.simantics.selectionview.ontology/graph.tg index 724deb153..cb9e2f834 100644 Binary files a/bundles/org.simantics.selectionview.ontology/graph.tg and b/bundles/org.simantics.selectionview.ontology/graph.tg differ diff --git a/bundles/org.simantics.selectionview.ontology/graph/Selectionview.pgraph b/bundles/org.simantics.selectionview.ontology/graph/Selectionview.pgraph index 58eba8471..cc1bc6200 100644 --- a/bundles/org.simantics.selectionview.ontology/graph/Selectionview.pgraph +++ b/bundles/org.simantics.selectionview.ontology/graph/Selectionview.pgraph @@ -132,7 +132,7 @@ SEL.CategoryHidden : SEL.StandardPropertyInfo SEL.StandardPropertyInfo.CategorySortingName "" SEL.StandardPropertyInfo.IsHidden true -SEL.getSpecialCategory ==> "Resource -> Resource" "Resource -> Maybe Resource" : 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 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 -> Maybe Resource" + @L0.assert VP.BrowseContext.HasVisualsContribution + _ : VP.VisualsContribution + VP.VisualsContribution.HasNodeType MOD.ModelingBrowseContext.Variable + VP.VisualsContribution.HasRule VP.DescriptionTooltipRule SEL.StandardProperties.BrowseContextWithoutChildren Maybe Resource +layer0Categories predicate = match predicate with + L0.HasName -> Just MOD.SystemPropertyInfo + _ -> Nothing + \ No newline at end of file diff --git a/bundles/org.simantics.selectionview.ui.ontology/src/org/simantics/selectionview/ui/ontology/SelectionViewUIResources.java b/bundles/org.simantics.selectionview.ui.ontology/src/org/simantics/selectionview/ui/ontology/SelectionViewUIResources.java index cdf0fa26f..b3b474592 100644 --- a/bundles/org.simantics.selectionview.ui.ontology/src/org/simantics/selectionview/ui/ontology/SelectionViewUIResources.java +++ b/bundles/org.simantics.selectionview.ui.ontology/src/org/simantics/selectionview/ui/ontology/SelectionViewUIResources.java @@ -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); diff --git a/bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/common/TreeTableCell.java b/bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/common/TreeTableCell.java index 2face448f..fb80d0760 100644 --- a/bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/common/TreeTableCell.java +++ b/bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/common/TreeTableCell.java @@ -12,15 +12,52 @@ *******************************************************************************/ 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; + } + } diff --git a/bundles/org.simantics.spreadsheet.graph/scl/Spreadsheet/All.scl b/bundles/org.simantics.spreadsheet.graph/scl/Spreadsheet/All.scl index ddfd3bef0..532331e55 100644 --- a/bundles/org.simantics.spreadsheet.graph/scl/Spreadsheet/All.scl +++ b/bundles/org.simantics.spreadsheet.graph/scl/Spreadsheet/All.scl @@ -10,6 +10,20 @@ importJava "org.simantics.spreadsheet.common.TableCell" where importJava "org.simantics.spreadsheet.common.TreeTableCell" where data TreeTableCell + @JavaName getData + getTreeTableCellData :: TreeTableCell -> a + + createTreeTableCell :: String -> a -> Maybe b -> Integer -> Integer -> Integer -> Boolean -> TreeTableCell + + @JavaName getText + treeTableCellText :: TreeTableCell -> String + @JavaName getFont + treeTableCellFont :: TreeTableCell -> Maybe IFont + @JavaName getRow + treeTableCellRow :: TreeTableCell -> Integer + @JavaName getColumn + treeTableCellColumn :: TreeTableCell -> Integer + importJava "org.simantics.spreadsheet.common.SpreadsheetCell" where data SpreadsheetCell