]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Add workbenchselection json fetcher to SCL interface 08/1908/1
authorMiro Richard Eklund <miro.eklund@semantum.fi>
Tue, 10 Jul 2018 14:42:14 +0000 (17:42 +0300)
committerMiro Richard Eklund <miro.eklund@semantum.fi>
Tue, 10 Jul 2018 14:42:14 +0000 (17:42 +0300)
Requires some small refactoring changes to AdaptableHintContext and
classes using it, which is why so many files were affected.

gitlab #41

Change-Id: I35bc8abe9e1eca8ff34ee503925645ee14d41664

12 files changed:
bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/AdaptableHintContext.java [moved from bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/AdaptableHintContext.java with 99% similarity]
bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/StandardWorkbenchSelectionElement.java [new file with mode: 0644]
bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/NatTableGraphExplorer.java
bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/RowSelectionItem.java
bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerFactory.java
bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerImpl.java
bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerImpl2.java
bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/GraphExplorerComposite.java
bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/ExportModel.java
bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/ExportSharedLibrary.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramViewerSelectionProvider.java
bundles/org.simantics.modeling/scl/Simantics/WorkbenchSelection.scl

similarity index 99%
rename from bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/AdaptableHintContext.java
rename to bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/AdaptableHintContext.java
index 3b6d45b82d5c34f88ab087898d981a2c655844da..bd7aa2790a303dcd491498abd1b1f93b551af15f 100644 (file)
@@ -9,7 +9,7 @@
  * Contributors:
  *     VTT Technical Research Centre of Finland - initial API and implementation
  *******************************************************************************/
-package org.simantics.browsing.ui.swt;
+package org.simantics.browsing.ui.common;
 
 import java.util.Arrays;
 import java.util.HashMap;
