Search in sources :

Example 6 with DBNDatabaseFolder

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

the class EntityEditor method createPathRow.

private void createPathRow(ToolBar infoGroup, final DBNDatabaseNode databaseNode) {
    final DBNDatabaseNode curNode = getEditorInput().getNavigatorNode();
    final ToolItem item = new ToolItem(infoGroup, databaseNode instanceof DBNDatabaseFolder ? SWT.DROP_DOWN : SWT.PUSH);
    item.setText(databaseNode.getNodeName());
    item.setImage(DBeaverIcons.getImage(databaseNode.getNodeIconDefault()));
    if (databaseNode == curNode) {
        item.setToolTipText(databaseNode.getNodeType());
        item.setEnabled(false);
    } else {
        item.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                if (e.detail == SWT.ARROW) {
                    int itemCount = 0;
                    if (breadcrumbsMenu != null) {
                        breadcrumbsMenu.dispose();
                    }
                    breadcrumbsMenu = new Menu(item.getParent().getShell());
                    try {
                        final DBNNode[] childNodes = NavigatorUtils.getNodeChildrenFiltered(VoidProgressMonitor.INSTANCE, databaseNode, false);
                        if (!ArrayUtils.isEmpty(childNodes)) {
                            for (final DBNNode folderItem : childNodes) {
                                MenuItem childItem = new MenuItem(breadcrumbsMenu, SWT.NONE);
                                childItem.setText(folderItem.getName());
                                //                                childItem.setImage(DBeaverIcons.getImage(folderItem.getNodeIconDefault()));
                                if (folderItem == curNode) {
                                    childItem.setEnabled(false);
                                }
                                childItem.addSelectionListener(new SelectionAdapter() {

                                    @Override
                                    public void widgetSelected(SelectionEvent e) {
                                        NavigatorHandlerObjectOpen.openEntityEditor(folderItem, null, PlatformUI.getWorkbench().getActiveWorkbenchWindow());
                                    }
                                });
                                itemCount++;
                                if (itemCount >= MAX_BREADCRUMBS_MENU_ITEM) {
                                    break;
                                }
                            }
                        }
                    } catch (Throwable e1) {
                        log.error(e1);
                    }
                    Rectangle rect = item.getBounds();
                    Point pt = item.getParent().toDisplay(new Point(rect.x, rect.y));
                    breadcrumbsMenu.setLocation(pt.x, pt.y + rect.height);
                    breadcrumbsMenu.setVisible(true);
                } else {
                    NavigatorHandlerObjectOpen.openEntityEditor(databaseNode, null, PlatformUI.getWorkbench().getActiveWorkbenchWindow());
                }
            }
        });
        item.setToolTipText("Open " + databaseNode.getNodeType() + " Editor");
    }
}
Also used : DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)

Example 7 with DBNDatabaseFolder

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

the class CompareObjectsHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (!(selection instanceof IStructuredSelection)) {
        return null;
    }
    IStructuredSelection ss = (IStructuredSelection) selection;
    if (ss.size() < 2) {
        log.error("At least 2 objects must be selected to perform compare");
        return null;
    }
    List<DBNDatabaseNode> nodes = new ArrayList<>();
    Class<?> firstType = null;
    DBXTreeNode firstMeta = null;
    for (Iterator<?> iter = ss.iterator(); iter.hasNext(); ) {
        DBNDatabaseNode node = (DBNDatabaseNode) iter.next();
        DBXTreeNode meta = null;
        if (node instanceof DBNDatabaseFolder) {
            meta = node.getMeta();
            if (firstMeta == null) {
                firstMeta = meta;
            }
        }
        if (node.getObject() == null) {
            log.error("Bad node with null object");
            return null;
        }
        Class<?> itemType = node.getObject().getClass();
        if (firstType == null) {
            firstType = itemType;
        } else {
            if (firstType != itemType || firstMeta != meta) {
                UIUtils.showErrorDialog(null, "Different object types", "Objects of different types were selected. You may compare only objects of the same type");
                return null;
            }
        }
        nodes.add(node);
    }
    CompareWizardDialog dialog = new CompareWizardDialog(workbenchWindow, new CompareObjectsWizard(nodes));
    dialog.open();
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DBXTreeNode(org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode) ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)

Example 8 with DBNDatabaseFolder

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

the class CompareReportRenderer method renderBody.

