Search in sources :

Example 26 with ViewerColumnController

use of org.jkiss.dbeaver.ui.controls.ViewerColumnController in project dbeaver by serge-rider.

the class NavigatorUtils method createContextMenu.

public static MenuManager createContextMenu(final IWorkbenchSite workbenchSite, final Viewer viewer, final ISelectionProvider selectionProvider, final IMenuListener menuListener) {
    final Control control = viewer.getControl();
    final MenuManager menuMgr = new MenuManager();
    Menu menu = menuMgr.createContextMenu(control);
    menu.addMenuListener(new MenuListener() {

        @Override
        public void menuHidden(MenuEvent e) {
        }

        @Override
        public void menuShown(MenuEvent e) {
            Menu m = (Menu) e.widget;
            DBNNode node = getSelectedNode(viewer.getSelection());
            if (node != null && !node.isLocked() && node.allowsOpen()) {
                String commandID = NavigatorUtils.getNodeActionCommand(DBXTreeNodeHandler.Action.open, node, NavigatorCommands.CMD_OBJECT_OPEN);
                // Get contribution item from menu item and check it's ID
                try {
                    for (MenuItem item : m.getItems()) {
                        Object itemData = item.getData();
                        if (itemData instanceof IContributionItem) {
                            String contribId = ((IContributionItem) itemData).getId();
                            if (contribId != null && contribId.equals(commandID)) {
                                m.setDefaultItem(item);
                            }
                        }
                    }
                } catch (Exception ex) {
                    log.debug(ex);
                }
            }
        }
    });
    menuMgr.addMenuListener(manager -> {
        ViewerColumnController columnController = ViewerColumnController.getFromControl(control);
        if (columnController != null && columnController.isClickOnHeader()) {
            columnController.fillConfigMenu(manager);
            manager.add(new Separator());
            return;
        }
        manager.add(new Separator());
        addStandardMenuItem(workbenchSite, manager, selectionProvider);
        if (menuListener != null) {
            menuListener.menuAboutToShow(manager);
        }
    });
    menuMgr.setRemoveAllWhenShown(true);
    control.setMenu(menu);
    return menuMgr;
}
Also used : ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) MenuListener(org.eclipse.swt.events.MenuListener) DBCException(org.jkiss.dbeaver.model.exec.DBCException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) MenuEvent(org.eclipse.swt.events.MenuEvent)

Example 27 with ViewerColumnController

use of org.jkiss.dbeaver.ui.controls.ViewerColumnController in project dbeaver by dbeaver.

the class PostgreCreateExtensionDialog method createDialogArea.

