]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/ModelledWizardPageImpl.java
Use RuntimeEnvironmentRequest2 where applicable
[simantics/platform.git] / bundles / org.simantics.browsing.ui.swt / src / org / simantics / browsing / ui / swt / ModelledWizardPageImpl.java
1 /*******************************************************************************
2  * Copyright (c) 2012 Association for Decentralized Information Management in
3  * Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.browsing.ui.swt;
13
14 import org.eclipse.jface.wizard.IWizardPage;
15 import org.eclipse.jface.wizard.WizardPage;
16 import org.eclipse.swt.widgets.Composite;
17 import org.eclipse.swt.widgets.Control;
18 import org.simantics.Simantics;
19 import org.simantics.browsing.ui.swt.stubs.BrowsingResource;
20 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
21 import org.simantics.databoard.Bindings;
22 import org.simantics.db.ReadGraph;
23 import org.simantics.db.Resource;
24 import org.simantics.db.exception.DatabaseException;
25 import org.simantics.db.management.ISessionContext;
26 import org.simantics.db.request.Read;
27
28 public class ModelledWizardPageImpl implements ModelledWizardPage {
29
30         final private Resource configuration;
31         
32         public ModelledWizardPageImpl(Resource configuration) {
33                 this.configuration = configuration;
34         }
35
36         class Page extends WizardPage {
37
38                 final private WidgetSupport support;
39                 
40                 public Page(String title, WidgetSupport support) {
41                         super(title, title, null);
42                         this.support = support;
43                 }
44                 
45                 @Override
46                 public void createControl(Composite parent) {
47
48                         try {
49
50                                 ModelledControl modelledControl = Simantics.getSession().syncRequest(new Read<ModelledControl>() {
51                                         @Override
52                                         public ModelledControl perform(ReadGraph graph) throws DatabaseException {
53                                                 BrowsingResource BRO = BrowsingResource.getInstance(graph);
54                                                 Resource controlResource = graph.getPossibleObject(configuration, BRO.WizardPage_Control);
55                                                 return graph.adapt(controlResource, ModelledControl.class);
56                                         }
57                                 });
58
59                                 Control control = modelledControl.create(parent, null, null, support);
60
61                                 setControl(control);
62
63                         } catch (DatabaseException e) {
64                                 
65                                 e.printStackTrace();
66                                 
67                         }
68                         
69                 }
70                 
71         }
72         
73         public IWizardPage create(ISessionContext context, WidgetSupport support) throws DatabaseException {
74
75                 String title = Simantics.getSession().syncRequest(new Read<String>() {
76                         @Override
77                         public String perform(ReadGraph graph) throws DatabaseException {
78                                 BrowsingResource br = BrowsingResource.getInstance(graph);
79                                 return graph.getPossibleRelatedValue(configuration, br.WizardPage_Title, Bindings.STRING);
80                         }
81                 });
82
83                 return new Page(title, support);
84                 
85         }
86         
87 }