Subversion Repository Public Repository

litesoft

Diff Revisions 626 vs 630 for /trunk/GWT_Sandbox/FormEngine/src/com/temp/client/foundation/widget/NameToID.java

Diff revisions: vs.
  @@ -1,15 +1,14 @@
1 1 package com.temp.client.foundation.widget;
2 2
3 + import com.google.gwt.user.client.ui.HasName;
4 + import com.google.gwt.user.client.ui.Widget;
5 + import com.temp.shared.utils.StringUtils;
6 +
3 7 import java.util.ArrayList;
4 8 import java.util.HashMap;
5 9 import java.util.List;
6 10 import java.util.Map;
7 11
8 - import com.temp.shared.utils.StringUtils;
9 -
10 - import com.google.gwt.user.client.ui.HasName;
11 - import com.google.gwt.user.client.ui.Widget;
12 -
13 12 public final class NameToID {
14 13 private Map<String, List<Widget>> widgetsById = new HashMap<String, List<Widget>>();
15 14
  @@ -29,18 +28,31 @@
29 28 this.suffix = StringUtils.deNull(suffix).trim();
30 29 }
31 30
31 + public NameToID add(List<HasName> widgets) {
32 + if (widgets != null)
33 + for (HasName widget : widgets) {
34 + tryAdd(widget);
35 + }
36 + return this;
37 + }
38 +
32 39 public NameToID add(HasName... widgets) {
33 - for (HasName widget : widgets) {
34 - if (widget instanceof Widget) {
35 - String id = extractId(widget);
36 - if (id != null) {
37 - add((Widget) widget, id + suffix);
38 - }
40 + if (widgets != null)
41 + for (HasName widget : widgets) {
42 + tryAdd(widget);
39 43 }
40 - }
41 44 return this;
42 45 }
43 46
47 + private void tryAdd(HasName widget) {
48 + if (widget instanceof Widget) {
49 + String id = extractId(widget);
50 + if (id != null) {
51 + add((Widget) widget, id + suffix);
52 + }
53 + }
54 + }
55 +
44 56 public void applyIDs() {
45 57 for (Map.Entry<String, List<Widget>> widgetByName : widgetsById.entrySet()) {
46 58 applyIDs(widgetByName.getValue(), widgetByName.getKey());
  @@ -67,7 +79,7 @@
67 79 applyID(widgets.get(0), id);
68 80 return;
69 81 }
70 - for (int i = 0; i < widgets.size();) {
82 + for (int i = 0; i < widgets.size(); ) {
71 83 Widget widget = widgets.get(i++);
72 84 applyID(widget, id + i);
73 85 }
  @@ -75,7 +87,7 @@
75 87
76 88 private void applyID(Widget widget, String id) {
77 89 if (widget instanceof IdSettable) {
78 - ((IdSettable)widget).setId(id);
90 + ((IdSettable) widget).setId(id);
79 91 } else {
80 92 widget.getElement().setId(id);
81 93 }