Search in sources :

Example 6 with SQLEditorInput

use of net.sourceforge.sqlexplorer.plugin.editors.SQLEditorInput 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)

Aggregations

SQLEditor (net.sourceforge.sqlexplorer.plugin.editors.SQLEditor)6 SQLEditorInput (net.sourceforge.sqlexplorer.plugin.editors.SQLEditorInput)6 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)5 PartInitException (org.eclipse.ui.PartInitException)3 SQLCannotConnectException (net.sourceforge.sqlexplorer.SQLCannotConnectException)2 Alias (net.sourceforge.sqlexplorer.dbproduct.Alias)2 User (net.sourceforge.sqlexplorer.dbproduct.User)2 TableNode (net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode)2 DatabaseStructureView (net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView)2 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 ConnectionsView (net.sourceforge.sqlexplorer.connections.ConnectionsView)1 ColumnNode (net.sourceforge.sqlexplorer.dbstructure.nodes.ColumnNode)1 SQLHistoryElement (net.sourceforge.sqlexplorer.history.SQLHistoryElement)1 OpenPasswordConnectDialogAction (net.sourceforge.sqlexplorer.plugin.actions.OpenPasswordConnectDialogAction)1 ExecSQLAction (net.sourceforge.sqlexplorer.sqleditor.actions.ExecSQLAction)1 ITableInfo (net.sourceforge.squirrel_sql.fw.sql.ITableInfo)1 PrimaryKeyInfo (net.sourceforge.squirrel_sql.fw.sql.PrimaryKeyInfo)1 SQLDatabaseMetaData (net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData)1 TableColumnInfo (net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo)1