]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/ModelledComposite.java
Added Chart Preferences action to time series chart editor context menu
[simantics/platform.git] / bundles / org.simantics.browsing.ui.swt / src / org / simantics / browsing / ui / swt / ModelledComposite.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 java.util.Collections;
15 import java.util.List;
16
17 import org.eclipse.jface.layout.GridLayoutFactory;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.layout.GridData;
20 import org.eclipse.swt.layout.GridLayout;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.swt.widgets.Layout;
23 import org.eclipse.ui.IWorkbenchSite;
24 import org.simantics.Simantics;
25 import org.simantics.browsing.ui.swt.stubs.BrowsingResource;
26 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
27 import org.simantics.databoard.Bindings;
28 import org.simantics.db.ReadGraph;
29 import org.simantics.db.Resource;
30 import org.simantics.db.common.primitiverequest.PossibleAdapter;
31 import org.simantics.db.common.utils.OrderedSetUtils;
32 import org.simantics.db.exception.DatabaseException;
33 import org.simantics.db.management.ISessionContext;
34 import org.simantics.db.request.Read;
35
36 public class ModelledComposite implements ModelledControl {
37
38         final private Resource configuration;
39         
40         public ModelledComposite(Resource configuration) {
41                 this.configuration = configuration;
42         }
43         
44         @Override
45         public Composite create(Composite parent, IWorkbenchSite site, ISessionContext context, WidgetSupport support) throws DatabaseException {
46                 
47         Composite composite = new Composite(parent, SWT.NONE);
48                 composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
49
50                 Layout layout = Simantics.getSession().syncRequest(new Read<Layout>() {
51
52                         @Override
53                         public Layout perform(ReadGraph graph) throws DatabaseException {
54
55                                 BrowsingResource br = BrowsingResource.getInstance(graph);
56                                 Integer columns = graph.getPossibleRelatedValue(configuration, br.Composite_ColumnCount, Bindings.INTEGER);
57                                 
58                                 GridLayout layout = GridLayoutFactory.fillDefaults().numColumns(1).equalWidth(false).margins(0, 0).spacing(0, 0).create();
59                                 if(columns != null) layout.numColumns = columns;
60                                 
61                                 return layout;
62                                 
63                         }
64                         
65                 });
66                 
67                 composite.setLayout(layout);
68                 
69 //              GridLayoutFactory.fillDefaults().numColumns(1).equalWidth(true).margins(0, 0).spacing(0, 0).applyTo(composite);
70                 
71                 List<Resource> children = Simantics.getSession().syncRequest(new Read<List<Resource>>() {
72
73                         @Override
74                         public List<Resource> perform(ReadGraph graph) throws DatabaseException {
75                                 BrowsingResource br = BrowsingResource.getInstance(graph);
76                                 Resource tabList = graph.getPossibleObject(configuration, br.Composite_Children);
77                                 if(tabList == null) return Collections.emptyList();
78                                 return OrderedSetUtils.toList(graph, tabList);
79                         }
80                         
81                 });
82
83                 for(final Resource child : children) {
84
85                         ModelledControl control = Simantics.getSession().syncRequest(new PossibleAdapter<ModelledControl>(child, ModelledControl.class));                       
86                         control.create(composite, site, context, support);
87                         
88                 }
89
90                 return composite;
91                 
92         }
93         
94 }