001: /*
002: * DbExplorerPanel.java
003: *
004: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005: *
006: * Copyright 2002-2008, Thomas Kellerer
007: * No part of this code maybe reused without the permission of the author
008: *
009: * To contact the author please send an email to: support@sql-workbench.net
010: *
011: */
012: package workbench.gui.dbobjects;
013:
014: import java.awt.BorderLayout;
015: import java.awt.Component;
016: import java.awt.Dimension;
017: import java.awt.EventQueue;
018: import java.awt.FlowLayout;
019: import java.awt.KeyboardFocusManager;
020: import java.awt.event.ActionEvent;
021: import java.awt.event.ActionListener;
022: import java.beans.PropertyChangeEvent;
023: import java.beans.PropertyChangeListener;
024: import java.io.IOException;
025: import java.sql.SQLException;
026: import java.util.Collections;
027: import java.util.List;
028:
029: import javax.swing.Box;
030: import javax.swing.JButton;
031: import javax.swing.JComboBox;
032: import javax.swing.JComponent;
033: import javax.swing.JLabel;
034: import javax.swing.JPanel;
035: import javax.swing.JTabbedPane;
036: import javax.swing.border.Border;
037: import javax.swing.border.CompoundBorder;
038: import javax.swing.border.EmptyBorder;
039: import javax.swing.border.EtchedBorder;
040: import javax.swing.event.ChangeEvent;
041: import javax.swing.event.ChangeListener;
042: import workbench.db.ConnectionMgr;
043: import workbench.db.ConnectionProfile;
044:
045: import workbench.db.WbConnection;
046: import workbench.interfaces.DbExecutionListener;
047: import workbench.util.ExceptionUtil;
048: import workbench.gui.MainWindow;
049: import workbench.gui.WbSwingUtilities;
050: import workbench.gui.actions.WbAction;
051: import workbench.gui.components.ConnectionInfo;
052: import workbench.gui.components.ConnectionSelector;
053: import workbench.gui.components.WbTabbedPane;
054: import workbench.gui.components.WbToolbar;
055: import workbench.interfaces.Connectable;
056: import workbench.interfaces.MainPanel;
057: import workbench.log.LogMgr;
058: import workbench.resource.ResourceMgr;
059: import workbench.resource.Settings;
060: import workbench.storage.DataStore;
061: import workbench.util.NumberStringCache;
062: import workbench.util.StringUtil;
063: import workbench.util.WbProperties;
064: import workbench.util.WbThread;
065: import workbench.util.WbWorkspace;
066:
067: /**
068: * The main container panel for the DbExplorer.
069: *
070: * This panel incorporates the panels to
071: * <ul>
072: * <li>Display a list of tables, views, etc {@link workbench.gui.dbobjects.TableListPanel}</li>
073: * <li>Display a list of procedures: {@link workbench.gui.dbobjects.ProcedureListPanel}</li>
074: * <li>Allow search across several table and columns: {@link workbench.gui.dbobjects.TableSearchPanel}</li>
075: * </ul>
076: * This panel can either be displayed inside the MainWindow as a tab, or as
077: * a separate Window (@link workbench.gui.dbobjects.DbExplorerWindow}
078: * @author support@sql-workbench.net
079: */
080: public class DbExplorerPanel extends JPanel implements ActionListener,
081: MainPanel, ChangeListener, DbExecutionListener,
082: PropertyChangeListener {
083: private JTabbedPane tabPane;
084: protected TableListPanel tables;
085: protected TableSearchPanel searchPanel;
086: protected ProcedureListPanel procs;
087: protected TriggerListPanel triggers;
088: protected JComboBox schemaSelector;
089: private JComboBox catalogSelector;
090: private JLabel schemaLabel;
091: private JLabel catalogLabel;
092: private JPanel selectorPanel;
093: boolean connected;
094: private WbConnection dbConnection;
095: private DbExplorerWindow window;
096: private WbToolbar toolbar;
097: private ConnectionInfo connectionInfo;
098: protected boolean retrievePending;
099: private boolean schemaRetrievePending = true;
100: private boolean connectionInitPending = true;
101: private int internalId = 0;
102: private ConnectionSelector connectionSelector;
103: private JButton selectConnectionButton;
104: private String tabTitle;
105: private static int instanceCount = 0;
106: private MainWindow mainWindow;
107: private boolean busy;
108: private String schemaFromWorkspace;
109: private String catalogFromWorkspace;
110: private boolean switchCatalog = false;
111: private JComponent currentFocus = null;
112:
113: public DbExplorerPanel() {
114: this (null);
115: }
116:
117: public DbExplorerPanel(MainWindow aParent) {
118: this .internalId = ++instanceCount;
119: this .mainWindow = aParent;
120: try {
121: tables = new TableListPanel(aParent);
122: setDbExecutionListener(aParent);
123: procs = new ProcedureListPanel(aParent);
124: this .searchPanel = new TableSearchPanel(tables);
125: tabPane = new WbTabbedPane(JTabbedPane.TOP);
126: tabPane.add(ResourceMgr.getString("TxtDbExplorerTables"),
127: tables);
128: tabPane.setToolTipTextAt(0, ResourceMgr
129: .getDescription("TxtDbExplorerTables"));
130:
131: String tabLocation = Settings.getInstance().getProperty(
132: "workbench.gui.dbobjects.maintabs", "top");
133: int location = JTabbedPane.TOP;
134: if (tabLocation.equalsIgnoreCase("bottom")) {
135: location = JTabbedPane.BOTTOM;
136: } else if (tabLocation.equalsIgnoreCase("left")) {
137: location = JTabbedPane.LEFT;
138: } else if (tabLocation.equalsIgnoreCase("right")) {
139: location = JTabbedPane.RIGHT;
140: }
141: tabPane.setTabPlacement(location);
142:
143: int index = 1;
144:
145: tabPane.add(ResourceMgr.getString("TxtDbExplorerProcs"),
146: procs);
147: tabPane.setToolTipTextAt(index, ResourceMgr
148: .getDescription("TxtDbExplorerProcs"));
149:
150: if (Settings.getInstance().getShowTriggerPanel()) {
151: triggers = new TriggerListPanel(aParent);
152: tabPane.add(ResourceMgr
153: .getString("TxtDbExplorerTriggers"), triggers);
154: tabPane.setToolTipTextAt(index++, ResourceMgr
155: .getDescription("TxtDbExplorerTriggers"));
156: }
157: tabPane.add(ResourceMgr.getString("TxtSearchTables"),
158: this .searchPanel);
159: tabPane.setToolTipTextAt(index++, ResourceMgr
160: .getDescription("TxtSearchTables"));
161: tabPane.setFocusable(false);
162:
163: this .setBorder(WbSwingUtilities.EMPTY_BORDER);
164: this .setLayout(new BorderLayout());
165:
166: this .selectorPanel = new JPanel();
167: this .selectorPanel.setLayout(new FlowLayout(
168: FlowLayout.LEFT, 5, 0));
169:
170: this .schemaLabel = new JLabel(ResourceMgr
171: .getString("LblSchema"));
172:
173: this .selectorPanel.add(schemaLabel);
174: this .schemaSelector = new JComboBox();
175: Dimension d = new Dimension(80, 20);
176: this .schemaSelector.setMinimumSize(d);
177: this .selectorPanel.add(this .schemaSelector);
178:
179: this .catalogSelector = new JComboBox();
180: this .catalogLabel = new JLabel("Catalog");
181: this .catalogSelector.setVisible(false);
182: this .catalogSelector.setEnabled(false);
183: this .catalogLabel.setVisible(false);
184: this .selectorPanel.add(catalogLabel);
185: this .selectorPanel.add(catalogSelector);
186:
187: this .add(this .selectorPanel, BorderLayout.NORTH);
188: this .add(tabPane, BorderLayout.CENTER);
189: this .searchPanel.restoreSettings();
190:
191: this .toolbar = new WbToolbar();
192: this .toolbar.addDefaultBorder();
193: d = new Dimension(30, 29);
194: this .toolbar.setMinimumSize(d);
195: this .toolbar.setPreferredSize(new Dimension(100, 29));
196: this .connectionInfo = new ConnectionInfo(this .toolbar
197: .getBackground());
198: this .connectionInfo.setMinimumSize(d);
199: this .toolbar.add(this .connectionInfo);
200: if (mainWindow != null)
201: mainWindow.addExecutionListener(this );
202:
203: KeyboardFocusManager focusManager = KeyboardFocusManager
204: .getCurrentKeyboardFocusManager();
205: focusManager.addPropertyChangeListener("focusOwner", this );
206: } catch (Throwable e) {
207: LogMgr.logError(this ,
208: "Could not initialize DbExplorerPanel", e);
209: }
210: }
211:
212: public void propertyChange(PropertyChangeEvent evt) {
213: if (!this .isVisible())
214: return;
215: String prop = evt.getPropertyName();
216:
217: Object o = evt.getNewValue();
218: if (o instanceof JComponent && "focusOwner".equals(prop)) {
219: currentFocus = (JComponent) evt.getNewValue();
220: }
221: }
222:
223: public void setConnectionClient(Connectable client) {
224: // not used
225: }
226:
227: public void setDbExecutionListener(DbExecutionListener l) {
228: if (this .tables != null) {
229: tables.setDbExecutionListener(l);
230: }
231: }
232:
233: public void setSwitchCatalog(boolean flag) {
234: this .switchCatalog = flag
235: && Settings.getInstance().getSwitchCatalogInExplorer();
236: }
237:
238: public void showConnectButton(ConnectionSelector selector) {
239: this .connectionSelector = selector;
240: this .selectConnectionButton = new JButton(ResourceMgr
241: .getString("LblSelectConnection"));
242: Border b = new CompoundBorder(new EtchedBorder(
243: EtchedBorder.LOWERED), new EmptyBorder(1, 10, 1, 10));
244: this .selectConnectionButton.setBorder(b);
245: this .selectConnectionButton.addActionListener(this );
246: this .selectorPanel.add(Box.createHorizontalStrut(15));
247: this .selectorPanel.add(this .selectConnectionButton);
248:
249: }
250:
251: private final Object busyLock = new Object();
252:
253: private void setBusy(boolean flag) {
254: synchronized (busyLock) {
255: busy = flag;
256: }
257: }
258:
259: public boolean isBusy() {
260: synchronized (busyLock) {
261: return this .busy;
262: }
263: }
264:
265: public String getId() {
266: return "WbExp-"
267: + NumberStringCache.getNumberString(this .internalId);
268: }
269:
270: private void readSchemas() {
271: if (this .isBusy() || isConnectionBusy()
272: || this .dbConnection == null
273: || this .dbConnection.getMetadata() == null) {
274: this .schemaRetrievePending = true;
275: return;
276: }
277:
278: String schemaToSelect = null;
279: try {
280: this .schemaSelector.removeActionListener(this );
281:
282: setBusy(true);
283:
284: List schemas = this .dbConnection.getMetadata().getSchemas();
285: String currentSchema = null;
286: boolean workspaceSchema = false;
287: if (this .dbConnection.getProfile().getStoreExplorerSchema()) {
288: currentSchema = this .schemaFromWorkspace;
289: workspaceSchema = true;
290: }
291:
292: if (currentSchema == null)
293: currentSchema = this .dbConnection.getCurrentSchema();
294: if (currentSchema == null)
295: currentSchema = this .dbConnection.getCurrentUser();
296:
297: if (schemas.size() > 0) {
298: this .schemaSelector.setEnabled(true);
299: this .schemaSelector.setVisible(true);
300: this .schemaLabel.setVisible(true);
301:
302: this .schemaSelector.removeAllItems();
303: this .schemaSelector.addItem("*");
304: for (int i = 0; i < schemas.size(); i++) {
305: String schema = (String) schemas.get(i);
306: if (schema != null) {
307: this .schemaSelector.addItem(schema.trim());
308: if (schema.equalsIgnoreCase(currentSchema))
309: schemaToSelect = schema;
310: }
311: }
312:
313: if (workspaceSchema && schemaToSelect == null) {
314: // when using the workspace for multiple connections
315: // it can happen that the stored schema does not exist
316: // for the current connection, in this case we revert
317: // to "current" schema
318: schemaToSelect = this .dbConnection.getMetadata()
319: .getCurrentSchema();
320: }
321: //LogMgr.logDebug("DbExplorerPanel.readSchemas()", "Selected schema entry: " + schemaToSelect);
322: if (schemaToSelect != null) {
323: schemaSelector.setSelectedItem(schemaToSelect);
324: } else {
325: schemaSelector.setSelectedIndex(0);
326: }
327: currentSchema = (String) schemaSelector
328: .getSelectedItem();
329: } else {
330: this .schemaSelector.setEnabled(false);
331: this .schemaSelector.setVisible(false);
332: this .schemaLabel.setVisible(false);
333: currentSchema = null;
334: }
335: readCatalogs();
336:
337: tables.setCatalogAndSchema(getSelectedCatalog(),
338: currentSchema, false);
339: procs.setCatalogAndSchema(getSelectedCatalog(),
340: currentSchema, false);
341: } catch (Throwable e) {
342: LogMgr.logError("DbExplorer.readSchemas()",
343: "Could not retrieve list of schemas", e);
344: } finally {
345: this .schemaRetrievePending = false;
346: setBusy(false);
347: }
348: this .schemaSelector.addActionListener(this );
349: }
350:
351: public boolean isConnected() {
352: return (this .dbConnection != null);
353: }
354:
355: private void doConnect(ConnectionProfile profile) {
356: ConnectionMgr mgr = ConnectionMgr.getInstance();
357: WbConnection conn = null;
358: try {
359: WbSwingUtilities.showWaitCursor(this );
360: conn = mgr.getConnection(profile, this .getId());
361: this .setConnection(conn);
362: if (Settings.getInstance().getRetrieveDbExplorer()) {
363: this .retrieve();
364: }
365: } catch (Exception e) {
366: String error = ExceptionUtil.getDisplay(e);
367: String msg = ResourceMgr.getString(
368: "ErrExplorerConnectFailed").replaceAll("%msg%",
369: error.trim());
370: WbSwingUtilities.showErrorMessage(this , msg);
371: LogMgr
372: .logError(
373: "MainWindow.showDbExplorer()",
374: "Error getting new connection for DbExplorer tab. Using connection from current panel",
375: e);
376: } finally {
377: WbSwingUtilities.showDefaultCursor(this );
378: }
379: }
380:
381: public void connect(final ConnectionProfile profile) {
382: // connecting can be pretty time consuming on a slow system
383: // so move it into its own thread...
384: if (!this .isConnected()) {
385: Thread t = new WbThread("DbExplorer connection") {
386: public void run() {
387: doConnect(profile);
388: }
389: };
390: t.start();
391: }
392: }
393:
394: private boolean isConnectionBusy() {
395: if (this .dbConnection == null)
396: return false;
397: if (this .dbConnection.getProfile()
398: .getUseSeparateConnectionPerTab())
399: return this .isBusy();
400: return dbConnection.isBusy();
401: }
402:
403: private void initConnection() {
404: if (this .dbConnection == null)
405: return;
406: try {
407: this .tables.setConnection(this .dbConnection);
408: this .procs.setConnection(dbConnection);
409: if (this .triggers != null)
410: this .triggers.setConnection(dbConnection);
411: if (this .searchPanel != null)
412: this .searchPanel.setConnection(dbConnection);
413: readSchemaLabel();
414: this .connectionInitPending = false;
415: } catch (Exception e) {
416: LogMgr.logError("DbExplorerPanel.initConnection()",
417: "Error during init", e);
418: }
419: }
420:
421: private void readSchemaLabel() {
422: StringBuilder s = new StringBuilder(this .dbConnection
423: .getMetadata().getSchemaTerm());
424: s.setCharAt(0, Character.toUpperCase(s.charAt(0)));
425: this .schemaLabel.setText(s.toString());
426: }
427:
428: public void setConnection(WbConnection aConnection) {
429: if (this .isBusy())
430: return;
431:
432: this .dbConnection = aConnection;
433: setSwitchCatalog(false);
434:
435: if (aConnection == null) {
436: this .reset();
437: this .connectionInitPending = false;
438: return;
439: }
440:
441: WbSwingUtilities.showWaitCursorOnWindow(this );
442:
443: try {
444: if (this .connectionSelector != null) {
445: // always switch database/catalog if in stand-alone mode
446: setSwitchCatalog(true);
447: } else if (aConnection.getProfile() != null) {
448: boolean separateConnection = aConnection.getProfile()
449: .getUseSeparateConnectionPerTab();
450: setSwitchCatalog(separateConnection);
451: // when dealing with tables that have LONG or LONG RAW columns
452: // and DBMS_OUTPUT was enabled, then retrieval of those columns
453: // does not work. If we have separate connections for each tab
454: // we can safely disable the DBMS_OUTPUT on this connection
455: // as there won't be a way to view the output anyway
456: if (separateConnection)
457: aConnection.getMetadata().disableOutput();
458: }
459:
460: this .connectionInitPending = true;
461: this .schemaRetrievePending = true;
462: this .retrievePending = Settings.getInstance()
463: .getRetrieveDbExplorer();
464:
465: if (this .window != null) {
466: String name = null;
467: ConnectionProfile prof = aConnection.getProfile();
468: if (prof != null)
469: name = prof.getName();
470: if (name != null)
471: this .window.setProfileName(name);
472: }
473:
474: this .connectionInfo.setConnection(aConnection);
475:
476: // Try to avoid concurrent execution on the
477: // same connection object
478: if (!this .isConnectionBusy()) {
479: initConnection();
480:
481: if (this .isVisible()) {
482: readSchemas();
483:
484: if (this .retrievePending) {
485: // if we are visible start the retrieve immediately
486: retrieve();
487: }
488: }
489: }
490: } catch (Throwable th) {
491: this .retrievePending = true;
492: this .schemaRetrievePending = true;
493: LogMgr.logError("DbExplorerPanel.setConnection()",
494: "Error during connection init", th);
495: } finally {
496: WbSwingUtilities.showDefaultCursorOnWindow(this );
497: }
498:
499: }
500:
501: private void readCatalogs() {
502: DataStore ds = this .dbConnection.getMetadata()
503: .getCatalogInformation();
504: this .catalogSelector.removeActionListener(this );
505: if (ds.getRowCount() == 0) {
506: this .catalogSelector.setVisible(false);
507: this .catalogSelector.setEnabled(false);
508: this .catalogLabel.setVisible(false);
509: this .catalogFromWorkspace = null;
510: } else {
511: String cat = StringUtil.capitalize(this .dbConnection
512: .getMetadata().getCatalogTerm());
513:
514: this .catalogSelector.removeAllItems();
515: this .catalogLabel.setText(cat);
516:
517: for (int i = 0; i < ds.getRowCount(); i++) {
518: String db = ds.getValueAsString(i, 0);
519: catalogSelector.addItem(db);
520: }
521: String db = this .dbConnection.getMetadata()
522: .getCurrentCatalog();
523: catalogSelector.setSelectedItem(db);
524: if (this .dbConnection.getProfile().getStoreExplorerSchema()
525: && this .catalogFromWorkspace != null) {
526: this .catalogSelector
527: .setSelectedItem(this .catalogFromWorkspace);
528: }
529: this .catalogSelector.addActionListener(this );
530: this .catalogSelector.setVisible(true);
531: this .catalogSelector.setEnabled(true);
532: this .catalogLabel.setVisible(true);
533: }
534: this .selectorPanel.validate();
535: }
536:
537: public void setVisible(boolean flag) {
538: boolean wasVisible = this .isVisible();
539: super .setVisible(flag);
540: if (!wasVisible && flag) {
541: if (schemaRetrievePending) {
542: this .readSchemas();
543: }
544: if (retrievePending) {
545: // retrievePending will be true, if the connection has
546: // been set already, the DbExplorer should be retrieved automatically
547: // and the panel was not visible when the connection was provided
548: EventQueue.invokeLater(new Runnable() {
549: public void run() {
550: retrieve();
551: }
552: });
553: }
554: if (currentFocus != null) {
555: WbSwingUtilities.requestFocus(currentFocus);
556: }
557: }
558: }
559:
560: public void panelSelected() {
561: Component panel = this .tabPane.getSelectedComponent();
562: if (panel == null)
563: return;
564: if (panel == this .tables) {
565: this .tables.panelSelected();
566: } else if (panel == this .procs) {
567: this .procs.panelSelected();
568: } else if (panel == this .triggers) {
569: this .triggers.panelSelected();
570: }
571: }
572:
573: public WbConnection getConnection() {
574: return this .dbConnection;
575: }
576:
577: public void reset() {
578: if (this .tables != null)
579: this .tables.reset();
580: if (this .procs != null)
581: this .procs.reset();
582: if (this .searchPanel != null)
583: this .searchPanel.reset();
584: if (this .tabPane != null && this .tabPane.getTabCount() > 0)
585: this .tabPane.setSelectedIndex(0);
586: }
587:
588: public void disconnect() {
589: this .reset();
590: this .tables.disconnect();
591: this .procs.disconnect();
592: if (this .triggers != null)
593: this .triggers.disconnect();
594: this .searchPanel.disconnect();
595: this .dbConnection = null;
596: }
597:
598: public void saveSettings() {
599: this .tables.saveSettings();
600: this .procs.saveSettings();
601: if (this .triggers != null)
602: this .triggers.saveSettings();
603: if (this .searchPanel != null)
604: this .searchPanel.saveSettings();
605: }
606:
607: public void restoreSettings() {
608: if (tables != null)
609: tables.restoreSettings();
610: if (procs != null)
611: procs.restoreSettings();
612: if (this .triggers != null)
613: triggers.restoreSettings();
614: if (this .searchPanel != null)
615: searchPanel.restoreSettings();
616: }
617:
618: public void actionPerformed(ActionEvent e) {
619: if (e.getSource() == this .schemaSelector) {
620: retrieve();
621: } else if (e.getSource() == this .selectConnectionButton) {
622: this .connectionSelector.selectConnection();
623: } else if (e.getSource() == this .catalogSelector) {
624: if (this .switchCatalog) {
625: try {
626: this .dbConnection.getMetadata().setCurrentCatalog(
627: getSelectedCatalog());
628: } catch (SQLException ex) {
629: WbSwingUtilities.showErrorMessage(this ,
630: ExceptionUtil.getDisplay(ex));
631: }
632: }
633: retrieve();
634: }
635: }
636:
637: protected String getSelectedCatalog() {
638: if (this .catalogSelector == null)
639: return null;
640: return (String) catalogSelector.getSelectedItem();
641: }
642:
643: protected void retrieve() {
644: if (this .dbConnection == null || this .dbConnection.isClosed())
645: return;
646:
647: if (this .isBusy() || isConnectionBusy()) {
648: this .retrievePending = true;
649: return;
650: }
651:
652: if (this .connectionInitPending) {
653: this .initConnection();
654: }
655:
656: if (this .schemaRetrievePending) {
657: this .readSchemas();
658: }
659:
660: final String schema = (String) schemaSelector.getSelectedItem();
661: final Component c = this ;
662:
663: Thread t = new WbThread("SchemaChange") {
664: public void run() {
665: try {
666: setBusy(true);
667: WbSwingUtilities.showWaitCursorOnWindow(c);
668: tables.setCatalogAndSchema(getSelectedCatalog(),
669: schema, true);
670: procs.setCatalogAndSchema(getSelectedCatalog(),
671: schema, true);
672: if (triggers != null)
673: triggers.setCatalogAndSchema(
674: getSelectedCatalog(), schema, true);
675: } catch (Exception ex) {
676: LogMgr.logError(this , "Could not set schema", ex);
677: } finally {
678: retrievePending = false;
679: setBusy(false);
680: WbSwingUtilities.showDefaultCursorOnWindow(c);
681: }
682: }
683: };
684: t.start();
685: }
686:
687: public String getName() {
688: return getTabTitle();
689: }
690:
691: public void setTabName(String name) {
692: this .tabTitle = name;
693: }
694:
695: public String getTabTitle() {
696: return ResourceMgr.getString("LblDbExplorer");
697: }
698:
699: public void setTabTitle(JTabbedPane tab, int index) {
700: String title = (this .tabTitle == null ? getTabTitle()
701: : this .tabTitle);
702:
703: String realTitle = title + " " + Integer.toString(index + 1);
704: tab.setTitleAt(index, realTitle);
705: if (index < 9) {
706: char c = Integer.toString(index + 1).charAt(0);
707: int pos = title.length() + 1;
708: tab.setMnemonicAt(index, c);
709: // The Mnemonic index has to be set explicitely otherwise
710: // the display would be wrong if the tab title contains
711: // the mnemonic character
712: tab.setDisplayedMnemonicIndexAt(index, pos);
713: }
714: }
715:
716: public DbExplorerWindow openWindow(String aProfileName) {
717: if (this .window == null) {
718: this .window = new DbExplorerWindow(this , aProfileName);
719: }
720: this .window.setVisible(true);
721: return this .window;
722: }
723:
724: public List getActions() {
725: return Collections.EMPTY_LIST;
726: }
727:
728: public WbToolbar getToolbar() {
729: return this .toolbar;
730: }
731:
732: public void showLogMessage(String aMsg) {
733: }
734:
735: public void clearStatusMessage() {
736: }
737:
738: public void showStatusMessage(String aMsg) {
739: }
740:
741: public void clearLog() {
742: }
743:
744: public void showLogPanel() {
745: }
746:
747: public void showResultPanel() {
748: }
749:
750: public void addToToolbar(WbAction anAction, boolean aFlag) {
751: }
752:
753: void explorerWindowClosed() {
754: if (this .dbConnection != null) {
755: if (this .dbConnection.getProfile()
756: .getUseSeparateConnectionPerTab()) {
757: try {
758: this .dbConnection.disconnect();
759: } catch (Throwable th) {
760: }
761: }
762: }
763: this .dispose();
764: this .disconnect();
765:
766: this .mainWindow.explorerWindowClosed(this .window);
767: this .window = null;
768: }
769:
770: public void updateUI() {
771: super .updateUI();
772: if (this .toolbar != null) {
773: this .toolbar.updateUI();
774: this .toolbar.repaint();
775: }
776: if (this .procs != null) {
777: this .procs.updateUI();
778: this .procs.repaint();
779: }
780: }
781:
782: public void stateChanged(ChangeEvent e) {
783: if (e.getSource() == this .tabPane) {
784: if (this .tabPane.getSelectedIndex() == 1) {
785: this .procs.retrieveIfNeeded();
786: }
787: }
788: }
789:
790: public void dispose() {
791: this .reset();
792: this .tables.dispose();
793: if (mainWindow != null) {
794: mainWindow.removeExecutionListener(this );
795: }
796: }
797:
798: public void saveToWorkspace(WbWorkspace w, int index)
799: throws IOException {
800: // this will increase the visible count for DbExplorer Panels in the workspace
801: w.dDbExplorerVisible();
802: Object s = this .schemaSelector.getSelectedItem();
803: WbProperties p = w.getSettings();
804: String key = "dbexplorer" + index + ".currentschema";
805: if (s != null) {
806: p.setProperty(key, s.toString());
807: } else if (this .schemaFromWorkspace != null) {
808: // if the DbExplorer was never "really" displayed we have to
809: // save the schema that we retrieved initially from the workspace
810: p.setProperty(key, this .schemaFromWorkspace);
811: }
812:
813: key = "dbexplorer" + index + ".currentcatalog";
814: s = this .getSelectedCatalog();
815: if (s != null) {
816: p.setProperty(key, s.toString());
817: } else if (this .catalogFromWorkspace != null) {
818: p.setProperty(key, this .catalogFromWorkspace);
819: }
820:
821: tables.saveToWorkspace(w, index);
822: searchPanel.saveToWorkspace(w, index);
823: procs.saveToWorkspace(w, index);
824: if (triggers != null)
825: triggers.saveToWorkspace(w, index);
826: }
827:
828: public boolean canCloseTab() {
829: return true;
830: }
831:
832: public void readFromWorkspace(WbWorkspace w, int index)
833: throws IOException {
834: this .schemaFromWorkspace = null;
835: this .catalogFromWorkspace = null;
836: this .reset();
837: try {
838: WbProperties p = w.getSettings();
839: this .schemaFromWorkspace = p.getProperty("dbexplorer"
840: + index + ".currentschema", null);
841: this .catalogFromWorkspace = p.getProperty("dbexplorer"
842: + index + ".currentcatalog", null);
843: tables.readFromWorkspace(w, index);
844: searchPanel.readFromWorkspace(w, index);
845: procs.readFromWorkspace(w, index);
846: if (triggers != null)
847: triggers.readFromWorkspace(w, index);
848: } catch (Exception e) {
849: LogMgr.logError("DbExplorerPanel.readFromWorkspace()",
850: "Error loading workspace", e);
851: }
852: }
853:
854: public void executionStart(WbConnection conn, Object source) {
855: }
856:
857: /*
858: * Fired by the SqlPanel if DB access finished
859: */
860: public void executionEnd(WbConnection conn, Object source) {
861: if (this.connectionInitPending) {
862: this.initConnection();
863: }
864: if (this.isVisible() && this.schemaRetrievePending) {
865: this.readSchemas();
866: }
867: if (this.isVisible() && this.retrievePending) {
868: this.retrieve();
869: }
870: }
871:
872: }
|