]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/DefaultSelectionDataResolver.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.browsing.ui.swt / src / org / simantics / browsing / ui / swt / DefaultSelectionDataResolver.java
diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/DefaultSelectionDataResolver.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/DefaultSelectionDataResolver.java
new file mode 100644 (file)
index 0000000..fd8359f
--- /dev/null
@@ -0,0 +1,48 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.browsing.ui.swt;\r
+\r
+import org.eclipse.core.runtime.IAdaptable;\r
+import org.simantics.browsing.ui.NodeContext;\r
+import org.simantics.browsing.ui.SelectionDataResolver;\r
+import org.simantics.ui.selection.ExplorerInputContentType;\r
+import org.simantics.ui.selection.WorkbenchSelectionElement;\r
+import org.simantics.ui.utils.ResourceAdaptionUtils;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class DefaultSelectionDataResolver implements SelectionDataResolver {\r
+\r
+    @Override\r
+    public Object resolve(Object o) {\r
+               \r
+        if(o instanceof NodeContext)\r
+            return (NodeContext)o;\r
+        if(o instanceof IAdaptable) {\r
+            IAdaptable adaptable = (IAdaptable)o;\r
+            NodeContext nodeContext = (NodeContext)adaptable.getAdapter(NodeContext.class);\r
+            if(nodeContext != null)\r
+                return nodeContext;\r
+            WorkbenchSelectionElement wse = (WorkbenchSelectionElement)adaptable.getAdapter(WorkbenchSelectionElement.class);\r
+            if(wse != null)\r
+                return wse.getContent(ExplorerInputContentType.INSTANCE);\r
+        }\r
+        if(o instanceof WorkbenchSelectionElement) {\r
+               WorkbenchSelectionElement wse = (WorkbenchSelectionElement)o;\r
+               if(wse != null) return wse.getContent(ExplorerInputContentType.INSTANCE);\r
+        }\r
+        return ResourceAdaptionUtils.adaptToResource(o);\r
+        \r
+       }\r
+\r
+}\r