]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Close Plant3DEditor automatically when its input disappears from DB 71/3971/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 5 Mar 2020 21:32:32 +0000 (23:32 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 5 Mar 2020 21:32:32 +0000 (23:32 +0200)
gitlab #102

Change-Id: Ifeaf13c1c9f8e000dbcd7a5ef4e6351ae1cff1a2

org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java

index 96789ff11770b871412d5e2d9aaff09bdee0579b..72f2c2066e4329bcac5c306786805ce4146eff01 100644 (file)
@@ -26,8 +26,10 @@ import org.simantics.Simantics;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.Session;
+import org.simantics.db.common.request.ParametrizedRead;
 import org.simantics.db.common.request.ReadRequest;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.request.combinations.Combinators;
 import org.simantics.g3d.scenegraph.NodeMap;
 import org.simantics.g3d.scenegraph.RenderListener;
 import org.simantics.g3d.scenegraph.base.INode;
@@ -78,6 +80,7 @@ import org.simantics.selectionview.StandardPropertyPage;
 import org.simantics.ui.workbench.IPropertyPage;
 import org.simantics.ui.workbench.IResourceEditorInput;
 import org.simantics.ui.workbench.ResourceEditorPart;
+import org.simantics.ui.workbench.editor.input.InputValidationCombinators;
 import org.simantics.utils.threads.ThreadUtils;
 import org.simantics.utils.ui.ExceptionUtils;
 
@@ -128,25 +131,23 @@ public class Plant3DEditor extends ResourceEditorPart {
        public static final int X = 0, Y = 1, Z = 2;
        
        protected int upDirection = 1;
-       
+
+       ParametrizedRead<IResourceEditorInput, Boolean> INPUT_VALIDATOR =
+                       Combinators.compose(
+                                       InputValidationCombinators.hasURI(),
+                                       InputValidationCombinators.extractInputResource()
+                                       );
+
+       @Override
+       protected ParametrizedRead<IResourceEditorInput, Boolean> getInputValidator() {
+               return INPUT_VALIDATOR;
+       }
+
        @Override
        public void createPartControl(Composite parent) {
                this.parent = parent;
-               //parent.setLayout (new FillLayout ());
-               
-        
-//             component = new SWTAWTComponent(parent,SWT.NONE) {
-//                     
-//                     @Override
-//                     protected Component createSwingComponent() {
-//                             if (panel == null) {
-//                                     panel = new InteractiveVtkPanel();
-//                                     vtkPanelUtil.registerPanel(panel);
-//                                     createScene();
-//                             }
-//                             return panel;
-//                     }
-//             };
+
+               activateValidation();
 
                IResourceEditorInput rei = (IResourceEditorInput)getEditorInput();
                input = rei.getResource();
@@ -322,7 +323,7 @@ public class Plant3DEditor extends ResourceEditorPart {
                             ExceptionUtils.logAndShowError("Failed to load model correctly", e);
                         }
                                        
-                                       List<vtkProp3D> props = new ArrayList<vtkProp3D>();
+                                       List<vtkProp3D> props = new ArrayList<>();
                                        collectProps(rootNode, props);
                                        fitToWindow(props);
                     }
@@ -515,19 +516,27 @@ public class Plant3DEditor extends ResourceEditorPart {
                }
        }
 
+       private class FitToWindow extends Action {
+               private List<INode> selected;
+               public FitToWindow(List<INode> selected) {
+                       super("Fit to Window");
+                       this.selected = selected;
+                       //setAccelerator('1');
+               }
+               @Override
+               public void run() {
+                       List<vtkProp3D> props = new ArrayList<>();
+                       final Collection<INode> collection = !selected.isEmpty() ? selected : getRootNode().getChild();
+                       for (INode n : collection)
+                               collectProps(n, props);
+
+                       fitToWindow(props);
+                       getPanel().refresh();
+               }
+       }
+
        protected void createFocusMenu(IMenuManager m, List<INode> selected) {
-               m.add(new Action("Fit to Window") {
-                       @Override
-                       public void run() {
-                               List<vtkProp3D> props = new ArrayList<>();
-                               final Collection<INode> collection = !selected.isEmpty() ? selected : getRootNode().getChild();
-                               for (INode n : collection)
-                                       collectProps(n, props);
-                               
-                               fitToWindow(props);
-                               getPanel().refresh();
-                       }
-               });
+               m.add(new FitToWindow(selected));
 
                if (!selected.isEmpty()) {
                        List<vtkProp3D> actors = new ArrayList<>();