diff options
author | Benjamin Muskalla | 2012-04-29 16:18:23 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2013-12-17 22:02:56 +0000 |
commit | 461cb61c85d4f7872c0faf5b9174d999bfcc98f5 (patch) | |
tree | c36be495374ed35a321c65beb44e6adc45f06f70 /org.eclipse.mylyn.tasks.ui/src/org | |
parent | 20324679c2367c793f27095c4ac89ebe7b725bf4 (diff) | |
download | org.eclipse.mylyn.tasks-461cb61c85d4f7872c0faf5b9174d999bfcc98f5.tar.gz org.eclipse.mylyn.tasks-461cb61c85d4f7872c0faf5b9174d999bfcc98f5.tar.xz org.eclipse.mylyn.tasks-461cb61c85d4f7872c0faf5b9174d999bfcc98f5.zip |
NEW - bug 378032: provide support for required attributes
https://bugs.eclipse.org/bugs/show_bug.cgi?id=378032
Change-Id: Ib3cfcb8c8cb489fab5afbb0565f6da0643ab4b97
Signed-off-by: Benjamin Muskalla <benjamin.muskalla@tasktop.com>
Diffstat (limited to 'org.eclipse.mylyn.tasks.ui/src/org')
3 files changed, 54 insertions, 3 deletions
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/Messages.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/Messages.java index 49597de80..5cf42dbf3 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/Messages.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/Messages.java @@ -25,6 +25,8 @@ public class Messages extends NLS { NLS.initializeMessages(BUNDLE_NAME, Messages.class); } + public static String AbstractAttributeEditor_AttributeIsRequired; + public static String AbstractReplyToCommentAction_Reply; public static String AttachmentSizeFormatter_0_bytes; diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/messages.properties b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/messages.properties index cb12598c9..0586ac69e 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/messages.properties +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/messages.properties @@ -8,6 +8,7 @@ # Contributors: # Tasktop Technologies - initial API and implementation ############################################################################### +AbstractAttributeEditor_AttributeIsRequired=This attribute is required AbstractReplyToCommentAction_Reply=Reply AttachmentSizeFormatter_0_bytes=0 bytes diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractAttributeEditor.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractAttributeEditor.java index 38291ebdd..f68a8a97a 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractAttributeEditor.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractAttributeEditor.java @@ -11,16 +11,22 @@ package org.eclipse.mylyn.tasks.ui.editors; +import org.apache.commons.lang.StringUtils; import org.eclipse.core.runtime.Assert; import org.eclipse.jface.action.LegacyActionTools; +import org.eclipse.jface.fieldassist.ControlDecoration; +import org.eclipse.jface.fieldassist.FieldDecorationRegistry; +import org.eclipse.mylyn.internal.tasks.ui.editors.Messages; import org.eclipse.mylyn.tasks.core.data.TaskAttribute; import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper; import org.eclipse.mylyn.tasks.core.data.TaskDataModel; import org.eclipse.mylyn.tasks.core.data.TaskDataModelEvent; import org.eclipse.mylyn.tasks.core.data.TaskDataModelListener; +import org.eclipse.swt.SWT; import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; @@ -66,10 +72,13 @@ public abstract class AbstractAttributeEditor { private final TaskDataModelListener modelListener = new TaskDataModelListener() { @Override public void attributeChanged(TaskDataModelEvent event) { - if (shouldAutoRefresh() && getTaskAttribute().equals(event.getTaskAttribute())) { + if (getTaskAttribute().equals(event.getTaskAttribute())) { try { - refreshInProgress = true; - refresh(); + if (shouldAutoRefresh()) { + refreshInProgress = true; + refresh(); + } + updateRequiredDecoration(); } catch (UnsupportedOperationException e) { } finally { refreshInProgress = false; @@ -84,6 +93,8 @@ public abstract class AbstractAttributeEditor { } }; + private ControlDecoration decoration; + /** * @since 3.0 */ @@ -233,10 +244,47 @@ public abstract class AbstractAttributeEditor { if (manager.hasOutgoingChanges(getTaskAttribute())) { decorateOutgoing(color); } + updateRequiredDecoration(); + } + } + + private void updateRequiredDecoration() { + if (getLabelControl() != null && isRequired()) { + decorateRequired(); + } else if (decoration != null) { + decoration.hide(); + decoration.dispose(); } } /** + * @since 3.11 + */ + protected void decorateRequired() { + decoration = new ControlDecoration(getLabelControl(), SWT.TOP | SWT.RIGHT); + decoration.setDescriptionText(Messages.AbstractAttributeEditor_AttributeIsRequired); + decoration.setMarginWidth(0); + Image image = FieldDecorationRegistry.getDefault() + .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR) + .getImage(); + decoration.setImage(image); + getLabelControl().addDisposeListener(new DisposeListener() { + public void widgetDisposed(DisposeEvent e) { + decoration.dispose(); + } + }); + } + + /** + * @since 3.11 + */ + protected boolean isRequired() { + boolean isRequired = getTaskAttribute().getMetaData().isRequired(); + boolean hasValue = !StringUtils.isEmpty(getTaskAttribute().getValue()); + return isRequired && !hasValue; + } + + /** * @since 3.0 */ protected void decorateOutgoing(Color color) { |