Search in sources :

Example 6 with User

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

the class ConnectionsView method getSelectedConnections.

/**
 * Returns a list of selected sessions; if recurse is true, then it includes indirectly selected sessions (eg a
 * selected user's sessions)
 *
 * @param recurse
 * @return Set of Sessions, never returns null
 */
public Set<SQLConnection> getSelectedConnections(boolean recurse) {
    IStructuredSelection selection = (IStructuredSelection) _treeViewer.getSelection();
    if (selection == null) {
        return EMPTY_CONNECTIONS;
    }
    LinkedHashSet<SQLConnection> result = new LinkedHashSet<SQLConnection>();
    Iterator iter = selection.iterator();
    while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof SQLConnection) {
            result.add((SQLConnection) obj);
        } else if (recurse) {
            if (obj instanceof Alias) {
                Alias alias = (Alias) obj;
                for (User user : alias.getUsers()) {
                    result.addAll(user.getConnections());
                }
            } else if (obj instanceof User) {
                User user = (User) obj;
                result.addAll(user.getConnections());
            }
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) User(net.sourceforge.sqlexplorer.dbproduct.User) Alias(net.sourceforge.sqlexplorer.dbproduct.Alias) SQLConnection(net.sourceforge.sqlexplorer.dbproduct.SQLConnection) Iterator(java.util.Iterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 7 with User

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

the class CopyUserAction method run.

/* (non-Javadoc)
	 * @see org.eclipse.jface.action.Action#run()
	 */
@Override
public void run() {
    User user = getView().getSelectedUser(false);
    EditUserDlg dlg = new EditUserDlg(Display.getCurrent().getActiveShell(), EditUserDlg.Type.COPY, user.getAlias(), user);
    dlg.open();
    getView().refresh();
}
Also used : User(net.sourceforge.sqlexplorer.dbproduct.User) EditUserDlg(net.sourceforge.sqlexplorer.dialogs.EditUserDlg)

Example 8 with User

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

the class EditUserAction method run.

/* (non-Javadoc)
	 * @see org.eclipse.jface.action.Action#run()
	 */
@Override
public void run() {
    User user = getView().getSelectedUser(false);
    EditUserDlg dlg = new EditUserDlg(Display.getCurrent().getActiveShell(), EditUserDlg.Type.EDIT, user.getAlias(), user);
    dlg.open();
    getView().refresh();
}
Also used : User(net.sourceforge.sqlexplorer.dbproduct.User) EditUserDlg(net.sourceforge.sqlexplorer.dialogs.EditUserDlg)

Example 9 with User

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

the class NewDatabaseStructureViewAction method run.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
@Override
public void run() {
    DatabaseStructureView view = SQLExplorerPlugin.getDefault().getDatabaseStructureView();
    if (view == null) {
        return;
    }
    Collection<User> users = getView().getSelectedUsers(true);
    for (User user : users) {
        try {
            // ADD msjian TDQ-8535 2014-4-25: we need to do this to make sure the hive connection can be created
            // successfully
            setMetadataToUserAndUpdateDriver(user);
            // TDQ-8535~
            view.addUser(user);
        } catch (SQLCannotConnectException e) {
            MessageDialog.openError(Display.getDefault().getActiveShell(), "Cannot connect", e.getMessage());
        }
    }
}
Also used : User(net.sourceforge.sqlexplorer.dbproduct.User) DatabaseStructureView(net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView) SQLCannotConnectException(net.sourceforge.sqlexplorer.SQLCannotConnectException)

Example 10 with User

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

the class ConnectionTreeLabelProvider method getText.

/**
 * Return the text to display
 *
 * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
 */
public String getText(Object element) {
    if (element instanceof Alias) {
        Alias alias = (Alias) element;
        String label = alias.getName();
        int numSessions = 0;
        for (User user : alias.getUsers()) numSessions += user.getConnections().size();
        if (numSessions == 1)
            return label + " (" + numSessions + " " + Messages.getString("ConnectionsView.ConnectedAlias.single.Postfix") + // $NON-NLS-1$
            ")";
        if (numSessions > 1)
            return label + " (" + numSessions + " " + Messages.getString("ConnectionsView.ConnectedAlias.multiple.Postfix") + // $NON-NLS-1$
            ")";
        return label;
    } else if (element instanceof User) {
        User user = (User) element;
        return user.getUserName();
    } else if (element instanceof SQLConnection) {
        SQLConnection connection = (SQLConnection) element;
        String label;
        if (connection.getDescription() == null) {
            // $NON-NLS-1$
            SimpleDateFormat fmt = new SimpleDateFormat("HH:mm:ss");
            // $NON-NLS-2$
            label = Messages.getString("ConnectionsView.ConnectedAlias.ConnectedSince") + ' ' + fmt.format(new Date(connection.getCreatedTime()));
        } else
            // $NON-NLS-2$
            label = Messages.getString("ConnectionsView.ConnectedAlias.Connection") + ' ' + connection.getDescription();
        if (connection.isPooled())
            // $NON-NLS-1$
            label += ' ' + Messages.getString("ConnectionsView.ConnectedAlias.Pooled");
        return label;
    }
    return null;
}
Also used : User(net.sourceforge.sqlexplorer.dbproduct.User) Alias(net.sourceforge.sqlexplorer.dbproduct.Alias) SQLConnection(net.sourceforge.sqlexplorer.dbproduct.SQLConnection) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

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