Search in sources :

Example 1 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 = getWizard().getPageSettings(this, DatabaseConsumerSettings.class);
    settings.loadNode(getContainer());
    DBNDatabaseNode containerNode = settings.getContainerNode();
    if (containerNode != null) {
        containerIcon.setImage(DBeaverIcons.getImage(containerNode.getNodeIconDefault()));
        containerName.setText(containerNode.getNodeFullName());
    }
    if (mappingViewer.getInput() == null) {
        Map<DBSDataContainer, DatabaseMappingContainer> dataMappings = settings.getDataMappings();
        for (DataTransferPipe pipe : getWizard().getSettings().getDataPipes()) {
            if (pipe.getProducer() == null) {
                continue;
            }
            DBSDataContainer sourceObject = (DBSDataContainer) pipe.getProducer().getSourceObject();
            if (!dataMappings.containsKey(sourceObject)) {
                DatabaseMappingContainer mapping;
                if (pipe.getConsumer() instanceof DatabaseTransferConsumer && ((DatabaseTransferConsumer) pipe.getConsumer()).getTargetObject() != null) {
                    try {
                        mapping = new DatabaseMappingContainer(getContainer(), sourceObject, ((DatabaseTransferConsumer) pipe.getConsumer()).getTargetObject());
                    } catch (DBException e) {
                        setMessage(e.getMessage(), IMessageProvider.ERROR);
                        mapping = new DatabaseMappingContainer(sourceObject);
                    }
                } else {
                    mapping = new DatabaseMappingContainer(sourceObject);
                }
                dataMappings.put(sourceObject, mapping);
            }
        }
        List<DatabaseMappingContainer> model = new ArrayList<>(dataMappings.values());
        mappingViewer.setInput(model);
        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) ArrayList(java.util.ArrayList) DataTransferPipe(org.jkiss.dbeaver.tools.transfer.wizard.DataTransferPipe) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 2 with DBNDatabaseNode

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

the class DataImportHandler method chooseProducer.

@Override
protected IDataTransferProducer chooseProducer(ExecutionEvent event, IDataTransferConsumer consumer) {
    final DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel();
    final DBNNode rootNode = DBeaverCore.getInstance().getLiveProjects().size() == 1 ? navigatorModel.getRoot().getProject(DBeaverCore.getInstance().getProjectRegistry().getActiveProject()) : navigatorModel.getRoot();
    DBNNode node = BrowseObjectDialog.selectObject(HandlerUtil.getActiveShell(event), "Select source container for '" + consumer.getTargetName() + "'", rootNode, null, new Class[] { DBSObjectContainer.class, DBSDataContainer.class }, new Class[] { DBSDataContainer.class });
    if (node instanceof DBNDatabaseNode) {
        DBSObject object = ((DBNDatabaseNode) node).getObject();
        if (object instanceof DBSDataContainer) {
            return new DatabaseTransferProducer((DBSDataContainer) object);
        }
    }
    return null;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DatabaseTransferProducer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel)

Example 3 with DBNDatabaseNode

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

the class CompareObjectsExecutor method compareChildren.

