0001: /*
0002: * Copyright 2000-2005 by Mark A. Kobold
0003: *
0004: * The contents of this file are subject to the Mozilla Public License Version
0005: * 1.1 (the "License"); you may not use this file except in compliance with the
0006: * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
0007: *
0008: * Software distributed under the License is distributed on an "AS IS" basis,
0009: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
0010: * the specific language governing rights and limitations under the License.
0011: *
0012: * The Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
0013: *
0014: * The Initial Developer of the Original Code is Markus A. Kobold.
0015: *
0016: * Portions created by Mark A. Kobold are Copyright (C)
0017: * 2000-2005 Mark A. Kobold. All Rights Reserved.
0018: *
0019: * Contributor(s):
0020: * Mark A. Kobold <mkobold@isqlviewer.com>.
0021: *
0022: * Contributor(s): all the names of the contributors are added in the source
0023: * code where applicable.
0024: *
0025: * If you didn't download this code from the following link, you should check
0026: * if you aren't using an obsolete version: http://isql.sourceforge.net/
0027: */
0028: package org.isqlviewer.ui;
0029:
0030: import java.awt.BorderLayout;
0031: import java.awt.Component;
0032: import java.awt.Frame;
0033: import java.awt.Window;
0034: import java.awt.dnd.DnDConstants;
0035: import java.awt.dnd.DragSource;
0036: import java.awt.dnd.DropTarget;
0037: import java.awt.event.ActionEvent;
0038: import java.awt.event.ActionListener;
0039: import java.awt.event.KeyEvent;
0040: import java.awt.event.WindowEvent;
0041: import java.io.IOException;
0042: import java.io.InputStream;
0043: import java.net.URL;
0044: import java.sql.Connection;
0045: import java.sql.DatabaseMetaData;
0046: import java.sql.ResultSet;
0047: import java.sql.SQLException;
0048: import java.util.ArrayList;
0049: import java.util.Collection;
0050: import java.util.Date;
0051: import java.util.Enumeration;
0052: import java.util.Map;
0053: import java.util.Set;
0054: import java.util.TooManyListenersException;
0055: import java.util.prefs.Preferences;
0056:
0057: import javax.swing.AbstractAction;
0058: import javax.swing.AbstractButton;
0059: import javax.swing.Action;
0060: import javax.swing.ActionMap;
0061: import javax.swing.BorderFactory;
0062: import javax.swing.ButtonGroup;
0063: import javax.swing.Icon;
0064: import javax.swing.InputMap;
0065: import javax.swing.JCheckBoxMenuItem;
0066: import javax.swing.JComponent;
0067: import javax.swing.JDialog;
0068: import javax.swing.JEditorPane;
0069: import javax.swing.JMenu;
0070: import javax.swing.JMenuBar;
0071: import javax.swing.JMenuItem;
0072: import javax.swing.JOptionPane;
0073: import javax.swing.JPanel;
0074: import javax.swing.JScrollPane;
0075: import javax.swing.JSplitPane;
0076: import javax.swing.JTabbedPane;
0077: import javax.swing.JToolBar;
0078: import javax.swing.JTree;
0079: import javax.swing.KeyStroke;
0080: import javax.swing.ListSelectionModel;
0081: import javax.swing.WindowConstants;
0082: import javax.swing.table.TableColumn;
0083: import javax.swing.table.TableColumnModel;
0084: import javax.swing.tree.TreePath;
0085: import javax.swing.tree.TreeSelectionModel;
0086: import javax.swing.undo.UndoManager;
0087:
0088: import org.apache.log4j.Logger;
0089: import org.isqlviewer.ServiceReference;
0090: import org.isqlviewer.bookmarks.Bookmark;
0091: import org.isqlviewer.bookmarks.BookmarkFolder;
0092: import org.isqlviewer.bookmarks.BookmarkReference;
0093: import org.isqlviewer.history.HistoricalCommand;
0094: import org.isqlviewer.model.BookmarkTreeModel;
0095: import org.isqlviewer.model.HistoryTreeModel;
0096: import org.isqlviewer.model.JdbcSchemaTreeModel;
0097: import org.isqlviewer.sql.ConnectionProfile;
0098: import org.isqlviewer.sql.JdbcService;
0099: import org.isqlviewer.sql.JdbcUtilities;
0100: import org.isqlviewer.sql.embedded.CompatabilityKit;
0101: import org.isqlviewer.sql.embedded.EmbeddedDatabase;
0102: import org.isqlviewer.swing.DocumentAppender;
0103: import org.isqlviewer.swing.EnhancedTabbedPane;
0104: import org.isqlviewer.swing.LoginDialog;
0105: import org.isqlviewer.swing.Refreshable;
0106: import org.isqlviewer.swing.SwingUtilities;
0107: import org.isqlviewer.swing.TabbedPaneLister;
0108: import org.isqlviewer.swing.WizardPanel;
0109: import org.isqlviewer.swing.action.CustomAction;
0110: import org.isqlviewer.swing.action.RefreshViewAction;
0111: import org.isqlviewer.swing.action.SharedActions;
0112: import org.isqlviewer.swing.action.SwingEventManager;
0113: import org.isqlviewer.swing.outline.JOutline;
0114: import org.isqlviewer.swing.table.EnhancedTableModel;
0115: import org.isqlviewer.ui.dnd.BookmarkTreeDropTarget;
0116: import org.isqlviewer.ui.dnd.ResultSetRendererDropTarget;
0117: import org.isqlviewer.ui.listeners.BookmarkMouseInputListener;
0118: import org.isqlviewer.ui.listeners.BookmarkTreeDragListener;
0119: import org.isqlviewer.ui.listeners.HistoryTreeDragListener;
0120: import org.isqlviewer.ui.listeners.SchemaTreeDragListener;
0121: import org.isqlviewer.ui.listeners.SchemaTreeListener;
0122: import org.isqlviewer.ui.renderer.BookmarkTreeCellRenderer;
0123: import org.isqlviewer.ui.renderer.HistoryTableCellRenderer;
0124: import org.isqlviewer.ui.renderer.HistoryTreeCellRenderer;
0125: import org.isqlviewer.ui.renderer.JDBCTreeCellRenderer;
0126: import org.isqlviewer.ui.wizards.Wizard;
0127: import org.isqlviewer.ui.wizards.service.ServiceWizard;
0128: import org.isqlviewer.util.IsqlToolkit;
0129: import org.isqlviewer.util.LocalMessages;
0130: import org.isqlviewer.util.QueryExecutor;
0131: import org.isqlviewer.util.StringUtilities;
0132: import org.isqlviewer.xml.ServiceDigester;
0133: import org.xml.sax.InputSource;
0134:
0135: /**
0136: * @author Mark A. Kobold <mkobold at isqlviewer dot com>
0137: * @version 1.0
0138: */
0139: public class JdbcWorkbench extends AbstractApplicationView implements
0140: ActionListener, TabbedPaneLister {
0141:
0142: // Preference keys for this view //
0143: private static final String SESSION_TEXT = "session.text";
0144: private static final String BOOKMARK_VISIBLE = "bookmark.visible";
0145: private static final String HISTORY_VISIBLE = "history.visible";
0146: private static final String SCHEMA_VISIBLE = "schema.visible";
0147: private static final String SOUTH_DIVIDER = "south.divider.location";
0148: private static final String WEST_DIVIDER = "west.divider.location";
0149: private static final String EAST_DIVIDER = "east.divider.location";
0150: private static final String CENTER_DIVIDER = "center.divider.location";
0151:
0152: private static final String DIVIDER_LOCATION = "org.isqlviewer.divider.location";
0153:
0154: private Preferences preferences = null;
0155: private JdbcSchemaTreeModel schemaModel = new JdbcSchemaTreeModel();
0156: private SqlCommandEditor commandEditor = new SqlCommandEditor(true);
0157: private JEditorPane console = new JEditorPane("text/rtf", "");
0158: private HistoryTreeModel commandHistory = new HistoryTreeModel();
0159: private JOutline historyView = new JOutline(commandHistory);
0160: private JTree schemaView = new JTree(schemaModel);
0161: private JTree bookmarkView = new JTree();
0162:
0163: private LocalMessages messages = new LocalMessages(
0164: "org.isqlviewer.ui.ResourceBundle");
0165:
0166: private SwingEventManager eventManager;
0167: private UndoManager undoManager = new UndoManager();
0168:
0169: private JMenu catalogMenu = null;
0170: private JMenu schemaMenu = null;
0171: private JMenu serviceMenu = null;
0172:
0173: private ButtonGroup catalogSelection = new ButtonGroup();
0174: private ButtonGroup schemaSelection = new ButtonGroup();
0175:
0176: private JdbcService currentService = null;
0177: private TabbedResultsetRenderer tabRenderer;
0178:
0179: private EnhancedTabbedPane rhsTabbedPane = new EnhancedTabbedPane(
0180: EnhancedTabbedPane.TOP);
0181: private EnhancedTabbedPane lhsTabbedPane = new EnhancedTabbedPane(
0182: EnhancedTabbedPane.TOP);
0183: private EnhancedTabbedPane centerTabbedPane = new EnhancedTabbedPane(
0184: EnhancedTabbedPane.TOP);
0185:
0186: private JSplitPane lhsSplitPane = new JSplitPane(
0187: JSplitPane.HORIZONTAL_SPLIT);
0188: private JSplitPane rhsSplitPane = new JSplitPane(
0189: JSplitPane.HORIZONTAL_SPLIT);
0190: private JSplitPane centerSplitPane = new JSplitPane(
0191: JSplitPane.VERTICAL_SPLIT);
0192: private JSplitPane rootSplitPane = new JSplitPane(
0193: JSplitPane.VERTICAL_SPLIT);
0194: private DocumentAppender documentAppender;
0195:
0196: public JdbcWorkbench() {
0197:
0198: Logger rootLogger = IsqlToolkit.getApplicationLogger();
0199: documentAppender = new DocumentAppender(console.getDocument(),
0200: console);
0201: rootLogger.addAppender(documentAppender);
0202: }
0203:
0204: public void actionPerformed(ActionEvent event) {
0205:
0206: int id = event.getID();
0207: switch (id) {
0208: case SharedActions.REFRESH_SELECTED_RESULTS:
0209: break;
0210: case SharedActions.NAVIGATE_LEFT_TAB:
0211: navigateLeftTab();
0212: break;
0213: case SharedActions.NAVIGATE_RIGHT_TAB:
0214: navigateRightTab();
0215: break;
0216: case SharedActions.CLOSE_SELECTED_RESULTS:
0217: closeSelectedResult();
0218: break;
0219: case SharedActions.CLOSE_ALL_RESULTS:
0220: centerTabbedPane.removeAllTabs();
0221: break;
0222: case SharedActions.CLEAR_ALL_HISTORY:
0223: clearAllHistory();
0224: break;
0225: case SharedActions.SERVICE_REMOVED:
0226: initializeServiceMenu();
0227: reloadQueryHistory();
0228: break;
0229: case SharedActions.SERVICE_UPDATED:
0230: case SharedActions.SERVICE_ADDED:
0231: initializeServiceMenu();
0232: break;
0233: case SharedActions.EXIT_APPLICATION:
0234: Window windowOwner = javax.swing.SwingUtilities
0235: .getWindowAncestor(console);
0236: windowOwner.dispatchEvent(new WindowEvent(windowOwner,
0237: WindowEvent.WINDOW_CLOSING));
0238: break;
0239: case SharedActions.EDIT_BOOKMARK:
0240: case SharedActions.DELETE_BOOKMARK_SELECTION:
0241: case SharedActions.ADD_BOOKMARK_FOLDER:
0242: case SharedActions.CREATE_NEW_BOOKMARK:
0243: TreePath tp = bookmarkView.getSelectionPath();
0244: Object selected = tp == null ? null : tp
0245: .getLastPathComponent();
0246: handleBookmarkAction(id, selected);
0247: break;
0248:
0249: case SharedActions.CONVERT_TEXT_TO_BOOKMARK:
0250: case SharedActions.CONVERT_HISTORY_TO_BOOKMARK:
0251: convertToBookmark(event);
0252: break;
0253: case SharedActions.SHOW_SERVICE_WIZARD:
0254: showWizard(ServiceWizard.class);
0255: break;
0256: case SharedActions.SHOW_CONNECTION_INFO:
0257: if (checkConnection()) {
0258: queryDatabaseMetadata();
0259: }
0260: break;
0261: case SharedActions.REFRESH_SELECTED_VIEW:
0262: Refreshable source = (Refreshable) event.getSource();
0263: if (source != null) {
0264: source.refreshView();
0265: }
0266: break;
0267: case SharedActions.SCHEMA_CHANGED:
0268: String selectedSchema = event.getActionCommand();
0269: String currentSchema = schemaModel.getCurrentSchema();
0270: if (!StringUtilities.compare(currentSchema, selectedSchema)) {
0271: schemaModel.setSchema(selectedSchema, true);
0272: info(messages.format("jdbcworkbench.schema_change",
0273: selectedSchema, currentSchema));
0274: updateSyntaxHighlighting();
0275: } else {
0276: info(messages.format(
0277: "jdbcworkbench.schema_change_skip",
0278: currentSchema));
0279: }
0280: break;
0281: case SharedActions.CATALOG_CHANGED:
0282: String selectedCatalog = catalogSelection.getSelection()
0283: .getActionCommand();
0284: String currentCatalog = schemaModel.getCurrentCatlog();
0285: if (!StringUtilities.compare(selectedCatalog,
0286: currentCatalog)) {
0287: info(messages.format("jdbcworkbench.catalog_change",
0288: selectedCatalog, currentCatalog));
0289: schemaModel.setCatalog(selectedCatalog, true);
0290: try {
0291: currentService.getConnection().setCatalog(
0292: selectedCatalog);
0293: updateSyntaxHighlighting();
0294: } catch (SQLException ignored) {
0295: }
0296: } else {
0297: info(messages.format(
0298: "jdbcworkbench.catalog_change_skip",
0299: currentCatalog));
0300: }
0301: break;
0302: case SharedActions.EXECUTE_SQL_COMMAND:
0303: String statement = event.getActionCommand();
0304: boolean connected = checkConnection();
0305: if (connected) {
0306: QueryExecutor executor = new QueryExecutor(
0307: currentService, tabRenderer, statement);
0308: executor.run();
0309: }
0310: break;
0311: case SharedActions.SERVICE_CONNECT:
0312: String service = event.getActionCommand();
0313: changeConnection(service);
0314: updateSyntaxHighlighting();
0315: break;
0316: case SharedActions.SERVICE_DISCONNECT:
0317: handleServiceDisconnect();
0318: break;
0319: case EnhancedTabbedPane.ACTION_TAB_DBL_CLICKED:
0320: Component componentSource = (Component) event.getSource();
0321: if (zoomComponent(componentSource) instanceof JTabbedPane) {
0322: restoreZoom(componentSource);
0323: }
0324: break;
0325: default:
0326: break;
0327: }
0328: }
0329:
0330: public void doLayout(JComponent parentComponent,
0331: Preferences userPreferences,
0332: SwingEventManager swingEventManager) {
0333:
0334: preferences = userPreferences.node("views/jdbc-workbench");
0335: tabRenderer = new TabbedResultsetRenderer(centerTabbedPane);
0336: this .eventManager = swingEventManager;
0337: this .eventManager.addActionListener(this );
0338:
0339: rhsSplitPane.setContinuousLayout(true);
0340: centerSplitPane.setContinuousLayout(true);
0341: lhsSplitPane.setContinuousLayout(true);
0342: rootSplitPane.setContinuousLayout(true);
0343:
0344: JPanel container = new JPanel();
0345: commandEditor
0346: .doLayout(container, userPreferences, eventManager);
0347: centerSplitPane.setTopComponent(container);
0348: centerSplitPane.setBottomComponent(centerTabbedPane);
0349: centerSplitPane.setBorder(BorderFactory.createEmptyBorder());
0350:
0351: rhsTabbedPane.setName("rhs");
0352: rhsTabbedPane.addActionListener(this );
0353: rhsTabbedPane.addTabbedPaneListener(this );
0354:
0355: lhsTabbedPane.setName("lhs");
0356: lhsTabbedPane.addActionListener(this );
0357: lhsTabbedPane.addTabbedPaneListener(this );
0358:
0359: TabbedResultsetRenderer renderer = new TabbedResultsetRenderer(
0360: centerTabbedPane);
0361: ResultSetRendererDropTarget rsrdt = new ResultSetRendererDropTarget();
0362: rsrdt.setEventManager(eventManager);
0363: rsrdt.setNodeRenderer(renderer);
0364: rsrdt.setTreeModel(schemaModel);
0365: try {
0366: DropTarget dt = new DropTarget();
0367: dt.addDropTargetListener(rsrdt);
0368: centerTabbedPane.setDropTarget(dt);
0369: } catch (TooManyListenersException e) {
0370: }
0371:
0372: centerTabbedPane.setName("query-results");
0373: centerTabbedPane.addActionListener(this );
0374: centerTabbedPane.addTabbedPaneListener(this );
0375:
0376: rhsSplitPane.setLeftComponent(centerSplitPane);
0377: rhsSplitPane.setBorder(BorderFactory.createEmptyBorder());
0378:
0379: lhsSplitPane.setRightComponent(rhsSplitPane);
0380: lhsSplitPane.setBorder(BorderFactory.createEmptyBorder());
0381:
0382: rootSplitPane.setTopComponent(lhsSplitPane);
0383: rootSplitPane.setBottomComponent(new JScrollPane(console));
0384: rootSplitPane.setBorder(BorderFactory.createEmptyBorder());
0385:
0386: parentComponent.setLayout(new BorderLayout());
0387: parentComponent.add(rootSplitPane, BorderLayout.CENTER);
0388:
0389: bookmarkView.setCellRenderer(new BookmarkTreeCellRenderer());
0390: bookmarkView.setRootVisible(false);
0391: bookmarkView.setScrollsOnExpand(true);
0392: }
0393:
0394: public void configureMenubar(JMenuBar menuBar) {
0395:
0396: menuBar.add(createFileMenu(eventManager, messages
0397: .getMessage("menu.file.title")));
0398:
0399: menuBar.add(createServiceMenu(messages
0400: .getMessage("menu.service.title")));
0401: menuBar.add(createCatalogMenu(messages
0402: .getMessage("menu.catalog.title")));
0403: menuBar.add(createSchemaMenu(messages
0404: .getMessage("menu.schema.title")));
0405: menuBar.add(createWindowMenu(eventManager, messages
0406: .getMessage("menu.window.title")));
0407: menuBar.add(createToolMenu(eventManager, messages
0408: .getMessage("menu.tools.title")));
0409:
0410: if (!SwingUtilities.isMacOS()
0411: || !Boolean
0412: .getBoolean(IsqlToolkit.PROPERTY_MRJ_ENABLED)) {
0413: JMenu t = createMenu(messages.format("menu.help.title"));
0414: menuBar.add(t);
0415: }
0416: }
0417:
0418: public void initializeView() {
0419:
0420: String isqlVersion = System
0421: .getProperty(IsqlToolkit.PROPERTY_VERSION);
0422: info(messages.format("JdbcWorkbench.initializing_isql",
0423: isqlVersion));
0424:
0425: String logicalVersion = System
0426: .getProperty("java.specification.version");
0427: String actualVersion = System.getProperty("java.version");
0428: String vmProvider = System.getProperty("java.vm.vendor");
0429: info(messages.format("JdbcWorkbench.jre_information",
0430: actualVersion, logicalVersion, vmProvider));
0431:
0432: configureSplitPanel(rhsSplitPane, EAST_DIVIDER);
0433: configureSplitPanel(centerSplitPane, CENTER_DIVIDER);
0434: configureSplitPanel(lhsSplitPane, WEST_DIVIDER);
0435: configureSplitPanel(rootSplitPane, SOUTH_DIVIDER);
0436:
0437: localizeTextComponent(console, undoManager);
0438: console.setEditable(false);
0439: console.setDragEnabled(true);
0440:
0441: commandEditor.initializeView();
0442: schemaMenu.setEnabled(false);
0443: catalogMenu.setEnabled(false);
0444:
0445: String sessionText = preferences.get(SESSION_TEXT, "");
0446: commandEditor.setText(sessionText);
0447:
0448: EmbeddedDatabase edb = EmbeddedDatabase.getSharedInstance();
0449: try {
0450: if (edb.initialize()) {
0451: info(messages.format("JdbcWorkbench.importing_service"));
0452: Collection<ServiceReference> services = CompatabilityKit
0453: .get2xxServices();
0454: for (ServiceReference serviceReference : services) {
0455: info(messages.format(
0456: "JdbcWorkbench.importing_service_x",
0457: serviceReference.getName()));
0458: edb.addService(serviceReference);
0459: }
0460: info(messages
0461: .format("JdbcWorkbench.importing_service_complete"));
0462:
0463: BookmarkFolder rootFolder = CompatabilityKit
0464: .get2xxBookmarks();
0465: if (rootFolder != null) {
0466: info(messages
0467: .format("JdbcWorkbench.importing_bookmarks"));
0468: edb.addBookmarkFolder(rootFolder);
0469: } else {
0470: info(messages
0471: .format("JdbcWorkbench.skipping_importing_bookmarks"));
0472: }
0473:
0474: info(messages.format("JdbcWorkbench.importing_history"));
0475: Collection<HistoricalCommand> history = CompatabilityKit
0476: .get2xxHistory();
0477: for (HistoricalCommand item : history) {
0478: edb.addHistoricalCommand(item);
0479: }
0480: info(messages.format(
0481: "JdbcWorkbench.import_history_success", Integer
0482: .toString(history.size())));
0483: }
0484: } catch (SQLException error) {
0485: error(
0486: messages
0487: .format("JdbcWorkbench.failed_to_initialize_internal_database"),
0488: error);
0489: }
0490: try {
0491: BookmarkFolder rootFolder = edb.getBookmarks();
0492: bookmarkView.setModel(new BookmarkTreeModel(rootFolder));
0493: initializeServiceMenu();
0494: reloadQueryHistory();
0495: } catch (SQLException e) {
0496: error(messages
0497: .format("JdbcWorkbench.failed_to_load_bookmarks"),
0498: e);
0499: return;
0500: }
0501: info(messages.format("JdbcWorkbench.initialization_complete"));
0502: }
0503:
0504: public void disposeView(Preferences userPreferences) {
0505:
0506: preferences = userPreferences.node("views/jdbc-workbench");
0507: preferences.putInt(CENTER_DIVIDER, centerSplitPane
0508: .getDividerLocation());
0509: preferences.putInt(EAST_DIVIDER, rhsSplitPane
0510: .getDividerLocation());
0511: preferences.putInt(WEST_DIVIDER, lhsSplitPane
0512: .getDividerLocation());
0513: preferences.putInt(SOUTH_DIVIDER, rootSplitPane
0514: .getDividerLocation());
0515:
0516: Boolean clientProperty = null;
0517: clientProperty = (Boolean) schemaView
0518: .getClientProperty(SCHEMA_VISIBLE);
0519: preferences.putBoolean(SCHEMA_VISIBLE, clientProperty
0520: .booleanValue());
0521:
0522: clientProperty = (Boolean) historyView
0523: .getClientProperty(HISTORY_VISIBLE);
0524: preferences.putBoolean(HISTORY_VISIBLE, clientProperty
0525: .booleanValue());
0526:
0527: clientProperty = (Boolean) bookmarkView
0528: .getClientProperty(BOOKMARK_VISIBLE);
0529: preferences.putBoolean(BOOKMARK_VISIBLE, clientProperty
0530: .booleanValue());
0531:
0532: preferences.put(SESSION_TEXT, commandEditor.getText());
0533: unlocalizeTextComponent(console, undoManager);
0534: }
0535:
0536: public void tabAdded(JTabbedPane tabPane, int index,
0537: Component component) {
0538:
0539: }
0540:
0541: public void tabRemoved(JTabbedPane tabPane, int index,
0542: Component component) {
0543:
0544: WorkbenchView view = (WorkbenchView) ((JComponent) component)
0545: .getClientProperty("type");
0546: WizardPanel panel = (WizardPanel) javax.swing.SwingUtilities
0547: .getAncestorOfClass(WizardPanel.class, tabPane);
0548: Component rootView = panel.getCard("root-view");
0549: boolean isEmptyTabbedPane = tabPane.getTabCount() == 0;
0550: if (isEmptyTabbedPane && rootView == tabPane) {
0551: zoomComponent(tabPane);
0552: if (tabPane == centerTabbedPane) {
0553: centerSplitPane.setBottomComponent(centerTabbedPane);
0554: restoreZoom(tabPane);
0555: centerSplitPane.invalidate();
0556: }
0557: } else if (isEmptyTabbedPane && tabPane != centerTabbedPane) {
0558: JSplitPane parent = (JSplitPane) javax.swing.SwingUtilities
0559: .getAncestorOfClass(JSplitPane.class, tabPane);
0560: parent.putClientProperty(DIVIDER_LOCATION, new Integer(
0561: parent.getDividerLocation()));
0562: parent.remove(tabPane);
0563: }
0564: if (view != null) {
0565: switch (view) {
0566: case BOOKMARK:
0567: bookmarkView.putClientProperty(BOOKMARK_VISIBLE,
0568: Boolean.FALSE);
0569: break;
0570: case HISTORY:
0571: historyView.putClientProperty(HISTORY_VISIBLE,
0572: Boolean.FALSE);
0573: break;
0574: case SCHEMA:
0575: schemaView.putClientProperty(SCHEMA_VISIBLE,
0576: Boolean.FALSE);
0577: break;
0578: }
0579: }
0580: }
0581:
0582: public Component zoomComponent(Component view) {
0583:
0584: JSplitPane splitParent = (JSplitPane) javax.swing.SwingUtilities
0585: .getAncestorOfClass(JSplitPane.class, view);
0586: if (splitParent != null) {
0587: splitParent.putClientProperty(DIVIDER_LOCATION,
0588: new Integer(splitParent.getDividerLocation()));
0589: }
0590: WizardPanel panel = (WizardPanel) javax.swing.SwingUtilities
0591: .getAncestorOfClass(WizardPanel.class, view);
0592: Component old = panel.removeCard("root-view");
0593: if (view != null && view != old) {
0594: panel.add(view, "root-view");
0595: panel.showCard("root-view");
0596: panel.add(old, "previous");
0597: panel.invalidate();
0598: } else {
0599: Component previous = panel.removeCard("previous");
0600: panel.add(previous, "root-view");
0601: }
0602: return old;
0603: }
0604:
0605: private void convertToBookmark(ActionEvent event) {
0606:
0607: Object eventSource = event.getSource();
0608: Bookmark bookmark = new Bookmark();
0609: if (eventSource instanceof HistoricalCommand) {
0610: HistoricalCommand historicalCommand = (HistoricalCommand) event
0611: .getSource();
0612: bookmark.setCreationTime(historicalCommand.getQueryTime());
0613: bookmark.setCommandText(historicalCommand.getCommandText());
0614: } else if (eventSource instanceof String) {
0615: bookmark.setCreationTime(new Date());
0616: bookmark.setCommandText((String) eventSource);
0617: } else {
0618: return;
0619: }
0620: String targetPath = event.getActionCommand();
0621:
0622: BookmarkTreeModel model = (BookmarkTreeModel) bookmarkView
0623: .getModel();
0624: BookmarkFolder rootFolder = (BookmarkFolder) model.getRoot();
0625: BookmarkFolder targetFolder = rootFolder
0626: .findChildPath(targetPath);
0627: bookmark.setLastAccess(new Date());
0628: bookmark.setFolder(targetFolder);
0629:
0630: EmbeddedDatabase database = EmbeddedDatabase
0631: .getSharedInstance();
0632: OperationStatus status = showModalEditor(BookmarkEditor.class,
0633: bookmark);
0634: if (status == OperationStatus.MODIFIED) {
0635: try {
0636: BookmarkReference reference = database
0637: .addBookmark(bookmark);
0638: model.addBookmark(reference, targetFolder);
0639: } catch (SQLException e) {
0640: error("", e);
0641: }
0642: }
0643: }
0644:
0645: private void reloadQueryHistory() {
0646:
0647: EmbeddedDatabase edb = EmbeddedDatabase.getSharedInstance();
0648: commandHistory.clear();
0649: try {
0650: Collection<HistoricalCommand> history = edb.getHistory();
0651: for (HistoricalCommand reference : history) {
0652: commandHistory.addReference(reference);
0653: }
0654: } catch (SQLException error) {
0655: error("", error);
0656: } finally {
0657: commandHistory.reload();
0658: }
0659: }
0660:
0661: private void initializeServiceMenu() {
0662:
0663: EmbeddedDatabase edb = EmbeddedDatabase.getSharedInstance();
0664: serviceMenu.removeAll();
0665: try {
0666: Collection<ServiceReference> services = edb
0667: .getRegisteredServices();
0668: for (ServiceReference reference : services) {
0669: String serviceName = reference.getName();
0670: addDynamicAction(serviceMenu, eventManager, "service",
0671: SharedActions.SERVICE_CONNECT, serviceName);
0672: }
0673: } catch (SQLException error) {
0674: error(messages
0675: .format("JdbcWorkbench.error_loading_services"),
0676: error);
0677: }
0678: serviceMenu.addSeparator();
0679: CustomAction ca = null;
0680: String acclerator = null;
0681:
0682: ca = new CustomAction("disconnect-service",
0683: SharedActions.SERVICE_DISCONNECT, eventManager);
0684: acclerator = messages
0685: .format("menu.disconnect_service.accelerator");
0686: ca.putValue(CustomAction.ICON_NAME, "disconnect");
0687: ca.putValue(Action.ACCELERATOR_KEY, SwingUtilities
0688: .getKeyStroke(acclerator));
0689: ca.putValue(Action.DEFAULT, messages
0690: .getMessage("menu.disconnect_service.title"));
0691: addMenuItem(serviceMenu, ca);
0692: }
0693:
0694: private void handleServiceDisconnect() {
0695:
0696: try {
0697: currentService.getConnection().close();
0698: } catch (SQLException sqle) {
0699: } finally {
0700: schemaModel.clear();
0701: }
0702: info(messages.format("jdbcworkbench.serivcedisconnect",
0703: currentService.getName()));
0704: }
0705:
0706: private boolean promptForService() {
0707:
0708: Object message = messages
0709: .getMessage("jdbcworkbench.please_select_your_service");
0710:
0711: EmbeddedDatabase edb = EmbeddedDatabase.getSharedInstance();
0712:
0713: Object[] selectionValues;
0714:
0715: try {
0716: Collection<ServiceReference> references = edb
0717: .getRegisteredServices();
0718: selectionValues = new Object[references.size()];
0719: int i = 0;
0720: for (ServiceReference reference : references) {
0721: selectionValues[i++] = reference.getName();
0722: }
0723: } catch (SQLException e) {
0724: error("", e);
0725: return false;
0726: }
0727:
0728: int type = JOptionPane.INFORMATION_MESSAGE;
0729: Frame frameOwner = (Frame) javax.swing.SwingUtilities
0730: .getAncestorOfClass(Frame.class, centerTabbedPane);
0731: Object selection = JOptionPane.showInputDialog(frameOwner,
0732: message, "", type, null, selectionValues, null);
0733: if (selection != null) {
0734: return changeConnection((String) selection);
0735: }
0736: return false;
0737: }
0738:
0739: private boolean changeConnection(String service) {
0740:
0741: if (currentService != null) {
0742: handleServiceDisconnect();
0743: }
0744: EmbeddedDatabase database = EmbeddedDatabase
0745: .getSharedInstance();
0746: try {
0747: ServiceReference reference = database
0748: .getServiceForName(service);
0749: URL url = reference.getResourceURL();
0750: InputStream inputStream = null;
0751: try {
0752: inputStream = url.openStream();
0753: InputSource inputSource = new InputSource(inputStream);
0754: currentService = ServiceDigester.parseService(
0755: inputSource, IsqlToolkit
0756: .getSharedEntityResolver());
0757: } catch (IOException error) {
0758: error("", error);
0759: } catch (Exception error) {
0760: error("", error);
0761: }
0762: } catch (SQLException error) {
0763: error("", error);
0764: }
0765:
0766: currentService.setCommandLogger(commandHistory);
0767: ConnectionProfile profile = currentService.getProfile();
0768: Connection connection = null;
0769: if (requiresPrompt(currentService)) {
0770: Frame frameOwner = (Frame) javax.swing.SwingUtilities
0771: .getAncestorOfClass(Frame.class, centerTabbedPane);
0772: LoginDialog dialog = new LoginDialog(frameOwner);
0773: dialog.setVisible(true);
0774: String[] tokens = dialog.getAuthTokens();
0775: if (tokens == null) {
0776: info(messages.format(
0777: "jdbcworkbench.connectioncancelled", service));
0778: return false;
0779: }
0780: try {
0781: connection = currentService.getConnection(tokens[0],
0782: tokens[1]);
0783: } catch (SQLException ignored) {
0784: return false;
0785: }
0786: } else {
0787: try {
0788: connection = currentService.getConnection();
0789: } catch (SQLException ignored) {
0790: return false;
0791: }
0792: }
0793: Logger newLogger = Logger.getLogger(currentService
0794: .getDriverClass());
0795: newLogger.addAppender(documentAppender);
0796:
0797: try {
0798: String preferredSchema = buildSchemaMenu(connection,
0799: profile);
0800: String preferredCatalog = buildCatalogMenu(connection,
0801: profile);
0802: DatabaseMetaData metaData = currentService.getConnection()
0803: .getMetaData();
0804:
0805: info(messages.format("jdbcworkbench.connectionsucessfull",
0806: service, preferredSchema, preferredCatalog));
0807:
0808: String name = metaData.getDriverName();
0809: String version = metaData.getDriverVersion();
0810: info(messages.format("jdbcworkbench.driver_information",
0811: name, version));
0812: name = metaData.getDatabaseProductName();
0813: version = metaData.getDatabaseProductVersion();
0814: info(messages.format("jdbcworkbench.database_information",
0815: name, version));
0816:
0817: schemaMenu.setEnabled(true);
0818: catalogMenu.setEnabled(true);
0819: schemaModel.setSchema(preferredSchema, false);
0820: schemaModel.setCatalog(preferredCatalog, false);
0821: schemaModel.updateConnection(connection, false);
0822: schemaModel.reload();
0823: } catch (SQLException e) {
0824: error("xxxxxx", e);
0825: }
0826: return true;
0827: }
0828:
0829: private static boolean requiresPrompt(JdbcService currentService) {
0830:
0831: String principal = currentService.getPrincipal();
0832: String credentials = currentService.getCredentials();
0833: return principal == null && credentials == null;
0834: }
0835:
0836: // private void showModalView(Class< ? extends AbstractApplicationView> name) {
0837: //
0838: // Preferences prefs = Preferences.userRoot().node(IsqlToolkit.getRootPreferencesNode());
0839: // AbstractApplicationView instance = null;
0840: // try {
0841: // instance = name.newInstance();
0842: // Object frameOwner = javax.swing.SwingUtilities.getAncestorOfClass(Frame.class, centerTabbedPane);
0843: // JDialog dialog = new JDialog((Frame) frameOwner);
0844: // JComponent contentPanel = (JComponent) dialog.getContentPane();
0845: // instance.doLayout(contentPanel, prefs, eventManager);
0846: // instance.initializeView();
0847: // dialog.pack();
0848: // dialog.setLocationRelativeTo((Component) frameOwner);
0849: // dialog.setModal(true);
0850: // dialog.setVisible(true);
0851: // } catch (InstantiationException e) {
0852: // debug("", e);
0853: // } catch (IllegalAccessException e) {
0854: // debug("", e);
0855: // } finally {
0856: // if (instance != null) {
0857: // try {
0858: // instance.disposeView(prefs);
0859: // } catch (Exception ignored) {
0860: // debug("", ignored);
0861: // }
0862: // }
0863: // }
0864: // }
0865:
0866: private void showWizard(Class<? extends Wizard> wizard) {
0867:
0868: Wizard instance = null;
0869: try {
0870: instance = wizard.newInstance();
0871: Frame frameOwner = (Frame) javax.swing.SwingUtilities
0872: .getAncestorOfClass(Frame.class, centerTabbedPane);
0873: WizardRunner wizardRunner = new WizardRunner(frameOwner,
0874: instance, eventManager);
0875: wizardRunner.pack();
0876: wizardRunner.setLocationRelativeTo(frameOwner);
0877: wizardRunner.setModal(true);
0878: wizardRunner.setVisible(true);
0879: } catch (InstantiationException e) {
0880: e.printStackTrace();
0881: } catch (IllegalAccessException e) {
0882: e.printStackTrace();
0883: }
0884: }
0885:
0886: private OperationStatus showModalEditor(
0887: Class<? extends AbstractObjectEditor> name,
0888: Object editableObject) {
0889:
0890: Preferences prefs = Preferences.userRoot().node(
0891: IsqlToolkit.getRootPreferencesNode());
0892: AbstractObjectEditor instance = null;
0893: try {
0894: instance = name.newInstance();
0895: Object frameOwner = javax.swing.SwingUtilities
0896: .getAncestorOfClass(Frame.class, centerTabbedPane);
0897: JDialog dialog = new JDialog((Frame) frameOwner);
0898:
0899: JComponent contentPanel = (JComponent) dialog
0900: .getContentPane();
0901: instance.doLayout(contentPanel, prefs, eventManager);
0902: instance.initializeView(editableObject);
0903: dialog
0904: .setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
0905: dialog.pack();
0906: dialog.setLocationRelativeTo((Component) frameOwner);
0907: dialog.setModal(true);
0908: dialog.setVisible(true);
0909: } catch (InstantiationException e) {
0910: e.printStackTrace();
0911: } catch (IllegalAccessException e) {
0912: e.printStackTrace();
0913: } finally {
0914: if (instance != null) {
0915: try {
0916: instance.disposeView(prefs);
0917: } catch (Exception ignored) {
0918: debug("", ignored);
0919: }
0920: }
0921: }
0922: if (instance != null) {
0923: return instance.getStatus();
0924: }
0925: return OperationStatus.UNKNOWN;
0926: }
0927:
0928: private JComponent layoutHistoryContainer(SwingEventManager manager) {
0929:
0930: JPanel view = new JPanel(new BorderLayout());
0931: view.putClientProperty("type", WorkbenchView.HISTORY);
0932: JToolBar toolbar = new JToolBar("history-tools",
0933: JToolBar.HORIZONTAL);
0934: toolbar.setFloatable(false);
0935: toolbar.setBorder(BorderFactory.createEmptyBorder());
0936:
0937: historyView.setTreeCellRenderer(new HistoryTreeCellRenderer(
0938: historyView));
0939: TableColumnModel columnModel = historyView.getColumnModel();
0940: TableColumn column = columnModel.getColumn(1);
0941: column.setCellRenderer(new HistoryTableCellRenderer(
0942: commandHistory));
0943:
0944: historyView.setRootVisible(false);
0945: ListSelectionModel tableSelectionModel = historyView
0946: .getSelectionModel();
0947: tableSelectionModel
0948: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
0949:
0950: HistoryTreeDragListener dragListener = new HistoryTreeDragListener(
0951: historyView);
0952: DragSource dndDragSource = DragSource.getDefaultDragSource();
0953: dndDragSource.createDefaultDragGestureRecognizer(historyView,
0954: DnDConstants.ACTION_COPY_OR_MOVE, dragListener);
0955:
0956: Action action = null;
0957: action = new CustomAction("clear-all-history",
0958: SharedActions.CLEAR_ALL_HISTORY, manager);
0959: action.putValue(Action.SHORT_DESCRIPTION, messages
0960: .getMessage("JdbcWorkbench.clear-all-history"));
0961: action.putValue(CustomAction.ICON_NAME, "history_clear");
0962: addButton(toolbar, manager, action);
0963:
0964: view.add(toolbar, BorderLayout.NORTH);
0965: view.add(new JScrollPane(historyView), BorderLayout.CENTER);
0966:
0967: return view;
0968: }
0969:
0970: private JComponent layoutBookmarkContainer(SwingEventManager manager) {
0971:
0972: JPanel view = new JPanel(new BorderLayout());
0973: view.putClientProperty("type", WorkbenchView.BOOKMARK);
0974: JToolBar toolbar = new JToolBar("bookmark-tools",
0975: JToolBar.HORIZONTAL);
0976:
0977: toolbar.setFloatable(false);
0978: toolbar.setBorder(BorderFactory.createEmptyBorder());
0979:
0980: view.add(toolbar, BorderLayout.NORTH);
0981: view.add(new JScrollPane(bookmarkView), BorderLayout.CENTER);
0982:
0983: bookmarkView.setDragEnabled(true);
0984: bookmarkView.setEditable(true);
0985: bookmarkView.getSelectionModel().setSelectionMode(
0986: TreeSelectionModel.SINGLE_TREE_SELECTION);
0987: bookmarkView.addMouseListener(new BookmarkMouseInputListener(
0988: bookmarkView, manager));
0989:
0990: BookmarkTreeDropTarget bookmarkDropListener = new BookmarkTreeDropTarget(
0991: manager);
0992: int supportedActions = DnDConstants.ACTION_COPY_OR_MOVE;
0993: bookmarkView.setDropTarget(new DropTarget(bookmarkView,
0994: supportedActions, bookmarkDropListener));
0995:
0996: Action action = null;
0997: InputMap im = bookmarkView.getInputMap(JComponent.WHEN_FOCUSED);
0998: ActionMap am = bookmarkView.getActionMap();
0999: KeyStroke ks = null;
1000:
1001: ks = KeyStroke.getKeyStroke(KeyEvent.VK_I,
1002: SwingUtilities.MENU_SHORTCUT_MASK, true);
1003: im.put(ks, "edit-bookmark");
1004: action = new CustomAction("edit-bookmark",
1005: SharedActions.EDIT_BOOKMARK, manager);
1006: action.putValue(Action.ACCELERATOR_KEY, ks);
1007: action.putValue(Action.SHORT_DESCRIPTION, messages
1008: .getMessage("JdbcWorkbench.edit_bookmark"));
1009: action.putValue(CustomAction.ICON_NAME, "edit");
1010: am.put("edit-bookmark", action);
1011:
1012: ks = KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0, true);
1013: im.put(ks, "delete-bookmark-selection");
1014: ks = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, true);
1015: action = new CustomAction("delete-bookmark-selection",
1016: SharedActions.DELETE_BOOKMARK_SELECTION, manager);
1017: action.putValue(Action.ACCELERATOR_KEY, ks);
1018: action.putValue(Action.SHORT_DESCRIPTION, messages
1019: .getMessage("JdbcWorkbench.delete_bookmark"));
1020: action.putValue(CustomAction.ICON_NAME, "delete");
1021: am.put("delete-bookmark-selection", action);
1022: im.put(ks, "delete-bookmark-selection");
1023:
1024: ks = KeyStroke.getKeyStroke(KeyEvent.VK_N,
1025: SwingUtilities.MENU_SHORTCUT_MASK, true);
1026: im.put(ks, "add-bookmark");
1027: action = new CustomAction("add-bookmark",
1028: SharedActions.CREATE_NEW_BOOKMARK, manager);
1029: action.putValue(Action.ACCELERATOR_KEY, ks);
1030: action.putValue(Action.SHORT_DESCRIPTION, messages
1031: .getMessage("JdbcWorkbench.create_new_bookmark"));
1032: action.putValue(CustomAction.ICON_NAME, "bookmark_add");
1033: am.put("add-bookmark", action);
1034:
1035: ks = KeyStroke.getKeyStroke(KeyEvent.VK_N,
1036: SwingUtilities.MENU_SHORTCUT_MASK
1037: | KeyEvent.SHIFT_DOWN_MASK, true);
1038: action = new CustomAction("add-bookmark-folder",
1039: SharedActions.ADD_BOOKMARK_FOLDER, manager);
1040: action.putValue(Action.ACCELERATOR_KEY, ks);
1041: action
1042: .putValue(
1043: Action.SHORT_DESCRIPTION,
1044: messages
1045: .getMessage("JdbcWorkbench.create_new_bookmark_folder"));
1046: action.putValue(CustomAction.ICON_NAME, "folder_add");
1047: am.put("add-bookmark-folder", action);
1048: im.put(ks, "add-bookmark-folder");
1049:
1050: BookmarkTreeDragListener dragListener = new BookmarkTreeDragListener(
1051: bookmarkView);
1052: DragSource dndDragSource = DragSource.getDefaultDragSource();
1053: dndDragSource.createDefaultDragGestureRecognizer(bookmarkView,
1054: supportedActions, dragListener);
1055:
1056: addButton(toolbar, manager, manager.getAction("add-bookmark"));
1057: addButton(toolbar, manager, manager
1058: .getAction("delete-bookmark-selection"));
1059: addButton(toolbar, manager, manager.getAction("edit-bookmark"));
1060: addButton(toolbar, manager, manager
1061: .getAction("add-bookmark-folder"));
1062:
1063: return view;
1064: }
1065:
1066: private JComponent layoutSchemaContainer(SwingEventManager manager) {
1067:
1068: JPanel view = new JPanel(new BorderLayout());
1069: view.putClientProperty("type", WorkbenchView.SCHEMA);
1070: JToolBar toolbar = new JToolBar("schema-tools",
1071: JToolBar.HORIZONTAL);
1072: toolbar.setFloatable(false);
1073: toolbar.setBorder(BorderFactory.createEmptyBorder());
1074:
1075: JdbcSchemaTreeRefreshable refresher = new JdbcSchemaTreeRefreshable(
1076: schemaModel, schemaView);
1077: Action action = new RefreshViewAction(manager, refresher);
1078: action.putValue(Action.SHORT_DESCRIPTION, messages
1079: .format("jdbcworkbench.refresh_current_schema_view"));
1080: action.putValue(CustomAction.ICON_NAME, "reload");
1081: addButton(toolbar, manager, action);
1082:
1083: action = new CustomAction("show-meta-data",
1084: SharedActions.SHOW_CONNECTION_INFO, manager);
1085: action.putValue(Action.SHORT_DESCRIPTION, messages
1086: .format("jdbcworkbench.show_meta_data"));
1087: action.putValue(CustomAction.ICON_NAME, "information");
1088: addButton(toolbar, manager, action);
1089:
1090: SchemaTreeListener listener = new SchemaTreeListener(
1091: schemaModel, tabRenderer, manager);
1092: schemaModel.setTablesEnabled(true);
1093: schemaView.setCellRenderer(new JDBCTreeCellRenderer());
1094: schemaView.setScrollsOnExpand(true);
1095: schemaView.setRootVisible(false);
1096: schemaView.addMouseListener(listener);
1097: schemaView.getSelectionModel().setSelectionMode(
1098: TreeSelectionModel.SINGLE_TREE_SELECTION);
1099: schemaView.addTreeExpansionListener(listener);
1100:
1101: InputMap im = schemaView.getInputMap();
1102: ActionMap am = schemaView.getActionMap();
1103: KeyStroke ks = null;
1104:
1105: ks = KeyStroke.getKeyStroke(KeyEvent.VK_I,
1106: SwingUtilities.MENU_SHORTCUT_MASK, true);
1107: im.put(ks, "show-metadata-info");
1108: action = new CustomAction("show-metadata-info",
1109: SharedActions.NAVIGATE_RIGHT_TAB, manager);
1110: action.putValue(Action.ACCELERATOR_KEY, ks);
1111: action.putValue(Action.SHORT_DESCRIPTION, messages
1112: .getMessage("JdbcWorkbench.show_connection_info"));
1113: action.putValue(CustomAction.ICON_NAME, "information");
1114: am.put("show-metadata-info", action);
1115:
1116: ks = KeyStroke.getKeyStroke(KeyEvent.VK_R,
1117: SwingUtilities.MENU_SHORTCUT_MASK, true);
1118: im.put(ks, "refresh-metadata-info");
1119: am.put("refresh-metadata-info", action);
1120:
1121: view.add(toolbar, BorderLayout.NORTH);
1122: view.add(new JScrollPane(schemaView), BorderLayout.CENTER);
1123:
1124: schemaView.setDragEnabled(true);
1125: SchemaTreeDragListener dragListener = new SchemaTreeDragListener(
1126: schemaView);
1127: DragSource dndDragSource = DragSource.getDefaultDragSource();
1128: int dndActions = DnDConstants.ACTION_COPY_OR_MOVE;
1129: dndDragSource.createDefaultDragGestureRecognizer(schemaView,
1130: dndActions, dragListener);
1131: return view;
1132: }
1133:
1134: private JMenu createFileMenu(SwingEventManager manager, String name) {
1135:
1136: JMenu menu = createMenu(name);
1137: CustomAction ca = null;
1138: String acclerator = null;
1139:
1140: JMenu newMenu = createMenu(messages.format("menu.new_submenu"));
1141: newMenu.setIcon(SwingUtilities.loadIconResource("spacer", 16));
1142: menu.add(newMenu);
1143:
1144: ca = new CustomAction("new-bookmark",
1145: SharedActions.CREATE_NEW_BOOKMARK, manager);
1146: ca.putValue(CustomAction.ICON_NAME, "bookmark");
1147: ca.putValue(Action.DEFAULT, messages
1148: .getMessage("menu.new_bookmark.title"));
1149: addMenuItem(newMenu, ca);
1150:
1151: ca = new CustomAction("new-service",
1152: SharedActions.SHOW_SERVICE_WIZARD, manager);
1153: ca.putValue(CustomAction.ICON_NAME, "service");
1154: ca.putValue(Action.DEFAULT, messages
1155: .getMessage("menu.new_service.title"));
1156: addMenuItem(newMenu, ca);
1157:
1158: menu.addSeparator();
1159:
1160: ca = new CustomAction("import-wizard",
1161: SharedActions.SHOW_IMPORT_WIZARD, manager);
1162: ca.putValue(Action.DEFAULT, messages
1163: .getMessage("menu.import_wizard.title"));
1164: ca.putValue(CustomAction.ICON_NAME, "import");
1165: ca.setEnabled(false);
1166: addMenuItem(menu, ca);
1167:
1168: ca = new CustomAction("export-wizard",
1169: SharedActions.SHOW_EXPORT_WIZARD, manager);
1170: ca.putValue(CustomAction.ICON_NAME, "export");
1171: ca.putValue(Action.DEFAULT, messages
1172: .getMessage("menu.export_wizard.title"));
1173: ca.setEnabled(false);
1174: addMenuItem(menu, ca);
1175:
1176: menu.addSeparator();
1177:
1178: ca = new CustomAction("close-tab",
1179: SharedActions.CLOSE_SELECTED_RESULTS, manager);
1180: acclerator = messages
1181: .format("menu.close_selected_view.accelerator");
1182: ca.putValue(Action.ACCELERATOR_KEY, SwingUtilities
1183: .getKeyStroke(acclerator));
1184: ca.putValue(Action.DEFAULT, messages
1185: .getMessage("menu.close_selected_view.title"));
1186: addMenuItem(menu, ca);
1187:
1188: ca = new CustomAction("close-all",
1189: SharedActions.CLOSE_ALL_RESULTS, manager);
1190: acclerator = messages
1191: .format("menu.close_all_views.accelerator");
1192: ca.putValue(Action.ACCELERATOR_KEY, SwingUtilities
1193: .getKeyStroke(acclerator));
1194: ca.putValue(Action.DEFAULT, messages
1195: .getMessage("menu.close_all_views.title"));
1196: addMenuItem(menu, ca);
1197:
1198: if (!(SwingUtilities.isMacOS() && Boolean
1199: .getBoolean(IsqlToolkit.PROPERTY_MRJ_ENABLED))) {
1200: menu.addSeparator();
1201: ca = new CustomAction("close-all",
1202: SharedActions.EXIT_APPLICATION, manager);
1203: acclerator = messages
1204: .format("menu.exit_application.accelerator");
1205: ca.putValue(Action.ACCELERATOR_KEY, SwingUtilities
1206: .getKeyStroke(acclerator));
1207: ca.putValue(CustomAction.ICON_NAME, "exit");
1208: ca.putValue(Action.DEFAULT, messages
1209: .getMessage("menu.exit_application.title"));
1210: addMenuItem(menu, ca);
1211: }
1212: return menu;
1213: }
1214:
1215: private JMenu createWindowMenu(SwingEventManager manager,
1216: String name) {
1217:
1218: JMenu menu = createMenu(name);
1219: JMenu viewMenu = createMenu(messages
1220: .getMessage("menu.show_view.title"));
1221: viewMenu.setIcon(SwingUtilities.loadIconResource("spacer", 16));
1222:
1223: ToggleViewAction action = null;
1224: CustomAction ca = null;
1225: String acclerator = null;
1226:
1227: action = new ToggleViewAction(WorkbenchView.BOOKMARK, this );
1228: acclerator = messages.format("menu.view_bookmarks.accelerator");
1229: action.putValue(CustomAction.ICON_NAME, "bookmark");
1230: action.putValue(Action.ACCELERATOR_KEY, SwingUtilities
1231: .getKeyStroke(acclerator));
1232: action.putValue(Action.DEFAULT, messages
1233: .format("menu.view_bookmarks.title"));
1234: if (preferences.getBoolean(BOOKMARK_VISIBLE, false)) {
1235: action.actionPerformed(new ActionEvent(this , 0, ""));
1236: } else {
1237: bookmarkView.putClientProperty(BOOKMARK_VISIBLE,
1238: Boolean.FALSE);
1239: }
1240: addMenuItem(viewMenu, action);
1241:
1242: action = new ToggleViewAction(WorkbenchView.HISTORY, this );
1243: action.putValue(CustomAction.ICON_NAME, "history");
1244: acclerator = messages.format("menu.view_history.accelerator");
1245: action.putValue(Action.ACCELERATOR_KEY, SwingUtilities
1246: .getKeyStroke(acclerator));
1247: action.putValue(Action.DEFAULT, messages
1248: .getMessage("menu.view_history.title"));
1249: if (preferences.getBoolean(HISTORY_VISIBLE, false)) {
1250: action.actionPerformed(new ActionEvent(this , 0, ""));
1251: } else {
1252: historyView.putClientProperty(HISTORY_VISIBLE,
1253: Boolean.FALSE);
1254: }
1255: addMenuItem(viewMenu, action);
1256:
1257: action = new ToggleViewAction(WorkbenchView.SCHEMA, this );
1258: action.putValue(CustomAction.ICON_NAME, "database");
1259: acclerator = messages.format("menu.view_schema.accelerator");
1260: action.putValue(Action.ACCELERATOR_KEY, SwingUtilities
1261: .getKeyStroke(acclerator));
1262: action.putValue(Action.DEFAULT, messages
1263: .getMessage("menu.view_schema.title"));
1264: if (preferences.getBoolean(SCHEMA_VISIBLE, false)) {
1265: action.actionPerformed(new ActionEvent(this , 0, ""));
1266: } else {
1267: schemaView.putClientProperty(SCHEMA_VISIBLE, Boolean.TRUE);
1268: }
1269: addMenuItem(viewMenu, action);
1270:
1271: menu.add(viewMenu);
1272: menu.addSeparator();
1273:
1274: ca = new CustomAction("refresh-current-view",
1275: SharedActions.REFRESH_SELECTED_RESULTS, manager);
1276: acclerator = messages
1277: .format("menu.refresh_selected_view.accelerator");
1278: ca.setEnabled(false);
1279: ca.putValue(CustomAction.ICON_NAME, "reload");
1280: ca.putValue(Action.ACCELERATOR_KEY, SwingUtilities
1281: .getKeyStroke(acclerator));
1282: ca.putValue(Action.DEFAULT, messages
1283: .getMessage("menu.refresh_selected_view.title"));
1284: addMenuItem(menu, ca);
1285:
1286: ca = new CustomAction("next-tab",
1287: SharedActions.NAVIGATE_RIGHT_TAB, manager);
1288: acclerator = messages
1289: .format("menu.navigate_right_tab.accelerator");
1290: ca.putValue(Action.ACCELERATOR_KEY, SwingUtilities
1291: .getKeyStroke(acclerator));
1292: ca.putValue(Action.DEFAULT, messages
1293: .getMessage("menu.navigate_right_tab.title"));
1294: addMenuItem(menu, ca);
1295:
1296: ca = new CustomAction("prev-tab",
1297: SharedActions.NAVIGATE_LEFT_TAB, manager);
1298: acclerator = messages
1299: .format("menu.navigate_left_tab.accelerator");
1300: ca.putValue(Action.ACCELERATOR_KEY, SwingUtilities
1301: .getKeyStroke(acclerator));
1302: ca.putValue(Action.DEFAULT, messages
1303: .getMessage("menu.navigate_left_tab.title"));
1304: addMenuItem(menu, ca);
1305:
1306: return menu;
1307: }
1308:
1309: private JMenu createToolMenu(SwingEventManager manager, String name) {
1310:
1311: JMenu menu = createMenu(name);
1312: CustomAction ca = null;
1313:
1314: ca = new CustomAction("show-service-wizard",
1315: SharedActions.SHOW_SERVICE_WIZARD, manager);
1316: ca.putValue(Action.DEFAULT, messages
1317: .getMessage("menu.show_service_wizard.title"));
1318: ca.putValue(CustomAction.ICON_NAME, "service_manager");
1319: addMenuItem(menu, ca);
1320:
1321: return menu;
1322: }
1323:
1324: private JMenu createServiceMenu(String name) {
1325:
1326: serviceMenu = createMenu(name);
1327: return serviceMenu;
1328: }
1329:
1330: private JMenu createSchemaMenu(String name) {
1331:
1332: schemaMenu = createMenu(name);
1333: return schemaMenu;
1334: }
1335:
1336: private String buildSchemaMenu(Connection connection,
1337: ConnectionProfile profile) throws SQLException {
1338:
1339: schemaMenu.removeAll();
1340: Enumeration<AbstractButton> elements = schemaSelection
1341: .getElements();
1342: while (elements.hasMoreElements()) {
1343: catalogSelection.remove(elements.nextElement());
1344: }
1345:
1346: ResultSet set = connection.getMetaData().getSchemas();
1347: String preferredSchema = profile.getPreferredSchema();
1348: if (preferredSchema == null
1349: || preferredSchema.trim().length() == 0) {
1350: preferredSchema = connection.getMetaData().getUserName();
1351: }
1352:
1353: boolean schemaFound = false;
1354: String firstAvailableSchema = null;
1355: try {
1356: while (set.next()) {
1357: String schema = set.getString("TABLE_SCHEM");
1358: if (!schemaFound
1359: && preferredSchema.equalsIgnoreCase(schema)) {
1360: schemaFound = true;
1361: }
1362: if (firstAvailableSchema == null) {
1363: firstAvailableSchema = schema;
1364: }
1365: CustomAction action = new CustomAction(schema,
1366: SharedActions.SCHEMA_CHANGED, eventManager);
1367: action.putValue(Action.DEFAULT, schema);
1368: action.putValue(CustomAction.ICON_NAME, "user");
1369:
1370: JCheckBoxMenuItem button = new JCheckBoxMenuItem(action);
1371: button.setName(schema);
1372: configureMenuItem(button, action);
1373: schemaSelection.add(button);
1374: if (schema.equals(preferredSchema)) {
1375: schemaSelection
1376: .setSelected(button.getModel(), true);
1377: }
1378: schemaMenu.add(button);
1379: }
1380: } finally {
1381: try {
1382: set.close();
1383: } catch (Throwable ignored) {
1384: }
1385: }
1386:
1387: if (!schemaFound) {
1388: warn(messages.format("jdbcworkbench.schemanotfoundwarning",
1389: preferredSchema));
1390: preferredSchema = firstAvailableSchema;
1391: Enumeration<AbstractButton> selections = schemaSelection
1392: .getElements();
1393: while (selections.hasMoreElements()) {
1394: AbstractButton button = selections.nextElement();
1395: String otherSchema = button.getName();
1396: if (otherSchema.equalsIgnoreCase(preferredSchema)) {
1397: schemaSelection
1398: .setSelected(button.getModel(), true);
1399: break;
1400: }
1401: }
1402: }
1403:
1404: if (schemaSelection.getButtonCount() == 0) {
1405: JMenuItem disabledOption = new JMenuItem();
1406: disabledOption.setEnabled(false);
1407: disabledOption.setText(messages
1408: .format("JdbcWorkbench.no_schemas"));
1409: disabledOption.setIcon(SwingUtilities.loadIconResource(
1410: "user", 16));
1411: schemaMenu.add(disabledOption);
1412: }
1413: return preferredSchema;
1414: }
1415:
1416: private JMenu createCatalogMenu(String name) {
1417:
1418: catalogMenu = createMenu(name);
1419: return catalogMenu;
1420: }
1421:
1422: private Component toggleView(WorkbenchView view, Component component) {
1423:
1424: String txt = null;
1425: String tip = null;
1426: Icon ico = null;
1427: boolean inTab = javax.swing.SwingUtilities.getAncestorOfClass(
1428: EnhancedTabbedPane.class, component) != null;
1429: Component componentView = null;
1430: boolean setDivider = false;
1431: switch (view) {
1432: case HISTORY:
1433: historyView
1434: .putClientProperty(HISTORY_VISIBLE, Boolean.TRUE);
1435: if (rhsSplitPane.getRightComponent() == null) {
1436: rhsSplitPane.setRightComponent(rhsTabbedPane);
1437: Integer dividerLocation = (Integer) rhsSplitPane
1438: .getClientProperty(DIVIDER_LOCATION);
1439: if (dividerLocation != null) {
1440: rhsSplitPane.setDividerLocation(dividerLocation
1441: .intValue());
1442: } else {
1443: setDivider = true;
1444: }
1445: }
1446: try {
1447: if (inTab) {
1448: rhsTabbedPane.setSelectedComponent(component);
1449: } else {
1450: ico = SwingUtilities
1451: .loadIconResource("history", 16);
1452: tip = messages
1453: .format("jdbcworkbench.history_tab.tip");
1454: componentView = layoutHistoryContainer(eventManager);
1455: rhsTabbedPane.addTab(txt, ico, componentView, tip);
1456: int index = rhsTabbedPane
1457: .indexOfComponent(componentView);
1458: rhsTabbedPane.setClosableTab(index, true);
1459: rhsTabbedPane.setSelectedIndex(index);
1460: return componentView;
1461: }
1462: } finally {
1463: if (setDivider) {
1464: int rootWidth = rhsSplitPane.getWidth();
1465: int tabWidth = rhsTabbedPane.getPreferredSize().width;
1466: rhsSplitPane.setDividerLocation(rootWidth
1467: - tabWidth);
1468: }
1469: }
1470: break;
1471: case BOOKMARK:
1472: bookmarkView.putClientProperty(BOOKMARK_VISIBLE,
1473: Boolean.TRUE);
1474: if (rhsSplitPane.getRightComponent() == null) {
1475: rhsSplitPane.setRightComponent(rhsTabbedPane);
1476: Integer dividerLocation = (Integer) rhsSplitPane
1477: .getClientProperty(DIVIDER_LOCATION);
1478: if (dividerLocation != null) {
1479: rhsSplitPane.setDividerLocation(dividerLocation
1480: .intValue());
1481: } else {
1482: setDivider = true;
1483: }
1484: }
1485: try {
1486: if (inTab) {
1487: rhsTabbedPane.setSelectedComponent(component);
1488: } else {
1489: ico = SwingUtilities.loadIconResource("bookmark",
1490: 16);
1491: tip = messages
1492: .format("jdbcworkbench.bookmark_tab.tip");
1493: componentView = layoutBookmarkContainer(eventManager);
1494: rhsTabbedPane.addTab(txt, ico, componentView, tip);
1495: int index = rhsTabbedPane
1496: .indexOfComponent(componentView);
1497: rhsTabbedPane.setClosableTab(index, true);
1498: rhsTabbedPane.setSelectedIndex(index);
1499: return componentView;
1500: }
1501: } finally {
1502: if (setDivider) {
1503: int rootWidth = rhsSplitPane.getWidth();
1504: int tabWidth = rhsTabbedPane.getPreferredSize().width;
1505: rhsSplitPane.setDividerLocation(rootWidth
1506: - tabWidth);
1507: }
1508: }
1509: break;
1510: case SCHEMA:
1511: schemaView.putClientProperty(SCHEMA_VISIBLE, Boolean.TRUE);
1512: if (lhsSplitPane.getLeftComponent() == null) {
1513: lhsSplitPane.setLeftComponent(lhsTabbedPane);
1514: setDivider = true;
1515: }
1516: try {
1517: if (inTab) {
1518: lhsTabbedPane.setSelectedComponent(component);
1519: } else {
1520: ico = SwingUtilities.loadIconResource("database",
1521: 16);
1522: tip = messages
1523: .format("jdbcworkbench.schema_tab.tip");
1524: componentView = layoutSchemaContainer(eventManager);
1525: lhsTabbedPane.addTab(txt, ico, componentView, tip);
1526: int index = lhsTabbedPane
1527: .indexOfComponent(componentView);
1528: lhsTabbedPane.setClosableTab(index, true);
1529: lhsTabbedPane.setSelectedIndex(index);
1530: return componentView;
1531: }
1532: } finally {
1533: if (setDivider) {
1534: int tabWidth = lhsTabbedPane.getPreferredSize().width;
1535: lhsSplitPane.setDividerLocation(tabWidth);
1536: }
1537: }
1538: break;
1539: }
1540: return component;
1541: }
1542:
1543: private void handleBookmarkAction(int action, Object selected) {
1544:
1545: BookmarkTreeModel model = (BookmarkTreeModel) bookmarkView
1546: .getModel();
1547: BookmarkFolder rootFolder = (BookmarkFolder) model.getRoot();
1548: BookmarkFolder parentFolder = null;
1549: OperationStatus status = OperationStatus.UNKNOWN;
1550: EmbeddedDatabase database = EmbeddedDatabase
1551: .getSharedInstance();
1552:
1553: switch (action) {
1554: case SharedActions.DELETE_BOOKMARK_SELECTION:
1555: Window owner = javax.swing.SwingUtilities
1556: .getWindowAncestor(bookmarkView);
1557: if (selected instanceof BookmarkReference) {
1558: BookmarkReference bookmark = (BookmarkReference) selected;
1559: parentFolder = rootFolder.findChildPath(bookmark
1560: .getPath());
1561: parentFolder = (parentFolder == null) ? rootFolder
1562: : parentFolder;
1563: String msg = messages.format(
1564: "jdbcworkbench.deletebookmark_confirm",
1565: bookmark.getName());
1566: int result = JOptionPane.NO_OPTION;
1567: int opt = JOptionPane.YES_NO_OPTION;
1568: int type = JOptionPane.QUESTION_MESSAGE;
1569: result = JOptionPane.showConfirmDialog(owner, msg, "",
1570: opt, type);
1571: if (result == JOptionPane.YES_OPTION) {
1572: try {
1573: database.removeBookmark(bookmark);
1574: model.removeBookmark(bookmark);
1575: } catch (SQLException e) {
1576: error("", e);
1577: }
1578: }
1579: } else if (selected instanceof BookmarkFolder) {
1580: BookmarkFolder folder = (BookmarkFolder) selected;
1581: String msg = messages.format(
1582: "jdbcworkbench.deletebookmarkfolder_confirm",
1583: folder.getName());
1584: int result = JOptionPane.NO_OPTION;
1585: int opt = JOptionPane.YES_NO_OPTION;
1586: int type = JOptionPane.QUESTION_MESSAGE;
1587: result = JOptionPane.showConfirmDialog(owner, msg, "",
1588: opt, type);
1589: if (result == JOptionPane.YES_OPTION) {
1590: try {
1591: database.removeBookmarkFolder(folder);
1592: model.removeBookmarkFolder(folder);
1593: } catch (SQLException e) {
1594: error("", e);
1595: }
1596: }
1597: }
1598: break;
1599: case SharedActions.CREATE_NEW_BOOKMARK:
1600: if (selected instanceof BookmarkReference) {
1601: BookmarkReference bookmark = (BookmarkReference) selected;
1602: parentFolder = rootFolder.findChildPath(bookmark
1603: .getPath());
1604: parentFolder = (parentFolder == null) ? rootFolder
1605: : parentFolder;
1606: } else {
1607: parentFolder = selected == null ? rootFolder
1608: : (BookmarkFolder) selected;
1609: }
1610:
1611: Bookmark bookmark = new Bookmark();
1612: bookmark.setCreationTime(new Date());
1613: bookmark.setLastAccess(new Date());
1614: bookmark.setFolder(parentFolder);
1615:
1616: status = showModalEditor(BookmarkEditor.class, bookmark);
1617: if (status == OperationStatus.MODIFIED) {
1618: try {
1619: BookmarkReference reference = database
1620: .addBookmark(bookmark);
1621: model.addBookmark(reference, parentFolder);
1622: } catch (SQLException e) {
1623: error("", e);
1624: }
1625: }
1626: break;
1627: case SharedActions.EDIT_BOOKMARK:
1628: if (selected instanceof BookmarkReference) {
1629: BookmarkReference reference = (BookmarkReference) selected;
1630: try {
1631: bookmark = database.getBookmark(reference);
1632: status = showModalEditor(BookmarkEditor.class,
1633: bookmark);
1634: if (status == OperationStatus.MODIFIED) {
1635: database.updateBookmark(bookmark);
1636: parentFolder = rootFolder
1637: .findChildPath(bookmark.getPath());
1638: parentFolder = (parentFolder == null) ? rootFolder
1639: : parentFolder;
1640:
1641: reference.setFavorite(bookmark.isFavorite());
1642: reference.setName(bookmark.getName());
1643: reference.setColorLabel(bookmark
1644: .getColorLabel());
1645: model.reload(parentFolder, reference);
1646: }
1647: } catch (SQLException e) {
1648: error("", e);
1649: }
1650: }
1651: break;
1652: case SharedActions.ADD_BOOKMARK_FOLDER:
1653: String promptText = messages
1654: .getMessage("jdbcworkbench.newbookmarkfolder-prompt");
1655: String defaultValue = messages
1656: .getMessage("jdbcworkbench.newbookmarkfolder-default");
1657: String folderName = JOptionPane.showInputDialog(
1658: bookmarkView, promptText, defaultValue);
1659: if (folderName == null || folderName.trim().length() == 0) {
1660: return;
1661: }
1662: if (selected instanceof BookmarkFolder) {
1663: parentFolder = (BookmarkFolder) selected;
1664: } else {
1665: parentFolder = rootFolder;
1666: }
1667: model.addBookmarkFolder(parentFolder, folderName);
1668: break;
1669: default:
1670: break;
1671: }
1672: }
1673:
1674: private void restoreZoom(Component componentSource) {
1675:
1676: JSplitPane splitPane = null;
1677: Integer dividerLocation = null;
1678: if (componentSource == rhsTabbedPane) {
1679: dividerLocation = (Integer) rhsSplitPane
1680: .getClientProperty(DIVIDER_LOCATION);
1681: rhsSplitPane.setRightComponent(rhsTabbedPane);
1682: if (dividerLocation == null) {
1683: int rootWidth = rhsSplitPane.getWidth();
1684: int tabWidth = rhsTabbedPane.getPreferredSize().width;
1685: dividerLocation = new Integer(rootWidth - tabWidth);
1686: }
1687: splitPane = rhsSplitPane;
1688: } else if (componentSource == centerTabbedPane) {
1689: dividerLocation = (Integer) centerSplitPane
1690: .getClientProperty(DIVIDER_LOCATION);
1691: centerSplitPane.setBottomComponent(centerTabbedPane);
1692: splitPane = centerSplitPane;
1693: } else if (componentSource == lhsTabbedPane) {
1694: dividerLocation = (Integer) lhsSplitPane
1695: .getClientProperty(DIVIDER_LOCATION);
1696: lhsSplitPane.setLeftComponent(lhsTabbedPane);
1697: if (dividerLocation == null) {
1698: dividerLocation = new Integer(lhsTabbedPane
1699: .getPreferredSize().width);
1700: }
1701: splitPane = rhsSplitPane;
1702: }
1703: if (splitPane != null) {
1704: if (dividerLocation != null) {
1705: splitPane
1706: .setDividerLocation(dividerLocation.intValue());
1707: }
1708: splitPane.invalidate();
1709: }
1710: }
1711:
1712: private String buildCatalogMenu(Connection connection,
1713: ConnectionProfile profile) throws SQLException {
1714:
1715: catalogMenu.removeAll();
1716: Enumeration<AbstractButton> elements = catalogSelection
1717: .getElements();
1718: while (elements.hasMoreElements()) {
1719: catalogSelection.remove(elements.nextElement());
1720: }
1721:
1722: ResultSet set = connection.getMetaData().getCatalogs();
1723: String preferredCatalog = profile.getPreferredCatalog();
1724: if (preferredCatalog == null
1725: || preferredCatalog.trim().length() == 0) {
1726: preferredCatalog = connection.getCatalog();
1727: }
1728:
1729: boolean catalogFound = false;
1730: String firstAvailableCatalog = null;
1731: try {
1732: while (set.next()) {
1733: String catalog = set.getString("TABLE_CAT");
1734: if (!catalogFound
1735: && preferredCatalog.equalsIgnoreCase(catalog)) {
1736: catalogFound = true;
1737: }
1738: if (firstAvailableCatalog == null) {
1739: firstAvailableCatalog = catalog;
1740: }
1741:
1742: CustomAction action = new CustomAction(catalog,
1743: SharedActions.CATALOG_CHANGED, eventManager);
1744: action.putValue(Action.DEFAULT, catalog);
1745: action.putValue(CustomAction.ICON_NAME, "catalog");
1746:
1747: JCheckBoxMenuItem button = new JCheckBoxMenuItem(action);
1748: configureMenuItem(button, action);
1749:
1750: catalogSelection.add(button);
1751: if (catalog.equals(preferredCatalog)) {
1752: catalogSelection.setSelected(button.getModel(),
1753: true);
1754: }
1755: catalogMenu.add(button);
1756: }
1757: } finally {
1758: try {
1759: set.close();
1760: } catch (Throwable ignored) {
1761: }
1762: }
1763:
1764: if (!catalogFound) {
1765: warn(messages.format(
1766: "jdbcworkbench.catalognotfoundwarning",
1767: preferredCatalog));
1768: preferredCatalog = firstAvailableCatalog;
1769: Enumeration<AbstractButton> selections = catalogSelection
1770: .getElements();
1771: while (selections.hasMoreElements()) {
1772: AbstractButton button = selections.nextElement();
1773: String otherCatalog = button.getName();
1774: if (otherCatalog.equalsIgnoreCase(preferredCatalog)) {
1775: catalogSelection.setSelected(button.getModel(),
1776: true);
1777: break;
1778: }
1779: }
1780: }
1781: if (catalogSelection.getButtonCount() == 0) {
1782: JMenuItem disabledOption = new JMenuItem();
1783: disabledOption.setEnabled(false);
1784: disabledOption.setText(messages
1785: .format("JdbcWorkbench.no_catalogs"));
1786: disabledOption.setIcon(SwingUtilities.loadIconResource(
1787: "catalog", 16));
1788: catalogMenu.add(disabledOption);
1789: }
1790: return preferredCatalog;
1791: }
1792:
1793: private void closeSelectedResult() {
1794:
1795: EnhancedTabbedPane tabbedPane = tabRenderer.getTabbedPane();
1796: int index = centerTabbedPane.getSelectedIndex();
1797: if (index >= 0) {
1798: tabbedPane.remove(index);
1799: }
1800: }
1801:
1802: private void navigateRightTab() {
1803:
1804: int index = centerTabbedPane.getSelectedIndex();
1805: if (index >= 0) {
1806: if ((index + 1) < centerTabbedPane.getTabCount()) {
1807: centerTabbedPane.setSelectedIndex(index + 1);
1808: } else {
1809: centerTabbedPane.setSelectedIndex(0);
1810: }
1811: }
1812: }
1813:
1814: private void navigateLeftTab() {
1815:
1816: int index = centerTabbedPane.getSelectedIndex();
1817: if (index >= 0) {
1818: if ((index - 1) >= 0) {
1819: centerTabbedPane.setSelectedIndex(index - 1);
1820: } else {
1821: index = centerTabbedPane.getTabCount();
1822: centerTabbedPane.setSelectedIndex(index - 1);
1823: }
1824: }
1825: }
1826:
1827: private void clearAllHistory() {
1828:
1829: EmbeddedDatabase edb = EmbeddedDatabase.getSharedInstance();
1830: try {
1831: int removedCount = edb.removeAllHistory();
1832: debug(messages.format(
1833: "JdbcWorkbench.removed_history_items", Integer
1834: .toString(removedCount)));
1835: } catch (SQLException error) {
1836: error(
1837: messages
1838: .format("JdbcWorkbench.clear_history_failed"),
1839: error);
1840: }
1841: reloadQueryHistory();
1842: }
1843:
1844: private void queryDatabaseMetadata() {
1845:
1846: int index;
1847: DataGrid dataGrid = new DataGrid();
1848: DatabaseMetaData metaData;
1849: try {
1850: metaData = currentService.getConnection().getMetaData();
1851: } catch (SQLException error) {
1852: error("", error);
1853: return;
1854: }
1855: JPanel view = new JPanel();
1856: dataGrid.doLayout(view, null, null);
1857: Map<String, Object> metaDataMap = JdbcUtilities
1858: .extractMetadata(metaData);
1859: EnhancedTableModel model = new EnhancedTableModel(new String[] {
1860: "Property", "Value" });
1861: Set<Map.Entry<String, Object>> entries = metaDataMap.entrySet();
1862: for (Map.Entry<String, Object> entry : entries) {
1863: ArrayList<Object> row = new ArrayList<Object>();
1864: row.add(entry.getKey());
1865: row.add(entry.getValue());
1866: model.addRow(row);
1867: }
1868: dataGrid.setModel(model);
1869: EnhancedTabbedPane tabbedPane = tabRenderer.getTabbedPane();
1870: tabbedPane.addTab(messages
1871: .format("JdbcWorkbench.database_metadata"), view);
1872: index = tabbedPane.indexOfComponent(view);
1873: tabbedPane.setClosableTab(index, true);
1874: tabbedPane.setIconAt(index, SwingUtilities.loadIconResource(
1875: "information", 16));
1876: }
1877:
1878: private boolean checkConnection() {
1879:
1880: try {
1881: if (currentService == null
1882: || currentService.getConnection().isClosed()) {
1883: return promptForService();
1884: }
1885: return true;
1886: } catch (SQLException ignored) {
1887: debug("", ignored);
1888: }
1889: return false;
1890: }
1891:
1892: private void updateSyntaxHighlighting() {
1893:
1894: try {
1895: String catalog = schemaModel.getCurrentCatlog();
1896: String schema = schemaModel.getCurrentSchema();
1897: commandEditor.updateServiceKeywords(currentService,
1898: catalog, schema);
1899: } catch (SQLException ignored) {
1900: debug("", ignored);
1901: }
1902: }
1903:
1904: private void configureSplitPanel(JSplitPane splitPanel,
1905: String preference) {
1906:
1907: int location = preferences.getInt(preference, 0);
1908: if (location == 0) {
1909: splitPanel.setDividerLocation(0.50d);
1910: } else {
1911: splitPanel.setDividerLocation(location);
1912: splitPanel.putClientProperty(DIVIDER_LOCATION, new Integer(
1913: splitPanel.getDividerLocation()));
1914: }
1915: }
1916:
1917: private static class ToggleViewAction extends AbstractAction {
1918:
1919: private static final long serialVersionUID = -1587118235512663612L;
1920: private WorkbenchView view = null;
1921: private JdbcWorkbench workbench = null;
1922: private Component viewComponent = null;
1923:
1924: public ToggleViewAction(WorkbenchView view,
1925: JdbcWorkbench workbench) {
1926:
1927: super ();
1928: this .view = view;
1929: this .workbench = workbench;
1930: }
1931:
1932: public void actionPerformed(ActionEvent e) {
1933:
1934: viewComponent = workbench.toggleView(view, viewComponent);
1935: }
1936: }
1937: }
|