Package org.olat.core.gui.control.winmgr

Examples of org.olat.core.gui.control.winmgr.Command


        if (jsPathToEvalBeforeAJAXAddJsCode.containsKey(addJs)) {
          fileInfo.put("before", jsPathToEvalBeforeAJAXAddJsCode.get(addJs));         
        }
        jsAdd.put(fileInfo);
      }
      Command com = CommandFactory.createJSCSSCommand();
      com.setSubJSON(root);
      return com;
    } catch (JSONException e) {
      throw new AssertException("wrong data put into json object", e);
    }
  }
View Full Code Here


                  // set window id to cur id, timestamp to current timestamp,
                  // component id to -1 -> indicates rerender
                  String uri = buildURIForRedirect(newModUri); // newModUri == null in case "just" new css or js libs have been added
                  // set this only for the first request (the .html request), but clear it afterwards for asyncmedia
                  validatingCausedRerendering = true;
                  Command rmrcom = CommandFactory.createParentRedirectTo(uri);
                  wbackofficeImpl.sendCommandTo(rmrcom);
                  //OLAT-4563: so the timestamp is not incremented, we do only a redirect
                  setDirty(false);
                } else {
                  // inline rendering by selectively replacing the dirty components in the dom tree of the browser
                  wbackofficeImpl.fireCycleEvent(Window.BEFORE_INLINE_RENDERING);
         
                  // Start by preparing the client: must be called prior to the
                  // other commands to not overwrite the form o2c dirty flag
                  // wich might be set by later commands
                  if (!this.isDirty()) {
                    wbackofficeImpl.sendCommandTo(CommandFactory.createPrepareClientCommand(wbackofficeImpl.getBusinessControlPath()));
                  }
                 
                  // Add the js and css files and related pre init commands
                  Command jscsscom = jsAndCssAdder.extractJSCSSCommand();
                  wbackofficeImpl.sendCommandTo(jscsscom);
                 
                  // Add the DOM replacement commands. Must be called after the
                  // js and css commands. Inline JS scripts might have
                  // dependencies to previously loaded js libs
                  if (this.isDirty()) {
                    // special case: when the window itself is dirty we require
                    // a full page refresh in any case
                    String reRenderUri = buildURIFor(this, timestampID, null);
                    Command rmrcom = CommandFactory.createParentRedirectTo(reRenderUri);
                    wbackofficeImpl.sendCommandTo(rmrcom);
                    this.setDirty(false);
                  } else {
                    // check for dirty child components in the component tree
                    Command co = handleDirties();
                   
                    //DUMP FOR EACH CLICK THE CURRENT JumpInPath -> for later usage and debugging.
                    //System.err.println("V^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^V");
                    WindowControl current = (WindowControl)wbackofficeImpl.getWindow().getAttribute("BUSPATH");
                    //System.err.println(current != null ? JumpInManager.getRestJumpInUri(current.getBusinessControl()) : "NONE");
                    //System.err.println("T^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^T");
                    wbackofficeImpl.fireCycleEvent(AFTER_INLINE_RENDERING);
                    if (co != null) { // see method handleDirties for the rare case of co == null even if there are dirty components;
                      wbackofficeImpl.sendCommandTo(co);
                    }
                  }
                }
              } else { // not inline
                if(!validForDispatching){
                  // not valid: fire oldtimestamp event
                  fireEvent(ureq, OLDTIMESTAMPCALL);
                }
                // not inline, new mediaresource
                // send it to the parent window (e.g. an excel download, but could also be a 302 redirect)
                // if the browser has e.g. pdf configured to be displayed inline, we want it to fill the whole area (self window), not the hidden iframe.
                // the same for 302.
                // -> send a command which offers a new location for the main window.
                // create a mapper which maps this mediaresource, and serves it once only
                MediaResourceMapper extMRM = new MediaResourceMapper();
                extMRM.setMediaResource(mmr);
                //FIXME:fj:b deregister old mapper, or reuse current one
                String res = MapperRegistry.getInstanceFor(ureq.getUserSession()).register(extMRM)+"/";
                // e.g. res = /olat/m/10001/
                Command rmrcom = CommandFactory.createParentRedirectForExternalResource(res);
                wbackofficeImpl.sendCommandTo(rmrcom);
              }
            } else { // not dispatched
              Tracing.logDebug("Found a valid timestamp but could not dispatch to component: ureq.compid:"+ureq.getComponentID()+" ureq.win-ts:"+ureq.getTimestampID()+" ureq.comp-ts:"+ureq.getComponentTimestamp() + " target.timestamp:" + target.getTimestamp() + " target=" + target, this.getClass());
              String reRenderUri = buildURIFor(this, timestampID, null);
              Command rmrcom = CommandFactory.createParentRedirectTo(reRenderUri);
              wbackofficeImpl.sendCommandTo(rmrcom);
            }
            MediaResource jsonmr = wbackofficeImpl.extractCommands(true);
            ServletUtil.serveResource(request, response, jsonmr);
          } catch (Throwable th) {
            // in any case, try to inform the user appropriately.
            // a) error while dispatching (e.g. db problem, npe, ...)
            // b) for inline: error while validating or json-rendering dirty components.
           
            // since an error has occured for a request which is targeted in the background iframe, we need to redirect to the error window.
            // create the error window
            try {
              Tracing.logDebug("Error in Window, rollback", getClass());
              DBFactory.getInstance().rollback();
           
              ChiefController msgcc = MsgFactory.createMessageChiefController(ureq, th);
              Window errWindow = msgcc.getWindow();
              // register window
              Windows.getWindows(ureq).registerWindow(errWindow);
              // redirect to the error window
              String newWinUri = buildRenderOnlyURIFor(errWindow);
              Command rmrcom = CommandFactory.createParentRedirectTo(newWinUri);
              wbackofficeImpl.sendCommandTo(rmrcom);
              MediaResource jsonmr = wbackofficeImpl.extractCommands(true);
              ServletUtil.serveResource(request, response, jsonmr);
            } catch (Throwable anotherTh) {
              Tracing.logError("Exception while handling exception!!!!", anotherTh, this.getClass());
View Full Code Here

   */
  public Command handleDirties() {
    // need to sync to window, since the dispatching must be finished so that the render tree is stable before we collect the dirties.
    // more accurately, the synchronized is needed when other classes than window call this method.
    synchronized(this) {
      Command com = null;
      boolean isDebugLog = Tracing.isDebugEnabled(Window.class);
      StringBuilder debugMsg = null;
     
      final List<Component> dirties = new ArrayList<Component>();
      ComponentVisitor dirtyV = new ComponentVisitor() {
        public boolean visit(Component comp, UserRequest ureq) {
          boolean visitChildren = false;
          if (!comp.isVisible()) {
            // a component just made -visible- still needs to be collected (detected by checking dirty flag)
            if (comp.isDirty()) {
              dirties.add(comp);
              comp.setDirty(false)// clear manually here since this component will not be rendered
            }
          } else if (comp.isDirty()) {
            dirties.add(comp);
          } else {
            // visible and not dirty -> visit children
            visitChildren = true;
          }       
          return visitChildren;
        }};
      ComponentTraverser ct = new ComponentTraverser(dirtyV, getContentPane(), false);
      ct.visitAll(null);
     
      int dCnt = dirties.size();
      if (dCnt > 0) { // collect the redraw dirties command
        try {     
          JSONObject root = new JSONObject();
          root.put("cc", dirties.size());
          root.put("wts", timestamp);
          JSONArray ja = new JSONArray();
          root.put("cps", ja);
         
          GlobalSettings gsettings = wbackofficeImpl.getGlobalSettings();
         
          synchronized(render_mutex) { //o_clusterOK by:fj
            // we let all dirty components render themselves.
            // not offered (since not usability-useful) is the include of new js-libraries and css-libraries here, since this may invoke a screen reload
            // which disturbes the user and lets him/her loose the focus and the cursor.
            AsyncMediaResponsible amr = null;
 
            long rstart = 0;
            if (isDebugLog) {
              rstart = System.currentTimeMillis();
              debugMsg = new StringBuilder("update:").append(String.valueOf(dCnt)).append(";");
            }
           
            for (int i = 0; i < dCnt; i++) {
              Component toRender = dirties.get(i);
              boolean wasDomR = toRender.isDomReplaceable();
              if (!wasDomR) {
                throw new AssertException("cannot replace as dom fragment:"+toRender.getComponentName()+" ("+toRender.getClass().getName()+"),"+toRender.getExtendedDebugInfo());
              }
             
              Panel wrapper = new Panel("renderpanel");
              wrapper.setDomReplaceable(false); // to omit <div> around the render helper panel
              RenderResult renderResult = null;
              StringOutput jsol = new StringOutput();
              StringOutput hdr = new StringOutput();
              String result = null;
              try {
                toRender.setDomReplaceable(false);
                wrapper.setContent(toRender);
                String newTimestamp = String.valueOf(timestamp);
                URLBuilder ubu = new URLBuilder(uriPrefix,getInstanceId(), newTimestamp,wbackofficeImpl);

                renderResult = new RenderResult();

                // if we have an around-component-interception
                // set the handler for this render cycle
                InterceptHandler interceptHandler = wbackofficeImpl.getInterceptHandler();
                if (interceptHandler != null) {
                  InterceptHandlerInstance dhri = interceptHandler.createInterceptHandlerInstance();
                  renderResult.setInterceptHandlerRenderInstance(dhri);
                }

                Renderer fr = Renderer.getInstance(wrapper,null, ubu, renderResult, gsettings);

                jsol = new StringOutput();
                fr.renderBodyOnLoadJSFunctionCall(jsol,toRender);

                hdr = new StringOutput();
                fr.renderHeaderIncludes(hdr, toRender);

                long pstart = 0;
                if (isDebugLog) {
                  pstart = System.currentTimeMillis();
                }
                result = fr.render(toRender).toString();
                if (isDebugLog) {
                  long pstop = System.currentTimeMillis();
                  debugMsg.append(toRender.getComponentName()).append(":").append((pstop - pstart));
                  if (i < dCnt - 1)
                    debugMsg.append(",");
                }
              } catch (Exception e) {
                throw new OLATRuntimeException(Window.class,renderResult.getLogMsg(), renderResult.getRenderException());
              } finally {
                toRender.setDomReplaceable(true);
              }
              if (renderResult.getRenderException() != null) throw new OLATRuntimeException(Window.class, renderResult.getLogMsg(),
                  renderResult.getRenderException());
             
              AsyncMediaResponsible curAmr = renderResult.getAsyncMediaResponsible();
              if (curAmr != null) {
                if (amr != null) {
                  throw new AssertException("can set amr only once in a screen!");
                } else {
                  amr = curAmr;
                }
              }
             
              JSONObject jo = new JSONObject();
              long cid = toRender.getDispatchID();
              if (Settings.isDebuging()) {
                // for debugging only
                jo.put("cname", toRender.getComponentName());
                jo.put("clisteners",toRender.getListenerInfo());
                jo.put("hfragsize", result.length());
              }           
             
              jo.put("cid", cid);
              jo.put("cidvis", toRender.isVisible());
              jo.put("hfrag", result);
              jo.put("jsol", jsol);
              jo.put("hdr", hdr);
              ja.put(jo);
            }
            //polling case should never set the asyncMediaResp.
            //to null otherwise it possible that e.g. pdf served as following click within a CP component
            if (amr != null) setAsyncMediaResponsible(amr);
                     
            if (isDebugLog) {
              long rstop = System.currentTimeMillis();
              debugMsg.append(";inl_part_render:").append((rstop-rstart));
              Tracing.logDebug(debugMsg.toString(), Window.class);
            }
          }
          com = CommandFactory.createDirtyComponentsCommand();
          com.setSubJSON(root);
          return com;
         
        } catch (JSONException e) {
          throw new AssertException("wrong data put into json object", e);
        }
View Full Code Here

TOP

Related Classes of org.olat.core.gui.control.winmgr.Command

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.