Search in sources :

Example 6 with ListContentProvider

use of org.jkiss.dbeaver.ui.controls.ListContentProvider 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(OracleMessages.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 = NavigatorUtils.getNodeByObject(unit);
                if (node != null) {
                    cell.setText(node.getNodeName());
                    cell.setImage(DBeaverIcons.getImage(node.getNodeIconDefault()));
                } else {
                    cell.setText(unit.toString());
                }
            }
        });
        columnController.addColumn(OracleMessages.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 = NavigatorUtils.getNodeByObject(unit);
                if (node != null) {
                    cell.setText(node.getNodeType());
                } else {
                    // $NON-NLS-1$
                    cell.setText("???");
                }
            }
        });
        columnController.createColumns();
        unitTable.addSelectionChangedListener(new ISelectionChangedListener() {

            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                getButton(COMPILE_ID).setEnabled(!selection.isEmpty());
            }
        });
        unitTable.addDoubleClickListener(new IDoubleClickListener() {

            @Override
            public void doubleClick(DoubleClickEvent 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, true);
    }
    return composite;
}
Also used : ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) 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) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) OracleSourceObject(org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject)

Example 7 with ListContentProvider

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

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 8 with ListContentProvider

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

the class ColumnsMappingDialog method createDialogArea.

@Override
protected Composite createDialogArea(Composite parent) {
    DBPDataSource targetDataSource = settings.getTargetDataSource(mapping);
    boldFont = UIUtils.makeBoldFont(parent.getFont());
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(2, false));
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    DBPDataSource sourceDataSource = mapping.getSource().getDataSource();
    UIUtils.createLabelText(composite, DTUIMessages.columns_mapping_dialog_composite_label_text_source_container, sourceDataSource == null ? "" : sourceDataSource.getContainer().getName(), SWT.BORDER | SWT.READ_ONLY);
    Text sourceEntity = UIUtils.createLabelText(composite, DTUIMessages.columns_mapping_dialog_composite_label_text_source_entity, DBUtils.getObjectFullName(mapping.getSource(), DBPEvaluationContext.UI), SWT.BORDER | SWT.READ_ONLY | SWT.MULTI | SWT.V_SCROLL);
    ((GridData) sourceEntity.getLayoutData()).widthHint = 600;
    ((GridData) sourceEntity.getLayoutData()).heightHint = UIUtils.getFontHeight(sourceEntity) * 3;
    UIUtils.createLabelText(composite, DTUIMessages.columns_mapping_dialog_composite_label_text_target_container, (targetDataSource == null ? "?" : targetDataSource.getContainer().getName()), SWT.BORDER | SWT.READ_ONLY);
    Text targetEntity = UIUtils.createLabelText(composite, DTUIMessages.columns_mapping_dialog_composite_label_text_target_entity, mapping.getTargetName(), SWT.BORDER | SWT.READ_ONLY);
    ((GridData) targetEntity.getLayoutData()).widthHint = 600;
    ((GridData) targetEntity.getLayoutData()).heightHint = UIUtils.getFontHeight(sourceEntity) * 3;
    mappingViewer = new TableViewer(composite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 600;
    gd.heightHint = 300;
    gd.horizontalSpan = 2;
    mappingViewer.getTable().setLayoutData(gd);
    mappingViewer.getTable().setLinesVisible(true);
    mappingViewer.getTable().setHeaderVisible(true);
    mappingViewer.setContentProvider(new ListContentProvider());
    mappingViewer.getTable().addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.character == SWT.DEL) {
                for (TableItem item : mappingViewer.getTable().getSelection()) {
                    DatabaseMappingAttribute attribute = (DatabaseMappingAttribute) item.getData();
                    attribute.setMappingType(DatabaseMappingType.skip);
                }
                mappingViewer.refresh();
            } else if (e.character == SWT.SPACE) {
                for (TableItem item : mappingViewer.getTable().getSelection()) {
                    DatabaseMappingAttribute attribute = (DatabaseMappingAttribute) item.getData();
                    attribute.setMappingType(DatabaseMappingType.existing);
                    try {
                        attribute.updateMappingType(new VoidProgressMonitor());
                    } catch (DBException e1) {
                        DBWorkbench.getPlatformUI().showError("Bad mapping", "Invalid column mapping", e1);
                    }
                }
                mappingViewer.refresh();
            }
        }
    });
    {
        TableViewerColumn columnSource = new TableViewerColumn(mappingViewer, SWT.LEFT);
        columnSource.setLabelProvider(new CellLabelProvider() {

            @Override
            public void update(ViewerCell cell) {
                DatabaseMappingAttribute attrMapping = (DatabaseMappingAttribute) cell.getElement();
                cell.setText(DBUtils.getObjectFullName(attrMapping.getSource(), DBPEvaluationContext.UI));
                if (attrMapping.getIcon() != null) {
                    cell.setImage(DBeaverIcons.getImage(attrMapping.getIcon()));
                }
            }
        });
        columnSource.getColumn().setText(DTUIMessages.columns_mapping_dialog_column_source_text);
        columnSource.getColumn().setWidth(170);
    }
    {
        TableViewerColumn columnSourceType = new TableViewerColumn(mappingViewer, SWT.LEFT);
        columnSourceType.setLabelProvider(new CellLabelProvider() {

            @Override
            public void update(ViewerCell cell) {
                cell.setText(((DatabaseMappingAttribute) cell.getElement()).getSourceType());
            }
        });
        columnSourceType.getColumn().setText(DTUIMessages.columns_mapping_dialog_column_source_type_text);
        columnSourceType.getColumn().setWidth(100);
    }
    {
        TableViewerColumn columnTarget = new TableViewerColumn(mappingViewer, SWT.LEFT);
        columnTarget.setLabelProvider(new CellLabelProvider() {

            @Override
            public void update(ViewerCell cell) {
                DatabaseMappingAttribute mapping = (DatabaseMappingAttribute) cell.getElement();
                cell.setText(mapping.getTargetName());
                if (mapping.getMappingType() == DatabaseMappingType.unspecified) {
                    cell.setBackground(UIUtils.getSharedTextColors().getColor(SharedTextColors.COLOR_WARNING));
                } else {
                    cell.setBackground(null);
                }
                cell.setFont(boldFont);
            }
        });
        columnTarget.getColumn().setText(DTUIMessages.columns_mapping_dialog_column_target_text);
        columnTarget.getColumn().setWidth(170);
        columnTarget.setEditingSupport(new EditingSupport(mappingViewer) {

            @Override
            protected CellEditor getCellEditor(Object element) {
                try {
                    java.util.List<String> items = new ArrayList<>();
                    DatabaseMappingAttribute mapping = (DatabaseMappingAttribute) element;
                    if (mapping.getParent().getMappingType() == DatabaseMappingType.existing && mapping.getParent().getTarget() instanceof DBSEntity) {
                        DBSEntity parentEntity = (DBSEntity) mapping.getParent().getTarget();
                        for (DBSEntityAttribute attr : CommonUtils.safeCollection(parentEntity.getAttributes(new VoidProgressMonitor()))) {
                            items.add(attr.getName());
                        }
                    }
                    items.add(DatabaseMappingAttribute.TARGET_NAME_SKIP);
                    return new CustomComboBoxCellEditor(mappingViewer, mappingViewer.getTable(), items.toArray(new String[0]), SWT.DROP_DOWN);
                } catch (DBException e) {
                    DBWorkbench.getPlatformUI().showError("Bad value", "Wrong target column", e);
                    return null;
                }
            }

            @Override
            protected boolean canEdit(Object element) {
                return true;
            }

            @Override
            protected Object getValue(Object element) {
                return ((DatabaseMappingAttribute) element).getTargetName();
            }

            @Override
            protected void setValue(Object element, Object value) {
                try {
                    String name = CommonUtils.toString(value);
                    DatabaseMappingAttribute attrMapping = (DatabaseMappingAttribute) element;
                    if (DatabaseMappingAttribute.TARGET_NAME_SKIP.equals(name)) {
                        attrMapping.setMappingType(DatabaseMappingType.skip);
                    } else {
                        if (attrMapping.getParent().getMappingType() == DatabaseMappingType.existing && attrMapping.getParent().getTarget() instanceof DBSEntity) {
                            DBSEntity parentEntity = (DBSEntity) attrMapping.getParent().getTarget();
                            for (DBSEntityAttribute attr : CommonUtils.safeCollection(parentEntity.getAttributes(new VoidProgressMonitor()))) {
                                if (name.equalsIgnoreCase(attr.getName())) {
                                    attrMapping.setTarget(attr);
                                    attrMapping.setMappingType(DatabaseMappingType.existing);
                                    attrMapping.setTargetName(name);
                                    return;
                                }
                            }
                        }
                        attrMapping.setMappingType(DatabaseMappingType.create);
                        attrMapping.setTargetName(name);
                    }
                } catch (DBException e) {
                    DBWorkbench.getPlatformUI().showError("Bad value", "Wrong target", e);
                } finally {
                    mappingViewer.refresh();
                }
            }
        });
    }
    {
        TableViewerColumn columnTargetType = new TableViewerColumn(mappingViewer, SWT.LEFT);
        columnTargetType.setLabelProvider(new CellLabelProvider() {

            @Override
            public void update(ViewerCell cell) {
                DatabaseMappingAttribute attrMapping = (DatabaseMappingAttribute) cell.getElement();
                DBPDataSource dataSource = settings.getTargetDataSource(attrMapping);
                cell.setText(attrMapping.getTargetType(dataSource, true));
                cell.setFont(boldFont);
            }
        });
        columnTargetType.getColumn().setText(DTUIMessages.columns_mapping_dialog_column_target_type_text);
        columnTargetType.getColumn().setWidth(100);
        columnTargetType.setEditingSupport(new EditingSupport(mappingViewer) {

            @Override
            protected CellEditor getCellEditor(Object element) {
                DatabaseMappingAttribute attrMapping = (DatabaseMappingAttribute) element;
                Set<String> types = new TreeSet<>();
                DBPDataSource dataSource = settings.getTargetDataSource(attrMapping);
                if (dataSource instanceof DBPDataTypeProvider) {
                    for (DBSDataType type : ((DBPDataTypeProvider) dataSource).getLocalDataTypes()) {
                        types.add(type.getName());
                    }
                }
                types.add(attrMapping.getTargetType(dataSource, true));
                return new CustomComboBoxCellEditor(mappingViewer, mappingViewer.getTable(), types.toArray(new String[0]), SWT.BORDER);
            }

            @Override
            protected boolean canEdit(Object element) {
                return true;
            }

            @Override
            protected Object getValue(Object element) {
                DatabaseMappingAttribute attrMapping = (DatabaseMappingAttribute) element;
                return attrMapping.getTargetType(settings.getTargetDataSource(attrMapping), true);
            }

            @Override
            protected void setValue(Object element, Object value) {
                DatabaseMappingAttribute attrMapping = (DatabaseMappingAttribute) element;
                attrMapping.setTargetType(CommonUtils.toString(value));
                mappingViewer.refresh(element);
            }
        });
    }
    {
        TableViewerColumn columnType = new TableViewerColumn(mappingViewer, SWT.LEFT);
        columnType.setLabelProvider(new CellLabelProvider() {

            @Override
            public void update(ViewerCell cell) {
                DatabaseMappingAttribute mapping = (DatabaseMappingAttribute) cell.getElement();
                String text = "";
                switch(mapping.getMappingType()) {
                    case unspecified:
                        text = "?";
                        break;
                    case existing:
                        text = DTUIMessages.columns_mapping_dialog_cell_text_existing;
                        break;
                    case create:
                        text = DTUIMessages.columns_mapping_dialog_cell_text_new;
                        break;
                    case skip:
                        text = DTUIMessages.columns_mapping_dialog_cell_text_skip;
                        break;
                }
                cell.setText(text);
            }
        });
        columnType.getColumn().setText(DTUIMessages.columns_mapping_dialog_column_type_text_mapping);
        columnType.getColumn().setWidth(60);
    }
    mappingViewer.setInput(attributeMappings);
    return parent;
}
Also used : DBException(org.jkiss.dbeaver.DBException) KeyAdapter(org.eclipse.swt.events.KeyAdapter) TableItem(org.eclipse.swt.widgets.TableItem) CustomComboBoxCellEditor(org.jkiss.dbeaver.ui.controls.CustomComboBoxCellEditor) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) Composite(org.eclipse.swt.widgets.Composite) DBSDataType(org.jkiss.dbeaver.model.struct.DBSDataType) Text(org.eclipse.swt.widgets.Text) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) DatabaseMappingAttribute(org.jkiss.dbeaver.tools.transfer.database.DatabaseMappingAttribute) java.util(java.util) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) GridData(org.eclipse.swt.layout.GridData) DBPDataTypeProvider(org.jkiss.dbeaver.model.DBPDataTypeProvider) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity)

