Package org.olat.test.guidemo

Source Code of org.olat.test.guidemo.GuiDemoPushPopController

/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <p>
*/

package org.olat.test.guidemo;

import java.util.Stack;

import org.olat.core.commons.fullWebApp.LayoutMain3ColsController;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.Component;
import org.olat.core.gui.components.link.Link;
import org.olat.core.gui.components.link.LinkFactory;
import org.olat.core.gui.components.velocity.VelocityContainer;
import org.olat.core.gui.control.Event;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.gui.control.controller.BasicController;
import org.olat.core.gui.control.generic.layout.MainLayoutController;

public class GuiDemoPushPopController extends BasicController {
 
  VelocityContainer vcMain, vcPush;
  Stack windowStack = new Stack();
  private Link pushButton;
  private Link popButton;
 
  public GuiDemoPushPopController(UserRequest ureq, WindowControl wControl) {
    super(ureq,wControl);
   
    vcMain = this.createVelocityContainer("guidemo-pushpop");
    pushButton = LinkFactory.createButton("guidemo.window.control.push", vcMain, this);
    popButton = LinkFactory.createButton("guidemo.window.control.pop", vcMain, this);
   
    vcMain.contextPut("stack", getStackHTMLRepresentation());   
    LayoutMain3ColsController layoutCtr = new LayoutMain3ColsController(ureq, getWindowControl(), null, null, vcMain, null);
    listenTo(layoutCtr);
   
    this.putInitialPanel(layoutCtr.getInitialComponent());
  }

  public void event(UserRequest ureq, Component source, Event event) {
    if (source == pushButton){     
      VelocityContainer container = this.createVelocityContainer("guidemo-pushpop");
      LayoutMain3ColsController layoutCtr = new LayoutMain3ColsController(ureq, getWindowControl(), null, null, container, null);
      listenTo(layoutCtr);
      windowStack.push(layoutCtr.getInitialComponent());
     
      container.put("guidemo.window.control.push", pushButton);
      container.put("guidemo.window.control.pop", popButton);
      container.contextPut("stack", getStackHTMLRepresentation());
      getWindowControl().pushToMainArea(container);
    }
    else if (source == popButton){
      if (windowStack.isEmpty()) {
        fireEvent(ureq, Event.DONE_EVENT);
      } else {
        getWindowControl().pop();
        windowStack.pop();
      }
    }
  }

  private String getStackHTMLRepresentation() {
    StringBuilder result = new StringBuilder();
    result.append("Current window stack:<br /><br />");
    for (int i = windowStack.size(); i > 0; i--) {
      Component component = (Component)windowStack.get(i-1);
      result.append("Stack position " + i + ": " + component.getComponentName() + "<br />");
    }
    return result.toString();
  }
 
  protected void doDispose() {
  }

}
TOP

Related Classes of org.olat.test.guidemo.GuiDemoPushPopController

TOP
Copyright © 2018 www.massapi.com. 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.