001 package org.springframework.richclient.widget;
002
003 import org.springframework.richclient.form.AbstractForm;
004 import org.springframework.richclient.form.ValidationResultsReporter;
005 import org.springframework.richclient.dialog.Messagable;
006 import org.springframework.richclient.command.AbstractCommand;
007
008 import javax.swing.*;
009 import java.util.List;
010 import java.util.Collections;
011
012 /**
013 * A decorator to add a {@link org.springframework.richclient.dialog.TitlePane} to a {@link org.springframework.richclient.form.Form}. Adds the commit command as a default widget
014 * command to show.
015 *
016 * TODO check all widget functionality
017 *
018 * @author Jan Hoskens
019 *
020 */
021 public class TitledWidgetForm extends AbstractTitledWidget
022 {
023
024 private AbstractForm form;
025
026 /**
027 * Set the inner form that needs decorating.
028 */
029 public void setForm(AbstractForm form)
030 {
031 this.form = form;
032 }
033
034 /**
035 * Returns the form.
036 */
037 public AbstractForm getForm()
038 {
039 return form;
040 }
041
042 @Override
043 public JComponent createWidgetContent()
044 {
045 newSingleLineResultsReporter(this);
046 return getForm().getControl();
047 }
048
049 @Override
050 public List<? extends AbstractCommand> getCommands()
051 {
052 return Collections.emptyList();
053 }
054
055 @Override
056 public ValidationResultsReporter newSingleLineResultsReporter(Messagable messagable)
057 {
058 return getForm().newSingleLineResultsReporter(this);
059 }
060
061 @Override
062 public void onAboutToHide()
063 {
064 super.onAboutToHide();
065 // NOTE in future form should be a widget
066 if (form instanceof Widget)
067 ((Widget) form).onAboutToHide();
068 }
069
070 @Override
071 public void onAboutToShow()
072 {
073 super.onAboutToShow();
074 // NOTE in future form should be a widget
075 if (form instanceof Widget)
076 ((Widget) form).onAboutToShow();
077 }
078 }
079