1 package org.simantics.views.swt.client.base;
\r
3 import org.eclipse.jface.layout.GridLayoutFactory;
\r
4 import org.eclipse.jface.layout.RowLayoutFactory;
\r
5 import org.eclipse.swt.SWT;
\r
6 import org.eclipse.swt.layout.GridData;
\r
7 import org.eclipse.swt.layout.GridLayout;
\r
8 import org.eclipse.swt.layout.RowData;
\r
9 import org.eclipse.swt.layout.RowLayout;
\r
10 import org.eclipse.swt.widgets.Layout;
\r
11 import org.simantics.browsing.ui.Column;
\r
12 import org.simantics.browsing.ui.Column.Align;
\r
13 import org.simantics.views.ViewUtils.ColumnBean;
\r
14 import org.simantics.views.ViewUtils.GridDataBean;
\r
15 import org.simantics.views.ViewUtils.GridLayoutBean;
\r
16 import org.simantics.views.ViewUtils.LayoutBean;
\r
17 import org.simantics.views.ViewUtils.LayoutDataBean;
\r
18 import org.simantics.views.ViewUtils.RowDataBean;
\r
19 import org.simantics.views.ViewUtils.RowLayoutBean;
\r
21 public class SWTViewUtils {
\r
23 public static Layout toLayout(GridLayoutBean bean) {
\r
24 GridLayout result = GridLayoutFactory.fillDefaults().numColumns(1).equalWidth(false).margins(0, 0).spacing(0, 0).create();
\r
25 result.numColumns = bean.numColumns;
\r
26 result.horizontalSpacing = bean.horizontalSpacing;
\r
27 result.verticalSpacing = bean.verticalSpacing;
\r
28 result.marginLeft = bean.marginLeft;
\r
29 result.marginRight = bean.marginRight;
\r
30 result.marginTop = bean.marginTop;
\r
31 result.marginBottom = bean.marginBottom;
\r
35 public static Layout toLayout(RowLayoutBean bean) {
\r
36 RowLayout result = RowLayoutFactory.fillDefaults().create();
\r
37 result.type = bean.type;
\r
38 result.spacing = bean.spacing;
\r
39 result.center = bean.center;
\r
40 result.fill = bean.fill;
\r
41 result.justify = bean.justify;
\r
42 result.pack = bean.pack;
\r
43 result.wrap = bean.wrap;
\r
44 result.marginLeft = bean.marginLeft;
\r
45 result.marginRight = bean.marginRight;
\r
46 result.marginTop = bean.marginTop;
\r
47 result.marginBottom = bean.marginBottom;
\r
51 public static GridData toGridData(GridDataBean bean) {
\r
52 GridData result = new GridData(SWT.FILL, SWT.FILL, true, false);
\r
53 result.horizontalSpan = bean.horizontalSpan;
\r
54 result.grabExcessHorizontalSpace = bean.grabExcessHorizontalSpace;
\r
55 result.grabExcessVerticalSpace = bean.grabExcessVerticalSpace;
\r
56 result.horizontalAlignment = bean.horizontalAlignment;
\r
57 result.verticalAlignment = bean.verticalAlignment;
\r
58 result.widthHint = bean.widthHint;
\r
59 result.heightHint = bean.heightHint;
\r
64 public static RowData toRowData(RowDataBean bean) {
\r
65 return new RowData(bean.width, bean.height);
\r
68 public static Layout toLayout(LayoutBean layout) {
\r
69 if (layout instanceof GridLayoutBean)
\r
70 return toLayout((GridLayoutBean) layout);
\r
71 if (layout instanceof RowLayoutBean)
\r
72 return toLayout((RowLayoutBean) layout);
\r
73 throw new IllegalArgumentException("unrecognized layout: " + layout);
\r
77 public static Object toLayoutData(LayoutDataBean layoutData) {
\r
78 if (layoutData instanceof GridDataBean)
\r
79 return toGridData((GridDataBean) layoutData);
\r
80 if (layoutData instanceof RowDataBean)
\r
81 return toRowData((RowDataBean) layoutData);
\r
82 throw new IllegalArgumentException("unrecognized layout data: " + layoutData);
\r
85 private static Align getAlign(String alignment) {
\r
86 if("LEFT".equals(alignment)) return Align.LEFT;
\r
87 else if("CENTER".equals(alignment)) return Align.CENTER;
\r
88 else if("RIGHT".equals(alignment)) return Align.RIGHT;
\r
89 else throw new IllegalArgumentException("Align should be either LEFT, CENTER or RIGHT (was " + alignment + ")");
\r
92 public static Column toColumn(ColumnBean bean) {
\r
93 Align align = getAlign(bean.alignment);
\r
94 return new Column(bean.key, bean.label, align, bean.width, bean.tooltip, bean.grab, bean.weight);
\r