Example 9 with ListContentProvider

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

the class DataTransferPagePipes method createInputsTable.

private void createInputsTable(Composite composite) {
    Composite panel = UIUtils.createComposite(composite, 1);
    // UIUtils.createControlLabel(panel, DTUIMessages.data_transfer_wizard_final_group_objects);
    inputsTable = new TableViewer(panel, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
    inputsTable.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
    inputsTable.getTable().setLinesVisible(true);
    inputsTable.getTable().setHeaderVisible(true);
    inputsTable.setContentProvider(new ListContentProvider());
    UIUtils.createTableContextMenu(inputsTable.getTable(), null);
    DBNModel nModel = DBWorkbench.getPlatform().getNavigatorModel();
    CellLabelProvider labelProvider = new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            DBSObject element = (DBSObject) cell.getElement();
            if (cell.getColumnIndex() == 0) {
                DBNDatabaseNode objectNode = nModel.getNodeByObject(element);
                DBPImage icon = objectNode != null ? objectNode.getNodeIconDefault() : DBValueFormatting.getObjectImage(element);
                cell.setImage(DBeaverIcons.getImage(icon));
                cell.setText(DBUtils.getObjectFullName(element, DBPEvaluationContext.UI));
            } else if (element.getDescription() != null) {
                cell.setText(element.getDescription());
            }
        }
    };
    {
        TableViewerColumn columnName = new TableViewerColumn(inputsTable, SWT.LEFT);
        columnName.setLabelProvider(labelProvider);
        columnName.getColumn().setText(DTMessages.data_transfer_wizard_init_column_exported);
        TableViewerColumn columnDesc = new TableViewerColumn(inputsTable, SWT.LEFT);
        columnDesc.setLabelProvider(labelProvider);
        columnDesc.getColumn().setText(DTMessages.data_transfer_wizard_init_column_description);
    }
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel) DBPImage(org.jkiss.dbeaver.model.DBPImage)

