Search in sources :

Example 56 with DBNDatabaseNode

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.

the class DatabaseConsumerPageMapping method activatePage.

@Override
public void activatePage() {
    final DatabaseConsumerSettings settings = getDatabaseConsumerSettings();
    // Detect producer container (e.g. schema)
    DBSObjectContainer producerContainer = null;
    for (DataTransferPipe pipe : getWizard().getSettings().getDataPipes()) {
        if (pipe.getProducer() != null) {
            DBSObject producerObject = pipe.getProducer().getDatabaseObject();
            if (producerObject instanceof DBSDataContainer) {
                DBSObject container = producerObject.getParentObject();
                if (container instanceof DBSObjectContainer) {
                    producerContainer = (DBSObjectContainer) container;
                }
            }
        }
    }
    settings.loadNode(getWizard().getRunnableContext(), getWizard().getSettings(), producerContainer);
    DBNDatabaseNode containerNode = settings.getContainerNode();
    if (containerNode != null) {
        try {
            containerPanel.checkValidContainerNode(containerNode);
            containerPanel.setContainerInfo(containerNode);
        } catch (DBException e) {
            setErrorMessage(e.getMessage());
        }
    }
    boolean newMappings = false;
    {
        // Load columns model. Update it only if mapping have different set of source columns
        // Otherwise we keep current mappings (to allow wizard page navigation without loosing mappings)
        List<DatabaseMappingContainer> model = new ArrayList<>();
        for (DataTransferPipe pipe : getWizard().getSettings().getDataPipes()) {
            if (pipe.getProducer() == null || !(pipe.getProducer().getDatabaseObject() instanceof DBSDataContainer)) {
                continue;
            }
            DBSDataContainer sourceDataContainer = (DBSDataContainer) pipe.getProducer().getDatabaseObject();
            DatabaseMappingContainer mapping = settings.getDataMapping(sourceDataContainer);
            {
                // Create new mapping for source object
                DatabaseMappingContainer newMapping;
                if (pipe.getConsumer() instanceof DatabaseTransferConsumer && ((DatabaseTransferConsumer) pipe.getConsumer()).getTargetObject() != null) {
                    try {
                        newMapping = new DatabaseMappingContainer(getWizard().getRunnableContext(), getDatabaseConsumerSettings(), sourceDataContainer, ((DatabaseTransferConsumer) pipe.getConsumer()).getTargetObject());
                    } catch (DBException e) {
                        setMessage(e.getMessage(), IMessageProvider.ERROR);
                        newMapping = new DatabaseMappingContainer(getDatabaseConsumerSettings(), sourceDataContainer);
                    }
                } else {
                    newMapping = new DatabaseMappingContainer(getDatabaseConsumerSettings(), sourceDataContainer);
                }
                newMapping.getAttributeMappings(getWizard().getRunnableContext());
                // Update current mapping if it differs from new one
                if (mapping == null || !mapping.isSameMapping(newMapping)) {
                    mapping = newMapping;
                    settings.addDataMappings(getWizard().getRunnableContext(), sourceDataContainer, mapping);
                }
            }
            model.add(mapping);
            newMappings = mapping.getMappingType() == DatabaseMappingType.unspecified;
        }
        mappingViewer.setInput(model);
        if (!model.isEmpty()) {
            // Select first element
            mappingViewer.setSelection(new StructuredSelection(model.get(0)));
        }
        if (newMappings) {
            autoAssignMappings();
        }
        Tree table = mappingViewer.getTree();
        int totalWidth = table.getClientArea().width;
        TreeColumn[] columns = table.getColumns();
        columns[0].setWidth(totalWidth * 40 / 100);
        columns[1].setWidth(totalWidth * 40 / 100);
        columns[2].setWidth(totalWidth * 20 / 100);
    }
    updatePageCompletion();
}
Also used : DBException(org.jkiss.dbeaver.DBException) DataTransferPipe(org.jkiss.dbeaver.tools.transfer.DataTransferPipe) ArrayList(java.util.ArrayList) List(java.util.List) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 57 with DBNDatabaseNode

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.

the class StreamProducerPageSettings method updateSingleConsumer.

