1313import org .argmap .client .ServerComm .LocalCallback ;
1414
1515import com .google .gwt .core .client .GWT ;
16- import com .google .gwt .core .client .RunAsyncCallback ;
1716import com .google .gwt .dom .client .Style ;
1817import com .google .gwt .dom .client .Style .Unit ;
1918import 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 () {
0 commit comments