blob: 0eb505761b5d9388dc3f6d8929dcca97baf8192f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
package com.vaadin.terminal.gwt.client;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
public class ApplicationConfiguration {
// can only be inited once, to avoid multiple-entrypoint-problem
private static WidgetSet initedWidgetSet;
private String id;
private String themeUri;
private String pathInfo;
private String appUri;
private JavaScriptObject versionInfo;
private String windowName;
private String communicationErrorCaption;
private String communicationErrorMessage;
private String communicationErrorUrl;
private boolean useDebugIdInDom = true;
private static ArrayList<ApplicationConnection> unstartedApplications = new ArrayList<ApplicationConnection>();
private static ArrayList<ApplicationConnection> runningApplications = new ArrayList<ApplicationConnection>();
public String getRootPanelId() {
return id;
}
public String getApplicationUri() {
return appUri;
}
public String getPathInfo() {
return pathInfo;
}
public String getThemeUri() {
return themeUri;
}
public void setAppId(String appId) {
id = appId;
}
public void setInitialWindowName(String name) {
windowName = name;
}
public String getInitialWindowName() {
return windowName;
}
public JavaScriptObject getVersionInfoJSObject() {
return versionInfo;
}
public String getCommunicationErrorCaption() {
return communicationErrorCaption;
}
public String getCommunicationErrorMessage() {
return communicationErrorMessage;
}
public String getCommunicationErrorUrl() {
return communicationErrorUrl;
}
private native void loadFromDOM()
/*-{
var id = this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::id;
if($wnd.vaadin.toolkitConfigurations && $wnd.vaadin.toolkitConfigurations[id]) {
var jsobj = $wnd.vaadin.toolkitConfigurations[id];
var uri = jsobj.appUri;
if(uri[uri.length -1] != "/") {
uri = uri + "/";
}
this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::appUri = uri;
this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::pathInfo = jsobj.pathInfo;
this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::themeUri = jsobj.themeUri;
if(jsobj.windowName) {
this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::windowName = jsobj.windowName;
}
if('useDebugIdInDom' in jsobj && typeof(jsobj.useDebugIdInDom) == "boolean") {
this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::useDebugIdInDom = jsobj.useDebugIdInDom;
}
if(jsobj.versionInfo) {
this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::versionInfo = jsobj.versionInfo;
}
if(jsobj.comErrMsg) {
this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::communicationErrorCaption = jsobj.comErrMsg.caption;
this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::communicationErrorMessage = jsobj.comErrMsg.message;
this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::communicationErrorUrl = jsobj.comErrMsg.url;
}
} else {
$wnd.alert("Toolkit app failed to initialize: " + this.id);
}
}-*/;
/**
* Inits the ApplicationConfiguration by reading the DOM and instantiating
* ApplicationConenctions accordingly. Call {@link #startNextApplication()}
* to actually start the applications.
*
* @param widgetset
* 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 (!wsname.startsWith(base) || !wsname.endsWith(simpleName)) {
// WidgetSet module name does not match implementation name;
// probably inherited WidgetSet with entry-point. Skip.
GWT.log("Ignored init for " + wsname + " when starting " + module,
null);
return;
}
if (initedWidgetSet != null) {
// Something went wrong: multiple widgetsets inited
String msg = "Tried to init " + widgetset.getClass().getName()
+ ", but " + initedWidgetSet.getClass().getName()
+ " is already inited.";
System.err.println(msg);
throw new IllegalStateException(msg);
}
initedWidgetSet = widgetset;
ArrayList<String> appIds = new ArrayList<String>();
loadAppIdListFromDOM(appIds);
for (Iterator<String> it = appIds.iterator(); it.hasNext();) {
String appId = it.next();
ApplicationConfiguration appConf = getConfigFromDOM(appId);
ApplicationConnection a = new ApplicationConnection(widgetset,
appConf);
unstartedApplications.add(a);
}
}
/**
* Starts the next unstarted application. The WidgetSet should call this
* once to start the first application; after that, each application should
* call this once it has started. This ensures that the applications are
* started synchronously, which is neccessary to avoid session-id problems.
*
* @return true if an unstarted application was found
*/
public static boolean startNextApplication() {
if (unstartedApplications.size() > 0) {
ApplicationConnection a = unstartedApplications.remove(0);
a.start();
runningApplications.add(a);
return true;
} else {
return false;
}
}
public static List<ApplicationConnection> getRunningApplications() {
return runningApplications;
}
private native static void loadAppIdListFromDOM(ArrayList<String> list)
/*-{
var j;
for(j in $wnd.vaadin.toolkitConfigurations) {
list.@java.util.Collection::add(Ljava/lang/Object;)(j);
}
}-*/;
public static ApplicationConfiguration getConfigFromDOM(String appId) {
ApplicationConfiguration conf = new ApplicationConfiguration();
conf.setAppId(appId);
conf.loadFromDOM();
return conf;
}
public native String getServletVersion()
/*-{
return this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::versionInfo.vaadinVersion;
}-*/;
public native String getApplicationVersion()
/*-{
return this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::versionInfo.applicationVersion;
}-*/;
public boolean useDebugIdInDOM() {
return useDebugIdInDom;
}
}
|