001 package org.springframework.richclient.form.builder.support;
002
003 import java.awt.event.FocusEvent;
004 import java.awt.event.FocusListener;
005
006 import javax.swing.JComponent;
007
008 import org.springframework.richclient.application.Application;
009
010 /**
011 * Abstract base class for showing text in the status bar when the form
012 * component gains focus.
013 *
014 * @author Peter De Bruycker
015 */
016 public abstract class AbstractFormComponentStatusBarInterceptor extends AbstractFormComponentInterceptor {
017
018 protected abstract String getStatusBarText(String propertyName);
019
020 public void processComponent(final String propertyName, final JComponent component) {
021 component.addFocusListener(new FocusListener() {
022 public void focusGained(FocusEvent e) {
023 if (Application.instance().getActiveWindow() != null) {
024 String caption = getStatusBarText(propertyName);
025 if (caption != null) {
026 Application.instance().getActiveWindow().getStatusBar().setMessage(caption);
027 }
028 }
029 }
030
031 public void focusLost(FocusEvent e) {
032 if (Application.instance().getActiveWindow() != null) {
033 Application.instance().getActiveWindow().getStatusBar().setMessage("");
034 }
035 }
036 });
037 }
038 }