Commit 51b3c98e96ab6c779319fdd10b7180d8fcdef4ca

Use the ?locale= query param instead of the &lang= token param.

* src/main/java/org/glom/web/client/place/ListPlace.java
* src/main/java/org/glom/web/client/place/DetailsPlace.java
* src/main/java/org/glom/web/client/place/HasSelectableTablePlace.java
Remove the lang token key and value.

* src/main/java/org/glom/web/client/ui/TableSelectionView.java
* src/main/java/org/glom/web/client/ui/TableSelectionViewImpl.java:
When the user selects a different locale from the chooser, use
Window.Location.assign() to change the URL, which then causes a reload.

* src/main/java/org/glom/web/client/Utils.java: Added getCurrentLocaleID().
* src/main/java/org/glom/web/client/activity/DetailsActivity.java
* src/main/java/org/glom/web/client/activity/DocumentSelectionActivity.java
* src/main/java/org/glom/web/client/activity/ListActivity.java
* src/main/java/org/glom/web/client/activity/TableSelectionActivity
* src/main/java/org/glom/web/client/ui/DocumentSelectionView.java
* src/main/java/org/glom/web/client/ui/DocumentSelectionViewImpl.java:
* src/main/java/org/glom/web/client/ui/ListView.java:
* src/main/java/org/glom/web/client/ui/ListViewImpl.java:

Remove localeID member variables and method/constructor parameters, instead
using Utils.getCurrentLocaleID() when we need a localID to pass to
OnlineGlomService.
ChangeLog
(28 / 0)
  
112012-01-26 Murray Cumming <murrayc@murrayc.com>
22
3 Use the ?locale= query param instead of the &lang= token param.
4
5 * src/main/java/org/glom/web/client/place/ListPlace.java
6 * src/main/java/org/glom/web/client/place/DetailsPlace.java
7 * src/main/java/org/glom/web/client/place/HasSelectableTablePlace.java
8 Remove the lang token key and value.
9
10 * src/main/java/org/glom/web/client/ui/TableSelectionView.java
11 * src/main/java/org/glom/web/client/ui/TableSelectionViewImpl.java:
12 When the user selects a different locale from the chooser, use
13 Window.Location.assign() to change the URL, which then causes a reload.
14
15 * src/main/java/org/glom/web/client/Utils.java: Added getCurrentLocaleID().
16 * src/main/java/org/glom/web/client/activity/DetailsActivity.java
17 * src/main/java/org/glom/web/client/activity/DocumentSelectionActivity.java
18 * src/main/java/org/glom/web/client/activity/ListActivity.java
19 * src/main/java/org/glom/web/client/activity/TableSelectionActivity
20 * src/main/java/org/glom/web/client/ui/DocumentSelectionView.java
21 * src/main/java/org/glom/web/client/ui/DocumentSelectionViewImpl.java:
22 * src/main/java/org/glom/web/client/ui/ListView.java:
23 * src/main/java/org/glom/web/client/ui/ListViewImpl.java:
24
25 Remove localeID member variables and method/constructor parameters, instead
26 using Utils.getCurrentLocaleID() when we need a localID to pass to
27 OnlineGlomService.
28
292012-01-26 Murray Cumming <murrayc@murrayc.com>
30
331 Internationalize the UI strings.
432
533 * pom.xml: gwt-maven-plugin: Add the i18n goal and specify a
  
