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.Component;
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.BoxLayout;
012: import javax.swing.Icon;
013: import javax.swing.ImageIcon;
014: import javax.swing.JOptionPane;
015: import javax.swing.JPanel;
016: import javax.swing.JTabbedPane;
017: import javax.swing.event.ChangeEvent;
018: import javax.swing.event.ChangeListener;
019: import org.dbbrowser.db.engine.exception.DBEngineException;
020: import org.dbbrowser.db.engine.model.DBTable;
021: import org.dbbrowser.ui.UIControllerForQueries;
022: import org.dbbrowser.ui.UIControllerForUpdates;
023: import org.dbbrowser.ui.helper.DBTableDataTableModel;
024: import org.dbbrowser.ui.panel.ButtonsPanel;
025: import org.dbbrowser.ui.widget.Button;
026: import org.dbbrowser.ui.widget.Table;
027:
028: public class DBIndexesPanel extends JPanel implements ActionListener,
029: ChangeListener {
030: private static final long serialVersionUID = UIControllerForQueries.version;
031:
032: private String addNewRecordIconFileName = PropertyManager
033: .getInstance()
034: .getProperty(
035: "dbbrowser-ui-dbbrowser-window-add-new-record-icon");
036: private String deleteRecordIconFileName = PropertyManager
037: .getInstance().getProperty(
038: "dbbrowser-ui-dbbrowser-window-delete-record-icon");
039:
040: private Icon iconForAddNewRecordButton = new ImageIcon(
041: addNewRecordIconFileName);
042: private Icon iconForDeleteRecordButton = new ImageIcon(
043: deleteRecordIconFileName);
044:
045: private static final String TITLE = InternationalizationManager
046: .getInstance().getMessage("dbbrowser-ui",
047: "dbbrowser-ui-dbbrowser-window-title-label", null);;
048: private static final String ADD_NEW_INDEX_BUTTON_LABEL = InternationalizationManager
049: .getInstance()
050: .getMessage(
051: "dbbrowser-ui",
052: "dbbrowser-ui-dbbrowser-indexes-tab-add-new-index-button-label",
053: null);;
054: private static final String REMOVE_INDEX_BUTTON_LABEL = InternationalizationManager
055: .getInstance()
056: .getMessage(
057: "dbbrowser-ui",
058: "dbbrowser-ui-dbbrowser-indexes-tab-remove-index-button-label",
059: null);;
060:
061: private UIControllerForQueries uiControllerForQueries = null;
062: private UIControllerForUpdates uiControllerForUpdates = null;
063:
064: private Table tableForIndexes = null;
065: private ButtonsPanel buttonsPanel = null;
066:
067: private boolean indexesSetupCompleted = false;
068:
069: public DBIndexesPanel(
070: UIControllerForQueries uiControllerForQueries,
071: UIControllerForUpdates uiControllerForUpdates) {
072: this .uiControllerForQueries = uiControllerForQueries;
073: this .uiControllerForUpdates = uiControllerForUpdates;
074: initialize();
075: }
076:
077: public void refresh() {
078: showIndexes();
079: }
080:
081: public void stateChanged(ChangeEvent e) {
082: //Setup indexes only if this panel has been selected
083: Object source = e.getSource();
084: if ((source != null) && (source instanceof JTabbedPane)) {
085: //Get the selected tab
086: JTabbedPane pane = (JTabbedPane) source;
087: Component selectedComponent = pane.getSelectedComponent();
088: if ((selectedComponent != null)
089: && (selectedComponent instanceof DBIndexesPanel)) {
090: //If indexes have not been retrieved, retrieve them and cache them
091: if (!indexesSetupCompleted) {
092: showIndexes();
093: }
094: }
095: }
096: }
097:
098: private void showIndexes() {
099: try {
100: //Remove existing panels
101: if (this .tableForIndexes != null) {
102: this .remove(this .tableForIndexes);
103: this .remove(this .buttonsPanel);
104: }
105:
106: DBTable dbTableOfIndexes = this .uiControllerForQueries
107: .listIndexes();
108:
109: //Add the table
110: this .tableForIndexes = new Table(
111: this .uiControllerForQueries,
112: this .uiControllerForUpdates);
113: this .add(tableForIndexes);
114:
115: //Set the buttons panel
116: Button addNewIndexButton = new Button(
117: ADD_NEW_INDEX_BUTTON_LABEL, this ,
118: ADD_NEW_INDEX_BUTTON_LABEL,
119: iconForAddNewRecordButton, Boolean.TRUE);
120: Button removeIndexButton = new Button(
121: REMOVE_INDEX_BUTTON_LABEL, this ,
122: REMOVE_INDEX_BUTTON_LABEL,
123: iconForDeleteRecordButton, Boolean.FALSE);
124: List listOfButtons = new ArrayList();
125: listOfButtons.add(addNewIndexButton);
126: listOfButtons.add(removeIndexButton);
127: buttonsPanel = new ButtonsPanel(listOfButtons);
128:
129: this .add(buttonsPanel);
130:
131: //Initialize table
132: this .initializeTable(dbTableOfIndexes);
133: indexesSetupCompleted = 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: }
148: }
149:
150: private void initialize() {
151: //Set the table for data
152: this .setLayout(new BoxLayout(this , BoxLayout.PAGE_AXIS));
153: }
154:
155: public void initializeTable(DBTable dbTableOfSequences) {
156: this .tableForIndexes.initializeTable(new DBTableDataTableModel(
157: dbTableOfSequences));
158: }
159:
160: public void actionPerformed(ActionEvent e) {
161: //Add a new column
162: if (ADD_NEW_INDEX_BUTTON_LABEL.equals(e.getActionCommand())) {
163: String UNIMPLEMENTED_FEATURE_MESSAGE = InternationalizationManager
164: .getInstance()
165: .getMessage(
166: "dbbrowser-ui",
167: "dbbrowser-ui-dbbrowser-unimplemented-feature",
168: null);
169: JOptionPane.showMessageDialog(null,
170: UNIMPLEMENTED_FEATURE_MESSAGE, TITLE,
171: JOptionPane.INFORMATION_MESSAGE);
172: }
173:
174: //Remove the selected column
175: if (REMOVE_INDEX_BUTTON_LABEL.equals(e.getActionCommand())) {
176: String UNIMPLEMENTED_FEATURE_MESSAGE = InternationalizationManager
177: .getInstance()
178: .getMessage(
179: "dbbrowser-ui",
180: "dbbrowser-ui-dbbrowser-unimplemented-feature",
181: null);
182: JOptionPane.showMessageDialog(null,
183: UNIMPLEMENTED_FEATURE_MESSAGE, TITLE,
184: JOptionPane.INFORMATION_MESSAGE);
185: }
186: }
187: }
|