]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.selectionview/src/org/simantics/selectionview/StandardProperties.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.selectionview / src / org / simantics / selectionview / StandardProperties.java
diff --git a/bundles/org.simantics.selectionview/src/org/simantics/selectionview/StandardProperties.java b/bundles/org.simantics.selectionview/src/org/simantics/selectionview/StandardProperties.java
new file mode 100644 (file)
index 0000000..82fdcfc
--- /dev/null
@@ -0,0 +1,88 @@
+/*******************************************************************************\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.selectionview;\r
+\r
+import java.util.Collection;\r
+import java.util.HashSet;\r
+import java.util.Set;\r
+\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.ui.IWorkbenchPartSite;\r
+import org.eclipse.ui.part.IPageSite;\r
+import org.simantics.browsing.ui.common.ErrorLogger;\r
+import org.simantics.browsing.ui.common.views.IFilterArea;\r
+import org.simantics.browsing.ui.common.views.IFilterAreaProvider;\r
+import org.simantics.db.ReadGraph;\r
+\r
+/**\r
+ * @author Antti Villberg\r
+ * \r
+ * @see StandardPropertyPage\r
+ */\r
+public class StandardProperties extends TabbedPropertyTable implements IFilterAreaProvider, IPropertyTab {\r
+\r
+    /**\r
+     * @param site\r
+     * @param pageSite\r
+     * @param parent\r
+     * @param style\r
+     * @param browseContexts the browse contexts to use for loading this\r
+     *        property table\r
+     * @param selectionProcessors a fixed set of selection processors, may be\r
+     *        <code>null</code>\r
+     */\r
+    public StandardProperties(IWorkbenchPartSite site, IPageSite pageSite, Composite parent, int style,\r
+            final Set<String> browseContexts, final Collection<SelectionProcessor<?, ?>> selectionProcessors) {\r
+        super(site, pageSite, parent, style);\r
+\r
+        final Set<SelectionProcessor<?, ?>> processors = new HashSet<SelectionProcessor<?, ?>>();\r
+        if (selectionProcessors != null)\r
+            processors.addAll(selectionProcessors);\r
+\r
+        //System.out.println("StandardProperties with contexts: " + browseContexts);\r
+        for (final SelectionProcessorBinding binding : SelectionProcessorBindingExtensionManager.getInstance().getBoundContributions(browseContexts)) {\r
+            //System.out.println("found " + binding.getProcessor());\r
+            processors.add(binding.getProcessor());\r
+        }\r
+\r
+        setSelectionProcessor(new SelectionProcessor<Object, ReadGraph>() {\r
+\r
+            @SuppressWarnings({ "rawtypes", "unchecked" })\r
+            @Override\r
+            public Collection<?> process(final Object selection, ReadGraph graph) {\r
+\r
+                HashSet<Object> l     = new HashSet<Object>();\r
+                for (SelectionProcessor p : processors) {\r
+                    Collection<?> c = p.process(selection, graph);\r
+                    if (c != null) {\r
+                        l.addAll(c);\r
+                    } else {\r
+                        ErrorLogger.defaultLogWarning("SelectionProcessor '" + p + "' invalidly returned null with selection '" + selection + "'", null);\r
+                    }\r
+                }\r
+\r
+                return l;\r
+\r
+            }\r
+\r
+        });\r
+    }\r
+\r
+    @Override\r
+    public IFilterArea getFilterArea() {\r
+        IPropertyTab active = getActiveTab();\r
+        if (!(active instanceof IFilterAreaProvider))\r
+            return null;\r
+        return ((IFilterAreaProvider) active).getFilterArea();\r
+    }\r
+\r
+}\r