1 /*
2 * Copyright 2002-2004 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16 package de.orangecafe.amazonrcp;
17
18 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20 import org.springframework.richclient.application.ApplicationWindow;
21 import org.springframework.richclient.application.config.ApplicationWindowConfigurer;
22 import org.springframework.richclient.application.config.DefaultApplicationLifecycleAdvisor;
23 import org.springframework.richclient.command.ActionCommand;
24
25 /**
26 * Custom application lifecycle implementation that configures the sample app at
27 * well defined points within its lifecycle.
28 *
29 * @author Keith Donald
30 */
31 public class SimpleLifecycleAdvisor extends DefaultApplicationLifecycleAdvisor {
32
33 private final Log logger = LogFactory.getLog(getClass());
34
35 /**
36 * This method is called prior to the opening of an application window. Note
37 * at this point the window control has not been created. This hook allows
38 * programmatic control over the configuration of the window (by setting
39 * properties on the configurer) and it provides a hook where code that
40 * needs to be executed prior to the window opening can be plugged in (like
41 * a startup wizard, for example).
42 *
43 * @param configurer The application window configurer
44 */
45 public void onPreWindowOpen( ApplicationWindowConfigurer configurer ) {
46
47 // If you override this method, it is critical to allow the superclass
48 // implementation to run as well.
49 super.onPreWindowOpen(configurer);
50
51 // Uncomment to hide the menubar, toolbar, or alter window size...
52 // configurer.setShowMenuBar(false);
53 // configurer.setShowToolBar(false);
54 // configurer.setInitialSize(new Dimension(640, 480));
55 }
56
57 /**
58 * Called just after the command context has been internalized. At this
59 * point, all the commands for the window have been created and are
60 * available for use. If you need to force the execution of a command prior
61 * to the display of an application window (like a login command), this is
62 * where you'd do it.
63 *
64 * @param window The window who's commands have just been created
65 */
66 public void onCommandsCreated( ApplicationWindow window ) {
67 if( logger.isInfoEnabled() ) {
68 logger.info("onCommandsCreated( windowNumber=" + window.getNumber() + " )");
69 }
70 }
71
72 /**
73 * Called after the actual window control has been created.
74 *
75 * @param window The window being processed
76 */
77 public void onWindowCreated( ApplicationWindow window ) {
78 if( logger.isInfoEnabled() ) {
79 logger.info("onWindowCreated( windowNumber=" + window.getNumber() + " )");
80 }
81 }
82
83 /**
84 * Called immediately after making the window visible.
85 *
86 * @param window The window being processed
87 */
88 public void onWindowOpened( ApplicationWindow window ) {
89 if( logger.isInfoEnabled() ) {
90 logger.info("onWindowOpened( windowNumber=" + window.getNumber() + " )");
91 }
92 }
93
94 /**
95 * Called when the window is being closed. This hook allows control over
96 * whether the window is allowed to close. By returning false from this
97 * method, the window will not be closed.
98 *
99 * @return boolean indicator if window should be closed. <code>true</code>
100 * to allow the close, <code>false</code> to prevent the close.
101 */
102 public boolean onPreWindowClose( ApplicationWindow window ) {
103 if( logger.isInfoEnabled() ) {
104 logger.info("onPreWindowClose( windowNumber=" + window.getNumber() + " )");
105 }
106 return true;
107 }
108
109 /**
110 * Called when the application has fully started. This is after the initial
111 * application window has been made visible.
112 */
113 public void onPostStartup() {
114 if( logger.isInfoEnabled() ) {
115 logger.info("onPostStartup()");
116 }
117
118 ActionCommand command = (ActionCommand) getApplication().getActiveWindow().getCommandManager().getCommand("searchAmazonCommand");
119 command.execute();
120 }
121 }