Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeo Dos Santos2013-12-13 14:26:37 -0500
committerGerrit Code Review @ Eclipse.org2013-12-17 20:13:01 -0500
commitb7eef8e0c8da174009283d5a2c7e2c518c21e9fd (patch)
tree37dced3a9d767f1784914896e6d5968d8033ecc8
parent461cb61c85d4f7872c0faf5b9174d999bfcc98f5 (diff)
downloadorg.eclipse.mylyn.tasks-b7eef8e0c8da174009283d5a2c7e2c518c21e9fd.tar.gz
org.eclipse.mylyn.tasks-b7eef8e0c8da174009283d5a2c7e2c518c21e9fd.tar.xz
org.eclipse.mylyn.tasks-b7eef8e0c8da174009283d5a2c7e2c518c21e9fd.zip
378032: [api] provide editor support for required attributes
Change-Id: I711b84be94880ab04fe0bfb15464bb4c5aa6cf33 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=378032 Signed-off-by: Leo Dos Santos <leo.dos.santos@tasktop.com>
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaTaskDataHandler.java5
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttribute.java6
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/AttributeEditorTest.java20
-rw-r--r--org.eclipse.mylyn.tasks.ui/icons/ovr16/overlay-required.gifbin48 -> 0 bytes
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractAttributeEditor.java48
5 files changed, 45 insertions, 34 deletions
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaTaskDataHandler.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaTaskDataHandler.java
index ba1f3f4dd..b50cca6da 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaTaskDataHandler.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaTaskDataHandler.java
@@ -546,7 +546,6 @@ public class BugzillaTaskDataHandler extends AbstractTaskDataHandler {
createAttribute(taskData, BugzillaAttribute.SHORT_DESC);
TaskAttribute attributeVersion = createAttribute(taskData, BugzillaAttribute.VERSION);
- attributeVersion.getMetaData().setRequired(true);
optionValues = repositoryConfiguration.getProductOptionValues(BugzillaAttribute.VERSION,
productAttribute.getValue());
Collections.sort(optionValues);
@@ -558,7 +557,6 @@ public class BugzillaTaskDataHandler extends AbstractTaskDataHandler {
}
TaskAttribute attributeComponent = createAttribute(taskData, BugzillaAttribute.COMPONENT);
- attributeComponent.getMetaData().setRequired(true);
optionValues = repositoryConfiguration.getProductOptionValues(BugzillaAttribute.COMPONENT,
productAttribute.getValue());
Collections.sort(optionValues);
@@ -609,7 +607,6 @@ public class BugzillaTaskDataHandler extends AbstractTaskDataHandler {
}
TaskAttribute attributeOPSYS = createAttribute(taskData, BugzillaAttribute.OP_SYS);
- attributeOPSYS.getMetaData().setRequired(true);
optionValues = repositoryConfiguration.getOptionValues(BugzillaAttribute.OP_SYS);
for (String option : optionValues) {
attributeOPSYS.putOption(option, option);
@@ -620,7 +617,6 @@ public class BugzillaTaskDataHandler extends AbstractTaskDataHandler {
}
TaskAttribute attributePriority = createAttribute(taskData, BugzillaAttribute.PRIORITY);
- attributePriority.getMetaData().setRequired(true);
optionValues = repositoryConfiguration.getOptionValues(BugzillaAttribute.PRIORITY);
for (String option : optionValues) {
attributePriority.putOption(option, option);
@@ -631,7 +627,6 @@ public class BugzillaTaskDataHandler extends AbstractTaskDataHandler {
}
TaskAttribute attributeSeverity = createAttribute(taskData, BugzillaAttribute.BUG_SEVERITY);
- attributeSeverity.getMetaData().setRequired(true);
optionValues = repositoryConfiguration.getOptionValues(BugzillaAttribute.BUG_SEVERITY);
for (String option : optionValues) {
attributeSeverity.putOption(option, option);
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttribute.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttribute.java
index 0f555f39a..dcea1d460 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttribute.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttribute.java
@@ -149,7 +149,11 @@ public final class TaskAttribute {
public static final String META_READ_ONLY = "task.meta.readOnly"; //$NON-NLS-1$
/**
- * @since 3.8
+ * Key for {@link TaskAttributeMetaData} used to specify that a field requires a value before it can be submitted to
+ * the server. This meta-data is used by the framework as a UI hint and does not guarantee that a connector will
+ * enforce compliance before attempting to post task data.
+ *
+ * @since 3.11
*/
public static final String META_REQUIRED = "task.meta.required"; //$NON-NLS-1$
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/AttributeEditorTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/AttributeEditorTest.java
index 77f3a15a1..d328f79b9 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/AttributeEditorTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/AttributeEditorTest.java
@@ -50,8 +50,8 @@ public class AttributeEditorTest extends TestCase {
}
@Override
- public boolean isRequired() {
- return super.isRequired();
+ public boolean needsValue() {
+ return super.needsValue();
}
@Override
@@ -90,22 +90,22 @@ public class AttributeEditorTest extends TestCase {
public void testDetermineNotRequired() throws Exception {
TaskAttribute attribute = new TaskAttribute(taskData.getRoot(), "not.required.field");
MockAttributeEditor editor = new MockAttributeEditor(manager, attribute);
- assertFalse(editor.isRequired());
+ assertFalse(editor.needsValue());
attribute.setValue("");
- assertFalse(editor.isRequired());
+ assertFalse(editor.needsValue());
attribute.setValue("abc");
- assertFalse(editor.isRequired());
+ assertFalse(editor.needsValue());
}
public void testDetermineRequired() throws Exception {
TaskAttribute attribute = new TaskAttribute(taskData.getRoot(), "a.required.field");
attribute.getMetaData().setRequired(true);
MockAttributeEditor editor = new MockAttributeEditor(manager, attribute);
- assertTrue(editor.isRequired());
+ assertTrue(editor.needsValue());
attribute.setValue("");
- assertTrue(editor.isRequired());
+ assertTrue(editor.needsValue());
attribute.setValue("abc");
- assertFalse(editor.isRequired());
+ assertFalse(editor.needsValue());
}
public void testDecorateRequired() throws Exception {
@@ -145,9 +145,9 @@ public class AttributeEditorTest extends TestCase {
}
@Override
- public boolean isRequired() {
+ public boolean needsValue() {
eventLog.append("asked");
- return super.isRequired();
+ return super.needsValue();
}
};
diff --git a/org.eclipse.mylyn.tasks.ui/icons/ovr16/overlay-required.gif b/org.eclipse.mylyn.tasks.ui/icons/ovr16/overlay-required.gif
deleted file mode 100644
index 1b17af928..000000000
--- a/org.eclipse.mylyn.tasks.ui/icons/ovr16/overlay-required.gif
+++ /dev/null
Binary files differ
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 f68a8a97a..b9fe5a8fc 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
@@ -93,6 +93,16 @@ public abstract class AbstractAttributeEditor {
}
};
+ private final DisposeListener disposeDecorationListener = new DisposeListener() {
+ @Override
+ public void widgetDisposed(DisposeEvent e) {
+ if (decoration != null) {
+ decoration.dispose();
+ decoration = null;
+ }
+ }
+ };
+
private ControlDecoration decoration;
/**
@@ -249,11 +259,15 @@ public abstract class AbstractAttributeEditor {
}
private void updateRequiredDecoration() {
- if (getLabelControl() != null && isRequired()) {
- decorateRequired();
- } else if (decoration != null) {
- decoration.hide();
- decoration.dispose();
+ if (getLabelControl() != null) {
+ if (needsValue()) {
+ decorateRequired();
+ } else if (decoration != null) {
+ decoration.hide();
+ decoration.dispose();
+ decoration = null;
+ getLabelControl().removeDisposeListener(disposeDecorationListener);
+ }
}
}
@@ -261,24 +275,22 @@ public abstract class AbstractAttributeEditor {
* @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();
- }
- });
+ if (decoration == null) {
+ 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(disposeDecorationListener);
+ }
}
/**
* @since 3.11
*/
- protected boolean isRequired() {
+ protected boolean needsValue() {
boolean isRequired = getTaskAttribute().getMetaData().isRequired();
boolean hasValue = !StringUtils.isEmpty(getTaskAttribute().getValue());
return isRequired && !hasValue;

Back to the top