001    /*
002     * Copyright 2002-2004 the original author or authors.
003     * 
004     * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005     * use this file except in compliance with the License. You may obtain a copy of
006     * the License at
007     * 
008     * http://www.apache.org/licenses/LICENSE-2.0
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012     * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013     * License for the specific language governing permissions and limitations under
014     * the License.
015     */
016    package org.springframework.richclient.samples.simple.app;
017    
018    import org.apache.commons.logging.Log;
019    import org.apache.commons.logging.LogFactory;
020    import org.springframework.richclient.application.ApplicationWindow;
021    import org.springframework.richclient.application.config.ApplicationWindowConfigurer;
022    import org.springframework.richclient.application.config.DefaultApplicationLifecycleAdvisor;
023    
024    /**
025     * Custom application lifecycle implementation that configures the sample app at well defined points within its
026     * lifecycle.
027     * @author Keith Donald
028     */
029    public class SimpleLifecycleAdvisor extends DefaultApplicationLifecycleAdvisor {
030    
031            private final Log logger = LogFactory.getLog(getClass());
032    
033            /**
034             * This method is called prior to the opening of an application window. Note at this point the window control has
035             * not been created. This hook allows programmatic control over the configuration of the window (by setting
036             * properties on the configurer) and it provides a hook where code that needs to be executed prior to the window
037             * opening can be plugged in (like a startup wizard, for example).
038             * @param configurer The application window configurer
039             */
040            public void onPreWindowOpen(ApplicationWindowConfigurer configurer) {
041    
042                    // If you override this method, it is critical to allow the superclass
043                    // implementation to run as well.
044                    super.onPreWindowOpen(configurer);
045    
046                    // Uncomment to hide the menubar, toolbar, or alter window size...
047                    // configurer.setShowMenuBar(false);
048                    // configurer.setShowToolBar(false);
049                    // configurer.setInitialSize(new Dimension(640, 480));
050            }
051    
052            /**
053             * Called just after the command context has been internalized. At this point, all the commands for the window have
054             * been created and are available for use. If you need to force the execution of a command prior to the display of
055             * an application window (like a login command), this is where you'd do it.
056             * @param window The window who's commands have just been created
057             */
058            public void onCommandsCreated(ApplicationWindow window) {
059                    if (logger.isInfoEnabled()) {
060                            logger.info("onCommandsCreated( windowNumber=" + window.getNumber() + " )");
061                    }
062            }
063    
064            /**
065             * Called after the actual window control has been created.
066             * @param window The window being processed
067             */
068            public void onWindowCreated(ApplicationWindow window) {
069                    if (logger.isInfoEnabled()) {
070                            logger.info("onWindowCreated( windowNumber=" + window.getNumber() + " )");
071                    }
072            }
073    
074            /**
075             * Called immediately after making the window visible.
076             * @param window The window being processed
077             */
078            public void onWindowOpened(ApplicationWindow window) {
079                    if (logger.isInfoEnabled()) {
080                            logger.info("onWindowOpened( windowNumber=" + window.getNumber() + " )");
081                    }
082            }
083    
084            /**
085             * Called when the window is being closed. This hook allows control over whether the window is allowed to close. By
086             * returning false from this method, the window will not be closed.
087             * @return boolean indicator if window should be closed. <code>true</code> to allow the close, <code>false</code>
088             * to prevent the close.
089             */
090            public boolean onPreWindowClose(ApplicationWindow window) {
091                    if (logger.isInfoEnabled()) {
092                            logger.info("onPreWindowClose( windowNumber=" + window.getNumber() + " )");
093                    }
094                    return true;
095            }
096    
097            /**
098             * Called when the application has fully started. This is after the initial application window has been made
099             * visible.
100             */
101            public void onPostStartup() {
102                    if (logger.isInfoEnabled()) {
103                            logger.info("onPostStartup()");
104                    }
105            }
106    
107    }