View | Details | Raw Unified | Return to bug 284384
Collapse All | Expand All

(-)src/org/eclipse/jface/examples/databinding/snippets/Snippet033CrossValidationControlDecoration.java (-5 / +5 lines)
Lines 113-125 Link Here
113
113
114
		// Customize the decoration's description text and image
114
		// Customize the decoration's description text and image
115
		ControlDecorationUpdater decorationUpdater = new ControlDecorationUpdater() {
115
		ControlDecorationUpdater decorationUpdater = new ControlDecorationUpdater() {
116
			protected String getDescriptionText(IStatus status) {
116
			protected String getDescriptionText(IStatus status, boolean init) {
117
				return "ERROR: " + super.getDescriptionText(status);
117
				return "ERROR: " + super.getDescriptionText(status, init);
118
			}
118
			}
119
119
120
			protected Image getImage(IStatus status) {
120
			protected Image getImage(IStatus status, boolean init) {
121
				return status.isOK() ? null : Display.getCurrent()
121
				return init ? null : status.isOK() ? null : Display
122
						.getSystemImage(SWT.ICON_ERROR);
122
						.getCurrent().getSystemImage(SWT.ICON_ERROR);
123
			}
123
			}
124
		};
124
		};
125
		ControlDecorationSupport.create(new DateRangeValidator(Observables
125
		ControlDecorationSupport.create(new DateRangeValidator(Observables
(-)src/org/eclipse/jface/internal/databinding/provisional/fieldassist/ControlDecorationSupport.java (-5 / +5 lines)
Lines 116-122 Link Here
116
116
117
	private IValueChangeListener statusChangeListener = new IValueChangeListener() {
117
	private IValueChangeListener statusChangeListener = new IValueChangeListener() {
118
		public void handleValueChange(ValueChangeEvent event) {
118
		public void handleValueChange(ValueChangeEvent event) {
119
			statusChanged((IStatus) validationStatus.getValue());
119
			statusChanged((IStatus) validationStatus.getValue(), false);
120
		}
120
		}
121
	};
121
	};
122
122
Lines 131-137 Link Here
131
					targetRemoved((IObservable) element);
131
					targetRemoved((IObservable) element);
132
				}
132
				}
133
			});
133
			});
134
			statusChanged((IStatus) validationStatus.getValue());
134
			statusChanged((IStatus) validationStatus.getValue(), false);
135
		}
135
		}
136
	};
136
	};
137
137
Lines 171-177 Link Here
171
		for (Iterator it = targets.iterator(); it.hasNext();)
171
		for (Iterator it = targets.iterator(); it.hasNext();)
172
			targetAdded((IObservable) it.next());
172
			targetAdded((IObservable) it.next());
173
173
174
		statusChanged((IStatus) validationStatus.getValue());
174
		statusChanged((IStatus) validationStatus.getValue(), true);
175
	}
175
	}
176
176
177
	private void targetAdded(IObservable target) {
177
	private void targetAdded(IObservable target) {
Lines 220-230 Link Here
220
		return null;
220
		return null;
221
	}
221
	}
222
222
223
	private void statusChanged(IStatus status) {
223
	private void statusChanged(IStatus status, boolean init) {
224
		for (Iterator it = targetDecorations.iterator(); it.hasNext();) {
224
		for (Iterator it = targetDecorations.iterator(); it.hasNext();) {
225
			TargetDecoration targetDecoration = (TargetDecoration) it.next();
225
			TargetDecoration targetDecoration = (TargetDecoration) it.next();
226
			ControlDecoration decoration = targetDecoration.decoration;
226
			ControlDecoration decoration = targetDecoration.decoration;
227
			updater.update(decoration, status);
227
			updater.update(decoration, status, init);
228
		}
228
		}
229
	}
229
	}
