001: package org.dbbrowser.ui.helper.exporthelper.wizard.panel;
002:
003: import infrastructure.internationalization.InternationalizationManager;
004: import java.awt.BorderLayout;
005: import java.awt.event.ActionEvent;
006: import java.awt.event.ActionListener;
007: import java.util.ArrayList;
008: import java.util.Iterator;
009: import java.util.List;
010: import javax.swing.BorderFactory;
011: import javax.swing.BoxLayout;
012: import javax.swing.JCheckBox;
013: import javax.swing.JPanel;
014: import javax.swing.JScrollPane;
015: import javax.swing.table.AbstractTableModel;
016: import org.dbbrowser.ui.UIControllerForQueries;
017: import org.dbbrowser.ui.panel.ButtonsPanel;
018: import org.dbbrowser.ui.widget.Button;
019:
020: /**
021: * Panel to select columns to include in the report
022: * @author amangat
023: */
024: public class IncludeTableColumnsWizardPanel extends AbstractWizardPanel
025: implements ActionListener {
026: private static final long serialVersionUID = UIControllerForQueries.version;
027: private static final String PANEL_TITLE = InternationalizationManager
028: .getInstance()
029: .getMessage(
030: "dbbrowser-export-wizard",
031: "dbbrowser-ui-export-wizard-select-columns-to-include-panel-title",
032: null);;
033: private static final String SELECT_ALL_COLUMNS_BUTTONS_LABEL = InternationalizationManager
034: .getInstance()
035: .getMessage(
036: "dbbrowser-export-wizard",
037: "dbbrowser-ui-export-wizard-select-columns-to-include-panel-select-all-button-label",
038: null);;
039: private static final String DESELECT_ALL_COLUMNS_BUTTONS_LABEL = InternationalizationManager
040: .getInstance()
041: .getMessage(
042: "dbbrowser-export-wizard",
043: "dbbrowser-ui-export-wizard-select-columns-to-include-panel-deselect-all-button-label",
044: null);;
045:
046: private AbstractTableModel abstractTableModel = null;
047: private List listOfCheckBoxForColumns = new ArrayList();
048:
049: /**
050: * Constrcuter
051: */
052: public IncludeTableColumnsWizardPanel(
053: AbstractTableModel abstractTableModel) {
054: super (PANEL_TITLE);
055: this .abstractTableModel = abstractTableModel;
056: setupPanel();
057: }
058:
059: public List getListOfColumnsToIncludeInExport() {
060: //Iterate through each checkbox and add it to list if it is checked
061: List listOfColumnsToIncludeInExport = new ArrayList();
062: Iterator i = listOfCheckBoxForColumns.iterator();
063: while (i.hasNext()) {
064: JCheckBox box = (JCheckBox) i.next();
065:
066: //if box is checked, add it to list
067: if (box.isSelected()) {
068: listOfColumnsToIncludeInExport.add(box.getText());
069: }
070: }
071: return listOfColumnsToIncludeInExport;
072: }
073:
074: public void actionPerformed(ActionEvent e) {
075: if (SELECT_ALL_COLUMNS_BUTTONS_LABEL.equals(e
076: .getActionCommand())) {
077: Iterator i = listOfCheckBoxForColumns.iterator();
078: while (i.hasNext()) {
079: JCheckBox checkBox = (JCheckBox) i.next();
080: checkBox.setSelected(true);
081: }
082: }
083:
084: if (DESELECT_ALL_COLUMNS_BUTTONS_LABEL.equals(e
085: .getActionCommand())) {
086: Iterator i = listOfCheckBoxForColumns.iterator();
087: while (i.hasNext()) {
088: JCheckBox checkBox = (JCheckBox) i.next();
089: checkBox.setSelected(false);
090: }
091: }
092: }
093:
094: private void setupPanel() {
095: JPanel panel = new JPanel();
096: panel.setBorder(BorderFactory.createEtchedBorder());
097:
098: //Set the layout
099: panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
100:
101: //Add the widgets
102: Button buttonToSelectAllColumns = new Button(
103: SELECT_ALL_COLUMNS_BUTTONS_LABEL, this ,
104: SELECT_ALL_COLUMNS_BUTTONS_LABEL, null, Boolean.FALSE);
105: Button buttonToDeSelectAllColumns = new Button(
106: DESELECT_ALL_COLUMNS_BUTTONS_LABEL, this ,
107: DESELECT_ALL_COLUMNS_BUTTONS_LABEL, null, Boolean.FALSE);
108: List listOfButtons = new ArrayList();
109: listOfButtons.add(buttonToSelectAllColumns);
110: listOfButtons.add(buttonToDeSelectAllColumns);
111: ButtonsPanel buttonsPanel = new ButtonsPanel(listOfButtons);
112: panel.add(buttonsPanel);
113:
114: //Panel for checkboxes for columns
115: JPanel panelForCheckboxes = new JPanel();
116: panelForCheckboxes.setLayout(new BoxLayout(panelForCheckboxes,
117: BoxLayout.Y_AXIS));
118: JScrollPane pane = new JScrollPane(panelForCheckboxes);
119:
120: //Add a checkbox for each column in the table - start from 1 as the first(0) column is column header
121: if (abstractTableModel != null) {
122: for (int i = 1; i < abstractTableModel.getColumnCount(); i++) {
123: String columnName = abstractTableModel.getColumnName(i);
124: JCheckBox checkBox = new JCheckBox(columnName);
125: checkBox.setSelected(true);
126: panelForCheckboxes.add(checkBox);
127: listOfCheckBoxForColumns.add(checkBox);
128: }
129: }
130:
131: panel.add(pane);
132:
133: this.add(panel, BorderLayout.CENTER);
134: }
135: }
|