2727import com.google.gwt.core.client.GWT;
2828import com.google.gwt.dom.client.Document;
2929import com.google.gwt.dom.client.Style.Visibility;
30import com.google.gwt.i18n.client.LocaleInfo;
3031import com.google.gwt.i18n.client.NumberFormat;
32import com.google.gwt.user.client.Window;
3133import com.google.gwt.user.client.ui.Widget;
3234
3335/**
110110 }
111111
112112 return primaryKeyItem;
113 }
114
115 public static String getCurrentLocaleName() {
116 String localeID = LocaleInfo.getCurrentLocale().getLocaleName();
117 if(localeID == "default")
118 {
119 localeID = ""; //This is how libglom refers to the default locale.
120 }
121
122 if(StringUtils.isEmpty(localeID))
123 {
124 // LocaleInfo.getCurrentLocale() returns "default" even if a real locale was specified in the URL,
125 // if the locale is not specified as supported in our OnlineGlom.gwt.xml file,
126 // but people could use locales in .glom files that we have not thought of,
127 // so we should allow their use by getting the query parameter value directly:
128 final String paramValue = Window.Location.getParameter(LocaleInfo.getLocaleQueryParam());
129 localeID = paramValue;
130 }
131
132 return localeID;
113133 }
114134
115135}
  
107107 private String documentID = "";
108108 private String tableName = "";
109109 private TypedDataItem primaryKeyValue;
110 private String localeID = "";
111110 private final ClientFactory clientFactory;
112111 private final DetailsView detailsView;
113112 ArrayList<DetailsCell> detailsCells;
116116 this.documentID = place.getDocumentID();
117117 this.tableName = place.getTableName();
118118 this.primaryKeyValue = place.getPrimaryKeyValue();
119 this.localeID = place.getLocaleID();
120119 this.clientFactory = clientFactory;
121120 detailsView = clientFactory.getDetailsView();
122121 }
141141 @Override
142142 public void onTableChange(final TableChangeEvent event) {
143143 // note the empty primary key item
144 goTo(new DetailsPlace(documentID, event.getNewTableName(), localeID, new TypedDataItem()));
144 goTo(new DetailsPlace(documentID, event.getNewTableName(), new TypedDataItem()));
145145 }
146146 });
147147
167167 }
168168
169169 };
170
171 final String localeID = Utils.getCurrentLocaleID();
170172 OnlineGlomServiceAsync.Util.getInstance().getDetailsLayoutAndData(documentID, tableName, primaryKeyValue,
171173 localeID, callback);
172174
178178 public void onQuickFindChange(final QuickFindChangeEvent event) {
179179 // We switch to the List view, to show search results.
180180 // TODO: Show the details view if there is only one result.
181 goTo(new ListPlace(documentID, tableName, localeID, event.getNewQuickFindText()));
181 goTo(new ListPlace(documentID, tableName, event.getNewQuickFindText()));
182182 }
183183 });
184184
187187 @Override
188188 public void onLocaleChange(final LocaleChangeEvent event) {
189189 // note the empty primary key item
190 goTo(new DetailsPlace(documentID, tableName, event.getNewLocaleID(), primaryKeyValue));
190 goTo(new DetailsPlace(documentID, tableName, primaryKeyValue));
191191 }
192192 });
193193
340340 if (navigationPrimaryKeyValue != null && !navigationPrimaryKeyValue.isEmpty()) {
341341 if (!newTableName.equals(tableName)) {
342342 // Go to a new DetailsPlace because the table name has changed.
343 goTo(new DetailsPlace(documentID, newTableName, localeID, navigationPrimaryKeyValue));
343 goTo(new DetailsPlace(documentID, newTableName, navigationPrimaryKeyValue));
344344 } else {
345345 // Refresh the details view with the new primary because the table name has not changed.
346346 primaryKeyValue = navigationPrimaryKeyValue;
  
6262 if (documents.getCount() > 0) {
6363 for (int i = 0; i < documents.getCount(); i++) {
6464 documentSelectionView
65 .addDocumentLink(documents.getDocumentID(i), documents.getTitle(i), "" /* localeID */);
65 .addDocumentLink(documents.getDocumentID(i), documents.getTitle(i));
6666 // TODO: Get default locale.
6767 }
6868 } else {
  
2222import org.glom.web.client.StringUtils;
2323import org.glom.web.client.ClientFactory;
2424import org.glom.web.client.OnlineGlomServiceAsync;
25import org.glom.web.client.Utils;
2526import org.glom.web.client.event.LocaleChangeEvent;
2627import org.glom.web.client.event.LocaleChangeEventHandler;
2728import org.glom.web.client.event.QuickFindChangeEvent;
4949
5050 private final String documentID;
5151 private final String tableName;
52 private final String localeID;
5352 private final String quickFind;
5453 private final ClientFactory clientFactory;
5554 private final ListView listView;
5757 public ListActivity(final ListPlace place, final ClientFactory clientFactory) {
5858 this.documentID = place.getDocumentID(); // TODO: Just store the place?
5959 this.tableName = place.getTableName();
60 this.localeID = place.getLocaleID();
6160 this.quickFind = place.getQuickFind();
6261 this.clientFactory = clientFactory;
6362 listView = clientFactory.getListView();
9494 eventBus.addHandler(TableChangeEvent.TYPE, new TableChangeEventHandler() {
9595 @Override
9696 public void onTableChange(final TableChangeEvent event) {
97 goTo(new ListPlace(documentID, event.getNewTableName(), localeID, ""));
97 goTo(new ListPlace(documentID, event.getNewTableName(), ""));
9898 }
9999 });
100100
110110 public void onSuccess(final LayoutGroup result) {
111111 // TODO check if result.getTableName() is the same as the tableName field. Update it if it's not the
112112 // same.
113 listView.setCellTable(documentID, result, localeID, quickFind);
113 listView.setCellTable(documentID, result, quickFind);
114114 }
115115 };
116
117 final String localeID = Utils.getCurrentLocaleID();
116118 OnlineGlomServiceAsync.Util.getInstance().getListViewLayout(documentID, tableName, localeID, callback);
117119
118120 // TODO: Avoid the code duplication with DetailsActivity.
124124 public void onQuickFindChange(final QuickFindChangeEvent event) {
125125 // We switch to the List view, to show search results.
126126 // TODO: Show the details view if there is only one result.
127 goTo(new ListPlace(documentID, tableName, localeID, event.getNewQuickFindText()));
127 goTo(new ListPlace(documentID, tableName, event.getNewQuickFindText()));
128128 }
129129 });
130130
133133 @Override
134134 public void onLocaleChange(final LocaleChangeEvent event) {
135135 // note the empty primary key item
136 goTo(new ListPlace(documentID, tableName, event.getNewLocaleID(), quickFind));
136 goTo(new ListPlace(documentID, tableName, quickFind));
137137 }
138138 });
139139
  
