X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.views.swt.client%2Fsrc%2Forg%2Fsimantics%2Fviews%2Fswt%2Fclient%2Fbase%2FSWTViewUtils.java;h=91cc7f7a1381bf81a9f3671c5455f46365521867;hp=6fc3491a1a69c4255a97a97aa52b7ffc45119be3;hb=089832880807e21e696b5f321a81fa93473c07a9;hpb=d37eb44554b881207f212b0801fc342918dd2b2c diff --git a/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/base/SWTViewUtils.java b/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/base/SWTViewUtils.java index 6fc3491a1..91cc7f7a1 100644 --- a/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/base/SWTViewUtils.java +++ b/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/base/SWTViewUtils.java @@ -1,15 +1,22 @@ package org.simantics.views.swt.client.base; import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.layout.RowLayoutFactory; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.layout.RowData; +import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Layout; import org.simantics.browsing.ui.Column; import org.simantics.browsing.ui.Column.Align; import org.simantics.views.ViewUtils.ColumnBean; import org.simantics.views.ViewUtils.GridDataBean; import org.simantics.views.ViewUtils.GridLayoutBean; +import org.simantics.views.ViewUtils.LayoutBean; +import org.simantics.views.ViewUtils.LayoutDataBean; +import org.simantics.views.ViewUtils.RowDataBean; +import org.simantics.views.ViewUtils.RowLayoutBean; public class SWTViewUtils { @@ -24,10 +31,25 @@ public class SWTViewUtils { result.marginBottom = bean.marginBottom; return result; } - - + + public static Layout toLayout(RowLayoutBean bean) { + RowLayout result = RowLayoutFactory.fillDefaults().create(); + result.type = bean.type; + result.spacing = bean.spacing; + result.center = bean.center; + result.fill = bean.fill; + result.justify = bean.justify; + result.pack = bean.pack; + result.wrap = bean.wrap; + result.marginLeft = bean.marginLeft; + result.marginRight = bean.marginRight; + result.marginTop = bean.marginTop; + result.marginBottom = bean.marginBottom; + return result; + } + public static GridData toGridData(GridDataBean bean) { - GridData result = new GridData(SWT.FILL, SWT.FILL, true, false); + GridData result = new GridData(SWT.FILL, SWT.FILL, true, false); result.horizontalSpan = bean.horizontalSpan; result.grabExcessHorizontalSpace = bean.grabExcessHorizontalSpace; result.grabExcessVerticalSpace = bean.grabExcessVerticalSpace; @@ -39,6 +61,27 @@ public class SWTViewUtils { } + public static RowData toRowData(RowDataBean bean) { + return new RowData(bean.width, bean.height); + } + + public static Layout toLayout(LayoutBean layout) { + if (layout instanceof GridLayoutBean) + return toLayout((GridLayoutBean) layout); + if (layout instanceof RowLayoutBean) + return toLayout((RowLayoutBean) layout); + throw new IllegalArgumentException("unrecognized layout: " + layout); + } + + + public static Object toLayoutData(LayoutDataBean layoutData) { + if (layoutData instanceof GridDataBean) + return toGridData((GridDataBean) layoutData); + if (layoutData instanceof RowDataBean) + return toRowData((RowDataBean) layoutData); + throw new IllegalArgumentException("unrecognized layout data: " + layoutData); + } + private static Align getAlign(String alignment) { if("LEFT".equals(alignment)) return Align.LEFT; else if("CENTER".equals(alignment)) return Align.CENTER;