Search in sources :

Example 1 with User

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

the class CreateAliasDlg method createDialogArea.

protected Control createDialogArea(Composite parent) {
    // top level composite
    Composite parentComposite = (Composite) super.createDialogArea(parent);
    // create a composite with standard margins and spacing
    Composite composite = new Composite(parentComposite, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
    layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
    layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    composite.setLayout(layout);
    final GridData gd_composite = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd_composite.heightHint = 238;
    composite.setLayoutData(gd_composite);
    composite.setFont(parentComposite.getFont());
    Composite nameGroup = new Composite(composite, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 3;
    layout.marginWidth = 10;
    nameGroup.setLayout(layout);
    GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
    data.heightHint = 211;
    nameGroup.setLayoutData(data);
    Label label = new Label(nameGroup, SWT.WRAP);
    // $NON-NLS-1$
    label.setText("Name");
    nameField = new Text(nameGroup, SWT.BORDER);
    if (type != Type.CREATE)
        nameField.setText(alias.getName());
    data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
    data.horizontalSpan = 2;
    data.widthHint = SIZING_TEXT_FIELD_WIDTH;
    nameField.setLayoutData(data);
    nameField.addKeyListener(new KeyListener() {

        public void keyPressed(org.eclipse.swt.events.KeyEvent e) {
            CreateAliasDlg.this.validate();
        }

        public void keyReleased(org.eclipse.swt.events.KeyEvent e) {
            CreateAliasDlg.this.validate();
        }
    });
    Label label2 = new Label(nameGroup, SWT.WRAP);
    // $NON-NLS-1$
    label2.setText("Driver");
    cboDriver = new Combo(nameGroup, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
    final GridData gd_driver = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
    gd_driver.widthHint = SIZING_TEXT_FIELD_WIDTH;
    cboDriver.setLayoutData(gd_driver);
    String defaultDriverName = SQLExplorerPlugin.getDefault().getPluginPreferences().getString(IConstants.DEFAULT_DRIVER);
    ManagedDriver defaultDriver = null;
    int defaultDriverIndex = 0;
    populateCombo();
    for (Entry<Integer, ManagedDriver> entry : comboDriverIndexes.entrySet()) {
        ManagedDriver driver = entry.getValue();
        if (driver.getName().startsWith(defaultDriverName)) {
            defaultDriver = driver;
            defaultDriverIndex = entry.getKey();
            break;
        }
    }
    Button btnListDrivers = new Button(nameGroup, SWT.NULL);
    // $NON-NLS-1$
    btnListDrivers.setText(Messages.getString("AliasDialog.EditDrivers"));
    final GridData gd_btnListDrivers = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
    btnListDrivers.setLayoutData(gd_btnListDrivers);
    btnListDrivers.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            PreferenceDialog dlg = PreferencesUtil.createPreferenceDialogOn(getShell(), null, new String[] { DriverPreferencePage.class.getName() }, null);
            if (dlg.open() == IDialogConstants.OK_ID)
                populateCombo();
        }
    });
    Label label3 = new Label(nameGroup, SWT.WRAP);
    // $NON-NLS-1$
    label3.setText("URL");
    urlField = new Text(nameGroup, SWT.BORDER);
    data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
    data.horizontalSpan = 2;
    data.widthHint = SIZING_TEXT_FIELD_WIDTH;
    urlField.setLayoutData(data);
    urlField.addKeyListener(new KeyListener() {

        public void keyPressed(org.eclipse.swt.events.KeyEvent e) {
            CreateAliasDlg.this.validate();
        }

        public void keyReleased(org.eclipse.swt.events.KeyEvent e) {
            CreateAliasDlg.this.validate();
        }
    });
    new Label(nameGroup, SWT.NONE);
    noUsernameRequired = new Button(nameGroup, SWT.CHECK);
    noUsernameRequired.setText("Username is not required for this database");
    new Label(nameGroup, SWT.NONE);
    Label label4 = new Label(nameGroup, SWT.WRAP);
    // $NON-NLS-1$
    label4.setText("User Name");
    userField = new Text(nameGroup, SWT.BORDER);
    data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
    data.horizontalSpan = 2;
    data.widthHint = SIZING_TEXT_FIELD_WIDTH;
    userField.setLayoutData(data);
    userField.addKeyListener(new KeyListener() {

        public void keyPressed(org.eclipse.swt.events.KeyEvent e) {
            CreateAliasDlg.this.validate();
        }

        public void keyReleased(org.eclipse.swt.events.KeyEvent e) {
            CreateAliasDlg.this.validate();
        }
    });
    Label label5 = new Label(nameGroup, SWT.WRAP);
    // $NON-NLS-1$
    label5.setText("Password");
    passwordField = new Text(nameGroup, SWT.BORDER);
    passwordField.setEchoChar('*');
    data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
    data.horizontalSpan = 2;
    data.widthHint = SIZING_TEXT_FIELD_WIDTH;
    passwordField.setLayoutData(data);
    cboDriver.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            int selIndex = cboDriver.getSelectionIndex();
            ManagedDriver driver = comboDriverIndexes.get(selIndex);
            urlField.setText(driver.getUrl());
            CreateAliasDlg.this.validate();
        }
    });
    if (!comboDriverIndexes.isEmpty() && defaultDriver != null) {
        cboDriver.select(defaultDriverIndex);
        urlField.setText(defaultDriver.getUrl());
    }
    new Label(nameGroup, SWT.NONE);
    final Composite connectionPropertiesComposite = new Composite(nameGroup, SWT.NONE);
    connectionPropertiesComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    final GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    connectionPropertiesComposite.setLayout(gridLayout);
    new Label(nameGroup, SWT.NONE);
    new Label(nameGroup, SWT.NONE);
    /* final Button */
    autoLogonButton = new Button(connectionPropertiesComposite, SWT.CHECK);
    autoLogonButton.setToolTipText("If set, SQLExplorer will try to logon without prompting");
    final GridData gd_autoLogonButton = new GridData(158, SWT.DEFAULT);
    autoLogonButton.setLayoutData(gd_autoLogonButton);
    autoLogonButton.setText("Auto logon");
    /* final Button */
    autoCommitButton = new Button(connectionPropertiesComposite, SWT.CHECK);
    autoCommitButton.setToolTipText("Sets the default for new SQL Editors");
    autoCommitButton.setText("Auto Commit");
    /* final Button */
    logonAtStartupButton = new Button(connectionPropertiesComposite, SWT.CHECK);
    logonAtStartupButton.setToolTipText("If set, SQLExplorer will establish a connection during startup");
    logonAtStartupButton.setText("Logon during startup");
    /* final Button */
    commitOnCloseButton = new Button(connectionPropertiesComposite, SWT.CHECK);
    commitOnCloseButton.setToolTipText("Sets the default for new SQL editors");
    commitOnCloseButton.setText("Commit on close");
    new Label(nameGroup, SWT.NONE);
    autoLogonButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            boolean checked = autoLogonButton.getSelection();
            logonAtStartupButton.setEnabled(checked);
            if (!checked)
                logonAtStartupButton.setSelection(false);
        }
    });
    logonAtStartupButton.setEnabled(alias.isConnectAtStartup());
    logonAtStartupButton.setSelection(alias.isConnectAtStartup());
    autoLogonButton.setSelection(alias.isConnectAtStartup());
    autoCommitButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            commitOnCloseButton.setEnabled(!autoCommitButton.getSelection());
        }
    });
    User user = alias.getDefaultUser();
    if (user != null) {
        autoCommitButton.setSelection(user.isAutoCommit());
        commitOnCloseButton.setEnabled(!user.isAutoCommit());
        commitOnCloseButton.setSelection(user.isCommitOnClose());
    }
    noUsernameRequired.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(final SelectionEvent e) {
            userField.setEnabled(!noUsernameRequired.getSelection());
            passwordField.setEnabled(!noUsernameRequired.getSelection());
        }
    });
    if (alias.hasNoUserName()) {
        noUsernameRequired.setSelection(true);
        userField.setEnabled(false);
        passwordField.setEnabled(false);
    } else {
        noUsernameRequired.setSelection(false);
        userField.setEnabled(true);
        passwordField.setEnabled(true);
        if (alias.getDefaultUser() != null) {
            userField.setText(alias.getDefaultUser().getUserName());
            passwordField.setText(alias.getDefaultUser().getPassword());
        }
    }
    if (type != Type.CREATE) {
        if (alias.getDriver() != null)
            cboDriver.setText(alias.getDriver().getName());
        urlField.setText(alias.getUrl());
    }
    return parentComposite;
}
Also used : User(net.sourceforge.sqlexplorer.dbproduct.User) Composite(org.eclipse.swt.widgets.Composite) ManagedDriver(net.sourceforge.sqlexplorer.dbproduct.ManagedDriver) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) GridLayout(org.eclipse.swt.layout.GridLayout) PreferenceDialog(org.eclipse.jface.preference.PreferenceDialog) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) KeyListener(org.eclipse.swt.events.KeyListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 2 with User

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

the class EditUserDlg method okPressed.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
	 */
@Override
protected void okPressed() {
    String userName = this.userName.getText().trim();
    String password = this.password.getText().trim();
    if (userName.length() < 1) {
        MessageDialog.openError(getShell(), Messages.getString("EditUserDlg.MustGiveUsername.Title"), Messages.getString("EditUserDlg.MustGiveUsername.Message"));
        return;
    }
    User newUser = new User(userName, password);
    newUser.setAutoCommit(autoCommit.getSelection());
    newUser.setCommitOnClose(commitOnClose.getSelection());
    alias.setHasNoUserName(false);
    User mergedUser = alias.addUser(newUser);
    if (mergedUser != user && user != null) {
        alias.removeUser(user);
        user = mergedUser;
    }
    super.okPressed();
}
Also used : User(net.sourceforge.sqlexplorer.dbproduct.User)

Example 3 with User

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

the class FileListEditor method init.

@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    // Configure the editor
    setSite(site);
    setInput(input);
    // Create the text editor
    editor = new TextEditor();
    editor.init(site, input);
    // 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)
			 */
        public void partClosed(IWorkbenchPartReference partRef) {
            if (partRef.getPart(false) == FileListEditor.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) TextEditor(org.eclipse.ui.editors.text.TextEditor) User(net.sourceforge.sqlexplorer.dbproduct.User) ConnectionsView(net.sourceforge.sqlexplorer.connections.ConnectionsView) IWorkbenchPartReference(org.eclipse.ui.IWorkbenchPartReference) SessionEstablishedAdapter(net.sourceforge.sqlexplorer.connections.SessionEstablishedAdapter) Session(net.sourceforge.sqlexplorer.dbproduct.Session)

Example 4 with User

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

the class ConnectionTreeActionGroup method fillContextMenu.

/**
 * Fill the node context menu with all the correct actions.
 *
 * @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager)
 */
public void fillContextMenu(IMenuManager menu) {
    ConnectionsView view = SQLExplorerPlugin.getDefault().getConnectionsView();
    Object[] selection = (view == null) ? null : view.getSelected();
    // If nothing is selected, then show the default ones
    if (selection == null || selection.length != 1) {
        // addAction(menu, new CloseAllConnectionsAction());
        return;
    }
    if (selection[0] instanceof Alias) {
        Alias alias = (Alias) selection[0];
        addAction(menu, new NewEditorAction());
        addAction(menu, new NewDatabaseStructureViewAction());
        addAction(menu, new ConnectAliasAction());
        menu.add(new Separator());
        for (User user : alias.getUsers()) if (!user.isAutoCommit()) {
            addAction(menu, new CommitAction());
            addAction(menu, new RollbackAction());
            menu.add(new Separator());
            break;
        }
    // addAction(menu, new NewUserAction());
    // addAction(menu, new ChangeAliasAction());
    // addAction(menu, new CopyAliasAction());
    // addAction(menu, new DeleteAction());
    } else if (selection[0] instanceof User) {
        User user = (User) selection[0];
        addAction(menu, new NewEditorAction());
        addAction(menu, new NewDatabaseStructureViewAction());
        addAction(menu, new ConnectAliasAction());
        menu.add(new Separator());
        if (!user.isAutoCommit()) {
            addAction(menu, new CommitAction());
            addAction(menu, new RollbackAction());
            menu.add(new Separator());
        }
    // addAction(menu, new NewUserAction());
    // addAction(menu, new EditUserAction());
    // addAction(menu, new CopyUserAction());
    // addAction(menu, new DeleteAction());
    } else if (selection[0] instanceof SQLConnection) {
        SQLConnection connection = (SQLConnection) selection[0];
        addAction(menu, new NewEditorAction());
        addAction(menu, new NewDatabaseStructureViewAction());
        menu.add(new Separator());
        if (!connection.getUser().isAutoCommit()) {
            addAction(menu, new CommitAction());
            addAction(menu, new RollbackAction());
            menu.add(new Separator());
        }
    // addAction(menu, new CloseConnectionAction());
    }
}
Also used : User(net.sourceforge.sqlexplorer.dbproduct.User) NewDatabaseStructureViewAction(net.sourceforge.sqlexplorer.connections.actions.NewDatabaseStructureViewAction) Alias(net.sourceforge.sqlexplorer.dbproduct.Alias) SQLConnection(net.sourceforge.sqlexplorer.dbproduct.SQLConnection) NewEditorAction(net.sourceforge.sqlexplorer.connections.actions.NewEditorAction) ConnectAliasAction(net.sourceforge.sqlexplorer.connections.actions.ConnectAliasAction) RollbackAction(net.sourceforge.sqlexplorer.connections.actions.RollbackAction) Separator(org.eclipse.jface.action.Separator) CommitAction(net.sourceforge.sqlexplorer.connections.actions.CommitAction)

Example 5 with User

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

the class ConnectionsView method getSelectedAliases.

/**
 * Returns a list of the selected Aliases. If recurse is true then the result will include any aliases associated
 * with other objects; eg, if a connection is selected and recurse is true, then the connection's alias will also be
 * returned
 *
 * @param recurse
 * @return Set of Aliases, never returns null
 */
public Set<Alias> getSelectedAliases(boolean recurse) {
    IStructuredSelection selection = (IStructuredSelection) _treeViewer.getSelection();
    if (selection == null) {
        return EMPTY_ALIASES;
    }
    LinkedHashSet<Alias> result = new LinkedHashSet<Alias>();
    Iterator iter = selection.iterator();
    while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof Alias) {
            result.add((Alias) obj);
        } else if (recurse) {
            if (obj instanceof User) {
                User user = (User) obj;
                result.add(user.getAlias());
            } else if (obj instanceof SQLConnection) {
                SQLConnection connection = (SQLConnection) obj;
                result.add(connection.getUser().getAlias());
            }
        }
    }
    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)

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