Search in sources :

Example 26 with ListContentProvider

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

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)

Example 27 with ListContentProvider

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

the class ObjectListDialog method createObjectSelector.

@NotNull
protected static <T extends DBPObject> DatabaseObjectListControl<T> createObjectSelector(Composite group, boolean singleSelection, String listId, List<T> selectedObjects, DBRRunnableWithResult<List<T>> objectReader) {
    return new DatabaseObjectListControl<T>(group, (singleSelection ? SWT.SINGLE : SWT.MULTI), null, new ListContentProvider()) {

        private Font boldFont;

        private ISearchExecutor searcher = new SearcherFilter();

        @NotNull
        @Override
        protected String getListConfigId(List<Class<?>> classList) {
            return listId;
        }

        @Override
        protected LoadingJob<Collection<T>> createLoadService() {
            return LoadingJob.createService(new AbstractLoadService<Collection<T>>() {

                @Override
                public Collection<T> evaluate(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    objectReader.run(monitor);
                    return objectReader.getResult();
                }

                @Override
                public Object getFamily() {
                    return ObjectListDialog.class;
                }
            }, new ObjectsLoadVisualizer() {

                @Override
                public void completeLoading(Collection<T> items) {
                    super.completeLoading(items);
                    performSearch(SearchType.NONE);
                    getItemsViewer().getControl().setFocus();
                }
            });
        }

        protected CellLabelProvider getColumnLabelProvider(ObjectColumn objectColumn) {
            return new ObjectLabelProvider(objectColumn);
        }

        @Override
        protected Object getObjectValue(T item) {
            if (item instanceof DBSWrapper) {
                return ((DBSWrapper) item).getObject();
            }
            return super.getObjectValue(item);
        }

        @Override
        protected DBPImage getObjectImage(T item) {
            if (item instanceof DBNDatabaseNode) {
                return ((DBNDatabaseNode) item).getNodeIcon();
            }
            return null;
        }

        @Override
        protected void setListData(Collection<T> items, boolean append) {
            super.setListData(items, append);
            if (selectedObjects != null) {
                getItemsViewer().setSelection(new StructuredSelection(selectedObjects), true);
            }
        }

        @Override
        public void fillCustomActions(IContributionManager contributionManager) {
            super.fillCustomActions(contributionManager);
            addColumnConfigAction(contributionManager);
        }

        protected void addSearchAction(IContributionManager contributionManager) {
            contributionManager.add(new Action("Filter objects", DBeaverIcons.getImageDescriptor(UIIcon.SEARCH)) {

                @Override
                public void run() {
                    performSearch(SearchType.NONE);
                }
            });
        }

        @Override
        protected ISearchExecutor getSearchRunner() {
            return searcher;
        }

        class ObjectLabelProvider extends ObjectColumnLabelProvider implements IFontProvider {

            ObjectLabelProvider(ObjectColumn objectColumn) {
                super(objectColumn);
            }

            @Override
            public Font getFont(Object element) {
                if (selectedObjects.contains(element)) {
                    if (boldFont == null) {
                        boldFont = UIUtils.makeBoldFont(group.getFont());
                        group.addDisposeListener(e -> boldFont.dispose());
                    }
                    return boldFont;
                }
                return null;
            }
        }
    };
}
Also used : ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) org.jkiss.dbeaver.ui(org.jkiss.dbeaver.ui) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) DBPImage(org.jkiss.dbeaver.model.DBPImage) NotNull(org.jkiss.code.NotNull) ArrayList(java.util.ArrayList) Composite(org.eclipse.swt.widgets.Composite) DatabaseObjectListControl(org.jkiss.dbeaver.ui.navigator.itemlist.DatabaseObjectListControl) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) Font(org.eclipse.swt.graphics.Font) GridData(org.eclipse.swt.layout.GridData) AbstractLoadService(org.jkiss.dbeaver.model.runtime.load.AbstractLoadService) CommonUtils(org.jkiss.utils.CommonUtils) Shell(org.eclipse.swt.widgets.Shell) DBRRunnableWithResult(org.jkiss.dbeaver.model.runtime.DBRRunnableWithResult) Collection(java.util.Collection) IContributionManager(org.eclipse.jface.action.IContributionManager) Action(org.eclipse.jface.action.Action) IFontProvider(org.eclipse.jface.viewers.IFontProvider) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) DBException(org.jkiss.dbeaver.DBException) SWT(org.eclipse.swt.SWT) DBPObject(org.jkiss.dbeaver.model.DBPObject) AbstractPopupPanel(org.jkiss.dbeaver.ui.dialogs.AbstractPopupPanel) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Control(org.eclipse.swt.widgets.Control) Action(org.eclipse.jface.action.Action) DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DatabaseObjectListControl(org.jkiss.dbeaver.ui.navigator.itemlist.DatabaseObjectListControl) Font(org.eclipse.swt.graphics.Font) InvocationTargetException(java.lang.reflect.InvocationTargetException) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) SWT(org.eclipse.swt.SWT) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) DBPObject(org.jkiss.dbeaver.model.DBPObject) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) IContributionManager(org.eclipse.jface.action.IContributionManager) NotNull(org.jkiss.code.NotNull)

