Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinTableComposite.java60
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OverridesComposite.java39
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlAligner.java618
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlSwitcher.java25
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledButton.java13
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledControl.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledControlUpdater.java32
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledLabel.java13
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledTableItem.java17
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/SWTUtil.java57
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/TableLayoutComposite.java35
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractPane.java9
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AddRemovePane.java9
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/TriStateCheckBox.java7
-rw-r--r--jpa/tests/org.eclipse.jpt.ui.tests/META-INF/MANIFEST.MF4
-rw-r--r--jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/JptUiTests.java8
-rw-r--r--jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/ControlAlignerTest.java332
-rw-r--r--jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/ControlSwitcherTest.java188
-rw-r--r--jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/JptUiUtilTests.java41
-rw-r--r--jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/LabeledButtonTest.java123
-rw-r--r--jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/LabeledControlUpdaterTest.java125
-rw-r--r--jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/LabeledLabelTest.java123
-rw-r--r--jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/LabeledTableItemTest.java123
23 files changed, 1495 insertions, 508 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinTableComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinTableComposite.java
index f496e2b0d0..f11accb08b 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinTableComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinTableComposite.java
@@ -445,6 +445,14 @@ public class JoinTableComposite extends AbstractFormPane<IJoinTable>
JoinTableComposite.this.addInverseJoinColumn(subject);
}
+ public IJoinColumn defaultJoinColumn(IJoinTable subject) {
+ return subject.getDefaultInverseJoinColumn();
+ }
+
+ public String defaultPropertyName() {
+ return IJoinTable.DEFAULT_INVERSE_JOIN_COLUMN;
+ }
+
public void editJoinColumn(IJoinTable subject, IJoinColumn joinColumn) {
JoinTableComposite.this.editInverseJoinColumn(joinColumn);
}
@@ -453,31 +461,23 @@ public class JoinTableComposite extends AbstractFormPane<IJoinTable>
return subject.containsSpecifiedInverseJoinColumns();
}
+ public void removeJoinColumns(IJoinTable subject, int[] selectedIndices) {
+ for (int index = selectedIndices.length; --index >= 0; ) {
+ subject.removeSpecifiedInverseJoinColumn(selectedIndices[index]);
+ }
+ }
+
public ListIterator<IJoinColumn> specifiedJoinColumns(IJoinTable subject) {
return subject.specifiedInverseJoinColumns();
}
-
+
public int specifiedJoinColumnsSize(IJoinTable subject) {
return subject.specifiedInverseJoinColumnsSize();
}
-
- public IJoinColumn defaultJoinColumn(IJoinTable subject) {
- return subject.getDefaultInverseJoinColumn();
- }
public String specifiedListPropertyName() {
return IJoinTable.SPECIFIED_INVERSE_JOIN_COLUMNS_LIST;
}
-
- public String defaultPropertyName() {
- return IJoinTable.DEFAULT_INVERSE_JOIN_COLUMN;
- }
-
- public void removeJoinColumns(IJoinTable subject, int[] selectedIndices) {
- for (int index = selectedIndices.length; --index >= 0; ) {
- subject.removeSpecifiedInverseJoinColumn(selectedIndices[index]);
- }
- }
}
private class JoinColumnsProvider implements IJoinColumnsEditor<IJoinTable> {
@@ -486,6 +486,14 @@ public class JoinTableComposite extends AbstractFormPane<IJoinTable>
JoinTableComposite.this.addJoinColumn(subject);
}
+ public IJoinColumn defaultJoinColumn(IJoinTable subject) {
+ return subject.getDefaultJoinColumn();
+ }
+
+ public String defaultPropertyName() {
+ return IJoinTable.DEFAULT_JOIN_COLUMN;
+ }
+
public void editJoinColumn(IJoinTable subject, IJoinColumn joinColumn) {
JoinTableComposite.this.editJoinColumn(joinColumn);
}
@@ -494,30 +502,22 @@ public class JoinTableComposite extends AbstractFormPane<IJoinTable>
return subject.containsSpecifiedJoinColumns();
}
+ public void removeJoinColumns(IJoinTable subject, int[] selectedIndices) {
+ for (int index = selectedIndices.length; --index >= 0; ) {
+ subject.removeSpecifiedJoinColumn(selectedIndices[index]);
+ }
+ }
+
public ListIterator<IJoinColumn> specifiedJoinColumns(IJoinTable subject) {
return subject.specifiedJoinColumns();
}
-
+
public int specifiedJoinColumnsSize(IJoinTable subject) {
return subject.specifiedJoinColumnsSize();
}
-
- public IJoinColumn defaultJoinColumn(IJoinTable subject) {
- return subject.getDefaultJoinColumn();
- }
public String specifiedListPropertyName() {
return IJoinTable.SPECIFIED_JOIN_COLUMNS_LIST;
}
-
- public String defaultPropertyName() {
- return IJoinTable.DEFAULT_JOIN_COLUMN;
- }
-
- public void removeJoinColumns(IJoinTable subject, int[] selectedIndices) {
- for (int index = selectedIndices.length; --index >= 0; ) {
- subject.removeSpecifiedJoinColumn(selectedIndices[index]);
- }
- }
}
} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OverridesComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OverridesComposite.java
index 857bdafb25..8ddeae6983 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OverridesComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OverridesComposite.java
@@ -403,11 +403,11 @@ public class OverridesComposite extends AbstractFormPane<IEntity>
columnComposite.setVisible(false);
joinColumnsComposite.enableWidgets(false);
columnComposite.enableWidgets(false);
- installControlSwitcher(overrideHolder, pageBook);
+ installOverrideControlSwitcher(overrideHolder, pageBook);
}
- private void installControlSwitcher(PropertyValueModel<IOverride> overrideHolder,
- PageBook pageBook) {
+ private void installOverrideControlSwitcher(PropertyValueModel<IOverride> overrideHolder,
+ PageBook pageBook) {
new ControlSwitcher<IOverride>(
overrideHolder,
@@ -491,6 +491,14 @@ public class OverridesComposite extends AbstractFormPane<IEntity>
OverridesComposite.this.addJoinColumn(subject);
}
+ public IJoinColumn defaultJoinColumn(IAssociationOverride subject) {
+ return null;
+ }
+
+ public String defaultPropertyName() {
+ return IAssociationOverride.DEFAULT_JOIN_COLUMNS_LIST;
+ }
+
public void editJoinColumn(IAssociationOverride subject, IJoinColumn joinColumn) {
OverridesComposite.this.editJoinColumn(joinColumn);
}
@@ -499,33 +507,22 @@ public class OverridesComposite extends AbstractFormPane<IEntity>
return subject.containsSpecifiedJoinColumns();
}
-
+ public void removeJoinColumns(IAssociationOverride subject, int[] selectedIndices) {
+ for (int index = selectedIndices.length; --index >= 0; ) {
+ subject.removeSpecifiedJoinColumn(selectedIndices[index]);
+ }
+ }
+
public ListIterator<IJoinColumn> specifiedJoinColumns(IAssociationOverride subject) {
return subject.specifiedJoinColumns();
}
-
+
public int specifiedJoinColumnsSize(IAssociationOverride subject) {
return subject.specifiedJoinColumnsSize();
}
-
- public IJoinColumn defaultJoinColumn(IAssociationOverride subject) {
- // TODO Auto-generated method stub
- return null;
- }
public String specifiedListPropertyName() {
return IAssociationOverride.SPECIFIED_JOIN_COLUMNS_LIST;
}
-
- public String defaultPropertyName() {
- // TODO Auto-generated method stub
- return IAssociationOverride.DEFAULT_JOIN_COLUMNS_LIST;
- }
-
- public void removeJoinColumns(IAssociationOverride subject, int[] selectedIndices) {
- for (int index = selectedIndices.length; --index >= 0; ) {
- subject.removeSpecifiedJoinColumn(selectedIndices[index]);
- }
- }
}
} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlAligner.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlAligner.java
index c270023247..1fa4958e28 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlAligner.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlAligner.java
@@ -11,6 +11,7 @@ package org.eclipse.jpt.ui.internal.util;
import java.util.ArrayList;
import java.util.Collection;
+import org.eclipse.core.runtime.Assert;
import org.eclipse.jpt.utility.internal.StringTools;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
@@ -107,32 +108,17 @@ public final class ControlAligner
* The types of events to listen in order to properly adjust the size of all
* the widgets.
*/
- private static final int[] EVENT_TYPES =
- {
+ private static final int[] EVENT_TYPES = {
SWT.Dispose,
SWT.Show,
SWT.Resize,
SWT.Hide
-// SWT.Move
- };
-
- /**
- * The types of events to listen in order to properly adjust the size of all
- * the widgets when a <code>Shell</code> is opening.
- */
- private static final int[] SHELL_EVENT_TYPES =
- {
- SWT.Dispose,
- SWT.Show,
- SWT.Resize
-// SWT.Hide
};
/**
* Creates a new <code>ControlAligner</code>.
*/
- public ControlAligner()
- {
+ public ControlAligner() {
super();
initialize();
}
@@ -140,23 +126,22 @@ public final class ControlAligner
/**
* Creates a new <code>ControlAligner</code>.
*
- * @param items The collection of <code>Component</code>s
+ * @param controls The collection of <code>Control</code>s
*/
- public ControlAligner(Collection<? extends Control> components)
- {
+ public ControlAligner(Collection<? extends Control> controls) {
this();
- addAllComponents(components);
+ addAllComponents(controls);
}
/**
- * Adds the given control. Its preferred width will be used along with the
- * width of all the other controls in order to get the widest control and
- * use its width as the width for all the controls.
+ * Adds the given control. Its width will be used along with the width of all
+ * the other registered controls in order to get the greater witdh and use
+ * it as the width for all the controls.
*
- * @param control The control to be added
+ * @param control The <code>Control</code> to be added
*/
- public void add(Control control)
- {
+ public void add(Control control) {
+
Wrapper wrapper = buildWrapper(control);
wrapper.addListener(listener);
wrappers.add(wrapper);
@@ -165,26 +150,23 @@ public final class ControlAligner
}
/**
- * Adds the given control. Its preferred width will be used along with the
- * width of all the other controls in order to get the widest control and
- * use its width as the width for all the controls.
+ * Adds the given control. Its width will be used along with the width of all
+ * the other registered controls in order to get the greater witdh and use
+ * it as the width for all the controls.
*
* @param controlAligner The <code>ControlAligner</code> to be added
- * @exception IllegalArgumentException Can't add the ControlAligner to itself
+ * @exception IllegalArgumentException Can't add the <code>ControlAligner</code>
+ * to itself
*/
- public void add(ControlAligner controlAligner)
- {
- if (controlAligner == this)
- {
- throw new IllegalArgumentException("Can't add the ControlAligner to itself");
- }
+ public void add(ControlAligner controlAligner) {
+
+ Assert.isLegal(controlAligner != this, "Can't add the ControlAligner to itself");
Wrapper wrapper = buildWrapper(controlAligner);
wrapper.addListener(listener);
wrappers.add(wrapper);
- if (!controlAligner.wrappers.isEmpty())
- {
+ if (!controlAligner.wrappers.isEmpty()) {
revalidate();
}
}
@@ -197,15 +179,14 @@ public final class ControlAligner
*
* @param items The collection of <code>Control</code>s
*/
- public void addAll(Collection<? extends Control> items)
- {
+ public void addAll(Collection<? extends Control> items) {
+
// Deactivate the auto validation while adding all the Controls
// in order to improve performance
boolean oldAutoValidate = autoValidate;
autoValidate = false;
- for (Control item : items)
- {
+ for (Control item : items) {
add(item);
}
@@ -221,15 +202,14 @@ public final class ControlAligner
*
* @param items The collection of <code>ControlAligner</code>s
*/
- public void addAllComponentAligners(Collection<ControlAligner> aligners)
- {
+ public void addAllComponentAligners(Collection<ControlAligner> aligners) {
+
// Deactivate the auto validation while adding all the JComponents and/or
// ComponentAligners in order to improve performance
boolean oldAutoValidate = autoValidate;
autoValidate = false;
- for (ControlAligner aligner : aligners)
- {
+ for (ControlAligner aligner : aligners) {
add(aligner);
}
@@ -245,15 +225,14 @@ public final class ControlAligner
*
* @param items The collection of <code>Control</code>s
*/
- public void addAllComponents(Collection<? extends Control> components)
- {
+ public void addAllComponents(Collection<? extends Control> components) {
+
// Deactivate the auto validation while adding all the JComponents and/or
// ComponentAligners in order to improve performance
boolean oldAutoValidate = autoValidate;
autoValidate = false;
- for (Control component : components)
- {
+ for (Control component : components) {
add(component);
}
@@ -266,10 +245,9 @@ public final class ControlAligner
*
* @param listener The <code>Listener</code> to be added
*/
- private void addListener(Listener listener)
- {
- if (changeSupport == null)
- {
+ private void addListener(Listener listener) {
+
+ if (changeSupport == null) {
changeSupport = new ArrayList<Listener>();
}
@@ -282,8 +260,7 @@ public final class ControlAligner
* @param control The control to be wrapped
* @return A new {@link Wrapper}
*/
- private Wrapper buildWrapper(Control control)
- {
+ private Wrapper buildWrapper(Control control) {
return new ControlWrapper(control);
}
@@ -293,8 +270,7 @@ public final class ControlAligner
* @param ControlAligner The <code>ControlAligner</code> to be wrapped
* @return A new {@link ControlAlignerWrapper}
*/
- private Wrapper buildWrapper(ControlAligner ControlAligner)
- {
+ private Wrapper buildWrapper(ControlAligner ControlAligner) {
return new ControlAlignerWrapper(ControlAligner);
}
@@ -304,22 +280,14 @@ public final class ControlAligner
* @param oldValue the old value of the property (as an int)
* @param newValue the new value of the property (as an int)
*/
- private void controlResized(int oldValue, int newValue)
- {
- if ((changeSupport != null) && (oldValue != newValue))
- {
- // Set a dummy widget otherwise EventObject will
- // throw a NPE for its source
+ private void controlResized(int oldValue, int newValue) {
+
+ if ((changeSupport != null) && (oldValue != newValue)) {
Event event = new Event();
event.widget = SWTUtil.getShell();
event.data = this;
-// Event controlEvent = new Event(event);
-
- // It seems we need to use reflection so the source can properly be set
-// ClassTools.setFieldValue(controlEvent, "source", this);
- for (Listener listener : changeSupport)
- {
+ for (Listener listener : changeSupport) {
listener.handleEvent(event);
}
}
@@ -332,36 +300,15 @@ public final class ControlAligner
* @return The width of the widest control or -1 if the length has not
* been calculated yet
*/
- public int getMaximumWidth()
- {
+ public int getMaximumWidth() {
return maximumWidth;
}
/**
- * Returns the size by determining which control has the greatest
- * width.
- *
- * @param checkVisibilityStatus <code>true</code> to check for the
- * visibility flag when calculating the preferred size; <code>false</code>
- * to calculate the size even if the control is not visible
- * @return The size of this <code>ControlAligner</code>, which is
- * {@link #getMaximumWidth()} for the width
- */
- private Point getPreferredSize(boolean checkVisibilityStatus)
- {
- if (maximumWidth == -1)
- {
- recalculateWidth(checkVisibilityStatus);
- }
-
- return new Point(maximumWidth, 0);
- }
-
- /**
* Initializes this <code>ControlAligner</code>.
*/
- private void initialize()
- {
+ private void initialize() {
+
this.autoValidate = true;
this.maximumWidth = -1;
this.listener = new ListenerHandler();
@@ -373,67 +320,31 @@ public final class ControlAligner
*
* @param source The source object to be invalidated
*/
- private void invalidate(Object source)
- {
- Wrapper wrapper = retrieveWrapper(source);
-
- if (wrapper.isLocked())
- {
- return;
- }
-
- Point size = wrapper.getCachedSize();
- size.x = 0;
- size.y = 0;
-
- wrapper.setPreferredSize(false, DEFAULT_SIZE);
- }
+ private void invalidate(Object source) {
- /**
- * Determines whether the wrapped component is visible or not, which will
- * determine if its preferred width will be included in the calculation of
- * this <code>ComponentAligner</code>'s minimum width.
- *
- * @return <code>true</code> if the source is visible; <code>false</code>
- * otherwise
- */
- private boolean isVisible()
- {
- boolean visible = true;
+ Wrapper wrapper = retrieveWrapper(source);
- for (Wrapper wrapper : wrappers)
- {
- visible &= wrapper.isVisible();
+ if (!wrapper.isLocked()) {
+ Point size = wrapper.cachedSize();
+ size.x = size.y = 0;
+ wrapper.setSize(DEFAULT_SIZE);
}
-
- return visible;
}
/**
* Updates the maximum length based on the widest control. This methods
* does not update the width of the controls.
- *
- * @param checkVisibilityStatus <code>true</code> to check for the
- * visibility flag when calculating the preferred size; <code>false</code>
- * to calculate the size even if the control is not visible
*/
- private void recalculateWidth(boolean checkVisibilityStatus)
- {
+ private void recalculateWidth() {
+
int width = -1;
- for (Wrapper wrapper : wrappers)
- {
- Point size = wrapper.getCachedSize();
+ for (Wrapper wrapper : wrappers) {
+ Point size = wrapper.cachedSize();
// The size has not been calculated yet
- if ((size.y == 0) /*&&
- (checkVisibilityStatus && wrapper.isVisible() ||
- !checkVisibilityStatus)*/)
- {
- Point newSize = wrapper.getPreferredSize(checkVisibilityStatus);
-
- size.x = newSize.x;
- size.y = newSize.y;
+ if (size.y == 0) {
+ size = wrapper.size();
}
// Only keep the greatest width
@@ -441,18 +352,27 @@ public final class ControlAligner
}
locked = true;
- setMaximumWidth(width);
- locked = false;
+
+ try {
+ setMaximumWidth(width);
+ }
+ finally {
+ locked = false;
+ }
}
/**
* Removes the given control. Its preferred width will not be used when
- * calculating the widest control.
+ * calculating the preferred width.
*
* @param control The control to be removed
+ * @exception AssertionFailedException If the given <code>Control</code> is
+ * <code>null</code>
*/
- public void remove(Control control)
- {
+ public void remove(Control control) {
+
+ Assert.isNotNull(control, "The Control to remove cannot be null");
+
Wrapper wrapper = retrieveWrapper(control);
wrapper.removeListener(listener);
wrappers.remove(wrapper);
@@ -462,12 +382,16 @@ public final class ControlAligner
/**
* Removes the given <code>ControlAligner</code>. Its preferred width
- * will not be used when calculating the widest control.
+ * will not be used when calculating the preferred witdh.
*
* @param controlAligner The <code>ControlAligner</code> to be removed
+ * @exception AssertionFailedException If the given <code>ControlAligner</code>
+ * is <code>null</code>
*/
- public void remove(ControlAligner controlAligner)
- {
+ public void remove(ControlAligner controlAligner) {
+
+ Assert.isNotNull(controlAligner, "The ControlAligner to remove cannot be null");
+
Wrapper wrapper = retrieveWrapper(controlAligner);
wrapper.removeListener(listener);
wrappers.remove(wrapper);
@@ -480,12 +404,11 @@ public final class ControlAligner
*
* @param listener The <code>Listener</code> to be removed
*/
- private void removeListener(Listener listener)
- {
+ private void removeListener(Listener listener) {
+
changeSupport.remove(listener);
- if (changeSupport.isEmpty())
- {
+ if (changeSupport.isEmpty()) {
changeSupport = null;
}
}
@@ -496,12 +419,10 @@ public final class ControlAligner
* @param source Either a <code>Control</code> or a <code>ControlAligner</code>
* @return Its <code>Wrapper</code>
*/
- private Wrapper retrieveWrapper(Object source)
- {
- for (Wrapper wrapper : wrappers)
- {
- if (wrapper.getSource() == source)
- {
+ private Wrapper retrieveWrapper(Object source) {
+
+ for (Wrapper wrapper : wrappers) {
+ if (wrapper.source() == source) {
return wrapper;
}
}
@@ -509,26 +430,16 @@ public final class ControlAligner
throw new IllegalArgumentException("Can't retrieve the Wrapper for " + source);
}
- private void revalidate()
- {
- revalidate(true);
- }
-
/**
* If the count of control is greater than one and {@link #isAutoValidate()}
* returns <code>true</code>, then the size of all the registered
* <code>Control</code>s will be udpated.
- *
- * @param checkVisibilityStatus <code>true</code> to check for the
- * visibility flag when calculating the preferred size; <code>false</code>
- * to calculate the size even if the control is not visible
*/
- private void revalidate(boolean checkVisibilityStatus)
- {
- if (autoValidate)
- {
- recalculateWidth(checkVisibilityStatus);
- revalidatePreferredSizeImp(!checkVisibilityStatus);
+ private void revalidate() {
+
+ if (autoValidate) {
+ recalculateWidth();
+ revalidateImp();
}
}
@@ -539,87 +450,59 @@ public final class ControlAligner
* @param event The <code>Event</code> sent by the UI thread when the state
* of a widget changed
*/
- private void revalidate(Event event)
- {
- boolean checkVisibilityStatus = true;
+ private void revalidate(Event event) {
+
+ // We don't need to revalidate during a revalidation process
+ if (locked) {
+ return;
+ }
+
Object source;
- if (event.widget != SWTUtil.getShell())
- {
+ if (event.widget != SWTUtil.getShell()) {
source = event.widget;
Control control = (Control) source;
- // When a dialog is opened, we need to actually force a relayout of
+ // When a dialog is opened, we need to actually force a layout of
// the controls, this is required because the control is actually
- // not visible when the preferred witdh is caculated
- if (control == control.getShell())
- {
- if (event.type == SWT.Dispose)
- {
+ // not visible when the preferred width is caculated
+ if (control == control.getShell()) {
+ if (event.type == SWT.Dispose) {
return;
}
- // When a dialog appears, the controls are actually not visible
- // force to calculate the preferred size anyway
- checkVisibilityStatus = false;
source = null;
}
}
- else
- {
+ else {
source = event.data;
}
// Either remove the ControlWrapper if the widget was disposed or
// invalidate the widget in order to recalculate the preferred size
- if (source != null)
- {
- if (event.type == SWT.Dispose)
- {
+ if (source != null) {
+ if (event.type == SWT.Dispose) {
Wrapper wrapper = retrieveWrapper(source);
wrappers.remove(wrapper);
}
- else
- {
+ else {
invalidate(source);
}
}
// Now revalidate all the Controls and ControlAligners
- revalidate(checkVisibilityStatus);
+ revalidate();
}
/**
- * Updates the preferred size of every component based on the widest
- * component.
- *
- * @param updateSize This flag is used to force the <code>Control</code>
- * to be resized
+ * Updates the size of every control based on the maximum width.
*/
- private void revalidatePreferredSizeImp(boolean updateSize)
- {
- for (Wrapper wrapper : wrappers)
- {
- Point size = wrapper.getCachedSize();
- size = new Point(maximumWidth, size.y);
- wrapper.setPreferredSize(updateSize, size);
- }
- }
+ private void revalidateImp() {
- /**
- * Updates the size of every control based on the widest control.
- *
- * @param updateSize This flag is used to force the <code>Control</code>
- * to be resized
- */
- private void revalidateSizeImp(boolean updateSize)
- {
- // Set the preferred width for every control
- for (Wrapper wrapper : wrappers)
- {
- Point size = wrapper.getCachedSize();
+ for (Wrapper wrapper : wrappers) {
+ Point size = wrapper.cachedSize();
size = new Point(maximumWidth, size.y);
- wrapper.setPreferredSize(updateSize, size);
+ wrapper.setSize(size);
}
}
@@ -629,28 +512,43 @@ public final class ControlAligner
*
* @param maximumWidth The width of the widest control
*/
- private void setMaximumWidth(int maximumWidth)
- {
+ private void setMaximumWidth(int maximumWidth) {
+
int oldMaximumWidth = getMaximumWidth();
this.maximumWidth = maximumWidth;
controlResized(oldMaximumWidth, maximumWidth);
}
/**
+ * Returns the size by determining which control has the greatest
+ * width.
+ *
+ * @return The size of this <code>ControlAligner</code>, which is
+ * {@link #getMaximumWidth()} for the width
+ */
+ private Point size() {
+
+ if (maximumWidth == -1) {
+ recalculateWidth();
+ }
+
+ return new Point(maximumWidth, 0);
+ }
+
+ /**
* Returns a string representation of this <code>ControlAligner</code>.
*
* @return Information about this object
*/
@Override
- public String toString()
- {
+ public String toString() {
+
StringBuffer sb = new StringBuffer();
- StringTools.buildToStringFor(this, sb);
- sb.append(", maximumWidth=");
+ sb.append("maximumWidth=");
sb.append(maximumWidth);
sb.append(", wrappers=");
sb.append(wrappers);
- return sb.toString();
+ return StringTools.buildToStringFor(this, sb);
}
/**
@@ -676,8 +574,7 @@ public final class ControlAligner
* @param controlAligner The <code>ControlAligner</code> to be
* encapsulated by this <code>Wrapper</code>
*/
- private ControlAlignerWrapper(ControlAligner controlAligner)
- {
+ private ControlAlignerWrapper(ControlAligner controlAligner) {
super();
this.controlAligner = controlAligner;
@@ -687,64 +584,35 @@ public final class ControlAligner
/*
* (non-Javadoc)
*/
- public void addListener(Listener listener)
- {
+ public void addListener(Listener listener) {
controlAligner.addListener(listener);
}
/*
* (non-Javadoc)
*/
- public Point getCachedSize()
- {
+ public Point cachedSize() {
return cachedSize;
}
/*
* (non-Javadoc)
*/
- public Point getPreferredSize(boolean checkVisibilityStatus)
- {
- return controlAligner.getPreferredSize(checkVisibilityStatus);
- }
-
- /*
- * (non-Javadoc)
- */
- public Object getSource()
- {
- return controlAligner;
- }
-
- /*
- * (non-Javadoc)
- */
- public boolean isLocked()
- {
+ public boolean isLocked() {
return controlAligner.locked;
}
/*
* (non-Javadoc)
*/
- public boolean isVisible()
- {
- return controlAligner.isVisible();
- }
-
- /*
- * (non-Javadoc)
- */
- public void removeListener(Listener listener)
- {
+ public void removeListener(Listener listener) {
controlAligner.removeListener(listener);
}
/*
* (non-Javadoc)
*/
- public void setPreferredSize(boolean updateSize, Point size)
- {
+ public void setSize(Point size) {
if (size == DEFAULT_SIZE)
{
controlAligner.maximumWidth = -1;
@@ -752,23 +620,36 @@ public final class ControlAligner
else if (controlAligner.maximumWidth != size.x)
{
controlAligner.maximumWidth = size.x;
- controlAligner.revalidateSizeImp(updateSize);
+ controlAligner.revalidateImp();
}
}
/*
* (non-Javadoc)
*/
+ public Point size() {
+ return controlAligner.size();
+ }
+
+ /*
+ * (non-Javadoc)
+ */
+ public Object source() {
+ return controlAligner;
+ }
+
+ /*
+ * (non-Javadoc)
+ */
@Override
- public String toString()
- {
+ public String toString() {
+
StringBuffer sb = new StringBuffer();
- StringTools.buildToStringFor(this, sb);
- sb.append("cachedSize=");
+ sb.append("Cached size=");
sb.append(cachedSize);
- sb.append(", controlAligner=");
+ sb.append(", ControlAligner=");
sb.append(controlAligner);
- return sb.toString();
+ return StringTools.buildToStringFor(this, sb);
}
}
@@ -780,7 +661,7 @@ public final class ControlAligner
/**
* The cached size, which is control's size.
*/
- private Point cachedSize;
+ private final Point cachedSize;
/**
* The control to be encapsulated by this <code>Wrapper</code>.
@@ -793,95 +674,75 @@ public final class ControlAligner
*
* @param control The control to be encapsulated by this <code>Wrapper</code>
*/
- private ControlWrapper(Control control)
- {
+ private ControlWrapper(Control control) {
super();
- this.control = control;
- cachedSize = new Point(0, 0);
+ this.control = control;
+ this.cachedSize = new Point(0, 0);
}
/*
* (non-Javadoc)
*/
- public void addListener(Listener listener)
- {
- for (int eventType : EVENT_TYPES)
- {
+ public void addListener(Listener listener) {
+
+ for (int eventType : EVENT_TYPES) {
control.addListener(eventType, listener);
}
- for (int eventType : SHELL_EVENT_TYPES)
- {
- control.getShell().addListener(eventType, listener);
- }
+// for (int eventType : SHELL_EVENT_TYPES) {
+// control.getShell().addListener(eventType, listener);
+// }
}
/*
* (non-Javadoc)
*/
- public Point getCachedSize()
- {
+ public Point cachedSize() {
return cachedSize;
}
/*
* (non-Javadoc)
*/
- public Point getPreferredSize(boolean checkVisibilityStatus)
- {
- return control.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
- }
-
- /*
- * (non-Javadoc)
- */
- public Object getSource()
- {
- return control;
- }
-
- /*
- * (non-Javadoc)
- */
- public boolean isLocked()
- {
+ public boolean isLocked() {
return false;
}
/*
* (non-Javadoc)
*/
- public boolean isVisible()
- {
+ public boolean isVisible() {
return control.isVisible();
}
/*
* (non-Javadoc)
*/
- public void removeListener(Listener listener)
- {
- for (int eventType : EVENT_TYPES)
- {
+ public void removeListener(Listener listener) {
+
+ for (int eventType : EVENT_TYPES) {
control.removeListener(eventType, listener);
}
- for (int eventType : SHELL_EVENT_TYPES)
- {
- control.getShell().removeListener(eventType, listener);
- }
+// for (int eventType : SHELL_EVENT_TYPES) {
+// control.getShell().removeListener(eventType, listener);
+// }
}
/*
* (non-Javadoc)
*/
- public void setPreferredSize(boolean updateSize, Point size)
- {
+ public void setSize(Point size) {
+
+ if (control.isDisposed()) {
+ return;
+ }
+
+ // Update the GridData with the new size
GridData data = (GridData) control.getLayoutData();
- if (data == null)
- {
+ if (data == null) {
data = new GridData();
data.horizontalAlignment = SWT.FILL;
control.setLayoutData(data);
@@ -890,29 +751,57 @@ public final class ControlAligner
data.widthHint = size.x;
data.heightHint = size.y;
- // Force the control to be resized, and tell its parent to re-layout
+ // Force the control to be resized, and tell its parent to layout
// its widgets
- if (updateSize && size.x > 0 && size.y > 0)
- {
+ if (size.x > 0) {
Rectangle bounds = control.getBounds();
- control.setBounds(bounds.x, bounds.y, size.x, size.y);
- control.getParent().layout(true);
+
+ // Only update the control's width if it's
+ // different from the current size
+ if (bounds.width != size.x) {
+ locked = true;
+
+ try {
+ control.setBounds(bounds.x, bounds.y, size.x, bounds.height);
+ control.getParent().layout(true);
+ }
+ finally
+ {
+ locked = false;
+ }
+ }
}
}
/*
* (non-Javadoc)
*/
+ public Point size() {
+ Point size = control.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
+ cachedSize.x = size.x;
+ cachedSize.y = size.y;
+ return size;
+ }
+
+ /*
+ * (non-Javadoc)
+ */
+ public Object source() {
+ return control;
+ }
+
+ /*
+ * (non-Javadoc)
+ */
@Override
- public String toString()
- {
+ public String toString() {
+
StringBuffer sb = new StringBuffer();
- StringTools.buildToStringFor(this, sb);
- sb.append("cachedSize=");
+ sb.append("Cached size=");
sb.append(cachedSize);
- sb.append(", control=");
+ sb.append(", Control=");
sb.append(control);
- return sb.toString();
+ return StringTools.buildToStringFor(this, sb);
}
}
@@ -922,8 +811,7 @@ public final class ControlAligner
*/
private class ListenerHandler implements Listener
{
- public void handleEvent(Event event)
- {
+ public void handleEvent(Event event) {
ControlAligner.this.revalidate(event);
}
}
@@ -935,13 +823,12 @@ public final class ControlAligner
private interface Wrapper
{
/**
- * Adds a <code>IPropertyChangeListener</code> for a specific property.
- * The listener will be invoked only when a call on
- * <code>firePropertyChange</code> names that specific property.
+ * Adds the given <code>Listener</code> to wrapped object in order to
+ * receive notification when its property changed.
*
* @param listener The <code>Listener</code> to be added
*/
- public void addListener(Listener listener);
+ void addListener(Listener listener);
/**
* Returns the cached size of the encapsulated source.
@@ -949,24 +836,7 @@ public final class ControlAligner
* @return A non-<code>null</code> <code>Point</code> where the x is the
* width and the y is the height of the widget
*/
- public Point getCachedSize();
-
- /**
- * Returns the preferred size of the wrapped source.
- *
- * @param checkVisibilityStatus <code>true</code> to check for the
- * visibility flag when calculating the preferred size; <code>false</code>
- * to calculate the size even if the control is not visible
- * @return The preferred size
- */
- public Point getPreferredSize(boolean checkVisibilityStatus);
-
- /**
- * Returns the encapsulated object.
- *
- * @return The object that is been wrapped
- */
- public Object getSource();
+ Point cachedSize();
/**
* Prevents infinite recursion when recalculating the preferred width.
@@ -975,32 +845,34 @@ public final class ControlAligner
* @return <code>true</code> to prevent this <code>Wrapper</code> from
* being invalidated; otherwise <code>false</code>
*/
- public boolean isLocked();
-
- /**
- * Determines whether the wrapped component is visible or not, which will
- * determine if its preferred width will be included in the calculation of
- * this <code>ComponentAligner</code>'s minimum width.
- *
- * @return <code>true</code> if the source is visible; <code>false</code>
- * otherwise
- */
- boolean isVisible();
+ boolean isLocked();
/**
* Removes the given <code>Listener</code>.
*
* @param listener The <code>Listener</code> to be removed
*/
- public void removeListener(Listener listener);
+ void removeListener(Listener listener);
/**
* Sets the size on the encapsulated source.
*
- * @param updateSize This flag is used to force the <code>Control</code>
- * to be resized
* @param size The new size
*/
- public void setPreferredSize(boolean updateSize, Point size);
+ void setSize(Point size);
+
+ /**
+ * Returns the preferred size of the wrapped source.
+ *
+ * @return The preferred size
+ */
+ Point size();
+
+ /**
+ * Returns the encapsulated object.
+ *
+ * @return The object that is been wrapped
+ */
+ Object source();
}
} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlSwitcher.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlSwitcher.java
index e70c010f7d..2c1def6475 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlSwitcher.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlSwitcher.java
@@ -104,15 +104,24 @@ public final class ControlSwitcher<T>
return;
}
+ // Retrieve the Control for the new value
Control pane = paneTransformer.transform(value);
+ boolean visible = (pane != null);
- if (pane == null) {
- pageBook.showPage(new Label(pageBook, SWT.SEPARATOR));
- }
- else {
- pageBook.showPage(pane);
- }
+ // Show the new page
+ if (visible) {
+ pageBook.showPage(pane);
+ }
+ else {
+ // Note: We can't null due to a bug in PageBook
+ pageBook.showPage(new Label(pageBook, SWT.SEPARATOR | SWT.HORIZONTAL));
+ }
+
+ if (pageBook.isVisible() != visible) {
+ pageBook.setVisible(visible);
+ }
- pageBook.setVisible(pane != null);
+ // Revalidate the parents in order to update the layout
+ SWTUtil.reflow(pageBook);
}
-}
+} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledButton.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledButton.java
index ca87b1f9be..d4ec2f8767 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledButton.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledButton.java
@@ -32,9 +32,12 @@ public final class LabeledButton implements LabeledControl
*
* @param button The button that will have its text and icon updated when
* required
+ * @exception AssertionFailedException If the given <code>Button</code> is
+ * <code>null</code>
*/
public LabeledButton(Button button) {
super();
+
Assert.isNotNull(button, "The button cannot be null");
this.button = button;
}
@@ -42,14 +45,18 @@ public final class LabeledButton implements LabeledControl
/*
* (non-Javadoc)
*/
- public void setIcon(Image image) {
- this.button.setImage(image);
+ public void setImage(Image image) {
+ if (!this.button.isDisposed()) {
+ this.button.setImage(image);
+ }
}
/*
* (non-Javadoc)
*/
public void setText(String text) {
- this.button.setText(text);
+ if (!this.button.isDisposed()) {
+ this.button.setText(text);
+ }
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledControl.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledControl.java
index 508872b76a..8a9716fa96 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledControl.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledControl.java
@@ -26,7 +26,7 @@ public interface LabeledControl {
*
* @param image The new <code>Image</code>
*/
- void setIcon(Image image);
+ void setImage(Image image);
/**
* Passes the text so the wrapped component can receive it.
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledControlUpdater.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledControlUpdater.java
index 1958bcdc44..7ce8aefbd1 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledControlUpdater.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledControlUpdater.java
@@ -48,21 +48,23 @@ public final class LabeledControlUpdater {
*
* @param labeledControl The wrapper around the control that needs to
* have its image and text updated
- * @param imageHolder The holder this class will listen for changes
- * @param textHolder The holder this class will listen for changes
+ * @param imageHolder The holder this class will listen for changes or
+ * <code>null</code> if the text never changes
+ * @param textHolder The holder this class will listen for changes or
+ * <code>null</code> if the image never changes
*/
public LabeledControlUpdater(LabeledControl labeledControl,
PropertyValueModel<String> textHolder,
PropertyValueModel<Image> imageHolder)
{
super();
- initialize(labeledControl, imageHolder, textHolder);
+ initialize(labeledControl, textHolder, imageHolder);
}
private PropertyChangeListener buildIconListener() {
return new SWTPropertyChangeListenerWrapper(buildIconListener_());
}
-
+
private PropertyChangeListener buildIconListener_() {
return new PropertyChangeListener() {
public void propertyChanged(PropertyChangeEvent e) {
@@ -79,7 +81,7 @@ public final class LabeledControlUpdater {
private PropertyChangeListener buildTextListener() {
return new SWTPropertyChangeListenerWrapper(buildTextListener_());
}
-
+
private PropertyChangeListener buildTextListener_() {
return new PropertyChangeListener() {
public void propertyChanged(PropertyChangeEvent e) {
@@ -94,16 +96,17 @@ public final class LabeledControlUpdater {
}
private void initialize(LabeledControl labeledControl,
- PropertyValueModel<Image> imageHolder,
- PropertyValueModel<String> textHolder)
+ PropertyValueModel<String> textHolder,
+ PropertyValueModel<Image> imageHolder)
{
Assert.isNotNull(labeledControl, "The LabeledControl cannot be null");
- Assert.isNotNull(textHolder, "The text holder cannot be null");
this.labeledControl = labeledControl;
- textHolder.addPropertyChangeListener(PropertyValueModel.VALUE, buildTextListener());
- setText(textHolder.value());
+ if (textHolder != null) {
+ textHolder.addPropertyChangeListener(PropertyValueModel.VALUE, buildTextListener());
+ setText(textHolder.value());
+ }
if (imageHolder != null) {
imageHolder.addPropertyChangeListener(PropertyValueModel.VALUE, buildIconListener());
@@ -112,10 +115,15 @@ public final class LabeledControlUpdater {
}
private void setImage(Image icon) {
- labeledControl.setIcon(icon);
+ labeledControl.setImage(icon);
}
private void setText(String text) {
+
+ if (text == null) {
+ text = "";
+ }
+
labeledControl.setText(text);
}
-}
+} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledLabel.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledLabel.java
index a1230ae71c..bb271327b6 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledLabel.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledLabel.java
@@ -32,9 +32,12 @@ public final class LabeledLabel implements LabeledControl
*
* @param label The label that will have its text and icon updated when
* required
+ * @exception AssertionFailedException If the given <code>Label</code> is
+ * <code>null</code>
*/
public LabeledLabel(Label label) {
super();
+
Assert.isNotNull(label, "The label cannot be null");
this.label = label;
}
@@ -42,14 +45,18 @@ public final class LabeledLabel implements LabeledControl
/*
* (non-Javadoc)
*/
- public void setIcon(Image image) {
- this.label.setImage(image);
+ public void setImage(Image image) {
+ if (!this.label.isDisposed()) {
+ this.label.setImage(image);
+ }
}
/*
* (non-Javadoc)
*/
public void setText(String text) {
- this.label.setText(text);
+ if (!this.label.isDisposed()) {
+ this.label.setText(text);
+ }
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledTableItem.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledTableItem.java
index bdf0174961..ffd5abc52c 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledTableItem.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledTableItem.java
@@ -34,6 +34,8 @@ public final class LabeledTableItem implements LabeledControl
*
* @param tableItem The <code>TableItem</code> that will have its text and
* icon updated when required
+ * @exception AssertionFailedException If the given <code>TableItem</code> is
+ * <code>null</code>
*/
public LabeledTableItem(TableItem tableItem) {
super();
@@ -45,13 +47,11 @@ public final class LabeledTableItem implements LabeledControl
/*
* (non-Javadoc)
*/
- public void setIcon(final Image image) {
+ public void setImage(final Image image) {
- if (tableItem.isDisposed()) {
- return;
+ if (!tableItem.isDisposed()) {
+ updateTableItem(tableItem.getText(), image);
}
-
- updateTableItem(tableItem.getText(), image);
}
/*
@@ -59,11 +59,9 @@ public final class LabeledTableItem implements LabeledControl
*/
public void setText(final String text) {
- if (tableItem.isDisposed()) {
- return;
+ if (!tableItem.isDisposed()) {
+ updateTableItem(text, tableItem.getImage());
}
-
- updateTableItem(text, tableItem.getImage());
}
private void updateTableItem(String text, Image image) {
@@ -87,6 +85,7 @@ public final class LabeledTableItem implements LabeledControl
tableItem.setImage(image);
tableItem.setChecked(checked);
tableItem.setGrayed(grayed);
+ tableItem.setBackground(table.getBackground());
table.layout(true, true);
table.getParent().getParent().layout(true, true);
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/SWTUtil.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/SWTUtil.java
index 3585006bdb..e2b5f4d10e 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/SWTUtil.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/SWTUtil.java
@@ -16,12 +16,14 @@ import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jpt.ui.internal.widgets.NullPostExecution;
import org.eclipse.jpt.ui.internal.widgets.PostExecution;
+import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
/**
* A suite of utility methods related to the user interface.
@@ -140,6 +142,43 @@ public class SWTUtil {
}
/**
+ * Relays out the parents of the <code>Control</code>. This was taken from
+ * the widget <code>Section</code>.
+ *
+ * @param pane The pane to revalidate as well as its parents
+ */
+ public static void reflow(Composite pane) {
+
+ for (Composite composite = pane; composite != null; ) {
+ composite.setRedraw(false);
+ composite = composite.getParent();
+
+ if (composite instanceof ScrolledForm) {
+ break;
+ }
+ }
+
+ for (Composite composite = pane; composite != null; ) {
+ composite.layout(true);
+ composite = composite.getParent();
+
+ if (composite instanceof ScrolledForm) {
+ ((ScrolledForm) composite).reflow(true);
+ break;
+ }
+ }
+
+ for (Composite composite = pane; composite != null; ) {
+ composite.setRedraw(true);
+ composite = composite.getParent();
+
+ if (composite instanceof ScrolledForm) {
+ break;
+ }
+ }
+ }
+
+ /**
* Sets whether the entire shell and its widgets should be enabled or
* everything should be unaccessible.
*
@@ -158,15 +197,6 @@ public class SWTUtil {
* Asynchronously launches the specified dialog in the UI thread.
*
* @param dialog The dialog to show on screen
- */
- public static void show(Dialog dialog) {
- show(dialog, NullPostExecution.<Dialog>instance());
- }
-
- /**
- * Asynchronously launches the specified dialog in the UI thread.
- *
- * @param dialog The dialog to show on screen
* @param postExecution This interface let the caller to invoke a piece of
* code once the dialog is disposed
*/
@@ -199,6 +229,15 @@ public class SWTUtil {
* Asynchronously launches the specified dialog in the UI thread.
*
* @param dialog The dialog to show on screen
+ */
+ public static void show(Dialog dialog) {
+ show(dialog, NullPostExecution.<Dialog>instance());
+ }
+
+ /**
+ * Asynchronously launches the specified dialog in the UI thread.
+ *
+ * @param dialog The dialog to show on screen
* @param postExecution This interface let the caller to invoke a piece of
* code once the dialog is disposed
*/
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/TableLayoutComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/TableLayoutComposite.java
index 11bb2b2e57..a037b12bd1 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/TableLayoutComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/TableLayoutComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
* 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
@@ -30,21 +30,21 @@ import org.eclipse.swt.widgets.TableColumn;
* A special composite to layout columns inside a table. The composite is needed since we have
* to layout the columns "before" the actual table gets layouted. Hence we can't use a normal
* layout manager.
- *
+ *
* copied from jdt.internal.ui.util
*/
public class TableLayoutComposite extends Composite {
/**
- * The number of extra pixels taken as horizontal trim by the table column.
+ * The number of extra pixels taken as horizontal trim by the table column.
* To ensure there are N pixels available for the content of the column,
* assign N+COLUMN_TRIM for the column width.
- *
+ *
* @since 3.1
*/
private static int COLUMN_TRIM = "carbon".equals(SWT.getPlatform()) ? 24 : 3; //$NON-NLS-1$
-
- private List columns= new ArrayList();
+
+ private List<ColumnLayoutData> columns= new ArrayList<ColumnLayoutData>();
/**
* Creates a new <code>TableLayoutComposite</code>.
@@ -52,7 +52,8 @@ public class TableLayoutComposite extends Composite {
public TableLayoutComposite(Composite parent, int style) {
super(parent, style);
addControlListener(new ControlAdapter() {
- public void controlResized(ControlEvent e) {
+ @Override
+ public void controlResized(ControlEvent e) {
Rectangle area= getClientArea();
Table table= (Table)getChildren()[0];
Point preferredSize= computeTableSize(table);
@@ -67,7 +68,7 @@ public class TableLayoutComposite extends Composite {
}
});
}
-
+
/**
* Adds a new column of data to this table layout.
*
@@ -76,16 +77,16 @@ public class TableLayoutComposite extends Composite {
public void addColumnData(ColumnLayoutData data) {
columns.add(data);
}
-
+
//---- Helpers -------------------------------------------------------------------------------------
-
+
private Point computeTableSize(Table table) {
Point result= table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
-
+
int width= 0;
int size= columns.size();
for (int i= 0; i < size; ++i) {
- ColumnLayoutData layoutData= (ColumnLayoutData) columns.get(i);
+ ColumnLayoutData layoutData= columns.get(i);
if (layoutData instanceof ColumnPixelData) {
ColumnPixelData col= (ColumnPixelData) layoutData;
width += col.width;
@@ -103,7 +104,7 @@ public class TableLayoutComposite extends Composite {
result.x= width;
return result;
}
-
+
private void layoutTable(Table table, int width, Rectangle area, boolean increase) {
// XXX: Layout is being called with an invalid value the first time
// it is being called on Linux. This method resets the
@@ -121,7 +122,7 @@ public class TableLayoutComposite extends Composite {
// First calc space occupied by fixed columns
for (int i= 0; i < size; i++) {
- ColumnLayoutData col= (ColumnLayoutData) columns.get(i);
+ ColumnLayoutData col= columns.get(i);
if (col instanceof ColumnPixelData) {
ColumnPixelData cpd= (ColumnPixelData) col;
int pixels= cpd.width;
@@ -148,7 +149,7 @@ public class TableLayoutComposite extends Composite {
int rest= width - fixedWidth;
int totalDistributed= 0;
for (int i= 0; i < size; ++i) {
- ColumnLayoutData col= (ColumnLayoutData) columns.get(i);
+ ColumnLayoutData col= columns.get(i);
if (col instanceof ColumnWeightData) {
ColumnWeightData cw= (ColumnWeightData) col;
// calculate weight as above
@@ -167,14 +168,14 @@ public class TableLayoutComposite extends Composite {
for (int i= 0; diff > 0; ++i) {
if (i == size)
i= 0;
- ColumnLayoutData col= (ColumnLayoutData) columns.get(i);
+ ColumnLayoutData col= columns.get(i);
if (col instanceof ColumnWeightData) {
++widths[i];
--diff;
}
}
}
-
+
if (increase) {
table.setSize(area.width, area.height);
}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractPane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractPane.java
index cb54528c6e..0d2edc00a3 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractPane.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractPane.java
@@ -1401,16 +1401,7 @@ public abstract class AbstractPane<T extends Model>
*/
protected final PageBook buildPageBook(Composite container) {
- GridLayout layout = new GridLayout(1, false);
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- layout.marginTop = 0;
- layout.marginLeft = 0;
- layout.marginBottom = 0;
- layout.marginRight = 0;
-
PageBook pageBook = new PageBook(container, SWT.NULL);
- pageBook.setLayout(layout);
pageBook.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
return pageBook;
}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AddRemovePane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AddRemovePane.java
index 5470430daf..54f1b60aac 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AddRemovePane.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AddRemovePane.java
@@ -221,15 +221,6 @@ public abstract class AddRemovePane<T extends Model> extends AbstractPane<T>
};
}
-// private ListChangeListener/*<Object>*/ buildListChangeListener() {
-// return new ListChangeAdapter/*<Object>*/() {
-// @Override
-// public void listChanged(ListChangeEvent/*<Object>*/ e) {
-// AddRemovePane.this.updateButtons();
-// }
-// };
-// }
-
/**
* @category Option
*/
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/TriStateCheckBox.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/TriStateCheckBox.java
index 91e80945e4..f5896b6c09 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/TriStateCheckBox.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/TriStateCheckBox.java
@@ -209,6 +209,13 @@ public final class TriStateCheckBox {
}
/**
+ * Disposes the actual widget.
+ */
+ public void dispose() {
+ getCheckBox().dispose();
+ }
+
+ /**
* Returns the actual <code>TableItem</code> used to show a tri-state check
* box.
*
diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/META-INF/MANIFEST.MF b/jpa/tests/org.eclipse.jpt.ui.tests/META-INF/MANIFEST.MF
index 89e2edbab8..f2f27019d5 100644
--- a/jpa/tests/org.eclipse.jpt.ui.tests/META-INF/MANIFEST.MF
+++ b/jpa/tests/org.eclipse.jpt.ui.tests/META-INF/MANIFEST.MF
@@ -5,13 +5,15 @@ Bundle-Vendor: %providerName
Bundle-SymbolicName: org.eclipse.jpt.ui.tests
Bundle-Version: 1.0.0
Require-Bundle: org.junit,
+ org.junit4;bundle-version="4.3.1",
org.eclipse.core.runtime,
org.eclipse.jface,
org.eclipse.jpt.core.tests,
org.eclipse.jpt.core.tests.extension.resource,
org.eclipse.jpt.utility,
org.eclipse.jpt.core,
- org.eclipse.jpt.ui
+ org.eclipse.jpt.ui,
+ org.eclipse.ui.workbench;bundle-version="3.4.0"
Eclipse-LazyStart: true
Export-Package: org.eclipse.jpt.ui.tests;x-internal:=true,
org.eclipse.jpt.ui.tests.internal.platform;x-internal:=true,
diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/JptUiTests.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/JptUiTests.java
index 98f849359c..09aac1629d 100644
--- a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/JptUiTests.java
+++ b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/JptUiTests.java
@@ -3,15 +3,16 @@
* 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.ui.tests;
-import org.eclipse.jpt.ui.tests.internal.platform.JptUiPlatformTests;
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.eclipse.jpt.ui.tests.internal.platform.JptUiPlatformTests;
+import org.eclipse.jpt.ui.tests.internal.util.JptUiUtilTests;
/**
* Runs all JPT UI Tests
@@ -21,9 +22,10 @@ public class JptUiTests {
public static Test suite() {
TestSuite suite = new TestSuite(JptUiTests.class.getPackage().getName());
suite.addTest(JptUiPlatformTests.suite());
+ suite.addTest(JptUiUtilTests.suite());
return suite;
}
-
+
private JptUiTests() {
super();
throw new UnsupportedOperationException();
diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/ControlAlignerTest.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/ControlAlignerTest.java
new file mode 100644
index 0000000000..eefd7bde08
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/ControlAlignerTest.java
@@ -0,0 +1,332 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.ui.tests.internal.util;
+
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jpt.ui.internal.util.ControlAligner;
+import org.eclipse.jpt.ui.internal.util.SWTUtil;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+@SuppressWarnings("nls")
+public final class ControlAlignerTest {
+
+ private Composite parent;
+
+ @Before
+ public void setUp() {
+ parent = new Composite(SWTUtil.getShell(), SWT.NONE);
+ parent.setLayout(new GridLayout());
+ }
+
+ @After
+ public void tearDown() {
+ if (parent != null) {
+ parent.dispose();
+ parent = null;
+ }
+ }
+
+ @Test
+ public void testAddControl1() throws Exception {
+
+ Label label = new Label(parent, SWT.NULL);
+
+ ControlAligner controlAligner = new ControlAligner();
+ controlAligner.add(label);
+
+ assertEquals(
+ "The maximum width should be 0,",
+ 0,
+ controlAligner.getMaximumWidth()
+ );
+
+ label.setText("This is a ControlAligner");
+ parent.layout(true, true);
+
+ Point size = label.getSize();
+
+ assertEquals(
+ "The width should be " + size.x + ",",
+ size.x,
+ controlAligner.getMaximumWidth()
+ );
+ }
+
+ @Test
+ public void testAddControl2() throws Exception {
+
+ Button button = new Button(parent, SWT.NULL);
+ button.setText("This is a ControlAligner");
+ parent.layout(true, true);
+
+ ControlAligner controlAligner = new ControlAligner();
+ controlAligner.add(button);
+
+ Point size = button.getSize();
+
+ assertEquals(
+ "The width should be " + size.x + ",",
+ size.x,
+ controlAligner.getMaximumWidth()
+ );
+ }
+
+ @Test
+ public void testAddControl3() throws Exception {
+
+ Label label = new Label(parent, SWT.NULL);
+ label.setText("This is very long text");
+
+ Button button = new Button(parent, SWT.NULL);
+ button.setText("Short text");
+ parent.layout(true, true);
+
+ ControlAligner controlAligner = new ControlAligner();
+ controlAligner.add(label);
+ controlAligner.add(button);
+
+ Point labelSize = label.getSize();
+ Point buttonSize = button.getSize();
+ int max = Math.max(labelSize.x, buttonSize.x);
+
+ assertEquals(
+ "The width should be " + max + ",",
+ max,
+ controlAligner.getMaximumWidth()
+ );
+ }
+
+ @Test
+ public void testDialog_AddControl1() throws Exception {
+
+ final ControlAligner controlAligner = new ControlAligner();
+ final int[] maximumWidth = new int[1];
+ final int[] size = new int[1];
+
+ TitleAreaDialog dialog = new TitleAreaDialog(SWTUtil.getShell()) {
+
+ private Label label;
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+
+ label = new Label(parent, SWT.LEFT);
+ label.setText("This is a ControlAligner");
+
+ GridData data = new GridData();
+ data.grabExcessHorizontalSpace = false;
+ data.horizontalAlignment = SWT.LEFT;
+ label.setLayoutData(data);
+
+ controlAligner.add(label);
+
+ return parent;
+ }
+
+ @Override
+ protected void initializeBounds() {
+ super.initializeBounds();
+ size[0] = label.getSize().x;
+ maximumWidth[0] = controlAligner.getMaximumWidth();
+ }
+ };
+
+ dialog.create();
+ dialog.close();
+
+ assertEquals(
+ "The width should be " + size[0] + ",",
+ size[0],
+ maximumWidth[0]
+ );
+ }
+
+ @Test
+ public void testDialog_AddControl2() throws Exception {
+
+ final ControlAligner controlAligner = new ControlAligner();
+ final int[] maximumWidth = new int[1];
+ final int[] sizes = new int[2];
+
+ TitleAreaDialog dialog = new TitleAreaDialog(SWTUtil.getShell()) {
+
+ private Button button;
+ private Label label;
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+
+ label = new Label(parent, SWT.NULL);
+ label.setText("This is a ControlAligner");
+
+ GridData data = new GridData();
+ data.grabExcessHorizontalSpace = false;
+ data.horizontalAlignment = SWT.LEFT;
+ label.setLayoutData(data);
+
+ controlAligner.add(label);
+
+ button = new Button(parent, SWT.NULL);
+ button.setText("Short text");
+
+ data = new GridData();
+ data.grabExcessHorizontalSpace = false;
+ data.horizontalAlignment = SWT.LEFT;
+ button.setLayoutData(data);
+
+ controlAligner.add(button);
+
+ return parent;
+ }
+
+ @Override
+ protected void initializeBounds() {
+ super.initializeBounds();
+ sizes[0] = label.getSize().x;
+ sizes[1] = button.getSize().x;
+ maximumWidth[0] = controlAligner.getMaximumWidth();
+ }
+ };
+
+ dialog.create();
+ dialog.close();
+
+ int labelSize = sizes[0];
+ int buttonSize = sizes[1];
+ int max = Math.max(labelSize, buttonSize);
+
+ assertEquals(
+ "The width should be " + max + ",",
+ max,
+ maximumWidth[0]
+ );
+ }
+
+ @Test
+ public void testRemoveControl1() throws Exception {
+
+ Button button = new Button(parent, SWT.NULL);
+ button.setText("This is a ControlAligner");
+ parent.layout(true, true);
+
+ ControlAligner controlAligner = new ControlAligner();
+ controlAligner.add(button);
+
+ Point size = button.getSize();
+
+ assertEquals(
+ "The width should be " + size.x + ",",
+ size.x,
+ controlAligner.getMaximumWidth()
+ );
+
+ controlAligner.remove(button);
+
+ assertEquals(
+ "The width should be -1, ",
+ -1,
+ controlAligner.getMaximumWidth()
+ );
+ }
+
+ @Test
+ public void testRemoveControl2() throws Exception {
+
+ Label label = new Label(parent, SWT.NULL);
+ label.setText("This is very long text");
+
+ Button button = new Button(parent, SWT.NULL);
+ button.setText("Short text");
+ parent.layout(true, true);
+
+ ControlAligner controlAligner = new ControlAligner();
+ controlAligner.add(label);
+ controlAligner.add(button);
+
+ Point labelSize = label.getSize();
+ Point buttonSize = button.getSize();
+ int max = Math.max(labelSize.x, buttonSize.x);
+
+ assertEquals(
+ "The width should be " + max + ",",
+ max,
+ controlAligner.getMaximumWidth()
+ );
+
+ controlAligner.remove(label);
+
+ Point newButtonSize = button.getSize();
+
+ assertNotSame(
+ "The old max and new max should not be the same",
+ max,
+ newButtonSize.x
+ );
+
+ assertEquals(
+ "The ControlAligner doesn't have the right maximum width",
+ newButtonSize.x,
+ controlAligner.getMaximumWidth()
+ );
+ }
+
+ @Test
+ public void testRemoveControl3() throws Exception {
+
+ Label label = new Label(parent, SWT.NULL);
+ label.setText("This is very long text");
+
+ Button button = new Button(parent, SWT.NULL);
+ button.setText("Short text");
+ parent.layout(true, true);
+
+ ControlAligner controlAligner = new ControlAligner();
+ controlAligner.add(label);
+ controlAligner.add(button);
+
+ Point labelSize = label.getSize();
+ Point buttonSize = button.getSize();
+ int max = Math.max(labelSize.x, buttonSize.x);
+
+ assertEquals(
+ "The width should be " + max + ",",
+ max,
+ controlAligner.getMaximumWidth()
+ );
+
+ label.dispose();
+
+ Point newButtonSize = button.getSize();
+
+ assertNotSame(
+ "The old max and new max should not be the same",
+ max,
+ newButtonSize.x
+ );
+
+ assertEquals(
+ "The ControlAligner doesn't have the right maximum width",
+ newButtonSize.x,
+ controlAligner.getMaximumWidth()
+ );
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/ControlSwitcherTest.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/ControlSwitcherTest.java
new file mode 100644
index 0000000000..018085f20d
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/ControlSwitcherTest.java
@@ -0,0 +1,188 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.ui.tests.internal.util;
+
+import org.eclipse.jpt.ui.internal.util.ControlSwitcher;
+import org.eclipse.jpt.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.Transformer;
+import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.part.PageBook;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+@SuppressWarnings("nls")
+public final class ControlSwitcherTest {
+
+ private PageBook pageBook;
+ private Composite pane1;
+ private Composite pane2;
+ private Composite parent;
+
+ private Composite buildPane1() {
+
+ if (pane1 == null) {
+
+ pane1 = new Composite(pageBook, SWT.NULL);
+ pane1.setLayout(new GridLayout(2, false));
+
+ Label label = new Label(pane1, SWT.NULL);
+ label.setText("&Test2:");
+
+ Text text = new Text(pane1, SWT.BORDER);
+ text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ Combo combo = new Combo(pane1, SWT.BORDER);
+
+ GridData data = new GridData(GridData.FILL_HORIZONTAL);
+ data.horizontalSpan = 2;
+ combo.setLayoutData(data);
+ }
+
+ return pane1;
+ }
+
+ private Composite buildPane2() {
+
+ if (pane2 == null) {
+
+ pane2 = new Composite(pageBook, SWT.NULL);
+ pane2.setLayout(new GridLayout(2, false));
+
+ Label label = new Label(pane2, SWT.NULL);
+ label.setText("&Test1:");
+
+ Text text = new Text(pane2, SWT.BORDER);
+ text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ }
+
+ return pane2;
+ }
+
+ private Transformer<Boolean, Control> buildTransformer() {
+ return new Transformer<Boolean, Control>() {
+ public Control transform(Boolean value) {
+ return (value == null) ? null : (value ? pane1 : pane2);
+ }
+ };
+ }
+
+ @Before
+ public void setUp() {
+ parent = new Composite(SWTUtil.getShell(), SWT.NONE);
+ parent.setLayout(new GridLayout());
+
+ pageBook = new PageBook(parent, SWT.NULL);
+ pageBook.setLayoutData(new GridData());
+ }
+
+ @After
+ public void tearDown() {
+
+ if (parent != null) {
+
+ parent.dispose();
+
+ parent = null;
+ pageBook = null;
+ }
+ }
+
+ @Test
+ public void testSwitch() {
+
+ SimplePropertyValueModel<Boolean> switchHolder = new SimplePropertyValueModel<Boolean>();
+ Transformer<Boolean, Control> transformer = buildTransformer();
+
+ pane1 = buildPane1();
+ pane1.setVisible(false);
+
+ pane2 = buildPane2();
+ pane2.setVisible(false);
+
+ new ControlSwitcher<Boolean>(
+ switchHolder,
+ transformer,
+ pageBook
+ );
+
+ // Test 1
+ switchHolder.setValue(true);
+ Control control = (Control) ClassTools.fieldValue(pageBook, "currentPage");
+
+ assertNotNull(
+ "The page book's page shouldn't be null",
+ control
+ );
+
+ assertSame(
+ "The current pane should be pane1",
+ pane1,
+ control
+ );
+
+ Point pane1Size = pane1.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ Point pageBookSize = pageBook.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+
+ assertEquals(
+ "The width of the PageBook should be the same as the width of pane1",
+ pane1Size.x,
+ pageBookSize.x
+ );
+
+ assertEquals(
+ "The height of the PageBook should be the same as the height of pane1",
+ pane1Size.y,
+ pageBookSize.y
+ );
+
+ // Test 2
+ switchHolder.setValue(false);
+ control = (Control) ClassTools.fieldValue(pageBook, "currentPage");
+
+ assertNotNull(
+ "The page book's page shouldn't be null",
+ control
+ );
+
+ assertSame(
+ "The current pane should be pane2",
+ pane2,
+ control
+ );
+
+ Point pane2Size = pane2.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ pageBookSize = pageBook.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+
+ assertEquals(
+ "The width of the PageBook should be the same as the width of pane2",
+ pane2Size.x,
+ pageBookSize.x
+ );
+
+ assertEquals(
+ "The height of the PageBook should be the same as the height of pane2",
+ pane2Size.y,
+ pageBookSize.y
+ );
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/JptUiUtilTests.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/JptUiUtilTests.java
new file mode 100644
index 0000000000..64b6f1b0d3
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/JptUiUtilTests.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.ui.tests.internal.util;
+
+import junit.framework.JUnit4TestAdapter;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+@SuiteClasses
+({
+ ControlAlignerTest.class,
+ ControlSwitcherTest.class,
+ LabeledButtonTest.class,
+ LabeledLabelTest.class,
+ LabeledTableItemTest.class,
+ LabeledControlUpdaterTest.class,
+})
+@RunWith(Suite.class)
+public final class JptUiUtilTests {
+
+ private JptUiUtilTests() {
+ super();
+ throw new UnsupportedOperationException();
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ suite.addTest(new JUnit4TestAdapter(JptUiUtilTests.class));
+ return suite;
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/LabeledButtonTest.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/LabeledButtonTest.java
new file mode 100644
index 0000000000..8057d1b29d
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/LabeledButtonTest.java
@@ -0,0 +1,123 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.ui.tests.internal.util;
+
+import org.eclipse.core.runtime.AssertionFailedException;
+import org.eclipse.jpt.ui.internal.util.LabeledButton;
+import org.eclipse.jpt.ui.internal.util.SWTUtil;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+@SuppressWarnings("nls")
+public final class LabeledButtonTest {
+
+ private Composite parent;
+
+ @Before
+ public void setUp() {
+ parent = new Composite(SWTUtil.getShell(), SWT.NONE);
+ parent.setLayout(new GridLayout());
+ }
+
+ @After
+ public void tearDown() {
+ if (parent != null) {
+ parent.dispose();
+ parent = null;
+ }
+ }
+
+ @Test
+ public void testLabeledButton1() {
+ Button button = new Button(parent, SWT.NULL);
+ new LabeledButton(button);
+ }
+
+ @Test(expected=AssertionFailedException.class)
+ public void testLabeledButton2() {
+ new LabeledButton(null);
+ }
+
+ @Test
+ public void testSetImage() {
+
+ Image expected = new Image(parent.getDisplay(), 16, 16);
+
+ try {
+ Button button = new Button(parent, SWT.NULL);
+ LabeledButton labeledButton = new LabeledButton(button);
+
+ labeledButton.setImage(expected);
+
+ assertEquals(
+ "The Button didn't receive the Image",
+ expected,
+ button.getImage()
+ );
+ }
+ finally {
+ expected.dispose();
+ }
+ }
+
+ @Test
+ public void testSetImageDispose() {
+
+ Image expected = new Image(parent.getDisplay(), 16, 16);
+
+ try {
+ Button button = new Button(parent, SWT.NULL);
+ LabeledButton labeledButton = new LabeledButton(button);
+
+ button.dispose();
+
+ // This should not fail but simply do nothing
+ labeledButton.setImage(expected);
+ }
+ finally {
+ expected.dispose();
+ }
+ }
+
+ @Test
+ public void testSetText() {
+ Button button = new Button(parent, SWT.NULL);
+ LabeledButton labeledButton = new LabeledButton(button);
+
+ String expected = "This is a test";
+ labeledButton.setText(expected);
+
+ assertEquals(
+ "The Button didn't receive the text",
+ expected,
+ button.getText()
+ );
+ }
+
+ @Test
+ public void testSetTextDispose() {
+ Button button = new Button(parent, SWT.NULL);
+ LabeledButton labeledButton = new LabeledButton(button);
+
+ button.dispose();
+
+ // This should not fail but simply do nothing
+ String expected = "This is a test";
+ labeledButton.setText(expected);
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/LabeledControlUpdaterTest.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/LabeledControlUpdaterTest.java
new file mode 100644
index 0000000000..8695ec78f3
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/LabeledControlUpdaterTest.java
@@ -0,0 +1,125 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.ui.tests.internal.util;
+
+import org.eclipse.jpt.ui.internal.util.LabeledControlUpdater;
+import org.eclipse.jpt.ui.internal.util.LabeledLabel;
+import org.eclipse.jpt.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+@SuppressWarnings("nls")
+public final class LabeledControlUpdaterTest {
+
+ private Composite parent;
+
+ @Before
+ public void setUp() {
+ parent = new Composite(SWTUtil.getShell(), SWT.NONE);
+ parent.setLayout(new GridLayout());
+ }
+
+ @After
+ public void tearDown() {
+ if (parent != null) {
+ parent.dispose();
+ parent = null;
+ }
+ }
+
+ @Test
+ public void testSetImage() {
+
+ Image expected = new Image(parent.getDisplay(), 16, 16);
+
+ try {
+ Label label = new Label(parent, SWT.NULL);
+ LabeledLabel labeledLabel = new LabeledLabel(label);
+
+ WritablePropertyValueModel<Image> imageHolder = new SimplePropertyValueModel<Image>();
+ new LabeledControlUpdater(labeledLabel, null, imageHolder);
+
+ labeledLabel.setImage(expected);
+
+ assertEquals(
+ "The Label didn't receive the Image",
+ expected,
+ label.getImage()
+ );
+ }
+ finally {
+ expected.dispose();
+ }
+ }
+
+ @Test
+ public void testSetImageDispose() {
+
+ Image expected = new Image(parent.getDisplay(), 16, 16);
+
+ try {
+ Label label = new Label(parent, SWT.NULL);
+ LabeledLabel labeledLabel = new LabeledLabel(label);
+
+ WritablePropertyValueModel<Image> imageHolder = new SimplePropertyValueModel<Image>();
+ new LabeledControlUpdater(labeledLabel, null, imageHolder);
+
+ label.dispose();
+ labeledLabel.setImage(expected);
+ }
+ finally {
+ expected.dispose();
+ }
+ }
+
+ @Test
+ public void testSetText() {
+
+ Label label = new Label(parent, SWT.NULL);
+ LabeledLabel labeledLabel = new LabeledLabel(label);
+
+ WritablePropertyValueModel<String> textHolder = new SimplePropertyValueModel<String>();
+ new LabeledControlUpdater(labeledLabel, textHolder);
+
+ String expected = "This is a test";
+ textHolder.setValue(expected);
+
+ assertEquals(
+ "The Label didn't receive the text",
+ expected,
+ label.getText()
+ );
+ }
+
+ @Test
+ public void testSetTextDispose() {
+
+ Label label = new Label(parent, SWT.NULL);
+ LabeledLabel labeledLabel = new LabeledLabel(label);
+
+ WritablePropertyValueModel<String> textHolder = new SimplePropertyValueModel<String>();
+ new LabeledControlUpdater(labeledLabel, textHolder);
+
+ label.dispose();
+
+ String expected = "This is a test";
+ textHolder.setValue(expected);
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/LabeledLabelTest.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/LabeledLabelTest.java
new file mode 100644
index 0000000000..5440d3c21d
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/LabeledLabelTest.java
@@ -0,0 +1,123 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.ui.tests.internal.util;
+
+import org.eclipse.core.runtime.AssertionFailedException;
+import org.eclipse.jpt.ui.internal.util.LabeledLabel;
+import org.eclipse.jpt.ui.internal.util.SWTUtil;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+@SuppressWarnings("nls")
+public final class LabeledLabelTest {
+
+ private Composite parent;
+
+ @Before
+ public void setUp() {
+ parent = new Composite(SWTUtil.getShell(), SWT.NONE);
+ parent.setLayout(new GridLayout());
+ }
+
+ @After
+ public void tearDown() {
+ if (parent != null) {
+ parent.dispose();
+ parent = null;
+ }
+ }
+
+ @Test
+ public void testLabeledButton1() {
+ Label label = new Label(parent, SWT.NULL);
+ new LabeledLabel(label);
+ }
+
+ @Test(expected=AssertionFailedException.class)
+ public void testLabeledButton2() {
+ new LabeledLabel(null);
+ }
+
+ @Test
+ public void testSetImage() {
+
+ Image expected = new Image(parent.getDisplay(), 16, 16);
+
+ try {
+ Label label = new Label(parent, SWT.NULL);
+ LabeledLabel labeledLabel = new LabeledLabel(label);
+
+ labeledLabel.setImage(expected);
+
+ assertEquals(
+ "The Label didn't receive the Image",
+ expected,
+ label.getImage()
+ );
+ }
+ finally {
+ expected.dispose();
+ }
+ }
+
+ @Test
+ public void testSetImageDispose() {
+
+ Image expected = new Image(parent.getDisplay(), 16, 16);
+
+ try {
+ Label label = new Label(parent, SWT.NULL);
+ LabeledLabel labeledLabel = new LabeledLabel(label);
+
+ label.dispose();
+
+ // This should not fail but simply do nothing
+ labeledLabel.setImage(expected);
+ }
+ finally {
+ expected.dispose();
+ }
+ }
+
+ @Test
+ public void testSetText() {
+ Label label = new Label(parent, SWT.NULL);
+ LabeledLabel labeledLabel = new LabeledLabel(label);
+
+ String expected = "This is a test";
+ labeledLabel.setText(expected);
+
+ assertEquals(
+ "The Label didn't receive the text",
+ expected,
+ label.getText()
+ );
+ }
+
+ @Test
+ public void testSetTextDispose() {
+ Label label = new Label(parent, SWT.NULL);
+ LabeledLabel labeledLabel = new LabeledLabel(label);
+
+ label.dispose();
+
+ // This should not fail but simply do nothing
+ String expected = "This is a test";
+ labeledLabel.setText(expected);
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/LabeledTableItemTest.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/LabeledTableItemTest.java
new file mode 100644
index 0000000000..17905fd830
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/util/LabeledTableItemTest.java
@@ -0,0 +1,123 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.ui.tests.internal.util;
+
+import org.eclipse.core.runtime.AssertionFailedException;
+import org.eclipse.jpt.ui.internal.util.LabeledTableItem;
+import org.eclipse.jpt.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.ui.internal.widgets.TriStateCheckBox;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+@SuppressWarnings("nls")
+public class LabeledTableItemTest {
+
+ private Composite parent;
+
+ @Before
+ public void setUp() {
+ parent = new Composite(SWTUtil.getShell(), SWT.NONE);
+ parent.setLayout(new GridLayout());
+ }
+
+ @After
+ public void tearDown() {
+ if (parent != null) {
+ parent.dispose();
+ parent = null;
+ }
+ }
+
+ @Test
+ public void testLabeledButton1() {
+ TriStateCheckBox checkBox = new TriStateCheckBox(parent);
+ new LabeledTableItem(checkBox.getCheckBox());
+ }
+
+ @Test(expected=AssertionFailedException.class)
+ public void testLabeledButton2() {
+ new LabeledTableItem(null);
+ }
+
+ @Test
+ public void testSetImage() {
+
+ Image expected = new Image(parent.getDisplay(), 16, 16);
+
+ try {
+ TriStateCheckBox checkBox = new TriStateCheckBox(parent);
+ LabeledTableItem labeledTableItem = new LabeledTableItem(checkBox.getCheckBox());
+
+ labeledTableItem.setImage(expected);
+
+ assertEquals(
+ "The TriStateCheckBox didn't receive the Image",
+ expected,
+ checkBox.getImage()
+ );
+ }
+ finally {
+ expected.dispose();
+ }
+ }
+
+ @Test
+ public void testSetImageDispose() {
+
+ Image expected = new Image(parent.getDisplay(), 16, 16);
+
+ try {
+ TriStateCheckBox checkBox = new TriStateCheckBox(parent);
+ LabeledTableItem labeledTableItem = new LabeledTableItem(checkBox.getCheckBox());
+
+ checkBox.dispose();
+
+ // This should not fail but simply do nothing
+ labeledTableItem.setImage(expected);
+ }
+ finally {
+ expected.dispose();
+ }
+ }
+
+ @Test
+ public void testSetText() {
+ TriStateCheckBox checkBox = new TriStateCheckBox(parent);
+ LabeledTableItem labeledTableItem = new LabeledTableItem(checkBox.getCheckBox());
+
+ String expected = "This is a test";
+ labeledTableItem.setText(expected);
+
+ assertEquals(
+ "The TriStateCheckBox didn't receive the text",
+ expected,
+ checkBox.getText()
+ );
+ }
+
+ @Test
+ public void testSetTextDispose() {
+ TriStateCheckBox checkBox = new TriStateCheckBox(parent);
+ LabeledTableItem labeledTableItem = new LabeledTableItem(checkBox.getCheckBox());
+
+ checkBox.dispose();
+
+ // This should not fail but simply do nothing
+ String expected = "This is a test";
+ labeledTableItem.setText(expected);
+ }
+}

Back to the top