Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspingel2010-12-10 14:29:43 -0500
committerspingel2010-12-10 14:29:43 -0500
commitd9af088498ce6b1f0af38cf85714cc99a77d5c75 (patch)
tree6990a282fb498b8eb390f35c88812eed37f91d2c
parent11fd0b1602eed078e905164ddb5b720e9d0bf2a4 (diff)
downloadorg.eclipse.mylyn.tasks-d9af088498ce6b1f0af38cf85714cc99a77d5c75.tar.gz
org.eclipse.mylyn.tasks-d9af088498ce6b1f0af38cf85714cc99a77d5c75.tar.xz
org.eclipse.mylyn.tasks-d9af088498ce6b1f0af38cf85714cc99a77d5c75.zip
NEW - bug 332328: [patch][api] extend AttributeEditorToolkit to support control decorations for validation
https://bugs.eclipse.org/bugs/show_bug.cgi?id=332328
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AttributeEditorToolkit.java48
1 files changed, 47 insertions, 1 deletions
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AttributeEditorToolkit.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AttributeEditorToolkit.java
index 456f4a1e6..32a176040 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AttributeEditorToolkit.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AttributeEditorToolkit.java
@@ -11,6 +11,8 @@
package org.eclipse.mylyn.tasks.ui.editors;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.fieldassist.ComboContentAdapter;
import org.eclipse.jface.fieldassist.ContentProposalAdapter;
import org.eclipse.jface.fieldassist.ControlDecoration;
@@ -29,9 +31,12 @@ import org.eclipse.mylyn.internal.tasks.ui.PersonProposalProvider;
import org.eclipse.mylyn.internal.tasks.ui.editors.EditorUtil;
import org.eclipse.mylyn.internal.tasks.ui.editors.Messages;
import org.eclipse.mylyn.internal.tasks.ui.editors.PersonAttributeEditor;
-import org.eclipse.mylyn.internal.tasks.ui.editors.RichTextAttributeEditor;
import org.eclipse.mylyn.internal.tasks.ui.editors.RepositoryTextViewerConfiguration.Mode;
+import org.eclipse.mylyn.internal.tasks.ui.editors.RichTextAttributeEditor;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.mylyn.tasks.core.data.TaskDataModelEvent;
+import org.eclipse.mylyn.tasks.core.data.TaskDataModelEvent.EventKind;
+import org.eclipse.mylyn.tasks.core.data.TaskDataModelListener;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
@@ -228,4 +233,45 @@ public class AttributeEditorToolkit {
this.renderingEngine = renderingEngine;
}
+ /**
+ * Adds input validation to an attribute editor and a controlDecoration if invalid
+ *
+ * @since 3.5
+ */
+ public static void createValidator(final AbstractAttributeEditor attributeEditor, Control control,
+ final IInputValidator validator) {
+ Assert.isNotNull(validator);
+ Assert.isNotNull(control);
+ Assert.isNotNull(attributeEditor);
+ final ControlDecoration decoration = new ControlDecoration(control, SWT.BOTTOM | SWT.LEFT);
+ decoration.setMarginWidth(2);
+ FieldDecoration errorDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(
+ FieldDecorationRegistry.DEC_ERROR);
+ decoration.setImage(errorDecoration.getImage());
+ decoration.hide();
+ final TaskDataModelListener validationListener = new TaskDataModelListener() {
+ @Override
+ public void attributeChanged(TaskDataModelEvent event) {
+ if (event.getTaskAttribute().equals(attributeEditor.getTaskAttribute())) {
+ String validationMessage = validator.isValid(attributeEditor.getTaskAttribute().getValue());
+ if (validationMessage == null) {
+ decoration.hide();
+ } else {
+ decoration.setDescriptionText(validationMessage);
+ decoration.show();
+ }
+ }
+ }
+ };
+ attributeEditor.getModel().addModelListener(validationListener);
+ control.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ decoration.dispose();
+ attributeEditor.getModel().removeModelListener(validationListener);
+ }
+ });
+ validationListener.attributeChanged(new TaskDataModelEvent(attributeEditor.getModel(), EventKind.CHANGED,
+ attributeEditor.getTaskAttribute()));
+ }
+
}

Back to the top