@Override
protected Composite createDialogArea(Composite parent) {
    final Composite composite = super.createDialogArea(parent);
    final Composite group = new Composite(composite, SWT.NONE);
    group.setLayout(new GridLayout(2, false));
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 600;
    gd.heightHint = 200;
    gd.verticalIndent = 0;
    gd.horizontalIndent = 0;
    group.setLayoutData(gd);
    // $NON-NLS-2$
    final Text databaseText = UIUtils.createLabelText(group, PostgreMessages.dialog_create_extension_database, newextension.getDatabase().getName(), SWT.BORDER | SWT.READ_ONLY);
    final Combo schemaCombo = UIUtils.createLabelCombo(group, PostgreMessages.dialog_create_extension_schema, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
    final Label lblExtension = UIUtils.createLabel(group, PostgreMessages.dialog_create_extension_name);
    extTable = new TableViewer(group, SWT.BORDER | SWT.UNDERLINE_SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);
    {
        final Table table = extTable.getTable();
        table.setLayoutData(new GridData(GridData.FILL_BOTH));
        table.setLinesVisible(true);
        table.setHeaderVisible(true);
        table.addControlListener(new ControlAdapter() {

            @Override
            public void controlResized(ControlEvent e) {
                UIUtils.packColumns(table);
                UIUtils.maxTableColumnsWidth(table);
                table.removeControlListener(this);
            }
        });
    }
    ViewerColumnController columnController = new ViewerColumnController("AvailabelExtensionDialog", extTable);
    columnController.addColumn(PostgreMessages.dialog_create_extension_column_name, null, SWT.NONE, true, true, new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            cell.setText(((PostgreAvailableExtension) cell.getElement()).getName());
        }
    });
    columnController.addColumn(PostgreMessages.dialog_create_extension_column_version, null, SWT.NONE, true, true, new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            cell.setText(((PostgreAvailableExtension) cell.getElement()).getVersion());
        }
    });
    columnController.addColumn(PostgreMessages.dialog_create_extension_column_description, null, SWT.NONE, true, true, new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            cell.setText(((PostgreAvailableExtension) cell.getElement()).getDescription());
        }
    });
    columnController.createColumns();
    extTable.addSelectionChangedListener(event -> {
        IStructuredSelection selection = (IStructuredSelection) event.getSelection();
        if (!selection.isEmpty()) {
            // installed.get(extensionCombo.getSelectionIndex());
            extension = (PostgreAvailableExtension) selection.getFirstElement();
            checkEnabled();
        }
    });
    extTable.setContentProvider(new ListContentProvider());
    schemaCombo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            schema = allSchemas.get(schemaCombo.getSelectionIndex());
            checkEnabled();
        }
    });
    new AbstractJob("Load schemas") {

        @Override
        protected IStatus run(DBRProgressMonitor monitor) {
            try {
                allSchemas = new ArrayList<>(newextension.getDatabase().getSchemas(monitor));
                UIUtils.syncExec(() -> {
                    for (PostgreSchema schema : allSchemas) {
                        schemaCombo.add(schema.getName());
                    }
                    schema = DBUtils.findObject(allSchemas, PostgreConstants.PUBLIC_SCHEMA_NAME);
                    if (schema != null) {
                        schemaCombo.setText(schema.getName());
                    }
                });
            } catch (DBException e) {
                return GeneralUtils.makeExceptionStatus(e);
            }
            return Status.OK_STATUS;
        }
    }.schedule();
    new AbstractJob("Load available extensions") {

        @Override
        protected IStatus run(DBRProgressMonitor monitor) {
            try {
                final List<PostgreAvailableExtension> installed = new ArrayList<>(newextension.getDatabase().getAvailableExtensions(monitor));
                UIUtils.syncExec(() -> {
                    extTable.setInput(installed);
                });
            } catch (DBException e) {
                return GeneralUtils.makeExceptionStatus(e);
            }
            return Status.OK_STATUS;
        }
    }.schedule();
    return composite;
}
Also used : PostgreAvailableExtension(org.jkiss.dbeaver.ext.postgresql.model.PostgreAvailableExtension) ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) DBException(org.jkiss.dbeaver.DBException) IStatus(org.eclipse.core.runtime.IStatus) ControlAdapter(org.eclipse.swt.events.ControlAdapter) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ViewerCell(org.eclipse.jface.viewers.ViewerCell) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) GridData(org.eclipse.swt.layout.GridData) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) ControlEvent(org.eclipse.swt.events.ControlEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) PostgreSchema(org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema)

Example 28 with ViewerColumnController

use of org.jkiss.dbeaver.ui.controls.ViewerColumnController in project dbeaver by dbeaver.

the class OracleCompilerDialog method createDialogArea.

