summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaren Butzke2012-10-25 10:38:30 (EDT)
committerKaren Butzke2012-10-26 14:10:18 (EDT)
commitd3b775c951265391f716c7860a84a72252f5ce13 (patch)
tree0910bae87f01bc8225c59c252c0997fa1d655a61
parentd95b4a75d98f11ac70121d6d7c5cd05a880ad14c (diff)
downloadwebtools.dali-d3b775c951265391f716c7860a84a72252f5ce13.zip
webtools.dali-d3b775c951265391f716c7860a84a72252f5ce13.tar.gz
webtools.dali-d3b775c951265391f716c7860a84a72252f5ce13.tar.bz2
added SWTTools.controlExpandedState for Sections
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/swt/SWTTools.java33
-rw-r--r--common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/JptUiUtilTests.java1
-rw-r--r--common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/SectionExpanderTest.java87
3 files changed, 121 insertions, 0 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/swt/SWTTools.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/swt/SWTTools.java
index bdc43e4..95d543e 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/swt/SWTTools.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/swt/SWTTools.java
@@ -27,6 +27,7 @@ import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Widget;
+import org.eclipse.ui.forms.widgets.Section;
/**
* Various SWT tools.
@@ -379,6 +380,38 @@ public final class SWTTools {
}
+ // ********** 'expanded' state **********
+
+ /**
+ * Control the <em>expanded</em> state of the specified section with the
+ * specified boolean model. If the boolean is <code>null<code>, the section's
+ * <em>expanded</em> state will be false.
+ */
+ public static void controlExpandedState(PropertyValueModel<Boolean> booleanModel, Section section) {
+ controlExpandedState(booleanModel, section, false);
+ }
+
+ /**
+ * Control the <em>expanded</em> state of the specified section with the
+ * specified boolean model. If the boolean is <code>null<code>, the section's
+ * <em>expanded</em> state will be the specified default value.
+ */
+ public static void controlExpandedState(PropertyValueModel<Boolean> booleanModel, Section section, boolean defaultValue) {
+ control(booleanModel, section, defaultValue, EXPANDED_ADAPTER);
+ }
+
+ private static final BooleanStateController.Adapter EXPANDED_ADAPTER =
+ new BooleanStateController.Adapter() {
+ public void setState(Control section, boolean b) {
+ ((Section) section).setExpanded(b);
+ }
+ };
+
+ private static void control(PropertyValueModel<Boolean> booleanModel, Section section, boolean defaultValue, BooleanStateController.Adapter adapter) {
+ // the new controller will add itself as a listener to the value model and the section
+ new SimpleBooleanStateController(booleanModel, section, defaultValue, adapter);
+ }
+
// ********** constructor **********
/**
diff --git a/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/JptUiUtilTests.java b/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/JptUiUtilTests.java
index 4f848cb..a308ba8 100644
--- a/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/JptUiUtilTests.java
+++ b/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/JptUiUtilTests.java
@@ -26,6 +26,7 @@ import org.junit.runners.Suite.SuiteClasses;
LabeledLabelTest.class,
LabeledControlUpdaterTest.class,
PaneVisibilityEnablerTest.class,
+ SectionExpanderTest.class,
})
@RunWith(Suite.class)
public final class JptUiUtilTests {
diff --git a/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/SectionExpanderTest.java b/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/SectionExpanderTest.java
new file mode 100644
index 0000000..4f9646c
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/util/SectionExpanderTest.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.tests.internal.util;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.ui.internal.utility.swt.SWTTools;
+import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.forms.widgets.ExpandableComposite;
+import org.eclipse.ui.forms.widgets.Section;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+@SuppressWarnings("nls")
+public final class SectionExpanderTest {
+
+ private Composite parent;
+
+ @Before
+ public void setUp() {
+ this.parent = new Composite(SWTUtil.getShell(), SWT.NONE);
+ this.parent.setLayout(new GridLayout());
+ }
+
+ @After
+ public void tearDown() {
+ if (this.parent != null) {
+ this.parent.dispose();
+ }
+ }
+
+ @Test
+ public void testSwitchState() {
+
+ SimplePropertyValueModel<Boolean> booleanModel =
+ new SimplePropertyValueModel<Boolean>(Boolean.FALSE);
+
+ Section section = new Section(this.parent, ExpandableComposite.TWISTIE);
+
+ SWTTools.controlExpandedState(booleanModel, section);
+
+ assertFalse(
+ "The Section should not be expanded",
+ section.isExpanded()
+ );
+
+ // Change state (null)
+ booleanModel.setValue(null);
+
+ assertFalse(
+ "The Section should not be expanded",
+ section.isExpanded()
+ );
+
+ // Change state (true)
+ booleanModel.setValue(Boolean.TRUE);
+
+ assertTrue(
+ "The Combo should be enabled",
+ section.isExpanded()
+ );
+
+ // Change state (false)
+ booleanModel.setValue(Boolean.FALSE);
+
+ assertFalse(
+ "The Combo should not be enabled",
+ section.isExpanded()
+ );
+
+ // Dispose
+ section.dispose();
+ booleanModel.setValue(Boolean.TRUE);
+ }
+}