]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/base/SWTViewUtils.java
6fc3491a1a69c4255a97a97aa52b7ffc45119be3
[simantics/platform.git] / bundles / org.simantics.views.swt.client / src / org / simantics / views / swt / client / base / SWTViewUtils.java
1 package org.simantics.views.swt.client.base;\r
2 \r
3 import org.eclipse.jface.layout.GridLayoutFactory;\r
4 import org.eclipse.swt.SWT;\r
5 import org.eclipse.swt.layout.GridData;\r
6 import org.eclipse.swt.layout.GridLayout;\r
7 import org.eclipse.swt.widgets.Layout;\r
8 import org.simantics.browsing.ui.Column;\r
9 import org.simantics.browsing.ui.Column.Align;\r
10 import org.simantics.views.ViewUtils.ColumnBean;\r
11 import org.simantics.views.ViewUtils.GridDataBean;\r
12 import org.simantics.views.ViewUtils.GridLayoutBean;\r
13 \r
14 public class SWTViewUtils {\r
15 \r
16         public static Layout toLayout(GridLayoutBean bean) {\r
17                 GridLayout result = GridLayoutFactory.fillDefaults().numColumns(1).equalWidth(false).margins(0, 0).spacing(0, 0).create();\r
18                 result.numColumns = bean.numColumns;\r
19                 result.horizontalSpacing = bean.horizontalSpacing;\r
20                 result.verticalSpacing = bean.verticalSpacing;\r
21                 result.marginLeft = bean.marginLeft;\r
22                 result.marginRight = bean.marginRight;\r
23                 result.marginTop = bean.marginTop;\r
24                 result.marginBottom = bean.marginBottom;\r
25                 return result;\r
26         }\r
27         \r
28         \r
29         public static GridData toGridData(GridDataBean bean) {\r
30                 GridData result = new GridData(SWT.FILL, SWT.FILL, true, false);           \r
31                 result.horizontalSpan = bean.horizontalSpan;\r
32                 result.grabExcessHorizontalSpace = bean.grabExcessHorizontalSpace;\r
33                 result.grabExcessVerticalSpace = bean.grabExcessVerticalSpace;\r
34                 result.horizontalAlignment = bean.horizontalAlignment;\r
35                 result.verticalAlignment = bean.verticalAlignment;\r
36                 result.widthHint = bean.widthHint;\r
37                 result.heightHint = bean.heightHint;\r
38                 return result;\r
39                 \r
40         }\r
41 \r
42         private static Align getAlign(String alignment) {\r
43                 if("LEFT".equals(alignment)) return Align.LEFT;\r
44                 else if("CENTER".equals(alignment)) return Align.CENTER;\r
45                 else if("RIGHT".equals(alignment)) return Align.RIGHT;\r
46                 else throw new IllegalArgumentException("Align should be either LEFT, CENTER or RIGHT (was " + alignment + ")");\r
47         }\r
48         \r
49         public static Column toColumn(ColumnBean bean) {\r
50                 Align align = getAlign(bean.alignment);\r
51                 return new Column(bean.key, bean.label, align, bean.width, bean.tooltip, bean.grab, bean.weight);\r
52         }\r
53         \r
54 }\r