diff --git a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/StandardWorkbenchSelectionElement.java b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/StandardWorkbenchSelectionElement.java
new file mode 100644 (file)
index 0000000..8d8628c
--- /dev/null
@@ -0,0 +1,152 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2012 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.browsing.ui.model;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.simantics.browsing.ui.BuiltinKeys;
+import org.simantics.browsing.ui.GraphExplorer;
+import org.simantics.browsing.ui.NodeContext;
+import org.simantics.browsing.ui.common.AdaptableHintContext;
+import org.simantics.browsing.ui.model.nodetypes.NodeType;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.request.PossibleVariable;
+import org.simantics.db.layer0.request.PossibleVariableRepresents;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.ui.selection.AnyResource;
+import org.simantics.ui.selection.AnyVariable;
+import org.simantics.ui.selection.ExplorerColumnContentType;
+import org.simantics.ui.selection.ExplorerInputContentType;
+import org.simantics.ui.selection.WorkbenchSelectionContentType;
+import org.simantics.ui.selection.WorkbenchSelectionElement;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class StandardWorkbenchSelectionElement extends AdaptableHintContext {
+
+       private static final Logger LOGGER = LoggerFactory.getLogger(StandardWorkbenchSelectionElement.class);
+       
+       public static WorkbenchSelectionElement nodeContextToWorkbenchSelectionElement (NodeContext context) {
+               return (new StandardWorkbenchSelectionElement(context));
+       }
+       
+    final public WorkbenchSelectionElement wse;
+    final public Object content;
+    final public Resource resource;
+    final public Variable variable;
+    final public Object input;
+    
+    private WorkbenchSelectionElement extractWse(Object content) {
+        if(content instanceof NodeContext) {
+            NodeContext context = (NodeContext)content;
+            Object input = context.getConstant(NodeType.TYPE);
+            if(input instanceof NodeType) 
+                return ((NodeType)input).getWorkbenchSelectionElement(context);
+        }
+        return null;
+    }
+    
+    private Resource extractResource(Object content) {
+       if(content instanceof NodeContext) {
+               NodeContext context = (NodeContext)content;
+               Object input = context.getConstant(BuiltinKeys.INPUT);
+               if(input instanceof Resource) return (Resource)input;
+               if(input instanceof IAdaptable) {
+                       Resource var = (Resource)((IAdaptable)input).getAdapter(Resource.class);
+                       if(var != null) return var;
+               }
+       }
+       return null;
+    }
+    
+    private Variable extractVariable(Object content) {
+       if(content instanceof NodeContext) {
+               NodeContext context = (NodeContext)content;
+               Object input = context.getConstant(BuiltinKeys.INPUT);
+               if(input instanceof Variable) return (Variable)input;
+               if(input instanceof IAdaptable) {
+                       Variable var = (Variable)((IAdaptable)input).getAdapter(Variable.class);
+                       if(var != null) return var;
+               }
+       }
+       return null;
+    }
+
+    private Object extractInput(Object content) {
+       if(content instanceof NodeContext) {
+               NodeContext context = (NodeContext)content;
+               return context.getConstant(BuiltinKeys.INPUT);
+       }
+       return null;
+    }
+
+    public StandardWorkbenchSelectionElement(Object content) {
+        super(new Key[0]);
+        this.content = content;
+        this.wse = extractWse(content);
+        this.resource = extractResource(content);
+        this.variable = extractVariable(content);
+        this.input = extractInput(content);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public <T> T getContent(WorkbenchSelectionContentType<T> contentType) {
+        if (wse != null) {
+            T result = wse.getContent(contentType);
+            if (result != null)
+                return result;
+        }
+
+        if (contentType instanceof AnyResource) {
+            if (resource != null)
+                return (T) resource;
+            if (variable == null)
+                return null;
+            try {
+                return (T) ((AnyResource) contentType).processor.syncRequest(new PossibleVariableRepresents(variable));
+            } catch (DatabaseException e) {
+                LOGGER.error("Unexpected error occurred while resolving Resource from Variable " + variable, e);
+            }
+        }
+        else if (contentType instanceof AnyVariable) {
+            if (variable != null)
+                return (T) variable;
+            if (resource == null)
+                return null;
+            try {
+                return (T) ((AnyVariable) contentType).processor.syncRequest(new PossibleVariable(resource));
+            } catch (DatabaseException e) {
+                LOGGER.error("Unexpected error occurred while resolving Variable from Resource " + resource, e);
+            }
+        } else if (contentType instanceof ExplorerInputContentType) {
+            return (T) input;
+        }
+        return null;
+    }
+
+    @SuppressWarnings("rawtypes")
+    @Override
+    public Object getAdapter(Class adapter) {
+       if(WorkbenchSelectionElement.class == adapter) {
+               return wse;
+       }
+       if(NodeContext.class == adapter) {
+           if(content instanceof NodeContext)
+               return (NodeContext)content;
+           else
+               return null;
+       }
+       return super.getAdapter(adapter);
+    }
+
+}
\ No newline at end of file
index 6765f65ead2e0a87877ee52c73f969b452bac0d6..be6a73a0c05dbff44a460e4b5de85bd9000947fb 100644 (file)
@@ -141,6 +141,7 @@ import org.simantics.browsing.ui.PrimitiveQueryUpdater;
 import org.simantics.browsing.ui.SelectionDataResolver;
 import org.simantics.browsing.ui.SelectionFilter;
 import org.simantics.browsing.ui.StatePersistor;
+import org.simantics.browsing.ui.common.AdaptableHintContext;
 import org.simantics.browsing.ui.common.ColumnKeys;
 import org.simantics.browsing.ui.common.ErrorLogger;
 import org.simantics.browsing.ui.common.NodeContextBuilder;
@@ -178,7 +179,6 @@ import org.simantics.browsing.ui.content.Labeler.EnumerationModifier;
 import org.simantics.browsing.ui.content.Labeler.Modifier;
 import org.simantics.browsing.ui.nattable.override.DefaultTreeLayerConfiguration2;
 import org.simantics.browsing.ui.swt.Activator;
-import org.simantics.browsing.ui.swt.AdaptableHintContext;
 import org.simantics.browsing.ui.swt.DefaultImageDecoratorsProcessor;
 import org.simantics.browsing.ui.swt.DefaultIsExpandedProcessor;
 import org.simantics.browsing.ui.swt.DefaultLabelDecoratorsProcessor;
index 3d943a0922967c31540e62257b727638f1229e14..319a7fbeaac0d69a5153aede65c226ccaee7f20f 100644 (file)
@@ -1,6 +1,6 @@
 package org.simantics.browsing.ui.nattable;
 
-import org.simantics.browsing.ui.swt.AdaptableHintContext;
+import org.simantics.browsing.ui.common.AdaptableHintContext;
 import org.simantics.db.layer0.SelectionHints;
 
 public class RowSelectionItem extends AdaptableHintContext {
index b99962bf00d579c6ceb3cf8e0d4eea39a85abe73..3312430ddd9903b29a0aa26dee364b3fe0edd3e9 100644 (file)
@@ -25,6 +25,7 @@ import org.simantics.browsing.ui.GraphExplorer;
 import org.simantics.browsing.ui.NodeContext;
 import org.simantics.browsing.ui.SelectionDataResolver;
 import org.simantics.browsing.ui.SelectionFilter;
+import org.simantics.browsing.ui.common.AdaptableHintContext;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.common.request.PossibleTypedParent;
index 0e45f86ca4843fe53233ecec6217a07026ee4954..3cf5f7478cd7af3dc23ff412db75eac0628f87c1 100644 (file)
@@ -114,6 +114,7 @@ import org.simantics.browsing.ui.PrimitiveQueryProcessor;
 import org.simantics.browsing.ui.SelectionDataResolver;
 import org.simantics.browsing.ui.SelectionFilter;
 import org.simantics.browsing.ui.StatePersistor;
+import org.simantics.browsing.ui.common.AdaptableHintContext;
 import org.simantics.browsing.ui.common.ColumnKeys;
 import org.simantics.browsing.ui.common.ErrorLogger;
 import org.simantics.browsing.ui.common.NodeContextBuilder;
index 928bed03facc844eea8ef2603307e0a2c988f965..af0fa25a355019468aecd5a89f6a6f950e69833e 100644 (file)
@@ -123,6 +123,7 @@ import org.simantics.browsing.ui.PrimitiveQueryUpdater;
 import org.simantics.browsing.ui.SelectionDataResolver;
 import org.simantics.browsing.ui.SelectionFilter;
 import org.simantics.browsing.ui.StatePersistor;
+import org.simantics.browsing.ui.common.AdaptableHintContext;
 import org.simantics.browsing.ui.common.ColumnKeys;
 import org.simantics.browsing.ui.common.ErrorLogger;
 import org.simantics.browsing.ui.common.NodeContextBuilder;
index f583d7e7f1df374f0466232cf40d786a4b14cf2b..0ee36b3659507240d8ae817dc1ea9ca14a88acfe 100644 (file)
@@ -57,6 +57,7 @@ import org.simantics.browsing.ui.GraphExplorer;
 import org.simantics.browsing.ui.GraphExplorer.TransientExplorerState;
 import org.simantics.browsing.ui.NodeContext;
 import org.simantics.browsing.ui.StatePersistor;
+import org.simantics.browsing.ui.common.AdaptableHintContext;
 import org.simantics.browsing.ui.common.ColumnKeys;
 import org.simantics.browsing.ui.common.EvaluatorData;
 import org.simantics.browsing.ui.common.EvaluatorDataImpl;
@@ -82,7 +83,6 @@ import org.simantics.browsing.ui.graph.impl.SessionContextInputSource;
 import org.simantics.browsing.ui.model.browsecontexts.BrowseContext;
 import org.simantics.browsing.ui.model.nodetypes.NodeType;
 import org.simantics.browsing.ui.swt.Activator;
-import org.simantics.browsing.ui.swt.AdaptableHintContext;
 import org.simantics.browsing.ui.swt.ComparatorSelector;
 import org.simantics.browsing.ui.swt.ContextMenuInitializer;
 import org.simantics.browsing.ui.swt.DefaultExplorerSelectionListener;
index a214029d5f8fbcd98d36ec0dabaa0a60d30c5e5a..81bcc0357ba8cc07b920c130ea2a983b171ee2e2 100644 (file)
@@ -20,7 +20,7 @@ import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.swt.widgets.Display;
 import org.simantics.Simantics;
-import org.simantics.browsing.ui.swt.AdaptableHintContext;
+import org.simantics.browsing.ui.common.AdaptableHintContext;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.common.request.UniqueRead;
index 7bd7b3dffa051fad5b44929cfea9120b396c212c..96f7da83094e142d9ee1998b12943cbf5f2d995c 100644 (file)
@@ -20,7 +20,7 @@ import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.swt.widgets.Display;
 import org.simantics.Simantics;
-import org.simantics.browsing.ui.swt.AdaptableHintContext;
+import org.simantics.browsing.ui.common.AdaptableHintContext;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.common.request.UniqueRead;
index 154d8d4c73cfed685ba560060899bfd9c80e7991..f1493e4cca5a5952e78c0155a548b7110f4a0758 100644 (file)
@@ -6,7 +6,7 @@ import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.ui.IWorkbenchPartSite;
 import org.simantics.Simantics;
-import org.simantics.browsing.ui.swt.AdaptableHintContext;
+import org.simantics.browsing.ui.common.AdaptableHintContext;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.common.request.ResourceRead;
index 60ab7797b288ab5a5b1316cd646ce2f55a7ef80a..fc060e083a02329c46d4d5a56a6a518e47e85fc9 100644 (file)
@@ -1,5 +1,5 @@
 import "Simantics/Variables"
-
+import "Simantics/Testing/BrowseContext"
 
 importJava "org.simantics.ui.selection.WorkbenchSelectionElement" where
     data WorkbenchSelectionElement
@@ -9,4 +9,8 @@ importJava "org.simantics.ui.selection.WorkbenchSelectionUtils" where
     possibleWSEVariable :: WorkbenchSelectionElement -> <ReadGraph> Maybe Variable
     @JavaName "getPossibleResourceSCL"
     possibleWSEResource :: WorkbenchSelectionElement -> <ReadGraph> Maybe Resource
-    
\ No newline at end of file
+    @JavaName "getPossibleJSON"
+    possibleWSEJson :: WorkbenchSelectionElement -> <ReadGraph> Maybe String
+
+importJava "org.simantics.browsing.ui.model.StandardWorkbenchSelectionElement" where
+    nodeContextToWorkbenchSelectionElement :: NodeContext -> WorkbenchSelectionElement
\ No newline at end of file