From 500980aa0ed16105db4724fdf61197ada19d043d Mon Sep 17 00:00:00 2001 From: luukkainen Date: Mon, 27 Oct 2008 14:25:52 +0000 Subject: [PATCH] git-svn-id: https://www.simantics.org/svn/simantics/3d/branches/dev@7286 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../proconf/g3d/base/EditorLoader.java | 51 +++++++++++++++++++ .../g3d/base/ThreeDimensionalEditorPart.java | 30 ++--------- .../proconf/g3d/common/JmeComposite.java | 12 +++++ 3 files changed, 68 insertions(+), 25 deletions(-) create mode 100644 org.simantics.proconf.g3d/src/org/simantics/proconf/g3d/base/EditorLoader.java diff --git a/org.simantics.proconf.g3d/src/org/simantics/proconf/g3d/base/EditorLoader.java b/org.simantics.proconf.g3d/src/org/simantics/proconf/g3d/base/EditorLoader.java new file mode 100644 index 00000000..dcc6cfca --- /dev/null +++ b/org.simantics.proconf.g3d/src/org/simantics/proconf/g3d/base/EditorLoader.java @@ -0,0 +1,51 @@ +package org.simantics.proconf.g3d.base; + +import org.eclipse.ui.IPartListener; +import org.eclipse.ui.IWorkbenchPart; + +/** + * IPartListener that allows editor to load its content after the editorPart is activated. + * + * This is crucial with 3D graphics, which does not work if the editor part is activated + * after the data has been loaded. + * + * @author Marko Luukkainen + * + */ +public abstract class EditorLoader implements IPartListener { + + boolean opened = false; + boolean activated = false; + + public void partOpened(IWorkbenchPart part) { + if (part.equals(getWorkbechPart())) { + opened = true; + } + } + + public void partActivated(IWorkbenchPart part) { + if (part.equals(getWorkbechPart())) { + if (opened & !activated) { + activated = true; + load(); + } + } + } + + public void partBroughtToTop(IWorkbenchPart part) {} + + public void partClosed(IWorkbenchPart part) {} + + public void partDeactivated(IWorkbenchPart part) {} + + /** + * Returns the IWorkbenchPart of the editor + * @return + */ + public abstract IWorkbenchPart getWorkbechPart(); + + /** + * Starts the content loading process + */ + public abstract void load(); +} diff --git a/org.simantics.proconf.g3d/src/org/simantics/proconf/g3d/base/ThreeDimensionalEditorPart.java b/org.simantics.proconf.g3d/src/org/simantics/proconf/g3d/base/ThreeDimensionalEditorPart.java index 4ad22bd2..f2f3bc12 100644 --- a/org.simantics.proconf.g3d/src/org/simantics/proconf/g3d/base/ThreeDimensionalEditorPart.java +++ b/org.simantics.proconf.g3d/src/org/simantics/proconf/g3d/base/ThreeDimensionalEditorPart.java @@ -49,33 +49,13 @@ public abstract class ThreeDimensionalEditorPart extends ResourceEditorPart impl editor = createEditor(getSessionContext()); // add partlistener that loads the scene-graph when the view has been created - this.getEditorSite().getPage().addPartListener(new IPartListener() { - - boolean opened = false; - boolean activated = false; - - public void partOpened(IWorkbenchPart part) { - if (part.equals(ThreeDimensionalEditorPart.this.getEditorSite().getPart())) { - opened = true; - } - } - - public void partActivated(IWorkbenchPart part) { - if (part.equals(ThreeDimensionalEditorPart.this.getEditorSite().getPart())) { - if (opened & !activated) { - activated = true; - load(); - } - } + this.getEditorSite().getPage().addPartListener(new EditorLoader() { + + public IWorkbenchPart getWorkbechPart() { + return ThreeDimensionalEditorPart.this.getEditorSite().getPart(); } - public void partBroughtToTop(IWorkbenchPart part) {} - - public void partClosed(IWorkbenchPart part) {} - - public void partDeactivated(IWorkbenchPart part) {} - - private void load() { + public void load() { //System.out.println("ThreeDimensionalEditorPart.reload()"); Session ses = ThreeDimensionalEditorPart.this.getSession(); GraphRequestAdapter r = new GraphRequestAdapter() { diff --git a/org.simantics.proconf.g3d/src/org/simantics/proconf/g3d/common/JmeComposite.java b/org.simantics.proconf.g3d/src/org/simantics/proconf/g3d/common/JmeComposite.java index 5cff3ffb..b1155728 100644 --- a/org.simantics.proconf.g3d/src/org/simantics/proconf/g3d/common/JmeComposite.java +++ b/org.simantics.proconf.g3d/src/org/simantics/proconf/g3d/common/JmeComposite.java @@ -17,6 +17,8 @@ import org.eclipse.core.runtime.Path; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ControlAdapter; import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.opengl.GLCanvas; @@ -55,6 +57,14 @@ public class JmeComposite extends Composite { } }); +// this.addPaintListener(new PaintListener() { +// @Override +// public void paintControl(PaintEvent e) { +// displaySystem.setCurrent(); +// JmeComposite.this.component.render(); +// } +// }); + } @@ -109,4 +119,6 @@ public class JmeComposite extends Composite { public DisplaySystem getDisplaySystem() { return displaySystem; } + + } -- 2.47.1