Search in sources :

Example 11 with User

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

the class DeleteAction method run.

public void run() {
    boolean okToDelete = MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), Messages.getString("ConnectionsView.ConfirmDelete.WindowTitle"), Messages.getString("ConnectionsView.ConfirmDelete.Message"));
    if (!okToDelete)
        return;
    for (User user : getView().getSelectedUsers(false)) user.getAlias().removeUser(user);
    for (Alias alias : getView().getSelectedAliases(false)) alias.remove();
    getView().refresh();
}
Also used : User(net.sourceforge.sqlexplorer.dbproduct.User) Alias(net.sourceforge.sqlexplorer.dbproduct.Alias)

Example 12 with User

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

the class DeleteAction method isAvailable.

/**
 * Only show action when there is at least 1 alias selected
 *
 * @see net.sourceforge.sqlexplorer.connections.actions.AbstractConnectionTreeAction#isAvailable()
 */
public boolean isAvailable() {
    if (getView() == null)
        return false;
    Set<Alias> aliases = getView().getSelectedAliases(false);
    Set<User> users = getView().getSelectedUsers(false);
    if (aliases.isEmpty() && users.isEmpty())
        return false;
    for (User user : users) if (user.getAlias().hasNoUserName())
        return false;
    return true;
}
Also used : User(net.sourceforge.sqlexplorer.dbproduct.User) Alias(net.sourceforge.sqlexplorer.dbproduct.Alias)

Example 13 with User

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

the class SQLEditorCatalogSwitcher method createControl.

protected Control createControl(Composite parent) {
    _catalogCombo = new Combo(parent, SWT.READ_ONLY);
    _catalogCombo.setToolTipText(Messages.getString("SQLEditor.Actions.ChooseCatalog.ToolTip"));
    _catalogCombo.setSize(200, _catalogCombo.getSize().y);
    _catalogCombo.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            int selIndex = _catalogCombo.getSelectionIndex();
            String newCat = _catalogCombo.getItem(selIndex);
            if (_editor.getSession() != null) {
                try {
                    _editor.getSession().setCatalog(newCat);
                } catch (Exception e1) {
                    SQLExplorerPlugin.error("Error changing catalog", e1);
                }
            }
        }
    });
    _catalogCombo.add("");
    if (_editor.getSession() != null) {
        try {
            String[] catalogs = getMetaDataSession().getCatalogs();
            User user = _editor.getSession().getUser();
            // Get the connection directly from the user because the session may be busy with its one one
            SQLConnection connection = user.getConnection();
            try {
                String currentCatalog = connection.getCatalog();
                for (int i = 0; i < catalogs.length; i++) {
                    _catalogCombo.add(catalogs[i]);
                    if (currentCatalog.equals(catalogs[i])) {
                        _catalogCombo.select(_catalogCombo.getItemCount() - 1);
                    }
                }
            } finally {
                if (connection != null)
                    user.releaseConnection(connection);
            }
        } catch (SQLException e) {
            SQLExplorerPlugin.error(e);
        }
    }
    return _catalogCombo;
}
Also used : User(net.sourceforge.sqlexplorer.dbproduct.User) SQLException(java.sql.SQLException) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SQLConnection(net.sourceforge.sqlexplorer.dbproduct.SQLConnection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Combo(org.eclipse.swt.widgets.Combo) SQLException(java.sql.SQLException)

Example 14 with User

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

the class SQLEditorSessionSwitcher method setSessionOptions.

private void setSessionOptions() {
    if (_sessionCombo.isDisposed()) {
        return;
    }
    _sessionCombo.removeAll();
    _sessionCombo.add("");
    int index = 0;
    User currentUser = null;
    if (_editor.getSession() != null) {
        currentUser = _editor.getSession().getUser();
    }
    for (Alias alias : SQLExplorerPlugin.getDefault().getAliasManager().getAliases()) {
        for (User user : alias.getUsers()) {
            _sessionCombo.add(user.getDescription());
            sessionIndexes.put(new Integer(index++), user);
            // MOD msjian TDQ-5927 2013-5-24: set the item identify by the username, url and connection name
            if (currentUser != null) {
                boolean isMatched = currentUser.getUserName().equals(user.getUserName()) && currentUser.getAlias().getUrl().equals(alias.getUrl());
                if (currentUser.getDatabaseConnection() != null) {
                    isMatched = isMatched && currentUser.getDatabaseConnection().getName().equals(alias.getName());
                }
                if (isMatched) {
                    _sessionCombo.select(_sessionCombo.getItemCount() - 1);
                }
            }
        }
    }
}
Also used : User(net.sourceforge.sqlexplorer.dbproduct.User) Alias(net.sourceforge.sqlexplorer.dbproduct.Alias)

Example 15 with User

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

the class ConnectionTreeContentProvider method getChildren.

/**
 * Return all the children
 *
 * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
 */
public Object[] getChildren(Object parentElement) {
    if (parentElement instanceof AliasManager) {
        AliasManager aliases = (AliasManager) parentElement;
        Object[] children = aliases.getAliases().toArray();
        return children;
    } else if (parentElement instanceof Alias) {
        Alias alias = (Alias) parentElement;
        Object[] children = alias.getUsers().toArray();
        return children;
    } else if (parentElement instanceof User) {
        User user = (User) parentElement;
        return user.getConnections().toArray();
    }
    return null;
}
Also used : AliasManager(net.sourceforge.sqlexplorer.dbproduct.AliasManager) User(net.sourceforge.sqlexplorer.dbproduct.User) Alias(net.sourceforge.sqlexplorer.dbproduct.Alias)

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