From: Matti Tahvonen Date: Fri, 8 Jun 2007 13:02:44 +0000 (+0000) Subject: small changes X-Git-Tag: 6.7.0.beta1~6292 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3a3350043d8d917b0b9ca7185a3c0c65ede27990;p=vaadin-framework.git small changes svn changeset:1656/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/terminal/gwt/client/Client.java b/src/com/itmill/toolkit/terminal/gwt/client/Client.java index 4be56306d3..3eccc4932c 100755 --- a/src/com/itmill/toolkit/terminal/gwt/client/Client.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/Client.java @@ -103,49 +103,44 @@ public class Client implements EntryPoint { private void handleReceivedJSONMessage(Response response) { Date start = new Date(); - try{ - console.log(response.getText().substring(3) + "}"); - JSONValue json = JSONParser - .parse(response.getText().substring(3) + "}"); - // Process changes - JSONArray changes = (JSONArray) ((JSONObject) json).get("changes"); - for (int i = 0; i < changes.size(); i++) { + console.log(response.getText().substring(3) + "}"); + JSONValue json = JSONParser + .parse(response.getText().substring(3) + "}"); + // Process changes + JSONArray changes = (JSONArray) ((JSONObject) json).get("changes"); + for (int i = 0; i < changes.size(); i++) { + try { + UIDL change = new UIDL((JSONArray) changes.get(i)); + console.log("Received the following change: "); try { - UIDL change = new UIDL((JSONArray) changes.get(i)); - console.log("Received the following change: "); - try { - console.dirUIDL(change); - } catch (Exception e) { - // TODO: dir doesn't work in any browser although it should work (works in hosted mode) - // it partially did at some part but now broken. - } - UIDL uidl = change.getChildUIDL(0); - Paintable paintable = getPaintable(uidl.getId()); - if (paintable != null) - paintable.updateFromUIDL(uidl, this); - else { - if (!uidl.getTag().equals("window")) - throw new IllegalStateException("Received update for " - + uidl.getTag() - + ", but there is no such paintable (" - + uidl.getId() + ") registered yet."); - Widget window = createWidgetFromUIDL(uidl); - // We should also handle other windows - RootPanel.get("itmtk-ajax-window").add(window); - } - - } catch (Throwable e) { - e.printStackTrace(); + console.dirUIDL(change); + } catch (Exception e) { + console.log(e.getMessage()); + // TODO: dir doesn't work in any browser although it should work (works in hosted mode) + // it partially did at some part but now broken. } - + UIDL uidl = change.getChildUIDL(0); + Paintable paintable = getPaintable(uidl.getId()); + if (paintable != null) + paintable.updateFromUIDL(uidl, this); + else { + if (!uidl.getTag().equals("window")) + throw new IllegalStateException("Received update for " + + uidl.getTag() + + ", but there is no such paintable (" + + uidl.getId() + ") registered yet."); + Widget window = createWidgetFromUIDL(uidl); + // We should also handle other windows + RootPanel.get("itmtk-ajax-window").add(window); + } + + } catch (Throwable e) { + e.printStackTrace(); } - long prosessingTime = (new Date().getTime()) - start.getTime(); - console.log(" Processing time was " + String.valueOf(prosessingTime)); - } catch (Exception e) { - // TODO: remove this try catch when uidl JSON stabilizes - console.log("Error parsing JSON:"); - console.log(response.getText().substring(3) + "}"); + } + long prosessingTime = (new Date().getTime()) - start.getTime(); + console.log(" Processing time was " + String.valueOf(prosessingTime)); } @@ -216,6 +211,16 @@ public class Client implements EntryPoint { addVariableToQueue(paintableId, variableName, newValue ? "true" : "false", immediate); } + public void updateVariable(String paintableId, String variableName, Object[] values, boolean immediate) { + StringBuffer buf = new StringBuffer(); + for (int i = 0; i < values.length; i++) { + if(i > 0) + buf.append(","); + buf.append(escapeString(values[i].toString())); + } + addVariableToQueue(paintableId, variableName, buf.toString(), immediate); + } + public WidgetFactory getWidgetFactory() { return widgetFactory; @@ -225,4 +230,5 @@ public class Client implements EntryPoint { this.widgetFactory = widgetFactory; } + } diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/TkSelect.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/TkSelect.java index 91c8fdc222..95b9d7b03d 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/TkSelect.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/TkSelect.java @@ -1,38 +1,69 @@ package com.itmill.toolkit.terminal.gwt.client.ui; import java.util.Iterator; +import java.util.Vector; +import com.google.gwt.user.client.ui.ChangeListener; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.ListBox; -import com.google.gwt.user.client.ui.TreeItem; import com.google.gwt.user.client.ui.VerticalPanel; - +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 TkSelect extends Composite implements Paintable { +public class TkSelect extends Composite implements Paintable, ChangeListener { Label caption = new Label(); ListBox select = new ListBox(); + private Client client; + private String id; + private boolean immediate; + public TkSelect() { VerticalPanel panel = new VerticalPanel(); panel.add(caption); panel.add(select); + select.addChangeListener(this); initWidget(panel); } public void updateFromUIDL(UIDL uidl, Client client) { + this.client = client; + this.id = uidl.getStringAttribute("id"); + this.immediate = uidl.getBooleanAttribute("immediate"); if (uidl.hasAttribute("caption")) caption.setText(uidl.getStringAttribute("caption")); + + if(uidl.hasAttribute("selectmode")) + select.setMultipleSelect(true); + else + select.setMultipleSelect(false); UIDL options = uidl.getChildUIDL(0); + select.clear(); for (Iterator i = options.getChildIterator(); i.hasNext();) { UIDL optionUidl = (UIDL)i.next(); select.addItem(optionUidl.getStringAttribute("caption"), optionUidl.getStringAttribute("key")); + if(optionUidl.hasAttribute("selected")) + select.setItemSelected(select.getItemCount()-1, true); + } + } + + public void onChange(Widget sender) { + if(select.isMultipleSelect()) { + Vector selectedItemKeys = new Vector(); + for(int i = 0; i < select.getItemCount();i++) { + if(select.isItemSelected(i)) + selectedItemKeys.add(select.getValue(i)); + } + Object[] values = selectedItemKeys.toArray(); + client.updateVariable(id, "selected", values, immediate); + } else { + client.updateVariable(id, "selected", new String[] { "" + select.getValue(select.getSelectedIndex())}, immediate); } } }