Example 10 with ListContentProvider

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

the class GenericFilterValueEdit method setupTable.

void setupTable(Composite composite, int style, boolean visibleLines, boolean visibleHeader, Object layoutData) {
    tableViewer = new TableViewer(composite, style);
    Table table = this.tableViewer.getTable();
    table.setLinesVisible(false);
    table.setHeaderVisible(visibleHeader);
    table.setLayoutData(layoutData);
    this.tableViewer.setContentProvider(new ListContentProvider());
    isCheckedTable = (style & SWT.CHECK) == SWT.CHECK;
    if (isCheckedTable) {
        buttonsPanel = UIUtils.createComposite(composite, 2);
        buttonsPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        toggleButton = UIUtils.createDialogButton(buttonsPanel, "&Select All", new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                TableItem[] items = tableViewer.getTable().getItems();
                if (Boolean.FALSE.equals(toggleButton.getData())) {
                    // Clear all checked
                    for (TableItem item : items) {
                        item.setChecked(false);
                    }
                    toggleButton.setData(false);
                    savedValues.clear();
                } else {
                    for (TableItem item : items) {
                        item.setChecked(true);
                        savedValues.add((((DBDLabelValuePair) item.getData())).getValue());
                    }
                    toggleButton.setData(true);
                }
                updateToggleButton(toggleButton);
            }
        });
        toggleButton.setData(true);
        GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
        gd.widthHint = 120;
        toggleButton.setLayoutData(gd);
        UIUtils.createEmptyLabel(buttonsPanel, 1, 1).setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        tableViewer.getTable().addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                if (e.detail == SWT.CHECK) {
                    DBDLabelValuePair value = (DBDLabelValuePair) e.item.getData();
                    if (((TableItem) e.item).getChecked()) {
                        savedValues.add(value.getValue());
                    } else {
                        savedValues.remove(value.getValue());
                    }
                    updateToggleButton(toggleButton);
                }
            }
        });
    }
}
Also used : ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) DBDLabelValuePair(org.jkiss.dbeaver.model.data.DBDLabelValuePair)

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