| 1 |  |   | 
  | 2 |  |   | 
  | 3 |  |   | 
  | 4 |  |   | 
  | 5 |  |   | 
  | 6 |  |   | 
  | 7 |  |   | 
  | 8 |  |   | 
  | 9 |  |   | 
  | 10 |  |   | 
  | 11 |  |   | 
  | 12 |  |   | 
  | 13 |  |   | 
  | 14 |  |   | 
  | 15 |  |   | 
  | 16 |  |  package org.kuali.student.common.ui.client.mvc; | 
  | 17 |  |   | 
  | 18 |  |  import java.util.ArrayList; | 
  | 19 |  |  import java.util.HashMap; | 
  | 20 |  |  import java.util.Iterator; | 
  | 21 |  |  import java.util.List; | 
  | 22 |  |  import java.util.Map; | 
  | 23 |  |   | 
  | 24 |  |  import org.kuali.student.common.assembly.data.Data; | 
  | 25 |  |  import org.kuali.student.common.rice.authorization.PermissionType; | 
  | 26 |  |  import org.kuali.student.common.ui.client.application.KSAsyncCallback; | 
  | 27 |  |  import org.kuali.student.common.ui.client.application.ViewContext; | 
  | 28 |  |  import org.kuali.student.common.ui.client.configurable.mvc.LayoutController; | 
  | 29 |  |  import org.kuali.student.common.ui.client.configurable.mvc.views.SectionView; | 
  | 30 |  |  import org.kuali.student.common.ui.client.mvc.breadcrumb.BreadcrumbSupport; | 
  | 31 |  |  import org.kuali.student.common.ui.client.mvc.history.HistoryManager; | 
  | 32 |  |  import org.kuali.student.common.ui.client.mvc.history.HistorySupport; | 
  | 33 |  |  import org.kuali.student.common.ui.client.mvc.history.NavigationEvent; | 
  | 34 |  |  import org.kuali.student.common.ui.client.reporting.ReportExport; | 
  | 35 |  |  import org.kuali.student.common.ui.client.security.AuthorizationCallback; | 
  | 36 |  |  import org.kuali.student.common.ui.client.security.RequiresAuthorization; | 
  | 37 |  |  import org.kuali.student.common.ui.client.service.GwtExportRpcService; | 
  | 38 |  |  import org.kuali.student.common.ui.client.service.GwtExportRpcServiceAsync; | 
  | 39 |  |  import org.kuali.student.common.ui.client.util.ExportElement; | 
  | 40 |  |  import org.kuali.student.common.ui.client.util.ExportUtils; | 
  | 41 |  |  import org.kuali.student.common.ui.client.widgets.progress.BlockingTask; | 
  | 42 |  |  import org.kuali.student.common.ui.client.widgets.progress.KSBlockingProgressIndicator; | 
  | 43 |  |   | 
  | 44 |  |  import com.google.gwt.core.client.GWT; | 
  | 45 |  |  import com.google.gwt.event.shared.HandlerManager; | 
  | 46 |  |  import com.google.gwt.event.shared.HandlerRegistration; | 
  | 47 |  |  import com.google.gwt.event.shared.GwtEvent.Type; | 
  | 48 |  |  import com.google.gwt.user.client.Window; | 
  | 49 |  |  import com.google.gwt.user.client.ui.Composite; | 
  | 50 |  |  import com.google.gwt.user.client.ui.Widget; | 
  | 51 |  |   | 
  | 52 |  |   | 
  | 53 |  |   | 
  | 54 |  |   | 
  | 55 |  |   | 
  | 56 |  |   | 
  | 57 |  |   | 
  | 58 | 0 |  public abstract class Controller extends Composite implements HistorySupport, BreadcrumbSupport, ReportExport{ | 
  | 59 | 0 |          public static final Callback<Boolean> NO_OP_CALLBACK = new Callback<Boolean>() { | 
  | 60 |  |                  @Override | 
  | 61 |  |                  public void exec(Boolean result) { | 
  | 62 |  |                           | 
  | 63 | 0 |                  } | 
  | 64 |  |          }; | 
  | 65 |  |           | 
  | 66 | 0 |      protected Controller parentController = null; | 
  | 67 | 0 |      private View currentView = null; | 
  | 68 | 0 |      private Enum<?> currentViewEnum = null; | 
  | 69 | 0 |      private String defaultModelId = null; | 
  | 70 | 0 |      protected ViewContext context = new ViewContext(); | 
  | 71 | 0 |      private final Map<String, ModelProvider<? extends Model>> models = new HashMap<String, ModelProvider<? extends Model>>(); | 
  | 72 | 0 |      private boolean fireNavEvents = true; | 
  | 73 | 0 |      private HandlerManager applicationEventHandlers = new HandlerManager(this); | 
  | 74 | 0 |      private GwtExportRpcServiceAsync reportExportRpcService = GWT.create(GwtExportRpcService.class); | 
  | 75 |  |       | 
  | 76 | 0 |      protected Controller() { | 
  | 77 | 0 |      } | 
  | 78 |  |       | 
  | 79 |  |       | 
  | 80 |  |   | 
  | 81 |  |   | 
  | 82 |  |   | 
  | 83 |  |   | 
  | 84 |  |   | 
  | 85 |  |   | 
  | 86 |  |      public <V extends Enum<?>> void showView(final V viewType){ | 
  | 87 | 0 |              this.showView(viewType, NO_OP_CALLBACK); | 
  | 88 | 0 |      } | 
  | 89 |  |       | 
  | 90 |  |   | 
  | 91 |  |       | 
  | 92 |  |       | 
  | 93 |  |   | 
  | 94 |  |   | 
  | 95 |  |   | 
  | 96 |  |   | 
  | 97 |  |   | 
  | 98 |  |   | 
  | 99 |  |   | 
  | 100 |  |   | 
  | 101 |  |   | 
  | 102 |  |   | 
  | 103 |  |   | 
  | 104 |  |   | 
  | 105 |  |   | 
  | 106 |  |   | 
  | 107 |  |   | 
  | 108 |  |   | 
  | 109 |  |   | 
  | 110 |  |      public <V extends Enum<?>> void showView(final V viewType, final Callback<Boolean> onReadyCallback) { | 
  | 111 | 0 |          GWT.log("showView " + viewType.toString(), null); | 
  | 112 | 0 |          getView(viewType, new Callback<View>(){ | 
  | 113 |  |   | 
  | 114 |  |                          @Override | 
  | 115 |  |                          public void exec(View result) { | 
  | 116 | 0 |                                  View view = result; | 
  | 117 | 0 |                                  if (view == null) { | 
  | 118 | 0 |                                  onReadyCallback.exec(false); | 
  | 119 |  |                               | 
  | 120 |  |                          } | 
  | 121 | 0 |                          beginShowView(view, viewType, onReadyCallback); | 
  | 122 |  |                                   | 
  | 123 | 0 |                          }},null); | 
  | 124 | 0 |      } | 
  | 125 |  |       | 
  | 126 |  |      private <V extends Enum<?>> void beginShowView(final View view, final V viewType, final Callback<Boolean> onReadyCallback){ | 
  | 127 | 0 |              beforeViewChange(viewType, new Callback<Boolean>(){ | 
  | 128 |  |   | 
  | 129 |  |                          @Override | 
  | 130 |  |                          public void exec(Boolean result) { | 
  | 131 | 0 |                                  if(result){ | 
  | 132 | 0 |                                           boolean requiresAuthz = (view instanceof RequiresAuthorization) && ((RequiresAuthorization)view).isAuthorizationRequired();  | 
  | 133 |  |                                                   | 
  | 134 | 0 |                                          if (requiresAuthz){ | 
  | 135 |  |                                                  ViewContext tempContext; | 
  | 136 | 0 |                                                  if(view instanceof LayoutController){ | 
  | 137 | 0 |                                                          tempContext = ((LayoutController) view).getViewContext(); | 
  | 138 |  |                                                  }                  | 
  | 139 |  |                                                  else{ | 
  | 140 | 0 |                                                          tempContext = view.getController().getViewContext(); | 
  | 141 |  |                                                  } | 
  | 142 |  |                                                   | 
  | 143 | 0 |                                                  PermissionType permType = (tempContext != null) ? tempContext.getPermissionType() : null; | 
  | 144 | 0 |                                                  if (permType != null) { | 
  | 145 | 0 |                                                          GWT.log("Checking permission type '" + permType.getPermissionTemplateName() + "' for view '" + view.toString() + "'", null); | 
  | 146 |  |                                                       | 
  | 147 | 0 |                                                          ((RequiresAuthorization)view).checkAuthorization(permType, new AuthorizationCallback(){ | 
  | 148 |  |                                                                          public void isAuthorized() { | 
  | 149 | 0 |                                                                                  finalizeShowView(view, viewType, onReadyCallback); | 
  | 150 | 0 |                                                                          } | 
  | 151 |  |                                   | 
  | 152 |  |                                                                          public void isNotAuthorized(String msg) { | 
  | 153 | 0 |                                                                                  Window.alert(msg); | 
  | 154 | 0 |                                                                                  onReadyCallback.exec(false);                                         | 
  | 155 | 0 |                                                                          }                         | 
  | 156 |  |                                                          }); | 
  | 157 |  |                                                  } | 
  | 158 |  |                                                  else { | 
  | 159 | 0 |                                                          GWT.log("Cannot find PermissionType for view '" + view.toString() + "' which requires authorization", null); | 
  | 160 | 0 |                                                      finalizeShowView(view, viewType, onReadyCallback); | 
  | 161 |  |                                                  } | 
  | 162 | 0 |                                          } else { | 
  | 163 | 0 |                                                      GWT.log("Not Requiring Auth.", null); | 
  | 164 | 0 |                                                  finalizeShowView(view, viewType, onReadyCallback); | 
  | 165 |  |                                          } | 
  | 166 | 0 |                                  } | 
  | 167 |  |                                  else{ | 
  | 168 | 0 |                                          onReadyCallback.exec(false); | 
  | 169 |  |                                  } | 
  | 170 |  |                                   | 
  | 171 | 0 |                          } | 
  | 172 |  |                  }); | 
  | 173 | 0 |      } | 
  | 174 |  |       | 
  | 175 |  |      private <V extends Enum<?>> void finalizeShowView(final View view, final V viewType, final Callback<Boolean> onReadyCallback){ | 
  | 176 | 0 |          if (((currentView == null) || currentView.beforeHide()) && view != null) { | 
  | 177 | 0 |                          view.beforeShow(new Callback<Boolean>() { | 
  | 178 |  |                                  @Override | 
  | 179 |  |                                  public void exec(Boolean result) { | 
  | 180 | 0 |                                          if (!result) { | 
  | 181 | 0 |                                                  GWT.log("showView: beforeShow yielded false " + viewType, null); | 
  | 182 | 0 |                                          onReadyCallback.exec(false); | 
  | 183 |  |                                          } else { | 
  | 184 | 0 |                                          if (currentView != null) { | 
  | 185 | 0 |                                          hideView(currentView); | 
  | 186 |  |                                      } | 
  | 187 |  |                                       | 
  | 188 | 0 |                                      currentViewEnum = viewType; | 
  | 189 | 0 |                                      currentView = view; | 
  | 190 | 0 |                                      GWT.log("renderView " + viewType.toString(), null); | 
  | 191 | 0 |                                      if(fireNavEvents){ | 
  | 192 | 0 |                                              fireNavigationEvent(); | 
  | 193 |  |                                      } | 
  | 194 | 0 |                                      renderView(view); | 
  | 195 | 0 |                                          onReadyCallback.exec(true); | 
  | 196 |  |                                           | 
  | 197 |  |                                          } | 
  | 198 | 0 |                                  } | 
  | 199 |  |                          }); | 
  | 200 |  |          } else { | 
  | 201 | 0 |                  onReadyCallback.exec(false); | 
  | 202 | 0 |              GWT.log("Current view canceled hide action", null); | 
  | 203 |  |          }             | 
  | 204 | 0 |      } | 
  | 205 |  |   | 
  | 206 |  |      protected void fireNavigationEvent() { | 
  | 207 |  |           | 
  | 208 |  |              | 
  | 209 |  |               | 
  | 210 | 0 |                  fireApplicationEvent(new NavigationEvent(Controller.this)); | 
  | 211 |  |               | 
  | 212 |  |           | 
  | 213 | 0 |      } | 
  | 214 |  |       | 
  | 215 |  |       | 
  | 216 |  |   | 
  | 217 |  |   | 
  | 218 |  |   | 
  | 219 |  |   | 
  | 220 |  |      public View getCurrentView() { | 
  | 221 | 0 |          return currentView; | 
  | 222 |  |      } | 
  | 223 |  |       | 
  | 224 |  |      public Enum<?> getCurrentViewEnum() { | 
  | 225 | 0 |          return currentViewEnum; | 
  | 226 |  |      } | 
  | 227 |  |   | 
  | 228 |  |      public void setCurrentViewEnum(Enum<?> currentViewEnum) { | 
  | 229 | 0 |          this.currentViewEnum = currentViewEnum; | 
  | 230 | 0 |      } | 
  | 231 |  |   | 
  | 232 |  |       | 
  | 233 |  |   | 
  | 234 |  |   | 
  | 235 |  |   | 
  | 236 |  |   | 
  | 237 |  |   | 
  | 238 |  |   | 
  | 239 |  |   | 
  | 240 |  |   | 
  | 241 |  |      public void setParentController(Controller controller) { | 
  | 242 | 0 |          parentController = controller; | 
  | 243 | 0 |      } | 
  | 244 |  |   | 
  | 245 |  |       | 
  | 246 |  |   | 
  | 247 |  |   | 
  | 248 |  |   | 
  | 249 |  |   | 
  | 250 |  |   | 
  | 251 |  |      public Controller getParentController() { | 
  | 252 | 0 |          if (parentController == null) { | 
  | 253 | 0 |              parentController = Controller.findController(this); | 
  | 254 |  |          } | 
  | 255 | 0 |          return parentController; | 
  | 256 |  |      } | 
  | 257 |  |   | 
  | 258 |  |       | 
  | 259 |  |   | 
  | 260 |  |   | 
  | 261 |  |   | 
  | 262 |  |   | 
  | 263 |  |   | 
  | 264 |  |   | 
  | 265 |  |      public static Controller findController(Widget w) { | 
  | 266 | 0 |          Controller result = null; | 
  | 267 |  |          while (true) { | 
  | 268 | 0 |              w = w.getParent(); | 
  | 269 | 0 |              if (w == null) { | 
  | 270 | 0 |                  break; | 
  | 271 | 0 |              } else if (w instanceof Controller) { | 
  | 272 | 0 |                  result = (Controller) w; | 
  | 273 | 0 |                  break; | 
  | 274 | 0 |              } else if (w instanceof View) { | 
  | 275 |  |                   | 
  | 276 |  |                   | 
  | 277 | 0 |                  result = ((View) w).getController(); | 
  | 278 | 0 |                  break; | 
  | 279 |  |              } | 
  | 280 |  |          } | 
  | 281 | 0 |          return result; | 
  | 282 |  |      } | 
  | 283 |  |   | 
  | 284 |  |       | 
  | 285 |  |   | 
  | 286 |  |   | 
  | 287 |  |   | 
  | 288 |  |   | 
  | 289 |  |   | 
  | 290 |  |   | 
  | 291 |  |   | 
  | 292 |  |   | 
  | 293 |  |   | 
  | 294 |  |   | 
  | 295 |  |   | 
  | 296 |  |      @SuppressWarnings("unchecked") | 
  | 297 |  |      public void requestModel(final Class modelType, final ModelRequestCallback callback) { | 
  | 298 | 0 |          requestModel((modelType == null) ? null : modelType.getName(), callback); | 
  | 299 | 0 |      } | 
  | 300 |  |       | 
  | 301 |  |      @SuppressWarnings("unchecked") | 
  | 302 |  |      public void requestModel(final String modelId, final ModelRequestCallback callback) { | 
  | 303 | 0 |          String id = (modelId == null) ? defaultModelId : modelId; | 
  | 304 |  |   | 
  | 305 | 0 |          ModelProvider<? extends Model> p = models.get(id); | 
  | 306 | 0 |          if (p != null) { | 
  | 307 | 0 |              p.requestModel(callback); | 
  | 308 | 0 |          } else if (getParentController() != null) { | 
  | 309 | 0 |              parentController.requestModel(modelId, callback); | 
  | 310 |  |          } else { | 
  | 311 | 0 |              if (callback != null) { | 
  | 312 | 0 |                  callback.onRequestFail(new RuntimeException("The requested model was not found: " + modelId)); | 
  | 313 |  |              } | 
  | 314 |  |          } | 
  | 315 | 0 |      } | 
  | 316 |  |   | 
  | 317 |  |      @SuppressWarnings("unchecked") | 
  | 318 |  |      public void requestModel(final ModelRequestCallback callback) { | 
  | 319 | 0 |          requestModel((String)null, callback); | 
  | 320 | 0 |      } | 
  | 321 |  |   | 
  | 322 |  |      public <T extends Model> void registerModel(String modelId, ModelProvider<T> provider) { | 
  | 323 | 0 |          models.put(modelId, provider); | 
  | 324 | 0 |      } | 
  | 325 |  |       | 
  | 326 |  |      public String getDefaultModelId() { | 
  | 327 | 0 |          return defaultModelId; | 
  | 328 |  |      } | 
  | 329 |  |      public void setDefaultModelId(String defaultModelId) { | 
  | 330 | 0 |          this.defaultModelId = defaultModelId; | 
  | 331 | 0 |      } | 
  | 332 |  |       | 
  | 333 |  |       | 
  | 334 |  |   | 
  | 335 |  |   | 
  | 336 |  |   | 
  | 337 |  |   | 
  | 338 |  |   | 
  | 339 |  |   | 
  | 340 |  |   | 
  | 341 |  |   | 
  | 342 |  |      @SuppressWarnings("unchecked") | 
  | 343 |  |      public HandlerRegistration addApplicationEventHandler(Type type, ApplicationEventHandler handler) { | 
  | 344 | 0 |          if ((handler instanceof UncheckedApplicationEventHandler) && (getParentController() != null)) { | 
  | 345 | 0 |              return parentController.addApplicationEventHandler(type, handler); | 
  | 346 |  |          } | 
  | 347 | 0 |          return applicationEventHandlers.addHandler(type, handler); | 
  | 348 |  |      } | 
  | 349 |  |   | 
  | 350 |  |       | 
  | 351 |  |   | 
  | 352 |  |   | 
  | 353 |  |   | 
  | 354 |  |   | 
  | 355 |  |      @SuppressWarnings("unchecked") | 
  | 356 |  |      public void fireApplicationEvent(ApplicationEvent event) { | 
  | 357 |  |           | 
  | 358 |  |           | 
  | 359 | 0 |          if ((event instanceof UncheckedApplicationEvent) && (getParentController() != null)) { | 
  | 360 | 0 |              parentController.fireApplicationEvent(event); | 
  | 361 |  |          } | 
  | 362 |  |           | 
  | 363 | 0 |          applicationEventHandlers.fireEvent(event); | 
  | 364 |  |   | 
  | 365 | 0 |      } | 
  | 366 |  |   | 
  | 367 |  |       | 
  | 368 |  |   | 
  | 369 |  |   | 
  | 370 |  |   | 
  | 371 |  |   | 
  | 372 |  |      protected abstract void renderView(View view); | 
  | 373 |  |   | 
  | 374 |  |       | 
  | 375 |  |   | 
  | 376 |  |   | 
  | 377 |  |   | 
  | 378 |  |   | 
  | 379 |  |      protected abstract void hideView(View view); | 
  | 380 |  |   | 
  | 381 |  |       | 
  | 382 |  |   | 
  | 383 |  |   | 
  | 384 |  |   | 
  | 385 |  |   | 
  | 386 |  |   | 
  | 387 |  |   | 
  | 388 |  |   | 
  | 389 |  |      protected <V extends Enum<?>> void getView(V viewType, Callback<View> callback, Map<String, String> tokenMap){ | 
  | 390 | 0 |              getView(viewType, callback); | 
  | 391 | 0 |      } | 
  | 392 |  |   | 
  | 393 |  |       | 
  | 394 |  |   | 
  | 395 |  |   | 
  | 396 |  |   | 
  | 397 |  |   | 
  | 398 |  |   | 
  | 399 |  |   | 
  | 400 |  |      protected abstract <V extends Enum<?>> void getView(V viewType, Callback<View> callback); | 
  | 401 |  |       | 
  | 402 |  |       | 
  | 403 |  |   | 
  | 404 |  |   | 
  | 405 |  |   | 
  | 406 |  |   | 
  | 407 |  |   | 
  | 408 |  |      public void beforeViewChange(Enum<?> viewChangingTo, Callback<Boolean> okToChangeCallback) { | 
  | 409 | 0 |              okToChangeCallback.exec(true); | 
  | 410 | 0 |      } | 
  | 411 |  |   | 
  | 412 |  |       | 
  | 413 |  |   | 
  | 414 |  |   | 
  | 415 |  |      public abstract void showDefaultView(Callback<Boolean> onReadyCallback); | 
  | 416 |  |       | 
  | 417 |  |      public abstract Enum<?> getViewEnumValue(String enumValue); | 
  | 418 |  |       | 
  | 419 |  |       | 
  | 420 |  |   | 
  | 421 |  |   | 
  | 422 |  |   | 
  | 423 |  |   | 
  | 424 |  |   | 
  | 425 |  |      @Override | 
  | 426 |  |      public String collectHistory(String historyStack) { | 
  | 427 | 0 |              String token = getHistoryToken(); | 
  | 428 | 0 |              historyStack = historyStack + "/" + token; | 
  | 429 |  |               | 
  | 430 | 0 |              if(currentView != null){ | 
  | 431 | 0 |                      String tempHistoryStack = historyStack; | 
  | 432 | 0 |                      historyStack = currentView.collectHistory(historyStack); | 
  | 433 |  |                       | 
  | 434 |  |                       | 
  | 435 | 0 |                      if(historyStack == null){ | 
  | 436 | 0 |                              historyStack = tempHistoryStack; | 
  | 437 |  |                      } | 
  | 438 | 0 |                      else if(historyStack != null && historyStack.isEmpty()){ | 
  | 439 | 0 |                              historyStack = tempHistoryStack; | 
  | 440 |  |                      } | 
  | 441 |  |              } | 
  | 442 | 0 |              return historyStack; | 
  | 443 |  |      } | 
  | 444 |  |       | 
  | 445 |  |      protected String getHistoryToken() { | 
  | 446 | 0 |              String historyToken = ""; | 
  | 447 | 0 |          if (currentViewEnum != null) { | 
  | 448 | 0 |              historyToken = currentViewEnum.toString(); | 
  | 449 | 0 |              if(currentView != null && currentView instanceof Controller  | 
  | 450 |  |                              && ((Controller)currentView).getViewContext() != null){ | 
  | 451 | 0 |                      ViewContext context = ((Controller) currentView).getViewContext(); | 
  | 452 | 0 |                      historyToken = HistoryManager.appendContext(historyToken, context); | 
  | 453 |  |              } | 
  | 454 |  |                | 
  | 455 |  |          } | 
  | 456 | 0 |          return historyToken; | 
  | 457 |  |      } | 
  | 458 |  |   | 
  | 459 |  |       | 
  | 460 |  |   | 
  | 461 |  |   | 
  | 462 |  |   | 
  | 463 |  |   | 
  | 464 |  |   | 
  | 465 |  |   | 
  | 466 |  |   | 
  | 467 |  |   | 
  | 468 |  |   | 
  | 469 |  |   | 
  | 470 |  |   | 
  | 471 |  |      @Override | 
  | 472 |  |      public void onHistoryEvent(String historyStack) { | 
  | 473 | 0 |              final String nextHistoryStack = HistoryManager.nextHistoryStack(historyStack); | 
  | 474 | 0 |          String[] tokens = HistoryManager.splitHistoryStack(nextHistoryStack); | 
  | 475 | 0 |          if (tokens.length >= 1 && tokens[0] != null && !tokens[0].isEmpty()) { | 
  | 476 | 0 |              final Map<String, String> tokenMap = HistoryManager.getTokenMap(tokens[0]); | 
  | 477 |  |               | 
  | 478 | 0 |              String viewEnumString = tokenMap.get("view"); | 
  | 479 | 0 |              if (viewEnumString != null) { | 
  | 480 | 0 |                  final Enum<?> viewEnum = getViewEnumValue(viewEnumString); | 
  | 481 |  |                   | 
  | 482 | 0 |                  if (viewEnum != null) { | 
  | 483 | 0 |                          getView(viewEnum, new Callback<View>(){ | 
  | 484 |  |   | 
  | 485 |  |                                                  @Override | 
  | 486 |  |                                                  public void exec(View result) { | 
  | 487 | 0 |                                                          View theView = result; | 
  | 488 | 0 |                                              boolean sameContext = true; | 
  | 489 | 0 |                                          if(theView instanceof Controller){ | 
  | 490 |  |                                                   | 
  | 491 | 0 |                                                  ViewContext newContext = new ViewContext(); | 
  | 492 | 0 |                                                  Iterator<String> tokenIt = tokenMap.keySet().iterator(); | 
  | 493 | 0 |                                                  while(tokenIt.hasNext()){ | 
  | 494 | 0 |                                                          String key = tokenIt.next(); | 
  | 495 | 0 |                                                          if(key.equals(ViewContext.ID_ATR)){ | 
  | 496 | 0 |                                                                  newContext.setId(tokenMap.get(ViewContext.ID_ATR)); | 
  | 497 |  |                                                          } | 
  | 498 | 0 |                                                          else if(key.equals(ViewContext.ID_TYPE_ATR)){ | 
  | 499 | 0 |                                                                  newContext.setIdType(tokenMap.get(ViewContext.ID_TYPE_ATR)); | 
  | 500 |  |                                                          } | 
  | 501 |  |                                                           | 
  | 502 | 0 |                                                          else if(!key.equals("view")){ | 
  | 503 | 0 |                                                                  newContext.setAttribute(key, tokenMap.get(key)); | 
  | 504 |  |                                                          } | 
  | 505 | 0 |                                                  } | 
  | 506 |  |                                                   | 
  | 507 | 0 |                                                  ViewContext viewContext = ((Controller) theView).getViewContext(); | 
  | 508 | 0 |                                                  if(viewContext.compareTo(newContext) != 0){ | 
  | 509 | 0 |                                                          ((Controller) theView).setViewContext(newContext); | 
  | 510 | 0 |                                                          sameContext = false; | 
  | 511 |  |                                                  } | 
  | 512 |  |                                          } | 
  | 513 | 0 |                                      if (currentViewEnum == null || !viewEnum.equals(currentViewEnum)  | 
  | 514 |  |                                                      || !sameContext) { | 
  | 515 | 0 |                                          beginShowView(theView, viewEnum, new Callback<Boolean>() { | 
  | 516 |  |                                              @Override | 
  | 517 |  |                                              public void exec(Boolean result) { | 
  | 518 | 0 |                                                  if (result) { | 
  | 519 | 0 |                                                      currentView.onHistoryEvent(nextHistoryStack); | 
  | 520 |  |                                                  } | 
  | 521 | 0 |                                              } | 
  | 522 |  |                                          }); | 
  | 523 | 0 |                                      } else if (currentView != null) { | 
  | 524 | 0 |                                              currentView.onHistoryEvent(nextHistoryStack); | 
  | 525 |  |                                      } | 
  | 526 | 0 |                                                  } | 
  | 527 |  |                                          },tokenMap); | 
  | 528 |  |       | 
  | 529 |  |                  } | 
  | 530 |  |              } | 
  | 531 | 0 |          } | 
  | 532 |  |          else{ | 
  | 533 | 0 |                      this.showDefaultView(new Callback<Boolean>(){ | 
  | 534 |  |   | 
  | 535 |  |                                  @Override | 
  | 536 |  |                                  public void exec(Boolean result) { | 
  | 537 | 0 |                                          if(result){ | 
  | 538 | 0 |                                                  currentView.onHistoryEvent(nextHistoryStack); | 
  | 539 |  |                                          } | 
  | 540 |  |                                           | 
  | 541 | 0 |                                  } | 
  | 542 |  |                          }); | 
  | 543 |  |              } | 
  | 544 |  |           | 
  | 545 | 0 |      } | 
  | 546 |  |   | 
  | 547 |  |       | 
  | 548 |  |   | 
  | 549 |  |   | 
  | 550 |  |   | 
  | 551 |  |   | 
  | 552 |  |   | 
  | 553 |  |   | 
  | 554 |  |      public void setViewContext(ViewContext viewContext){ | 
  | 555 | 0 |              this.context = viewContext; | 
  | 556 | 0 |      } | 
  | 557 |  |   | 
  | 558 |  |      public ViewContext getViewContext() { | 
  | 559 | 0 |              return this.context; | 
  | 560 |  |      } | 
  | 561 |  |       | 
  | 562 |  |      public void resetCurrentView(){ | 
  | 563 | 0 |              currentView = null; | 
  | 564 | 0 |      } | 
  | 565 |  |     | 
  | 566 |  |       | 
  | 567 |  |   | 
  | 568 |  |   | 
  | 569 |  |   | 
  | 570 |  |   | 
  | 571 |  |   | 
  | 572 |  |   | 
  | 573 |  |      @Override | 
  | 574 |  |      public void doReportExport(List<ExportElement> exportElements, final String format, final String reportTitle) {         | 
  | 575 |  |        | 
  | 576 | 0 |              final BlockingTask loadDataTask = new BlockingTask("Generating Export File"); | 
  | 577 |  |           | 
  | 578 | 0 |          DataModel dataModel = getExportDataModel(); | 
  | 579 | 0 |          Data modelDataObject = null; | 
  | 580 | 0 |          if (dataModel != null) { | 
  | 581 | 0 |              modelDataObject = dataModel.getRoot(); | 
  | 582 |  |          }    | 
  | 583 |  |           | 
  | 584 |  |           | 
  | 585 |  |           | 
  | 586 | 0 |          KSBlockingProgressIndicator.addTask(loadDataTask); | 
  | 587 |  |           | 
  | 588 | 0 |          reportExportRpcService.reportExport(exportElements, modelDataObject, getExportTemplateName(), format, reportTitle, new KSAsyncCallback<String>() { | 
  | 589 |  |                      @Override | 
  | 590 |  |                      public void onSuccess(String result) { | 
  | 591 |  |                           | 
  | 592 |  |                               | 
  | 593 |  |                               | 
  | 594 | 0 |                              String baseUrl = GWT.getHostPageBaseURL(); | 
  | 595 | 0 |                              baseUrl = baseUrl.replaceFirst(GWT.getModuleName() + "/", "");                                                 | 
  | 596 |  |                               | 
  | 597 | 0 |                              KSBlockingProgressIndicator.removeTask(loadDataTask); | 
  | 598 |  |                               | 
  | 599 | 0 |                          Window.open(baseUrl + "exportDownloadHTTPServlet?exportId="+result + "&format=" + format, "", "");                           | 
  | 600 | 0 |                      } | 
  | 601 |  |   | 
  | 602 |  |                                          @Override | 
  | 603 |  |                                          public void handleFailure(Throwable caught) { | 
  | 604 | 0 |                                                  KSBlockingProgressIndicator.removeTask(loadDataTask); | 
  | 605 | 0 |                                                  super.handleFailure(caught); | 
  | 606 | 0 |                                          }                                                     | 
  | 607 |  |                       | 
  | 608 |  |                  }); | 
  | 609 |  |   | 
  | 610 |  |               | 
  | 611 |  |           | 
  | 612 | 0 |      } | 
  | 613 |  |          | 
  | 614 |  |       | 
  | 615 |  |      @Override | 
  | 616 |  |      public DataModel getExportDataModel() { | 
  | 617 | 0 |          return null; | 
  | 618 |  |      } | 
  | 619 |  |   | 
  | 620 |  |       | 
  | 621 |  |   | 
  | 622 |  |   | 
  | 623 |  |   | 
  | 624 |  |      @Override | 
  | 625 |  |      public String getExportTemplateName() { | 
  | 626 | 0 |          return exportTemplateName; | 
  | 627 |  |      } | 
  | 628 |  |       | 
  | 629 |  |      @Override | 
  | 630 |  |      public List<ExportElement> getExportElementsFromView() { | 
  | 631 | 0 |          String viewName = null; | 
  | 632 | 0 |          View currentView = this.getCurrentView(); | 
  | 633 | 0 |          if (currentView != null) { | 
  | 634 |  |               | 
  | 635 | 0 |              ArrayList<ExportElement> exportElements = null; | 
  | 636 |  |   | 
  | 637 | 0 |              if (currentView != null && currentView instanceof SectionView) { | 
  | 638 | 0 |                  viewName =  currentView.getName(); | 
  | 639 | 0 |                  exportElements = ExportUtils.getExportElementsFromView((SectionView)currentView, exportElements, viewName, "Sectionname"); | 
  | 640 | 0 |                  return exportElements; | 
  | 641 |  |              } else { | 
  | 642 |  |   | 
  | 643 |  |              } | 
  | 644 |  |          } else { | 
  | 645 |  |   | 
  | 646 |  |          } | 
  | 647 | 0 |          return null; | 
  | 648 |  |      } | 
  | 649 |  |  } |