001: package org.dbbrowser.ui.helper.exporthelper.wizard.panel;
002:
003: import infrastructure.internationalization.InternationalizationManager;
004: import java.awt.BorderLayout;
005: import java.awt.Dimension;
006: import java.awt.event.ActionEvent;
007: import java.awt.event.ActionListener;
008: import java.io.File;
009: import javax.swing.BorderFactory;
010: import javax.swing.BoxLayout;
011: import javax.swing.ButtonGroup;
012: import javax.swing.JButton;
013: import javax.swing.JFileChooser;
014: import javax.swing.JPanel;
015: import javax.swing.JRadioButton;
016: import javax.swing.JTextField;
017: import org.dbbrowser.ui.UIControllerForQueries;
018: import org.dbbrowser.ui.helper.exporthelper.wizard.WizardState;
019:
020: /**
021: * Panel to get the export type from the user
022: * @author amangat
023: *
024: */
025: public class ExportTypeWizardPanel extends AbstractWizardPanel
026: implements ActionListener {
027: private static final long serialVersionUID = UIControllerForQueries.version;
028:
029: public static final String PDF = "pdf";
030: public static final String CSV = "csv";
031: public static final String EXCEL = "xls";
032: public static final String SQL = "sql";
033:
034: private ButtonGroup buttonGroup = new ButtonGroup();
035:
036: private static final String PANEL_TITLE = InternationalizationManager
037: .getInstance().getMessage("dbbrowser-export-wizard",
038: "dbbrowser-ui-export-wizard-export-panel-title",
039: null);;
040: private static final String SAVE_AS_BUTTON_LABEL = InternationalizationManager
041: .getInstance().getMessage("dbbrowser-export-wizard",
042: "dbbrowser-ui-export-wizard-save-as-button-label",
043: null);;
044: private String locationOfFileToExportTo = "export";
045: private JTextField fieldForFilename = null;
046: private static final String SAVE_AS_BUTTON_ACTION_COMMAND = "SAVE_AS";
047:
048: /**
049: * Constructer
050: */
051: public ExportTypeWizardPanel() {
052: super (PANEL_TITLE);
053:
054: //Set the default export type to be CSV
055: WizardState.getInstance().setState("Export type", CSV);
056: WizardState.getInstance().setState("Save as",
057: locationOfFileToExportTo + "." + CSV);
058:
059: this .add(setupPanel(), BorderLayout.CENTER);
060: }
061:
062: public void actionPerformed(ActionEvent e) {
063: if (SAVE_AS_BUTTON_ACTION_COMMAND.equals(e.getActionCommand())) {
064: JFileChooser jfc = new JFileChooser(".");
065: int ans = jfc.showSaveDialog(null);
066: if (JFileChooser.APPROVE_OPTION == ans) {
067: File selectedFile = jfc.getSelectedFile();
068: this .fieldForFilename.setText(selectedFile
069: .getAbsolutePath());
070: WizardState.getInstance().setState("Save as",
071: selectedFile.getAbsolutePath());
072: }
073: } else {
074: //Store the state in the WizardState
075: WizardState.getInstance().setState("Export type",
076: e.getActionCommand());
077: WizardState.getInstance().setState(
078: "Save as",
079: locationOfFileToExportTo + "."
080: + e.getActionCommand());
081: File f = new File(locationOfFileToExportTo + "."
082: + e.getActionCommand());
083: this .fieldForFilename.setText(f.getAbsolutePath());
084: }
085: }
086:
087: private JPanel setupPanel() {
088: JPanel panel = new JPanel();
089: panel.setBorder(BorderFactory.createEtchedBorder());
090: panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
091:
092: //Add the radio button for export type
093: JRadioButton csvRadioButton = new JRadioButton(CSV);
094: JRadioButton pdfRadioButton = new JRadioButton(PDF);
095: JRadioButton excelRadioButton = new JRadioButton(EXCEL);
096: JRadioButton sqlRadioButton = new JRadioButton(SQL);
097: buttonGroup.add(pdfRadioButton);
098: buttonGroup.add(csvRadioButton);
099: buttonGroup.add(excelRadioButton);
100: buttonGroup.add(sqlRadioButton);
101: pdfRadioButton.addActionListener(this );
102: csvRadioButton.addActionListener(this );
103: excelRadioButton.addActionListener(this );
104: sqlRadioButton.addActionListener(this );
105: csvRadioButton.setSelected(true);
106:
107: //Add the buttons
108: panel.add(csvRadioButton);
109: panel.add(pdfRadioButton);
110: panel.add(excelRadioButton);
111: panel.add(sqlRadioButton);
112:
113: //Add the textfield and button for location of file
114: File f = new File(locationOfFileToExportTo + "." + CSV);
115: this .fieldForFilename = new JTextField(f.getAbsolutePath());
116: JButton buttonForFile = new JButton(SAVE_AS_BUTTON_LABEL);
117: buttonForFile.setActionCommand(SAVE_AS_BUTTON_ACTION_COMMAND);
118: buttonForFile.addActionListener(this );
119: JPanel panelForFileLocation = new JPanel();
120: panelForFileLocation.setLayout(new BoxLayout(
121: panelForFileLocation, BoxLayout.X_AXIS));
122: panelForFileLocation.add(fieldForFilename);
123: panelForFileLocation.add(buttonForFile);
124: panelForFileLocation.setMaximumSize(new Dimension(
125: panelForFileLocation.getMaximumSize().width, 20));
126: panel.add(panelForFileLocation);
127:
128: return panel;
129: }
130: }
|