summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Drossel2009-04-20 09:04:17 (EDT)
committerCarsten Drossel2009-04-20 09:04:17 (EDT)
commitaac08735e848e112e3aa5a1dbf978d3bdc619f3d (patch)
treeb9e89d75686c940b395bd5cd23caec79550c69ea
parent8edbfd8162a10886f031c020b8c1b1a0b34e630c (diff)
downloadorg.eclipse.riena-aac08735e848e112e3aa5a1dbf978d3bdc619f3d.zip
org.eclipse.riena-aac08735e848e112e3aa5a1dbf978d3bdc619f3d.tar.gz
org.eclipse.riena-aac08735e848e112e3aa5a1dbf978d3bdc619f3d.tar.bz2
bug 268897 - AbstractSelectableRidget fires selection event twice
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/internal/ui/ridgets/swt/AbstractTableRidgetTest.java29
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/internal/ui/ridgets/swt/ListRidgetTest.java3
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/internal/ui/ridgets/swt/MasterDetailsRidgetTest.java62
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/internal/ui/ridgets/swt/TreeRidgetTest2.java42
-rw-r--r--org.eclipse.riena.ui.ridgets.swt/src/org/eclipse/riena/ui/ridgets/swt/AbstractSelectableRidget.java13
-rw-r--r--org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/ISelectableRidget.java3
6 files changed, 87 insertions, 65 deletions
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/internal/ui/ridgets/swt/AbstractTableRidgetTest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/internal/ui/ridgets/swt/AbstractTableRidgetTest.java
index 1bff22d..efd64cc 100644
--- a/org.eclipse.riena.tests/src/org/eclipse/riena/internal/ui/ridgets/swt/AbstractTableRidgetTest.java
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/internal/ui/ridgets/swt/AbstractTableRidgetTest.java
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.riena.internal.ui.ridgets.swt;
-import java.beans.PropertyChangeEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -652,11 +651,7 @@ public abstract class AbstractTableRidgetTest extends AbstractSWTRidgetTest {
java.util.List<?> oldSelection = Collections.EMPTY_LIST;
java.util.List<?> newSelection = Arrays.asList(new Object[] { person1 });
- PropertyChangeEvent multiEvent = new PropertyChangeEvent(ridget, ISelectableRidget.PROPERTY_SELECTION,
- oldSelection, newSelection);
- PropertyChangeEvent singleEvent = new PropertyChangeEvent(ridget, ISelectableRidget.PROPERTY_SELECTION, null,
- person1);
- expectPropertyChangeEvents(multiEvent, singleEvent);
+ expectPropertyChangeEvent(ISelectableRidget.PROPERTY_SELECTION, oldSelection, newSelection);
ridget.setSelection(0);
@@ -670,9 +665,7 @@ public abstract class AbstractTableRidgetTest extends AbstractSWTRidgetTest {
oldSelection = newSelection;
newSelection = Collections.EMPTY_LIST;
- multiEvent = new PropertyChangeEvent(ridget, ISelectableRidget.PROPERTY_SELECTION, oldSelection, newSelection);
- singleEvent = new PropertyChangeEvent(ridget, ISelectableRidget.PROPERTY_SELECTION, person1, null);
- expectPropertyChangeEvents(multiEvent, singleEvent);
+ expectPropertyChangeEvent(ISelectableRidget.PROPERTY_SELECTION, oldSelection, newSelection);
ridget.setSelection(Collections.EMPTY_LIST);
@@ -680,9 +673,7 @@ public abstract class AbstractTableRidgetTest extends AbstractSWTRidgetTest {
oldSelection = Collections.EMPTY_LIST;
newSelection = Arrays.asList(new Object[] { person2 });
- multiEvent = new PropertyChangeEvent(ridget, ISelectableRidget.PROPERTY_SELECTION, oldSelection, newSelection);
- singleEvent = new PropertyChangeEvent(ridget, ISelectableRidget.PROPERTY_SELECTION, null, person2);
- expectPropertyChangeEvents(multiEvent, singleEvent);
+ expectPropertyChangeEvent(ISelectableRidget.PROPERTY_SELECTION, oldSelection, newSelection);
ridget.setSelection(new int[] { 1, 2 });
@@ -711,11 +702,7 @@ public abstract class AbstractTableRidgetTest extends AbstractSWTRidgetTest {
java.util.List<?> oldSelection = Collections.EMPTY_LIST;
java.util.List<?> newSelection = Arrays.asList(new Object[] { person1 });
- PropertyChangeEvent multiEvent = new PropertyChangeEvent(ridget, ISelectableRidget.PROPERTY_SELECTION,
- oldSelection, newSelection);
- PropertyChangeEvent singleEvent = new PropertyChangeEvent(ridget, ISelectableRidget.PROPERTY_SELECTION, null,
- person1);
- expectPropertyChangeEvents(multiEvent, singleEvent);
+ expectPropertyChangeEvent(ISelectableRidget.PROPERTY_SELECTION, oldSelection, newSelection);
ridget.setSelection(0);
@@ -729,9 +716,7 @@ public abstract class AbstractTableRidgetTest extends AbstractSWTRidgetTest {
oldSelection = newSelection;
newSelection = Collections.EMPTY_LIST;
- multiEvent = new PropertyChangeEvent(ridget, ISelectableRidget.PROPERTY_SELECTION, oldSelection, newSelection);
- singleEvent = new PropertyChangeEvent(ridget, ISelectableRidget.PROPERTY_SELECTION, person1, null);
- expectPropertyChangeEvents(multiEvent, singleEvent);
+ expectPropertyChangeEvent(ISelectableRidget.PROPERTY_SELECTION, oldSelection, newSelection);
ridget.setSelection(Collections.EMPTY_LIST);
@@ -739,9 +724,7 @@ public abstract class AbstractTableRidgetTest extends AbstractSWTRidgetTest {
oldSelection = Collections.EMPTY_LIST;
newSelection = Arrays.asList(new Object[] { person2, person3 });
- multiEvent = new PropertyChangeEvent(ridget, ISelectableRidget.PROPERTY_SELECTION, oldSelection, newSelection);
- singleEvent = new PropertyChangeEvent(ridget, ISelectableRidget.PROPERTY_SELECTION, null, person2);
- expectPropertyChangeEvents(multiEvent, singleEvent);
+ expectPropertyChangeEvent(ISelectableRidget.PROPERTY_SELECTION, oldSelection, newSelection);
ridget.setSelection(new int[] { 1, 2 });
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/internal/ui/ridgets/swt/ListRidgetTest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/internal/ui/ridgets/swt/ListRidgetTest.java
index c8f5e2e..787fecb 100644
--- a/org.eclipse.riena.tests/src/org/eclipse/riena/internal/ui/ridgets/swt/ListRidgetTest.java
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/internal/ui/ridgets/swt/ListRidgetTest.java
@@ -12,12 +12,10 @@ package org.eclipse.riena.internal.ui.ridgets.swt;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import org.eclipse.core.databinding.observable.list.IObservableList;
-import org.eclipse.core.databinding.observable.list.WritableList;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
@@ -580,7 +578,6 @@ public class ListRidgetTest extends AbstractTableRidgetTest {
*/
public void testDisabledDoesNotFireSelection() {
ListRidget ridget = getRidget();
- ridget.setSelectionType(ISelectableRidget.SelectionType.MULTI);
FTPropertyChangeListener listener = new FTPropertyChangeListener();
ridget.addPropertyChangeListener(ISelectableRidget.PROPERTY_SELECTION, listener);
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/internal/ui/ridgets/swt/MasterDetailsRidgetTest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/internal/ui/ridgets/swt/MasterDetailsRidgetTest.java
index 94d3152..b508299 100644
--- a/org.eclipse.riena.tests/src/org/eclipse/riena/internal/ui/ridgets/swt/MasterDetailsRidgetTest.java
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/internal/ui/ridgets/swt/MasterDetailsRidgetTest.java
@@ -10,7 +10,11 @@
*******************************************************************************/
package org.eclipse.riena.internal.ui.ridgets.swt;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import org.eclipse.core.databinding.observable.list.WritableList;
@@ -28,6 +32,7 @@ import org.eclipse.riena.ui.ridgets.IMasterDetailsDelegate;
import org.eclipse.riena.ui.ridgets.IMasterDetailsRidget;
import org.eclipse.riena.ui.ridgets.IRidget;
import org.eclipse.riena.ui.ridgets.IRidgetContainer;
+import org.eclipse.riena.ui.ridgets.ISelectableRidget;
import org.eclipse.riena.ui.ridgets.ITextRidget;
import org.eclipse.riena.ui.ridgets.swt.uibinding.SwtControlRidgetMapper;
import org.eclipse.riena.ui.ridgets.uibinding.DefaultBindingManager;
@@ -321,6 +326,41 @@ public class MasterDetailsRidgetTest extends AbstractSWTRidgetTest {
assertEquals("TestR0C2", widget2.txtColumn2.getText());
}
+ public void testSetSelectionFiresEvents() {
+ IMasterDetailsRidget ridget = getRidget();
+ MDBean item0 = input.get(0);
+ FTPropertyChangeListener listener = new FTPropertyChangeListener();
+
+ bindToModel(true);
+ ridget.addPropertyChangeListener(ISelectableRidget.PROPERTY_SELECTION, listener);
+
+ ridget.setSelection(item0);
+ java.util.List<?> oldSelection = Collections.EMPTY_LIST;
+ java.util.List<?> newSelection = Arrays.asList(new Object[] { item0 });
+ assertPropertyChangeEvent(1, oldSelection, newSelection, listener);
+
+ ridget.setSelection(item0);
+ assertEquals(1, listener.count);
+
+ // TODO this code can replace the 4 lines below once 272651 is fixed
+ // MDBean item1 = input.get(1);
+ // ridget.setSelection(item1);
+ // oldSelection = newSelection;
+ // newSelection = Arrays.asList(new Object[] { item1 });
+ // assertPropertyChangeEvent(2, oldSelection, newSelection, listener);
+ //
+ // ridget.setSelection(null);
+ // oldSelection = newSelection;
+ // newSelection = Collections.EMPTY_LIST;
+ // assertPropertyChangeEvent(3, oldSelection, newSelection, listener);
+
+ ridget.setSelection(null);
+ oldSelection = newSelection;
+ newSelection = Collections.EMPTY_LIST;
+ assertPropertyChangeEvent(2, oldSelection, newSelection, listener);
+
+ }
+
// helping methods
//////////////////
@@ -333,6 +373,14 @@ public class MasterDetailsRidgetTest extends AbstractSWTRidgetTest {
}
}
+ private void assertPropertyChangeEvent(int count, Object oldValue, Object newValue,
+ FTPropertyChangeListener listener) {
+ assertEquals(count, listener.count);
+ assertEquals("selection", listener.event.getPropertyName());
+ assertEquals(oldValue, listener.event.getOldValue());
+ assertEquals(newValue, listener.event.getNewValue());
+ }
+
private void bindToModel(boolean withUpdate) {
WritableList list = new WritableList(input, MDBean.class);
getRidget().bindToModel(list, MDBean.class, columnProperties, columnHeaders);
@@ -478,4 +526,18 @@ public class MasterDetailsRidgetTest extends AbstractSWTRidgetTest {
}
}
+ /**
+ * PropertyChangeListener stub used for testing.
+ */
+ private static final class FTPropertyChangeListener implements PropertyChangeListener {
+
+ private int count;
+ private PropertyChangeEvent event;
+
+ public void propertyChange(PropertyChangeEvent event) {
+ count++;
+ this.event = event;
+ }
+ }
+
}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/internal/ui/ridgets/swt/TreeRidgetTest2.java b/org.eclipse.riena.tests/src/org/eclipse/riena/internal/ui/ridgets/swt/TreeRidgetTest2.java
index 910aea3..fec4a08 100644
--- a/org.eclipse.riena.tests/src/org/eclipse/riena/internal/ui/ridgets/swt/TreeRidgetTest2.java
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/internal/ui/ridgets/swt/TreeRidgetTest2.java
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.riena.internal.ui.ridgets.swt;
-import java.beans.PropertyChangeEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -25,6 +24,13 @@ import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.observable.list.WritableList;
import org.eclipse.core.databinding.observable.value.WritableValue;
import org.eclipse.core.runtime.Assert;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+
import org.eclipse.riena.beans.common.Person;
import org.eclipse.riena.tests.TreeUtils;
import org.eclipse.riena.tests.UITestHelper;
@@ -37,12 +43,6 @@ import org.eclipse.riena.ui.ridgets.tree2.ITreeNode;
import org.eclipse.riena.ui.ridgets.tree2.TreeNode;
import org.eclipse.riena.ui.tests.base.TestMultiSelectionBean;
import org.eclipse.riena.ui.tests.base.TestSingleSelectionBean;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.swt.widgets.TreeItem;
/**
* Tests for the class {@link TreeRidget}.
@@ -501,11 +501,7 @@ public class TreeRidgetTest2 extends AbstractSWTRidgetTest {
java.util.List<?> oldSelection = Collections.EMPTY_LIST;
java.util.List<?> newSelection = Arrays.asList(new Object[] { root });
- PropertyChangeEvent multiEvent = new PropertyChangeEvent(ridget, ISelectableRidget.PROPERTY_SELECTION,
- oldSelection, newSelection);
- PropertyChangeEvent singleEvent = new PropertyChangeEvent(ridget, ISelectableRidget.PROPERTY_SELECTION, null,
- root);
- expectPropertyChangeEvents(multiEvent, singleEvent);
+ expectPropertyChangeEvent(ISelectableRidget.PROPERTY_SELECTION, oldSelection, newSelection);
ridget.setSelection(root);
@@ -519,9 +515,7 @@ public class TreeRidgetTest2 extends AbstractSWTRidgetTest {
oldSelection = newSelection;
newSelection = Collections.EMPTY_LIST;
- multiEvent = new PropertyChangeEvent(ridget, ISelectableRidget.PROPERTY_SELECTION, oldSelection, newSelection);
- singleEvent = new PropertyChangeEvent(ridget, ISelectableRidget.PROPERTY_SELECTION, root, null);
- expectPropertyChangeEvents(multiEvent, singleEvent);
+ expectPropertyChangeEvent(ISelectableRidget.PROPERTY_SELECTION, oldSelection, newSelection);
ridget.setSelection(Collections.EMPTY_LIST);
@@ -529,9 +523,7 @@ public class TreeRidgetTest2 extends AbstractSWTRidgetTest {
oldSelection = Collections.EMPTY_LIST;
newSelection = Arrays.asList(new Object[] { rootChild1 });
- multiEvent = new PropertyChangeEvent(ridget, ISelectableRidget.PROPERTY_SELECTION, oldSelection, newSelection);
- singleEvent = new PropertyChangeEvent(ridget, ISelectableRidget.PROPERTY_SELECTION, null, rootChild1);
- expectPropertyChangeEvents(multiEvent, singleEvent);
+ expectPropertyChangeEvent(ISelectableRidget.PROPERTY_SELECTION, oldSelection, newSelection);
ridget.setSelection(Arrays.asList(new Object[] { rootChild1, rootChild1Child1 }));
@@ -557,11 +549,7 @@ public class TreeRidgetTest2 extends AbstractSWTRidgetTest {
java.util.List<?> oldSelection = Collections.EMPTY_LIST;
java.util.List<?> newSelection = Arrays.asList(new Object[] { root });
- PropertyChangeEvent multiEvent = new PropertyChangeEvent(ridget, ISelectableRidget.PROPERTY_SELECTION,
- oldSelection, newSelection);
- PropertyChangeEvent singleEvent = new PropertyChangeEvent(ridget, ISelectableRidget.PROPERTY_SELECTION, null,
- root);
- expectPropertyChangeEvents(multiEvent, singleEvent);
+ expectPropertyChangeEvent(ISelectableRidget.PROPERTY_SELECTION, oldSelection, newSelection);
ridget.setSelection(root);
@@ -575,9 +563,7 @@ public class TreeRidgetTest2 extends AbstractSWTRidgetTest {
oldSelection = newSelection;
newSelection = Collections.EMPTY_LIST;
- multiEvent = new PropertyChangeEvent(ridget, ISelectableRidget.PROPERTY_SELECTION, oldSelection, newSelection);
- singleEvent = new PropertyChangeEvent(ridget, ISelectableRidget.PROPERTY_SELECTION, root, null);
- expectPropertyChangeEvents(multiEvent, singleEvent);
+ expectPropertyChangeEvent(ISelectableRidget.PROPERTY_SELECTION, oldSelection, newSelection);
ridget.setSelection(Collections.EMPTY_LIST);
@@ -585,9 +571,7 @@ public class TreeRidgetTest2 extends AbstractSWTRidgetTest {
oldSelection = Collections.EMPTY_LIST;
newSelection = Arrays.asList(new Object[] { rootChild1, rootChild1Child1 });
- multiEvent = new PropertyChangeEvent(ridget, ISelectableRidget.PROPERTY_SELECTION, oldSelection, newSelection);
- singleEvent = new PropertyChangeEvent(ridget, ISelectableRidget.PROPERTY_SELECTION, null, rootChild1);
- expectPropertyChangeEvents(multiEvent, singleEvent);
+ expectPropertyChangeEvent(ISelectableRidget.PROPERTY_SELECTION, oldSelection, newSelection);
ridget.setSelection(Arrays.asList(new Object[] { rootChild1, rootChild1Child1 }));
diff --git a/org.eclipse.riena.ui.ridgets.swt/src/org/eclipse/riena/ui/ridgets/swt/AbstractSelectableRidget.java b/org.eclipse.riena.ui.ridgets.swt/src/org/eclipse/riena/ui/ridgets/swt/AbstractSelectableRidget.java
index e96375e..4b6b142 100644
--- a/org.eclipse.riena.ui.ridgets.swt/src/org/eclipse/riena/ui/ridgets/swt/AbstractSelectableRidget.java
+++ b/org.eclipse.riena.ui.ridgets.swt/src/org/eclipse/riena/ui/ridgets/swt/AbstractSelectableRidget.java
@@ -28,7 +28,6 @@ import org.eclipse.core.databinding.observable.list.ListDiff;
import org.eclipse.core.databinding.observable.list.ListDiffEntry;
import org.eclipse.core.databinding.observable.list.WritableList;
import org.eclipse.core.databinding.observable.value.IObservableValue;
-import org.eclipse.core.databinding.observable.value.ValueDiff;
import org.eclipse.core.databinding.observable.value.WritableValue;
import org.eclipse.core.runtime.Assert;
@@ -215,14 +214,6 @@ public abstract class AbstractSelectableRidget extends AbstractSWTRidget impleme
super(null, Object.class);
}
- @Override
- protected void fireValueChange(ValueDiff diff) {
- super.fireValueChange(diff);
- String key = ISelectableRidget.PROPERTY_SELECTION;
- Object oldValue = diff.getOldValue();
- Object newValue = diff.getNewValue();
- AbstractSelectableRidget.this.firePropertyChange(key, oldValue, newValue);
- }
};
/**
@@ -236,6 +227,10 @@ public abstract class AbstractSelectableRidget extends AbstractSWTRidget impleme
super(new ArrayList<Object>(), Object.class);
}
+ /**
+ * Only the MultiSelectionObservable is firing selection property change
+ * events to avoid duplicate events (bug 268897)
+ */
@Override
protected void fireListChange(ListDiff diff) {
super.fireListChange(diff);
diff --git a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/ISelectableRidget.java b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/ISelectableRidget.java
index 00b62e5..e5ca92c 100644
--- a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/ISelectableRidget.java
+++ b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/ISelectableRidget.java
@@ -26,7 +26,8 @@ public interface ISelectableRidget extends IMarkableRidget {
* This property will be fired every time the selection changes. If the
* selection type is single selection, the selection will contain zero or
* one items. If the selection type is multiple selection, the selection
- * will contain zero or more items.
+ * will contain zero or more items. In both cases the old and new value of
+ * the PropertyChangeEvent are collections.
*/
String PROPERTY_SELECTION = "selection"; //$NON-NLS-1$