]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/GridComposite.java
Improvements to modelled SWT documents
[simantics/platform.git] / bundles / org.simantics.document.swt.core / src / org / simantics / document / swt / core / widget / GridComposite.java
1 /*******************************************************************************
2  * Copyright (c) 2019 Association for Decentralized Information Management
3  * in 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  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.document.swt.core.widget;
13
14 import org.eclipse.jface.layout.GridLayoutFactory;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.widgets.Composite;
17 import org.simantics.datatypes.literal.RGB;
18 import org.simantics.document.server.JSONObject;
19 import org.simantics.document.swt.core.SWTDocument;
20 import org.simantics.document.swt.core.base.HasWidgetsWidgetManager;
21 import org.simantics.document.swt.core.bean.MarginsBean;
22
23 public class GridComposite extends HasWidgetsWidgetManager<Composite> {
24
25         @Override
26         protected void doUpdateProperties(SWTDocument document, Composite control, JSONObject object) {
27         }
28
29         @Override
30         protected Composite doCreateControl(SWTDocument document, Composite parent, JSONObject object) {
31
32                 MarginsBean extendedMargins = object.getBeanJSONFieldDefault("extendedMargins", MarginsBean.BINDING, new MarginsBean(0, 0, 0, 0));
33                 RGB.Integer background = object.getBeanJSONFieldDefault("background", RGB.Integer.BINDING, new RGB.Integer(255, 255, 255));
34                 Integer numColumns = object.getJSONFieldDefault("numColumns", 1);
35
36                 Composite result = new Composite(parent, SWT.NONE);
37                 GridLayoutFactory.fillDefaults().
38                         numColumns(numColumns).
39                         extendedMargins(extendedMargins.left, extendedMargins.right, extendedMargins.top, extendedMargins.bottom).
40                         spacing(0, 0).
41                         applyTo(result);
42                 result.setBackground(document.getColor(background));
43                 return result;
44
45         }
46
47 }