]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/property/P3DSelectionProcessor.java
Add units to ComponentSelectionDialog
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / property / P3DSelectionProcessor.java
index 3bef85b501ddcfb0cb4a4e99f341596af5d18fef..b78fac4e1bb58e020fa4e6dfe159a3ea98655024 100644 (file)
@@ -3,6 +3,7 @@ package org.simantics.plant3d.property;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+import java.util.function.Consumer;
 
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.swt.widgets.Composite;
@@ -18,7 +19,7 @@ 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.scenegraph.base.INode;
 import org.simantics.g3d.tools.AdaptationUtils;
 import org.simantics.g3d.vtk.property.VTKPropertyTabContributor;
 import org.simantics.objmap.structural.StructuralResource;
@@ -26,7 +27,6 @@ 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 org.simantics.utils.threads.SWTThread;
 
 import vtk.vtkProp;
@@ -43,7 +43,7 @@ public class P3DSelectionProcessor implements SelectionProcessor<Object, ReadGra
                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);
+               Collection<INode> nodeCollection = AdaptationUtils.adaptToCollection(selection, INode.class);
                boolean readOnly = false;
                if (resourceCollection.size() == 0 && structuralResourceCollection.size() > 0) {
                        for (StructuralResource sr : structuralResourceCollection) {
@@ -55,7 +55,7 @@ public class P3DSelectionProcessor implements SelectionProcessor<Object, ReadGra
 
 
                if (nodeCollection.size() == 1) {
-                       IG3DNode node = nodeCollection.iterator().next();
+                       INode node = nodeCollection.iterator().next();
                        List<PropertyTabContributor> contributors = PropertyTabUtil.getContributors(node);
                        int i = 100;
                        for (PropertyTabContributor c : contributors) {
@@ -70,7 +70,7 @@ public class P3DSelectionProcessor implements SelectionProcessor<Object, ReadGra
                                        throw new NullPointerException();
                                result.add(new ComparableTabContributor(new VTKPropertyTabContributor(SWTThread.getThreadAccess()), -2, prop, "VTK"));
                        }
-
+                       
                        if (resourceCollection.size() > 0) {
                                if (resourceCollection.size() > 1)
                                        result.add(new ComparableTabContributor(new MultiSelectionTabContibutor(),0, resourceCollection, "Graph"));
@@ -83,9 +83,18 @@ public class P3DSelectionProcessor implements SelectionProcessor<Object, ReadGra
                                                e.printStackTrace();
                                        }
                                }
-                       }  
+                       }
                }
 
+               if (resourceCollection.size() == 1){
+                       try {
+                               Resource r = resourceCollection.iterator().next();
+                               result.add(new ComparableTabContributor(new P3DBasicPropertyTab(!readOnly), 0, r, "Properties"));
+                       } catch (Exception e) {
+                               e.printStackTrace();
+                       }
+               }
+               
                if(result.size() == 0) {
                        result.add(new ComparableTabContributor(new NoneSelectionTabContributor(),0, resourceCollection, "Empty"));
                }
@@ -99,14 +108,20 @@ public class P3DSelectionProcessor implements SelectionProcessor<Object, ReadGra
                public P3DBasicPropertyTab(boolean enabled) {
                        this.enabled = enabled;
                }
-               public void updatePartName(ISelection forSelection, Callback<String> updateCallback) {
+               
+               
+
+               @Override
+               public void updatePartName(ISelection forSelection, Consumer<String> updateCallback) {
                        Read<String> read = getPartNameReadRequest(forSelection);
                        if (read == null) {
-                               updateCallback.run("Override to control part name (PropertyTabContributorImpl.updatePartName)");
+                               updateCallback.accept("Override to control part name (PropertyTabContributorImpl.updatePartName)");
                        } else {
                                Simantics.getSession().asyncRequest(read, new PartNameListener(updateCallback));
                        }
                }
+
+               @Override
                public Read<String> getPartNameReadRequest(ISelection forSelection) {
                        final Resource r  =  AdaptationUtils.adaptToSingle(forSelection, Resource.class);
                        if (r == null)
@@ -131,10 +146,12 @@ public class P3DSelectionProcessor implements SelectionProcessor<Object, ReadGra
 
 
        public class MultiSelectionTabContibutor extends PropertyTabContributorImpl {
+               @Override
                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);
                }
 
+               @Override
                public Read<String> getPartNameReadRequest(ISelection forSelection) {
                        final Collection<Resource> coll =  AdaptationUtils.adaptToCollection(forSelection, Resource.class);
                        if (coll.size() == 0)
@@ -161,8 +178,9 @@ public class P3DSelectionProcessor implements SelectionProcessor<Object, ReadGra
 
                }
 
-               public void updatePartName(ISelection forSelection, Callback<String> updateCallback) {
-                       updateCallback.run("No Selection");
+               //@Override
+               public void updatePartName(ISelection forSelection, Consumer<String> updateCallback) {
+                       updateCallback.accept("No Selection");
                }
        }