|
From: <pat...@us...> - 2010-07-15 08:30:33
|
Revision: 1089
http://cishell.svn.sourceforge.net/cishell/?rev=1089&view=rev
Author: pataphil
Date: 2010-07-15 08:30:27 +0000 (Thu, 15 Jul 2010)
Log Message:
-----------
* Added ArrayListUtilities.copyAndSort().
* Fixed some GUIModel stuff.
Modified Paths:
--------------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/DropDownDataSynchronizer.java
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java 2010-07-13 21:30:22 UTC (rev 1088)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java 2010-07-15 08:30:27 UTC (rev 1089)
@@ -2,10 +2,18 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
import java.util.List;
public class ArrayListUtilities {
+ public static<T extends Comparable<T>> List<T> copyAndSort(Collection<T> items) {
+ List<T> copy = new ArrayList<T>(items);
+ Collections.sort(copy);
+
+ return copy;
+ }
+
// TODO: Move this to CollectionUtilities.
public static<T> Collection<T> unionCollections(
Collection<T> items1,
@@ -36,7 +44,25 @@
Collection<T> items1,
Collection<T> items2,
Collection<T> keysToSkip) {
- return new ArrayList<T>(unionCollections(items1, items2, keysToSkip));
+ List<T> union = new ArrayList<T>();
+
+ if (keysToSkip == null) {
+ keysToSkip = new ArrayList<T>();
+ }
+
+ for (T element : items1) {
+ if (!union.contains(element) && !keysToSkip.contains(element)) {
+ union.add(element);
+ }
+ }
+
+ for (T element : items2) {
+ if (!union.contains(element) && !keysToSkip.contains(element)) {
+ union.add(element);
+ }
+ }
+
+ return union;
}
/* Implodes list to a String with the String.valueOf the elements separated
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java 2010-07-13 21:30:22 UTC (rev 1088)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java 2010-07-15 08:30:27 UTC (rev 1089)
@@ -2,7 +2,6 @@
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -61,13 +60,15 @@
Composite parent,
int style) {
java.util.List<String> orderedOptionLabels = new ArrayList<String>(unorderedOptionLabels);
- Collections.sort(orderedOptionLabels);
Combo dropDown = new Combo(parent, style | SWT.DROP_DOWN);
DropDownDataSynchronizer dataSynchronizer = new DropDownDataSynchronizer(
dropDown, selectedIndex, orderedOptionLabels, optionValuesByLabels);
GUIModelField<String, Combo, DropDownDataSynchronizer> field =
new GUIModelField<String, Combo, DropDownDataSynchronizer>(
- name, orderedOptionLabels.get(selectedIndex), dropDown, dataSynchronizer);
+ name,
+ optionValuesByLabels.get(orderedOptionLabels.get(selectedIndex)),
+ dropDown,
+ dataSynchronizer);
addField(field);
return field;
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java 2010-07-13 21:30:22 UTC (rev 1088)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java 2010-07-15 08:30:27 UTC (rev 1089)
@@ -8,6 +8,7 @@
public class GUIModelField<T, U extends Widget, V extends ModelDataSynchronizer<T>> {
private String name;
private T defaultValue;
+ private T previousValue;
private T value;
private U widget;
private V dataSynchronizer;
@@ -26,9 +27,9 @@
this.widget.addListener(this.dataSynchronizer.swtUpdateListenerCode(), new Listener() {
public void handleEvent(Event event) {
if (event.type == GUIModelField.this.dataSynchronizer.swtUpdateListenerCode()) {
+ GUIModelField.this.previousValue = GUIModelField.this.value;
GUIModelField.this.value =
GUIModelField.this.dataSynchronizer.synchronizeFromGUI();
- System.err.println(GUIModelField.this.value);
}
}
});
@@ -38,6 +39,10 @@
return this.name;
}
+ public T getPreviousValue() {
+ return this.previousValue;
+ }
+
public T getValue() {
return this.value;
}
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/DropDownDataSynchronizer.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/DropDownDataSynchronizer.java 2010-07-13 21:30:22 UTC (rev 1088)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/DropDownDataSynchronizer.java 2010-07-15 08:30:27 UTC (rev 1089)
@@ -14,7 +14,7 @@
public class DropDownDataSynchronizer implements ModelDataSynchronizer<String> {
private Combo dropDown;
private BiMap<Integer, String> optionLabels;
- private Map<String, String> optionValuesByLabels;
+ private BiMap<String, String> optionValuesByLabels;
public DropDownDataSynchronizer(
Combo dropDown,
@@ -22,10 +22,8 @@
List<String> optionLabels,
Map<String, String> optionValuesByLabels) {
this.dropDown = dropDown;
- this.optionLabels = HashBiMap.create(MapUtilities.mapIndexToValues(optionLabels));
- this.optionValuesByLabels = optionValuesByLabels;
- this.dropDown.setItems(optionLabels.toArray(new String[0]));
+ setOptions(optionLabels, optionValuesByLabels);
this.dropDown.select(selectedIndex);
}
@@ -39,11 +37,12 @@
}
public String synchronizeFromGUI() {
- return this.optionLabels.get(this.dropDown.getSelectionIndex());
+ return value();
}
public String synchronizeToGUI(String value) {
- this.dropDown.select(this.optionLabels.inverse().get(value));
+ String label = this.optionValuesByLabels.inverse().get(value);
+ this.dropDown.select(this.optionLabels.inverse().get(label));
return value();
}
@@ -51,4 +50,12 @@
public String reset(String defaultValue) {
return synchronizeToGUI(defaultValue);
}
+
+ public void setOptions(List<String> optionLabels, Map<String, String> optionValuesByLabels) {
+ this.optionLabels = HashBiMap.create(MapUtilities.mapIndexToValues(optionLabels));
+ this.optionValuesByLabels = HashBiMap.create(optionValuesByLabels);
+
+ this.dropDown.setItems(optionLabels.toArray(new String[0]));
+ this.dropDown.select(0);
+ }
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|