Search in sources :

Example 1 with ObjectListControl

use of org.jkiss.dbeaver.ui.navigator.itemlist.ObjectListControl in project dbeaver by dbeaver.

the class ObjectACLEditor method createPartControl.

public void createPartControl(Composite parent) {
    this.pageControl = new PageControl(parent);
    SashForm composite = UIUtils.createPartDivider(getSite().getPart(), this.pageControl, SWT.HORIZONTAL);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    roleOrObjectTable = new DatabaseNavigatorTree(composite, DBWorkbench.getPlatform().getNavigatorModel().getRoot(), SWT.MULTI | SWT.FULL_SELECTION, false, isRoleEditor() ? new DatabaseObjectFilter() : null);
    roleOrObjectTable.setLayoutData(new GridData(GridData.FILL_BOTH));
    final TreeViewer treeViewer = roleOrObjectTable.getViewer();
    treeViewer.setLabelProvider(new DatabaseNavigatorLabelProvider(treeViewer) {

        @Override
        public Font getFont(Object element) {
            if (element instanceof DBNDatabaseNode) {
                DBSObject object = ((DBNDatabaseNode) element).getObject();
                if (object instanceof DBSSchema) {
                    String schemaPrefix = DBUtils.getQuotedIdentifier(object) + ".";
                    for (String tableName : privilegeMap.keySet()) {
                        if (tableName.startsWith(schemaPrefix)) {
                            return boldFont;
                        }
                    }
                } else if (getObjectPermissions(object) != null) {
                    return boldFont;
                }
            }
            return null;
        }
    });
    treeViewer.addSelectionChangedListener(event -> handleSelectionChange());
    treeViewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (element instanceof DBNNode && !(element instanceof DBNDatabaseNode)) {
                return false;
            }
            if (element instanceof DBNDatabaseFolder) {
                try {
                    String elementTypeName = ((DBNDatabaseFolder) element).getMeta().getType();
                    if (elementTypeName == null) {
                        return false;
                    }
                    Class<?> childType = Class.forName(elementTypeName);
                    return DBAPrivilegeOwner.class.isAssignableFrom(childType);
                } catch (ClassNotFoundException e) {
                    return false;
                }
            }
            return true;
        }
    });
    {
        permEditPanel = new Composite(composite, SWT.NONE);
        permEditPanel.setLayout(new GridLayout(1, true));
        permissionTable = new ObjectListControl<DBAPrivilege>(permEditPanel, SWT.FULL_SELECTION | SWT.CHECK, new ListContentProvider()) {

            @Override
            protected String getListConfigId(List<Class<?>> classList) {
                return ObjectACLEditor.this.getClass().getName();
            }

            @Override
            protected LoadingJob<Collection<DBAPrivilege>> createLoadService() {
                return null;
            }
        };
        permissionTable.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        /*
            UIUtils.createTableColumn(permissionTable, SWT.LEFT, "Permission");
            UIUtils.createTableColumn(permissionTable, SWT.CENTER, "With GRANT");
            UIUtils.createTableColumn(permissionTable, SWT.CENTER, "With Hierarchy");
            permissionTable.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    if (e.detail == SWT.CHECK) {
                        updateCurrentPrivileges(((TableItem) e.item).getChecked(), (DBAPrivilegeType) e.item.getData());
                    }
                }
            });

            if (!isRoleEditor()) {
                for (PRIVILEGE_TYPE pt : getACLManager().getPrivilegeTypes()) {
                    if (!pt.isValid() || !pt.supportsType(getDatabaseObject().getClass())) {
                        continue;
                    }
                    TableItem privItem = new TableItem(permissionTable, SWT.LEFT);
                    privItem.setText(0, pt.getName());
                    privItem.setData(pt);
                }
            }
*/
        Composite buttonPanel = new Composite(permEditPanel, SWT.NONE);
        buttonPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        buttonPanel.setLayout(new RowLayout());
        UIUtils.createPushButton(buttonPanel, "Grant All", null, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
            /*
                    boolean hadNonChecked = false;
                    for (TableItem item : permissionTable.getItems()) {
                        if (!item.getChecked()) hadNonChecked = true;
                        item.setChecked(true);
                    }
                    if (hadNonChecked) updateCurrentPrivileges(true, null);
*/
            }
        });
        UIUtils.createPushButton(buttonPanel, "Revoke All", null, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
            /*
                    boolean hadChecked = false;
                    for (TableItem item : permissionTable.getItems()) {
                        if (item.getChecked()) hadChecked = true;
                        item.setChecked(false);
                    }
                    if (hadChecked) {
                        updateCurrentPrivileges(false, null);
                    }
*/
            }
        });
        objectDescriptionText = new Text(permEditPanel, SWT.READ_ONLY | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
        objectDescriptionText.setLayoutData(new GridData(GridData.FILL_BOTH));
    }
    pageControl.createOrSubstituteProgressPanel(getSite());
    updateObjectPermissions(null);
}
Also used : DatabaseNavigatorLabelProvider(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorLabelProvider) ObjectListControl(org.jkiss.dbeaver.ui.navigator.itemlist.ObjectListControl) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TreeViewer(org.eclipse.jface.viewers.TreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) Font(org.eclipse.swt.graphics.Font) GridLayout(org.eclipse.swt.layout.GridLayout) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) DatabaseNavigatorTree(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree) SashForm(org.eclipse.swt.custom.SashForm) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ProgressPageControl(org.jkiss.dbeaver.ui.controls.ProgressPageControl) GridData(org.eclipse.swt.layout.GridData) Collection(java.util.Collection) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject)

