### Eclipse Workspace Patch 1.0 #P org.eclipse.jface.examples.databinding Index: src/org/eclipse/jface/examples/databinding/snippets/Snippet033CrossValidationControlDecoration.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet033CrossValidationControlDecoration.java,v retrieving revision 1.1 diff -u -r1.1 Snippet033CrossValidationControlDecoration.java --- src/org/eclipse/jface/examples/databinding/snippets/Snippet033CrossValidationControlDecoration.java 31 Mar 2009 14:58:51 -0000 1.1 +++ src/org/eclipse/jface/examples/databinding/snippets/Snippet033CrossValidationControlDecoration.java 23 Jul 2009 17:49:57 -0000 @@ -113,13 +113,13 @@ // Customize the decoration's description text and image ControlDecorationUpdater decorationUpdater = new ControlDecorationUpdater() { - protected String getDescriptionText(IStatus status) { - return "ERROR: " + super.getDescriptionText(status); + protected String getDescriptionText(IStatus status, boolean init) { + return "ERROR: " + super.getDescriptionText(status, init); } - protected Image getImage(IStatus status) { - return status.isOK() ? null : Display.getCurrent() - .getSystemImage(SWT.ICON_ERROR); + protected Image getImage(IStatus status, boolean init) { + return init ? null : status.isOK() ? null : Display + .getCurrent().getSystemImage(SWT.ICON_ERROR); } }; ControlDecorationSupport.create(new DateRangeValidator(Observables #P org.eclipse.jface.databinding Index: src/org/eclipse/jface/internal/databinding/provisional/fieldassist/ControlDecorationSupport.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/fieldassist/ControlDecorationSupport.java,v retrieving revision 1.1 diff -u -r1.1 ControlDecorationSupport.java --- src/org/eclipse/jface/internal/databinding/provisional/fieldassist/ControlDecorationSupport.java 31 Mar 2009 14:58:53 -0000 1.1 +++ src/org/eclipse/jface/internal/databinding/provisional/fieldassist/ControlDecorationSupport.java 23 Jul 2009 17:49:58 -0000 @@ -116,7 +116,7 @@ private IValueChangeListener statusChangeListener = new IValueChangeListener() { public void handleValueChange(ValueChangeEvent event) { - statusChanged((IStatus) validationStatus.getValue()); + statusChanged((IStatus) validationStatus.getValue(), false); } }; @@ -131,7 +131,7 @@ targetRemoved((IObservable) element); } }); - statusChanged((IStatus) validationStatus.getValue()); + statusChanged((IStatus) validationStatus.getValue(), false); } }; @@ -171,7 +171,7 @@ for (Iterator it = targets.iterator(); it.hasNext();) targetAdded((IObservable) it.next()); - statusChanged((IStatus) validationStatus.getValue()); + statusChanged((IStatus) validationStatus.getValue(), true); } private void targetAdded(IObservable target) { @@ -220,11 +220,11 @@ return null; } - private void statusChanged(IStatus status) { + private void statusChanged(IStatus status, boolean init) { for (Iterator it = targetDecorations.iterator(); it.hasNext();) { TargetDecoration targetDecoration = (TargetDecoration) it.next(); ControlDecoration decoration = targetDecoration.decoration; - updater.update(decoration, status); + updater.update(decoration, status, init); } } Index: src/org/eclipse/jface/internal/databinding/provisional/fieldassist/ControlDecorationUpdater.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/fieldassist/ControlDecorationUpdater.java,v retrieving revision 1.1 diff -u -r1.1 ControlDecorationUpdater.java --- src/org/eclipse/jface/internal/databinding/provisional/fieldassist/ControlDecorationUpdater.java 31 Mar 2009 14:58:53 -0000 1.1 +++ src/org/eclipse/jface/internal/databinding/provisional/fieldassist/ControlDecorationUpdater.java 23 Jul 2009 17:49:58 -0000 @@ -30,6 +30,24 @@ public class ControlDecorationUpdater { /** * EXPERIMENTAL: This method is not API. It is experimental and + * subject to arbitrary change, including removals. Please provide feedback + * if you would like to see this become API. + * + * @return . + */ + public static ControlDecorationUpdater required() { + return new ControlDecorationUpdater() { + protected String getFieldDecorationId(IStatus status, boolean init) { + String decorationId = super.getFieldDecorationId(status, init); + if (decorationId == null || init) + return FieldDecorationRegistry.DEC_REQUIRED; + return decorationId; + } + }; + } + + /** + * EXPERIMENTAL: This method is not API. It is experimental and * subject to arbitrary change, including removal. Please provide feedback * if you would like to see this become API. *

@@ -40,13 +58,16 @@ * the ControlDecoration to update * @param status * the status to be displayed by the decoration + * @param init + * whether the decoration is being updated for the first time */ - protected void update(ControlDecoration decoration, IStatus status) { + protected void update(ControlDecoration decoration, IStatus status, + boolean init) { if (status == null || status.isOK()) { decoration.hide(); } else { - decoration.setImage(getImage(status)); - decoration.setDescriptionText(getDescriptionText(status)); + decoration.setImage(getImage(status, init)); + decoration.setDescriptionText(getDescriptionText(status, init)); decoration.show(); } } @@ -62,10 +83,12 @@ * * @param status * the status object. + * @param init + * whether the decoration is being updated for the first time * @return the description text to show in a ControlDecoration for the given * status. */ - protected String getDescriptionText(IStatus status) { + protected String getDescriptionText(IStatus status, boolean init) { return status == null ? "" : status.getMessage(); //$NON-NLS-1$ } @@ -76,25 +99,45 @@ *

* Returns an image to display in a ControlDecoration which is appropriate * for the given status. The default implementation of this method returns - * an image according to status.getSeverity(): + * an image according to status.getSeverity() and/or the + * init parameter: *

* * @param status - * the status object. + * the status object (may be null) + * @param init + * whether the decoration is being updated for the first time * @return an image to display in a ControlDecoration which is appropriate * for the given status. */ - protected Image getImage(IStatus status) { + protected Image getImage(IStatus status, boolean init) { + FieldDecoration decoration = FieldDecorationRegistry.getDefault() + .getFieldDecoration(getFieldDecorationId(status, init)); + return decoration == null ? null : decoration.getImage(); + } + + /** + * EXPERIMENTAL: This method is not API. It is experimental and + * subject to arbitrary change, including removal. Please provide feedback + * if you would like to see this become API. + * + * @param status + * the status object (may be null) + * @param init + * whether the decoration is being updated for the first time + * @return . + */ + protected String getFieldDecorationId(IStatus status, boolean init) { if (status == null) return null; - String fieldDecorationID = null; switch (status.getSeverity()) { case IStatus.INFO: @@ -105,12 +148,10 @@ break; case IStatus.ERROR: case IStatus.CANCEL: - fieldDecorationID = FieldDecorationRegistry.DEC_ERROR; + if (!init) + fieldDecorationID = FieldDecorationRegistry.DEC_ERROR; break; } - - FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault() - .getFieldDecoration(fieldDecorationID); - return fieldDecoration == null ? null : fieldDecoration.getImage(); + return fieldDecorationID; } }