package com.vaadin.terminal;
import java.io.Serializable;
+import java.util.Map;
/**
* This interface defines the methods for painting XML to the UIDL stream.
* @VERSION@
* @since 3.0
*/
-public interface PaintTarget extends Serializable{
+public interface PaintTarget extends Serializable {
/**
* Prints single XMLsection.
*/
public void addAttribute(String name, String value) throws PaintException;
+ /**
+ * TODO
+ *
+ * @param name
+ * @param value
+ * @throws PaintException
+ */
+ public void addAttribute(String name, Map<?, ?> value)
+ throws PaintException;
+
/**
* Adds a string type variable.
*
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
-import java.util.Vector;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.core.client.JsArray;
+import com.google.gwt.core.client.JsArrayString;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.json.client.JSONArray;
-import com.google.gwt.json.client.JSONObject;
-import com.google.gwt.json.client.JSONParser;
-import com.google.gwt.json.client.JSONString;
-import com.google.gwt.json.client.JSONValue;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.DeferredCommand;
private static Console console;
- private final Vector<String> pendingVariables = new Vector<String>();
+ private final ArrayList<String> pendingVariables = new ArrayList<String>();
private final ComponentDetailMap idToPaintableDetail = ComponentDetailMap
.create();
private final ApplicationConfiguration configuration;
/** List of pending variable change bursts that must be submitted in order */
- private final Vector<Vector<String>> pendingVariableBursts = new Vector<Vector<String>>();
+ private final ArrayList<ArrayList<String>> pendingVariableBursts = new ArrayList<ArrayList<String>>();
/** Timer for automatic refirect to SessionExpiredURL */
private Timer redirectTimer;
private void checkForPendingVariableBursts() {
cleanVariableBurst(pendingVariables);
if (pendingVariableBursts.size() > 0) {
- for (Iterator<Vector<String>> iterator = pendingVariableBursts
+ for (Iterator<ArrayList<String>> iterator = pendingVariableBursts
.iterator(); iterator.hasNext();) {
cleanVariableBurst(iterator.next());
}
- Vector<String> nextBurst = pendingVariableBursts.firstElement();
+ ArrayList<String> nextBurst = pendingVariableBursts.get(0);
pendingVariableBursts.remove(0);
buildAndSendVariableBurst(nextBurst, false);
}
*
* @param variableBurst
*/
- private void cleanVariableBurst(Vector<String> variableBurst) {
+ private void cleanVariableBurst(ArrayList<String> variableBurst) {
for (int i = 1; i < variableBurst.size(); i += 2) {
String id = variableBurst.get(i);
id = id.substring(0, id.indexOf(VAR_FIELD_SEPARATOR));
}
}
+ private static native ValueMap parseJSONResponse(String jsonText)
+ /*-{
+ return $wnd.eval('(' + jsonText + ')');
+ }-*/;
+
private void handleReceivedJSONMessage(Response response) {
final Date start = new Date();
String jsonText = response.getText();
// for(;;);[realjson]
jsonText = jsonText.substring(9, jsonText.length() - 1);
- JSONValue json;
+ ValueMap json;
try {
- json = JSONParser.parse(jsonText);
+ json = parseJSONResponse(jsonText);
} catch (final com.google.gwt.json.client.JSONException e) {
endRequest();
showCommunicationError(e.getMessage() + " - Original JSON-text:");
return;
}
// Handle redirect
- final JSONObject redirect = (JSONObject) ((JSONObject) json)
- .get("redirect");
- if (redirect != null) {
- final JSONString url = (JSONString) redirect.get("url");
- if (url != null) {
- console.log("redirecting to " + url.stringValue());
- redirect(url.stringValue());
- return;
- }
+ if (json.containsKey("redirect")) {
+ String url = json.getValueMap("redirect").getString("url");
+ console.log("redirecting to " + url);
+ redirect(url);
+ return;
}
- // Store resources
- final JSONObject resources = (JSONObject) ((JSONObject) json)
- .get("resources");
- for (final Iterator<String> i = resources.keySet().iterator(); i
- .hasNext();) {
- final String key = i.next();
- resourcesMap.put(key, ((JSONString) resources.get(key))
- .stringValue());
+ if (json.containsKey("resources")) {
+ ValueMap resources = json.getValueMap("resources");
+ JsArrayString keyArray = resources.getKeyArray();
+ int l = keyArray.length();
+ for (int i = 0; i < l; i++) {
+ String key = keyArray.get(i);
+ resourcesMap.put(key, resources.getAsString(key));
+ }
}
- // Store locale data
- if (((JSONObject) json).containsKey("locales")) {
- final JSONArray l = (JSONArray) ((JSONObject) json).get("locales");
- for (int i = 0; i < l.size(); i++) {
- LocaleService.addLocale((JSONObject) l.get(i));
- }
+ if (json.containsKey("locales")) {
+ // Store locale data
+ JsArray<ValueMap> valueMapArray = json
+ .getJSValueMapArray("locales");
+ LocaleService.addLocales(valueMapArray);
}
- JSONObject meta = null;
- if (((JSONObject) json).containsKey("meta")) {
- meta = ((JSONObject) json).get("meta").isObject();
+ ValueMap meta = null;
+ if (json.containsKey("meta")) {
+ meta = json.getValueMap("meta");
if (meta.containsKey("repaintAll")) {
view.clear();
idToPaintableDetail.clear();
}
}
if (meta.containsKey("timedRedirect")) {
- final JSONObject timedRedirect = meta.get("timedRedirect")
- .isObject();
+ final ValueMap timedRedirect = meta
+ .getValueMap("timedRedirect");
redirectTimer = new Timer() {
@Override
public void run() {
- redirect(timedRedirect.get("url").isString()
- .stringValue());
+ redirect(timedRedirect.getString("url"));
}
};
- sessionExpirationInterval = Integer.parseInt(timedRedirect.get(
- "interval").toString());
+ sessionExpirationInterval = timedRedirect.getInt("interval");
}
}
+
if (redirectTimer != null) {
redirectTimer.schedule(1000 * sessionExpirationInterval);
}
+
// Process changes
- final JSONArray changes = (JSONArray) ((JSONObject) json)
- .get("changes");
+ JsArray<ValueMap> changes = json.getJSValueMapArray("changes");
- Vector<Paintable> updatedWidgets = new Vector<Paintable>();
+ ArrayList<Paintable> updatedWidgets = new ArrayList<Paintable>();
relativeSizeChanges.clear();
componentCaptionSizeChanges.clear();
- for (int i = 0; i < changes.size(); i++) {
+ int length = changes.length();
+ for (int i = 0; i < length; i++) {
try {
- final UIDL change = new UIDL((JSONArray) changes.get(i));
+ final UIDL change = changes.get(i).cast();
try {
console.dirUIDL(change);
} catch (final Exception e) {
if (meta != null) {
if (meta.containsKey("appError")) {
- JSONObject error = meta.get("appError").isObject();
- JSONValue val = error.get("caption");
+ ValueMap error = meta.getValueMap("appError");
String html = "";
- if (val.isString() != null) {
- html += "<h1>" + val.isString().stringValue() + "</h1>";
+ if (error.containsKey("caption")) {
+ html += "<h1>" + error.getAsString("caption") + "</h1>";
}
- val = error.get("message");
- if (val.isString() != null) {
- html += "<p>" + val.isString().stringValue() + "</p>";
+ if (error.containsKey("message")) {
+ html += "<p>" + error.getAsString("message") + "</p>";
}
- val = error.get("url");
String url = null;
- if (val.isString() != null) {
- url = val.isString().stringValue();
+ if (error.containsKey("url")) {
+ url = error.getAsString("url");
}
if (html.length() != 0) {
applicationRunning = false;
}
if (validatingLayouts) {
- getConsole().printLayoutProblems(
- meta.get("invalidLayouts").isArray(), this,
+ getConsole().printLayoutProblems(meta, this,
zeroHeightComponents, zeroWidthComponents);
zeroHeightComponents = null;
zeroWidthComponents = null;
endRequest();
}
+ private UIDL getUidl(JSONArray changes, int i) {
+ return (UIDL) changes.get(i).isArray().getJavaScriptObject();
+ }
+
/**
* This method assures that all pending variable changes are sent to server.
* Method uses synchronized xmlhttprequest and does not return before the
public void sendPendingVariableChangesSync() {
if (applicationRunning) {
pendingVariableBursts.add(pendingVariables);
- Vector<String> nextBurst = pendingVariableBursts.firstElement();
+ ArrayList<String> nextBurst = pendingVariableBursts.get(0);
pendingVariableBursts.remove(0);
buildAndSendVariableBurst(nextBurst, true);
}
// skip empty queues if there are pending bursts to be sent
if (pendingVariables.size() > 0
|| pendingVariableBursts.size() == 0) {
- Vector<String> burst = (Vector<String>) pendingVariables
+ ArrayList<String> burst = (ArrayList<String>) pendingVariables
.clone();
pendingVariableBursts.add(burst);
pendingVariables.clear();
* @param forceSync
* Should we use synchronous request?
*/
- private void buildAndSendVariableBurst(Vector<String> pendingVariables,
+ private void buildAndSendVariableBurst(ArrayList<String> pendingVariables,
boolean forceSync) {
final StringBuffer req = new StringBuffer();
pendingVariables.clear();
// Append all the busts to this synchronous request
if (forceSync && !pendingVariableBursts.isEmpty()) {
- pendingVariables = pendingVariableBursts.firstElement();
+ pendingVariables = pendingVariableBursts.get(0);
pendingVariableBursts.remove(0);
req.append(VAR_BURST_SEPARATOR);
}
import java.util.Set;
-import com.google.gwt.json.client.JSONArray;
-
public interface Console {
public abstract void log(String msg);
public abstract void dirUIDL(UIDL u);
- public abstract void printLayoutProblems(JSONArray array,
+ public abstract void printLayoutProblems(ValueMap meta,
ApplicationConnection applicationConnection,
Set<Paintable> zeroHeightComponents,
Set<Paintable> zeroWidthComponents);
import java.util.Map;\r
import java.util.Set;\r
\r
-import com.google.gwt.json.client.JSONArray;\r
-import com.google.gwt.json.client.JSONBoolean;\r
-import com.google.gwt.json.client.JSONNumber;\r
-import com.google.gwt.json.client.JSONObject;\r
-import com.google.gwt.json.client.JSONString;\r
+import com.google.gwt.core.client.JsArray;\r
\r
/**\r
* Date / time etc. localisation service for all widgets. Caches all loaded\r
*/\r
public class LocaleService {\r
\r
- private static Map cache = new HashMap();\r
+ private static Map<String, ValueMap> cache = new HashMap<String, ValueMap>();\r
private static String defaultLocale;\r
\r
- public static void addLocale(JSONObject json) {\r
- final String key = ((JSONString) json.get("name")).stringValue();\r
+ public static void addLocale(ValueMap valueMap) {\r
+\r
+ final String key = valueMap.getString("name");\r
if (cache.containsKey(key)) {\r
cache.remove(key);\r
}\r
- cache.put(key, json);\r
+ cache.put(key, valueMap);\r
if (cache.size() == 1) {\r
setDefaultLocale(key);\r
}\r
public static String[] getMonthNames(String locale)\r
throws LocaleNotLoadedException {\r
if (cache.containsKey(locale)) {\r
- final JSONObject l = (JSONObject) cache.get(locale);\r
- final JSONArray mn = (JSONArray) l.get("mn");\r
- final String[] temp = new String[12];\r
- temp[0] = ((JSONString) mn.get(0)).stringValue();\r
- temp[1] = ((JSONString) mn.get(1)).stringValue();\r
- temp[2] = ((JSONString) mn.get(2)).stringValue();\r
- temp[3] = ((JSONString) mn.get(3)).stringValue();\r
- temp[4] = ((JSONString) mn.get(4)).stringValue();\r
- temp[5] = ((JSONString) mn.get(5)).stringValue();\r
- temp[6] = ((JSONString) mn.get(6)).stringValue();\r
- temp[7] = ((JSONString) mn.get(7)).stringValue();\r
- temp[8] = ((JSONString) mn.get(8)).stringValue();\r
- temp[9] = ((JSONString) mn.get(9)).stringValue();\r
- temp[10] = ((JSONString) mn.get(10)).stringValue();\r
- temp[11] = ((JSONString) mn.get(11)).stringValue();\r
- return temp;\r
+ final ValueMap l = cache.get(locale);\r
+ return l.getStringArray("mn");\r
} else {\r
throw new LocaleNotLoadedException(locale);\r
}\r
public static String[] getShortMonthNames(String locale)\r
throws LocaleNotLoadedException {\r
if (cache.containsKey(locale)) {\r
- final JSONObject l = (JSONObject) cache.get(locale);\r
- final JSONArray smn = (JSONArray) l.get("smn");\r
- final String[] temp = new String[12];\r
- temp[0] = ((JSONString) smn.get(0)).stringValue();\r
- temp[1] = ((JSONString) smn.get(1)).stringValue();\r
- temp[2] = ((JSONString) smn.get(2)).stringValue();\r
- temp[3] = ((JSONString) smn.get(3)).stringValue();\r
- temp[4] = ((JSONString) smn.get(4)).stringValue();\r
- temp[5] = ((JSONString) smn.get(5)).stringValue();\r
- temp[6] = ((JSONString) smn.get(6)).stringValue();\r
- temp[7] = ((JSONString) smn.get(7)).stringValue();\r
- temp[8] = ((JSONString) smn.get(8)).stringValue();\r
- temp[9] = ((JSONString) smn.get(9)).stringValue();\r
- temp[10] = ((JSONString) smn.get(10)).stringValue();\r
- temp[11] = ((JSONString) smn.get(11)).stringValue();\r
- return temp;\r
+ final ValueMap l = cache.get(locale);\r
+ return l.getStringArray("smn");\r
} else {\r
throw new LocaleNotLoadedException(locale);\r
}\r
public static String[] getDayNames(String locale)\r
throws LocaleNotLoadedException {\r
if (cache.containsKey(locale)) {\r
- final JSONObject l = (JSONObject) cache.get(locale);\r
- final JSONArray dn = (JSONArray) l.get("dn");\r
- final String[] temp = new String[7];\r
- temp[0] = ((JSONString) dn.get(0)).stringValue();\r
- temp[1] = ((JSONString) dn.get(1)).stringValue();\r
- temp[2] = ((JSONString) dn.get(2)).stringValue();\r
- temp[3] = ((JSONString) dn.get(3)).stringValue();\r
- temp[4] = ((JSONString) dn.get(4)).stringValue();\r
- temp[5] = ((JSONString) dn.get(5)).stringValue();\r
- temp[6] = ((JSONString) dn.get(6)).stringValue();\r
- return temp;\r
+ final ValueMap l = cache.get(locale);\r
+ return l.getStringArray("dn");\r
} else {\r
throw new LocaleNotLoadedException(locale);\r
}\r
public static String[] getShortDayNames(String locale)\r
throws LocaleNotLoadedException {\r
if (cache.containsKey(locale)) {\r
- final JSONObject l = (JSONObject) cache.get(locale);\r
- final JSONArray sdn = (JSONArray) l.get("sdn");\r
- final String[] temp = new String[7];\r
- temp[0] = ((JSONString) sdn.get(0)).stringValue();\r
- temp[1] = ((JSONString) sdn.get(1)).stringValue();\r
- temp[2] = ((JSONString) sdn.get(2)).stringValue();\r
- temp[3] = ((JSONString) sdn.get(3)).stringValue();\r
- temp[4] = ((JSONString) sdn.get(4)).stringValue();\r
- temp[5] = ((JSONString) sdn.get(5)).stringValue();\r
- temp[6] = ((JSONString) sdn.get(6)).stringValue();\r
- return temp;\r
+ final ValueMap l = cache.get(locale);\r
+ return l.getStringArray("sdn");\r
} else {\r
throw new LocaleNotLoadedException(locale);\r
}\r
public static int getFirstDayOfWeek(String locale)\r
throws LocaleNotLoadedException {\r
if (cache.containsKey(locale)) {\r
- final JSONObject l = (JSONObject) cache.get(locale);\r
- final JSONNumber fdow = (JSONNumber) l.get("fdow");\r
- return (int) fdow.getValue();\r
+ final ValueMap l = cache.get(locale);\r
+ return l.getInt("fdow");\r
} else {\r
throw new LocaleNotLoadedException(locale);\r
}\r
public static String getDateFormat(String locale)\r
throws LocaleNotLoadedException {\r
if (cache.containsKey(locale)) {\r
- final JSONObject l = (JSONObject) cache.get(locale);\r
- final JSONString df = (JSONString) l.get("df");\r
- return df.stringValue();\r
+ final ValueMap l = cache.get(locale);\r
+ return l.getString("df");\r
} else {\r
throw new LocaleNotLoadedException(locale);\r
}\r
public static boolean isTwelveHourClock(String locale)\r
throws LocaleNotLoadedException {\r
if (cache.containsKey(locale)) {\r
- final JSONObject l = (JSONObject) cache.get(locale);\r
- final JSONBoolean thc = (JSONBoolean) l.get("thc");\r
- return thc.booleanValue();\r
+ final ValueMap l = cache.get(locale);\r
+ return l.getBoolean("thc");\r
} else {\r
throw new LocaleNotLoadedException(locale);\r
}\r
public static String getClockDelimiter(String locale)\r
throws LocaleNotLoadedException {\r
if (cache.containsKey(locale)) {\r
- final JSONObject l = (JSONObject) cache.get(locale);\r
- final JSONString hmd = (JSONString) l.get("hmd");\r
- return hmd.stringValue();\r
+ final ValueMap l = cache.get(locale);\r
+ return l.getString("hmd");\r
} else {\r
throw new LocaleNotLoadedException(locale);\r
}\r
public static String[] getAmPmStrings(String locale)\r
throws LocaleNotLoadedException {\r
if (cache.containsKey(locale)) {\r
- final JSONObject l = (JSONObject) cache.get(locale);\r
- final JSONArray ampm = (JSONArray) l.get("ampm");\r
- final String[] temp = new String[2];\r
- temp[0] = ((JSONString) ampm.get(0)).stringValue();\r
- temp[1] = ((JSONString) ampm.get(1)).stringValue();\r
- return temp;\r
+ final ValueMap l = cache.get(locale);\r
+ return l.getStringArray("ampm");\r
} else {\r
throw new LocaleNotLoadedException(locale);\r
}\r
\r
}\r
\r
+ public static void addLocales(JsArray<ValueMap> valueMapArray) {\r
+ for (int i = 0; i < valueMapArray.length(); i++) {\r
+ addLocale(valueMapArray.get(i));\r
+\r
+ }\r
+\r
+ }\r
+\r
}\r
import java.util.Set;
-import com.google.gwt.json.client.JSONArray;
-
/**
* Client side console implementation for non-debug mode that discards all
* messages.
public void printObject(Object msg) {
}
- public void printLayoutProblems(JSONArray array,
+ public void printLayoutProblems(ValueMap meta,
ApplicationConnection applicationConnection,
Set<Paintable> zeroHeightComponents,
Set<Paintable> zeroWidthComponents) {
import java.util.Iterator;
import java.util.Set;
-import com.google.gwt.event.logical.shared.OpenEvent;
-import com.google.gwt.event.logical.shared.OpenHandler;
-import com.google.gwt.json.client.JSONArray;
-import com.google.gwt.json.client.JSONBoolean;
-import com.google.gwt.json.client.JSONNumber;
-import com.google.gwt.json.client.JSONObject;
-import com.google.gwt.json.client.JSONString;
-import com.google.gwt.json.client.JSONValue;
-import com.google.gwt.user.client.DOM;
-import com.google.gwt.user.client.ui.Tree;
-import com.google.gwt.user.client.ui.TreeItem;
-
-public class UIDL {
-
- JSONArray json;
-
- public UIDL(JSONArray json) {
- this.json = json;
+import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.core.client.JsArrayString;
+
+public final class UIDL extends JavaScriptObject {
+
+ protected UIDL() {
}
public String getId() {
- final JSONValue val = ((JSONObject) json.get(1)).get("id");
- if (val == null) {
- return null;
- }
- return ((JSONString) val).stringValue();
+ return getStringAttribute("id");
}
- public String getTag() {
- return ((JSONString) json.get(0)).stringValue();
- }
+ public native String getTag()
+ /*-{
+ return this[0];
+ }-*/;
+
+ private native ValueMap attr()
+ /*-{
+ return this[1];
+ }-*/;
+
+ private native ValueMap var()
+ /*-{
+ return this[1]["v"];
+ }-*/;
+
+ private native boolean hasVariables()
+ /*-{
+ return Boolean(this[1]["v"]);
+ }-*/;
public String getStringAttribute(String name) {
- final JSONValue val = ((JSONObject) json.get(1)).get(name);
- if (val == null) {
- return null;
- }
- return ((JSONString) val).stringValue();
+ return attr().getString(name);
}
public Set<String> getAttributeNames() {
- final HashSet<String> attrs = new HashSet<String>(((JSONObject) json
- .get(1)).keySet());
- attrs.remove("v");
- return attrs;
+ Set<String> keySet = attr().getKeySet();
+ keySet.remove("v");
+ return keySet;
}
- public int getIntAttribute(String name) {
- final JSONValue val = ((JSONObject) json.get(1)).get(name);
- if (val == null) {
- return 0;
+ public Set<String> getVariableNames() {
+ if (!hasVariables()) {
+ return new HashSet<String>();
+ } else {
+ Set<String> keySet = var().getKeySet();
+ return keySet;
}
- final double num = val.isNumber().doubleValue();
- return (int) num;
+ }
+
+ public int getIntAttribute(String name) {
+ return attr().getInt(name);
}
public long getLongAttribute(String name) {
- final JSONValue val = ((JSONObject) json.get(1)).get(name);
- if (val == null) {
- return 0;
- }
- final double num = val.isNumber().doubleValue();
- return (long) num;
+ return (long) attr().getRawNumber(name);
}
public float getFloatAttribute(String name) {
- final JSONValue val = ((JSONObject) json.get(1)).get(name);
- if (val == null) {
- return 0;
- }
- final double num = val.isNumber().doubleValue();
- return (float) num;
+ return (float) attr().getRawNumber(name);
}
public double getDoubleAttribute(String name) {
- final JSONValue val = ((JSONObject) json.get(1)).get(name);
- if (val == null) {
- return 0;
- }
- final double num = val.isNumber().doubleValue();
- return num;
+ return attr().getRawNumber(name);
}
public boolean getBooleanAttribute(String name) {
- final JSONValue val = ((JSONObject) json.get(1)).get(name);
- if (val == null) {
- return false;
- }
- return val.isBoolean().booleanValue();
+ return attr().getBoolean(name);
}
- public String[] getStringArrayAttribute(String name) {
- final JSONArray a = (JSONArray) ((JSONObject) json.get(1)).get(name);
- final String[] s = new String[a.size()];
- for (int i = 0; i < a.size(); i++) {
- s[i] = ((JSONString) a.get(i)).stringValue();
- }
- return s;
+ public ValueMap getMapAttribute(String name) {
+ return attr().getValueMap(name);
}
- public int[] getIntArrayAttribute(String name) {
- final JSONArray a = (JSONArray) ((JSONObject) json.get(1)).get(name);
- final int[] s = new int[a.size()];
- for (int i = 0; i < a.size(); i++) {
- s[i] = Integer.parseInt(((JSONString) a.get(i)).stringValue());
- }
- return s;
+ public String[] getStringArrayAttribute(String name) {
+ return attr().getStringArray(name);
}
- public HashSet<String> getStringArrayAttributeAsSet(String string) {
- final JSONArray a = getArrayVariable(string);
- final HashSet<String> s = new HashSet<String>();
- for (int i = 0; i < a.size(); i++) {
- s.add(((JSONString) a.get(i)).stringValue());
- }
- return s;
+ public int[] getIntArrayAttribute(final String name) {
+ return attr().getIntArray(name);
}
/**
- * Get attributes value as string whateever the type is
+ * Get attributes value as string whatever the type is
*
* @param name
* @return string presentation of attribute
*/
- private String getAttribute(String name) {
- return json.get(1).isObject().get(name).toString();
- }
-
- public boolean hasAttribute(String name) {
- return ((JSONObject) json.get(1)).get(name) != null;
- }
+ native String getAttribute(String name)
+ /*-{
+ return '' + this[1][name];
+ }-*/;
- public UIDL getChildUIDL(int i) {
+ native String getVariable(String name)
+ /*-{
+ return '' + this[1]['v'][name];
+ }-*/;
- final JSONValue c = json.get(i + 2);
- if (c == null) {
- return null;
- }
- if (c.isArray() != null) {
- return new UIDL(c.isArray());
- }
- throw new IllegalStateException("Child node " + i
- + " is not of type UIDL");
+ public boolean hasAttribute(final String name) {
+ return attr().containsKey(name);
}
- public String getChildString(int i) {
+ public native UIDL getChildUIDL(int i)
+ /*-{
+ return this[i + 2];
+ }-*/;
- final JSONValue c = json.get(i + 2);
- if (c.isString() != null) {
- return ((JSONString) c).stringValue();
- }
- throw new IllegalStateException("Child node " + i
- + " is not of type String");
- }
+ public native String getChildString(int i)
+ /*-{
+ return this[i + 2];
+ }-*/;
+
+ private native XML getChildXML(int index)
+ /*-{
+ return this[index + 2];
+ }-*/;
public Iterator<Object> getChildIterator() {
return new Iterator<Object>() {
- int index = 2;
+ int index = -1;
public void remove() {
throw new UnsupportedOperationException();
public Object next() {
- if (json.size() > index) {
- final JSONValue c = json.get(index++);
- if (c.isString() != null) {
- return c.isString().stringValue();
- } else if (c.isArray() != null) {
- return new UIDL(c.isArray());
- } else if (c.isObject() != null) {
- return new XML(c.isObject());
- } else {
- throw new IllegalStateException("Illegal child " + c
- + " in tag " + getTag() + " at index " + index);
+ if (hasNext()) {
+ int typeOfChild = typeOfChild(index++);
+ switch (typeOfChild) {
+ case CHILD_TYPE_UIDL:
+ UIDL childUIDL = getChildUIDL(index);
+ return childUIDL;
+ case CHILD_TYPE_STRING:
+ return getChildString(index);
+ case CHILD_TYPE_XML:
+ return getChildXML(index);
+ default:
+ throw new IllegalStateException(
+ "Illegal child in tag " + getTag()
+ + " at index " + index);
}
}
return null;
}
public boolean hasNext() {
- return json.size() > index;
+ int count = getChildCount();
+ return count > index + 1;
}
};
}
- public int getNumberOfChildren() {
- return json.size() - 2;
- }
+ private static final int CHILD_TYPE_STRING = 0;
+ private static final int CHILD_TYPE_UIDL = 1;
+ private static final int CHILD_TYPE_XML = 2;
- @Override
- public String toString() {
- String s = "<" + getTag();
-
- Set<String> attributeNames = getAttributeNames();
- for (String name : attributeNames) {
- s += " " + name + "=";
- final JSONValue v = ((JSONObject) json.get(1)).get(name);
- if (v.isString() != null) {
- s += v;
+ private native int typeOfChild(int index)
+ /*-{
+ var t = typeof this[index + 2];
+ if(t == "object") {
+ if(typeof(t.length) == "number") {
+ return 1;
} else {
- s += "\"" + v + "\"";
+ return 2;
}
+ } else if (t == "string") {
+ return 0;
}
+ return -1;
+ }-*/;
- s += ">\n";
-
- final Iterator<Object> i = getChildIterator();
- while (i.hasNext()) {
- final Object c = i.next();
- s += c.toString();
- }
-
- s += "</" + getTag() + ">\n";
-
- return s;
- }
-
+ /**
+ *
+ * @return
+ *
+ * @deprecated
+ */
+ @Deprecated
public String getChildrenAsXML() {
- String s = "";
- final Iterator<Object> i = getChildIterator();
- while (i.hasNext()) {
- final Object c = i.next();
- s += c.toString();
- }
- return s;
- }
-
- public VUIDLBrowser print_r() {
- return new VUIDLBrowser();
- }
-
- private class VUIDLBrowser extends Tree {
- public VUIDLBrowser() {
-
- DOM.setStyleAttribute(getElement(), "position", "");
-
- final TreeItem root = new TreeItem(getTag());
- addItem(root);
- root.addItem("");
- addOpenHandler(new OpenHandler<TreeItem>() {
- boolean isLoaded;
-
- public void onOpen(OpenEvent<TreeItem> event) {
- TreeItem item = event.getTarget();
- if (item == root && !isLoaded) {
- removeItem(root);
- addItem(dir());
- final Iterator<TreeItem> it = treeItemIterator();
- while (it.hasNext()) {
- it.next().setState(true);
- }
- isLoaded = true;
- }
- }
- });
- }
-
- @Override
- protected boolean isKeyboardNavigationEnabled(TreeItem currentItem) {
- return false;
- }
-
- }
-
- public TreeItem dir() {
-
- String nodeName = getTag();
- Set<String> attributeNames = getAttributeNames();
- for (String name : attributeNames) {
- final String value = getAttribute(name);
- nodeName += " " + name + "=" + value;
- }
- final TreeItem item = new TreeItem(nodeName);
-
- try {
- TreeItem tmp = null;
- Set<String> keySet = getVariableHash().keySet();
- for (String name : keySet) {
- String value = "";
- try {
- value = getStringVariable(name);
- } catch (final Exception e) {
- try {
- final JSONArray a = getArrayVariable(name);
- value = a.toString();
- } catch (final Exception e2) {
- try {
- final int intVal = getIntVariable(name);
- value = String.valueOf(intVal);
- } catch (final Exception e3) {
- value = "unknown";
- }
- }
- }
- if (tmp == null) {
- tmp = new TreeItem("variables");
- }
- tmp.addItem(name + "=" + value);
- }
- if (tmp != null) {
- item.addItem(tmp);
- }
- } catch (final Exception e) {
- // Ignored, no variables
- }
-
- final Iterator<Object> i = getChildIterator();
- while (i.hasNext()) {
- final Object child = i.next();
- try {
- final UIDL c = (UIDL) child;
- item.addItem(c.dir());
-
- } catch (final Exception e) {
- item.addItem(child.toString());
- }
- }
- return item;
- }
-
- private JSONObject getVariableHash() {
- final JSONObject v = (JSONObject) ((JSONObject) json.get(1)).get("v");
- if (v == null) {
- throw new IllegalArgumentException("No variables defined in tag.");
- }
- return v;
+ return toString();
}
public boolean hasVariable(String name) {
- final JSONObject variables = (JSONObject) ((JSONObject) json.get(1))
- .get("v");
- if (variables == null) {
- return false;
- }
- return variables.keySet().contains(name);
+ return var().containsKey(name);
}
public String getStringVariable(String name) {
- final JSONString t = (JSONString) getVariableHash().get(name);
- if (t == null) {
- throw new IllegalArgumentException("No such variable: " + name);
- }
- return t.stringValue();
+ return var().getString(name);
}
public int getIntVariable(String name) {
- final JSONNumber t = (JSONNumber) getVariableHash().get(name);
- if (t == null) {
- throw new IllegalArgumentException("No such variable: " + name);
- }
- return (int) t.doubleValue();
+ return var().getInt(name);
}
public long getLongVariable(String name) {
- final JSONNumber t = (JSONNumber) getVariableHash().get(name);
- if (t == null) {
- throw new IllegalArgumentException("No such variable: " + name);
- }
- return (long) t.doubleValue();
+ return (long) var().getRawNumber(name);
}
public float getFloatVariable(String name) {
- final JSONNumber t = (JSONNumber) getVariableHash().get(name);
- if (t == null) {
- throw new IllegalArgumentException("No such variable: " + name);
- }
- return (float) t.doubleValue();
+ return (float) var().getRawNumber(name);
}
public double getDoubleVariable(String name) {
- final JSONNumber t = (JSONNumber) getVariableHash().get(name);
- if (t == null) {
- throw new IllegalArgumentException("No such variable: " + name);
- }
- return t.doubleValue();
+ return var().getRawNumber(name);
}
public boolean getBooleanVariable(String name) {
- final JSONBoolean t = (JSONBoolean) getVariableHash().get(name);
- if (t == null) {
- throw new IllegalArgumentException("No such variable: " + name);
- }
- return t.booleanValue();
- }
-
- private JSONArray getArrayVariable(String name) {
- final JSONArray t = (JSONArray) getVariableHash().get(name);
- if (t == null) {
- throw new IllegalArgumentException("No such variable: " + name);
- }
- return t;
+ return var().getBoolean(name);
}
public String[] getStringArrayVariable(String name) {
- final JSONArray a = getArrayVariable(name);
- final String[] s = new String[a.size()];
- for (int i = 0; i < a.size(); i++) {
- s[i] = ((JSONString) a.get(i)).stringValue();
- }
- return s;
+ return var().getStringArray(name);
}
- public Set<String> getStringArrayVariableAsSet(String name) {
- final JSONArray a = getArrayVariable(name);
+ public Set<String> getStringArrayVariableAsSet(final String name) {
final HashSet<String> s = new HashSet<String>();
- for (int i = 0; i < a.size(); i++) {
- s.add(((JSONString) a.get(i)).stringValue());
+ JsArrayString a = var().getJSStringArray(name);
+ for (int i = 0; i < a.length(); i++) {
+ s.add(a.get(i));
}
return s;
}
public int[] getIntArrayVariable(String name) {
- final JSONArray a = getArrayVariable(name);
- final int[] s = new int[a.size()];
- for (int i = 0; i < a.size(); i++) {
- final JSONValue v = a.get(i);
- s[i] = v.isNumber() != null ? (int) v.isNumber().doubleValue()
- : Integer.parseInt(v.toString());
- }
- return s;
+ return var().getIntArray(name);
}
- public class XML {
- JSONObject x;
-
- private XML(JSONObject x) {
- this.x = x;
+ public final static class XML extends JavaScriptObject {
+ protected XML() {
}
- public String getXMLAsString() {
- final StringBuffer sb = new StringBuffer();
- Set<String> keySet = x.keySet();
- for (String tag : keySet) {
- sb.append("<");
- sb.append(tag);
- sb.append(">");
- sb.append(x.get(tag).isString().stringValue());
- sb.append("</");
- sb.append(tag);
- sb.append(">");
+ public native String getXMLAsString()
+ /*-{
+ var buf = new Array();
+ var self = this;
+ for(j in self) {
+ buf.push("<");
+ buf.push(j);
+ buf.push(">");
+ buf.push(self[j]);
+ buf.push("</");
+ buf.push("tag");
+ buf.push(">");
}
- return sb.toString();
- }
+ return buf.join();
+ }-*/;
}
- public int getChildCount() {
- return json.size() - 2;
- }
+ public native int getChildCount()
+ /*-{
+ return this.length - 2;
+ }-*/;
- public UIDL getErrors() {
- final JSONArray a = (JSONArray) ((JSONObject) json.get(1)).get("error");
- return new UIDL(a);
- }
+ public native UIDL getErrors()
+ /*-{
+ return this[1]['error'];
+ }-*/;
+
+ native boolean isMapAttribute(String name)
+ /*-{
+ return typeof this[1][name] == "object";
+ }-*/;
}
public static native int getRequiredWidth(
com.google.gwt.dom.client.Element element)
/*-{
- var width;
- if (element == null) {
- width = 0;
- } else if (element.getBoundingClientRect != null) {
+ if (element.getBoundingClientRect) {
var rect = element.getBoundingClientRect();
- width = Math.ceil(rect.right - rect.left);
+ return Math.ceil(rect.right - rect.left);
} else {
- width = element.offsetWidth;
+ return element.offsetWidth;
}
- return width;
}-*/;
public static native int getRequiredHeight(
import java.util.List;
import java.util.Set;
-import com.google.gwt.json.client.JSONArray;
-import com.google.gwt.json.client.JSONObject;
-import com.google.gwt.json.client.JSONValue;
+import com.google.gwt.core.client.JsArray;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
* .terminal.gwt.client.UIDL)
*/
public void dirUIDL(UIDL u) {
- panel.add(u.print_r());
- consoleLog(u.getChildrenAsXML());
+ if (panel.isAttached()) {
+ panel.add(new VUIDLBrowser(u));
+ }
+ consoleDir(u);
+ // consoleLog(u.getChildrenAsXML());
}
+ private static native void consoleDir(UIDL u)
+ /*-{
+ if($wnd.console && $wnd.console.log) {
+ if($wnd.console.dir) {
+ $wnd.console.dir(u);
+ } else {
+ $wnd.console.log(u);
+ }
+ }
+
+ }-*/;
+
private static native void consoleLog(String msg)
/*-{
if($wnd.console && $wnd.console.log) {
}
}-*/;
- public void printLayoutProblems(JSONArray array, ApplicationConnection ac,
+ public void printLayoutProblems(ValueMap meta, ApplicationConnection ac,
Set<Paintable> zeroHeightComponents,
Set<Paintable> zeroWidthComponents) {
- int size = array.size();
+ JsArray<ValueMap> valueMapArray = meta
+ .getJSValueMapArray("invalidLayouts");
+ int size = valueMapArray.length();
panel.add(new HTML("<div>************************</di>"
+ "<h4>Layouts analyzed on server, total top level problems: "
+ size + " </h4>"));
TreeItem root = new TreeItem("Root problems");
for (int i = 0; i < size; i++) {
- JSONObject error = array.get(i).isObject();
- printLayoutError(error, root, ac);
+ printLayoutError(valueMapArray.get(i), root, ac);
}
panel.add(tree);
tree.addItem(root);
}
}
- private void printLayoutError(JSONObject error, TreeItem parent,
+ private void printLayoutError(ValueMap valueMap, TreeItem parent,
final ApplicationConnection ac) {
- final String pid = error.get("id").isString().stringValue();
+ final String pid = valueMap.getString("id");
final Paintable paintable = ac.getPaintable(pid);
TreeItem errorNode = new TreeItem();
VerticalPanel errorDetails = new VerticalPanel();
errorDetails.add(new Label(Util.getSimpleName(paintable) + " id: "
+ pid));
- if (error.containsKey("heightMsg")) {
+ if (valueMap.containsKey("heightMsg")) {
errorDetails.add(new Label("Height problem: "
- + error.get("heightMsg")));
+ + valueMap.getString("heightMsg")));
}
- if (error.containsKey("widthMsg")) {
+ if (valueMap.containsKey("widthMsg")) {
errorDetails.add(new Label("Width problem: "
- + error.get("widthMsg")));
+ + valueMap.getString("widthMsg")));
}
final CheckBox emphasisInUi = new CheckBox("Emphasis component in UI");
emphasisInUi.addClickListener(new ClickListener() {
});
errorDetails.add(emphasisInUi);
errorNode.setWidget(errorDetails);
- if (error.containsKey("subErrors")) {
+ if (valueMap.containsKey("subErrors")) {
HTML l = new HTML(
"<em>Expand this node to show problems that may be dependent on this problem.</em>");
errorDetails.add(l);
- JSONArray array = error.get("subErrors").isArray();
- for (int i = 0; i < array.size(); i++) {
- JSONValue value = array.get(i);
- if (value != null && value.isObject() != null) {
- printLayoutError(value.isObject(), errorNode, ac);
- } else {
- System.out.print(value);
- }
+ JsArray<ValueMap> suberrors = valueMap
+ .getJSValueMapArray("subErrors");
+ for (int i = 0; i < suberrors.length(); i++) {
+ ValueMap value = suberrors.get(i);
+ printLayoutError(value, errorNode, ac);
}
}
--- /dev/null
+/**
+ *
+ */
+package com.vaadin.terminal.gwt.client;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import com.google.gwt.core.client.JsArrayString;
+import com.google.gwt.event.logical.shared.OpenEvent;
+import com.google.gwt.event.logical.shared.OpenHandler;
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.ui.Tree;
+import com.google.gwt.user.client.ui.TreeItem;
+
+public class VUIDLBrowser extends Tree {
+ /**
+ *
+ */
+ private final UIDL uidl;
+
+ public VUIDLBrowser(final UIDL uidl) {
+
+ this.uidl = uidl;
+ DOM.setStyleAttribute(getElement(), "position", "");
+
+ final UIDLItem root = new UIDLItem(this.uidl);
+ addItem(root);
+ addOpenHandler(new OpenHandler<TreeItem>() {
+ public void onOpen(OpenEvent<TreeItem> event) {
+ TreeItem item = event.getTarget();
+ if (item.getChildCount() == 1
+ && item.getChild(0).getText().equals("LOADING")) {
+ ((UIDLItem) item).dir();
+ }
+ }
+ });
+ }
+
+ @Override
+ protected boolean isKeyboardNavigationEnabled(TreeItem currentItem) {
+ return false;
+ }
+
+ class UIDLItem extends TreeItem {
+
+ private UIDL uidl;
+
+ UIDLItem(UIDL uidl) {
+ this.uidl = uidl;
+ try {
+ setText(uidl.getTag());
+ addItem("LOADING");
+ } catch (Exception e) {
+ setText(uidl.toString());
+ }
+ }
+
+ public void dir() {
+ TreeItem temp = getChild(0);
+ removeItem(temp);
+
+ String nodeName = uidl.getTag();
+ Set<String> attributeNames = uidl.getAttributeNames();
+ for (String name : attributeNames) {
+ if (uidl.isMapAttribute(name)) {
+ try {
+ ValueMap map = uidl.getMapAttribute(name);
+ JsArrayString keyArray = map.getKeyArray();
+ nodeName += " " + name + "=" + "{";
+ for (int i = 0; i < keyArray.length(); i++) {
+ nodeName += keyArray.get(i) + ":"
+ + map.getAsString(keyArray.get(i)) + ",";
+ }
+ nodeName += "}";
+ } catch (Exception e) {
+
+ }
+ } else {
+ final String value = uidl.getAttribute(name);
+ nodeName += " " + name + "=" + value;
+ }
+ }
+ setText(nodeName);
+
+ try {
+ TreeItem tmp = null;
+ Set<String> variableNames = uidl.getVariableNames();
+ for (String name : variableNames) {
+ String value = "";
+ try {
+ value = uidl.getVariable(name);
+ } catch (final Exception e) {
+ try {
+ String[] stringArrayAttribute = uidl
+ .getStringArrayAttribute(name);
+ value = stringArrayAttribute.toString();
+ } catch (final Exception e2) {
+ try {
+ final int intVal = uidl.getIntVariable(name);
+ value = String.valueOf(intVal);
+ } catch (final Exception e3) {
+ value = "unknown";
+ }
+ }
+ }
+ if (tmp == null) {
+ tmp = new TreeItem("variables");
+ }
+ tmp.addItem(name + "=" + value);
+ }
+ if (tmp != null) {
+ addItem(tmp);
+ }
+ } catch (final Exception e) {
+ // Ignored, no variables
+ }
+
+ final Iterator<Object> i = uidl.getChildIterator();
+ while (i.hasNext()) {
+ final Object child = i.next();
+ try {
+ final UIDL c = (UIDL) child;
+ final TreeItem childItem = new UIDLItem(c);
+ addItem(childItem);
+
+ } catch (final Exception e) {
+ addItem(child.toString());
+ }
+ }
+ }
+ }
+
+}
\ No newline at end of file
--- /dev/null
+/**
+ *
+ */
+package com.vaadin.terminal.gwt.client;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.core.client.JsArray;
+import com.google.gwt.core.client.JsArrayString;
+
+public final class ValueMap extends JavaScriptObject {
+ protected ValueMap() {
+ }
+
+ public native double getRawNumber(final String name)
+ /*-{
+ return this[name];
+ }-*/;
+
+ public native int getInt(final String name)
+ /*-{
+ return this[name];
+ }-*/;
+
+ public native boolean getBoolean(final String name)
+ /*-{
+ return Boolean(this[name]);
+ }-*/;
+
+ public native String getString(String name)
+ /*-{
+ return this[name];
+ }-*/;
+
+ public native JsArrayString getKeyArray()
+ /*-{
+ var a = new Array();
+ var attr = this;
+ for(var j in attr) {
+ a.push(j);
+ }
+ return a;
+ }-*/;
+
+ public Set<String> getKeySet() {
+ final HashSet<String> attrs = new HashSet<String>();
+ JsArrayString attributeNamesArray = getKeyArray();
+ for (int i = 0; i < attributeNamesArray.length(); i++) {
+ attrs.add(attributeNamesArray.get(i));
+ }
+ return attrs;
+ }
+
+ native JsArrayString getJSStringArray(String name)
+ /*-{
+ return this[name];
+ }-*/;
+
+ native JsArray<ValueMap> getJSValueMapArray(String name)
+ /*-{
+ return this[name];
+ }-*/;
+
+ public String[] getStringArray(final String name) {
+ JsArrayString stringArrayAttribute = getJSStringArray(name);
+ final String[] s = new String[stringArrayAttribute.length()];
+ for (int i = 0; i < stringArrayAttribute.length(); i++) {
+ s[i] = stringArrayAttribute.get(i);
+ }
+ return s;
+ }
+
+ public int[] getIntArray(final String name) {
+ JsArrayString stringArrayAttribute = getJSStringArray(name);
+ final int[] s = new int[stringArrayAttribute.length()];
+ for (int i = 0; i < stringArrayAttribute.length(); i++) {
+ s[i] = Integer.parseInt(stringArrayAttribute.get(i));
+ }
+ return s;
+ }
+
+ public native boolean containsKey(final String name)
+ /*-{
+ return name in this;
+ }-*/;
+
+ public native ValueMap getValueMap(String name)
+ /*-{
+ return this[name];
+ }-*/;
+
+ native String getAsString(String name)
+ /*-{
+ return '' + this[name];
+ }-*/;
+
+}
\ No newline at end of file
package com.vaadin.terminal.gwt.client.ui;
+import java.util.ArrayList;
import java.util.Iterator;
-import java.util.Vector;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.ListBox;
@Override
protected Object[] getSelectedItems() {
- final Vector selectedItemKeys = new Vector();
+ final ArrayList selectedItemKeys = new ArrayList();
for (int i = 0; i < select.getItemCount(); i++) {
if (select.isItemSelected(i)) {
selectedItemKeys.add(select.getValue(i));
package com.vaadin.terminal.gwt.client.ui;
+import java.util.ArrayList;
import java.util.Iterator;
-import java.util.Vector;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.BrowserInfo;
@Override
protected Object[] getSelectedItems() {
- final Vector selectedItemKeys = new Vector();
+ final ArrayList selectedItemKeys = new ArrayList();
for (int i = 0; i < select.getItemCount(); i++) {
if (select.isItemSelected(i)) {
selectedItemKeys.add(select.getValue(i));
import java.util.Iterator;\r
import java.util.Set;\r
\r
+import com.google.gwt.core.client.JsArrayString;\r
import com.google.gwt.user.client.ui.Widget;\r
import com.vaadin.terminal.gwt.client.ApplicationConnection;\r
import com.vaadin.terminal.gwt.client.BrowserInfo;\r
import com.vaadin.terminal.gwt.client.RenderSpace;\r
import com.vaadin.terminal.gwt.client.UIDL;\r
import com.vaadin.terminal.gwt.client.Util;\r
+import com.vaadin.terminal.gwt.client.ValueMap;\r
import com.vaadin.terminal.gwt.client.RenderInformation.FloatSize;\r
import com.vaadin.terminal.gwt.client.RenderInformation.Size;\r
import com.vaadin.terminal.gwt.client.ui.layout.CellBasedLayout;\r
\r
private boolean sizeHasChangedDuringRendering = false;\r
\r
+ private ValueMap expandRatios;\r
+\r
+ private double expandRatioSum;\r
+\r
+ private double defaultExpandRatio;\r
+\r
+ private ValueMap alignments;\r
+\r
public VOrderedLayout() {\r
this(CLASSNAME, ORIENTATION_VERTICAL);\r
allowOrientationUpdate = true;\r
}\r
\r
if (remaining > 0) {\r
+\r
// Some left-over pixels due to rounding errors\r
\r
// Add one pixel to each container until there are no pixels left\r
+ // FIXME extra pixels should be divided among expanded widgets if\r
+ // such a widgets exists\r
\r
Iterator<Widget> widgetIterator = iterator();\r
while (widgetIterator.hasNext() && remaining-- > 0) {\r
ArrayList<Widget> renderedWidgets) {\r
\r
/*\r
- * UIDL contains component alignments as a comma separated list.\r
- * \r
- * See com.vaadin.terminal.gwt.client.ui.AlignmentInfo.java for possible\r
- * values.\r
*/\r
- final int[] alignments = uidl.getIntArrayAttribute("alignments");\r
+ alignments = uidl.getMapAttribute("alignments");\r
\r
/*\r
- * UIDL contains normalized expand ratios as a comma separated list.\r
+ * UIDL contains a map of paintable ids to expand ratios\r
*/\r
- final int[] expandRatios = uidl.getIntArrayAttribute("expandRatios");\r
+\r
+ expandRatios = uidl.getMapAttribute("expandRatios");\r
+ expandRatioSum = -1.0;\r
\r
for (int i = 0; i < renderedWidgets.size(); i++) {\r
Widget widget = renderedWidgets.get(i);\r
+ String pid = client.getPid(widget.getElement());\r
\r
ChildComponentContainer container = getComponentContainer(widget);\r
\r
// Calculate alignment info\r
- container.setAlignment(new AlignmentInfo(alignments[i]));\r
+ container.setAlignment(getAlignment(pid));\r
\r
// Update expand ratio\r
- container.setExpandRatio(expandRatios[i]);\r
+ container.setNormalizedExpandRatio(getExpandRatio(pid));\r
+ }\r
+ }\r
+\r
+ private AlignmentInfo getAlignment(String pid) {\r
+ if (alignments.containsKey(pid)) {\r
+ return new AlignmentInfo(alignments.getInt(pid));\r
+ } else {\r
+ return AlignmentInfo.TOP_LEFT;\r
+ }\r
+ }\r
+\r
+ private double getExpandRatio(String pid) {\r
+ if (expandRatioSum < 0) {\r
+ expandRatioSum = 0;\r
+ JsArrayString keyArray = expandRatios.getKeyArray();\r
+ int length = keyArray.length();\r
+ for (int i = 0; i < length; i++) {\r
+ expandRatioSum += expandRatios.getRawNumber(keyArray.get(i));\r
+ }\r
+ if (expandRatioSum == 0) {\r
+ // by default split equally among components\r
+ defaultExpandRatio = 1.0 / widgetToComponentContainer.size();\r
+ } else {\r
+ defaultExpandRatio = 0;\r
+ }\r
+ }\r
+ if (expandRatios.containsKey(pid)) {\r
+ return expandRatios.getRawNumber(pid) / expandRatioSum;\r
+ } else {\r
+ return defaultExpandRatio;\r
}\r
}\r
\r
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
-import java.util.Vector;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.NodeList;
private static final int WRAPPER_WIDTH = 9000;
- Vector<Widget> visibleCells = new Vector<Widget>();
+ ArrayList<Widget> visibleCells = new ArrayList<Widget>();
HashMap<String, HeaderCell> availableCells = new HashMap<String, HeaderCell>();
// insert to right slot
DOM.insertChild(tr, cell.getElement(), index);
adopt(cell);
- visibleCells.insertElementAt(cell, index);
-
+ visibleCells.add(index, cell);
} else if (index == visibleCells.size()) {
// simply append
DOM.appendChild(tr, cell.getElement());
DOM.removeChild(tr, cell);
DOM.insertChild(tr, cell, newIndex);
- visibleCells.insertElementAt(hCell, newIndex);
+ visibleCells.add(newIndex, hCell);
}
public Iterator<Widget> iterator() {
private int rowHeight = -1;
- private final List<Widget> renderedRows = new Vector<Widget>();
+ private final List<Widget> renderedRows = new ArrayList<Widget>();
/**
* Due some optimizations row height measuring is deferred and initial
public class VScrollTableRow extends Panel implements ActionOwner,
Container {
- Vector<Widget> childWidgets = new Vector<Widget>();
+ ArrayList<Widget> childWidgets = new ArrayList<Widget>();
private boolean selected = false;
private final int rowKey;
private List<UIDL> pendingComponentPaints;
oldComponent.removeFromParent();
parentElement.appendChild(newComponent.getElement());
- childWidgets.insertElementAt(newComponent, index);
+ childWidgets.add(index, newComponent);
adopt(newComponent);
}
package com.vaadin.terminal.gwt.client.ui;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
-import java.util.Vector;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
private int selectMode = Table.SELECT_MODE_NONE;
- private final Vector selectedRowKeys = new Vector();
+ private final ArrayList selectedRowKeys = new ArrayList();
private int totalRows;
\r
package com.vaadin.terminal.gwt.client.ui;\r
\r
+import java.util.ArrayList;\r
import java.util.Iterator;\r
-import java.util.Vector;\r
\r
import com.google.gwt.user.client.DOM;\r
import com.google.gwt.user.client.ui.FlowPanel;\r
\r
@Override\r
protected Object[] getSelectedItems() {\r
- final Vector selectedItemKeys = new Vector();\r
+ final ArrayList selectedItemKeys = new ArrayList();\r
for (int i = 0; i < selections.getItemCount(); i++) {\r
selectedItemKeys.add(selections.getValue(i));\r
}\r
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.Paintable;
import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.VUIDLBrowser;
public class VUnknownComponent extends Composite implements Paintable {
com.google.gwt.user.client.ui.Label caption = new com.google.gwt.user.client.ui.Label();;
- Tree uidlTree = new Tree();
+ Tree uidlTree;
+ private VerticalPanel panel;
public VUnknownComponent() {
- final VerticalPanel panel = new VerticalPanel();
+ panel = new VerticalPanel();
panel.add(caption);
- panel.add(uidlTree);
initWidget(panel);
setStyleName("vaadin-unknown");
caption.setStyleName("vaadin-unknown-caption");
return;
}
setCaption("Client faced an unknown component type. Unrendered UIDL:");
- uidlTree.clear();
- uidlTree.addItem(uidl.dir());
+ if (uidlTree != null) {
+ uidlTree.removeFromParent();
+ }
+
+ uidlTree = new VUIDLBrowser(uidl);
+ panel.add(uidlTree);
}
public void setCaption(String c) {
package com.vaadin.terminal.gwt.client.ui;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.Set;
-import java.util.Vector;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DOM;
private static final int MIN_WIDTH = 150;
- private static Vector<VWindow> windowOrder = new Vector<VWindow>();
+ private static ArrayList<VWindow> windowOrder = new ArrayList<VWindow>();
public static final String CLASSNAME = "v-window";
* @return
*/
private boolean isActive() {
- return windowOrder.lastElement().equals(this);
+ return windowOrder.get(windowOrder.size() - 1).equals(this);
}
public void setWindowOrder(int order) {
private int captionHeight = 0;
/**
+ *
* Padding added to the container when it is larger than the component.
*/
private Size containerExpansion = new Size(0, 0);
- private float expandRatio;
+ private double expandRatio;
private int containerMarginLeft = 0;
private int containerMarginTop = 0;
public void setAlignment(AlignmentInfo alignmentInfo) {
alignment = alignmentInfo;
-
}
public Size getWidgetSize() {
}
- public void setExpandRatio(int expandRatio) {
- this.expandRatio = (expandRatio / 1000.0f);
+ /**
+ * Sets the normalized expand ratio of this slot. The fraction that this
+ * slot will use of "excess space".
+ *
+ * @param expandRatio
+ */
+ public void setNormalizedExpandRatio(double expandRatio) {
+ this.expandRatio = expandRatio;
}
public int expand(int orientation, int spaceForExpansion) {
- int expansionAmount = (int) ((double) spaceForExpansion * expandRatio);
+ int expansionAmount = (int) (spaceForExpansion * expandRatio);
if (orientation == CellBasedLayout.ORIENTATION_HORIZONTAL) {
// HORIZONTAL
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.Map;
import java.util.Set;
import java.util.Stack;
import java.util.Vector;
import com.vaadin.terminal.Resource;
import com.vaadin.terminal.ThemeResource;
import com.vaadin.terminal.VariableOwner;
+import com.vaadin.ui.Alignment;
import com.vaadin.ui.Component;
/**
}
+ public void addAttribute(String name, Map<?, ?> value)
+ throws PaintException {
+
+ StringBuilder sb = new StringBuilder();
+ sb.append("\"");
+ sb.append(name);
+ sb.append("\": ");
+ sb.append("{");
+ for (Iterator<?> it = value.keySet().iterator(); it.hasNext();) {
+ Object key = it.next();
+ Object mapValue = value.get(key);
+ sb.append("\"");
+ if (key instanceof Paintable) {
+ Paintable paintable = (Paintable) key;
+ sb.append(getPaintIdentifier(paintable));
+ } else {
+ sb.append(escapeJSON(key.toString()));
+ }
+ sb.append("\":");
+ if (mapValue instanceof Float || mapValue instanceof Integer
+ || mapValue instanceof Double
+ || mapValue instanceof Boolean
+ || mapValue instanceof Alignment) {
+ sb.append(mapValue);
+ } else {
+ sb.append("\"");
+ sb.append(escapeJSON(mapValue.toString()));
+ sb.append("\"");
+ }
+ if (it.hasNext()) {
+ sb.append(",");
+ }
+ }
+ sb.append("}");
+
+ tag.addAttribute(sb.toString());
+ }
+
public void addAttribute(String name, Object[] values) {
// In case of null data output nothing:
if ((values == null) || (name == null)) {
* @throws PaintException
* if the paint operation failed.
*
- * @see com.vaadin.terminal.PaintTarget#addXMLSection(String,
- * String, String)
+ * @see com.vaadin.terminal.PaintTarget#addXMLSection(String, String,
+ * String)
*/
public void addXMLSection(String sectionTagName, String sectionData,
String namespace) throws PaintException {
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.terminal.PaintTarget#startTag(com.vaadin.terminal
+ * @see com.vaadin.terminal.PaintTarget#startTag(com.vaadin.terminal
* .Paintable, java.lang.String)
*/
public boolean startTag(Paintable paintable, String tagName)
public void paintReference(Paintable paintable, String referenceName)
throws PaintException {
+ final String id = getPaintIdentifier(paintable);
+ addAttribute(referenceName, id);
+ }
+
+ public String getPaintIdentifier(Paintable paintable) throws PaintException {
if (!manager.hasPaintableId(paintable)) {
if (identifiersCreatedDueRefPaint == null) {
identifiersCreatedDueRefPaint = new HashSet<Paintable>();
}
identifiersCreatedDueRefPaint.add(paintable);
}
- final String id = manager.getPaintableId(paintable);
- addAttribute(referenceName, id);
+ return manager.getPaintableId(paintable);
}
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.terminal.PaintTarget#addCharacterData(java.lang.String
- * )
+ * @see com.vaadin.terminal.PaintTarget#addCharacterData(java.lang.String )
*/
public void addCharacterData(String text) throws PaintException {
if (text != null) {
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
-import java.util.Map.Entry;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
target.addAttribute("spacing", spacing);
}
- final String[] alignmentsArray = new String[components.size()];
- final Integer[] expandRatioArray = new Integer[components.size()];
- float sum = getExpandRatioSum();
- boolean equallyDivided = false;
- int realSum = 0;
- if (sum == 0 && components.size() > 0) {
- // no component has been expanded, all components have same expand
- // rate
- equallyDivided = true;
- float equalSize = 1 / (float) components.size();
- int myRatio = Math.round(equalSize * 1000);
- for (int i = 0; i < expandRatioArray.length; i++) {
- expandRatioArray[i] = myRatio;
- }
- realSum = myRatio * components.size();
- }
-
// Adds all items in all the locations
- int index = 0;
- for (final Iterator i = components.iterator(); i.hasNext();) {
- final Component c = (Component) i.next();
- if (c != null) {
- // Paint child component UIDL
- c.paint(target);
- alignmentsArray[index] = String
- .valueOf(getComponentAlignment(c).getBitMask());
- if (!equallyDivided) {
- int myRatio = Math.round((getExpandRatio(c) / sum) * 1000);
- expandRatioArray[index] = myRatio;
- realSum += myRatio;
- }
- index++;
- }
- }
-
- // correct possible rounding error
- if (expandRatioArray.length > 0) {
- expandRatioArray[0] -= realSum - 1000;
+ for (Component c : components) {
+ // Paint child component UIDL
+ c.paint(target);
}
// Add child component alignment info to layout tag
- target.addAttribute("alignments", alignmentsArray);
- target.addAttribute("expandRatios", expandRatioArray);
- }
-
- private float getExpandRatioSum() {
- float sum = 0;
- for (Iterator<Entry<Component, Float>> iterator = componentToExpandRatio
- .entrySet().iterator(); iterator.hasNext();) {
- sum += iterator.next().getValue();
- }
- return sum;
+ target.addAttribute("alignments", componentToAlignment);
+ target.addAttribute("expandRatios", componentToExpandRatio);
}
/* Documented in superclass */