X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2FModelledWizard.java;h=d037d426b8e573c5edd6e5d64c14468118ec4221;hp=78d33262e1763ff0abe2af498d02bd85215be225;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/ModelledWizard.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/ModelledWizard.java index 78d33262e..d037d426b 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/ModelledWizard.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/ModelledWizard.java @@ -1,125 +1,125 @@ -/******************************************************************************* - * Copyright (c) 2012 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.browsing.ui.swt; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.eclipse.jface.wizard.IWizardPage; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IWorkbenchSite; -import org.simantics.Simantics; -import org.simantics.browsing.ui.swt.stubs.BrowsingResource; -import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; -import org.simantics.databoard.Bindings; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.primitiverequest.PossibleAdapter; -import org.simantics.db.common.utils.OrderedSetUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.management.ISessionContext; -import org.simantics.db.request.Read; - -/** - * @author Tuukka Lehtonen - */ -public class ModelledWizard extends Wizard implements ModelledAction { - - final Resource configuration; - - final private ArrayList pages = new ArrayList(); - - private Runnable finishAction; - - public ModelledWizard(Resource configuration) { - setNeedsProgressMonitor(true); - this.configuration = configuration; - } - - @Override - public void addPages() { - super.addPages(); - for(IWizardPage page : pages) addPage(page); - } - - @Override - public boolean performFinish() { - return true; - } - - @Override - public Runnable create(IWorkbenchSite site, ISessionContext context, final WidgetSupport support) throws DatabaseException { - - String title = Simantics.getSession().syncRequest(new Read() { - - @Override - public String perform(ReadGraph graph) throws DatabaseException { - BrowsingResource br = BrowsingResource.getInstance(graph); - return graph.getPossibleRelatedValue(configuration, br.Wizard_Title, Bindings.STRING); - } - - }); - - setWindowTitle(title); - - List pageResources = Simantics.getSession().syncRequest(new Read>() { - - @Override - public List perform(ReadGraph graph) throws DatabaseException { - BrowsingResource br = BrowsingResource.getInstance(graph); - Resource pageList = graph.getPossibleObject(configuration, br.Wizard_Pages); - if(pageList == null) return Collections.emptyList(); - return OrderedSetUtils.toList(graph, pageList); - } - - }); - - for(final Resource page : pageResources) { - - ModelledWizardPage p = Simantics.getSession().syncRequest(new PossibleAdapter(page, ModelledWizardPage.class)); - pages.add(p.create(context, support)); - - } - - ModelledAction finishAction = Simantics.getSession().syncRequest(new Read() { - @Override - public ModelledAction perform(ReadGraph graph) throws DatabaseException { - BrowsingResource BRO = BrowsingResource.getInstance(graph); - Resource actionResource = graph.getPossibleObject(configuration, BRO.Wizard_FinishAction); - return graph.adapt(actionResource, ModelledAction.class); - } - }); - - this.finishAction = finishAction.create(null, null, support); - - return new Runnable() { - - @Override - public void run() { - - WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), ModelledWizard.this); - dialog.create(); - support.update(); - dialog.open(); - - if(ModelledWizard.this.finishAction != null) ModelledWizard.this.finishAction.run(); - - } - - }; - - } - -} +/******************************************************************************* + * Copyright (c) 2012 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.browsing.ui.swt; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.Simantics; +import org.simantics.browsing.ui.swt.stubs.BrowsingResource; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.primitiverequest.PossibleAdapter; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.db.request.Read; + +/** + * @author Tuukka Lehtonen + */ +public class ModelledWizard extends Wizard implements ModelledAction { + + final Resource configuration; + + final private ArrayList pages = new ArrayList(); + + private Runnable finishAction; + + public ModelledWizard(Resource configuration) { + setNeedsProgressMonitor(true); + this.configuration = configuration; + } + + @Override + public void addPages() { + super.addPages(); + for(IWizardPage page : pages) addPage(page); + } + + @Override + public boolean performFinish() { + return true; + } + + @Override + public Runnable create(IWorkbenchSite site, ISessionContext context, final WidgetSupport support) throws DatabaseException { + + String title = Simantics.getSession().syncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + BrowsingResource br = BrowsingResource.getInstance(graph); + return graph.getPossibleRelatedValue(configuration, br.Wizard_Title, Bindings.STRING); + } + + }); + + setWindowTitle(title); + + List pageResources = Simantics.getSession().syncRequest(new Read>() { + + @Override + public List perform(ReadGraph graph) throws DatabaseException { + BrowsingResource br = BrowsingResource.getInstance(graph); + Resource pageList = graph.getPossibleObject(configuration, br.Wizard_Pages); + if(pageList == null) return Collections.emptyList(); + return OrderedSetUtils.toList(graph, pageList); + } + + }); + + for(final Resource page : pageResources) { + + ModelledWizardPage p = Simantics.getSession().syncRequest(new PossibleAdapter(page, ModelledWizardPage.class)); + pages.add(p.create(context, support)); + + } + + ModelledAction finishAction = Simantics.getSession().syncRequest(new Read() { + @Override + public ModelledAction perform(ReadGraph graph) throws DatabaseException { + BrowsingResource BRO = BrowsingResource.getInstance(graph); + Resource actionResource = graph.getPossibleObject(configuration, BRO.Wizard_FinishAction); + return graph.adapt(actionResource, ModelledAction.class); + } + }); + + this.finishAction = finishAction.create(null, null, support); + + return new Runnable() { + + @Override + public void run() { + + WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), ModelledWizard.this); + dialog.create(); + support.update(); + dialog.open(); + + if(ModelledWizard.this.finishAction != null) ModelledWizard.this.finishAction.run(); + + } + + }; + + } + +}