private void updateSingleConsumer(DBRProgressMonitor monitor, DataTransferPipe pipe, File file) {
    final StreamProducerSettings producerSettings = getWizard().getPageSettings(this, StreamProducerSettings.class);
    final StreamTransferProducer oldProducer = pipe.getProducer() instanceof StreamTransferProducer ? (StreamTransferProducer) pipe.getProducer() : null;
    final StreamTransferProducer newProducer = new StreamTransferProducer(new StreamEntityMapping(file));
    pipe.setProducer(newProducer);
    producerSettings.updateProducerSettingsFromStream(monitor, newProducer, getWizard().getSettings());
    IDataTransferSettings consumerSettings = getWizard().getSettings().getNodeSettings(getWizard().getSettings().getConsumer());
    if (consumerSettings instanceof DatabaseConsumerSettings) {
        DatabaseConsumerSettings settings = (DatabaseConsumerSettings) consumerSettings;
        DatabaseMappingContainer mapping = new DatabaseMappingContainer(settings, newProducer.getDatabaseObject());
        if (pipe.getConsumer() != null && pipe.getConsumer().getDatabaseObject() instanceof DBSDataManipulator) {
            DBSDataManipulator databaseObject = (DBSDataManipulator) pipe.getConsumer().getDatabaseObject();
            DBNDatabaseNode databaseNode = DBNUtils.getNodeByObject(monitor, databaseObject.getParentObject(), false);
            if (databaseNode != null) {
                settings.setContainerNode(databaseNode);
            }
            mapping.setTarget(databaseObject);
        } else {
            mapping.setTarget(null);
            mapping.setTargetName(generateTableName(newProducer.getInputFile()));
        }
        if (oldProducer != null) {
            // Remove old mapping because we're just replaced file
            DatabaseMappingContainer oldMappingContainer = settings.getDataMappings().remove(oldProducer.getDatabaseObject());
            if (oldMappingContainer != null && oldMappingContainer.getSource() instanceof StreamEntityMapping) {
                StreamEntityMapping oldEntityMapping = (StreamEntityMapping) oldMappingContainer.getSource();
                // Copy mappings from old producer if columns are the same
                if (oldEntityMapping.isSameColumns(newProducer.getEntityMapping())) {
                    StreamEntityMapping entityMapping = new StreamEntityMapping(file);
                    settings.addDataMappings(getWizard().getRunnableContext(), entityMapping, new DatabaseMappingContainer(oldMappingContainer, entityMapping));
                    StreamTransferProducer producer = new StreamTransferProducer(entityMapping);
                    pipe.setProducer(producer);
                    producerSettings.updateProducerSettingsFromStream(monitor, producer, getWizard().getSettings());
                    return;
                }
            }
        }
        settings.addDataMappings(getWizard().getRunnableContext(), newProducer.getDatabaseObject(), mapping);
    }
}
Also used : StreamTransferProducer(org.jkiss.dbeaver.tools.transfer.stream.StreamTransferProducer) StreamProducerSettings(org.jkiss.dbeaver.tools.transfer.stream.StreamProducerSettings) DatabaseConsumerSettings(org.jkiss.dbeaver.tools.transfer.database.DatabaseConsumerSettings) DBSDataManipulator(org.jkiss.dbeaver.model.struct.DBSDataManipulator) StreamEntityMapping(org.jkiss.dbeaver.tools.transfer.stream.StreamEntityMapping) DatabaseMappingContainer(org.jkiss.dbeaver.tools.transfer.database.DatabaseMappingContainer) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 58 with DBNDatabaseNode

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode 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 59 with DBNDatabaseNode

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.

the class SearchDataPage method saveTreeState.

protected void saveTreeState() {
    // Object sources
    StringBuilder sourcesString = new StringBuilder();
    for (DBNNode node : selectorPanel.getCheckedNodes()) {
        if (node instanceof DBNDatabaseNode && ((DBNDatabaseNode) node).getObject() instanceof DBSDataContainer) {
            if (sourcesString.length() > 0) {
                // $NON-NLS-1$
                sourcesString.append("|");
            }
            sourcesString.append(node.getNodeItemPath());
        }
    }
    searchStateCache.put(getClass(), sourcesString.toString());
}
Also used : DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 60 with DBNDatabaseNode

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.

the class ItemListControl method fillCustomActions.