private void compareChildren(DBRProgressMonitor monitor, List<DBNDatabaseNode> nodes) throws DBException, InterruptedException {
    // Compare children
    int nodeCount = nodes.size();
    List<DBNDatabaseNode[]> allChildren = new ArrayList<>(nodeCount);
    for (int i = 0; i < nodeCount; i++) {
        DBNDatabaseNode node = nodes.get(i);
        // Cache structure if possible
        if (node.getObject() instanceof DBSObjectContainer) {
            ((DBSObjectContainer) node.getObject()).cacheStructure(monitor, DBSObjectContainer.STRUCT_ALL);
        }
        try {
            DBNDatabaseNode[] children = node.getChildren(monitor);
            allChildren.add(children);
        } catch (Exception e) {
            log.warn("Error reading child nodes for compare", e);
            allChildren.add(null);
        }
    }
    Set<String> allChildNames = new LinkedHashSet<>();
    for (DBNDatabaseNode[] childList : allChildren) {
        if (childList == null)
            continue;
        for (DBNDatabaseNode child : childList) {
            DBXTreeNode meta = child.getMeta();
            if (meta.isVirtual()) {
                // Skip virtual nodes
                continue;
            }
            if (settings.isSkipSystemObjects() && child.getObject() instanceof DBPSystemObject && ((DBPSystemObject) child.getObject()).isSystem()) {
                // Skip system objects
                continue;
            }
            allChildNames.add(child.getNodeName());
        }
    }
    for (String childName : allChildNames) {
        int[] childIndexes = new int[nodeCount];
        for (int i = 0; i < nodeCount; i++) {
            childIndexes[i] = -1;
            DBNDatabaseNode[] childList = allChildren.get(i);
            if (childList == null)
                continue;
            for (int k = 0; k < childList.length; k++) {
                DBNDatabaseNode child = childList[k];
                if (child.getNodeName().equals(childName)) {
                    childIndexes[i] = k;
                    break;
                }
            }
        }
        List<DBNDatabaseNode> nodesToCompare = new ArrayList<>(nodeCount);
        for (int i = 0; i < nodeCount; i++) {
            if (childIndexes[i] == -1) {
            // Missing
            } else {
                for (int k = 0; k < nodeCount; k++) {
                    if (k != i && childIndexes[k] != childIndexes[i]) {
                        // Wrong index - add to report
                        break;
                    }
                }
                final DBNDatabaseNode[] childList = allChildren.get(i);
                if (childList != null) {
                    nodesToCompare.add(childList[childIndexes[i]]);
                }
            }
        }
        // Compare children recursively
        compareNodes(monitor, nodesToCompare);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBXTreeNode(org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode) DBSObjectContainer(org.jkiss.dbeaver.model.struct.DBSObjectContainer) DBPSystemObject(org.jkiss.dbeaver.model.DBPSystemObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 4 with DBNDatabaseNode

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

the class CompareObjectsWizard method renderReport.

private void renderReport(DBRProgressMonitor monitor, CompareReport report) {
    try {
        File reportFile;
        switch(settings.getOutputType()) {
            case BROWSER:
                reportFile = File.createTempFile("compare-report", ".html");
                break;
            default:
                {
                    //"compare-report.html";
                    StringBuilder fileName = new StringBuilder("compare");
                    for (DBNDatabaseNode node : report.getNodes()) {
                        fileName.append("-").append(CommonUtils.escapeIdentifier(node.getName()));
                    }
                    fileName.append("-report.html");
                    reportFile = new File(settings.getOutputFolder(), fileName.toString());
                    break;
                }
        }
        reportFile.deleteOnExit();
        try (OutputStream outputStream = new FileOutputStream(reportFile)) {
            monitor.beginTask("Render report", report.getReportLines().size());
            CompareReportRenderer reportRenderer = new CompareReportRenderer();
            reportRenderer.renderReport(monitor, report, getSettings(), outputStream);
            monitor.done();
        }
        UIUtils.launchProgram(reportFile.getAbsolutePath());
    } catch (IOException e) {
        showError(e.getMessage());
        log.error(e);
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 5 with DBNDatabaseNode

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

the class NavigatorHandlerRefresh method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    //final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    final IWorkbenchPart workbenchPart = HandlerUtil.getActivePart(event);
    INavigatorModelView navigatorView;
    if (workbenchPart instanceof INavigatorModelView) {
        navigatorView = (INavigatorModelView) workbenchPart;
    } else {
        navigatorView = workbenchPart.getAdapter(INavigatorModelView.class);
    }
    if (navigatorView == null) {
        // Try to refresh as refreshable part
        if (workbenchPart instanceof IRefreshablePart) {
            ((IRefreshablePart) workbenchPart).refreshPart(this, true);
        }
        return null;
    }
    final List<DBNNode> refreshObjects = new ArrayList<>();
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    DBNNode rootNode = navigatorView.getRootNode();
    if (rootNode == null) {
        if (workbenchPart instanceof IEditorPart) {
            if (((IEditorPart) workbenchPart).getEditorInput() instanceof IDatabaseEditorInput) {
                rootNode = ((IDatabaseEditorInput) ((IEditorPart) workbenchPart).getEditorInput()).getNavigatorNode();
            }
        }
    }
    if (rootNode != null && rootNode.getParentNode() instanceof DBNDatabaseNode) {
        refreshObjects.add(rootNode);
    } else if (selection instanceof IStructuredSelection) {
        final IStructuredSelection structSelection = (IStructuredSelection) selection;
        for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
            Object object = iter.next();
            if (object instanceof DBNNode) {
                refreshObjects.add((DBNNode) object);
            }
        }
    }
    // Refresh objects
    if (!refreshObjects.isEmpty()) {
        refreshNavigator(refreshObjects);
    }
    return null;
}
Also used : DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) IRefreshablePart(org.jkiss.dbeaver.ui.IRefreshablePart) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) INavigatorModelView(org.jkiss.dbeaver.ui.navigator.INavigatorModelView) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

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