Search in sources :

Example 26 with Alias

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

the class OpenInEditorAction method run.

public void run() {
    try {
        TableItem[] ti = _table.getSelection();
        if (ti == null || ti.length == 0) {
            return;
        }
        String queryDelimiter = SQLExplorerPlugin.getDefault().getPluginPreferences().getString(IConstants.SQL_QRY_DELIMITER);
        StringBuffer copiedText = new StringBuffer();
        for (int i = 0; i < ti.length; i++) {
            SQLHistoryElement el = (SQLHistoryElement) ti[i].getData();
            copiedText.append(el.getRawSQLString());
            if (ti.length > 0) {
                copiedText.append(queryDelimiter);
                copiedText.append("\n");
            }
        }
        SQLHistoryElement sqlHistoryElement = (SQLHistoryElement) ti[0].getData();
        User user = sqlHistoryElement.getUser();
        Alias alias;
        if (user != null)
            alias = user.getAlias();
        else {
            alias = sqlHistoryElement.getAlias();
            if (alias != null)
                user = alias.getDefaultUser();
            if (user == null) {
                ConnectionsView view = SQLExplorerPlugin.getDefault().getConnectionsView();
                if (view != null)
                    user = view.getDefaultUser();
            }
        }
        if (user != null && !user.hasAuthenticated()) {
            boolean okToOpen = MessageDialog.openConfirm(_table.getShell(), Messages.getString("SQLHistoryView.OpenInEditor.Confirm.Title"), Messages.getString("SQLHistoryView.OpenInEditor.Confirm.Message.Prefix") + " " + user.getDescription() + Messages.getString("SQLHistoryView.OpenInEditor.Confirm.Message.Postfix"));
            if (okToOpen) {
                OpenPasswordConnectDialogAction openDlgAction = new OpenPasswordConnectDialogAction(alias, user, false);
                openDlgAction.run();
            }
        }
        SQLEditorInput input = new SQLEditorInput("SQL Editor (" + SQLExplorerPlugin.getDefault().getEditorSerialNo() + ").sql");
        input.setUser(user);
        IWorkbenchPage page = SQLExplorerPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
        if (page == null)
            return;
        SQLEditor editorPart = (SQLEditor) page.openEditor(input, SQLEditor.class.getName());
        editorPart.setText(copiedText.toString());
    } catch (Throwable e) {
        SQLExplorerPlugin.error("Error creating sql editor", e);
    }
}
Also used : SQLEditor(net.sourceforge.sqlexplorer.plugin.editors.SQLEditor) User(net.sourceforge.sqlexplorer.dbproduct.User) ConnectionsView(net.sourceforge.sqlexplorer.connections.ConnectionsView) TableItem(org.eclipse.swt.widgets.TableItem) OpenPasswordConnectDialogAction(net.sourceforge.sqlexplorer.plugin.actions.OpenPasswordConnectDialogAction) SQLEditorInput(net.sourceforge.sqlexplorer.plugin.editors.SQLEditorInput) SQLHistoryElement(net.sourceforge.sqlexplorer.history.SQLHistoryElement) Alias(net.sourceforge.sqlexplorer.dbproduct.Alias) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

Example 27 with Alias

use of net.sourceforge.sqlexplorer.dbproduct.Alias 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

Alias (net.sourceforge.sqlexplorer.dbproduct.Alias)27 User (net.sourceforge.sqlexplorer.dbproduct.User)14 SQLConnection (net.sourceforge.sqlexplorer.dbproduct.SQLConnection)6 AliasManager (net.sourceforge.sqlexplorer.dbproduct.AliasManager)5 DatabaseStructureView (net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 SQLExplorerPlugin (net.sourceforge.sqlexplorer.plugin.SQLExplorerPlugin)4 PartInitException (org.eclipse.ui.PartInitException)4 Iterator (java.util.Iterator)3 LinkedHashSet (java.util.LinkedHashSet)3 CreateAliasDlg (net.sourceforge.sqlexplorer.dialogs.CreateAliasDlg)3 MalformedURLException (java.net.MalformedURLException)2 SQLCannotConnectException (net.sourceforge.sqlexplorer.SQLCannotConnectException)2 Session (net.sourceforge.sqlexplorer.dbproduct.Session)2 OpenPasswordConnectDialogAction (net.sourceforge.sqlexplorer.plugin.actions.OpenPasswordConnectDialogAction)2 SQLEditor (net.sourceforge.sqlexplorer.plugin.editors.SQLEditor)2 SQLEditorInput (net.sourceforge.sqlexplorer.plugin.editors.SQLEditorInput)2 Menu (org.eclipse.swt.widgets.Menu)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1