Search in sources :

Example 6 with SQLCannotConnectException

use of net.sourceforge.sqlexplorer.SQLCannotConnectException in project tdq-studio-se by Talend.

the class SQLExplorerPlugin method startDefaultConnections.

/**
 * Open all connections that have the 'open on startup property'. This method should be called from within the UI
 * thread!
 */
public void startDefaultConnections(ConnectionsView connectionsView) {
    this.connectionsView = connectionsView;
    if (_defaultConnectionsStarted) {
        return;
    }
    String fontDesc = getPluginPreferences().getString(IConstants.FONT);
    FontData fontData = null;
    try {
        try {
            fontData = new FontData(fontDesc);
        } catch (IllegalArgumentException e) {
            fontData = new FontData("1|Courier New|10|0|WINDOWS|1|-13|0|0|0|400|0|0|0|0|3|2|1|49|Courier New");
        }
        PreferenceConverter.setValue(getPreferenceStore(), IConstants.FONT, fontData);
    } catch (IllegalArgumentException e) {
        error("Error setting font", e);
    }
    boolean openEditor = SQLExplorerPlugin.getDefault().getPluginPreferences().getBoolean(IConstants.AUTO_OPEN_EDITOR);
    // Get the database structure view - NOTE: we don't use SQLExplorerPlugin.getDatabaseView()
    // because it may not have an active page yet
    DatabaseStructureView dbView = null;
    IWorkbenchSite site = connectionsView.getSite();
    if (site.getPage() != null) {
        dbView = (DatabaseStructureView) site.getPage().findView(DatabaseStructureView.class.getName());
    }
    for (Alias alias : aliasManager.getAliases()) {
        if (alias.isConnectAtStartup() && alias.isAutoLogon() && alias.getDefaultUser() != null) {
            if (dbView != null) {
                try {
                    dbView.addUser(alias.getDefaultUser());
                } catch (SQLCannotConnectException e) {
                // Ignore it; the problem is already in the log, we do not want to delay startup, and the
                // problem will
                // be apparent as soon as the user tries to use the connection
                }
            }
            if (openEditor) {
                SQLEditorInput input = new SQLEditorInput(SQL_EDITOR + SQLExplorerPlugin.getDefault().getEditorSerialNo() + SQL);
                input.setUser(alias.getDefaultUser());
                try {
                    site.getPage().openEditor(input, SQLEditor.class.getName());
                } catch (PartInitException e) {
                    SQLExplorerPlugin.error("Cannot open SQL editor", e);
                }
            }
        }
    }
    _defaultConnectionsStarted = true;
}
Also used : IWorkbenchSite(org.eclipse.ui.IWorkbenchSite) SQLEditorInput(net.sourceforge.sqlexplorer.plugin.editors.SQLEditorInput) SQLEditor(net.sourceforge.sqlexplorer.plugin.editors.SQLEditor) Alias(net.sourceforge.sqlexplorer.dbproduct.Alias) FontData(org.eclipse.swt.graphics.FontData) DatabaseStructureView(net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView) PartInitException(org.eclipse.ui.PartInitException) SQLCannotConnectException(net.sourceforge.sqlexplorer.SQLCannotConnectException)

Example 7 with SQLCannotConnectException

use of net.sourceforge.sqlexplorer.SQLCannotConnectException in project tdq-studio-se by Talend.

the class SQLExplorerPlugin method error.

/**
 * Global log method.
 *
 * @param message
 * @param t
 */
public static void error(String message, Throwable t) {
    if (t instanceof SQLCannotConnectException) {
        getDefault().getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, String.valueOf(message), null));
    } else {
        getDefault().getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, String.valueOf(message), t));
        _logger.error(message, t);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) SQLCannotConnectException(net.sourceforge.sqlexplorer.SQLCannotConnectException)

Aggregations

SQLCannotConnectException (net.sourceforge.sqlexplorer.SQLCannotConnectException)7 DatabaseStructureView (net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView)4 SQLException (java.sql.SQLException)2 SQLEditor (net.sourceforge.sqlexplorer.plugin.editors.SQLEditor)2 SQLEditorInput (net.sourceforge.sqlexplorer.plugin.editors.SQLEditorInput)2 Connection (java.sql.Connection)1 Properties (java.util.Properties)1 ExplorerException (net.sourceforge.sqlexplorer.ExplorerException)1 SessionEstablishedAdapter (net.sourceforge.sqlexplorer.connections.SessionEstablishedAdapter)1 SessionEstablishedListener (net.sourceforge.sqlexplorer.connections.SessionEstablishedListener)1 Alias (net.sourceforge.sqlexplorer.dbproduct.Alias)1 Session (net.sourceforge.sqlexplorer.dbproduct.Session)1 User (net.sourceforge.sqlexplorer.dbproduct.User)1 DBTreeActionGroup (net.sourceforge.sqlexplorer.dbstructure.DBTreeActionGroup)1 DBTreeContentProvider (net.sourceforge.sqlexplorer.dbstructure.DBTreeContentProvider)1 DBTreeLabelProvider (net.sourceforge.sqlexplorer.dbstructure.DBTreeLabelProvider)1 DatabaseNode (net.sourceforge.sqlexplorer.dbstructure.nodes.DatabaseNode)1 INode (net.sourceforge.sqlexplorer.dbstructure.nodes.INode)1 TableNode (net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode)1 ValidationException (net.sourceforge.squirrel_sql.fw.persist.ValidationException)1