]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java
Avoid extra write transactions when opening Plant3D editor
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / editor / Plant3DEditor.java
index 72f2c2066e4329bcac5c306786805ce4146eff01..b4448e670749caef8e30b8685d33422eb922cb55 100644 (file)
@@ -7,6 +7,7 @@ import java.util.List;
 import java.util.Set;
 
 import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.action.IMenuListener;
 import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.MenuManager;
@@ -303,34 +304,44 @@ public class Plant3DEditor extends ResourceEditorPart {
                        
                        @Override
                        public void run() {
+                               nodeMap.setChangeTracking(false);
                                nodeMap.populate();
+                               nodeMap.setChangeTracking(true);
                                panel.addListener(new RenderListener() {
-                    
-                    @Override
-                    public void preRender() {
-                   
-                    }
-                    
-                    @Override
-                    public void postRender() {
-                        panel.removeListener(this);
-                        
-                        try {
-                            P3DUtil.finalizeDBLoad2(rootNode);
-                            if (nodeMap.isRangeModified());
-                                nodeMap.commit("Load sync");
-                        } catch (Exception e) {
-                            ExceptionUtils.logAndShowError("Failed to load model correctly", e);
-                        }
-                                       
-                                       List<vtkProp3D> props = new ArrayList<>();
-                                       collectProps(rootNode, props);
-                                       fitToWindow(props);
-                    }
-                });
+
+                                       @Override
+                                       public void preRender() {
+
+                                       }
+
+                                       @Override
+                                       public void postRender() {
+                                               panel.removeListener(this);
+
+                                               try {
+                                                       P3DUtil.finalizeDBLoad2(rootNode);
+                                                       if (nodeMap.getMapping().isRangeModified())
+                                                               nodeMap.commit("Load sync");
+                                               } catch (Exception e) {
+                                                       ExceptionUtils.logAndShowError("Failed to load model correctly", e);
+                                               }
+                                               
+                                               onEditorInitializationComplete();
+                                               
+                                               List<vtkProp3D> props = new ArrayList<>();
+                                               collectProps(rootNode, props);
+                                               fitToWindow(props);
+                                       }
+                               });
                        }
                });
-               
+
+       }
+
+       /**
+        * This can be overridden by clients to perform extra initialization tasks
+        */
+       protected void onEditorInitializationComplete() {
        }
        
        protected IMappingSchema<Resource, INode> getSchema(ReadGraph graph) throws DatabaseException {
@@ -516,7 +527,7 @@ public class Plant3DEditor extends ResourceEditorPart {
                }
        }
 
-       private class FitToWindow extends Action {
+       protected class FitToWindow extends Action {
                private List<INode> selected;
                public FitToWindow(List<INode> selected) {
                        super("Fit to Window");
@@ -536,7 +547,7 @@ public class Plant3DEditor extends ResourceEditorPart {
        }
 
        protected void createFocusMenu(IMenuManager m, List<INode> selected) {
-               m.add(new FitToWindow(selected));
+               m.add(createFitToWindowAction(selected));
 
                if (!selected.isEmpty()) {
                        List<vtkProp3D> actors = new ArrayList<>();
@@ -548,7 +559,11 @@ public class Plant3DEditor extends ResourceEditorPart {
                        }
                }
        }
-       
+
+       protected IAction createFitToWindowAction(List<INode> selected) {
+               return new FitToWindow(selected);
+       }
+
        private IContentOutlinePage createOutline() {
                if (rootNode == null || selectionProvider == null)
                        return null;