aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/terminal/gwt/client
diff options
context:
space:
mode:
authorMatti Tahvonen <matti.tahvonen@itmill.com>2010-06-04 13:22:00 +0000
committerMatti Tahvonen <matti.tahvonen@itmill.com>2010-06-04 13:22:00 +0000
commitc64015c8904ab7f66521887db874ac798c49e42b (patch)
treea3ea1c4136831bebe5a78e68e90164d698c63dc4 /src/com/vaadin/terminal/gwt/client
parent2752d636743b1091b6c52baf26d39ce5c7d50964 (diff)
downloadvaadin-framework-c64015c8904ab7f66521887db874ac798c49e42b.tar.gz
vaadin-framework-c64015c8904ab7f66521887db874ac798c49e42b.zip
initial implementation of code splitting #4408
svn changeset:13561/svn branch:6.4
Diffstat (limited to 'src/com/vaadin/terminal/gwt/client')
-rw-r--r--src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java42
-rwxr-xr-xsrc/com/vaadin/terminal/gwt/client/ApplicationConnection.java290
-rw-r--r--src/com/vaadin/terminal/gwt/client/DefaultWidgetSet.java10
-rw-r--r--src/com/vaadin/terminal/gwt/client/WidgetMap.java4
-rw-r--r--src/com/vaadin/terminal/gwt/client/WidgetSet.java4
5 files changed, 203 insertions, 147 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java b/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java
index bf66921235..f54032cfdb 100644
--- a/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java
+++ b/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java
@@ -6,11 +6,12 @@ package com.vaadin.terminal.gwt.client;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
-import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArrayString;
+import com.google.gwt.user.client.Command;
import com.vaadin.terminal.gwt.client.ui.VUnknownComponent;
public class ApplicationConfiguration {
@@ -37,6 +38,11 @@ public class ApplicationConfiguration {
private String windowId;
+ // TODO consider to make this hashmap per application
+ LinkedList<Command> callbacks = new LinkedList<Command>();
+
+ private int widgetsLoading;
+
private static ArrayList<ApplicationConnection> unstartedApplications = new ArrayList<ApplicationConnection>();
private static ArrayList<ApplicationConnection> runningApplications = new ArrayList<ApplicationConnection>();
@@ -146,11 +152,6 @@ public class ApplicationConfiguration {
* the widgetset that is running the apps
*/
public static void initConfigurations(WidgetSet widgetset) {
- String wsname = widgetset.getClass().getName();
- String module = GWT.getModuleName();
- int lastdot = module.lastIndexOf(".");
- String base = module.substring(0, lastdot);
- String simpleName = module.substring(lastdot + 1);
if (initedWidgetSet != null) {
// Multiple widgetsets inited; can happen with custom WS + entry
@@ -241,7 +242,7 @@ public class ApplicationConfiguration {
for (int i = 0; i < keyArray.length(); i++) {
String key = keyArray.get(i).intern();
int value = valueMap.getInt(key);
- classes[value] = widgetSet.getImplementationByClassName(key);
+ classes[value] = widgetSet.getImplementationByClassName(key, this);
if (classes[value] == VUnknownComponent.class) {
if (unknownComponents == null) {
unknownComponents = new HashMap<String, String>();
@@ -267,4 +268,31 @@ public class ApplicationConfiguration {
}
return null;
}
+
+ /**
+ *
+ * @param c
+ */
+ void runWhenWidgetsLoaded(Command c) {
+ if (widgetsLoading == 0) {
+ c.execute();
+ } else {
+ callbacks.add(c);
+ }
+ }
+
+ void widgetLoadStart() {
+ widgetsLoading++;
+ }
+
+ void widgetLoaded() {
+ widgetsLoading--;
+ if (widgetsLoading == 0 && !callbacks.isEmpty()) {
+ for (Command cmd : callbacks) {
+ cmd.execute();
+ }
+ callbacks.clear();
+ }
+
+ }
}
diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
index 9d649bcd99..449971ac39 100755
--- a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
+++ b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
@@ -670,10 +670,10 @@ public class ApplicationConnection {
private void handleReceivedJSONMessage(Response response) {
final Date start = new Date();
- String jsonText = response.getText();
// for(;;);[realjson]
- jsonText = jsonText.substring(9, jsonText.length() - 1);
- ValueMap json;
+ final String jsonText = response.getText().substring(9,
+ response.getText().length() - 1);
+ final ValueMap json;
try {
json = parseJSONResponse(jsonText);
} catch (final Exception e) {
@@ -714,159 +714,181 @@ public class ApplicationConnection {
json.getValueMap("typeMappings"), widgetSet);
}
- if (json.containsKey("locales")) {
- // Store locale data
- JsArray<ValueMap> valueMapArray = json
- .getJSValueMapArray("locales");
- LocaleService.addLocales(valueMapArray);
- }
+ Command c = new Command() {
+ public void execute() {
- ValueMap meta = null;
- if (json.containsKey("meta")) {
- meta = json.getValueMap("meta");
- if (meta.containsKey("repaintAll")) {
- view.clear();
- idToPaintableDetail.clear();
- if (meta.containsKey("invalidLayouts")) {
- validatingLayouts = true;
- zeroWidthComponents = new HashSet<Paintable>();
- zeroHeightComponents = new HashSet<Paintable>();
+ if (json.containsKey("locales")) {
+ // Store locale data
+ JsArray<ValueMap> valueMapArray = json
+ .getJSValueMapArray("locales");
+ LocaleService.addLocales(valueMapArray);
}
- }
- if (meta.containsKey("timedRedirect")) {
- final ValueMap timedRedirect = meta
- .getValueMap("timedRedirect");
- redirectTimer = new Timer() {
- @Override
- public void run() {
- redirect(timedRedirect.getString("url"));
+
+ ValueMap meta = null;
+ if (json.containsKey("meta")) {
+ meta = json.getValueMap("meta");
+ if (meta.containsKey("repaintAll")) {
+ view.clear();
+ idToPaintableDetail.clear();
+ if (meta.containsKey("invalidLayouts")) {
+ validatingLayouts = true;
+ zeroWidthComponents = new HashSet<Paintable>();
+ zeroHeightComponents = new HashSet<Paintable>();
+ }
}
- };
- sessionExpirationInterval = timedRedirect.getInt("interval");
- }
- }
+ if (meta.containsKey("timedRedirect")) {
+ final ValueMap timedRedirect = meta
+ .getValueMap("timedRedirect");
+ redirectTimer = new Timer() {
+ @Override
+ public void run() {
+ redirect(timedRedirect.getString("url"));
+ }
+ };
+ sessionExpirationInterval = timedRedirect
+ .getInt("interval");
+ }
+ }
- if (redirectTimer != null) {
- redirectTimer.schedule(1000 * sessionExpirationInterval);
- }
+ if (redirectTimer != null) {
+ redirectTimer.schedule(1000 * sessionExpirationInterval);
+ }
- // Process changes
- JsArray<ValueMap> changes = json.getJSValueMapArray("changes");
+ // Process changes
+ JsArray<ValueMap> changes = json.getJSValueMapArray("changes");
- ArrayList<Paintable> updatedWidgets = new ArrayList<Paintable>();
- relativeSizeChanges.clear();
- componentCaptionSizeChanges.clear();
+ ArrayList<Paintable> updatedWidgets = new ArrayList<Paintable>();
+ relativeSizeChanges.clear();
+ componentCaptionSizeChanges.clear();
- int length = changes.length();
- for (int i = 0; i < length; i++) {
- try {
- final UIDL change = changes.get(i).cast();
- try {
- console.dirUIDL(change);
- } catch (final Exception e) {
- ClientExceptionHandler.displayError(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.
- }
- final UIDL uidl = change.getChildUIDL(0);
- // TODO optimize
- final Paintable paintable = getPaintable(uidl.getId());
- if (paintable != null) {
- paintable.updateFromUIDL(uidl, this);
- // paintable may have changed during render to another
- // implementation, use the new one for updated widgets map
- updatedWidgets.add(idToPaintableDetail.get(uidl.getId())
- .getComponent());
- } else {
- if (!uidl.getTag().equals(
- configuration.getEncodedWindowTag())) {
- ClientExceptionHandler
- .displayError("Received update for "
- + uidl.getTag()
- + ", but there is no such paintable ("
- + uidl.getId() + ") rendered.");
- } else {
- view.updateFromUIDL(uidl, this);
+ int length = changes.length();
+ for (int i = 0; i < length; i++) {
+ try {
+ final UIDL change = changes.get(i).cast();
+ try {
+ console.dirUIDL(change);
+ } catch (final Exception e) {
+ ClientExceptionHandler.displayError(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.
+ }
+ final UIDL uidl = change.getChildUIDL(0);
+ // TODO optimize
+ final Paintable paintable = getPaintable(uidl.getId());
+ if (paintable != null) {
+ paintable.updateFromUIDL(uidl,
+ ApplicationConnection.this);
+ // paintable may have changed during render to
+ // another
+ // implementation, use the new one for updated
+ // widgets map
+ updatedWidgets.add(idToPaintableDetail.get(
+ uidl.getId()).getComponent());
+ } else {
+ if (!uidl.getTag().equals(
+ configuration.getEncodedWindowTag())) {
+ ClientExceptionHandler
+ .displayError("Received update for "
+ + uidl.getTag()
+ + ", but there is no such paintable ("
+ + uidl.getId() + ") rendered.");
+ } else {
+ view.updateFromUIDL(uidl,
+ ApplicationConnection.this);
+ }
+ }
+ } catch (final Throwable e) {
+ ClientExceptionHandler.displayError(e);
}
}
- } catch (final Throwable e) {
- ClientExceptionHandler.displayError(e);
- }
- }
- if (json.containsKey("dd")) {
- // response contains data for drag and drop service
- VDragAndDropManager.get().handleServerResponse(
- json.getValueMap("dd"));
- }
+ if (json.containsKey("dd")) {
+ // response contains data for drag and drop service
+ VDragAndDropManager.get().handleServerResponse(
+ json.getValueMap("dd"));
+ }
- // Check which widgets' size has been updated
- Set<Paintable> sizeUpdatedWidgets = new HashSet<Paintable>();
+ // Check which widgets' size has been updated
+ Set<Paintable> sizeUpdatedWidgets = new HashSet<Paintable>();
- updatedWidgets.addAll(relativeSizeChanges);
- sizeUpdatedWidgets.addAll(componentCaptionSizeChanges);
+ updatedWidgets.addAll(relativeSizeChanges);
+ sizeUpdatedWidgets.addAll(componentCaptionSizeChanges);
- for (Paintable paintable : updatedWidgets) {
- ComponentDetail detail = idToPaintableDetail.get(getPid(paintable));
- Widget widget = (Widget) paintable;
- Size oldSize = detail.getOffsetSize();
- Size newSize = new Size(widget.getOffsetWidth(), widget
- .getOffsetHeight());
+ for (Paintable paintable : updatedWidgets) {
+ ComponentDetail detail = idToPaintableDetail
+ .get(getPid(paintable));
+ Widget widget = (Widget) paintable;
+ Size oldSize = detail.getOffsetSize();
+ Size newSize = new Size(widget.getOffsetWidth(), widget
+ .getOffsetHeight());
- if (oldSize == null || !oldSize.equals(newSize)) {
- sizeUpdatedWidgets.add(paintable);
- detail.setOffsetSize(newSize);
- }
+ if (oldSize == null || !oldSize.equals(newSize)) {
+ sizeUpdatedWidgets.add(paintable);
+ detail.setOffsetSize(newSize);
+ }
- }
+ }
- Util.componentSizeUpdated(sizeUpdatedWidgets);
+ Util.componentSizeUpdated(sizeUpdatedWidgets);
- if (meta != null) {
- if (meta.containsKey("appError")) {
- ValueMap error = meta.getValueMap("appError");
- String html = "";
- if (error.containsKey("caption")
- && error.getString("caption") != null) {
- html += "<h1>" + error.getAsString("caption") + "</h1>";
- }
- if (error.containsKey("message")
- && error.getString("message") != null) {
- html += "<p>" + error.getAsString("message") + "</p>";
- }
- String url = null;
- if (error.containsKey("url")) {
- url = error.getString("url");
- }
+ if (meta != null) {
+ if (meta.containsKey("appError")) {
+ ValueMap error = meta.getValueMap("appError");
+ String html = "";
+ if (error.containsKey("caption")
+ && error.getString("caption") != null) {
+ html += "<h1>" + error.getAsString("caption")
+ + "</h1>";
+ }
+ if (error.containsKey("message")
+ && error.getString("message") != null) {
+ html += "<p>" + error.getAsString("message")
+ + "</p>";
+ }
+ String url = null;
+ if (error.containsKey("url")) {
+ url = error.getString("url");
+ }
- if (html.length() != 0) {
- /* 45 min */
- VNotification n = new VNotification(1000 * 60 * 45);
- n.addEventListener(new NotificationRedirect(url));
- n.show(html, VNotification.CENTERED_TOP,
- VNotification.STYLE_SYSTEM);
- } else {
- redirect(url);
+ if (html.length() != 0) {
+ /* 45 min */
+ VNotification n = new VNotification(1000 * 60 * 45);
+ n.addEventListener(new NotificationRedirect(url));
+ n.show(html, VNotification.CENTERED_TOP,
+ VNotification.STYLE_SYSTEM);
+ } else {
+ redirect(url);
+ }
+ applicationRunning = false;
+ }
+ if (validatingLayouts) {
+ getConsole().printLayoutProblems(meta,
+ ApplicationConnection.this,
+ zeroHeightComponents, zeroWidthComponents);
+ zeroHeightComponents = null;
+ zeroWidthComponents = null;
+ validatingLayouts = false;
+
+ }
}
- applicationRunning = false;
- }
- if (validatingLayouts) {
- getConsole().printLayoutProblems(meta, this,
- zeroHeightComponents, zeroWidthComponents);
- zeroHeightComponents = null;
- zeroWidthComponents = null;
- validatingLayouts = false;
- }
- }
+ // TODO build profiling for widget impl loading time
+
+ final long prosessingTime = (new Date().getTime())
+ - start.getTime();
+ console.log(" Processing time was "
+ + String.valueOf(prosessingTime) + "ms for "
+ + jsonText.length() + " characters of JSON");
+ console.log("Referenced paintables: "
+ + idToPaintableDetail.size());
- final long prosessingTime = (new Date().getTime()) - start.getTime();
- console.log(" Processing time was " + String.valueOf(prosessingTime)
- + "ms for " + jsonText.length() + " characters of JSON");
- console.log("Referenced paintables: " + idToPaintableDetail.size());
+ endRequest();
- endRequest();
+ }
+ };
+ configuration.runWhenWidgetsLoaded(c);
}
/**
diff --git a/src/com/vaadin/terminal/gwt/client/DefaultWidgetSet.java b/src/com/vaadin/terminal/gwt/client/DefaultWidgetSet.java
index c34e5d8bb3..ae6001c1aa 100644
--- a/src/com/vaadin/terminal/gwt/client/DefaultWidgetSet.java
+++ b/src/com/vaadin/terminal/gwt/client/DefaultWidgetSet.java
@@ -9,7 +9,6 @@ import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ui.VButton;
import com.vaadin.terminal.gwt.client.ui.VCheckBox;
import com.vaadin.terminal.gwt.client.ui.VDateFieldCalendar;
-import com.vaadin.terminal.gwt.client.ui.VDragAndDropWrapper;
import com.vaadin.terminal.gwt.client.ui.VFilterSelect;
import com.vaadin.terminal.gwt.client.ui.VListSelect;
import com.vaadin.terminal.gwt.client.ui.VNativeSelect;
@@ -69,7 +68,7 @@ public class DefaultWidgetSet implements WidgetSet {
Class<? extends Paintable> widgetClass = conf
.getWidgetClassByEncodedTag(tag);
- // TODO add our quirks
+ // add our historical quirks
if (widgetClass == VButton.class && uidl.hasAttribute("type")) {
return VCheckBox.class;
@@ -119,10 +118,13 @@ public class DefaultWidgetSet implements WidgetSet {
}
public Class<? extends Paintable> getImplementationByClassName(
- String fullyqualifiedName) {
+ String fullyqualifiedName,
+ ApplicationConfiguration applicationConfiguration) {
Class<? extends Paintable> implementationByServerSideClassName = map
- .getImplementationByServerSideClassName(fullyqualifiedName);
+ .getImplementationByServerSideClassName(fullyqualifiedName,
+ applicationConfiguration);
return implementationByServerSideClassName;
}
+
}
diff --git a/src/com/vaadin/terminal/gwt/client/WidgetMap.java b/src/com/vaadin/terminal/gwt/client/WidgetMap.java
index d9df64b8d0..c6e50b0f51 100644
--- a/src/com/vaadin/terminal/gwt/client/WidgetMap.java
+++ b/src/com/vaadin/terminal/gwt/client/WidgetMap.java
@@ -12,6 +12,7 @@ import com.vaadin.terminal.gwt.client.ui.VWindow;
public abstract class WidgetMap {
public Paintable instantiate(Class<? extends Paintable> classType) {
+
/*
* Yes, this (including the generated) may look very odd code, but due
* the nature of GWT, we cannot do this with reflect. Luckily this is
@@ -36,6 +37,7 @@ public abstract class WidgetMap {
}
public abstract Class<? extends Paintable> getImplementationByServerSideClassName(
- String fullyqualifiedName);
+ String fullyqualifiedName,
+ ApplicationConfiguration applicationConfiguration);
}
diff --git a/src/com/vaadin/terminal/gwt/client/WidgetSet.java b/src/com/vaadin/terminal/gwt/client/WidgetSet.java
index 832e985397..f2a960b950 100644
--- a/src/com/vaadin/terminal/gwt/client/WidgetSet.java
+++ b/src/com/vaadin/terminal/gwt/client/WidgetSet.java
@@ -42,9 +42,11 @@ public interface WidgetSet extends EntryPoint {
* qualified name.
*
* @param fullyQualifiedName
+ * @param applicationConfiguration
* @return
*/
public Class<? extends Paintable> getImplementationByClassName(
- String fullyQualifiedName);
+ String fullyQualifiedName,
+ ApplicationConfiguration applicationConfiguration);
}