01 package ch.goodsolutions.demo.basics;
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.gui.control.generic.dialog.DialogController;
14
15 public class SimpleDemoController extends BasicController {
16 // our components
17 private VelocityContainer mainVC;
18 private Link simpleLink;
19 private Link anotherButton;
20 private Panel content_A;
21 private Panel content_B;
22
23 // a simple subcontroller we use
24 private DialogController dialogC;
25
26 public SimpleDemoController(UserRequest ureq, WindowControl wControl) {
27 super(ureq, wControl);
28 // create the main template for this demo controller
29 mainVC = createVelocityContainer("index");
30
31 // create a yet empty panel and put it into the main template
32 content_A = new Panel("content_A");
33 // 'content1' is the name how we like to reference it from within the template
34 mainVC.put("content1", content_A);
35
36 // create a yet empty panel and put it into the main template
37 content_B = new Panel("content_B");
38 // 'content2' is the name how we like to reference it from within the template
39 mainVC.put("content2", content_B);
40
41
42 // create a link (button)
43 simpleLink = LinkFactory.createButtonSmall("simpleLink", mainVC, this);
44 // init main template
45 putInitialPanel(mainVC);
46 }
47
48 protected void event(UserRequest ureq, Component source, Event event) {
49 if (source == simpleLink) {
50 VelocityContainer sampleVC = createVelocityContainer("sample");
51 anotherButton = LinkFactory.createButtonSmall("anotherButton", sampleVC, this);
52 content_A.setContent(sampleVC);
53 dialogC = DialogController.createOkCancelDialogController(ureq.getLocale(), translate("question"), this);
54 content_B.setContent(dialogC.getInitialComponent());
55 } else if (source == anotherButton) {
56 content_A.setContent(null);
57 }
58 }
59
60 protected void event(UserRequest ureq, Controller source, Event event) {
61 // if we get the answer from the dialogcontroller, we inform the user
62 if (source == dialogC) {
63 if (event == DialogController.EVENT_FIRSTBUTTON) {
64 // ok, since ok/cancel dialog
65 showInfo("dialog.ok.chosen", null);
66 } // else cancelled, show nothing
67 // in all cases, emtpy the panel holding the dialog
68 content_B.setContent(null);
69 }
70 }
71
72 protected void doDispose() {
73 if (dialogC != null) dialogC.dispose();
74 }
75
76 }
|