]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/base/SWTViewUtils.java
Several Wiki documentation view improvements.
[simantics/platform.git] / bundles / org.simantics.views.swt.client / src / org / simantics / views / swt / client / base / SWTViewUtils.java
index 6fc3491a1a69c4255a97a97aa52b7ffc45119be3..91cc7f7a1381bf81a9f3671c5455f46365521867 100644 (file)
@@ -1,15 +1,22 @@
 package org.simantics.views.swt.client.base;\r
 \r
 import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.jface.layout.RowLayoutFactory;\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.layout.RowData;\r
+import org.eclipse.swt.layout.RowLayout;\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
+import org.simantics.views.ViewUtils.LayoutBean;\r
+import org.simantics.views.ViewUtils.LayoutDataBean;\r
+import org.simantics.views.ViewUtils.RowDataBean;\r
+import org.simantics.views.ViewUtils.RowLayoutBean;\r
 \r
 public class SWTViewUtils {\r
 \r
@@ -24,10 +31,25 @@ public class SWTViewUtils {
                result.marginBottom = bean.marginBottom;\r
                return result;\r
        }\r
-       \r
-       \r
+\r
+       public static Layout toLayout(RowLayoutBean bean) {\r
+               RowLayout result = RowLayoutFactory.fillDefaults().create();\r
+               result.type = bean.type;\r
+               result.spacing = bean.spacing;\r
+               result.center = bean.center;\r
+               result.fill = bean.fill;\r
+               result.justify = bean.justify;\r
+               result.pack = bean.pack;\r
+               result.wrap = bean.wrap;\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
        public static GridData toGridData(GridDataBean bean) {\r
-               GridData result = new GridData(SWT.FILL, SWT.FILL, true, false);           \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
@@ -39,6 +61,27 @@ public class SWTViewUtils {
                \r
        }\r
 \r
+       public static RowData toRowData(RowDataBean bean) {\r
+               return new RowData(bean.width, bean.height);\r
+       }\r
+\r
+       public static Layout toLayout(LayoutBean layout) {\r
+               if (layout instanceof GridLayoutBean)\r
+                       return toLayout((GridLayoutBean) layout);\r
+               if (layout instanceof RowLayoutBean)\r
+                       return toLayout((RowLayoutBean) layout);\r
+               throw new IllegalArgumentException("unrecognized layout: " + layout);\r
+       }\r
+\r
+\r
+       public static Object toLayoutData(LayoutDataBean layoutData) {\r
+               if (layoutData instanceof GridDataBean)\r
+                       return toGridData((GridDataBean) layoutData);\r
+               if (layoutData instanceof RowDataBean)\r
+                       return toRowData((RowDataBean) layoutData);\r
+               throw new IllegalArgumentException("unrecognized layout data: " + layoutData);\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