1 /*******************************************************************************
2 * Copyright (c) 2012 Association for Decentralized Information Management in
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.browsing.ui.swt;
14 import java.util.Collections;
15 import java.util.List;
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;
36 public class ModelledComposite implements ModelledControl {
38 final private Resource configuration;
40 public ModelledComposite(Resource configuration) {
41 this.configuration = configuration;
45 public Composite create(Composite parent, IWorkbenchSite site, ISessionContext context, WidgetSupport support) throws DatabaseException {
47 Composite composite = new Composite(parent, SWT.NONE);
48 composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
50 Layout layout = Simantics.getSession().syncRequest(new Read<Layout>() {
53 public Layout perform(ReadGraph graph) throws DatabaseException {
55 BrowsingResource br = BrowsingResource.getInstance(graph);
56 Integer columns = graph.getPossibleRelatedValue(configuration, br.Composite_ColumnCount, Bindings.INTEGER);
58 GridLayout layout = GridLayoutFactory.fillDefaults().numColumns(1).equalWidth(false).margins(0, 0).spacing(0, 0).create();
59 if(columns != null) layout.numColumns = columns;
67 composite.setLayout(layout);
69 // GridLayoutFactory.fillDefaults().numColumns(1).equalWidth(true).margins(0, 0).spacing(0, 0).applyTo(composite);
71 List<Resource> children = Simantics.getSession().syncRequest(new Read<List<Resource>>() {
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);
83 for(final Resource child : children) {
85 ModelledControl control = Simantics.getSession().syncRequest(new PossibleAdapter<ModelledControl>(child, ModelledControl.class));
86 control.create(composite, site, context, support);