001    package org.springframework.richclient.samples.showcase.util;
002    
003    import java.awt.Dimension;
004    
005    import javax.swing.JComponent;
006    import javax.swing.JPanel;
007    import javax.swing.JScrollPane;
008    import javax.swing.JSplitPane;
009    import javax.swing.JTextArea;
010    import javax.swing.ScrollPaneConstants;
011    
012    import org.springframework.richclient.command.AbstractCommand;
013    import org.springframework.richclient.command.ActionCommand;
014    import org.springframework.richclient.command.CommandGroup;
015    import org.springframework.richclient.dialog.TitledApplicationDialog;
016    import org.springframework.util.Assert;
017    
018    import com.jgoodies.forms.factories.FormFactory;
019    import com.jgoodies.forms.layout.CellConstraints;
020    import com.jgoodies.forms.layout.ColumnSpec;
021    import com.jgoodies.forms.layout.FormLayout;
022    import com.jgoodies.forms.layout.FormSpec;
023    import com.jgoodies.forms.layout.RowSpec;
024    import com.jgoodies.forms.layout.Sizes;
025    
026    public abstract class AbstractReporterTitledApplicationDialog extends TitledApplicationDialog {
027    
028            private ActionCommand clearTextAreaCommand;
029    
030            private JTextArea messageArea;
031    
032            /**
033             * Returns the textArea to append info.
034             */
035            public JTextArea getMessageArea() {
036                    return messageArea;
037            }
038    
039            public ActionCommand getClearTextAreaCommand() {
040                    if (this.clearTextAreaCommand == null) {
041                            this.clearTextAreaCommand = new ActionCommand(getClearTextAreaCommandFaceDescriptorId()) {
042    
043                                    protected void doExecuteCommand() {
044                                            getMessageArea().setText(null);
045                                    }
046                            };
047                            getCommandConfigurer().configure(this.clearTextAreaCommand);
048                    }
049                    return this.clearTextAreaCommand;
050            }
051    
052            protected String getClearTextAreaCommandFaceDescriptorId() {
053                    return "reporterDialog.clearTextAreaCommand";
054            }
055    
056            abstract protected Reporter getReporter();
057    
058            @Override
059            protected JComponent createTitledDialogContentPane() {
060                    messageArea = new JTextArea();
061                    messageArea.setEditable(false);
062                    Reporter reporter = getReporter();
063                    Assert.notNull(reporter);
064                    reporter.setMessageArea(messageArea);
065    
066                    JPanel panel = new JPanel(new FormLayout(new ColumnSpec[] {
067                                    new ColumnSpec(ColumnSpec.FILL, Sizes.PREFERRED, FormSpec.DEFAULT_GROW),
068                                    FormFactory.UNRELATED_GAP_COLSPEC, new ColumnSpec(ColumnSpec.FILL, Sizes.DEFAULT, FormSpec.NO_GROW) },
069                                    new RowSpec[] { new RowSpec(RowSpec.FILL, Sizes.DEFAULT, FormSpec.DEFAULT_GROW), }));
070                    CellConstraints cc = new CellConstraints();
071                    panel.add(reporter.getControl(), cc.xy(1, 1));
072                    AbstractCommand[] reporterCommands = reporter.getReporterCommands();
073                    AbstractCommand[] commandStack = new AbstractCommand[reporterCommands.length + 1];
074                    System.arraycopy(reporterCommands, 0, commandStack, 0, reporterCommands.length);
075                    commandStack[reporterCommands.length] = getClearTextAreaCommand();
076                    CommandGroup commandGroup = CommandGroup.createCommandGroup(commandStack);
077                    panel.add(commandGroup.createButtonStack(), cc.xy(3, 1));
078                    JScrollPane scrollPane = new JScrollPane(messageArea,
079                                    ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
080                    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, panel, scrollPane);
081                    scrollPane.setPreferredSize(new Dimension(200, 100));
082                    return splitPane;
083            }
084    
085            @Override
086            protected boolean onFinish() {
087                    return true;
088            }
089    
090    }