@Override
public void fillCustomActions(IContributionManager contributionManager) {
    super.fillCustomActions(contributionManager);
    final DBNNode rootNode = getRootNode();
    if (rootNode instanceof DBNDatabaseFolder && ((DBNDatabaseFolder) rootNode).getItemsMeta() != null) {
        contributionManager.add(new Action(UINavigatorMessages.obj_editor_properties_control_action_filter_setting, DBeaverIcons.getImageDescriptor(UIIcon.FILTER)) {

            @Override
            public void run() {
                NavigatorHandlerFilterConfig.configureFilters(getShell(), rootNode);
            }
        });
    }
    addColumnConfigAction(contributionManager);
    IWorkbenchSite workbenchSite = getWorkbenchSite();
    if (rootNode instanceof DBNDatabaseFolder) {
        contributionManager.add(new Separator());
        contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_OPEN));
        {
            if (ObjectPropertyTester.canCreateObject(rootNode, true)) {
                contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_CREATE));
            } else if (ObjectPropertyTester.canCreateObject(rootNode, false)) {
                contributionManager.add(new Action(null, Action.AS_DROP_DOWN_MENU) {

                    {
                        setActionDefinitionId(NavigatorCommands.CMD_OBJECT_CREATE);
                    }

                    @Override
                    public void run() {
                        super.run();
                    }

                    @Override
                    public IMenuCreator getMenuCreator() {
                        return new MenuCreator(control -> {
                            List<IContributionItem> items = NavigatorHandlerObjectCreateNew.fillCreateMenuItems((IWorkbenchPartSite) workbenchSite, rootNode);
                            MenuManager menuManager = new MenuManager();
                            for (IContributionItem cc : items) {
                                menuManager.add(cc);
                            }
                            return menuManager;
                        });
                    }
                });
            }
        }
        contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_DELETE));
    }
    if (rootNode instanceof DBNDatabaseNode && rootNode.isPersisted()) {
        boolean hasReorder = false;
        List<Class<?>> childrenTypes = ((DBNDatabaseNode) rootNode).getChildrenTypes(null);
        for (Class<?> chilType : childrenTypes) {
            if (DBWorkbench.getPlatform().getEditorsRegistry().getObjectManager(chilType, DBEObjectReorderer.class) != null) {
                hasReorder = true;
                break;
            }
        }
        if (hasReorder) {
            contributionManager.add(new Separator());
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_MOVE_UP));
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_MOVE_DOWN));
        }
    }
    if (rootNode instanceof DBNDatabaseNode) {
        // Expand/collapse
        final List<DBXTreeNode> inlineMetas = collectInlineMetas((DBNDatabaseNode) rootNode, ((DBNDatabaseNode) rootNode).getMeta());
        if (!inlineMetas.isEmpty()) {
            contributionManager.add(new Separator());
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.NAVIGATE_COLLAPSE_ALL, null, UIIcon.TREE_COLLAPSE_ALL));
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.NAVIGATE_EXPAND_ALL, null, UIIcon.TREE_EXPAND_ALL));
        }
    }
    // Save/revert
    if (workbenchSite instanceof MultiPageEditorSite) {
        final MultiPageEditorPart editor = ((MultiPageEditorSite) workbenchSite).getMultiPageEditor();
        if (editor instanceof EntityEditor) {
            contributionManager.add(new Separator());
            DatabaseEditorUtils.contributeStandardEditorActions(workbenchSite, contributionManager);
        }
    }
}
Also used : IWorkbenchSite(org.eclipse.ui.IWorkbenchSite) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) DatabaseLoadService(org.jkiss.dbeaver.model.runtime.load.DatabaseLoadService) ObjectPropertyTester(org.jkiss.dbeaver.ui.actions.ObjectPropertyTester) Arrays(java.util.Arrays) org.eclipse.jface.action(org.eclipse.jface.action) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) org.jkiss.dbeaver.ui(org.jkiss.dbeaver.ui) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) IWorkbenchCommandConstants(org.eclipse.ui.IWorkbenchCommandConstants) NavigatorCommands(org.jkiss.dbeaver.ui.navigator.NavigatorCommands) PropertyEditorUtils(org.jkiss.dbeaver.ui.properties.PropertyEditorUtils) ArrayList(java.util.ArrayList) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) DBNUtils(org.jkiss.dbeaver.model.navigator.DBNUtils) Composite(org.eclipse.swt.widgets.Composite) NavigatorHandlerFilterConfig(org.jkiss.dbeaver.ui.navigator.actions.NavigatorHandlerFilterConfig) Log(org.jkiss.dbeaver.Log) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) ObjectPropertyDescriptor(org.jkiss.dbeaver.runtime.properties.ObjectPropertyDescriptor) Font(org.eclipse.swt.graphics.Font) DBPObjectStatisticsCollector(org.jkiss.dbeaver.model.DBPObjectStatisticsCollector) DBUtils(org.jkiss.dbeaver.model.DBUtils) IWorkbenchSite(org.eclipse.ui.IWorkbenchSite) Collection(java.util.Collection) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) ArrayUtils(org.jkiss.utils.ArrayUtils) org.eclipse.jface.viewers(org.eclipse.jface.viewers) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) UINavigatorMessages(org.jkiss.dbeaver.ui.internal.UINavigatorMessages) InvocationTargetException(java.lang.reflect.InvocationTargetException) MultiPageEditorSite(org.eclipse.ui.part.MultiPageEditorSite) List(java.util.List) Color(org.eclipse.swt.graphics.Color) SWT(org.eclipse.swt.SWT) DatabaseEditorUtils(org.jkiss.dbeaver.ui.editors.DatabaseEditorUtils) DBXTreeNode(org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode) NavigatorHandlerObjectCreateNew(org.jkiss.dbeaver.ui.navigator.actions.NavigatorHandlerObjectCreateNew) DBEObjectReorderer(org.jkiss.dbeaver.model.edit.DBEObjectReorderer) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) DBXTreeNode(org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode) DBEObjectReorderer(org.jkiss.dbeaver.model.edit.DBEObjectReorderer) ArrayList(java.util.ArrayList) List(java.util.List) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) MultiPageEditorSite(org.eclipse.ui.part.MultiPageEditorSite)

Aggregations

DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)222 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)85 DBException (org.jkiss.dbeaver.DBException)83 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)81 InvocationTargetException (java.lang.reflect.InvocationTargetException)53 ArrayList (java.util.ArrayList)44 GridData (org.eclipse.swt.layout.GridData)36 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)29 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)28 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)27 DBNModel (org.jkiss.dbeaver.model.navigator.DBNModel)26 ISelection (org.eclipse.jface.viewers.ISelection)21 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)21 DBNDatabaseFolder (org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)19 Collection (java.util.Collection)18 List (java.util.List)17 Composite (org.eclipse.swt.widgets.Composite)17 DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)17 DBXTreeNode (org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode)17 SWT (org.eclipse.swt.SWT)15