Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcus Hoepfner2019-09-29 08:57:13 +0000
committerMatthias Becker2020-06-09 09:33:38 +0000
commit2ecf7f617dfdcc1d41fa791b5ed7126bbd6d0b17 (patch)
tree68966350151ecfdce21abfb0303ceb7472657bd1
parenta1a4de65fa44c09452b4f12d20abc85780b238eb (diff)
downloadeclipse.platform.ui-2ecf7f617dfdcc1d41fa791b5ed7126bbd6d0b17.tar.gz
eclipse.platform.ui-2ecf7f617dfdcc1d41fa791b5ed7126bbd6d0b17.tar.xz
eclipse.platform.ui-2ecf7f617dfdcc1d41fa791b5ed7126bbd6d0b17.zip
Bug 551589 SashFormFactory
Change-Id: I1340c21d4cf1dc4386e330fbcde15f24a808ec14 Signed-off-by: Marcus Hoepfner <marcus.hoepfner@sap.com>
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/widgets/SashFormFactory.java90
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/widgets/WidgetFactory.java12
-rw-r--r--tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/widgets/AllWidgetTests.java1
-rw-r--r--tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/widgets/TestUnitSashFormFactory.java38
4 files changed, 141 insertions, 0 deletions
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/widgets/SashFormFactory.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/widgets/SashFormFactory.java
new file mode 100644
index 00000000000..bcedea2602a
--- /dev/null
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/widgets/SashFormFactory.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Marcus Hoepfner and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Marcus Hoepfner - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jface.widgets;
+
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * This class provides a convenient shorthand for creating and initializing
+ * {@link SashForm}. This offers several benefits over creating SashForm normal
+ * way:
+ *
+ * <ul>
+ * <li>The same factory can be used many times to create several SashForm
+ * instances</li>
+ * <li>The setters on SashFormFactory all return "this", allowing them to be
+ * chained</li>
+ * </ul>
+ *
+ * Example usage:
+ *
+ * <pre>
+ * SashForm sashForm = SashFormFactory.newFormSash(SWT.HORIZONTAL).create(parent);
+ * Composite c1 = CompositeFactory.newComposite(SWT.NONE).create(sashForm);
+ * Composite c2 = CompositeFactory.newComposite(SWT.NONE).create(sashForm);
+ * sashForm.setWeights(new int[] { 30, 70 });
+ * </pre>
+ * <p>
+ * The above example creates a horizontal sash. Note that
+ * {@link SashForm#setWeights(int[])} can only be called after children have
+ * been added to the SashForm. Hence this method is not part of this factory.
+ * </p>
+ *
+ * <pre>
+ * GridDataFactory gridDataFactory = GridDataFactory.swtDefaults();
+ * SashFactory sashFactory = SashFactory.newSash(SWT.HORIZONTAL).layout(gridDataFactory::create);
+ * sashFactory.data("Sash 1").create(parent);
+ * sashFactory.data("Sash 2").create(parent);
+ * sashFactory.data("Sash 3").create(parent);
+ * </pre>
+ * <p>
+ * The above example creates three sashForms using the same instance of
+ * SashFormFactory. Note the layout method. A Supplier is used to create unique
+ * GridData for every single sash.
+ * </p>
+ *
+ * @since 3.21
+ */
+public final class SashFormFactory extends AbstractControlFactory<SashFormFactory, SashForm> {
+
+ private SashFormFactory(int style) {
+ super(SashFormFactory.class, parent -> new SashForm(parent, style));
+ }
+
+ /**
+ * Creates a new SashFormFactory with the given style. Refer to
+ * {@link SashForm#SashForm(Composite, int)} for possible styles.
+ *
+ * @param style
+ * @return a new SashFormFactory instance
+ */
+ public static SashFormFactory newSashForm(int style) {
+ return new SashFormFactory(style);
+ }
+
+ /**
+ * Specify the width of the sashes when the controls in the SashForm are laid
+ * out.
+ *
+ * @param width the width of the sashes
+ * @return this
+ *
+ * @see SashForm#setSashWidth
+ */
+ public SashFormFactory sashWidth(int width) {
+ addProperty(sash -> sash.setSashWidth(width));
+ return this;
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/widgets/WidgetFactory.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/widgets/WidgetFactory.java
index 75deeaee988..9bbebdd8cd1 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/widgets/WidgetFactory.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/widgets/WidgetFactory.java
@@ -14,6 +14,7 @@
package org.eclipse.jface.widgets;
+import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
@@ -164,4 +165,15 @@ public final class WidgetFactory {
public static SashFactory sash(int style) {
return SashFactory.newSash(style);
}
+
+ /**
+ * @param style SWT style applicable for SashForm. Refer to
+ * {@link SashForm#SashForm(Composite, int)} for supported styles.
+ * @return SashFormFactory
+ *
+ * @since 3.21
+ */
+ public static SashFormFactory sashForm(int style) {
+ return SashFormFactory.newSashForm(style);
+ }
} \ No newline at end of file
diff --git a/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/widgets/AllWidgetTests.java b/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/widgets/AllWidgetTests.java
index 7305dd13413..9fbb60cd0d4 100644
--- a/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/widgets/AllWidgetTests.java
+++ b/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/widgets/AllWidgetTests.java
@@ -19,6 +19,7 @@ import org.junit.runners.Suite.SuiteClasses;
TestUnitCompositeFactory.class, //
TestUnitLabelFactory.class, //
TestUnitSashFactory.class, //
+ TestUnitSashFormFactory.class, //
TestUnitSpinnerFactory.class, //
TestUnitTextFactory.class, //
TestUnitTableFactory.class, //
diff --git a/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/widgets/TestUnitSashFormFactory.java b/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/widgets/TestUnitSashFormFactory.java
new file mode 100644
index 00000000000..0ded0a3b8a6
--- /dev/null
+++ b/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/widgets/TestUnitSashFormFactory.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Marcus Hoepfner and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Marcus Hoepfner - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jface.tests.widgets;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.jface.widgets.SashFormFactory;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.SashForm;
+import org.junit.Test;
+
+public class TestUnitSashFormFactory extends AbstractFactoryTest {
+
+ @Test
+ public void createsSashForm() {
+ SashForm sashForm = SashFormFactory.newSashForm(SWT.HORIZONTAL).create(shell);
+
+ assertEquals(shell, sashForm.getParent());
+ assertEquals(SWT.HORIZONTAL, sashForm.getStyle() & SWT.HORIZONTAL);
+ }
+
+ @Test
+ public void setsSashWidth() {
+ SashForm sashForm = SashFormFactory.newSashForm(SWT.HORIZONTAL).sashWidth(5).create(shell);
+ assertEquals(5, sashForm.getSashWidth());
+ }
+} \ No newline at end of file

Back to the top