]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.views.swt/src/org/simantics/views/swt/ModelledWizardPageImpl.java
Added utility for truncating collected history data
[simantics/platform.git] / bundles / org.simantics.views.swt / src / org / simantics / views / swt / ModelledWizardPageImpl.java
1 package org.simantics.views.swt;
2
3 import org.eclipse.jface.wizard.IWizardPage;
4 import org.eclipse.jface.wizard.WizardPage;
5 import org.eclipse.swt.widgets.Composite;
6 import org.simantics.Simantics;
7 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
8 import org.simantics.databoard.Bindings;
9 import org.simantics.db.ReadGraph;
10 import org.simantics.db.Resource;
11 import org.simantics.db.common.request.UniqueRead;
12 import org.simantics.db.common.utils.Logger;
13 import org.simantics.db.exception.DatabaseException;
14 import org.simantics.db.management.ISessionContext;
15 import org.simantics.db.request.Read;
16 import org.simantics.views.ontology.ViewsResources;
17 import org.simantics.views.swt.client.base.SWTRoot;
18
19 public class ModelledWizardPageImpl implements ModelledWizardPage {
20
21         final private Resource configuration;
22         private SWTRoot root;
23         
24         public ModelledWizardPageImpl(Resource configuration) {
25                 this.configuration = configuration;
26         }
27         
28         @Override
29         public SWTRoot getRoot() {
30                 return root;
31         }
32
33         class Page extends WizardPage {
34
35                 final private Resource runtime;
36                 
37                 public Page(String title, Resource runtime) {
38                         super(title, title, null);
39                         this.runtime = runtime;
40                 }
41                 
42                 @Override
43                 public void createControl(Composite parent) {
44
45                         try {
46
47                                 Resource control = Simantics.getSession().sync(new UniqueRead<Resource>() {
48                                         @Override
49                                         public Resource perform(ReadGraph graph) throws DatabaseException {
50                                                 ViewsResources VIEW = ViewsResources.getInstance(graph);
51                                                 return graph.getPossibleObject(configuration, VIEW.Wizard_Page_Control);
52                                         }
53                                 });
54                                 
55                                 SWTViewLoaderProcess process = new SWTViewLoaderProcess(null, null);
56                                 root = process.load(control, runtime);
57                                 root.createControls(parent);
58
59                                 setControl(root.getSingleChild());
60
61                         } catch (DatabaseException e) {
62                                 
63                                 e.printStackTrace();
64                                 Logger.defaultLogError(e);
65                                 
66                         }
67                         
68                 }
69                 
70         }
71         
72         public IWizardPage create(ISessionContext context, WidgetSupport support, Resource runtime) throws DatabaseException {
73
74                 String title = Simantics.getSession().syncRequest(new Read<String>() {
75                         @Override
76                         public String perform(ReadGraph graph) throws DatabaseException {
77                                 ViewsResources VIEW = ViewsResources.getInstance(graph);
78                                 return graph.getPossibleRelatedValue(configuration, VIEW.Wizard_Page_Title, Bindings.STRING);
79                         }
80                 });
81
82                 return new Page(title, runtime);
83                 
84         }
85         
86 }