summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJordan Dukadinov2012-03-28 11:48:52 (EDT)
committerJordan Dukadinov2012-04-04 09:01:26 (EDT)
commit333ae646e465a6d0e2671d731da962dc0ad62611 (patch)
treee5d165ce7a1db95c4bfc001105ae108b202790cd
parent98e00819c930ee5cac634c249eafdd18d5a4cd81 (diff)
downloadorg.eclipse.riena-333ae646e465a6d0e2671d731da962dc0ad62611.zip
org.eclipse.riena-333ae646e465a6d0e2671d731da962dc0ad62611.tar.gz
org.eclipse.riena-333ae646e465a6d0e2671d731da962dc0ad62611.tar.bz2
also reset error decoration object when setting a new UI control to a
ridget - bug 294024
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/swt/MarkerSupportTest.java43
-rw-r--r--org.eclipse.riena.ui.ridgets.swt/src/org/eclipse/riena/ui/ridgets/swt/MarkerSupport.java66
2 files changed, 68 insertions, 41 deletions
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/swt/MarkerSupportTest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/swt/MarkerSupportTest.java
index d780920..155f123 100644
--- a/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/swt/MarkerSupportTest.java
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/swt/MarkerSupportTest.java
@@ -36,6 +36,7 @@ import org.eclipse.riena.ui.core.marker.ICustomMarker;
import org.eclipse.riena.ui.core.marker.MandatoryMarker;
import org.eclipse.riena.ui.core.marker.NegativeMarker;
import org.eclipse.riena.ui.core.marker.OutputMarker;
+import org.eclipse.riena.ui.ridgets.IControlDecoration;
import org.eclipse.riena.ui.ridgets.ITextRidget;
import org.eclipse.riena.ui.swt.lnf.ILnfResource;
import org.eclipse.riena.ui.swt.lnf.LnfKeyConstants;
@@ -67,6 +68,29 @@ public class MarkerSupportTest extends RienaTestCase {
display = null;
}
+ /**
+ * Bug 294024: The control decoration is always associated with a UI element and must be reset when <tt>setUIControl(...)</tt> is called on a ridget. We can
+ * not reuse the control decoration after the ui control has been changed.
+ * <p>
+ * see {@link ControlDecoration}
+ */
+ public void testUpdateControlDecorationOnUpdateControl() throws Exception {
+ final DefaultRealm realm = new DefaultRealm();
+ try {
+ final Text control1 = new Text(shell, SWT.NONE);
+ final Text control2 = new Text(shell, SWT.NONE);
+ final ITextRidget ridget = new TextRidget();
+ ridget.setUIControl(control1);
+ ridget.setErrorMarked(true);
+ final MarkerSupport support = ReflectionUtils.getHidden(ridget, "markerSupport");
+ final IControlDecoration ed1 = ReflectionUtils.invokeHidden(support, "getOrCreateErrorDecorationForControl", control1);
+ ridget.setUIControl(control2);
+ assertNotSame(ed1, ReflectionUtils.invokeHidden(support, "getOrCreateErrorDecorationForControl", control2));
+ } finally {
+ realm.dispose();
+ }
+ }
+
public void testHideDisabledRidgetContentSystemProperty() throws IOException {
System.clearProperty(HIDE_DISABLED_RIDGET_CONTENT);
assertFalse(getHideDisabledRidgetContent());
@@ -125,8 +149,7 @@ public class MarkerSupportTest extends RienaTestCase {
final TextRidget ridget = new TextRidget();
ridget.setUIControl(control);
final BasicMarkerSupport msup = ReflectionUtils.invokeHidden(ridget, "createMarkerSupport");
- final Object visualizer = ReflectionUtils
- .invokeHidden(msup, "getDisabledMarkerVisualizer", (Object[]) null);
+ final Object visualizer = ReflectionUtils.invokeHidden(msup, "getDisabledMarkerVisualizer", (Object[]) null);
assertNotNull(visualizer);
@@ -190,7 +213,7 @@ public class MarkerSupportTest extends RienaTestCase {
ridget.addMarker(new ErrorMarker());
markerSupport.updateMarkers();
- final ControlDecoration errorDecoration = ReflectionUtils.getHidden(markerSupport, "errorDecoration");
+ final ControlDecoration errorDecoration = ReflectionUtils.invokeHidden(markerSupport, "getErrorDecorationForControl", control);
assertNotNull(errorDecoration);
assertTrue(errorDecoration.isVisible());
@@ -204,8 +227,7 @@ public class MarkerSupportTest extends RienaTestCase {
}
/**
- * Test reflection usage which does not cause an exception in method
- * getControlBackground()
+ * Test reflection usage which does not cause an exception in method getControlBackground()
*/
public void testReflectionUtilsUsageInGetControlBackground() {
final CCombo combo = new CCombo(shell, SWT.NONE);
@@ -321,9 +343,8 @@ public class MarkerSupportTest extends RienaTestCase {
//////////////////
/**
- * This {@code ClassLoader}s method {@code getFreshMarkSupportClass()}
- * retrieves with each call a new, fresh {@code MarkSupport} class. This
- * allows testing of the static field which gets initialized on class load.
+ * This {@code ClassLoader}s method {@code getFreshMarkSupportClass()} retrieves with each call a new, fresh {@code MarkSupport} class. This allows testing
+ * of the static field which gets initialized on class load.
*/
private static class MarkSupportClassLoader extends ClassLoader {
public MarkSupportClassLoader() {
@@ -366,8 +387,7 @@ public class MarkerSupportTest extends RienaTestCase {
@Override
protected void initializeTheme() {
super.initializeTheme();
- final Map<String, ILnfResource> resourceTable = ReflectionUtils.getHidden(MyNonsenseLnf.this,
- "resourceTable");
+ final Map<String, ILnfResource> resourceTable = ReflectionUtils.getHidden(MyNonsenseLnf.this, "resourceTable");
resourceTable.clear();
final Map<String, Object> settingTable = ReflectionUtils.getHidden(MyNonsenseLnf.this, "settingTable");
settingTable.clear();
@@ -376,8 +396,7 @@ public class MarkerSupportTest extends RienaTestCase {
}
/**
- * This extension changes the visibility of some protected methods for
- * testing.
+ * This extension changes the visibility of some protected methods for testing.
*/
private static class MyMarkerSupport extends MarkerSupport {
diff --git a/org.eclipse.riena.ui.ridgets.swt/src/org/eclipse/riena/ui/ridgets/swt/MarkerSupport.java b/org.eclipse.riena.ui.ridgets.swt/src/org/eclipse/riena/ui/ridgets/swt/MarkerSupport.java
index 95640aa..5e2f61f 100644
--- a/org.eclipse.riena.ui.ridgets.swt/src/org/eclipse/riena/ui/ridgets/swt/MarkerSupport.java
+++ b/org.eclipse.riena.ui.ridgets.swt/src/org/eclipse/riena/ui/ridgets/swt/MarkerSupport.java
@@ -58,8 +58,7 @@ import org.eclipse.riena.ui.swt.lnf.rienadefault.RienaDefaultLnf;
/**
* Helper class for SWT Ridgets to delegate their marker issues to.
* <p>
- * The class can hide these marker types (including subclasses):
- * {@link MandatoryMarker}, {@link ErrorMarker}
+ * The class can hide these marker types (including subclasses): {@link MandatoryMarker}, {@link ErrorMarker}
*/
public class MarkerSupport extends BasicMarkerSupport {
@@ -68,40 +67,34 @@ public class MarkerSupport extends BasicMarkerSupport {
private static final String PRE_OUTPUT_BACKGROUND_KEY = "MaSu.preOuBa"; //$NON-NLS-1$
private static final String PRE_OUTPUT_FOREGROUND_KEY = "MaSu.preOuFo"; //$NON-NLS-1$
private static final String PRE_NEGATIVE_FOREGROUND_KEY = "MaSu.preNeFo"; //$NON-NLS-1$
+ private static final String ERROR_DECORATION_FOR_CONTROL_KEY = "MaSu.errDe"; //$NON-NLS-1$
private static final long FLASH_DURATION_MS = 300;
/**
- * This flag defines the default value that defines whether disabled ridgets
- * do hide their content. Since v2.0 the default value is {@code false}. It
- * can be overridden by setting the system property
- * {@code 'HIDE_DISABLED_RIDGET_CONTENT'} to {@code true}.
+ * This flag defines the default value that defines whether disabled ridgets do hide their content. Since v2.0 the default value is {@code false}. It can be
+ * overridden by setting the system property {@code 'HIDE_DISABLED_RIDGET_CONTENT'} to {@code true}.
* <p>
- * Note: A Look&Feel constants exists to define whether disabled ridgets do
- * hide their content: {@code LnfKeyConstants.DISABLED_MARKER_HIDE_CONTENT}.
- * The default value is only used, if the current Look&Feel doesn't use
- * {@code LnfKeyConstants.DISABLED_MARKER_HIDE_CONTENT}.
+ * Note: A Look&Feel constants exists to define whether disabled ridgets do hide their content: {@code LnfKeyConstants.DISABLED_MARKER_HIDE_CONTENT}. The
+ * default value is only used, if the current Look&Feel doesn't use {@code LnfKeyConstants.DISABLED_MARKER_HIDE_CONTENT}.
*/
private static final boolean HIDE_DISABLED_RIDGET_CONTENT = Boolean.parseBoolean(System.getProperty(
"HIDE_DISABLED_RIDGET_CONTENT", Boolean.FALSE.toString())); //$NON-NLS-1$
private static Boolean hideDisabledRidgetContent;
- private IControlDecoration errorDecoration;
private boolean isFlashInProgress;
// internal data of the control
private final Map<String, Object> internalData;
/**
- * Returns whether the content of a disabled ridget should be visible (
- * {@code false}) or hidden {@code true}.
+ * Returns whether the content of a disabled ridget should be visible ( {@code false}) or hidden {@code true}.
*
* @return ({@code false}): visible; {@code true}: hidden
* @since 2.0
*/
public static boolean isHideDisabledRidgetContent() {
if (hideDisabledRidgetContent == null) {
- hideDisabledRidgetContent = LnfManager.getLnf().getBooleanSetting(
- LnfKeyConstants.DISABLED_MARKER_HIDE_CONTENT, HIDE_DISABLED_RIDGET_CONTENT);
+ hideDisabledRidgetContent = LnfManager.getLnf().getBooleanSetting(LnfKeyConstants.DISABLED_MARKER_HIDE_CONTENT, HIDE_DISABLED_RIDGET_CONTENT);
}
return hideDisabledRidgetContent;
}
@@ -125,10 +118,7 @@ public class MarkerSupport extends BasicMarkerSupport {
if (!isFlashInProgress && control != null) {
isFlashInProgress = true;
- if (errorDecoration == null) {
- errorDecoration = createErrorDecoration(control);
- }
-
+ final IControlDecoration errorDecoration = getOrCreateErrorDecorationForControl(control);
final boolean isShowing = errorDecoration.isVisible();
if (isShowing) {
errorDecoration.hide();
@@ -163,10 +153,7 @@ public class MarkerSupport extends BasicMarkerSupport {
////////////////////
protected void addError(final Control control) {
- if (errorDecoration == null) {
- errorDecoration = createErrorDecoration(control);
- }
- errorDecoration.show();
+ getOrCreateErrorDecorationForControl(control).show();
}
protected void addMandatory(final Control control) {
@@ -234,6 +221,7 @@ public class MarkerSupport extends BasicMarkerSupport {
}
protected void clearError(final Control control) {
+ final IControlDecoration errorDecoration = getErrorDecorationForControl(control);
if (errorDecoration != null) {
errorDecoration.hide();
}
@@ -300,6 +288,29 @@ public class MarkerSupport extends BasicMarkerSupport {
// helping methods
//////////////////
+ /**
+ * Since each {@link IControlDecoration} is associated with exactly one UI control, we must ensure that we do not reuse the old decoration after a new
+ * control is set.
+ * <p>
+ * DO NOT RENAME. This method is being called by the unit tests (via reflection).
+ */
+ private IControlDecoration getErrorDecorationForControl(final Control control) {
+ return (IControlDecoration) control.getData(ERROR_DECORATION_FOR_CONTROL_KEY);
+ }
+
+ /**
+ * Check the data field with key {@link MarkerSupport}.ERROR_DECORATION_FOR_CONTROL_KEY and returns the value if set, otherwise create a control decoration
+ * and set it as control data.
+ *
+ * @return never <code>null</code>
+ */
+ private IControlDecoration getOrCreateErrorDecorationForControl(final Control control) {
+ if (getErrorDecorationForControl(control) == null) {
+ control.setData(ERROR_DECORATION_FOR_CONTROL_KEY, createErrorDecoration(control));
+ }
+ return getErrorDecorationForControl(control);
+ }
+
private void addNegative(final Control control) {
if (getData(PRE_NEGATIVE_FOREGROUND_KEY) == null) {
setData(PRE_NEGATIVE_FOREGROUND_KEY, control.getForeground());
@@ -346,8 +357,7 @@ public class MarkerSupport extends BasicMarkerSupport {
}
private void updateError(final Control control) {
- if (getRidget().isErrorMarked() && getRidget().isEnabled() && getRidget().isVisible()
- && !isHidden(ErrorMarker.class)) {
+ if (getRidget().isErrorMarked() && getRidget().isEnabled() && getRidget().isVisible() && !isHidden(ErrorMarker.class)) {
if (!(isButton(control) && getRidget().isOutputOnly())) {
addError(control);
} else {
@@ -359,8 +369,7 @@ public class MarkerSupport extends BasicMarkerSupport {
}
private void updateMandatory(final Control control) {
- if (isMandatory(getRidget()) && !getRidget().isOutputOnly() && getRidget().isEnabled()
- && !isHidden(MandatoryMarker.class)) {
+ if (isMandatory(getRidget()) && !getRidget().isOutputOnly() && getRidget().isEnabled() && !isHidden(MandatoryMarker.class)) {
addMandatory(control);
} else {
clearMandatory(control);
@@ -460,8 +469,7 @@ public class MarkerSupport extends BasicMarkerSupport {
/**
* {@inheritDoc}
* <p>
- * The constructor of this implementation sets the margin width and the
- * image to avoid unnecessary updates.
+ * The constructor of this implementation sets the margin width and the image to avoid unnecessary updates.
*/
private static class MarkerControlDecoration extends ControlDecoration implements IControlDecoration {