--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * 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.function.Consumer;\r
+\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.ISelectionProvider;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Control;\r
+import org.eclipse.swt.widgets.Tree;\r
+import org.eclipse.ui.IWorkbenchSite;\r
+import org.simantics.browsing.ui.Column;\r
+import org.simantics.browsing.ui.Column.Align;\r
+import org.simantics.browsing.ui.GraphExplorer;\r
+import org.simantics.browsing.ui.common.ColumnKeys;\r
+import org.simantics.browsing.ui.common.EvaluatorData;\r
+import org.simantics.browsing.ui.common.EvaluatorData.Evaluator;\r
+import org.simantics.browsing.ui.common.comparators.AlphanumericComparatorFactory;\r
+import org.simantics.browsing.ui.common.processors.FilterSelectionRequestQueryProcessor;\r
+import org.simantics.browsing.ui.common.views.IFilterArea;\r
+import org.simantics.browsing.ui.graph.impl.ArrayPropertyLabelerFactory;\r
+import org.simantics.browsing.ui.graph.impl.ArrayPropertyValueViewpointFactory;\r
+import org.simantics.browsing.ui.graph.impl.PropertyViewpointFactory;\r
+import org.simantics.browsing.ui.graph.impl.RelationContextLabelerFactory;\r
+import org.simantics.browsing.ui.graph.impl.ResourceProperty;\r
+import org.simantics.browsing.ui.graph.impl.StringRepresentationLabelerFactory;\r
+import org.simantics.browsing.ui.swt.ArrayPropertyImagerFactory;\r
+import org.simantics.browsing.ui.swt.PropertyIsExpandedProcessor;\r
+import org.simantics.browsing.ui.swt.PropertyLabelDecoratorFactory;\r
+import org.simantics.browsing.ui.swt.RootFilterArea;\r
+import org.simantics.browsing.ui.swt.SingleSelectionInputSource;\r
+import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.db.RelationContext;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Statement;\r
+import org.simantics.db.common.ResourceArray;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class BasicPropertyTab extends PropertyTabContributorImpl {\r
+\r
+ protected RootFilterArea filterArea;\r
+ protected GraphExplorerComposite parameterExplorer;\r
+\r
+ public void updatePartName(ISelection forSelection, Consumer<String> updateCallback) {\r
+ updateCallback.accept(null);\r
+ }\r
+\r
+ protected void initializeExplorerWithEvaluator(GraphExplorer explorer, ISessionContext context,\r
+ EvaluatorData data) {\r
+\r
+ Evaluator resourceEvaluator = data.newEvaluator()\r
+ .addViewpoint(new PropertyViewpointFactory(), 1.0)\r
+ .addComparator(new AlphanumericComparatorFactory(ColumnKeys.PROPERTY), 2.0)\r
+ .addComparator(new AlphanumericComparatorFactory(ColumnKeys.PROPERTY, true), 1.0)\r
+ .addLabeler(new StringRepresentationLabelerFactory(ColumnKeys.PROPERTY), 1.0);\r
+\r
+ Evaluator statementEvaluator = data.newEvaluator()\r
+ .addViewpoint(new PropertyViewpointFactory(), 1.0)\r
+ .addComparator(new AlphanumericComparatorFactory(ColumnKeys.PROPERTY), 2.0)\r
+ .addComparator(new AlphanumericComparatorFactory(ColumnKeys.PROPERTY, true), 1.0);\r
+\r
+ Evaluator relationContextEvaluator = data.newEvaluator()\r
+ .addLabeler(new RelationContextLabelerFactory(), 1.0);\r
+\r
+ Evaluator propertyEvaluator = data.newEvaluator()\r
+ .addViewpoint(new ArrayPropertyValueViewpointFactory(), 1.0)\r
+ .addLabeler(new ArrayPropertyLabelerFactory(), 1.0)\r
+ .addImager(new ArrayPropertyImagerFactory(), 1.0)\r
+ .addLabelDecorator(new PropertyLabelDecoratorFactory(), 1.0);\r
+\r
+ data.addEvaluator(Resource.class, resourceEvaluator);\r
+ data.addEvaluator(ResourceArray.class, resourceEvaluator);\r
+ data.addEvaluator(Statement.class, statementEvaluator);\r
+ data.addEvaluator(RelationContext.class, relationContextEvaluator);\r
+ data.addEvaluator(ResourceProperty.class, propertyEvaluator);\r
+ \r
+ }\r
+\r
+ @Override\r
+ public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {\r
+ Column[] COLUMNS = new Column[] {\r
+ new Column(ColumnKeys.PROPERTY, Align.LEFT, 175, "Property Name", true, 1),\r
+ new Column(ColumnKeys.VALUE, Align.LEFT, 175, "Value of Property", true, 3)\r
+ };\r
+\r
+ parameterExplorer = new GraphExplorerComposite(\r
+ ArrayMap.keys("displaySelectors", "displayFilter").values(false, false),\r
+ site, body, support, SWT.FULL_SELECTION | SWT.MULTI) {\r
+ @Override\r
+ protected void initializeExplorerWithEvaluator(GraphExplorer explorer, ISessionContext context, EvaluatorData data) {\r
+ BasicPropertyTab.this.initializeExplorerWithEvaluator(explorer, context, data);\r
+ }\r
+ };\r
+ // Must set, even if empty.\r
+ parameterExplorer.setBrowseContexts();\r
+ //parameterExplorer.setStatePersistor(new IdentifiedStatePersistor(getClass().getCanonicalName()));\r
+ parameterExplorer.setContextMenuId("#PropertiesPopup");\r
+ parameterExplorer.setEditingColumn(ColumnKeys.VALUE);\r
+ parameterExplorer.setColumns(COLUMNS);\r
+ parameterExplorer.setInputSource(new SingleSelectionInputSource(Resource.class));\r
+ parameterExplorer.finish();\r
+ GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(parameterExplorer);\r
+\r
+ Control c = parameterExplorer.getExplorerControl();\r
+ if (c instanceof Tree)\r
+ ((Tree) c).setLinesVisible(true);\r
+\r
+ FilterSelectionRequestQueryProcessor filterProcessor = new FilterSelectionRequestQueryProcessor();\r
+ parameterExplorer.getExplorer().setPrimitiveProcessor(filterProcessor);\r
+ filterArea = new RootFilterArea(parameterExplorer.getExplorer(), filterProcessor, parameterExplorer, SWT.NONE);\r
+ filterArea.moveAbove(parameterExplorer.getExplorerComposite());\r
+\r
+ // IMPORTANT: without this property expandedness tracking will not work properly\r
+ parameterExplorer.getExplorer().setPrimitiveProcessor(new PropertyIsExpandedProcessor());\r
+ }\r
+\r
+ @Override\r
+ public IFilterArea getFilterArea() {\r
+ return filterArea;\r
+ }\r
+\r
+ @Override\r
+ public ISelectionProvider getSelectionProvider() {\r
+ return (ISelectionProvider) parameterExplorer.getAdapter(ISelectionProvider.class);\r
+ }\r
+\r
+}
\ No newline at end of file