private void renderBody(DBRProgressMonitor monitor) throws IOException {
    // Table head
    xml.startElement("tr");
    xml.startElement("th");
    xml.addText("Structure");
    xml.endElement();
    for (DBNDatabaseNode node : report.getNodes()) {
        xml.startElement("th");
        xml.addText(node.getNodeFullName());
        xml.endElement();
    }
    xml.endElement();
    // Table body
    boolean showOnlyDifferences = settings.isShowOnlyDifferences();
    int objectCount = report.getNodes().size();
    List<CompareReportLine> reportLines = report.getReportLines();
    int reportLinesSize = reportLines.size();
    for (int i = 0; i < reportLinesSize; i++) {
        monitor.worked(1);
        CompareReportLine line = reportLines.get(i);
        if (showOnlyDifferences && !line.hasDifference) {
            continue;
        }
        boolean onlyStructure = line.structure instanceof DBNDatabaseFolder && !line.hasDifference;
        // Skip empty folders
        if (onlyStructure && (i >= reportLinesSize - 1 || reportLines.get(i + 1).depth <= line.depth)) {
            continue;
        }
        xml.startElement("tr");
        xml.addAttribute("class", "object level" + line.depth);
        xml.startElement("td");
        xml.addText(line.structure.getNodeType());
        xml.endElement();
        if (onlyStructure) {
            xml.startElement("td");
            xml.addAttribute("colspan", line.nodes.length);
            xml.addText("&nbsp;", false);
            xml.endElement();
        } else {
            for (int k = 0; k < objectCount; k++) {
                xml.startElement("td");
                if (line.nodes[k] == null) {
                    xml.addAttribute("class", "missing");
                    xml.addText("N/A");
                } else {
                    xml.addText(line.nodes[k].getName());
                }
                xml.endElement();
            }
        }
        xml.endElement();
        if (line.properties != null) {
            for (CompareReportProperty reportProperty : line.properties) {
                boolean differs = false;
                Object firstValue = null;
                boolean hasValue = false;
                for (int k = 0; k < reportProperty.values.length; k++) {
                    if (line.nodes[k] == null) {
                        // Ignore properties of missing objects
                        continue;
                    }
                    Object value = reportProperty.values[k];
                    if (value != null) {
                        hasValue = true;
                        if (firstValue == null) {
                            firstValue = value;
                        }
                    }
                    if (!CompareUtils.equalPropertyValues(value, firstValue)) {
                        differs = true;
                        break;
                    }
                }
                if (!hasValue) {
                    // Skip[ properties when nobody have it's value
                    continue;
                }
                if (showOnlyDifferences && !differs) {
                    continue;
                }
                xml.startElement("tr");
                xml.addAttribute("class", "property level" + (line.depth + 1) + (differs ? " differs" : ""));
                xml.startElement("td");
                xml.addText(reportProperty.property.getDisplayName());
                xml.endElement();
                for (int k = 0; k < objectCount; k++) {
                    xml.startElement("td");
                    String stringValue = "";
                    if (reportProperty.values[k] != null) {
                        stringValue = reportProperty.values[k].toString();
                    }
                    if (CommonUtils.isEmpty(stringValue)) {
                        xml.addText("&nbsp;", false);
                    } else {
                        xml.addText(stringValue);
                    }
                    xml.endElement();
                }
                xml.endElement();
            }
        }
    }
    // Table footer
    xml.startElement("tr");
    xml.addAttribute("class", "object");
    xml.startElement("td");
    xml.addAttribute("colspan", report.getNodes().size() + 1);
    xml.addText("" + reportLines.size() + " objects compared");
    xml.endElement();
    xml.endElement();
}
Also used : DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)

Aggregations

DBNDatabaseFolder (org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)8 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)5 ISelection (org.eclipse.jface.viewers.ISelection)4 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)4 DBNDatabaseItem (org.jkiss.dbeaver.model.navigator.DBNDatabaseItem)3 DBXTreeItem (org.jkiss.dbeaver.model.navigator.meta.DBXTreeItem)3 DBSObjectFilter (org.jkiss.dbeaver.model.struct.DBSObjectFilter)3 ArrayList (java.util.ArrayList)1 Action (org.eclipse.jface.action.Action)1 Separator (org.eclipse.jface.action.Separator)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Point (org.eclipse.swt.graphics.Point)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 IWorkbenchSite (org.eclipse.ui.IWorkbenchSite)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 MultiPageEditorPart (org.eclipse.ui.part.MultiPageEditorPart)1 MultiPageEditorSite (org.eclipse.ui.part.MultiPageEditorSite)1 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)1