Search in sources :

Example 16 with DBNDatabaseNode

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

the class CheckboxTreeManager method updateCheckStates.

public void updateCheckStates() {
    Set<DBNDatabaseNode> parentList = new LinkedHashSet<>();
    for (Object element : viewer.getCheckedElements()) {
        for (DBNNode node = ((DBNDatabaseNode) element).getParentNode(); node != null; node = node.getParentNode()) {
            if (node instanceof DBNDatabaseNode) {
                parentList.add((DBNDatabaseNode) node);
                viewer.setChecked(node, true);
            }
        }
    }
    updateElementsCheck(parentList.toArray(), true, false);
}
Also used : DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 17 with DBNDatabaseNode

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

the class CheckboxTreeManager method collectChildren.

private boolean collectChildren(DBRProgressMonitor monitor, final Object element, List<DBNDatabaseNode> targetChildren, List<DBNDatabaseNode> targetContainers, boolean onlyChecked) throws DBException {
    if (element instanceof DBNDatabaseNode) {
        for (ViewerFilter filter : filters) {
            if (!filter.select(viewer, ((DBNDatabaseNode) element).getParentNode(), element)) {
                return false;
            }
        }
        boolean isChecked = ArrayUtils.contains(checkedElements, element);
        for (Class<?> type : targetTypes) {
            if (type.isInstance(((DBNDatabaseNode) element).getObject())) {
                if (!onlyChecked || isChecked) {
                    targetChildren.add((DBNDatabaseNode) element);
                }
                return true;
            }
        }
        ((DBNDatabaseNode) element).initializeNode(monitor, null);
        DBNDatabaseNode[] children = ((DBNDatabaseNode) element).getChildren(monitor);
        if (!ArrayUtils.isEmpty(children)) {
            boolean foundChild = false;
            for (DBNDatabaseNode child : children) {
                if (collectChildren(monitor, child, targetChildren, targetContainers, onlyChecked)) {
                    foundChild = true;
                }
            }
            if (foundChild) {
                if (!onlyChecked || isChecked) {
                    targetContainers.add((DBNDatabaseNode) element);
                }
            }
            return foundChild;
        }
    }
    return false;
}
Also used : ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 18 with DBNDatabaseNode

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode 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(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 = DBeaverCore.getInstance().getNavigatorModel().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 = DBeaverCore.getInstance().getNavigatorModel().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 19 with DBNDatabaseNode

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

the class DiagramCreateWizard method performFinish.

@Override
public boolean performFinish() {
    try {
        Collection<DBNNode> initialContent = pageContent.getInitialContent();
        List<DBSObject> rootObjects = new ArrayList<>();
        for (DBNNode node : initialContent) {
            if (node instanceof DBNDatabaseNode) {
                rootObjects.add(((DBNDatabaseNode) node).getObject());
            }
        }
        DiagramCreator creator = new DiagramCreator(rootObjects);
        DBeaverUI.run(getContainer(), true, true, creator);
        NavigatorHandlerObjectOpen.openResource(creator.diagramFile, DBeaverUI.getActiveWorkbenchWindow());
    } catch (InterruptedException ex) {
        return false;
    } catch (InvocationTargetException ex) {
        DBUserInterface.getInstance().showError("Create error", "Cannot create diagram", ex.getTargetException());
        return false;
    }
    return true;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ArrayList(java.util.ArrayList) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 20 with DBNDatabaseNode

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

the class SearchDataQuery method run.

@Override
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
    try {
        String searchString = params.getSearchString();
        // monitor.subTask("Collect tables");
        Set<DBPDataSource> dataSources = new HashSet<>();
        for (DBSDataContainer searcher : params.sources) {
            dataSources.add(searcher.getDataSource());
        }
        // Search
        DBNModel dbnModel = DBeaverCore.getInstance().getNavigatorModel();
        monitor.beginTask("Search \"" + searchString + "\" in " + params.sources.size() + " table(s) / " + dataSources.size() + " database(s)", params.sources.size());
        try {
            for (DBSDataContainer dataContainer : params.sources) {
                if (monitor.isCanceled()) {
                    break;
                }
                String objectName = DBUtils.getObjectFullName(dataContainer, DBPEvaluationContext.DML);
                DBNDatabaseNode node = dbnModel.findNode(dataContainer);
                if (node == null) {
                    log.warn("Can't find tree node for object \"" + objectName + "\"");
                    continue;
                }
                monitor.subTask(objectName);
                DBPDataSource dataSource = dataContainer.getDataSource();
                if (dataSource == null) {
                    log.warn("Object \"" + objectName + "\" not connected");
                    continue;
                }
                SearchTableMonitor searchMonitor = new SearchTableMonitor();
                try (DBCSession session = DBUtils.openUtilSession(searchMonitor, dataSource, "Search rows in " + objectName)) {
                    TestDataReceiver dataReceiver = new TestDataReceiver(searchMonitor);
                    try {
                        findRows(session, dataContainer, dataReceiver);
                    } catch (DBCException e) {
                        // Search failed in some container - just write an error in log.
                        // We don't want to break whole search because of one single table.
                        log.error("Fulltext search failed in '" + dataContainer.getName() + "'", e);
                    }
                    if (dataReceiver.rowCount > 0) {
                        SearchDataObject object = new SearchDataObject(node, dataReceiver.rowCount, dataReceiver.filter);
                        searchResult.addObjects(Collections.singletonList(object));
                    }
                }
                monitor.worked(1);
            }
        } finally {
            monitor.done();
        }
        return Status.OK_STATUS;
    } catch (Exception e) {
        return GeneralUtils.makeExceptionStatus(e);
    }
}
Also used : DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) DBException(org.jkiss.dbeaver.DBException) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Aggregations

DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)165 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)64 DBException (org.jkiss.dbeaver.DBException)60 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)60 InvocationTargetException (java.lang.reflect.InvocationTargetException)38 ArrayList (java.util.ArrayList)29 GridData (org.eclipse.swt.layout.GridData)27 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)21 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)21 DBNModel (org.jkiss.dbeaver.model.navigator.DBNModel)20 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)20 ISelection (org.eclipse.jface.viewers.ISelection)16 DBNDatabaseFolder (org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)15 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)13 SelectionEvent (org.eclipse.swt.events.SelectionEvent)13 DBXTreeNode (org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode)13 Collection (java.util.Collection)12 Composite (org.eclipse.swt.widgets.Composite)12 DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)12 IEditorPart (org.eclipse.ui.IEditorPart)11