001: package org.dbbrowser.ui.panel.dbbrowserwindow;
002:
003: import java.awt.BorderLayout;
004: import java.io.File;
005: import infrastructure.internationalization.InternationalizationManager;
006: import infrastructure.propertymanager.PropertyManager;
007: import javax.swing.*;
008: import javax.swing.border.BevelBorder;
009: import org.dbbrowser.db.engine.exception.DBEngineException;
010: import org.dbbrowser.ui.UIControllerForQueries;
011: import org.dbbrowser.ui.UIControllerForRawSQL;
012: import org.dbbrowser.ui.UIControllerForUpdates;
013:
014: public class DBBrowserConnectionInstancePanel extends JPanel {
015: private static final long serialVersionUID = UIControllerForQueries.version;
016:
017: private UIControllerForQueries uiControllerForQueries = null;
018: private UIControllerForUpdates uiControllerForUpdates = null;
019: private UIControllerForRawSQL uiControllerForRawSQL = null;
020: private static final String TITLE = InternationalizationManager
021: .getInstance().getMessage("dbbrowser-ui",
022: "dbbrowser-ui-dbbrowser-window-title-label", null);;
023:
024: //Tabbed panes
025: private BrowserPanel browserPanel = null;
026: private SQLPanel sqlPanel = null;
027: private DBTableSequencesPanel dbTableSequencesPanel = null;
028: private DBIndexesPanel dbIndexesPanel = null;
029: private DBConstraintsPanel dbConstraintsPanel = null;
030: private JTabbedPane tabbedPane = null;
031:
032: public DBBrowserConnectionInstancePanel(
033: UIControllerForQueries uiControllerForQueries,
034: UIControllerForUpdates uiControllerForUpdates,
035: UIControllerForRawSQL uiControllerForRawSQL) {
036: this .uiControllerForUpdates = uiControllerForUpdates;
037: this .uiControllerForQueries = uiControllerForQueries;
038: this .uiControllerForRawSQL = uiControllerForRawSQL;
039: initialize();
040:
041: //Setup the tabbed pane
042: setupTabbedPane();
043: }
044:
045: public void refresh() {
046: this .browserPanel.refresh();
047: this .dbTableSequencesPanel.refresh();
048: this .dbIndexesPanel.refresh();
049: }
050:
051: public void commit() {
052: try {
053: //Commit if autocommit if off
054: String autoCommitFlag = PropertyManager.getInstance()
055: .getProperty("dbbrowser-auto-commit");
056: if ("false".equals(autoCommitFlag)) {
057: this .uiControllerForUpdates.commit();
058: this .uiControllerForRawSQL.commit();
059: }
060: } catch (DBEngineException exc) {
061: String errorMessage = InternationalizationManager
062: .getInstance().getMessage("dbbrowser-ui",
063: "dbbrowser-ui-dbbrowser-window-sql-failed",
064: null);
065: JOptionPane.showMessageDialog(null, errorMessage + " - "
066: + exc.getMessage(), TITLE,
067: JOptionPane.ERROR_MESSAGE);
068: }
069: }
070:
071: public void rollback() {
072: try {
073: //Rollback if autocommit if off
074: String autoCommitFlag = PropertyManager.getInstance()
075: .getProperty("dbbrowser-auto-commit");
076: if ("false".equals(autoCommitFlag)) {
077: this .uiControllerForUpdates.rollback();
078: this .uiControllerForRawSQL.rollback();
079: }
080: } catch (DBEngineException exc) {
081: String errorMessage = InternationalizationManager
082: .getInstance().getMessage("dbbrowser-ui",
083: "dbbrowser-ui-dbbrowser-window-sql-failed",
084: null);
085: JOptionPane.showMessageDialog(null, errorMessage + " - "
086: + exc.getMessage(), TITLE,
087: JOptionPane.ERROR_MESSAGE);
088: }
089: }
090:
091: public void runBatchFile(File file) {
092: this .sqlPanel.runBatchFile(file);
093: this .tabbedPane.setSelectedComponent(this .sqlPanel);
094: }
095:
096: public String getConnectionInfoName() {
097: return this .uiControllerForQueries.getConnectionInfo()
098: .getName();
099: }
100:
101: private void initialize() {
102: //Set the layout
103: this .setLayout(new BorderLayout());
104:
105: //Add a border
106: this .setBorder(BorderFactory
107: .createBevelBorder(BevelBorder.LOWERED));
108: }
109:
110: private void setupTabbedPane() {
111: tabbedPane = new JTabbedPane();
112: Icon browserTabIcon = new ImageIcon(
113: PropertyManager
114: .getInstance()
115: .getProperty(
116: "dbbrowser-ui-dbbrowser-window-tab-browser-icon"));
117: String browserTabbedPaneTitle = InternationalizationManager
118: .getInstance().getMessage("dbbrowser-ui",
119: "dbbrowser-ui-dbbrowser-browser-tab-title",
120: null);
121: this .browserPanel = new BrowserPanel(
122: this .uiControllerForQueries,
123: this .uiControllerForUpdates, this .uiControllerForRawSQL);
124: tabbedPane.addTab(browserTabbedPaneTitle, browserTabIcon,
125: this .browserPanel, browserTabbedPaneTitle);
126:
127: Icon sqlTabIcon = new ImageIcon(PropertyManager.getInstance()
128: .getProperty(
129: "dbbrowser-ui-dbbrowser-window-tab-sql-icon"));
130: String sqlTabbedPaneTitle = InternationalizationManager
131: .getInstance().getMessage("dbbrowser-ui",
132: "dbbrowser-ui-dbbrowser-sql-tab-title", null);
133: this .sqlPanel = new SQLPanel(this .uiControllerForQueries,
134: this .uiControllerForRawSQL);
135: tabbedPane.addTab(sqlTabbedPaneTitle, sqlTabIcon,
136: this .sqlPanel, sqlTabbedPaneTitle);
137:
138: Icon sequencesTabIcon = new ImageIcon(
139: PropertyManager
140: .getInstance()
141: .getProperty(
142: "dbbrowser-ui-dbbrowser-window-sequences-tab-icon"));
143: String dbTableSequencesTitle = InternationalizationManager
144: .getInstance()
145: .getMessage(
146: "dbbrowser-ui",
147: "dbbrowser-ui-dbbrowser-browser-tab-db-table-sequences-tab-title",
148: null);
149: this .dbTableSequencesPanel = new DBTableSequencesPanel(
150: this .uiControllerForQueries,
151: this .uiControllerForUpdates);
152: tabbedPane.addTab(dbTableSequencesTitle, sequencesTabIcon,
153: this .dbTableSequencesPanel, dbTableSequencesTitle);
154:
155: Icon indexTabIcon = new ImageIcon(PropertyManager.getInstance()
156: .getProperty(
157: "dbbrowser-ui-dbbrowser-window-index-tab-icon"));
158: String dbTableIndexTitle = InternationalizationManager
159: .getInstance()
160: .getMessage(
161: "dbbrowser-ui",
162: "dbbrowser-ui-dbbrowser-browser-tab-db-table-indexes-tab-title",
163: null);
164: this .dbIndexesPanel = new DBIndexesPanel(
165: this .uiControllerForQueries,
166: this .uiControllerForUpdates);
167: tabbedPane.addTab(dbTableIndexTitle, indexTabIcon,
168: this .dbIndexesPanel, dbTableIndexTitle);
169:
170: Icon constraintsTabIcon = new ImageIcon(
171: PropertyManager
172: .getInstance()
173: .getProperty(
174: "dbbrowser-ui-dbbrowser-window-constraints-tab-icon"));
175: String dbTableConstraintsTabbedPaneTitle = InternationalizationManager
176: .getInstance()
177: .getMessage(
178: "dbbrowser-ui",
179: "dbbrowser-ui-dbbrowser-browser-tab-db-table-constraints-tab-title",
180: null);
181: this .dbConstraintsPanel = new DBConstraintsPanel(
182: this .uiControllerForQueries,
183: this .uiControllerForUpdates);
184: tabbedPane.addTab(dbTableConstraintsTabbedPaneTitle,
185: constraintsTabIcon, this .dbConstraintsPanel,
186: dbTableConstraintsTabbedPaneTitle);
187:
188: this .add(tabbedPane);
189:
190: //Add the change listener for tab. This is invoked when the user clicks on the tab. Lazy loads the list of sequences for a tablespace
191: this.tabbedPane.addChangeListener(this.dbTableSequencesPanel);
192: this.tabbedPane.addChangeListener(this.dbIndexesPanel);
193: this.tabbedPane.addChangeListener(this.dbConstraintsPanel);
194: }
195: }
|