Permalink
Browse files

Bug fixes

  • Loading branch information...
1 parent 1c1c114 commit c512f6af41f8e56dba5f6995dc8188025a097dc8 @bradseefeld committed Aug 25, 2012
View
13 pom.xml
@@ -6,12 +6,12 @@
<groupId>com.bradley.gwt</groupId>
<artifactId>gwt-ui</artifactId>
<packaging>jar</packaging>
- <version>1.0.0-SNAPSHOT</version>
+ <version>1.0.0</version>
<name>GWT Maven Archetype</name>
<properties>
- <gwt.version>2.4.0</gwt.version>
- <plugin.gwt.version>2.3.0</plugin.gwt.version>
+ <gwt.version>2.5.0-rc1</gwt.version>
+ <plugin.gwt.version>2.5.0-rc1</plugin.gwt.version>
<slf4j.version>1.6.1</slf4j.version>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
@@ -76,12 +76,7 @@
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>${slf4j.version}</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
+ <artifactId>slf4j-jdk14</artifactId>
<version>${slf4j.version}</version>
</dependency>
</dependencies>
@@ -1,12 +1,30 @@
package com.bradley.gwt.user.client.google.analytics;
+import com.google.gwt.core.client.GWT;
+
public final class GoogleAnalyticsUtil {
- public static native void trackEvent(String category, String action, String label) /*-{
+ public static void trackEvent(String category, String action, String label) {
+ if (!GWT.isProdMode()) {
+ return;
+ }
+
+ _trackEvent(category, action, label);
+ }
+
+ public static void trackEvent(String category, String action, String label, int intArg) {
+ if (!GWT.isProdMode()) {
+ return;
+ }
+
+ _trackEvent(category, action, label, intArg);
+ }
+
+ private static native void _trackEvent(String category, String action, String label) /*-{
$wnd._gaq.push(['_trackEvent', category, action, label]);
}-*/;
- public static native void trackEvent(String category, String action, String label, int intArg) /*-{
+ private static native void _trackEvent(String category, String action, String label, int intArg) /*-{
$wnd._gaq.push(['_trackEvent', category, action, label, intArg]);
}-*/;
}
@@ -0,0 +1,11 @@
+package com.bradley.gwt.user.client.resource;
+
+import com.google.gwt.user.cellview.client.CellList;
+
+public interface CellListResources extends CellList.Resources {
+
+ public interface Style extends CellList.Style {}
+
+ @Source("css/cell-list.css")
+ Style cellListStyle();
+}
@@ -85,8 +85,8 @@ public void setValue(Date value, boolean fireEvents) {
setValue(value);
}
- public void addChangeHandler(ChangeHandler handler) {
- textbox.addChangeHandler(handler);
+ public HandlerRegistration addChangeHandler(ChangeHandler handler) {
+ return textbox.addChangeHandler(handler);
}
@Override
@@ -6,14 +6,16 @@
import com.google.gwt.core.client.GWT;
import com.google.gwt.editor.client.LeafValueEditor;
import com.google.gwt.event.dom.client.ChangeHandler;
+import com.google.gwt.event.dom.client.HasChangeHandlers;
+import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
-public class DateTimeEditor extends Composite implements LeafValueEditor<Date> {
+public class DateTimeEditor extends Composite implements LeafValueEditor<Date>, HasChangeHandlers {
@UiField
DateBox date;
@@ -42,9 +44,9 @@ public DateTimeEditor() {
initWidget(binder.createAndBindUi(this));
}
- public void addChangeHandler(ChangeHandler handler) {
- date.addChangeHandler(handler);
+ public HandlerRegistration addChangeHandler(ChangeHandler handler) {
time.addChangeHandler(handler);
+ return date.addChangeHandler(handler);
}
@Override
@@ -71,23 +73,8 @@ public Date getValue() {
if (time == null) {
return day;
}
- LOG.finer("Raw time is " + time.getTime());
-
- long timeMillis = time.getTime() % (24 * 60 * 60 * 1000);
- int offsetMillis = new Date().getTimezoneOffset() * 60 * 1000;
- int dayMillis = 24 * 60 * 60 * 1000;
- if (timeMillis < offsetMillis) {
- // Need to add a day to time to account for day overflow
- timeMillis += dayMillis;
- } else if (timeMillis + offsetMillis > dayMillis) {
- //timeMillis -= dayMillis;
- }
- timeMillis -= offsetMillis;
-
- LOG.finer("Milliseconds into day is " + timeMillis);
- Date d = new Date(day.getTime() + timeMillis);
- return d;
+ return DateTimeEditor.merge(day, time);
}
public DateBox getDateBox() {
@@ -105,4 +92,24 @@ public Label getDateLabel() {
public Label getTimeLabel() {
return timeLabel;
}
+
+ public static Date merge(Date day, Date time) {
+ LOG.finer("Raw time is " + time.getTime());
+
+ long timeMillis = time.getTime() % (24 * 60 * 60 * 1000);
+ int offsetMillis = new Date().getTimezoneOffset() * 60 * 1000;
+ int dayMillis = 24 * 60 * 60 * 1000;
+ if (timeMillis < offsetMillis) {
+ // Need to add a day to time to account for day overflow
+ timeMillis += dayMillis;
+ } else if (timeMillis + offsetMillis > dayMillis) {
+ //timeMillis -= dayMillis;
+ }
+
+ timeMillis -= offsetMillis;
+
+ LOG.finer("Milliseconds into day is " + timeMillis);
+ Date d = new Date(day.getTime() + timeMillis);
+ return d;
+ }
}
@@ -11,6 +11,6 @@
* @param <M>
* @param <T>
*/
-public class DualListBox<M, T> extends MultiSelectListBox<M, T> {
+public class DualListBox<M, T> extends MultiSelectSetBox<M, T> {
}
@@ -0,0 +1,165 @@
+package com.bradley.gwt.user.client.ui;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import com.google.gwt.user.client.ui.ListBox;
+
+public class MultiSelectBox<M, T> extends ListBox {
+
+ /**
+ * A map of html option value (String) to the type being set/get. This is
+ * really a String repsentation of the values hashcode to the value.
+ */
+ protected Map<String, T> values;
+
+ /**
+ * A renderer that will transform complex objects into Strings for
+ * presentation.
+ */
+ protected Renderer<M> renderer;
+
+ protected List<T> lazySelectValues;
+
+ /** True if the widget has been enhanced by jquery. */
+ protected boolean enhanced = false;
+
+ /** Internal class level logger. */
+ private static final Logger LOG = Logger.getLogger(MultiSelectSetBox.class.getName());
+
+ /**
+ * Default constructor.
+ */
+ public MultiSelectBox() {
+ super(true);
+
+ values = new HashMap<String, T>();
+ }
+
+ @Override
+ public void clear() {
+ values.clear();
+ super.clear();
+ }
+
+ /**
+ * Add an option to the list.
+ *
+ * @param display The text that is displayed in the list.
+ * @param value The value that is given back when this option is selected.
+ */
+ public void addItem(String display, T value) {
+ values.put(valueOf(value), value);
+ super.addItem(display, valueOf(value));
+
+ if (lazySelectValues != null) {
+ setValue(lazySelectValues);
+ }
+ }
+
+ /**
+ * Add an option to the list.
+ *
+ * @param model The model that represents what will be displayed.
+ * @param value The value that is given back when this option is selected.
+ */
+ public void addItem(M model, T value) {
+ values.put(valueOf(value), value);
+ super.addItem(render(model), valueOf(value));
+
+ if (lazySelectValues != null) {
+ setValue(lazySelectValues);
+ }
+ }
+
+ public void setValue(List<T> values) {
+ if (values == null) {
+ return;
+ }
+
+ /*
+ * Sometimes the list of options is loaded lazily from the server. In this
+ * case, we may be setting the selected options before the list of options
+ * actually loads. To support this use case without requiring extra coding
+ * on the developers part, we will hold off on selection until items are
+ * added.
+ */
+ if (getItemCount() == 0) {
+ LOG.fine("Attempting to set values when no options exist. We will " +
+ "hold off on setting the values until some options have been " +
+ "added.");
+ lazySelectValues = values;
+ }
+
+ for (int i = 0; i < getItemCount(); i++) {
+ for (T value : values) {
+ if (getValue(i).equals(valueOf(value))) {
+ setItemSelected(i, true);
+ }
+ }
+ }
+ }
+
+ /**
+ * Set the renderer responsible for generating a valid display value
+ * for the complex model type.
+ *
+ * @param renderer
+ */
+ public void setRenderer(Renderer<M> renderer) {
+ this.renderer = renderer;
+ }
+
+ /**
+ * Remove all selected values.
+ *
+ * @return The items removed.
+ */
+ public Set<T> removeSelected() {
+ Set<T> removed = new HashSet<T>();
+
+ for (int i = getItemCount() - 1; i >= 0; i--) {
+ if (isItemSelected(i)) {
+ String key = getValue(i);
+ removed.add(values.get(key));
+ values.remove(key);
+ removeItem(i);
+ }
+ }
+
+ return removed;
+ }
+
+ /**
+ * Render the complex model into a simple String to be used in the list.
+ *
+ * @param item
+ * @return
+ */
+ protected String render(M item) {
+ if (renderer == null) {
+ return item.toString();
+ }
+
+ return renderer.render(item);
+ }
+
+ /**
+ * Convert this value to a simple String. Should be unique per item given.
+ *
+ * @param item
+ * @return
+ */
+ protected String valueOf(T item) {
+ if (item == null) {
+ return "";
+ }
+
+ return item.toString();
+ }
+}
Oops, something went wrong.

0 comments on commit c512f6a

Please sign in to comment.