001: package org.dbbrowser.ui.panel.dbbrowserwindow;
002:
003: import infrastructure.internationalization.InternationalizationManager;
004: import infrastructure.logging.Log;
005: import infrastructure.propertymanager.PropertyManager;
006: import java.awt.*;
007: import java.awt.event.ActionEvent;
008: import java.awt.event.ActionListener;
009: import java.util.ArrayList;
010: import java.util.List;
011: import javax.swing.*;
012: import javax.swing.event.ChangeListener;
013: import javax.swing.event.ChangeEvent;
014: import org.dbbrowser.db.engine.model.DBTable;
015: import org.dbbrowser.db.engine.exception.DBEngineException;
016: import org.dbbrowser.ui.helper.DBTableDataTableModel;
017: import org.dbbrowser.ui.UIControllerForQueries;
018: import org.dbbrowser.ui.UIControllerForUpdates;
019: import org.dbbrowser.ui.panel.ButtonsPanel;
020: import org.dbbrowser.ui.widget.Button;
021: import org.dbbrowser.ui.widget.Table;
022: import org.dbbrowser.drivermanager.ConnectionInfo;
023:
024: public class DBTableSequencesPanel extends JPanel implements
025: ActionListener, ChangeListener {
026: private static final long serialVersionUID = UIControllerForQueries.version;
027:
028: private String addNewRecordIconFileName = PropertyManager
029: .getInstance()
030: .getProperty(
031: "dbbrowser-ui-dbbrowser-window-add-new-record-icon");
032: private String deleteRecordIconFileName = PropertyManager
033: .getInstance().getProperty(
034: "dbbrowser-ui-dbbrowser-window-delete-record-icon");
035:
036: private Icon iconForAddNewRecordButton = new ImageIcon(
037: addNewRecordIconFileName);
038: private Icon iconForDeleteRecordButton = new ImageIcon(
039: deleteRecordIconFileName);
040:
041: private static final String TITLE = InternationalizationManager
042: .getInstance().getMessage("dbbrowser-ui",
043: "dbbrowser-ui-dbbrowser-window-title-label", null);;
044: private static final String ADD_NEW_SEQUENCE_BUTTON_LABEL = InternationalizationManager
045: .getInstance()
046: .getMessage(
047: "dbbrowser-ui",
048: "dbbrowser-ui-dbbrowser-browser-tab-table-sequences-panel-add-new-sequence-button-label",
049: null);;
050: private static final String REMOVE_SEQUENCE_BUTTON_LABEL = InternationalizationManager
051: .getInstance()
052: .getMessage(
053: "dbbrowser-ui",
054: "dbbrowser-ui-dbbrowser-browser-tab-table-sequences-panel-remove-sequence-button-label",
055: null);;
056:
057: private UIControllerForQueries uiControllerForQueries = null;
058: private UIControllerForUpdates uiControllerForUpdates = null;
059: private Table tableForSequences = null;
060: private ButtonsPanel buttonsPanel = null;
061:
062: private boolean sequencesSetupCompleted = false;
063:
064: public DBTableSequencesPanel(
065: UIControllerForQueries uiControllerForQueries,
066: UIControllerForUpdates uiControllerForUpdates) {
067: this .uiControllerForQueries = uiControllerForQueries;
068: this .uiControllerForUpdates = uiControllerForUpdates;
069: initialize();
070: }
071:
072: public void refresh() {
073: showSequences();
074: }
075:
076: public void stateChanged(ChangeEvent e) {
077: //Setup sequences only if this panel has been selected
078: Object source = e.getSource();
079: if ((source != null) && (source instanceof JTabbedPane)) {
080: //Get the selected tab
081: JTabbedPane pane = (JTabbedPane) source;
082: Component selectedComponent = pane.getSelectedComponent();
083: if ((selectedComponent != null)
084: && (selectedComponent instanceof DBTableSequencesPanel)) {
085: //If sequences have not been retrieved, retrieve them and cache them
086: if (!sequencesSetupCompleted) {
087: showSequences();
088: }
089: }
090: }
091: }
092:
093: private void showSequences() {
094: try {
095: //Remove existing panels
096: if (this .tableForSequences != null) {
097: this .remove(this .tableForSequences);
098: this .remove(this .buttonsPanel);
099: }
100:
101: //Show all sequences in the database if it is a oracle database
102: ConnectionInfo ci = this .uiControllerForQueries
103: .getConnectionInfo();
104: String dbmsType = ci.getDBMSType();
105: DBTable dbTableOfSequences = this .uiControllerForQueries
106: .listSequences();
107:
108: //Add the table
109: this .tableForSequences = new Table(
110: this .uiControllerForQueries,
111: this .uiControllerForUpdates);
112: this .add(tableForSequences);
113:
114: //Set the buttons panel
115: Button addNewSequenceButton = new Button(
116: ADD_NEW_SEQUENCE_BUTTON_LABEL, this ,
117: ADD_NEW_SEQUENCE_BUTTON_LABEL,
118: iconForAddNewRecordButton, Boolean.TRUE);
119: Button removeSequenceButton = new Button(
120: REMOVE_SEQUENCE_BUTTON_LABEL, this ,
121: REMOVE_SEQUENCE_BUTTON_LABEL,
122: iconForDeleteRecordButton, Boolean.FALSE);
123: List listOfButtons = new ArrayList();
124: listOfButtons.add(addNewSequenceButton);
125: listOfButtons.add(removeSequenceButton);
126: buttonsPanel = new ButtonsPanel(listOfButtons);
127:
128: this .add(buttonsPanel);
129:
130: //Initialize table
131: this .initializeTable(dbTableOfSequences);
132:
133: sequencesSetupCompleted = true;
134: } catch (DBEngineException exc) {
135: Log.getInstance()
136: .fatalMessage(
137: exc.getClass().getName() + " - "
138: + exc.getMessage(),
139: BrowserPanel.class.getName());
140: String sqlFailedLabel = InternationalizationManager
141: .getInstance().getMessage("dbbrowser-ui",
142: "dbbrowser-ui-dbbrowser-window-sql-failed",
143: null);
144: JOptionPane.showMessageDialog(null, sqlFailedLabel + " - "
145: + exc.getMessage(), TITLE,
146: JOptionPane.ERROR_MESSAGE);
147: } catch (UnsupportedOperationException exc) {
148: ConnectionInfo ci = this .uiControllerForQueries
149: .getConnectionInfo();
150: String[] dbmsTypes = new String[] { ci.getDBMSType() };
151: String featureSupportedByDBMSLabel = InternationalizationManager
152: .getInstance()
153: .getMessage(
154: "dbbrowser-ui",
155: "dbbrowser-ui-dbbrowser-feature-not-supported-error-message",
156: dbmsTypes);
157: JLabel label = new JLabel(featureSupportedByDBMSLabel);
158: label.setHorizontalAlignment(SwingConstants.CENTER);
159: this .setLayout(new BorderLayout());
160: this .add(label);
161: }
162: }
163:
164: private void initialize() {
165: //Set the table for data
166: this .setLayout(new BoxLayout(this , BoxLayout.PAGE_AXIS));
167: }
168:
169: public void initializeTable(DBTable dbTableOfSequences) {
170: this .tableForSequences
171: .initializeTable(new DBTableDataTableModel(
172: dbTableOfSequences));
173: }
174:
175: public void actionPerformed(ActionEvent e) {
176: //Add a new column
177: if (ADD_NEW_SEQUENCE_BUTTON_LABEL.equals(e.getActionCommand())) {
178: String UNIMPLEMENTED_FEATURE_MESSAGE = InternationalizationManager
179: .getInstance()
180: .getMessage(
181: "dbbrowser-ui",
182: "dbbrowser-ui-dbbrowser-unimplemented-feature",
183: null);
184: JOptionPane.showMessageDialog(null,
185: UNIMPLEMENTED_FEATURE_MESSAGE, TITLE,
186: JOptionPane.INFORMATION_MESSAGE);
187: }
188:
189: //Remove the selected column
190: if (REMOVE_SEQUENCE_BUTTON_LABEL.equals(e.getActionCommand())) {
191: String UNIMPLEMENTED_FEATURE_MESSAGE = InternationalizationManager
192: .getInstance()
193: .getMessage(
194: "dbbrowser-ui",
195: "dbbrowser-ui-dbbrowser-unimplemented-feature",
196: null);
197: JOptionPane.showMessageDialog(null,
198: UNIMPLEMENTED_FEATURE_MESSAGE, TITLE,
199: JOptionPane.INFORMATION_MESSAGE);
200: }
201: }
202: }
|