Browse Source

Added drafting classes for locale handling.

Changed most component classnames to public.
Added a new method hasVariable to UIDL class.
Client now uses POST for requests and has some drafting methods for locale loading.

svn changeset:1767/svn branch:trunk
tags/6.7.0.beta1
Jouni Koivuviita 17 years ago
parent
commit
ea15bacee1

+ 27
- 1
src/com/itmill/toolkit/terminal/gwt/client/Client.java View File

@@ -82,7 +82,7 @@ public class Client implements EntryPoint {

private void makeUidlRequest(String requestData) {
console.log("Making UIDL Request with params: " + requestData);
rb = new RequestBuilder(RequestBuilder.GET, appUri
rb = new RequestBuilder(RequestBuilder.POST, appUri
+ "/UIDL/?requestId=" + (Math.random()) + "&" + requestData);
try {
rb.sendRequest(requestData, new RequestCallback() {
@@ -353,4 +353,30 @@ public class Client implements EntryPoint {
return (String) resourcesMap.get(name);
}

public JSONObject getLocale(String locale) {
// TODO should perform synchronous call to server to fetch
// locale specific strings
// (GWT only supports synchrounous requests from v. 1.4)
console.log("Loading a new locale: " + locale);
rb = new RequestBuilder(RequestBuilder.POST, appUri
+ "/locale/?requestId=" + (Math.random()) + "&" + locale);
/*try {
rb.sendRequest(locale, new RequestCallback() {
public void onError(Request request, Throwable exception) {
console.error("Got error");
}

public void onResponseReceived(Request request,
Response response) {
handleReceivedJSONMessage(response);
}

});

} catch (RequestException e) {
console.error(e.getMessage());
}*/
// TODO
return null;
}
}

+ 44
- 0
src/com/itmill/toolkit/terminal/gwt/client/DateTimeService.java View File

@@ -0,0 +1,44 @@
package com.itmill.toolkit.terminal.gwt.client;
/**
* This class provides date/time parsing services to all components.
*
* @author Jouni Koivuviita
*
*/
public class DateTimeService {
private LocaleService localeService;
private String currentLocale;
public DateTimeService(Client client) {
localeService = new LocaleService(client);
}
public DateTimeService(Client client, String locale) {
this(client);
setLocale(locale);
}
public void setLocale(String locale) {
currentLocale = locale;
}
public String getLocale() {
return currentLocale;
}
public String getMonth(int month) throws Exception {
if(currentLocale != null)
return localeService.getMonthNames(currentLocale)[month];
else throw new Exception("No locale specified.");
}
public String getShortMonth(int month) throws Exception {
if(currentLocale != null)
return localeService.getShortMonthNames(currentLocale)[month];
else throw new Exception("No locale specified.");
}
}

+ 3
- 0
src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetFactory.java View File

@@ -6,6 +6,7 @@ import com.itmill.toolkit.terminal.gwt.client.ui.IButton;
import com.itmill.toolkit.terminal.gwt.client.ui.ICheckBox;
import com.itmill.toolkit.terminal.gwt.client.ui.IComponent;
import com.itmill.toolkit.terminal.gwt.client.ui.ICustomLayout;
import com.itmill.toolkit.terminal.gwt.client.ui.IDateField;
import com.itmill.toolkit.terminal.gwt.client.ui.IEmbedded;
import com.itmill.toolkit.terminal.gwt.client.ui.IGridLayout;
import com.itmill.toolkit.terminal.gwt.client.ui.IHorizontalLayout;
@@ -75,6 +76,8 @@ public class DefaultWidgetFactory implements WidgetFactory {
}
if ("table".equals(tag))
return new ITable();
if("datefield".equals(tag))
return new IDateField();

return new IUnknownComponent();
}

+ 81
- 0
src/com/itmill/toolkit/terminal/gwt/client/LocaleService.java View File

@@ -0,0 +1,81 @@
package com.itmill.toolkit.terminal.gwt.client;
import java.util.HashMap;
import java.util.Map;
import com.google.gwt.json.client.JSONObject;
/**
* Date / time etc. localisation service for all widgets.
* Should cache all loaded locales as JSON strings.
*
* @author Jouni Koivuviita
*
*/
public class LocaleService {
private Client client;
private Map cache = new HashMap();
public LocaleService(Client client){
this.client = client;
}
private void loadLocale(String locale) {
JSONObject resp = client.getLocale(locale);
cache.put(locale, resp);
}
public String[] getMonthNames(String locale) {
// TODO
//if(cache.containsKey(locale))
//else loadLocale(locale);
String[] temp = new String[12];
temp[0] = "tammi"; temp[1] = "helmi"; temp[2] = "maalis"; temp[3] = "huhti";
temp[4] = "touko"; temp[5] = "kesä"; temp[6] = "heinä"; temp[7] = "elo";
temp[8] = "syys"; temp[9] = "loka"; temp[10] = "marras"; temp[11] = "joulu";
return temp;
}
public String[] getShortMonthNames(String locale) {
// TODO
//if(cache.containsKey(locale))
//else loadLocale(locale);
String[] temp = new String[12];
temp[0] = "tam"; temp[1] = "hel"; temp[2] = "maa"; temp[3] = "huh";
temp[4] = "tou"; temp[5] = "kes"; temp[6] = "hei"; temp[7] = "elo";
temp[8] = "syy"; temp[9] = "lok"; temp[10] = "mar"; temp[11] = "jou";
return temp;
}
public String[] getDayNames(String locale) {
// TODO
//if(cache.containsKey(locale))
//else loadLocale(locale);
String[] temp = new String[7];
temp[1] = "maanatai"; temp[2] = "tiistai"; temp[3] = "keskiviikko";
temp[4] = "torstai"; temp[5] = "perjantai"; temp[6] = "lauantai";
temp[0] = "sunnuntai";
return temp;
}
public String[] getShortDayNames(String locale) {
// TODO
//if(cache.containsKey(locale))
//else loadLocale(locale);
String[] temp = new String[7];
temp[1] = "ma"; temp[2] = "ti"; temp[3] = "ke";
temp[4] = "to"; temp[5] = "pe"; temp[6] = "la";
temp[0] = "su";
return temp;
}
public int getFirstDayOfWeek(String locale) {
// TODO
//if(cache.containsKey(locale))
//else loadLocale(locale);
return 1;
}
}

+ 8
- 0
src/com/itmill/toolkit/terminal/gwt/client/UIDL.java View File

@@ -265,6 +265,14 @@ public class UIDL {
throw new IllegalArgumentException("No variables defined in tag.");
return v;
}
public boolean hasVariable(String name) {
Object v = null;
try {
v = getVariableHash().get(name);
} catch(IllegalArgumentException e) {}
return v != null;
}

public String getStringVariable(String name) {
JSONString t = (JSONString) getVariableHash().get(name);

+ 1
- 1
src/com/itmill/toolkit/terminal/gwt/client/ui/IButton.java View File

@@ -9,7 +9,7 @@ import com.itmill.toolkit.terminal.gwt.client.UIDL;

public class IButton extends Button implements Paintable {
private static final String CLASSNAME = "i-button";
public static final String CLASSNAME = "i-button";

String id;


+ 126
- 0
src/com/itmill/toolkit/terminal/gwt/client/ui/IDateField.java View File

@@ -0,0 +1,126 @@
package com.itmill.toolkit.terminal.gwt.client.ui;
import java.util.Date;
import com.google.gwt.user.client.ui.ChangeListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.Widget;
import com.itmill.toolkit.terminal.gwt.client.Client;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
public class IDateField extends Composite implements Paintable, ChangeListener {
/*
* This implementation is old already.
* We should use the DateTimeService class (which is a draft) to get
* locale specific strings and use them to build the datefield
* and its different styles (with inheritance of course).
*
* Drafting usage patterns:
*
* DateTimeService dts = new DateTimeService(client, "fi_FI");
* String month = dts.getMonth(0); // Returns "January"
* String day = dts.getDay(19); // Returns e.g. "sunday"
* String dateformat = dts.getDateFormat(); // Returns something like MM_/_DD_/_YYYY
* String timeformat = dts.getTimeFormat(); // Returns something like HH_:_MM
* String date = dts.parseDate(new Date()); // Returns e.g. 6/19/2007 14:32
* String date = dts.parseFullDate(new Date()); // Returns e.g. Tuesday 6th June 2007 14:32
*/
public static final String CLASSNAME = "i-datefield";
String id;
Client client;
private boolean immediate;
private FlowPanel container;
private ListBox year;
private static int RESOLUTION_YEAR = 0;
private static int RESOLUTION_MONTH = 1;
private static int RESOLUTION_DAY = 2;
private static int RESOLUTION_HOUR = 3;
private static int RESOLUTION_MIN = 4;
private static int RESOLUTION_SEC = 5;
private static int RESOLUTION_MSEC = 6;
private int currentResolution = RESOLUTION_YEAR;
public IDateField() {
container = new FlowPanel();
initWidget(container);
}
public void updateFromUIDL(UIDL uidl, Client client) {
// Ensure correct implementation and let layout manage caption
if (client.updateComponent(this, uidl, true))
return;
// Save details
this.client = client;
id = uidl.getId();
immediate = uidl.getBooleanAttribute("immediate");
int newResolution = RESOLUTION_YEAR;
if(uidl.hasAttribute("month"))
newResolution = RESOLUTION_MONTH;
if(uidl.hasAttribute("day"))
newResolution = RESOLUTION_DAY;
if(uidl.hasAttribute("hour"))
newResolution = RESOLUTION_HOUR;
if(uidl.hasAttribute("min"))
newResolution = RESOLUTION_MIN;
if(uidl.hasAttribute("sec"))
newResolution = RESOLUTION_SEC;
if(uidl.hasAttribute("msec"))
newResolution = RESOLUTION_MSEC;
if(currentResolution > newResolution)
container.clear();
if(uidl.hasVariable("year")) {
int selectedYear = uidl.getIntVariable("year");
int y = container.getWidgetIndex(year);
if(y > -1) {
year = (ListBox) container.getWidget(y);
// Deselect old value
year.setItemSelected(year.getSelectedIndex(), false);
// and select new
for(int i=0; i < year.getItemCount(); i++)
if(year.getValue(i).equals(""+selectedYear)) {
year.setSelectedIndex(i);
break;
}
} else {
year = new ListBox();
year.setStyleName(ISelect.CLASSNAME);
int today = 1900 + (new Date()).getYear();
for(int i=1970; i<today+400; i++) {
year.addItem(""+i, ""+i);
if(i == selectedYear)
year.setSelectedIndex(year.getItemCount()-1);
}
year.addChangeListener(this);
container.add(year);
}
}
currentResolution = newResolution;
}
public void onChange(Widget sender) {
if(sender == year && client != null)
client.updateVariable(id, "year", year.getValue(year.getSelectedIndex()), immediate);
}
}

+ 4
- 1
src/com/itmill/toolkit/terminal/gwt/client/ui/ILabel.java View File

@@ -1,14 +1,17 @@
package com.itmill.toolkit.terminal.gwt.client.ui;

import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.itmill.toolkit.terminal.gwt.client.Client;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;

public class ILabel extends HTML implements Paintable {
public static final String CLASSNAME = "i-label";

public void updateFromUIDL(UIDL uidl, Client client) {
setStyleName(CLASSNAME);

if (client.updateComponent(this, uidl, true))
return;

+ 1
- 1
src/com/itmill/toolkit/terminal/gwt/client/ui/IOptionGroup.java View File

@@ -12,7 +12,7 @@ import com.itmill.toolkit.terminal.gwt.client.UIDL;
public class IOptionGroup extends IOptionGroupBase {
private static final String CLASSNAME = "i-select-optiongroup";
public static final String CLASSNAME = "i-select-optiongroup";
private Panel panel;

+ 1
- 1
src/com/itmill/toolkit/terminal/gwt/client/ui/IOptionGroupBase.java View File

@@ -15,7 +15,7 @@ import com.itmill.toolkit.terminal.gwt.client.UIDL;
abstract class IOptionGroupBase extends Composite implements Paintable, ClickListener, ChangeListener, KeyboardListener {
static final String CLASSNAME_OPTION = "i-select-option";
public static final String CLASSNAME_OPTION = "i-select-option";
Client client;

+ 1
- 1
src/com/itmill/toolkit/terminal/gwt/client/ui/IPanel.java View File

@@ -9,7 +9,7 @@ import com.itmill.toolkit.terminal.gwt.client.UIDL;

public class IPanel extends FlowPanel implements Paintable {
private static final String CLASSNAME = "i-panel";
public static final String CLASSNAME = "i-panel";
Client client;

+ 1
- 1
src/com/itmill/toolkit/terminal/gwt/client/ui/ISelect.java View File

@@ -9,7 +9,7 @@ import com.itmill.toolkit.terminal.gwt.client.UIDL;

public class ISelect extends IOptionGroupBase {
private static final String CLASSNAME = "i-select";
public static final String CLASSNAME = "i-select";
private static final int VISIBLE_COUNT = 10;

+ 1
- 2
src/com/itmill/toolkit/terminal/gwt/client/ui/ITabsheet.java View File

@@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.Iterator;

import com.google.gwt.user.client.ui.DeckPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.SourcesTabEvents;
import com.google.gwt.user.client.ui.TabBar;
@@ -17,7 +16,7 @@ import com.itmill.toolkit.terminal.gwt.client.UIDL;

public class ITabsheet extends TabPanel implements Paintable {
private static final String CLASSNAME = "i-tabsheet";
public static final String CLASSNAME = "i-tabsheet";

String id;


+ 2
- 2
src/com/itmill/toolkit/terminal/gwt/client/ui/ITextField.java View File

@@ -22,12 +22,12 @@ public class ITextField extends TextBoxBase implements
/**
* The input node CSS classname.
*/
private static final String CLASSNAME = "i-textfield";
public static final String CLASSNAME = "i-textfield";
/**
* This CSS classname is added to the input node on hover.
*/
private static final String CLASSNAME_FOCUS = "i-textfield-focus";
public static final String CLASSNAME_FOCUS = "i-textfield-focus";

protected String id;


+ 1
- 1
src/com/itmill/toolkit/terminal/gwt/client/ui/ITree.java View File

@@ -13,7 +13,7 @@ import com.itmill.toolkit.terminal.gwt.client.UIDL;

public class ITree extends Tree implements Paintable {
private static final String CLASSNAME = "i-tree";
public static final String CLASSNAME = "i-tree";

Set selectedIds = new HashSet();
Client client;

+ 0
- 1
src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java View File

@@ -1,6 +1,5 @@
package com.itmill.toolkit.terminal.gwt.client.ui;

import com.google.gwt.user.client.ui.FlowPanel;
import com.itmill.toolkit.terminal.gwt.client.Client;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;

Loading…
Cancel
Save