From: Tuukka Lehtonen Date: Thu, 5 Mar 2020 21:32:32 +0000 (+0200) Subject: Close Plant3DEditor automatically when its input disappears from DB X-Git-Tag: v1.43.0~47 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F71%2F3971%2F1;p=simantics%2F3d.git Close Plant3DEditor automatically when its input disappears from DB gitlab #102 Change-Id: Ifeaf13c1c9f8e000dbcd7a5ef4e6351ae1cff1a2 --- diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java b/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java index 96789ff1..72f2c206 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java @@ -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 INPUT_VALIDATOR = + Combinators.compose( + InputValidationCombinators.hasURI(), + InputValidationCombinators.extractInputResource() + ); + + @Override + protected ParametrizedRead 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 props = new ArrayList(); + List props = new ArrayList<>(); collectProps(rootNode, props); fitToWindow(props); } @@ -515,19 +516,27 @@ public class Plant3DEditor extends ResourceEditorPart { } } + private class FitToWindow extends Action { + private List selected; + public FitToWindow(List selected) { + super("Fit to Window"); + this.selected = selected; + //setAccelerator('1'); + } + @Override + public void run() { + List props = new ArrayList<>(); + final Collection collection = !selected.isEmpty() ? selected : getRootNode().getChild(); + for (INode n : collection) + collectProps(n, props); + + fitToWindow(props); + getPanel().refresh(); + } + } + protected void createFocusMenu(IMenuManager m, List selected) { - m.add(new Action("Fit to Window") { - @Override - public void run() { - List props = new ArrayList<>(); - final Collection 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 actors = new ArrayList<>();