@Override
protected Composite createDialogArea(Composite parent) {
    GridData gd;
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(2, false));
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    {
        Composite unitsGroup = new Composite(composite, SWT.NONE);
        gd = new GridData(GridData.FILL_BOTH);
        gd.widthHint = 250;
        gd.heightHint = 200;
        gd.verticalIndent = 0;
        gd.horizontalIndent = 0;
        unitsGroup.setLayoutData(gd);
        unitsGroup.setLayout(new GridLayout(1, false));
        unitTable = new TableViewer(unitsGroup, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);
        {
            final Table table = unitTable.getTable();
            table.setLayoutData(new GridData(GridData.FILL_BOTH));
            table.setLinesVisible(true);
            table.setHeaderVisible(true);
        }
        ViewerColumnController columnController = new ViewerColumnController("OracleCompilerDialog", unitTable);
        columnController.addColumn(OracleUIMessages.views_oracle_compiler_dialog_column_name, null, SWT.NONE, true, true, new CellLabelProvider() {

            @Override
            public void update(ViewerCell cell) {
                DBSObject unit = (DBSObject) cell.getElement();
                final DBNDatabaseNode node = DBNUtils.getNodeByObject(unit);
                if (node != null) {
                    cell.setText(node.getNodeName());
                    cell.setImage(DBeaverIcons.getImage(node.getNodeIconDefault()));
                } else {
                    cell.setText(unit.toString());
                }
            }
        });
        columnController.addColumn(OracleUIMessages.views_oracle_compiler_dialog_column_type, null, SWT.NONE, true, true, new CellLabelProvider() {

            @Override
            public void update(ViewerCell cell) {
                DBSObject unit = (DBSObject) cell.getElement();
                final DBNDatabaseNode node = DBNUtils.getNodeByObject(unit);
                if (node != null) {
                    cell.setText(node.getNodeType());
                } else {
                    // $NON-NLS-1$
                    cell.setText("???");
                }
            }
        });
        columnController.createColumns();
        unitTable.addSelectionChangedListener(event -> {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            getButton(COMPILE_ID).setEnabled(!selection.isEmpty());
        });
        unitTable.addDoubleClickListener(event -> {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (!selection.isEmpty()) {
                OracleSourceObject unit = (OracleSourceObject) selection.getFirstElement();
                NavigatorHandlerObjectOpen.openEntityEditor(unit);
            }
        });
        unitTable.setContentProvider(new ListContentProvider());
        unitTable.setInput(compileUnits);
    }
    {
        Composite infoGroup = new Composite(composite, SWT.NONE);
        gd = new GridData(GridData.FILL_BOTH);
        gd.widthHint = 400;
        gd.heightHint = 200;
        gd.verticalIndent = 0;
        gd.horizontalIndent = 0;
        infoGroup.setLayoutData(gd);
        infoGroup.setLayout(new GridLayout(1, false));
        compileLog = new ObjectCompilerLogViewer(infoGroup, null, true);
    }
    return composite;
}
Also used : DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) DBCException(org.jkiss.dbeaver.model.exec.DBCException) Table(org.eclipse.swt.widgets.Table) BaseDialog(org.jkiss.dbeaver.ui.dialogs.BaseDialog) DBNUtils(org.jkiss.dbeaver.model.navigator.DBNUtils) DBeaverIcons(org.jkiss.dbeaver.ui.DBeaverIcons) ViewerCell(org.eclipse.jface.viewers.ViewerCell) Composite(org.eclipse.swt.widgets.Composite) UIUtils(org.jkiss.dbeaver.ui.UIUtils) ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) Log(org.jkiss.dbeaver.Log) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) ObjectCompilerLogViewer(org.jkiss.dbeaver.ui.controls.ObjectCompilerLogViewer) GridData(org.eclipse.swt.layout.GridData) CommonUtils(org.jkiss.utils.CommonUtils) Shell(org.eclipse.swt.widgets.Shell) NLS(org.eclipse.osgi.util.NLS) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) NavigatorHandlerObjectOpen(org.jkiss.dbeaver.ui.navigator.actions.NavigatorHandlerObjectOpen) OracleSourceObject(org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject) SWT(org.eclipse.swt.SWT) OracleUIMessages(org.jkiss.dbeaver.ext.oracle.ui.internal.OracleUIMessages) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ViewerCell(org.eclipse.jface.viewers.ViewerCell) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) GridLayout(org.eclipse.swt.layout.GridLayout) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) GridData(org.eclipse.swt.layout.GridData) ObjectCompilerLogViewer(org.jkiss.dbeaver.ui.controls.ObjectCompilerLogViewer) TableViewer(org.eclipse.jface.viewers.TableViewer) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) OracleSourceObject(org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider)

Aggregations

ViewerColumnController (org.jkiss.dbeaver.ui.controls.ViewerColumnController)28 GridData (org.eclipse.swt.layout.GridData)13 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 List (java.util.List)8 Image (org.eclipse.swt.graphics.Image)7 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)7 ListContentProvider (org.jkiss.dbeaver.ui.controls.ListContentProvider)7 Collection (java.util.Collection)6 GridLayout (org.eclipse.swt.layout.GridLayout)6 DBException (org.jkiss.dbeaver.DBException)6 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)6 DBDLabelValuePair (org.jkiss.dbeaver.model.data.DBDLabelValuePair)6 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)6 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)5 Pattern (java.util.regex.Pattern)4 IStatus (org.eclipse.core.runtime.IStatus)4 Composite (org.eclipse.swt.widgets.Composite)4 Table (org.eclipse.swt.widgets.Table)4 OracleSourceObject (org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject)4 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)4