--- /dev/null
+package org.simantics.views.swt.client.base;\r
+\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.layout.GridData;\r
+import org.eclipse.swt.layout.GridLayout;\r
+import org.eclipse.swt.widgets.Layout;\r
+import org.simantics.browsing.ui.Column;\r
+import org.simantics.browsing.ui.Column.Align;\r
+import org.simantics.views.ViewUtils.ColumnBean;\r
+import org.simantics.views.ViewUtils.GridDataBean;\r
+import org.simantics.views.ViewUtils.GridLayoutBean;\r
+\r
+public class SWTViewUtils {\r
+\r
+ public static Layout toLayout(GridLayoutBean bean) {\r
+ GridLayout result = GridLayoutFactory.fillDefaults().numColumns(1).equalWidth(false).margins(0, 0).spacing(0, 0).create();\r
+ result.numColumns = bean.numColumns;\r
+ result.horizontalSpacing = bean.horizontalSpacing;\r
+ result.verticalSpacing = bean.verticalSpacing;\r
+ result.marginLeft = bean.marginLeft;\r
+ result.marginRight = bean.marginRight;\r
+ result.marginTop = bean.marginTop;\r
+ result.marginBottom = bean.marginBottom;\r
+ return result;\r
+ }\r
+ \r
+ \r
+ public static GridData toGridData(GridDataBean bean) {\r
+ GridData result = new GridData(SWT.FILL, SWT.FILL, true, false); \r
+ result.horizontalSpan = bean.horizontalSpan;\r
+ result.grabExcessHorizontalSpace = bean.grabExcessHorizontalSpace;\r
+ result.grabExcessVerticalSpace = bean.grabExcessVerticalSpace;\r
+ result.horizontalAlignment = bean.horizontalAlignment;\r
+ result.verticalAlignment = bean.verticalAlignment;\r
+ result.widthHint = bean.widthHint;\r
+ result.heightHint = bean.heightHint;\r
+ return result;\r
+ \r
+ }\r
+\r
+ private static Align getAlign(String alignment) {\r
+ if("LEFT".equals(alignment)) return Align.LEFT;\r
+ else if("CENTER".equals(alignment)) return Align.CENTER;\r
+ else if("RIGHT".equals(alignment)) return Align.RIGHT;\r
+ else throw new IllegalArgumentException("Align should be either LEFT, CENTER or RIGHT (was " + alignment + ")");\r
+ }\r
+ \r
+ public static Column toColumn(ColumnBean bean) {\r
+ Align align = getAlign(bean.alignment);\r
+ return new Column(bean.key, bean.label, align, bean.width, bean.tooltip, bean.grab, bean.weight);\r
+ }\r
+ \r
+}\r