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.showcase;
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
026     * well defined points within its lifecycle.
027     * 
028     * @author Keith Donald
029     */
030    public class ShowcaseLifecycleAdvisor extends DefaultApplicationLifecycleAdvisor {
031    
032        private final Log logger = LogFactory.getLog(getClass());
033    
034        /**
035         * This method is called prior to the opening of an application window. Note
036         * at this point the window control has not been created. This hook allows
037         * programmatic control over the configuration of the window (by setting
038         * properties on the configurer) and it provides a hook where code that
039         * needs to be executed prior to the window opening can be plugged in (like
040         * a startup wizard, for example).
041         * 
042         * @param configurer The application window configurer
043         */
044        public void onPreWindowOpen( ApplicationWindowConfigurer configurer ) {
045    
046            // If you override this method, it is critical to allow the superclass
047            // implementation to run as well.
048            super.onPreWindowOpen(configurer);
049    
050            // Uncomment to hide the menubar, toolbar, or alter window size...
051            // configurer.setShowMenuBar(false);
052            // configurer.setShowToolBar(false);
053            // configurer.setInitialSize(new Dimension(640, 480));
054        }
055    
056        /**
057         * Called just after the command context has been internalized. At this
058         * point, all the commands for the window have been created and are
059         * available for use. If you need to force the execution of a command prior
060         * to the display of an application window (like a login command), this is
061         * where you'd do it.
062         * 
063         * @param window The window who's commands have just been created
064         */
065        public void onCommandsCreated( ApplicationWindow window ) {
066            if( logger.isInfoEnabled() ) {
067                logger.info("onCommandsCreated( windowNumber=" + window.getNumber() + " )");
068            }
069        }
070    
071        /**
072         * Called after the actual window control has been created.
073         * 
074         * @param window The window being processed
075         */
076        public void onWindowCreated( ApplicationWindow window ) {
077            if( logger.isInfoEnabled() ) {
078                logger.info("onWindowCreated( windowNumber=" + window.getNumber() + " )");
079            }
080        }
081    
082        /**
083         * Called immediately after making the window visible.
084         * 
085         * @param window The window being processed
086         */
087        public void onWindowOpened( ApplicationWindow window ) {
088            if( logger.isInfoEnabled() ) {
089                logger.info("onWindowOpened( windowNumber=" + window.getNumber() + " )");
090            }
091        }
092    
093        /**
094         * Called when the window is being closed. This hook allows control over
095         * whether the window is allowed to close. By returning false from this
096         * method, the window will not be closed.
097         * 
098         * @return boolean indicator if window should be closed. <code>true</code>
099         *         to allow the close, <code>false</code> to prevent the close.
100         */
101        public boolean onPreWindowClose( ApplicationWindow window ) {
102            if( logger.isInfoEnabled() ) {
103                logger.info("onPreWindowClose( windowNumber=" + window.getNumber() + " )");
104            }
105            return true;
106        }
107    
108        /**
109         * Called when the application has fully started. This is after the initial
110         * application window has been made visible.
111         */
112        public void onPostStartup() {
113            if( logger.isInfoEnabled() ) {
114                logger.info("onPostStartup()");
115            }
116        }
117    
118    }