Search in sources :

Example 26 with User

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

the class SQLEditor method init.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.IEditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
     */
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    // Configure the editor
    setSite(site);
    // PTODO qzhang fixed bug 3904: syschronize the resource.
    if (input instanceof FileEditorInput) {
        try {
            ((FileEditorInput) input).getFile().getParent().refreshLocal(IResource.DEPTH_ONE, null);
        } catch (CoreException e) {
            e.printStackTrace();
        }
    }
    setInput(input);
    // Create the text editor
    textEditor = new SQLTextEditor(this);
    textEditor.init(site, input);
    // setPartName(getSite().getPage().getLabel());
    // Make sure we get notification that our editor is closing because
    // we may need to stop running queries
    getSite().getPage().addPartListener(new PartAdapter2() {

        /*
             * (non-JavaDoc)
             * 
             * @see net.sourceforge.sqlexplorer.util.PartAdapter2#partClosed(org.eclipse.ui.IWorkbenchPartReference)
             */
        @Override
        public void partClosed(IWorkbenchPartReference partRef) {
            if (partRef.getPart(false) == SQLEditor.this) {
                onCloseEditor();
            }
        }
    });
    // If we havn't got a view, then try for the current session in the ConnectionsView
    if (getSession() == null) {
        ConnectionsView view = SQLExplorerPlugin.getDefault().getConnectionsView();
        if (view != null) {
            User user = view.getDefaultUser();
            if (user != null) {
                user.queueForNewSession(new SessionEstablishedAdapter() {

                    @Override
                    public void sessionEstablished(Session session) {
                        setSession(session);
                    }
                });
            }
        }
    }
}
Also used : PartAdapter2(net.sourceforge.sqlexplorer.util.PartAdapter2) User(net.sourceforge.sqlexplorer.dbproduct.User) CoreException(org.eclipse.core.runtime.CoreException) ConnectionsView(net.sourceforge.sqlexplorer.connections.ConnectionsView) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPartReference(org.eclipse.ui.IWorkbenchPartReference) SessionEstablishedAdapter(net.sourceforge.sqlexplorer.connections.SessionEstablishedAdapter) Session(net.sourceforge.sqlexplorer.dbproduct.Session)

Example 27 with User

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

the class CreateAliasDlg method okPressed.

protected void okPressed() {
    try {
        User previousUser = alias.getDefaultUser();
        alias.setName(nameField.getText().trim());
        int selIndex = cboDriver.getSelectionIndex();
        ManagedDriver driver = comboDriverIndexes.get(selIndex);
        alias.setDriver(driver);
        alias.setUrl(urlField.getText().trim());
        if (noUsernameRequired.getSelection())
            alias.setHasNoUserName(true);
        else {
            alias.setHasNoUserName(false);
            if (userField.getText().trim().length() > 0)
                alias.setDefaultUser(new User(userField.getText().trim(), passwordField.getText().trim()));
        }
        alias.setName(this.nameField.getText().trim());
        alias.setSchemaFilterExpression("");
        alias.setNameFilterExpression("");
        alias.setFolderFilterExpression("");
        alias.setConnectAtStartup(logonAtStartupButton.getSelection());
        alias.setAutoLogon(autoLogonButton.getSelection());
        if (type != Type.CHANGE)
            SQLExplorerPlugin.getDefault().getAliasManager().addAlias(alias);
        else // objects even though we have explicitly created a new instance of User above)
        if (alias.getDefaultUser() != previousUser) {
            if (!previousUser.isInUse())
                alias.removeUser(previousUser);
        }
        User user = alias.getDefaultUser();
        if (user != null) {
            user.setAutoCommit(autoCommitButton.getSelection());
            user.setCommitOnClose(commitOnCloseButton.getSelection());
        }
    } catch (ExplorerException excp) {
        // $NON-NLS-1$
        SQLExplorerPlugin.error("Validation Exception", excp);
    // System.out.println(Messages.getString("Error_Validation_Exception_4"));//$NON-NLS-1$
    }
    // Notify that ther has been changes
    SQLExplorerPlugin.getDefault().getAliasManager().modelChanged();
    close();
}
Also used : User(net.sourceforge.sqlexplorer.dbproduct.User) ExplorerException(net.sourceforge.sqlexplorer.ExplorerException) ManagedDriver(net.sourceforge.sqlexplorer.dbproduct.ManagedDriver)

Example 28 with User

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

Aggregations

User (net.sourceforge.sqlexplorer.dbproduct.User)28 Alias (net.sourceforge.sqlexplorer.dbproduct.Alias)14 SQLConnection (net.sourceforge.sqlexplorer.dbproduct.SQLConnection)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 Iterator (java.util.Iterator)3 LinkedHashSet (java.util.LinkedHashSet)3 ConnectionsView (net.sourceforge.sqlexplorer.connections.ConnectionsView)3 SessionEstablishedAdapter (net.sourceforge.sqlexplorer.connections.SessionEstablishedAdapter)3 ManagedDriver (net.sourceforge.sqlexplorer.dbproduct.ManagedDriver)3 Session (net.sourceforge.sqlexplorer.dbproduct.Session)3 OpenPasswordConnectDialogAction (net.sourceforge.sqlexplorer.plugin.actions.OpenPasswordConnectDialogAction)3 SQLCannotConnectException (net.sourceforge.sqlexplorer.SQLCannotConnectException)2 AliasManager (net.sourceforge.sqlexplorer.dbproduct.AliasManager)2 EditUserDlg (net.sourceforge.sqlexplorer.dialogs.EditUserDlg)2 SQLEditor (net.sourceforge.sqlexplorer.plugin.editors.SQLEditor)2 SQLEditorInput (net.sourceforge.sqlexplorer.plugin.editors.SQLEditorInput)2 DatabaseStructureView (net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView)2 PartAdapter2 (net.sourceforge.sqlexplorer.util.PartAdapter2)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2