X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.views.swt%2Fsrc%2Forg%2Fsimantics%2Fviews%2Fswt%2FModelledWizard.java;h=0749b7e1133a0fb6e6406f36419d8ee033e74d85;hb=894991ee53490cb8e28dd48b0da686203411324a;hp=70d8c9c1f47bd6b958f46cf9410815f2de609d30;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.views.swt/src/org/simantics/views/swt/ModelledWizard.java b/bundles/org.simantics.views.swt/src/org/simantics/views/swt/ModelledWizard.java index 70d8c9c1f..0749b7e11 100644 --- a/bundles/org.simantics.views.swt/src/org/simantics/views/swt/ModelledWizard.java +++ b/bundles/org.simantics.views.swt/src/org/simantics/views/swt/ModelledWizard.java @@ -1,176 +1,176 @@ -package org.simantics.views.swt; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.IWizardPage; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.IWorkbenchWizard; -import org.simantics.Simantics; -import org.simantics.browsing.ui.swt.ModelledAction; -import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; -import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.VirtualGraph; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.primitiverequest.PossibleAdapter; -import org.simantics.db.common.request.WriteResultRequest; -import org.simantics.db.common.utils.ListUtils; -import org.simantics.db.common.utils.Logger; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.management.ISessionContext; -import org.simantics.db.request.Read; -import org.simantics.layer0.Layer0; -import org.simantics.scenegraph.ontology.ScenegraphResources; -import org.simantics.scl.runtime.function.Function1; -import org.simantics.views.ontology.ViewsResources; - -/** - * @author Tuukka Lehtonen - */ -public class ModelledWizard extends Wizard implements IWorkbenchWizard, ModelledAction { - - final String configurationURI; - - final private ArrayList pages = new ArrayList(); - final private ArrayList modelledPages = new ArrayList(); - - - private Function1 finishAction; - private Resource runtime; - - public ModelledWizard(String configurationURI) { - setNeedsProgressMonitor(true); - this.configurationURI = configurationURI; - } - - public List getModelledPages() { - return modelledPages; - } - - @Override - public void addPages() { - super.addPages(); - for(IWizardPage page : pages) addPage(page); - } - - @Override - public boolean performFinish() { - - finishAction.apply(this); - return true; - - } - - public void loadPages(IWorkbenchSite site, ISessionContext context, final WidgetSupport support) throws DatabaseException { - - runtime = Simantics.getSession().sync(new WriteResultRequest(Simantics.getSession().getService(VirtualGraph.class)) { - @Override - public Resource perform(WriteGraph graph) throws DatabaseException { - Layer0 L0 = Layer0.getInstance(graph); - ScenegraphResources SG = ScenegraphResources.getInstance(graph); - Resource runtime = graph.newResource(); - graph.claim(runtime, L0.InstanceOf, null, SG.Runtime); - return runtime; - } - }); - - finishAction = Simantics.getSession().syncRequest(new Read>() { - @Override - public Function1 perform(ReadGraph graph) throws DatabaseException { - ViewsResources VIEW = ViewsResources.getInstance(graph); - Resource configuration = graph.getResource(configurationURI); - return graph.getPossibleRelatedValue2(configuration, VIEW.Wizard_FinishAction); - } - }); - - List pageResources = Simantics.getSession().syncRequest(new Read>() { - - @Override - public List perform(ReadGraph graph) throws DatabaseException { - ViewsResources VIEW = ViewsResources.getInstance(graph); - Resource configuration = graph.getResource(configurationURI); - Resource pageList = graph.getPossibleObject(configuration, VIEW.Wizard_Pages); - if(pageList == null) return Collections.emptyList(); - return ListUtils.toList(graph, pageList); - } - - }); - - for(final Resource page : pageResources) { - - ModelledWizardPage p = Simantics.getSession().syncRequest(new PossibleAdapter(page, ModelledWizardPage.class)); - pages.add(p.create(context, support, runtime)); - modelledPages.add(p); - - } - - } - - @Override - public Runnable create(IWorkbenchSite site, ISessionContext context, final WidgetSupport support) throws DatabaseException { - - List pageResources = Simantics.getSession().syncRequest(new Read>() { - - @Override - public List perform(ReadGraph graph) throws DatabaseException { - ViewsResources VIEW = ViewsResources.getInstance(graph); - Resource configuration = graph.getResource(configurationURI); - Resource pageList = graph.getPossibleObject(configuration, VIEW.Wizard_Pages); - if(pageList == null) return Collections.emptyList(); - return ListUtils.toList(graph, pageList); - } - - }); - - runtime = Simantics.getSession().sync(new WriteResultRequest(Simantics.getSession().getService(VirtualGraph.class)) { - @Override - public Resource perform(WriteGraph graph) throws DatabaseException { - Layer0 L0 = Layer0.getInstance(graph); - ScenegraphResources SG = ScenegraphResources.getInstance(graph); - Resource runtime = graph.newResource(); - graph.claim(runtime, L0.InstanceOf, null, SG.Runtime); - return runtime; - } - }); - - for(final Resource page : pageResources) { - - ModelledWizardPage p = Simantics.getSession().syncRequest(new PossibleAdapter(page, ModelledWizardPage.class)); - pages.add(p.create(context, support, runtime)); - - } - - finishAction = Simantics.getSession().syncRequest(new Read>() { - @Override - public Function1 perform(ReadGraph graph) throws DatabaseException { - ViewsResources VIEW = ViewsResources.getInstance(graph); - Resource configuration = graph.getResource(configurationURI); - return graph.getPossibleRelatedValue2(configuration, VIEW.Wizard_FinishAction); - } - }); - - return null; - - } - - @Override - public void init(IWorkbench workbench, IStructuredSelection selection) { - - WidgetSupportImpl support = new WidgetSupportImpl(); - try { - loadPages(null, Simantics.getSessionContext(), support); - support.finish(); - support.fireInput(Simantics.getSessionContext(), selection); - } catch (DatabaseException e) { - Logger.defaultLogError(e); - } - - } - -} +package org.simantics.views.swt; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchSite; +import org.eclipse.ui.IWorkbenchWizard; +import org.simantics.Simantics; +import org.simantics.browsing.ui.swt.ModelledAction; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.VirtualGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.primitiverequest.PossibleAdapter; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.common.utils.Logger; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.scenegraph.ontology.ScenegraphResources; +import org.simantics.scl.runtime.function.Function1; +import org.simantics.views.ontology.ViewsResources; + +/** + * @author Tuukka Lehtonen + */ +public class ModelledWizard extends Wizard implements IWorkbenchWizard, ModelledAction { + + final String configurationURI; + + final private ArrayList pages = new ArrayList(); + final private ArrayList modelledPages = new ArrayList(); + + + private Function1 finishAction; + private Resource runtime; + + public ModelledWizard(String configurationURI) { + setNeedsProgressMonitor(true); + this.configurationURI = configurationURI; + } + + public List getModelledPages() { + return modelledPages; + } + + @Override + public void addPages() { + super.addPages(); + for(IWizardPage page : pages) addPage(page); + } + + @Override + public boolean performFinish() { + + finishAction.apply(this); + return true; + + } + + public void loadPages(IWorkbenchSite site, ISessionContext context, final WidgetSupport support) throws DatabaseException { + + runtime = Simantics.getSession().sync(new WriteResultRequest(Simantics.getSession().getService(VirtualGraph.class)) { + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + ScenegraphResources SG = ScenegraphResources.getInstance(graph); + Resource runtime = graph.newResource(); + graph.claim(runtime, L0.InstanceOf, null, SG.Runtime); + return runtime; + } + }); + + finishAction = Simantics.getSession().syncRequest(new Read>() { + @Override + public Function1 perform(ReadGraph graph) throws DatabaseException { + ViewsResources VIEW = ViewsResources.getInstance(graph); + Resource configuration = graph.getResource(configurationURI); + return graph.getPossibleRelatedValue2(configuration, VIEW.Wizard_FinishAction); + } + }); + + List pageResources = Simantics.getSession().syncRequest(new Read>() { + + @Override + public List perform(ReadGraph graph) throws DatabaseException { + ViewsResources VIEW = ViewsResources.getInstance(graph); + Resource configuration = graph.getResource(configurationURI); + Resource pageList = graph.getPossibleObject(configuration, VIEW.Wizard_Pages); + if(pageList == null) return Collections.emptyList(); + return ListUtils.toList(graph, pageList); + } + + }); + + for(final Resource page : pageResources) { + + ModelledWizardPage p = Simantics.getSession().syncRequest(new PossibleAdapter(page, ModelledWizardPage.class)); + pages.add(p.create(context, support, runtime)); + modelledPages.add(p); + + } + + } + + @Override + public Runnable create(IWorkbenchSite site, ISessionContext context, final WidgetSupport support) throws DatabaseException { + + List pageResources = Simantics.getSession().syncRequest(new Read>() { + + @Override + public List perform(ReadGraph graph) throws DatabaseException { + ViewsResources VIEW = ViewsResources.getInstance(graph); + Resource configuration = graph.getResource(configurationURI); + Resource pageList = graph.getPossibleObject(configuration, VIEW.Wizard_Pages); + if(pageList == null) return Collections.emptyList(); + return ListUtils.toList(graph, pageList); + } + + }); + + runtime = Simantics.getSession().sync(new WriteResultRequest(Simantics.getSession().getService(VirtualGraph.class)) { + @Override + public Resource perform(WriteGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + ScenegraphResources SG = ScenegraphResources.getInstance(graph); + Resource runtime = graph.newResource(); + graph.claim(runtime, L0.InstanceOf, null, SG.Runtime); + return runtime; + } + }); + + for(final Resource page : pageResources) { + + ModelledWizardPage p = Simantics.getSession().syncRequest(new PossibleAdapter(page, ModelledWizardPage.class)); + pages.add(p.create(context, support, runtime)); + + } + + finishAction = Simantics.getSession().syncRequest(new Read>() { + @Override + public Function1 perform(ReadGraph graph) throws DatabaseException { + ViewsResources VIEW = ViewsResources.getInstance(graph); + Resource configuration = graph.getResource(configurationURI); + return graph.getPossibleRelatedValue2(configuration, VIEW.Wizard_FinishAction); + } + }); + + return null; + + } + + @Override + public void init(IWorkbench workbench, IStructuredSelection selection) { + + WidgetSupportImpl support = new WidgetSupportImpl(); + try { + loadPages(null, Simantics.getSessionContext(), support); + support.finish(); + support.fireInput(Simantics.getSessionContext(), selection); + } catch (DatabaseException e) { + Logger.defaultLogError(e); + } + + } + +}