Search in sources :

Example 1 with MySQLPrivilege

use of org.jkiss.dbeaver.ext.mysql.model.MySQLPrivilege in project dbeaver by serge-rider.

the class MySQLUserEditorGeneral method createPartControl.

@Override
public void createPartControl(Composite parent) {
    pageControl = new PageControl(parent);
    Composite container = UIUtils.createPlaceholder(pageControl, 2, 5);
    GridData gd = new GridData(GridData.FILL_VERTICAL);
    container.setLayoutData(gd);
    newUser = !getDatabaseObject().isPersisted();
    {
        Composite loginGroup = UIUtils.createControlGroup(container, MySQLMessages.editors_user_editor_general_group_login, 2, GridData.HORIZONTAL_ALIGN_BEGINNING, 200);
        userNameText = UIUtils.createLabelText(loginGroup, MySQLMessages.editors_user_editor_general_label_user_name, getDatabaseObject().getUserName());
        userNameText.setEditable(newUser);
        if (newUser) {
            ControlPropertyCommandListener.create(this, userNameText, UserPropertyHandler.NAME);
        }
        hostText = UIUtils.createLabelText(loginGroup, MySQLMessages.editors_user_editor_general_label_host, getDatabaseObject().getHost());
        hostText.setEditable(newUser);
        if (newUser) {
            ControlPropertyCommandListener.create(this, hostText, UserPropertyHandler.HOST);
        }
        //$NON-NLS-1$
        String password = newUser ? "" : DEF_PASSWORD_VALUE;
        Text passwordText = UIUtils.createLabelText(loginGroup, MySQLMessages.editors_user_editor_general_label_password, password, SWT.BORDER | SWT.PASSWORD);
        ControlPropertyCommandListener.create(this, passwordText, UserPropertyHandler.PASSWORD);
        Text confirmText = UIUtils.createLabelText(loginGroup, MySQLMessages.editors_user_editor_general_label_confirm, password, SWT.BORDER | SWT.PASSWORD);
        ControlPropertyCommandListener.create(this, confirmText, UserPropertyHandler.PASSWORD_CONFIRM);
    }
    {
        Composite limitsGroup = UIUtils.createControlGroup(container, MySQLMessages.editors_user_editor_general_group_limits, 2, GridData.HORIZONTAL_ALIGN_BEGINNING, 0);
        Spinner maxQueriesText = UIUtils.createLabelSpinner(limitsGroup, MySQLMessages.editors_user_editor_general_spinner_max_queries, getDatabaseObject().getMaxQuestions(), 0, Integer.MAX_VALUE);
        ControlPropertyCommandListener.create(this, maxQueriesText, UserPropertyHandler.MAX_QUERIES);
        Spinner maxUpdatesText = UIUtils.createLabelSpinner(limitsGroup, MySQLMessages.editors_user_editor_general_spinner_max_updates, getDatabaseObject().getMaxUpdates(), 0, Integer.MAX_VALUE);
        ControlPropertyCommandListener.create(this, maxUpdatesText, UserPropertyHandler.MAX_UPDATES);
        Spinner maxConnectionsText = UIUtils.createLabelSpinner(limitsGroup, MySQLMessages.editors_user_editor_general_spinner_max_connections, getDatabaseObject().getMaxConnections(), 0, Integer.MAX_VALUE);
        ControlPropertyCommandListener.create(this, maxConnectionsText, UserPropertyHandler.MAX_CONNECTIONS);
        Spinner maxUserConnectionsText = UIUtils.createLabelSpinner(limitsGroup, MySQLMessages.editors_user_editor_general_spinner_max_user_connections, getDatabaseObject().getMaxUserConnections(), 0, Integer.MAX_VALUE);
        ControlPropertyCommandListener.create(this, maxUserConnectionsText, UserPropertyHandler.MAX_USER_CONNECTIONS);
    }
    {
        privTable = new PrivilegeTableControl(container, MySQLMessages.editors_user_editor_general_control_dba_privileges);
        gd = new GridData(GridData.FILL_BOTH);
        gd.horizontalSpan = 2;
        privTable.setLayoutData(gd);
        privTable.addListener(SWT.Modify, new Listener() {

            @Override
            public void handleEvent(Event event) {
                final MySQLPrivilege privilege = (MySQLPrivilege) event.data;
                final boolean grant = event.detail == 1;
                addChangeCommand(new MySQLCommandGrantPrivilege(getDatabaseObject(), grant, null, null, privilege), new DBECommandReflector<MySQLUser, MySQLCommandGrantPrivilege>() {

                    @Override
                    public void redoCommand(MySQLCommandGrantPrivilege mySQLCommandGrantPrivilege) {
                        if (!privTable.isDisposed()) {
                            privTable.checkPrivilege(privilege, grant);
                        }
                    }

                    @Override
                    public void undoCommand(MySQLCommandGrantPrivilege mySQLCommandGrantPrivilege) {
                        if (!privTable.isDisposed()) {
                            privTable.checkPrivilege(privilege, !grant);
                        }
                    }
                });
            }
        });
    }
    pageControl.createProgressPanel();
    commandlistener = new CommandListener();
    getEditorInput().getCommandContext().addCommandListener(commandlistener);
}
Also used : ControlPropertyCommandListener(org.jkiss.dbeaver.ui.editors.ControlPropertyCommandListener) MySQLCommandGrantPrivilege(org.jkiss.dbeaver.ext.mysql.edit.MySQLCommandGrantPrivilege) PrivilegeTableControl(org.jkiss.dbeaver.ext.mysql.controls.PrivilegeTableControl) ControlPropertyCommandListener(org.jkiss.dbeaver.ui.editors.ControlPropertyCommandListener) MySQLUser(org.jkiss.dbeaver.ext.mysql.model.MySQLUser) GridData(org.eclipse.swt.layout.GridData) MySQLPrivilege(org.jkiss.dbeaver.ext.mysql.model.MySQLPrivilege)

