Added:
/trunk/modules/com.solertium.util.gwt/src/com/solertium/util/gwt/ui/GenericHTMLListBox.java
Modified:
/trunk/modules/com.solertium.util.gwt/META-INF/MANIFEST.MF
/trunk/modules/com.solertium.util.gwt/src/com/solertium/util/gwt/ui/GenericHTMLMultipleListBox.java
/trunk/modules/com.solertium.util.gwt/src/com/solertium/util/gwt/ui/HTMLListBox.java
=======================================
--- /dev/null
+++
/trunk/modules/com.solertium.util.gwt/src/com/solertium/util/gwt/ui/GenericHTMLListBox.java
Thu Jul 22 10:47:04 2010
@@ -0,0 +1,181 @@
+package com.solertium.util.gwt.ui;
+
+import java.util.ArrayList;
+
+import com.google.gwt.user.client.ui.Grid;
+import com.google.gwt.user.client.ui.HTML;
+import com.google.gwt.user.client.ui.ScrollPanel;
+import com.google.gwt.user.client.ui.SourcesTableEvents;
+import com.google.gwt.user.client.ui.TableListener;
+
+public class GenericHTMLListBox<T> extends ScrollPanel {
+
+ protected ArrayList<T> items;
+ protected Grid table;
+
+ protected int selectedIndex;
+ protected boolean isEnabled = true;
+
+ protected String width;
+ protected int initSize;
+
+ protected int schedule = 1500;
+ private ChangeListener<T> listener;
+
+ /**
+ * Creates a new Listbox with the designated width. If any widgets within
+ * the listbox violate this width, the box will scroll horizontally.
+ *
+ * @param width
+ */
+ public GenericHTMLListBox(final String width, int initSize) {
+ super();
+ items = new ArrayList<T>();
+ setWidth(this.width = width);
+ init(initSize);
+ }
+
+ public void setChangeListener(ChangeListener<T> listener) {
+ this.listener = listener;
+ }
+
+ /**
+ * Adds a new item with a display name and selection value
+ *
+ * @param name
+ * @param value
+ */
+ public void addItem(final String name, final T value) {
+ addItem(name, value, null);
+ }
+
+ /**
+ * Adds an item with a display name, selection value, and, optionally, a
+ * tooltip. Will be ignored if null.
+ *
+ * @param name
+ * @param value
+ * @param toolTip
+ */
+ public void addItem(final String name, final T value, final String
toolTip) {
+ HTML html;
+ if (toolTip == null) {
+ html = new HTML(name);
+ } else {
+ html = new HTMLWithToolTip(name, toolTip);
+ ((HTMLWithToolTip)html).setSchedule(schedule);
+ }
+
+ html.setWordWrap(false);
+ html.setStyleName("CIPD_ListBox_Item");
+
+ if (initSize > items.size()) {
+ table.setWidget(items.size(), 0, html);
+ items.add(value);
+
+ table.getColumnFormatter().setWidth(0, width);
+ }
+ }
+
+ /**
+ * Clears the list.
+ */
+ public void clear() {
+ items.clear();
+ if(table!=null) remove(table);
+ selectedIndex = -1;
+ }
+
+ public int getItemCount() {
+ return items.size();
+ }
+
+ public int getSelectedIndex() {
+ return selectedIndex;
+ }
+
+ public String getSelectedText() {
+ return getText(selectedIndex);
+ }
+
+ public T getSelectedValue() {
+ return items.get(selectedIndex);
+ }
+
+ public void onChange(T selectedValue) {
+ if (listener != null)
+ listener.onChange(selectedValue);
+ }
+
+ /**
+ * Pulls the table from the scrollpanel
+ *
+ * @return
+ */
+ public Grid getTableView() {
+ return table;
+ }
+
+ public String getText(final int index) {
+ return ((HTML) table.getWidget(index, 0)).getText();
+ }
+
+ public T getValue(final int index) {
+ return items.get(index);
+ }
+
+ public int indexOf(final T value) {
+ return items.indexOf(value);
+ }
+
+ public boolean isEmpty() {
+ return items.isEmpty();
+ }
+
+ public void setEnabled(final boolean isEnabled) {
+ this.isEnabled = isEnabled;
+ }
+
+ public void setSelectedIndex(final int index) {
+ selectedIndex = index;
+ for (int i = 0; i < items.size(); i++) {
+ ((HTML) table.getWidget(i, 0))
+ .setStyleName(i == index ? "CIPD_ListBox_ItemSelected"
+ : "CIPD_ListBox_Item");
+ }
+ }
+
+ public void setText(final String text, final int index) {
+ ((HTML) table.getWidget(index, 0)).setHTML(text);
+ }
+
+ public void setTooltipSchedule(final int schedule) {
+ this.schedule = schedule;
+ }
+
+ public void init(int size) {
+ this.initSize = size;
+ table = new Grid(size,1);
+ table.addTableListener(new TableListener() {
+ public void onCellClicked(final SourcesTableEvents sender,
+ final int row, final int cell) {
+ if (isEnabled) {
+ setSelectedIndex(row);
+ onChange(items.get(row));
+ }
+ }
+ });
+ setWidget(table);
+ }
+
+ public void showItemInView(final int index) {
+ setScrollPosition(index * 10);
+ }
+
+ public static interface ChangeListener<T> {
+
+ public abstract void onChange(T selectedValue);
+
+ }
+
+}
=======================================
--- /trunk/modules/com.solertium.util.gwt/META-INF/MANIFEST.MF Thu Jun 25
07:35:33 2009
+++ /trunk/modules/com.solertium.util.gwt/META-INF/MANIFEST.MF Thu Jul 22
10:47:04 2010
@@ -8,7 +8,4 @@
Export-Package: com.solertium.util.gwt,
com.solertium.util.gwt.api,
com.solertium.util.gwt.ui
-Import-Package: com.google.gwt.core.client,
- com.google.gwt.user.client,
- com.google.gwt.user.client.rpc,
- com.google.gwt.user.client.ui
+Require-Bundle: com.google.gwt
=======================================
---
/trunk/modules/com.solertium.util.gwt/src/com/solertium/util/gwt/ui/GenericHTMLMultipleListBox.java
Thu Jul 15 15:09:28 2010
+++
/trunk/modules/com.solertium.util.gwt/src/com/solertium/util/gwt/ui/GenericHTMLMultipleListBox.java
Thu Jul 22 10:47:04 2010
@@ -182,7 +182,7 @@
protected String width;
protected int schedule = 1500;
- protected CheckChangeListener<T> listener;
+ private CheckChangeListener<T> listener;
public GenericHTMLMultipleListBox(final String width) {
super();
=======================================
---
/trunk/modules/com.solertium.util.gwt/src/com/solertium/util/gwt/ui/HTMLListBox.java
Fri Sep 4 13:08:49 2009
+++
/trunk/modules/com.solertium.util.gwt/src/com/solertium/util/gwt/ui/HTMLListBox.java
Thu Jul 22 10:47:04 2010
@@ -15,13 +15,6 @@
*/
package com.solertium.util.gwt.ui;
-import java.util.ArrayList;
-
-import com.google.gwt.user.client.ui.Grid;
-import com.google.gwt.user.client.ui.HTML;
-import com.google.gwt.user.client.ui.ScrollPanel;
-import com.google.gwt.user.client.ui.SourcesTableEvents;
-import com.google.gwt.user.client.ui.TableListener;
/**
* HTMLListBox.java
@@ -34,30 +27,11 @@
* @author carl.scott
*
*/
-public abstract class HTMLListBox extends ScrollPanel {
-
- protected ArrayList<String> items;
- protected Grid table;
-
- protected int selectedIndex;
- protected boolean isEnabled = true;
-
- protected String width;
- protected int initSize;
-
- protected int schedule = 1500;
-
- /**
- * Creates a new Listbox with the designated width. If any widgets within
- * the listbox violate this width, the box will scroll horizontally.
- *
- * @param width
- */
- public HTMLListBox(final String width, int initSize) {
- super();
- items = new ArrayList<String>();
- setWidth(this.width = width);
- init(initSize);
+public abstract class HTMLListBox extends GenericHTMLListBox<String>
implements GenericHTMLListBox.ChangeListener<String> {
+
+ public HTMLListBox(String width, int initSize) {
+ super(width, initSize);
+ setChangeListener(this);
}
/**
@@ -68,140 +42,7 @@
public void addItem(final String name) {
addItem(name, name);
}
-
- /**
- * Adds a new item with a display name and selection value
- *
- * @param name
- * @param value
- */
- public void addItem(final String name, final String value) {
- addItem(name, value, null);
- }
-
- /**
- * Adds an item with a display name, selection value, and, optionally, a
- * tooltip. Will be ignored if null.
- *
- * @param name
- * @param value
- * @param toolTip
- */
- public void addItem(final String name, final String value, final String
toolTip) {
- HTML html;
- if (toolTip == null) {
- html = new HTML(name);
- } else {
- html = new HTMLWithToolTip(name, toolTip);
- ((HTMLWithToolTip)html).setSchedule(schedule);
- }
-
- html.setWordWrap(false);
- html.setStyleName("CIPD_ListBox_Item");
-
- if (initSize > items.size()) {
- table.setWidget(items.size(), 0, html);
- items.add(value);
-
- table.getColumnFormatter().setWidth(0, width);
- }
- }
-
- /**
- * Clears the list.
- */
- public void clear() {
- items.clear();
- if(table!=null) remove(table);
- selectedIndex = -1;
- }
-
- public int getItemCount() {
- return items.size();
- }
-
- public int getSelectedIndex() {
- return selectedIndex;
- }
-
- public String getSelectedText() {
- return getText(selectedIndex);
- }
-
- public String getSelectedValue() {
- return (String) items.get(selectedIndex);
- }
-
- /**
- * Pulls the table from the scrollpanel
- *
- * @return
- */
- public Grid getTableView() {
- return table;
- }
-
- public String getText(final int index) {
- return ((HTML) table.getWidget(index, 0)).getText();
- }
-
- public String getValue(final int index) {
- return (String) items.get(index);
- }
-
- public int indexOf(final String value) {
- return items.indexOf(value);
- }
-
- public boolean isEmpty() {
- return items.isEmpty();
- }
-
- /**
- * Method that occurs when an item is clicked.
- *
- * @param selectedValue
- */
+
public abstract void onChange(String selectedValue);
- public void setEnabled(final boolean isEnabled) {
- this.isEnabled = isEnabled;
- }
-
- public void setSelectedIndex(final int index) {
- selectedIndex = index;
- for (int i = 0; i < items.size(); i++) {
- ((HTML) table.getWidget(i, 0))
- .setStyleName(i == index ? "CIPD_ListBox_ItemSelected"
- : "CIPD_ListBox_Item");
- }
- }
-
- public void setText(final String text, final int index) {
- ((HTML) table.getWidget(index, 0)).setHTML(text);
- }
-
- public void setTooltipSchedule(final int schedule) {
- this.schedule = schedule;
- }
-
- public void init(int size) {
- this.initSize = size;
- table = new Grid(size,1);
- table.addTableListener(new TableListener() {
- public void onCellClicked(final SourcesTableEvents sender,
- final int row, final int cell) {
- if (isEnabled) {
- setSelectedIndex(row);
- onChange((String) items.get(row));
- }
- }
- });
- setWidget(table);
- }
-
- public void showItemInView(final int index) {
- setScrollPosition(index * 10);
- }
-
-}
+}