--- /dev/null
+package org.simantics.plant3d.property;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IWorkbenchSite;
+import org.simantics.Simantics;
+import org.simantics.browsing.ui.swt.PartNameListener;
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.management.ISessionContext;
+import org.simantics.db.request.Read;
+import org.simantics.g3d.property.PropertyTabContributor;
+import org.simantics.g3d.property.PropertyTabUtil;
+import org.simantics.g3d.scenegraph.IG3DNode;
+import org.simantics.g3d.tools.AdaptationUtils;
+import org.simantics.g3d.vtk.property.VTKPropertyTabContributor;
+import org.simantics.objmap.structural.StructuralResource;
+import org.simantics.selectionview.BasicPropertyTab;
+import org.simantics.selectionview.ComparableTabContributor;
+import org.simantics.selectionview.PropertyTabContributorImpl;
+import org.simantics.selectionview.SelectionProcessor;
+import org.simantics.utils.datastructures.Callback;
+
+import vtk.vtkProp;
+
+public class P3DSelectionProcessor implements SelectionProcessor<Object, ReadGraph> {
+
+ private static final boolean DEBUG = false;
+ @Override
+ public Collection<?> process(Object selection, ReadGraph backend) {
+// System.out.println(getClass().getSimpleName() + " incoming selection: " + ObjectUtils.toString(selection));
+
+
+ Collection<ComparableTabContributor> result = new ArrayList<ComparableTabContributor>();
+ Collection<Resource> resourceCollection = AdaptationUtils.adaptToCollection(selection, Resource.class);
+ Collection<StructuralResource> structuralResourceCollection = AdaptationUtils.adaptToCollection(selection, StructuralResource.class);
+ Collection<vtkProp> propCollection = AdaptationUtils.adaptToCollection(selection, vtkProp.class);
+ Collection<IG3DNode> nodeCollection = AdaptationUtils.adaptToCollection(selection, IG3DNode.class);
+ boolean readOnly = false;
+ if (resourceCollection.size() == 0 && structuralResourceCollection.size() > 0) {
+ for (StructuralResource sr : structuralResourceCollection) {
+ if (sr.isStructural() && !sr.isStructuralRoot())
+ readOnly = true;
+ resourceCollection.add(sr.getResource());
+ }
+ }
+
+
+ if (nodeCollection.size() == 1) {
+ IG3DNode node = nodeCollection.iterator().next();
+ List<PropertyTabContributor> contributors = PropertyTabUtil.getContributors(node);
+ int i = 100;
+ for (PropertyTabContributor c : contributors) {
+ result.add(new ComparableTabContributor(c, i--, node, c.getId()));
+ }
+ }
+
+ if (DEBUG) {
+ if (propCollection.size() == 1) {
+ vtkProp prop = propCollection.iterator().next();
+ if (prop == null)
+ throw new NullPointerException();
+ result.add(new ComparableTabContributor(new VTKPropertyTabContributor(), -2, prop, "VTK"));
+ }
+
+ if (resourceCollection.size() > 0) {
+ if (resourceCollection.size() > 1)
+ result.add(new ComparableTabContributor(new MultiSelectionTabContibutor(),0, resourceCollection, "Graph"));
+ else if (resourceCollection.size() == 1){
+ try {
+ Resource r = resourceCollection.iterator().next();
+ result.add(new ComparableTabContributor(new P3DBasicPropertyTab(!readOnly), 0, r, "Graph"));
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ if(result.size() == 0) {
+ result.add(new ComparableTabContributor(new NoneSelectionTabContributor(),0, resourceCollection, "Empty"));
+ }
+
+ return result;
+ }
+
+ public class P3DBasicPropertyTab extends BasicPropertyTab {
+
+ boolean enabled;
+ public P3DBasicPropertyTab(boolean enabled) {
+ this.enabled = enabled;
+ }
+ public void updatePartName(ISelection forSelection, Callback<String> updateCallback) {
+ Read<String> read = getPartNameReadRequest(forSelection);
+ if (read == null) {
+ updateCallback.run("Override to control part name (PropertyTabContributorImpl.updatePartName)");
+ } else {
+ Simantics.getSession().asyncRequest(read, new PartNameListener(updateCallback));
+ }
+ }
+ public Read<String> getPartNameReadRequest(ISelection forSelection) {
+ final Resource r = AdaptationUtils.adaptToSingle(forSelection, Resource.class);
+ if (r == null)
+ return null;
+ return new Read<String>() {
+ @Override
+ public String perform(ReadGraph graph) throws DatabaseException {
+ return NameUtils.getSafeName(graph, r);
+ }
+ };
+ }
+
+ @Override
+ public void createControls(Composite body, IWorkbenchSite site,
+ ISessionContext context, WidgetSupport support) {
+ // TODO Auto-generated method stub
+ super.createControls(body, site, context, support);
+ ((Composite)parameterExplorer.getExplorerControl()).setEnabled(enabled);
+ }
+ }
+
+
+
+ public class MultiSelectionTabContibutor extends PropertyTabContributorImpl {
+ public void createControls(org.eclipse.swt.widgets.Composite body, org.eclipse.ui.IWorkbenchSite site, org.simantics.db.management.ISessionContext context, org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport support) {
+ //Composite composite = new Composite(body, SWT.NONE);
+ }
+
+ public Read<String> getPartNameReadRequest(ISelection forSelection) {
+ final Collection<Resource> coll = AdaptationUtils.adaptToCollection(forSelection, Resource.class);
+ if (coll.size() == 0)
+ return null;
+ return new Read<String>() {
+ @Override
+ public String perform(ReadGraph graph) throws DatabaseException {
+ String title = "";
+ for (Resource r : coll) {
+ title += NameUtils.getSafeName(graph, r) +",";
+ }
+ System.out.println(title);
+ return title.substring(0,title.length()-1);
+ }
+ };
+ }
+ }
+
+ public class NoneSelectionTabContributor extends PropertyTabContributorImpl {
+ @Override
+ public void createControls(Composite body, IWorkbenchSite site,
+ ISessionContext context, WidgetSupport support) {
+ //Composite composite = new Composite(body, SWT.NONE);
+
+ }
+
+ public void updatePartName(ISelection forSelection, Callback<String> updateCallback) {
+ updateCallback.run("No Selection");
+ }
+ }
+
+
+}