001 /* 002 * Copyright 2002-2006 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.application.support; 017 018 import java.awt.BorderLayout; 019 020 import javax.swing.JComponent; 021 import javax.swing.JPanel; 022 023 import org.springframework.richclient.application.ApplicationPage; 024 import org.springframework.richclient.application.ApplicationWindow; 025 import org.springframework.richclient.application.PageComponent; 026 import org.springframework.richclient.application.PageComponentPane; 027 import org.springframework.richclient.application.PageDescriptor; 028 import org.springframework.richclient.application.PageLayoutBuilder; 029 030 /** 031 * Provides a standard implementation of {@link ApplicationPage} 032 */ 033 public class DefaultApplicationPage extends AbstractApplicationPage implements PageLayoutBuilder { 034 035 private JComponent control; 036 037 public DefaultApplicationPage() { 038 039 } 040 041 public DefaultApplicationPage( ApplicationWindow window, PageDescriptor pageDescriptor ) { 042 super( window, pageDescriptor ); 043 } 044 045 // Initial Application Page Layout Builder methods 046 public void addView( String viewDescriptorId ) { 047 showView( viewDescriptorId ); 048 } 049 050 protected void doAddPageComponent( PageComponent pageComponent ) { 051 // trigger the createControl method of the PageComponent, so if a 052 // PageComponentListener is added 053 // in the createControl method, the componentOpened event is received. 054 pageComponent.getControl(); 055 } 056 057 /** 058 * {@inheritDoc} 059 * 060 * Only one pageComponent is shown at a time, so if it's the active one, 061 * remove all components from this page. 062 */ 063 protected void doRemovePageComponent( PageComponent pageComponent ) { 064 if (pageComponent == getActiveComponent()) 065 { 066 this.control.removeAll(); 067 this.control.validate(); 068 this.control.repaint(); 069 } 070 } 071 072 protected boolean giveFocusTo( PageComponent pageComponent ) { 073 PageComponentPane pane = pageComponent.getContext().getPane(); 074 this.control.removeAll(); 075 this.control.add( pane.getControl() ); 076 this.control.validate(); 077 this.control.repaint(); 078 pane.getControl().requestFocusInWindow(); 079 080 return true; 081 } 082 083 protected JComponent createControl() { 084 this.control = new JPanel( new BorderLayout() ); 085 this.getPageDescriptor().buildInitialLayout( this ); 086 087 return control; 088 } 089 }