001 package org.springframework.richclient.widget;
002
003 import org.springframework.richclient.command.AbstractCommand;
004
005 import javax.swing.*;
006 import java.util.List;
007
008 /**
009 * Widget specifies the interface for Swing component factories
010 *
011 * General usage of implementations:
012 * <ol>
013 * <li>Instantiate the widget</li>
014 * <li>Set specific parameters for the widget or use overloaded constructors
015 * to combine this step and the previous one</li>
016 * <li>Get the component using {@link #getComponent()}</li>
017 * </ol>
018 */
019 public interface Widget
020 {
021 static Widget EMPTY_WIDGET = new AbstractWidget(){
022
023 public JComponent getComponent()
024 {
025 return new JPanel();
026 }};
027
028 /**
029 * @return A not <code>null</code> graphical component built using the
030 * parameters held in the widget instance.
031 */
032 public JComponent getComponent();
033
034 /**
035 * Hook method called before showing the component on screen.
036 */
037 public void onAboutToShow();
038
039 /**
040 * Hook method called before moving the component to the background (=hiding)
041 */
042 public void onAboutToHide();
043
044 /**
045 * Encompasses the status of the widget between onAboutToShow() and onAboutToHide().
046 * A component does not know when it's active, even if there is an isShowing() method
047 * in it's API (due to tab panels or scroll panes).
048 *
049 * @return <code>true</code> if the widget is shown in the foreground.
050 */
051 public boolean isShowing();
052
053 /**
054 * Checks whether this component can be closed visually, for example when there
055 * are no unsaved changes.
056 *
057 * @return <code>true</code> if the widget can be closed without problems.
058 */
059 public boolean canClose();
060
061 /**
062 * Returns a list of commands for this widget.
063 */
064 public List<? extends AbstractCommand> getCommands();
065 }