2222import org.glom.web.client.StringUtils;
2323import org.glom.web.client.ClientFactory;
2424import org.glom.web.client.OnlineGlomServiceAsync;
25import org.glom.web.client.Utils;
2526import org.glom.web.client.event.LocaleChangeEvent;
2627import org.glom.web.client.event.QuickFindChangeEvent;
2728import org.glom.web.client.event.TableChangeEvent;
4040import com.google.gwt.event.dom.client.HasChangeHandlers;
4141import com.google.gwt.event.shared.EventBus;
4242import com.google.gwt.event.shared.HandlerRegistration;
43import com.google.gwt.i18n.client.LocaleInfo;
4344import com.google.gwt.place.shared.Place;
4445import com.google.gwt.user.client.Window;
4546import com.google.gwt.user.client.rpc.AsyncCallback;
5454 private String documentID;
5555 private String documentTitle;
5656 private String tableName;
57 private String localeID;
5857 private String quickFind;
5958 private HandlerRegistration tableChangeHandlerRegistration = null;
6059 private HandlerRegistration quickFindChangeHandlerRegistration = null;
108108 @Override
109109 public void onChange(final ChangeEvent event) {
110110 // Show the translated version of the document title and the table names:
111 localeID = tableSelectionView.getSelectedLocale();
111 final String localeID = tableSelectionView.getSelectedLocale();
112112 fillView(tableSelectionView);
113
114 final String newURL = Window.Location.createUrlBuilder().setParameter(LocaleInfo.getLocaleQueryParam(), localeID).buildString();
115 Window.Location.assign(newURL);
113116
114117 // Fire a locale change event so that other views (e.g. the details view) know about the change and can
115118 // update themselves.
146146 tableSelectionView.setSelectedTableName(tableName);
147147
148148 tableSelectionView.setLocaleList(result.getLocaleIDs(), result.getLocaleTitles());
149
150 final String localeID = Utils.getCurrentLocaleID();
149151 tableSelectionView.setSelectedLocale(localeID);
150152
151153 documentTitle = result.getTitle();
155155 Window.setTitle(documentTitle + ": " + tableSelectionView.getSelectedTableTitle());
156156 }
157157 };
158 final String localeID = Utils.getCurrentLocaleID();
158159 OnlineGlomServiceAsync.Util.getInstance().getDocumentInfo(documentID, localeID, callback);
159160
160161 // Show the quickFind text that was specified by the URL token:
167167 public void setPlace(final HasSelectableTablePlace place) {
168168 documentID = place.getDocumentID();
169169 tableName = place.getTableName();
170 localeID = place.getLocaleID();
171170
172171 try {
173172 final ListPlace asPlace = (ListPlace) place;
185185 // show the 'back to list' link if we're at a DetailsPlace, hide it otherwise
186186 if (place instanceof DetailsPlace) {
187187 tableSelectionView.setBackLinkVisible(true);
188 tableSelectionView.setBackLink(documentID, tableName, localeID, ""); // TODO: quickfind?
188 tableSelectionView.setBackLink(documentID, tableName, ""); // TODO: quickfind?
189189 } else if (place instanceof ListPlace) {
190190 tableSelectionView.setBackLinkVisible(false);
191191 }
  
3131public class DetailsPlace extends HasSelectableTablePlace {
3232 private final TypedDataItem primaryKeyValue;
3333
34 public DetailsPlace(final String documentID, final String tableName, final String localeID,
34 public DetailsPlace(final String documentID, final String tableName,
3535 final TypedDataItem primarykeyValue) {
36 super(documentID, tableName, localeID);
36 super(documentID, tableName);
3737 this.primaryKeyValue = primarykeyValue;
3838 }
3939
102102 final HashMap<String, String> params = new HashMap<String, String>();
103103 params.put(documentKey, place.getDocumentID());
104104 params.put(tableKey, place.getTableName());
105 params.put(localeKey, place.getLocaleID());
106105 params.put(primaryKeyValueKey, primaryKeyValueString);
107106 return buildParamsToken(params);
108107 }
119119 // default empty values
120120 String documentID = "";
121121 String tableName = ""; // an empty value represents the default table
122 String localeID = "";
123122
124123 final TypedDataItem primaryKeyValue = new TypedDataItem();
125124
126125 final HashMap<String, String> params = getTokenParams(token);
127126
128127 if (params == null) {
129 return new DetailsPlace("", "", "", primaryKeyValue);
128 return new DetailsPlace("", "", primaryKeyValue);
130129 }
131130
132131 if (params.get(documentKey) != null) {
136136 tableName = params.get(tableKey);
137137 }
138138
139 if (params.get(localeKey) != null) {
140 localeID = params.get(localeKey);
141 }
142
143139 if (params.get(primaryKeyValueKey) != null) {
144140 final String primaryKeyValueString = params.get(primaryKeyValueKey);
145141 // Set as unknown because the type of the primary key is not known at this point. A proper primary key
145145
146146 if (StringUtils.isEmpty(documentID)) {
147147 // The documentID was not retrieved from the URL. Use empty values for the details place.
148 return new DetailsPlace("", "", localeID, primaryKeyValue);
148 return new DetailsPlace("", "", primaryKeyValue);
149149 }
150150
151 return new DetailsPlace(documentID, tableName, localeID, primaryKeyValue);
151 return new DetailsPlace(documentID, tableName, primaryKeyValue);
152152 }
153153 }
154154
  
3636
3737 private final String documentID;
3838 private final String tableName;
39 private final String localeID;
4039
41 public HasSelectableTablePlace(final String documentID, final String tableName, final String localeID) {
40 public HasSelectableTablePlace(final String documentID, final String tableName) {
4241 this.documentID = documentID;
4342 this.tableName = tableName;
44 this.localeID = localeID;
4543 }
4644
4745 public String getDocumentID() {
5050 return tableName;
5151 }
5252
53 public String getLocaleID() {
54 return localeID;
55 }
56
5753 public static class Tokenizer {
5854 protected final String documentKey = "document";
5955 protected final String tableKey = "table";
60 protected final String localeKey = "lang";
6156 private final String separator = "&";
6257 private final String equals = "=";
6358
  
3030
3131 private final String quickFind;
3232
33 public ListPlace(final String documentID, final String tableName, final String localeID, final String quickFind) {
34 super(documentID, tableName, localeID);
33 public ListPlace(final String documentID, final String tableName, final String quickFind) {
34 super(documentID, tableName);
3535 this.quickFind = quickFind;
3636 }
3737
4848 final HashMap<String, String> params = new HashMap<String, String>();
4949 params.put(documentKey, place.getDocumentID());
5050 params.put(tableKey, place.getTableName());
51 params.put(localeKey, place.getLocaleID());
5251 params.put(quickFindKey, place.getQuickFind());
5352 return buildParamsToken(params);
5453 }
5757 // default empty values
5858 String documentID = "";
5959 String tableName = ""; // an empty value represents the default table
60 String localeID = "";
6160 String quickFind = "";
6261
6362 final HashMap<String, String> params = getTokenParams(token);
6463
6564 if (params == null) {
66 return new ListPlace("", "", "", "");
65 return new ListPlace("", "", "");
6766 }
6867
6968 if (params.get(documentKey) != null) {
7373 tableName = params.get(tableKey);
7474 }
7575
76 if (params.get(localeKey) != null) {
77 localeID = params.get(localeKey);
78 }
79
8076 if (params.get(quickFindKey) != null) {
8177 quickFind = params.get(quickFindKey);
8278 }
8379
8480 if (StringUtils.isEmpty(documentID)) {
8581 // The documentID was not retrieved from the URL. Use empty values for the list place.
86 return new ListPlace("", "", localeID, "");
82 return new ListPlace("", "", "");
8783 }
8884
89 return new ListPlace(documentID, tableName, localeID, quickFind);
85 return new ListPlace(documentID, tableName, quickFind);
9086 }
9187 }
9288
  
2121
2222public interface DocumentSelectionView extends View {
2323
24 void addDocumentLink(String documentID, String title, String localeID);
24 void addDocumentLink(String documentID, String title);
2525
2626 void clearHyperLinks();
2727
  
5252 }
5353
5454 @Override
55 public void addDocumentLink(final String documentID, final String title, final String localeID) {
55 public void addDocumentLink(final String documentID, final String title) {
5656 final Anchor link = new Anchor(title);
5757 link.setStyleName("documentLink");
5858 link.addClickHandler(new ClickHandler() {
5959 @Override
6060 public void onClick(final ClickEvent event) {
61 presenter.goTo(new ListPlace(documentID, "", localeID, ""));
61 presenter.goTo(new ListPlace(documentID, "", ""));
6262 }
6363 });
6464 documentLinks.add(link);
  
2626 */
2727public interface ListView extends View {
2828
29 public void setCellTable(final String documentID, LayoutGroup layoutGroup, String localeID, String quickFind);
29 public void setCellTable(final String documentID, LayoutGroup layoutGroup, String quickFind);
3030}
  
3939 private class ListViewNavigationButtonCell extends NavigationButtonCell {
4040 private final String documentID;
4141 private final String tableName;
42 private final String localeID;
4342
44 public ListViewNavigationButtonCell(final String documentID, final String tableName, final String localeID) {
43 public ListViewNavigationButtonCell(final String documentID, final String tableName) {
4544 this.documentID = documentID;
4645 this.tableName = tableName;
47 this.localeID = localeID;
4846 }
4947
5048 /*
5555 @Override
5656 protected void onEnterKeyDown(final Context context, final Element parent, final String value,
5757 final NativeEvent event, final ValueUpdater<String> valueUpdater) {
58 presenter.goTo(new DetailsPlace(documentID, tableName, localeID, (TypedDataItem) context.getKey()));
58 presenter.goTo(new DetailsPlace(documentID, tableName, (TypedDataItem) context.getKey()));
5959 }
6060
6161 }
7373 }
7474
7575 @Override
76 public void setCellTable(final String documentID, final LayoutGroup layoutGroup, final String localeID,
76 public void setCellTable(final String documentID, final LayoutGroup layoutGroup,
7777 final String quickFind) {
7878 // This is not really in the MVP style because we're creating a new ListTable (really just a configured
7979 // CellTable) for every document and table name change. The issue with creating a re-usable CellTable with
8787 mainPanel.clear();
8888
8989 final ListViewTable listViewTable = new ListViewTable(documentID, layoutGroup,
90 new ListViewNavigationButtonCell(documentID, layoutGroup.getTableName(), localeID), quickFind);
90 new ListViewNavigationButtonCell(documentID, layoutGroup.getTableName()), quickFind);
9191
9292 if (layoutGroup.getExpectedResultSize() <= listViewTable.getMinNumVisibleRows()) {
9393 // Set the table row count to the minimum row count if the data row count is less than or equal to
  
6060
6161 void setBackLinkVisible(boolean visible);
6262
63 void setBackLink(final String documentID, final String tableName, final String localeID, String quickFind);
63 void setBackLink(final String documentID, final String tableName, String quickFind);
6464
6565 void setDocumentTitle(String documentTitle);
6666}
  
8686
8787 localesChooser.setStyleName("localeschooser"); // TODO: This is tedious.
8888
89 // headbox with the table selector
89 // headbox with the table selector
9090 final FlowPanel headbox = new FlowPanel();
9191 DOM.setElementAttribute(headbox.getElement(), "id", "headbox");
9292 headbox.add(tablesChooser);
133133 }
134134
135135 @Override
136 public void setBackLink(final String documentID, final String tableName, final String localeID,
136 public void setBackLink(final String documentID, final String tableName,
137137 final String quickFind) {
138138 backLinkHandlerReg.removeHandler();
139139 backLinkHandlerReg = backLink.addClickHandler(new ClickHandler() {
140140 @Override
141141 public void onClick(final ClickEvent event) {
142 presenter.goTo(new ListPlace(documentID, tableName, localeID, ""));
142 presenter.goTo(new ListPlace(documentID, tableName, ""));
143143 }
144144 });
145145 }