Example 2 with ObjectListControl

use of org.jkiss.dbeaver.ui.navigator.itemlist.ObjectListControl in project dbeaver by serge-rider.

the class ObjectACLEditor method createPartControl.

public void createPartControl(Composite parent) {
    this.pageControl = new PageControl(parent);
    SashForm composite = UIUtils.createPartDivider(getSite().getPart(), this.pageControl, SWT.HORIZONTAL);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    roleOrObjectTable = new DatabaseNavigatorTree(composite, DBWorkbench.getPlatform().getNavigatorModel().getRoot(), SWT.MULTI | SWT.FULL_SELECTION, false, isRoleEditor() ? new DatabaseObjectFilter() : null);
    roleOrObjectTable.setLayoutData(new GridData(GridData.FILL_BOTH));
    final TreeViewer treeViewer = roleOrObjectTable.getViewer();
    treeViewer.setLabelProvider(new DatabaseNavigatorLabelProvider(treeViewer) {

        @Override
        public Font getFont(Object element) {
            if (element instanceof DBNDatabaseNode) {
                DBSObject object = ((DBNDatabaseNode) element).getObject();
                if (object instanceof DBSSchema) {
                    String schemaPrefix = DBUtils.getQuotedIdentifier(object) + ".";
                    for (String tableName : privilegeMap.keySet()) {
                        if (tableName.startsWith(schemaPrefix)) {
                            return boldFont;
                        }
                    }
                } else if (getObjectPermissions(object) != null) {
                    return boldFont;
                }
            }
            return null;
        }
    });
    treeViewer.addSelectionChangedListener(event -> handleSelectionChange());
    treeViewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (element instanceof DBNNode && !(element instanceof DBNDatabaseNode)) {
                return false;
            }
            if (element instanceof DBNDatabaseFolder) {
                try {
                    String elementTypeName = ((DBNDatabaseFolder) element).getMeta().getType();
                    if (elementTypeName == null) {
                        return false;
                    }
                    Class<?> childType = Class.forName(elementTypeName);
                    return DBAPrivilegeOwner.class.isAssignableFrom(childType);
                } catch (ClassNotFoundException e) {
                    return false;
                }
            }
            return true;
        }
    });
    {
        permEditPanel = new Composite(composite, SWT.NONE);
        permEditPanel.setLayout(new GridLayout(1, true));
        permissionTable = new ObjectListControl<DBAPrivilege>(permEditPanel, SWT.FULL_SELECTION | SWT.CHECK, new ListContentProvider()) {

            @Override
            protected String getListConfigId(List<Class<?>> classList) {
                return ObjectACLEditor.this.getClass().getName();
            }

            @Override
            protected LoadingJob<Collection<DBAPrivilege>> createLoadService() {
                return null;
            }
        };
        permissionTable.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        /*
            UIUtils.createTableColumn(permissionTable, SWT.LEFT, "Permission");
            UIUtils.createTableColumn(permissionTable, SWT.CENTER, "With GRANT");
            UIUtils.createTableColumn(permissionTable, SWT.CENTER, "With Hierarchy");
            permissionTable.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    if (e.detail == SWT.CHECK) {
                        updateCurrentPrivileges(((TableItem) e.item).getChecked(), (DBAPrivilegeType) e.item.getData());
                    }
                }
            });

            if (!isRoleEditor()) {
                for (PRIVILEGE_TYPE pt : getACLManager().getPrivilegeTypes()) {
                    if (!pt.isValid() || !pt.supportsType(getDatabaseObject().getClass())) {
                        continue;
                    }
                    TableItem privItem = new TableItem(permissionTable, SWT.LEFT);
                    privItem.setText(0, pt.getName());
                    privItem.setData(pt);
                }
            }
*/
        Composite buttonPanel = new Composite(permEditPanel, SWT.NONE);
        buttonPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        buttonPanel.setLayout(new RowLayout());
        UIUtils.createPushButton(buttonPanel, "Grant All", null, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
            /*
                    boolean hadNonChecked = false;
                    for (TableItem item : permissionTable.getItems()) {
                        if (!item.getChecked()) hadNonChecked = true;
                        item.setChecked(true);
                    }
                    if (hadNonChecked) updateCurrentPrivileges(true, null);
*/
            }
        });
        UIUtils.createPushButton(buttonPanel, "Revoke All", null, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
            /*
                    boolean hadChecked = false;
                    for (TableItem item : permissionTable.getItems()) {
                        if (item.getChecked()) hadChecked = true;
                        item.setChecked(false);
                    }
                    if (hadChecked) {
                        updateCurrentPrivileges(false, null);
                    }
*/
            }
        });
        objectDescriptionText = new Text(permEditPanel, SWT.READ_ONLY | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
        objectDescriptionText.setLayoutData(new GridData(GridData.FILL_BOTH));
    }
    pageControl.createOrSubstituteProgressPanel(getSite());
    updateObjectPermissions(null);
}
Also used : DatabaseNavigatorLabelProvider(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorLabelProvider) ObjectListControl(org.jkiss.dbeaver.ui.navigator.itemlist.ObjectListControl) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TreeViewer(org.eclipse.jface.viewers.TreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) Font(org.eclipse.swt.graphics.Font) GridLayout(org.eclipse.swt.layout.GridLayout) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) DatabaseNavigatorTree(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree) SashForm(org.eclipse.swt.custom.SashForm) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ProgressPageControl(org.jkiss.dbeaver.ui.controls.ProgressPageControl) GridData(org.eclipse.swt.layout.GridData) Collection(java.util.Collection) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject)

Aggregations

Collection (java.util.Collection)2 List (java.util.List)2 TreeViewer (org.eclipse.jface.viewers.TreeViewer)2 Viewer (org.eclipse.jface.viewers.Viewer)2 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)2 SashForm (org.eclipse.swt.custom.SashForm)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Font (org.eclipse.swt.graphics.Font)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 RowLayout (org.eclipse.swt.layout.RowLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 Text (org.eclipse.swt.widgets.Text)2 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)2 ListContentProvider (org.jkiss.dbeaver.ui.controls.ListContentProvider)2 ProgressPageControl (org.jkiss.dbeaver.ui.controls.ProgressPageControl)2 DatabaseNavigatorLabelProvider (org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorLabelProvider)2 DatabaseNavigatorTree (org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree)2 ObjectListControl (org.jkiss.dbeaver.ui.navigator.itemlist.ObjectListControl)2