Example 28 with ListContentProvider

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

the class SQLToolTaskWizardPageSettings method createControl.

@Override
public void createControl(Composite parent) {
    initializeDialogUnits(parent);
    Composite composite = UIUtils.createComposite(parent, 1);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    SashForm previewSplitter = new SashForm(composite, SWT.VERTICAL);
    previewSplitter.setLayoutData(new GridData(GridData.FILL_BOTH));
    SashForm settingsPanel = new SashForm(previewSplitter, SWT.HORIZONTAL);
    Group objectsPanel;
    {
        objectsPanel = UIUtils.createControlGroup(settingsPanel, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_group_label_objects, 2, GridData.FILL_BOTH, 0);
        objectsViewer = new TableViewer(objectsPanel, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
        objectsViewer.setContentProvider(new ListContentProvider());
        objectsViewer.setLabelProvider(new ColumnLabelProvider() {

            @Override
            public String getText(Object element) {
                return DBUtils.getObjectFullName((DBPNamedObject) element, DBPEvaluationContext.UI);
            }

            @Override
            public Image getImage(Object element) {
                return DBeaverIcons.getImage(DBValueFormatting.getObjectImage((DBPObject) element));
            }
        });
        GridData gd = new GridData(GridData.FILL_BOTH);
        gd.heightHint = 150;
        gd.widthHint = 200;
        final Table objectTable = objectsViewer.getTable();
        objectTable.setLayoutData(gd);
        ToolBar buttonsToolbar = new ToolBar(objectsPanel, SWT.VERTICAL);
        buttonsToolbar.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
        UIUtils.createToolItem(buttonsToolbar, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_tool_item_text_add_string, UIIcon.ROW_ADD, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                DBNProject projectNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(sqlWizard.getProject());
                SQLToolTaskObjectSelectorDialog objectListDialog = new SQLToolTaskObjectSelectorDialog(getShell(), projectNode, (TaskTypeDescriptor) sqlWizard.getTaskType());
                if (objectListDialog.open() == IDialogConstants.OK_ID) {
                    for (DBSObject object : objectListDialog.getSelectedObjects()) {
                        if (!selectedObjects.contains(object)) {
                            selectedObjects.add(object);
                        }
                    }
                    refreshObjects();
                    updatePageCompletion();
                }
            }
        });
        ToolItem deleteItem = UIUtils.createToolItem(buttonsToolbar, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_tool_item_text_remove_string, UIIcon.ROW_DELETE, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                ISelection selection = objectsViewer.getSelection();
                if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
                    for (Object element : ((IStructuredSelection) selection).toArray()) {
                        if (element instanceof DBSObject) {
                            selectedObjects.remove(element);
                        }
                    }
                    refreshObjects();
                    updatePageCompletion();
                }
            }
        });
        UIUtils.createToolBarSeparator(buttonsToolbar, SWT.HORIZONTAL);
        ToolItem[] moveButtons = new ToolItem[2];
        moveButtons[0] = UIUtils.createToolItem(buttonsToolbar, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_tool_item_text_move_script_up, UIIcon.ARROW_UP, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                int selectionIndex = objectTable.getSelectionIndex();
                if (selectionIndex > 0) {
                    DBSObject prevScript = selectedObjects.get(selectionIndex - 1);
                    selectedObjects.set(selectionIndex - 1, selectedObjects.get(selectionIndex));
                    selectedObjects.set(selectionIndex, prevScript);
                    refreshObjects();
                }
                moveButtons[0].setEnabled(selectionIndex > 1);
                moveButtons[1].setEnabled(selectionIndex < objectTable.getItemCount() - 1);
            }
        });
        moveButtons[1] = UIUtils.createToolItem(buttonsToolbar, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_tool_item_text_move_script_down, UIIcon.ARROW_DOWN, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                int selectionIndex = objectTable.getSelectionIndex();
                if (selectionIndex < objectTable.getItemCount() - 1) {
                    DBSObject nextScript = selectedObjects.get(selectionIndex + 1);
                    selectedObjects.set(selectionIndex + 1, selectedObjects.get(selectionIndex));
                    selectedObjects.set(selectionIndex, nextScript);
                    refreshObjects();
                }
                moveButtons[0].setEnabled(selectionIndex > 0);
                moveButtons[1].setEnabled(selectionIndex < objectTable.getItemCount() - 2);
            }
        });
        objectsViewer.addSelectionChangedListener(event -> {
            int selectionIndex = objectTable.getSelectionIndex();
            deleteItem.setEnabled(selectionIndex >= 0);
            moveButtons[0].setEnabled(selectionIndex > 0);
            moveButtons[1].setEnabled(selectionIndex < objectTable.getItemCount() - 1);
        });
        deleteItem.setEnabled(false);
        moveButtons[0].setEnabled(false);
        moveButtons[1].setEnabled(false);
    }
    {
        Group optionsPanel = UIUtils.createControlGroup(settingsPanel, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_group_label_settings, 1, GridData.FILL_BOTH, 0);
        taskOptionsViewer = new PropertyTreeViewer(optionsPanel, SWT.BORDER);
        taskOptionsViewer.addPropertyChangeListener(event -> updateScriptPreview());
    }
    Composite previewPanel = UIUtils.createComposite(previewSplitter, 1);
    previewPanel.setLayout(new FillLayout());
    serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
    if (serviceSQL != null) {
        try {
            sqlPreviewPanel = serviceSQL.createSQLPanel(UIUtils.getActiveWorkbenchWindow().getActivePage().getActivePart().getSite(), previewPanel, this, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_sql_panel_name, true, "");
        } catch (DBException e) {
            DBWorkbench.getPlatformUI().showError(TasksSQLUIMessages.sql_tool_task_wizard_page_settings_title_sql_preview_error, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_message_sql_preview_panel, e);
        }
    }
    Composite controlsPanel = UIUtils.createComposite(composite, 2);
    UIUtils.createDialogButton(controlsPanel, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_dialog_button_label_copy, new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String text = serviceSQL.getSQLPanelText(sqlPreviewPanel);
            if (!CommonUtils.isEmpty(text)) {
                UIUtils.setClipboardContents(getShell().getDisplay(), TextTransfer.getInstance(), text);
            }
        }
    });
    getWizard().createTaskSaveButtons(controlsPanel, true, 1);
    loadSettings();
    if (taskOptionsViewer.getTree().getItemCount() == 0) {
        settingsPanel.setMaximizedControl(objectsPanel);
    }
    setControl(composite);
}
Also used : DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) ActiveWizardPage(org.jkiss.dbeaver.ui.dialogs.ActiveWizardPage) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) SashForm(org.eclipse.swt.custom.SashForm) Image(org.eclipse.swt.graphics.Image) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) DBCException(org.jkiss.dbeaver.model.exec.DBCException) Nullable(org.jkiss.code.Nullable) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) TaskTypeDescriptor(org.jkiss.dbeaver.registry.task.TaskTypeDescriptor) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL) ArrayList(java.util.ArrayList) DBeaverIcons(org.jkiss.dbeaver.ui.DBeaverIcons) UIUtils(org.jkiss.dbeaver.ui.UIUtils) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Log(org.jkiss.dbeaver.Log) DBNProject(org.jkiss.dbeaver.model.navigator.DBNProject) UIIcon(org.jkiss.dbeaver.ui.UIIcon) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) org.jkiss.dbeaver.model(org.jkiss.dbeaver.model) SQLToolExecuteSettings(org.jkiss.dbeaver.model.sql.task.SQLToolExecuteSettings) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CommonUtils(org.jkiss.utils.CommonUtils) NLS(org.eclipse.osgi.util.NLS) PropertyTreeViewer(org.jkiss.dbeaver.ui.properties.PropertyTreeViewer) org.eclipse.swt.widgets(org.eclipse.swt.widgets) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) PropertySourceEditable(org.jkiss.dbeaver.runtime.properties.PropertySourceEditable) List(java.util.List) SQLToolExecuteHandler(org.jkiss.dbeaver.model.sql.task.SQLToolExecuteHandler) DBException(org.jkiss.dbeaver.DBException) TasksSQLUIMessages(org.jkiss.dbeaver.tasks.ui.sql.internal.TasksSQLUIMessages) SWT(org.eclipse.swt.SWT) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBException(org.jkiss.dbeaver.DBException) PropertyTreeViewer(org.jkiss.dbeaver.ui.properties.PropertyTreeViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) DBNProject(org.jkiss.dbeaver.model.navigator.DBNProject) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FillLayout(org.eclipse.swt.layout.FillLayout) SashForm(org.eclipse.swt.custom.SashForm) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) GridData(org.eclipse.swt.layout.GridData) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 29 with ListContentProvider

