001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.impl.wsdl.actions.iface.tools.support;
014:
015: import java.awt.BorderLayout;
016: import java.awt.Color;
017: import java.awt.Component;
018: import java.awt.Dimension;
019: import java.awt.HeadlessException;
020: import java.awt.event.ActionEvent;
021:
022: import javax.swing.AbstractAction;
023: import javax.swing.BorderFactory;
024: import javax.swing.JButton;
025: import javax.swing.JDialog;
026: import javax.swing.JLabel;
027: import javax.swing.JScrollPane;
028: import javax.swing.JTextArea;
029:
030: import com.eviware.soapui.support.UISupport;
031: import com.jgoodies.forms.builder.ButtonBarBuilder;
032:
033: /**
034: * Action to display the contents of a generated configuration file
035: *
036: * @author ole.matzura
037: */
038:
039: public abstract class ShowConfigFileAction extends AbstractAction {
040: private ContentDialog dialog;
041: private final String title;
042: private final String description;
043:
044: public ShowConfigFileAction(String title, String description) {
045: super ("Show Config");
046:
047: this .title = title;
048: this .description = description;
049: }
050:
051: public void actionPerformed(ActionEvent e) {
052: if (dialog == null)
053: dialog = new ContentDialog(title, description);
054:
055: dialog.showDialog();
056: }
057:
058: protected abstract String getConfigFile();
059:
060: public class ContentDialog extends JDialog {
061: private JTextArea contentArea;
062:
063: public ContentDialog(String title, String description)
064: throws HeadlessException {
065: super (UISupport.getMainFrame());
066: setTitle(title);
067: setModal(true);
068:
069: getContentPane().setLayout(new BorderLayout());
070: JLabel label = new JLabel(description);
071: label.setBorder(BorderFactory.createEmptyBorder(10, 10, 0,
072: 10));
073: getContentPane().add(label, BorderLayout.NORTH);
074: getContentPane().add(buildContent(), BorderLayout.CENTER);
075:
076: ButtonBarBuilder builder = ButtonBarBuilder
077: .createLeftToRightBuilder();
078: builder.addGlue();
079: builder.addFixed(new JButton(new CloseAction()));
080:
081: builder.setBorder(BorderFactory.createEmptyBorder(0, 10,
082: 10, 10));
083: getContentPane()
084: .add(builder.getPanel(), BorderLayout.SOUTH);
085:
086: pack();
087: }
088:
089: public void showDialog() {
090: contentArea.setText(getConfigFile());
091: setVisible(true);
092: }
093:
094: private Component buildContent() {
095: contentArea = new JTextArea();
096: contentArea.setEditable(false);
097: contentArea.setBackground(Color.WHITE);
098: JScrollPane scrollPane = new JScrollPane(contentArea);
099: scrollPane.setPreferredSize(new Dimension(500, 300));
100:
101: return UISupport.wrapInEmptyPanel(scrollPane, BorderFactory
102: .createEmptyBorder(10, 10, 10, 10));
103: }
104:
105: private final class CloseAction extends AbstractAction {
106: public CloseAction() {
107: super ("Close");
108: }
109:
110: public void actionPerformed(ActionEvent e) {
111: setVisible(false);
112: }
113: }
114: }
115: }
|