Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspingel2011-05-10 10:06:21 +0000
committerspingel2011-05-10 10:06:21 +0000
commit6c49082460521e5e50426eb8036c8d0284f1577f (patch)
treeeef873a21d7af500c98e6537b348a7332752a6d4 /org.eclipse.mylyn.tasks.ui
parent149081d946c3a89d5680caeef390f95e88e882c3 (diff)
downloadorg.eclipse.mylyn.tasks-6c49082460521e5e50426eb8036c8d0284f1577f.tar.gz
org.eclipse.mylyn.tasks-6c49082460521e5e50426eb8036c8d0284f1577f.tar.xz
org.eclipse.mylyn.tasks-6c49082460521e5e50426eb8036c8d0284f1577f.zip
NEW - bug 343005: [patch][api] framework should provide facility to update attribute editors when the TaskDataModel changes
https://bugs.eclipse.org/bugs/show_bug.cgi?id=343005
Diffstat (limited to 'org.eclipse.mylyn.tasks.ui')
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/BooleanAttributeEditor.java7
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/CheckboxMultiSelectAttributeEditor.java45
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/DateAttributeEditor.java34
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/LongTextAttributeEditor.java24
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/MultiSelectionAttributeEditor.java40
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/PriorityAttributeEditor.java33
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/RichTextAttributeEditor.java18
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/SingleSelectionAttributeEditor.java31
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TextAttributeEditor.java20
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractAttributeEditor.java48
10 files changed, 215 insertions, 85 deletions
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/BooleanAttributeEditor.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/BooleanAttributeEditor.java
index 741a430d2..b1433a274 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/BooleanAttributeEditor.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/BooleanAttributeEditor.java
@@ -67,7 +67,7 @@ public class BooleanAttributeEditor extends AbstractAttributeEditor {
@Override
public void refresh() {
- if (button == null) {
+ if (button == null || button.isDisposed()) {
return;
}
@@ -78,4 +78,9 @@ public class BooleanAttributeEditor extends AbstractAttributeEditor {
ignoreNotification = false;
}
}
+
+ @Override
+ public boolean shouldAutoRefresh() {
+ return true;
+ }
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/CheckboxMultiSelectAttributeEditor.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/CheckboxMultiSelectAttributeEditor.java
index 13039e301..088add854 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/CheckboxMultiSelectAttributeEditor.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/CheckboxMultiSelectAttributeEditor.java
@@ -42,6 +42,7 @@ import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.forms.widgets.SharedScrolledComposite;
@@ -57,6 +58,8 @@ public class CheckboxMultiSelectAttributeEditor extends AbstractAttributeEditor
private Button button;
+ private boolean cflowSelect;
+
public CheckboxMultiSelectAttributeEditor(TaskDataModel manager, TaskAttribute taskAttribute) {
super(manager, taskAttribute);
setLayoutHint(new LayoutHint(RowSpan.SINGLE, ColumnSpan.MULTIPLE));
@@ -107,20 +110,25 @@ public class CheckboxMultiSelectAttributeEditor extends AbstractAttributeEditor
selectionDialog.addEventListener(new IInPlaceDialogListener() {
public void buttonPressed(InPlaceDialogEvent event) {
- if (event.getReturnCode() == Window.OK) {
- Set<String> newValues = selectionDialog.getSelectedValues();
- if (!new HashSet<String>(values).equals(newValues)) {
- setValues(new ArrayList<String>(newValues));
- attributeChanged();
- updateText();
- }
- } else if (event.getReturnCode() == AbstractInPlaceDialog.ID_CLEAR) {
- Set<String> newValues = new HashSet<String>();
- if (!new HashSet<String>(values).equals(newValues)) {
- setValues(new ArrayList<String>(newValues));
- attributeChanged();
- updateText();
+ cflowSelect = true;
+ try {
+ if (event.getReturnCode() == Window.OK) {
+ Set<String> newValues = selectionDialog.getSelectedValues();
+ if (!new HashSet<String>(values).equals(newValues)) {
+ setValues(new ArrayList<String>(newValues));
+ attributeChanged();
+ updateText();
+ }
+ } else if (event.getReturnCode() == AbstractInPlaceDialog.ID_CLEAR) {
+ Set<String> newValues = new HashSet<String>();
+ if (!new HashSet<String>(values).equals(newValues)) {
+ setValues(new ArrayList<String>(newValues));
+ attributeChanged();
+ updateText();
+ }
}
+ } finally {
+ cflowSelect = false;
}
}
});
@@ -214,4 +222,15 @@ public class CheckboxMultiSelectAttributeEditor extends AbstractAttributeEditor
}
}
+ @Override
+ public void refresh() {
+ if (!cflowSelect) {
+ updateText();
+ }
+ }
+
+ @Override
+ public boolean shouldAutoRefresh() {
+ return true;
+ }
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/DateAttributeEditor.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/DateAttributeEditor.java
index 5ee8388fd..7a07f5113 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/DateAttributeEditor.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/DateAttributeEditor.java
@@ -41,6 +41,8 @@ public class DateAttributeEditor extends AbstractAttributeEditor {
private boolean showTime;
+ private Text text;
+
public DateAttributeEditor(TaskDataModel manager, TaskAttribute taskAttribute) {
super(manager, taskAttribute);
setLayoutHint(new LayoutHint(RowSpan.SINGLE, ColumnSpan.SINGLE));
@@ -49,7 +51,7 @@ public class DateAttributeEditor extends AbstractAttributeEditor {
@Override
public void createControl(Composite composite, FormToolkit toolkit) {
if (isReadOnly()) {
- Text text = new Text(composite, SWT.FLAT | SWT.READ_ONLY);
+ text = new Text(composite, SWT.FLAT | SWT.READ_ONLY);
text.setFont(EditorUtil.TEXT_FONT);
toolkit.adapt(text, false, false);
text.setData(FormToolkit.KEY_DRAW_BORDER, Boolean.FALSE);
@@ -65,11 +67,7 @@ public class DateAttributeEditor extends AbstractAttributeEditor {
} else {
datePicker.setDateFormat(EditorUtil.getDateTimeFormat());
}
- if (getValue() != null) {
- Calendar cal = Calendar.getInstance();
- cal.setTime(getValue());
- datePicker.setDate(cal);
- }
+ updateDatePicker();
datePicker.addPickerSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
@@ -89,6 +87,7 @@ public class DateAttributeEditor extends AbstractAttributeEditor {
datePicker.setDate(null);
}
}
+
});
GridDataFactory.fillDefaults().hint(120, SWT.DEFAULT).grab(false, false).applyTo(datePicker);
@@ -99,6 +98,14 @@ public class DateAttributeEditor extends AbstractAttributeEditor {
}
}
+ private void updateDatePicker() {
+ if (getValue() != null) {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(getValue());
+ datePicker.setDate(cal);
+ }
+ }
+
@Override
protected void decorateIncoming(Color color) {
if (datePicker != null) {
@@ -136,4 +143,19 @@ public class DateAttributeEditor extends AbstractAttributeEditor {
attributeChanged();
}
+ @Override
+ public void refresh() {
+ if (text != null && !text.isDisposed()) {
+ text.setText(getTextValue());
+ }
+ if (datePicker != null && !datePicker.isDisposed()) {
+ updateDatePicker();
+ }
+ }
+
+ @Override
+ public boolean shouldAutoRefresh() {
+ return true;
+ }
+
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/LongTextAttributeEditor.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/LongTextAttributeEditor.java
index 7d46a3521..66c8fef23 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/LongTextAttributeEditor.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/LongTextAttributeEditor.java
@@ -34,6 +34,10 @@ import org.eclipse.ui.forms.widgets.FormToolkit;
*/
public class LongTextAttributeEditor extends AbstractAttributeEditor {
+ private SourceViewer viewer;
+
+ private boolean cflowModify;
+
public LongTextAttributeEditor(TaskDataModel manager, TaskAttribute taskAttribute) {
super(manager, taskAttribute);
setLayoutHint(new LayoutHint(RowSpan.MULTIPLE, ColumnSpan.MULTIPLE));
@@ -45,7 +49,7 @@ public class LongTextAttributeEditor extends AbstractAttributeEditor {
if (!isReadOnly()) {
style |= SWT.V_SCROLL;
}
- SourceViewer viewer = new SourceViewer(parent, null, style);
+ viewer = new SourceViewer(parent, null, style);
RepositoryTextViewerConfiguration configuration = RichTextEditor.installHyperlinkPresenter(viewer,
getModel().getTaskRepository(), getModel().getTask(), Mode.DEFAULT);
viewer.configure(configuration);
@@ -64,7 +68,12 @@ public class LongTextAttributeEditor extends AbstractAttributeEditor {
text.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
text.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
- setValue(text.getText());
+ try {
+ cflowModify = true;
+ setValue(text.getText());
+ } finally {
+ cflowModify = false;
+ }
CommonFormUtil.ensureVisible(text);
}
});
@@ -82,4 +91,15 @@ public class LongTextAttributeEditor extends AbstractAttributeEditor {
attributeChanged();
}
+ @Override
+ public void refresh() {
+ if (!cflowModify && viewer.getTextWidget() != null && !viewer.getTextWidget().isDisposed()) {
+ viewer.getDocument().set(getValue());
+ }
+ }
+
+ @Override
+ public boolean shouldAutoRefresh() {
+ return true;
+ }
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/MultiSelectionAttributeEditor.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/MultiSelectionAttributeEditor.java
index 28a3507f6..50443f72d 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/MultiSelectionAttributeEditor.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/MultiSelectionAttributeEditor.java
@@ -29,6 +29,7 @@ import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.forms.widgets.FormToolkit;
/**
@@ -70,13 +71,7 @@ public class MultiSelectionAttributeEditor extends AbstractAttributeEditor {
list.setFont(EditorUtil.TEXT_FONT);
list.setToolTipText(getDescription());
- Map<String, String> labelByValue = getAttributeMapper().getOptions(getTaskAttribute());
- if (labelByValue != null) {
- allValues = labelByValue.keySet().toArray(new String[0]);
- for (String value : allValues) {
- list.add(labelByValue.get(value));
- }
- }
+ updateListWithOptions();
select(getValues(), getValuesLabels());
@@ -102,6 +97,23 @@ public class MultiSelectionAttributeEditor extends AbstractAttributeEditor {
}
}
+ private void updateListWithOptions() {
+ if (list != null && !list.isDisposed()) {
+ Map<String, String> labelByValue = getAttributeMapper().getOptions(getTaskAttribute());
+ if (labelByValue != null) {
+ int topIndex = list.getTopIndex();
+ list.removeAll();
+ allValues = labelByValue.keySet().toArray(new String[0]);
+ for (String value : allValues) {
+ list.add(labelByValue.get(value));
+ }
+ if (topIndex > 0) {
+ list.setTopIndex(topIndex);
+ }
+ }
+ }
+ }
+
public String[] getValues() {
return getAttributeMapper().getValues(getTaskAttribute()).toArray(new String[0]);
}
@@ -111,7 +123,7 @@ public class MultiSelectionAttributeEditor extends AbstractAttributeEditor {
}
private void select(String[] values, String[] labels) {
- if (text != null) {
+ if (text != null && !text.isDisposed()) {
StringBuilder valueString = new StringBuilder();
if (labels != null) {
for (int i = 0; i < labels.length; i++) {
@@ -123,7 +135,7 @@ public class MultiSelectionAttributeEditor extends AbstractAttributeEditor {
}
text.setText(valueString.toString());
- } else if (list != null) {
+ } else if (list != null && !list.isDisposed()) {
if (values != null) {
list.deselectAll();
Set<String> selectedValues = new HashSet<String>(Arrays.asList(values));
@@ -144,4 +156,14 @@ public class MultiSelectionAttributeEditor extends AbstractAttributeEditor {
attributeChanged();
}
+ @Override
+ public void refresh() {
+ updateListWithOptions();
+ select(getValues(), getValuesLabels());
+ }
+
+ @Override
+ public boolean shouldAutoRefresh() {
+ return true;
+ }
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/PriorityAttributeEditor.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/PriorityAttributeEditor.java
index 98fa005e2..367d3f350 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/PriorityAttributeEditor.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/PriorityAttributeEditor.java
@@ -15,12 +15,8 @@ import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylyn.tasks.core.ITaskMapping;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
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.mylyn.tasks.ui.TasksUi;
import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.forms.widgets.FormToolkit;
@@ -33,15 +29,6 @@ public class PriorityAttributeEditor extends AbstractAttributeEditor {
private ITaskMapping mapping;
- private final TaskDataModelListener modelListener = new TaskDataModelListener() {
- @Override
- public void attributeChanged(TaskDataModelEvent event) {
- if (getTaskAttribute().equals(event.getTaskAttribute())) {
- refresh();
- }
- }
- };
-
public PriorityAttributeEditor(TaskDataModel manager, TaskAttribute taskAttribute) {
super(manager, taskAttribute);
boolean noOptions = getAttributeMapper().getOptions(getTaskAttribute()).size() == 0;
@@ -62,14 +49,6 @@ public class PriorityAttributeEditor extends AbstractAttributeEditor {
editor.setReadOnly(isReadOnly());
editor.createControl(parent, toolkit);
setControl(editor.getControl());
- getControl().addDisposeListener(new DisposeListener() {
-
- public void widgetDisposed(DisposeEvent e) {
- getModel().removeModelListener(modelListener);
- }
-
- });
- getModel().addModelListener(modelListener);
refresh();
}
@@ -83,8 +62,15 @@ public class PriorityAttributeEditor extends AbstractAttributeEditor {
@Override
public void refresh() {
- editor.setLabelByValue(getAttributeMapper().getOptions(getTaskAttribute()));
- updateEditor();
+ if (editor.getControl() != null && !editor.getControl().isDisposed()) {
+ editor.setLabelByValue(getAttributeMapper().getOptions(getTaskAttribute()));
+ updateEditor();
+ }
+ }
+
+ @Override
+ public boolean shouldAutoRefresh() {
+ return true;
}
public void setValue(String value) {
@@ -92,7 +78,6 @@ public class PriorityAttributeEditor extends AbstractAttributeEditor {
if (!oldValue.equals(value)) {
getAttributeMapper().setValue(getTaskAttribute(), value);
attributeChanged();
- updateEditor();
}
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/RichTextAttributeEditor.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/RichTextAttributeEditor.java
index 0e7aee07c..269521a3b 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/RichTextAttributeEditor.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/RichTextAttributeEditor.java
@@ -162,15 +162,23 @@ public class RichTextAttributeEditor extends AbstractAttributeEditor {
@Override
public void refresh() {
- try {
- ignoreNotification = true;
- editor.setText(getValue());
- } finally {
- ignoreNotification = false;
+ // proceed if the control is null (i.e. has not yet been created); setText will create it
+ if (editor.getControl() == null || !editor.getControl().isDisposed()) {
+ try {
+ ignoreNotification = true;
+ editor.setText(getValue());
+ } finally {
+ ignoreNotification = false;
+ }
}
}
@Override
+ public boolean shouldAutoRefresh() {
+ return true;
+ }
+
+ @Override
protected void decorateIncoming(Color color) {
super.decorateIncoming(color);
if (editor != null) {
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/SingleSelectionAttributeEditor.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/SingleSelectionAttributeEditor.java
index c407929f2..e199cc1d6 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/SingleSelectionAttributeEditor.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/SingleSelectionAttributeEditor.java
@@ -16,13 +16,9 @@ import java.util.Map;
import org.eclipse.core.runtime.Assert;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
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.mylyn.tasks.ui.editors.AbstractAttributeEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Composite;
@@ -42,15 +38,6 @@ public class SingleSelectionAttributeEditor extends AbstractAttributeEditor {
private String[] values;
- private final TaskDataModelListener modelListener = new TaskDataModelListener() {
- @Override
- public void attributeChanged(TaskDataModelEvent event) {
- if (getTaskAttribute().equals(event.getTaskAttribute())) {
- refresh();
- }
- }
- };
-
public SingleSelectionAttributeEditor(TaskDataModel manager, TaskAttribute taskAttribute) {
super(manager, taskAttribute);
}
@@ -88,15 +75,6 @@ public class SingleSelectionAttributeEditor extends AbstractAttributeEditor {
setControl(combo);
}
refresh();
-
- getControl().addDisposeListener(new DisposeListener() {
-
- public void widgetDisposed(DisposeEvent e) {
- getModel().removeModelListener(modelListener);
- }
-
- });
- getModel().addModelListener(modelListener);
}
public String getValue() {
@@ -111,7 +89,7 @@ public class SingleSelectionAttributeEditor extends AbstractAttributeEditor {
public void refresh() {
try {
ignoreNotification = true;
- if (text != null) {
+ if (text != null && !text.isDisposed()) {
String label = getValueLabel();
if ("".equals(label)) { //$NON-NLS-1$
// if set to the empty string the label will use 64px on GTK
@@ -119,7 +97,7 @@ public class SingleSelectionAttributeEditor extends AbstractAttributeEditor {
} else {
text.setText(label);
}
- } else if (combo != null) {
+ } else if (combo != null && !combo.isDisposed()) {
combo.removeAll();
Map<String, String> labelByValue = getAttributeMapper().getOptions(getTaskAttribute());
if (labelByValue != null) {
@@ -136,6 +114,11 @@ public class SingleSelectionAttributeEditor extends AbstractAttributeEditor {
}
}
+ @Override
+ public boolean shouldAutoRefresh() {
+ return true;
+ }
+
private void select(String value, String label) {
if (values != null) {
for (int i = 0; i < values.length; i++) {
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TextAttributeEditor.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TextAttributeEditor.java
index 8c28b637b..769ab6738 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TextAttributeEditor.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TextAttributeEditor.java
@@ -32,6 +32,8 @@ public class TextAttributeEditor extends AbstractAttributeEditor {
private Text text;
+ private boolean cflowModifyText;
+
public TextAttributeEditor(TaskDataModel manager, TaskAttribute taskAttribute) {
super(manager, taskAttribute);
setLayoutHint(new LayoutHint(RowSpan.SINGLE, ColumnSpan.SINGLE));
@@ -56,7 +58,12 @@ public class TextAttributeEditor extends AbstractAttributeEditor {
text.setToolTipText(getDescription());
text.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
- setValue(text.getText());
+ cflowModifyText = true;// prevent infinite recursion and also prevent resetting the caret location
+ try {
+ setValue(text.getText());
+ } finally {
+ cflowModifyText = false;
+ }
CommonFormUtil.ensureVisible(text);
}
});
@@ -74,4 +81,15 @@ public class TextAttributeEditor extends AbstractAttributeEditor {
attributeChanged();
}
+ @Override
+ public void refresh() {
+ if (!cflowModifyText && text != null && !text.isDisposed()) {
+ text.setText(getValue());
+ }
+ }
+
+ @Override
+ public boolean shouldAutoRefresh() {
+ return true;
+ }
}
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 e664819c3..4c7ccac3c 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
@@ -16,6 +16,10 @@ import org.eclipse.mylyn.internal.provisional.commons.ui.CommonUiUtil;
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.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
@@ -56,6 +60,24 @@ public abstract class AbstractAttributeEditor {
private String description;
+ private final TaskDataModelListener modelListener = new TaskDataModelListener() {
+ @Override
+ public void attributeChanged(TaskDataModelEvent event) {
+ if (shouldAutoRefresh() && getTaskAttribute().equals(event.getTaskAttribute())) {
+ try {
+ refresh();
+ } catch (UnsupportedOperationException e) {
+ }
+ }
+ }
+ };
+
+ private final DisposeListener disposeListener = new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ getModel().removeModelListener(modelListener);
+ }
+ };
+
/**
* @since 3.0
*/
@@ -67,6 +89,7 @@ public abstract class AbstractAttributeEditor {
setDecorationEnabled(true);
setReadOnly(taskAttribute.getMetaData().isReadOnly());
setDescription(taskAttribute.getMetaData().getValue(TaskAttribute.META_DESCRIPTION));
+ getModel().addModelListener(modelListener);
}
/**
@@ -166,9 +189,13 @@ public abstract class AbstractAttributeEditor {
* @since 3.0
*/
protected void setControl(Control control) {
+ if (this.control != null && !this.control.isDisposed()) {
+ this.control.removeDisposeListener(disposeListener);
+ }
this.control = control;
if (control != null) {
control.setData(KEY_TASK_ATTRIBUTE, taskAttribute);
+ control.addDisposeListener(disposeListener);
}
}
@@ -247,6 +274,17 @@ public abstract class AbstractAttributeEditor {
}
/**
+ * Subclasses that implement refresh should override this method to return true, so that they will be automatically
+ * refreshed when the model changes.
+ *
+ * @return whether the editor should be automatically refreshed when the model changes
+ * @since 3.6
+ */
+ protected boolean shouldAutoRefresh() {
+ return false;
+ }
+
+ /**
* @since 3.5
*/
public String getDescription() {
@@ -260,4 +298,14 @@ public abstract class AbstractAttributeEditor {
this.description = description;
}
+ /**
+ * @since 3.6
+ */
+ protected void updateLabel() {
+ Label labelControl = getLabelControl();
+ if (labelControl != null && !labelControl.isDisposed()) {
+ labelControl.setText(getLabel());
+ }
+ }
+
}

Back to the top