use of org.jkiss.dbeaver.ui.controls.ListContentProvider 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 30 with ListContentProvider

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

the class DashboardAddDialog method createDialogArea.

@Override
protected Composite createDialogArea(Composite parent) {
    Composite dialogArea = super.createDialogArea(parent);
    // AdvancedListViewer listViewer = new AdvancedListViewer(dialogArea, SWT.NONE);
    // listViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    TableViewer dashboardTable = new TableViewer(dialogArea, SWT.BORDER | SWT.FULL_SELECTION);
    dashboardTable.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    Table table = dashboardTable.getTable();
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 400;
    gd.heightHint = 200;
    table.setLayoutData(gd);
    table.setHeaderVisible(true);
    UIUtils.createTableColumn(table, SWT.LEFT, UIDashboardMessages.dialog_add_dashboard_column_name);
    UIUtils.createTableColumn(table, SWT.LEFT, UIDashboardMessages.dialog_add_dashboard_column_description);
    dashboardTable.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            DashboardDescriptor dashboardDescriptor = (DashboardDescriptor) cell.getElement();
            if (cell.getColumnIndex() == 0) {
                cell.setText(dashboardDescriptor.getName());
            } else {
                cell.setText(CommonUtils.notEmpty(dashboardDescriptor.getDescription()));
            }
        }
    });
    dashboardTable.addDoubleClickListener(event -> {
        if (!dashboardTable.getSelection().isEmpty()) {
            okPressed();
        }
    });
    dashboardTable.addSelectionChangedListener(event -> {
        ISelection selection = dashboardTable.getSelection();
        getButton(IDialogConstants.OK_ID).setEnabled(!selection.isEmpty());
        if (selection instanceof IStructuredSelection) {
            selectedDashboard = (DashboardDescriptor) ((IStructuredSelection) selection).getFirstElement();
        }
        getButton(IDialogConstants.OK_ID).setEnabled(selectedDashboard != null);
    });
    table.addPaintListener(e -> {
        if (table.getItemCount() == 0) {
            final String dbmsName = viewConfiguration.getDataSourceContainer().getDriver().getName();
            final String msg = NLS.bind(UIDashboardMessages.dialog_add_dashboard_message_no_more_dashboards_for, dbmsName);
            UIUtils.drawMessageOverControl(table, e, msg, 0);
        }
    });
    dashboardTable.setContentProvider(new ListContentProvider());
    java.util.List<DashboardDescriptor> dashboards = new ArrayList<>(DashboardRegistry.getInstance().getDashboards(viewConfiguration.getDataSourceContainer(), false));
    dashboards.removeIf(descriptor -> viewConfiguration.getDashboardConfig(descriptor.getId()) != null);
    dashboardTable.setInput(dashboards);
    UIUtils.asyncExec(() -> UIUtils.packColumns(table, true));
    return dialogArea;
}
Also used : Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ArrayList(java.util.ArrayList) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) DashboardDescriptor(org.jkiss.dbeaver.ui.dashboard.registry.DashboardDescriptor) GridData(org.eclipse.swt.layout.GridData)

Aggregations

ListContentProvider (org.jkiss.dbeaver.ui.controls.ListContentProvider)33 GridData (org.eclipse.swt.layout.GridData)29 Composite (org.eclipse.swt.widgets.Composite)20 List (java.util.List)14 DBException (org.jkiss.dbeaver.DBException)14 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)14 ArrayList (java.util.ArrayList)12 GridLayout (org.eclipse.swt.layout.GridLayout)12 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)11 SWT (org.eclipse.swt.SWT)10 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)10 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)9 IDialogConstants (org.eclipse.jface.dialogs.IDialogConstants)8 TableViewer (org.eclipse.jface.viewers.TableViewer)8 SashForm (org.eclipse.swt.custom.SashForm)8 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)8 DBPObject (org.jkiss.dbeaver.model.DBPObject)7 ViewerColumnController (org.jkiss.dbeaver.ui.controls.ViewerColumnController)7 Collection (java.util.Collection)6