UsingServiceDemoController.java
01 package ch.goodsolutions.demo.soa.usersearch;
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 import org.olat.core.service.ServiceFactory;
14 
15 import ch.goodsolutions.services.user.bl.User;
16 import ch.goodsolutions.services.user.ui.UserSearchUIService;
17 
18 public class UsingServiceDemoController extends BasicController {
19   private VelocityContainer mainVC;
20   private Link searchUserLink;
21   private Panel contentPanel_A;
22   private Controller searchController;
23     
24   public UsingServiceDemoController(UserRequest ureq, WindowControl wControl) {
25     super(ureq, wControl);
26     // create the main template for this demo controller
27     mainVC = createVelocityContainer("index");
28     // create a link (button)
29     searchUserLink = LinkFactory.createButtonSmall("searchUserLink", mainVC, this);
30     // create a new, initially empty panel to later show the user search in it
31     contentPanel_A = new Panel("content A");
32     mainVC.put("content_A", contentPanel_A);
33     // init main template
34     putInitialPanel(mainVC);
35   }
36 
37   protected void event(UserRequest ureq, Component source, Event event) {
38     if (source == searchUserLink) {
39       // 1. get the user search service
40       UserSearchUIService searchUIService = (UserSearchUIServiceServiceFactory.getService(UserSearchUIService.class);
41       // 2. prepare all arguments and let the controller create
42       searchController = searchUIService.createUserSearchController(ureq, getWindowControl()/*listener*/ this, false, false);      
43       // and position it on the screen
44       contentPanel_A.setContent(searchController.getInitialComponent());
45       // to be perfect, we say that we cannot "browser-back" this step
46       ignoreEventInHistory();
47     }
48   }
49 
50 
51   protected void event(UserRequest ureq, Controller source, Event event) {
52     if (source == searchController) {
53       // 1. get the user search service
54       UserSearchUIService searchUIService = (UserSearchUIServiceServiceFactory.getService(UserSearchUIService.class);
55       User user = searchUIService.getChosenUser(event);
56       if (user != null) {
57         // the user chose a user
58         showInfo("user.chosen", user.getIdentity().getName());
59       }
60       // clear the search from screen and dispose the controller
61       contentPanel_A.setContent(null);
62       searchController.dispose();
63     }
64   }
65 
66   protected void doDispose() {
67     // dispose child controller, if there is one
68     if (searchController != nullsearchController.dispose();
69   }
70 
71 }