ControllerDemoController.java
01 package ch.goodsolutions.demo.basics2;
02 
03 import org.olat.core.gui.UserRequest;
04 import org.olat.core.gui.components.Component;
05 import org.olat.core.gui.components.link.Link;
06 import org.olat.core.gui.components.link.LinkFactory;
07 import org.olat.core.gui.components.panel.Panel;
08 import org.olat.core.gui.components.velocity.VelocityContainer;
09 import org.olat.core.gui.control.Controller;
10 import org.olat.core.gui.control.Event;
11 import org.olat.core.gui.control.WindowControl;
12 import org.olat.core.gui.control.controller.BasicController;
13 
14 import ch.goodsolutions.services.user.ui.impl.UserSearchController;
15 import ch.goodsolutions.services.user.ui.impl.events.SingleUserChosenEvent;
16 
17 public class ControllerDemoController extends BasicController {
18   private VelocityContainer mainVC;
19   private Link simpleLink, secondLink;
20   private Panel content_A;
21 
22   private Controller userSearchController;
23   private Controller userSearchController2;
24   
25   public ControllerDemoController(UserRequest ureq, WindowControl wControl) {
26     super(ureq, wControl);
27     // create the main template for this demo controller
28     mainVC = createVelocityContainer("index");
29     // create a yet empty panel and put it into the main template
30     content_A = new Panel("content_A");
31     // 'content1' is the name how it is referenced from within the template
32     mainVC.put("content1", content_A);
33     
34     // create a link (button)
35     simpleLink = LinkFactory.createButtonSmall("simpleLink", mainVC, this);
36     
37     // create a link (button) for a later opening a modal dialog
38     secondLink = LinkFactory.createButtonSmall("secondLink", mainVC, this);
39 
40     // init main template
41     putInitialPanel(mainVC);
42   }
43 
44   protected void event(UserRequest ureq, Component source, Event event) {
45     if (source == simpleLink) {
46       userSearchController = new UserSearchController(ureq, getWindowControl(), false, false);
47       userSearchController.addControllerListener(this);
48       content_A.setContent(userSearchController.getInitialComponent());
49     else if (source == secondLink) {
50       userSearchController2 = new UserSearchController(ureq, getWindowControl(), true, false);
51       userSearchController2.addControllerListener(this);
52       getWindowControl().pushAsModalDialog(userSearchController2.getInitialComponent());
53     }
54   }
55 
56   protected void event(UserRequest ureq, Controller source, Event event) {
57     if (source == userSearchController) {
58       if (event instanceof SingleUserChosenEvent) {
59         SingleUserChosenEvent suce = (SingleUserChosenEvent)event;
60         showInfo("user.chosen", suce.getChosenUser().getLastName());
61       
62     else if (source == userSearchController2) {
63       if (event instanceof SingleUserChosenEvent) {
64         SingleUserChosenEvent suce = (SingleUserChosenEvent)event;
65         showInfo("user.chosen.modal", suce.getChosenUser().getLastName());
66       }
67       // in all cases (chosen/cancelled), remove the modal dialog
68       getWindowControl().pop();
69     }
70   }
71   
72   protected void doDispose() {
73     if (userSearchController != nulluserSearchController.dispose();
74     if (userSearchController2 != nulluserSearchController2.dispose();
75   }
76 
77 }