X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.views.swt%2Fsrc%2Forg%2Fsimantics%2Fviews%2Fswt%2FSWTViewLoaderProcess.java;h=a18638ed11b8249e5a29d871bf791f1f4f81015b;hb=894991ee53490cb8e28dd48b0da686203411324a;hp=f5c4d83bac5e39cb005ad41b564f7e89a3182152;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.views.swt/src/org/simantics/views/swt/SWTViewLoaderProcess.java b/bundles/org.simantics.views.swt/src/org/simantics/views/swt/SWTViewLoaderProcess.java index f5c4d83ba..a18638ed1 100644 --- a/bundles/org.simantics.views.swt/src/org/simantics/views/swt/SWTViewLoaderProcess.java +++ b/bundles/org.simantics.views.swt/src/org/simantics/views/swt/SWTViewLoaderProcess.java @@ -1,111 +1,111 @@ -package org.simantics.views.swt; - -import org.eclipse.ui.IWorkbenchSite; -import org.simantics.Simantics; -import org.simantics.browsing.ui.common.ErrorLogger; -import org.simantics.browsing.ui.graph.impl.GraphInputSources; -import org.simantics.browsing.ui.graph.impl.InputSourceListener; -import org.simantics.browsing.ui.graph.impl.ObservableInputSource; -import org.simantics.browsing.ui.graph.impl.SessionContextInputSource; -import org.simantics.browsing.ui.graph.impl.WorkbenchSessionContextInputSource; -import org.simantics.db.ReadGraph; -import org.simantics.db.RequestProcessor; -import org.simantics.db.Resource; -import org.simantics.db.common.request.UniqueRead; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.variable.Variable; -import org.simantics.db.layer0.variable.VariableRepository; -import org.simantics.db.layer0.variable.Variables; -import org.simantics.scenegraph.INode; -import org.simantics.scenegraph.loader.ScenegraphLoaderProcess; -import org.simantics.views.ontology.ViewsResources; -import org.simantics.views.swt.client.base.SWTRoot; - -public class SWTViewLoaderProcess extends ScenegraphLoaderProcess { - - final private ModelledView view; - final private IWorkbenchSite site; - - public static class ISL implements InputSourceListener { - - private SWTViewLoaderProcess process; - - ISL(SWTViewLoaderProcess process) { - this.process = process; - } - - void dispose() { - process = null; - } - - @Override - public void inputChanged(SessionContextInputSource source) { - if(process == null) return; - Object input = source.get( Simantics.getSessionContext() ); - if (input != null) - process.view.inputChanged(source.getProvider(), input); - else - ErrorLogger.defaultLogWarning("input source " + source + " invalidly returned null", new Exception("for stack trace only")); - } - }; - - ISL inputSourceListener = new ISL(this); - - public SWTViewLoaderProcess(ModelledView view, IWorkbenchSite site, String name) { - super(name); - this.view = view; - this.site = site; - this.root = new SWTRoot(site); - } - - public SWTViewLoaderProcess(ModelledView view, IWorkbenchSite site) { - this(view, site, ""); - } - - @Override - public INode getRoot() { - return root; - } - - @Override - protected void initialize(RequestProcessor processor, final Variable configuration) throws DatabaseException { - - SessionContextInputSource inputSource = processor.sync(new UniqueRead() { - @Override - public SessionContextInputSource perform(ReadGraph graph) throws DatabaseException { - ViewsResources VIEW = ViewsResources.getInstance(graph); - Resource represents = configuration.getRepresents(graph); - Resource inputSource = graph.getPossibleObject(represents, VIEW.HasInputSource); - if (inputSource == null) - return GraphInputSources.projectSource(); - return graph.adapt(inputSource, SessionContextInputSource.class); - } - }); - - if(view != null) - view.setInputSource(inputSource); - - if (inputSource instanceof ObservableInputSource) - ((ObservableInputSource) inputSource).setListener(inputSourceListener); - - if (inputSource instanceof WorkbenchSessionContextInputSource) - ((WorkbenchSessionContextInputSource) inputSource).init(site, view); - - } - - @Override - public void dispose() { - - if (isDisposed()) - return; - - inputSourceListener.dispose(); - for(String uri : registeredURIs) VariableRepository.unregister(uri); - SWTRoot r = (SWTRoot)root; - r.dispose(); - - super.dispose(); - - } - -} +package org.simantics.views.swt; + +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.Simantics; +import org.simantics.browsing.ui.common.ErrorLogger; +import org.simantics.browsing.ui.graph.impl.GraphInputSources; +import org.simantics.browsing.ui.graph.impl.InputSourceListener; +import org.simantics.browsing.ui.graph.impl.ObservableInputSource; +import org.simantics.browsing.ui.graph.impl.SessionContextInputSource; +import org.simantics.browsing.ui.graph.impl.WorkbenchSessionContextInputSource; +import org.simantics.db.ReadGraph; +import org.simantics.db.RequestProcessor; +import org.simantics.db.Resource; +import org.simantics.db.common.request.UniqueRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.VariableRepository; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.scenegraph.INode; +import org.simantics.scenegraph.loader.ScenegraphLoaderProcess; +import org.simantics.views.ontology.ViewsResources; +import org.simantics.views.swt.client.base.SWTRoot; + +public class SWTViewLoaderProcess extends ScenegraphLoaderProcess { + + final private ModelledView view; + final private IWorkbenchSite site; + + public static class ISL implements InputSourceListener { + + private SWTViewLoaderProcess process; + + ISL(SWTViewLoaderProcess process) { + this.process = process; + } + + void dispose() { + process = null; + } + + @Override + public void inputChanged(SessionContextInputSource source) { + if(process == null) return; + Object input = source.get( Simantics.getSessionContext() ); + if (input != null) + process.view.inputChanged(source.getProvider(), input); + else + ErrorLogger.defaultLogWarning("input source " + source + " invalidly returned null", new Exception("for stack trace only")); + } + }; + + ISL inputSourceListener = new ISL(this); + + public SWTViewLoaderProcess(ModelledView view, IWorkbenchSite site, String name) { + super(name); + this.view = view; + this.site = site; + this.root = new SWTRoot(site); + } + + public SWTViewLoaderProcess(ModelledView view, IWorkbenchSite site) { + this(view, site, ""); + } + + @Override + public INode getRoot() { + return root; + } + + @Override + protected void initialize(RequestProcessor processor, final Variable configuration) throws DatabaseException { + + SessionContextInputSource inputSource = processor.sync(new UniqueRead() { + @Override + public SessionContextInputSource perform(ReadGraph graph) throws DatabaseException { + ViewsResources VIEW = ViewsResources.getInstance(graph); + Resource represents = configuration.getRepresents(graph); + Resource inputSource = graph.getPossibleObject(represents, VIEW.HasInputSource); + if (inputSource == null) + return GraphInputSources.projectSource(); + return graph.adapt(inputSource, SessionContextInputSource.class); + } + }); + + if(view != null) + view.setInputSource(inputSource); + + if (inputSource instanceof ObservableInputSource) + ((ObservableInputSource) inputSource).setListener(inputSourceListener); + + if (inputSource instanceof WorkbenchSessionContextInputSource) + ((WorkbenchSessionContextInputSource) inputSource).init(site, view); + + } + + @Override + public void dispose() { + + if (isDisposed()) + return; + + inputSourceListener.dispose(); + for(String uri : registeredURIs) VariableRepository.unregister(uri); + SWTRoot r = (SWTRoot)root; + r.dispose(); + + super.dispose(); + + } + +}