1 package org.simantics.views.swt;
3 import org.eclipse.ui.IWorkbenchSite;
4 import org.simantics.Simantics;
5 import org.simantics.browsing.ui.common.ErrorLogger;
6 import org.simantics.browsing.ui.graph.impl.GraphInputSources;
7 import org.simantics.browsing.ui.graph.impl.InputSourceListener;
8 import org.simantics.browsing.ui.graph.impl.ObservableInputSource;
9 import org.simantics.browsing.ui.graph.impl.SessionContextInputSource;
10 import org.simantics.browsing.ui.graph.impl.WorkbenchSessionContextInputSource;
11 import org.simantics.db.ReadGraph;
12 import org.simantics.db.RequestProcessor;
13 import org.simantics.db.Resource;
14 import org.simantics.db.common.request.UniqueRead;
15 import org.simantics.db.exception.DatabaseException;
16 import org.simantics.db.layer0.variable.Variable;
17 import org.simantics.db.layer0.variable.VariableRepository;
18 import org.simantics.db.layer0.variable.Variables;
19 import org.simantics.scenegraph.INode;
20 import org.simantics.scenegraph.loader.ScenegraphLoaderProcess;
21 import org.simantics.views.ontology.ViewsResources;
22 import org.simantics.views.swt.client.base.SWTRoot;
24 public class SWTViewLoaderProcess extends ScenegraphLoaderProcess {
26 final private ModelledView view;
27 final private IWorkbenchSite site;
29 public static class ISL implements InputSourceListener {
31 private SWTViewLoaderProcess process;
33 ISL(SWTViewLoaderProcess process) {
34 this.process = process;
42 public void inputChanged(SessionContextInputSource source) {
43 if(process == null) return;
44 Object input = source.get( Simantics.getSessionContext() );
46 process.view.inputChanged(source.getProvider(), input);
48 ErrorLogger.defaultLogWarning("input source " + source + " invalidly returned null", new Exception("for stack trace only"));
52 ISL inputSourceListener = new ISL(this);
54 public SWTViewLoaderProcess(ModelledView view, IWorkbenchSite site, String name) {
58 this.root = new SWTRoot(site);
61 public SWTViewLoaderProcess(ModelledView view, IWorkbenchSite site) {
62 this(view, site, "<unnamed SWTViewLoaderProcess>");
66 public INode getRoot() {
71 protected void initialize(RequestProcessor processor, final Variable configuration) throws DatabaseException {
73 SessionContextInputSource inputSource = processor.sync(new UniqueRead<SessionContextInputSource>() {
75 public SessionContextInputSource perform(ReadGraph graph) throws DatabaseException {
76 ViewsResources VIEW = ViewsResources.getInstance(graph);
77 Resource represents = configuration.getRepresents(graph);
78 Resource inputSource = graph.getPossibleObject(represents, VIEW.HasInputSource);
79 if (inputSource == null)
80 return GraphInputSources.projectSource();
81 return graph.adapt(inputSource, SessionContextInputSource.class);
86 view.setInputSource(inputSource);
88 if (inputSource instanceof ObservableInputSource)
89 ((ObservableInputSource) inputSource).setListener(inputSourceListener);
91 if (inputSource instanceof WorkbenchSessionContextInputSource)
92 ((WorkbenchSessionContextInputSource) inputSource).init(site, view);
97 public void dispose() {
102 inputSourceListener.dispose();
103 for(String uri : registeredURIs) VariableRepository.unregister(uri);
104 SWTRoot r = (SWTRoot)root;