]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.selectionview/src/org/simantics/selectionview/BasicPropertyTab.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.selectionview / src / org / simantics / selectionview / BasicPropertyTab.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
3  * Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.selectionview;
13
14 import java.util.function.Consumer;
15
16 import org.eclipse.jface.layout.GridDataFactory;
17 import org.eclipse.jface.viewers.ISelection;
18 import org.eclipse.jface.viewers.ISelectionProvider;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Control;
22 import org.eclipse.swt.widgets.Tree;
23 import org.eclipse.ui.IWorkbenchSite;
24 import org.simantics.browsing.ui.Column;
25 import org.simantics.browsing.ui.Column.Align;
26 import org.simantics.browsing.ui.GraphExplorer;
27 import org.simantics.browsing.ui.common.ColumnKeys;
28 import org.simantics.browsing.ui.common.EvaluatorData;
29 import org.simantics.browsing.ui.common.EvaluatorData.Evaluator;
30 import org.simantics.browsing.ui.common.comparators.AlphanumericComparatorFactory;
31 import org.simantics.browsing.ui.common.processors.FilterSelectionRequestQueryProcessor;
32 import org.simantics.browsing.ui.common.views.IFilterArea;
33 import org.simantics.browsing.ui.graph.impl.ArrayPropertyLabelerFactory;
34 import org.simantics.browsing.ui.graph.impl.ArrayPropertyValueViewpointFactory;
35 import org.simantics.browsing.ui.graph.impl.PropertyViewpointFactory;
36 import org.simantics.browsing.ui.graph.impl.RelationContextLabelerFactory;
37 import org.simantics.browsing.ui.graph.impl.ResourceProperty;
38 import org.simantics.browsing.ui.graph.impl.StringRepresentationLabelerFactory;
39 import org.simantics.browsing.ui.swt.ArrayPropertyImagerFactory;
40 import org.simantics.browsing.ui.swt.PropertyIsExpandedProcessor;
41 import org.simantics.browsing.ui.swt.PropertyLabelDecoratorFactory;
42 import org.simantics.browsing.ui.swt.RootFilterArea;
43 import org.simantics.browsing.ui.swt.SingleSelectionInputSource;
44 import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;
45 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
46 import org.simantics.db.RelationContext;
47 import org.simantics.db.Resource;
48 import org.simantics.db.Statement;
49 import org.simantics.db.common.ResourceArray;
50 import org.simantics.db.management.ISessionContext;
51 import org.simantics.utils.datastructures.ArrayMap;
52
53 /**
54  * @author Tuukka Lehtonen
55  */
56 public class BasicPropertyTab extends PropertyTabContributorImpl {
57
58     protected RootFilterArea         filterArea;
59     protected GraphExplorerComposite parameterExplorer;
60
61     public void updatePartName(ISelection forSelection, Consumer<String> updateCallback) {
62         updateCallback.accept(null);
63     }
64
65     protected void initializeExplorerWithEvaluator(GraphExplorer explorer, ISessionContext context,
66             EvaluatorData data) {
67
68         Evaluator resourceEvaluator = data.newEvaluator()
69                 .addViewpoint(new PropertyViewpointFactory(), 1.0)
70                 .addComparator(new AlphanumericComparatorFactory(ColumnKeys.PROPERTY), 2.0)
71                 .addComparator(new AlphanumericComparatorFactory(ColumnKeys.PROPERTY, true), 1.0)
72                 .addLabeler(new StringRepresentationLabelerFactory(ColumnKeys.PROPERTY), 1.0);
73
74         Evaluator statementEvaluator = data.newEvaluator()
75                 .addViewpoint(new PropertyViewpointFactory(), 1.0)
76                 .addComparator(new AlphanumericComparatorFactory(ColumnKeys.PROPERTY), 2.0)
77                 .addComparator(new AlphanumericComparatorFactory(ColumnKeys.PROPERTY, true), 1.0);
78
79         Evaluator relationContextEvaluator = data.newEvaluator()
80                 .addLabeler(new RelationContextLabelerFactory(), 1.0);
81
82         Evaluator propertyEvaluator = data.newEvaluator()
83                 .addViewpoint(new ArrayPropertyValueViewpointFactory(), 1.0)
84                 .addLabeler(new ArrayPropertyLabelerFactory(), 1.0)
85                 .addImager(new ArrayPropertyImagerFactory(), 1.0)
86                 .addLabelDecorator(new PropertyLabelDecoratorFactory(), 1.0);
87
88         data.addEvaluator(Resource.class, resourceEvaluator);
89         data.addEvaluator(ResourceArray.class, resourceEvaluator);
90         data.addEvaluator(Statement.class, statementEvaluator);
91         data.addEvaluator(RelationContext.class, relationContextEvaluator);
92         data.addEvaluator(ResourceProperty.class, propertyEvaluator);
93         
94     }
95
96     @Override
97     public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {
98         Column[] COLUMNS = new Column[] {
99                 new Column(ColumnKeys.PROPERTY, Align.LEFT, 175, "Property Name", true, 1),
100                 new Column(ColumnKeys.VALUE, Align.LEFT, 175, "Value of Property", true, 3)
101         };
102
103         parameterExplorer = new GraphExplorerComposite(
104                 ArrayMap.keys("displaySelectors", "displayFilter").values(false, false),
105                 site, body, support, SWT.FULL_SELECTION | SWT.MULTI) {
106             @Override
107             protected void initializeExplorerWithEvaluator(GraphExplorer explorer, ISessionContext context, EvaluatorData data) {
108                 BasicPropertyTab.this.initializeExplorerWithEvaluator(explorer, context, data);
109             }
110         };
111         // Must set, even if empty.
112         parameterExplorer.setBrowseContexts();
113         //parameterExplorer.setStatePersistor(new IdentifiedStatePersistor(getClass().getCanonicalName()));
114         parameterExplorer.setContextMenuId("#PropertiesPopup");
115         parameterExplorer.setEditingColumn(ColumnKeys.VALUE);
116         parameterExplorer.setColumns(COLUMNS);
117         parameterExplorer.setInputSource(new SingleSelectionInputSource(Resource.class));
118         parameterExplorer.finish();
119         GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(parameterExplorer);
120
121         Control c = parameterExplorer.getExplorerControl();
122         if (c instanceof Tree)
123             ((Tree) c).setLinesVisible(true);
124
125         FilterSelectionRequestQueryProcessor filterProcessor = new FilterSelectionRequestQueryProcessor();
126         parameterExplorer.getExplorer().setPrimitiveProcessor(filterProcessor);
127         filterArea = new RootFilterArea(parameterExplorer.getExplorer(), filterProcessor, parameterExplorer, SWT.NONE);
128         filterArea.moveAbove(parameterExplorer.getExplorerComposite());
129
130         // IMPORTANT: without this property expandedness tracking will not work properly
131         parameterExplorer.getExplorer().setPrimitiveProcessor(new PropertyIsExpandedProcessor());
132     }
133
134     @Override
135     public IFilterArea getFilterArea() {
136         return filterArea;
137     }
138
139     @Override
140     public ISelectionProvider getSelectionProvider() {
141         return (ISelectionProvider) parameterExplorer.getAdapter(ISelectionProvider.class);
142     }
143
144 }