230
230
(-)src/org/eclipse/jface/internal/databinding/provisional/fieldassist/ControlDecorationUpdater.java (-18 / +59 lines)
Lines 30-35 Link Here
30
public class ControlDecorationUpdater {
30
public class ControlDecorationUpdater {
31
	/**
31
	/**
32
	 * <b>EXPERIMENTAL</b>: This method is not API. It is experimental and
32
	 * <b>EXPERIMENTAL</b>: This method is not API. It is experimental and
33
	 * subject to arbitrary change, including removals. Please provide feedback
34
	 * if you would like to see this become API.
35
	 * 
36
	 * @return .
37
	 */
38
	public static ControlDecorationUpdater required() {
39
		return new ControlDecorationUpdater() {
40
			protected String getFieldDecorationId(IStatus status, boolean init) {
41
				String decorationId = super.getFieldDecorationId(status, init);
42
				if (decorationId == null || init)
43
					return FieldDecorationRegistry.DEC_REQUIRED;
44
				return decorationId;
45
			}
46
		};
47
	}
48
49
	/**
50
	 * <b>EXPERIMENTAL</b>: This method is not API. It is experimental and
33
	 * subject to arbitrary change, including removal. Please provide feedback
51
	 * subject to arbitrary change, including removal. Please provide feedback
34
	 * if you would like to see this become API.
52
	 * if you would like to see this become API.
35
	 * <p>
53
	 * <p>
Lines 40-52 Link Here
40
	 *            the ControlDecoration to update
58
	 *            the ControlDecoration to update
41
	 * @param status
59
	 * @param status
42
	 *            the status to be displayed by the decoration
60
	 *            the status to be displayed by the decoration
61
	 * @param init
62
	 *            whether the decoration is being updated for the first time
43
	 */
63
	 */
44
	protected void update(ControlDecoration decoration, IStatus status) {
64
	protected void update(ControlDecoration decoration, IStatus status,
65
			boolean init) {
45
		if (status == null || status.isOK()) {
66
		if (status == null || status.isOK()) {
46
			decoration.hide();
67
			decoration.hide();
47
		} else {
68
		} else {
48
			decoration.setImage(getImage(status));
69
			decoration.setImage(getImage(status, init));
49
			decoration.setDescriptionText(getDescriptionText(status));
70
			decoration.setDescriptionText(getDescriptionText(status, init));
50
			decoration.show();
71
			decoration.show();
51
		}
72
		}
52
	}
73
	}
Lines 62-71 Link Here
62
	 * 
83
	 * 
63
	 * @param status
84
	 * @param status
64
	 *            the status object.
85
	 *            the status object.
86
	 * @param init
87
	 *            whether the decoration is being updated for the first time
65
	 * @return the description text to show in a ControlDecoration for the given
88
	 * @return the description text to show in a ControlDecoration for the given
66
	 *         status.
89
	 *         status.
67
	 */
90
	 */
68
	protected String getDescriptionText(IStatus status) {
91
	protected String getDescriptionText(IStatus status, boolean init) {
69
		return status == null ? "" : status.getMessage(); //$NON-NLS-1$
92
		return status == null ? "" : status.getMessage(); //$NON-NLS-1$
70
	}
93
	}
71
94
Lines 76-100 Link Here
76
	 * <p>
99
	 * <p>
77
	 * Returns an image to display in a ControlDecoration which is appropriate
100
	 * Returns an image to display in a ControlDecoration which is appropriate
78
	 * for the given status. The default implementation of this method returns
101
	 * for the given status. The default implementation of this method returns
79
	 * an image according to <code>status.getSeverity()</code>:
102
	 * an image according to <code>status.getSeverity()</code> and/or the
103
	 * <code>init</code> parameter:
80
	 * <ul>
104
	 * <ul>
81
	 * <li>IStatus.OK => No image
105
	 * <li>severity == IStatus.OK => No image
82
	 * <li>IStatus.INFO => FieldDecorationRegistry.DEC_INFORMATION
106
	 * <li>severity == IStatus.INFO => FieldDecorationRegistry.DEC_INFORMATION
83
	 * <li>IStatus.WARNING => FieldDecorationRegistry.DEC_WARNING
107
	 * <li>severity == IStatus.WARNING => FieldDecorationRegistry.DEC_WARNING
84
	 * <li>IStatus.ERROR => FieldDecorationRegistry.DEC_ERROR
108
	 * <li>init == true => No image
85
	 * <li>IStatus.CANCEL => FieldDecorationRegistry.DEC_ERROR
109
	 * <li>severity == IStatus.ERROR => FieldDecorationRegistry.DEC_ERROR
110
	 * <li>severity == IStatus.CANCEL => FieldDecorationRegistry.DEC_ERROR
86
	 * <li>Other => No image
111
	 * <li>Other => No image
87
	 * </ul>
112
	 * </ul>
88
	 * 
113
	 * 
89
	 * @param status
114
	 * @param status
90
	 *            the status object.
115
	 *            the status object (may be null)
116
	 * @param init
117
	 *            whether the decoration is being updated for the first time
91
	 * @return an image to display in a ControlDecoration which is appropriate
118
	 * @return an image to display in a ControlDecoration which is appropriate
92
	 *         for the given status.
119
	 *         for the given status.
93
	 */
120
	 */
94
	protected Image getImage(IStatus status) {
121
	protected Image getImage(IStatus status, boolean init) {
122
		FieldDecoration decoration = FieldDecorationRegistry.getDefault()
123
				.getFieldDecoration(getFieldDecorationId(status, init));
124
		return decoration == null ? null : decoration.getImage();
125
	}
126
127
	/**
128
	 * <b>EXPERIMENTAL</b>: This method is not API. It is experimental and
129
	 * subject to arbitrary change, including removal. Please provide feedback
130
	 * if you would like to see this become API.
131
	 * 
132
	 * @param status
133
	 *            the status object (may be null)
134
	 * @param init
135
	 *            whether the decoration is being updated for the first time
136
	 * @return .
137
	 */
138
	protected String getFieldDecorationId(IStatus status, boolean init) {
95
		if (status == null)
139
		if (status == null)
96
			return null;
140
			return null;
97
98
		String fieldDecorationID = null;
141
		String fieldDecorationID = null;
99
		switch (status.getSeverity()) {
142
		switch (status.getSeverity()) {
100
		case IStatus.INFO:
143
		case IStatus.INFO:
Lines 105-116 Link Here
105
			break;
148
			break;
106
		case IStatus.ERROR:
149
		case IStatus.ERROR:
107
		case IStatus.CANCEL:
150
		case IStatus.CANCEL:
108
			fieldDecorationID = FieldDecorationRegistry.DEC_ERROR;
151
			if (!init)
152
				fieldDecorationID = FieldDecorationRegistry.DEC_ERROR;
109
			break;
153
			break;
110
		}
154
		}
111
155
		return fieldDecorationID;
112
		FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault()
113
				.getFieldDecoration(fieldDecorationID);
114
		return fieldDecoration == null ? null : fieldDecoration.getImage();
115
	}
156
	}
116
}
157
}

Return to bug 284384