Skip to content

Commit aa01d93

Browse files
committed
moved a bunch of code to GWT.runAsync calls in effort to reduce size of the initial fragment.
1 parent c010852 commit aa01d93

File tree

5 files changed

+73
-70
lines changed

5 files changed

+73
-70
lines changed

Implementation Notes.odt

-533 Bytes
Binary file not shown.

src/org/argmap/client/ArgMap.java

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.google.gwt.core.client.EntryPoint;
66
import com.google.gwt.core.client.GWT;
77
import com.google.gwt.core.client.GWT.UncaughtExceptionHandler;
8-
import com.google.gwt.core.client.RunAsyncCallback;
98
import com.google.gwt.dom.client.Style;
109
import com.google.gwt.event.logical.shared.SelectionEvent;
1110
import com.google.gwt.event.logical.shared.SelectionHandler;
@@ -141,7 +140,7 @@ public void onModuleLoad() {
141140
messageMap = new MultiMap<String, Message>();
142141
editMode = new ModeEdit(this);
143142

144-
GWT.runAsync(new RunAsyncCallback() {
143+
GWT.runAsync(new AsyncRunCallback() {
145144

146145
@Override
147146
public void onSuccess() {
@@ -174,13 +173,6 @@ public void onSuccess() {
174173
getLoginInfo();
175174

176175
}
177-
178-
@Override
179-
public void onFailure(Throwable reason) {
180-
ArgMap.messageTimed("Code download failed", MessageType.ERROR);
181-
Log.log("am.oml", "Code download failed" + reason.toString());
182-
183-
}
184176
});
185177
}
186178

@@ -216,21 +208,13 @@ public void call(LoginInfo loginInfo) {
216208
loginPanel.add(nickName);
217209
loginPanel.add(signOutLink);
218210
if (loginInfo.isAdmin) {
219-
GWT.runAsync(new RunAsyncCallback() {
211+
GWT.runAsync(new AsyncRunCallback() {
220212

221213
@Override
222214
public void onSuccess() {
223215
modePanel.add(new ModeAdmin(ArgMap.this),
224216
"Admin");
225217
}
226-
227-
@Override
228-
public void onFailure(Throwable reason) {
229-
ArgMap.messageTimed("Code download failed",
230-
MessageType.ERROR);
231-
Log.log("am.sv.a.of", "Code download failed"
232-
+ reason.toString());
233-
}
234218
});
235219
}
236220
} else {
@@ -250,7 +234,7 @@ public static boolean loggedIn() {
250234

251235
public void showVersions() {
252236
if (!versionsIsDisplayed()) {
253-
GWT.runAsync(new RunAsyncCallback() {
237+
GWT.runAsync(new AsyncRunCallback() {
254238

255239
@Override
256240
public void onSuccess() {
@@ -259,14 +243,6 @@ public void onSuccess() {
259243
}
260244
modePanel.insert(versionsMode, "History", 1);
261245
}
262-
263-
@Override
264-
public void onFailure(Throwable reason) {
265-
ArgMap.messageTimed("Code download failed",
266-
MessageType.ERROR);
267-
Log.log("am.sv.a.of",
268-
"Code download failed" + reason.toString());
269-
}
270246
});
271247
}
272248
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.argmap.client;
2+
3+
import org.argmap.client.ArgMap.MessageType;
4+
5+
import com.google.gwt.core.client.RunAsyncCallback;
6+
7+
public abstract class AsyncRunCallback implements RunAsyncCallback {
8+
@Override
9+
public void onFailure(Throwable reason) {
10+
ArgMap.messageTimed("Code download failed", MessageType.ERROR);
11+
Log.log("arc.on", "Code download failed" + reason.toString());
12+
}
13+
}

src/org/argmap/client/ModeEdit.java

Lines changed: 56 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.argmap.client.ServerComm.LocalCallback;
1414

1515
import com.google.gwt.core.client.GWT;
16-
import com.google.gwt.core.client.RunAsyncCallback;
1716
import com.google.gwt.dom.client.Style;
1817
import com.google.gwt.dom.client.Style.Unit;
1918
import com.google.gwt.event.dom.client.ClickEvent;
@@ -72,7 +71,7 @@ public class ModeEdit extends ResizeComposite implements KeyUpHandler,
7271
// private SplitLayoutPanel sideSplit;
7372

7473
private TextBox searchTextBox;
75-
private final EditModeTree tree;
74+
private EditModeTree tree;
7675
private Button addPropButton;
7776
private MainSearchTimer mainSearchTimer;
7877
public SideSearchTimer sideSearchTimer;
@@ -108,30 +107,34 @@ public ModeEdit(ArgMap argMap) {
108107
this.argMap = argMap;
109108

110109
/***********************************************************
111-
* first setup the tree and start loading the propositions * so that
112-
* they can be loading while everything else is * being setup *
110+
* first start loading the propositions so that they can be loading
111+
* while everything else is being setup
113112
***********************************************************/
114-
/*
115-
* setup the tree area
116-
*/
117-
tree = new EditModeTree();
118-
tree.addOpenHandlerTracked(this);
119-
tree.addCloseHandler(this);
120-
tree.addSelectionHandler(this);
121-
tree.setAnimationEnabled(false);
122113

123114
/*
124115
* get the props and preload the callback
125116
*/
126117
getRootProps();
118+
119+
/*
120+
* note that setting up the tree is done in getRootPropsCallback inside
121+
* a GWT.async() to delay loading all the code having to do with the
122+
* tree until after we've fired of a getRootProps() request to the
123+
* server...
124+
*
125+
* below we call getRootPropsCallback with a null argument so that the
126+
* very next thing we do is start downloading the code fragment to
127+
* handle whatever the server returns from the getRootProps() call, even
128+
* before that call returns.
129+
*/
127130
getRootPropsCallback(null);
128131

129132
/*
130133
* setup the update timer
131134
*/
132135
updateTimer = new UpdateTimer();
133136

134-
GWT.runAsync(new RunAsyncCallback() {
137+
GWT.runAsync(new AsyncRunCallback() {
135138

136139
@Override
137140
public void onSuccess() {
@@ -249,23 +252,33 @@ public void onClick(ClickEvent event) {
249252
setSideBarText("welcome");
250253
initWidget(mainSplit);
251254
}
252-
253-
@Override
254-
public void onFailure(Throwable reason) {
255-
ArgMap.messageTimed("Code download failed", MessageType.ERROR);
256-
Log.log("me.me", "Code download failed" + reason.toString());
257-
}
258255
});
259256
}
260257

258+
private void initTree() {
259+
/*
260+
* setup the tree area
261+
*/
262+
if (tree == null) {
263+
tree = new EditModeTree();
264+
tree.addOpenHandlerTracked(this);
265+
tree.addCloseHandler(this);
266+
tree.addSelectionHandler(this);
267+
tree.setAnimationEnabled(false);
268+
}
269+
}
270+
261271
private void getRootPropsCallback(final PartialTrees allNodes) {
262-
GWT.runAsync(new RunAsyncCallback() {
272+
GWT.runAsync(new AsyncRunCallback() {
263273

264274
@Override
265275
public void onSuccess() {
266276
if (allNodes == null) {
267277
return;
268278
}
279+
280+
initTree();
281+
269282
Log log = Log.getLog("em.em.cb");
270283
log.log("Prop Tree From Server");
271284
for (Long id : allNodes.rootIDs) {
@@ -285,13 +298,6 @@ public void onSuccess() {
285298
log.finish();
286299

287300
}
288-
289-
@Override
290-
public void onFailure(Throwable reason) {
291-
ArgMap.messageTimed("Code download failed", MessageType.ERROR);
292-
Log.log("me.me", "Code download failed" + reason.toString());
293-
294-
}
295301
});
296302
}
297303

@@ -1029,23 +1035,30 @@ private void message(String delay) {
10291035

10301036
@Override
10311037
public void run() {
1032-
long timeSinceUserAction = System.currentTimeMillis()
1033-
- lastUserAction;
1034-
if (timeSinceUserAction < 10 * MINUTE) {
1035-
currentFrequency = INITIAL_FREQUENCY;
1036-
} else if (timeSinceUserAction < HOUR) {
1037-
currentFrequency = 30 * SECOND;
1038-
message("30 seconds");
1039-
} else if (timeSinceUserAction < DAY) {
1040-
currentFrequency = 30 * MINUTE;
1041-
message("30 minutes");
1042-
} else {
1043-
currentFrequency = DAY;
1044-
message("24 hours");
1045-
}
1038+
GWT.runAsync(new AsyncRunCallback() {
1039+
1040+
@Override
1041+
public void onSuccess() {
1042+
long timeSinceUserAction = System.currentTimeMillis()
1043+
- lastUserAction;
1044+
if (timeSinceUserAction < 10 * MINUTE) {
1045+
currentFrequency = INITIAL_FREQUENCY;
1046+
} else if (timeSinceUserAction < HOUR) {
1047+
currentFrequency = 30 * SECOND;
1048+
message("30 seconds");
1049+
} else if (timeSinceUserAction < DAY) {
1050+
currentFrequency = 30 * MINUTE;
1051+
message("30 minutes");
1052+
} else {
1053+
currentFrequency = DAY;
1054+
message("24 hours");
1055+
}
1056+
1057+
schedule(currentFrequency);
1058+
if (on) getUpdatesAndApply();
1059+
}
1060+
});
10461061

1047-
schedule(currentFrequency);
1048-
if (on) getUpdatesAndApply();
10491062
}
10501063

10511064
public void start() {

src/org/argmap/client/ModeVersions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public class ModeVersions extends ResizeComposite implements
132132
private Map<ViewChange, String> mapArgTitle;
133133
private Map<ViewChange, Integer> mapPropIndex;
134134
private Map<ViewChange, Integer> mapArgIndex;
135+
private Map<ViewChange, Boolean> mapPropNegated;
135136

136137
/*
137138
* A ViewChange contains a pointer to a ViewNodeVer and a Change object, as

0 commit comments

Comments
 (0)