Example 2 with MySQLPrivilege

use of org.jkiss.dbeaver.ext.mysql.model.MySQLPrivilege in project dbeaver by serge-rider.

the class PrivilegeTableControl method fillPrivileges.

public void fillPrivileges(Collection<MySQLPrivilege> privs) {
    if (privTable.isDisposed()) {
        return;
    }
    privTable.removeAll();
    for (MySQLPrivilege priv : privs) {
        TableItem item = new TableItem(privTable, SWT.NONE);
        item.setText(0, priv.getName());
        item.setText(1, priv.getDescription());
        item.setData(priv);
    /*
            Button checkbox = new Button(privTable, SWT.CHECK);
            checkbox.pack();
            TableEditor editor = new TableEditor(privTable);
            editor.setEditor(checkbox, item, 1);
            Point size = checkbox.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            editor.minimumWidth = size.x;
            editor.minimumHeight = size.y;
            editor.horizontalAlignment = SWT.CENTER;
            editor.verticalAlignment = SWT.CENTER;

            item.setData("grant", checkbox);
*/
    }
    UIUtils.packColumns(privTable);
}
Also used : MySQLPrivilege(org.jkiss.dbeaver.ext.mysql.model.MySQLPrivilege)

Example 3 with MySQLPrivilege

use of org.jkiss.dbeaver.ext.mysql.model.MySQLPrivilege in project dbeaver by serge-rider.

the class PrivilegeTableControl method fillGrants.

public void fillGrants(List<MySQLGrant> grants) {
    if (grants == null) {
        return;
    }
    for (TableItem item : privTable.getItems()) {
        MySQLPrivilege privilege = (MySQLPrivilege) item.getData();
        //Button grantCheck = (Button)item.getData("grant");
        //, grantOption = false;
        boolean checked = false;
        for (MySQLGrant grant : grants) {
            if (grant.isAllPrivileges() || grant.getPrivileges().contains(privilege) || (grant.isGrantOption() && privilege.isGrantOption())) {
                checked = true;
                //grantOption = grant.isGrantOption();
                break;
            }
        }
        item.setChecked(checked);
    //grantCheck.setSelection(grantOption);
    }
}
Also used : MySQLPrivilege(org.jkiss.dbeaver.ext.mysql.model.MySQLPrivilege) MySQLGrant(org.jkiss.dbeaver.ext.mysql.model.MySQLGrant)

Example 4 with MySQLPrivilege

use of org.jkiss.dbeaver.ext.mysql.model.MySQLPrivilege in project dbeaver by serge-rider.

the class MySQLUserEditorGeneral method activatePart.

@Override
public void activatePart() {
    if (isLoaded) {
        return;
    }
    isLoaded = true;
    LoadingJob.createService(new DatabaseLoadService<List<MySQLPrivilege>>(MySQLMessages.editors_user_editor_general_service_load_catalog_privileges, getExecutionContext()) {

        @Override
        public List<MySQLPrivilege> evaluate(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                final List<MySQLPrivilege> privList = getDatabaseObject().getDataSource().getPrivilegesByKind(monitor, MySQLPrivilege.Kind.ADMIN);
                for (Iterator<MySQLPrivilege> iterator = privList.iterator(); iterator.hasNext(); ) {
                    MySQLPrivilege priv = iterator.next();
                    // Remove proxy (it is not singleton)
                    if (priv.getName().equalsIgnoreCase("proxy")) {
                        iterator.remove();
                    }
                }
                return privList;
            } catch (DBException e) {
                throw new InvocationTargetException(e);
            }
        }
    }, pageControl.createLoadVisualizer()).schedule();
}
Also used : DBException(org.jkiss.dbeaver.DBException) DatabaseLoadService(org.jkiss.dbeaver.model.runtime.load.DatabaseLoadService) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) MySQLPrivilege(org.jkiss.dbeaver.ext.mysql.model.MySQLPrivilege) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

MySQLPrivilege (org.jkiss.dbeaver.ext.mysql.model.MySQLPrivilege)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 GridData (org.eclipse.swt.layout.GridData)1 DBException (org.jkiss.dbeaver.DBException)1 PrivilegeTableControl (org.jkiss.dbeaver.ext.mysql.controls.PrivilegeTableControl)1 MySQLCommandGrantPrivilege (org.jkiss.dbeaver.ext.mysql.edit.MySQLCommandGrantPrivilege)1 MySQLGrant (org.jkiss.dbeaver.ext.mysql.model.MySQLGrant)1 MySQLUser (org.jkiss.dbeaver.ext.mysql.model.MySQLUser)1 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)1 DatabaseLoadService (org.jkiss.dbeaver.model.runtime.load.DatabaseLoadService)1 ControlPropertyCommandListener (org.jkiss.dbeaver.ui.editors.ControlPropertyCommandListener)1