1 /*
2 * Scope: a generic MVC framework.
3 * Copyright (c) 2000-2002, Steve Meyfroidt
4 * All rights reserved.
5 * Email: smeyfroi@users.sourceforge.net
6 *
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * Neither the name "Scope" nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 *
36 *
37 * $Id: LaunchpadController.java,v 1.5 2002/06/17 09:56:00 ludovicc Exp $
38 */
39
40
41 package samples;
42
43
44 import org.scopemvc.controller.basic.BasicController;
45 import org.scopemvc.controller.basic.ViewContext;
46 import org.scopemvc.core.Control;
47 import org.scopemvc.core.ControlException;
48 import org.scopemvc.util.Debug;
49 import java.net.URL;
50 import org.apache.commons.logging.LogFactory;import org.apache.commons.logging.Log;
51
52
53 /***
54 * @author <A HREF="mailto:smeyfroi@users.sourceforge.net">Steve Meyfroidt</A>
55 * @version $Revision: 1.5 $ $Date: 2002/06/17 09:56:00 $
56 */
57 public class LaunchpadController extends BasicController {
58
59
60 private static final Log LOG = LogFactory.getLog(LaunchpadController.class);
61
62
63 /***
64 * A Control ID.
65 */
66 public static final String LAUNCH = "Launch selected example";
67
68
69 /***
70 * A Control ID.
71 */
72 public static final String SELECT = "select";
73
74
75 /***
76 * A Control ID.
77 */
78 public static final String QUIT = "Quit";
79
80
81 public LaunchpadController() {
82 setModel(new LaunchpadModel());
83 setView(new LaunchpadView());
84 }
85
86
87 /***
88 * Respond to LAUNCH and SELECT.
89 */
90 protected void doHandleControl(Control inControl) throws ControlException {
91 if (inControl.matchesID(LAUNCH)) {
92 doLaunch();
93 } else if (inControl.matchesID(SELECT)) {
94 doSelect();
95 } else if (inControl.matchesID(EXIT_CONTROL_ID)) {
96 // handle these explicitly by calling shutdown on the controller that wants to shutdown.
97 if (Debug.ON) Debug.assertTrue(inControl.getParameter() instanceof BasicController);
98 ((BasicController)inControl.getParameter()).shutdown();
99 } else if (inControl.matchesID(QUIT)) {
100 ViewContext.getViewContext().exit();
101 }
102 }
103
104
105 /***
106 * On LAUNCH, fire off a new instance of the selected
107 * example's Controller as a child of this.
108 */
109 protected void doLaunch() throws ControlException {
110 ExampleModel selected = ((LaunchpadModel)getModel()).getSelectedExample();
111 if (selected == null) {
112 return;
113 }
114 String controller = selected.getControllerName();
115 try {
116 BasicController c = (BasicController)Class.forName(controller).newInstance();
117 addChild(c);
118 c.startup();
119 } catch (Exception e) {
120 LOG.fatal("Can't launch: " + controller, e);
121 throw new ControlException("CANT_LAUNCH", controller);
122 }
123 }
124
125
126 /***
127 * On SELECT, get the view to load the appropriate HTML
128 * into the viewer pane. (Note that the selection in the model is
129 * automatically updated with the newly selected object).
130 */
131 protected void doSelect() {
132 URL url = ((LaunchpadModel)getModel()).getSelectedExample().getDocumentUrl();
133 ((LaunchpadView)getView()).showURL(url);
134 }
135
136
137 public void startup() {
138 showView();
139 }
140 }
141
This page was automatically generated by Maven