Search in sources :

Example 46 with DBNDatabaseNode

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

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)

Example 47 with DBNDatabaseNode

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

the class NavigatorHandlerCopyAbstract method copySelection.

private void copySelection(IWorkbenchWindow workbenchWindow, IWorkbenchPart activePart, ISelection selection) {
    ClipboardData clipboardData = new ClipboardData();
    {
        IClipboardSource clipboardSource = activePart.getAdapter(IClipboardSource.class);
        if (clipboardSource != null) {
            clipboardSource.addClipboardData(getCopyMode(), clipboardData);
        }
    }
    if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
        final IStructuredSelection structSelection = (IStructuredSelection) selection;
        List<DBNNode> selectedNodes = new ArrayList<>();
        List<DBPNamedObject> selectedObjects = new ArrayList<>();
        List<String> selectedFiles = new ArrayList<>();
        StringBuilder buf = new StringBuilder();
        for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
            Object object = iter.next();
            String objectValue = getObjectDisplayString(object);
            if (objectValue == null) {
                continue;
            }
            DBNNode node = RuntimeUtils.getObjectAdapter(object, DBNNode.class);
            DBPNamedObject dbObject = null;
            if (node instanceof DBNDatabaseNode) {
                dbObject = ((DBNDatabaseNode) node).getObject();
            }
            if (dbObject == null) {
                dbObject = RuntimeUtils.getObjectAdapter(object, DBPNamedObject.class);
            }
            if (node != null) {
                selectedNodes.add(node);
            }
            if (node instanceof DBNResource && ((DBNResource) node).getResource() instanceof IFile) {
                final IFile file = (IFile) ((DBNResource) node).getResource();
                if (file != null) {
                    selectedFiles.add(file.getLocation().makeAbsolute().toFile().getAbsolutePath());
                }
            }
            if (dbObject != null) {
                selectedObjects.add(dbObject);
            }
            if (buf.length() > 0) {
                buf.append(GeneralUtils.getDefaultLineSeparator());
            }
            buf.append(objectValue);
        }
        {
            if (buf.length() > 0 && !clipboardData.hasTransfer(TextTransfer.getInstance())) {
                clipboardData.addTransfer(TextTransfer.getInstance(), buf.toString());
            }
            if (!selectedNodes.isEmpty() && !clipboardData.hasTransfer(TreeNodeTransfer.getInstance())) {
                clipboardData.addTransfer(TreeNodeTransfer.getInstance(), selectedNodes);
            }
            if (!selectedObjects.isEmpty() && !clipboardData.hasTransfer(DatabaseObjectTransfer.getInstance())) {
                clipboardData.addTransfer(DatabaseObjectTransfer.getInstance(), selectedObjects);
            }
            if (!selectedFiles.isEmpty() && !clipboardData.hasTransfer(FileTransfer.getInstance())) {
                clipboardData.addTransfer(FileTransfer.getInstance(), selectedFiles.toArray(new String[selectedFiles.size()]));
            }
        }
    }
    if (clipboardData.hasData()) {
        clipboardData.pushToClipboard(workbenchWindow.getShell().getDisplay());
    // ObjectPropertyTester.firePropertyChange(ObjectPropertyTester.PROP_CAN_PASTE);
    }
}
Also used : IClipboardSource(org.jkiss.dbeaver.ui.IClipboardSource) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) IFile(org.eclipse.core.resources.IFile) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ClipboardData(org.jkiss.dbeaver.ui.ClipboardData) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 48 with DBNDatabaseNode

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

the class NavigatorHandlerObjectMove method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    DBNNode node = NavigatorUtils.getSelectedNode(selection);
    if (node == null || !(node.getParentNode() instanceof DBNContainer)) {
        return null;
    }
    DBSObject object = ((DBNDatabaseNode) node).getObject();
    if (!(object instanceof DBPOrderedObject)) {
        return null;
    }
    @SuppressWarnings("unchecked") DBEObjectReorderer<DBSObject> objectReorderer = DBWorkbench.getPlatform().getEditorsRegistry().getObjectManager(object.getClass(), DBEObjectReorderer.class);
    if (objectReorderer == null) {
        return null;
    }
    DBPOrderedObject orderedObject = (DBPOrderedObject) object;
    try {
        // Sibling objects - they are involved in reordering process
        List<DBSObject> siblingObjects = new ArrayList<>();
        for (DBNNode siblingNode : node.getParentNode().getChildren(new VoidProgressMonitor())) {
            if (siblingNode instanceof DBNDatabaseNode) {
                DBSObject siblingObject = ((DBNDatabaseNode) siblingNode).getObject();
                if (siblingObject.getClass() != object.getClass()) {
                    log.warn("Sibling object class " + siblingObject.getClass() + " differs from moving object class " + object.getClass().getName());
                } else {
                    siblingObjects.add(siblingObject);
                }
            } else {
                log.warn("Wrong sibling node type: " + siblingNode);
            }
        }
        CommandTarget commandTarget = getCommandTarget(HandlerUtil.getActiveWorkbenchWindow(event), node.getParentNode(), object.getClass(), false);
        String actionId = event.getCommand().getId();
        switch(actionId) {
            case NavigatorCommands.CMD_OBJECT_MOVE_UP:
                objectReorderer.setObjectOrdinalPosition(commandTarget.getContext(), object, siblingObjects, orderedObject.getOrdinalPosition() - 1);
                break;
            case NavigatorCommands.CMD_OBJECT_MOVE_DOWN:
                objectReorderer.setObjectOrdinalPosition(commandTarget.getContext(), object, siblingObjects, orderedObject.getOrdinalPosition() + 1);
                break;
        }
        if (object.isPersisted() && commandTarget.getEditor() == null) {
            Map<String, Object> options = DBPScriptObject.EMPTY_OPTIONS;
            if (!showScript(HandlerUtil.getActiveWorkbenchWindow(event), commandTarget.getContext(), options, "Reorder script")) {
                commandTarget.getContext().resetChanges(true);
                return false;
            } else {
                ObjectSaver orderer = new ObjectSaver(commandTarget.getContext(), options);
                TasksJob.runTask("Change object '" + object.getName() + "' position", orderer);
            }
        }
    } catch (DBException e) {
        DBWorkbench.getPlatformUI().showError("Object move", "Error during object reposition", e);
    }
    return null;
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBPOrderedObject(org.jkiss.dbeaver.model.DBPOrderedObject) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBNContainer(org.jkiss.dbeaver.model.navigator.DBNContainer) ArrayList(java.util.ArrayList) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ISelection(org.eclipse.jface.viewers.ISelection) DBPOrderedObject(org.jkiss.dbeaver.model.DBPOrderedObject) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPScriptObject(org.jkiss.dbeaver.model.DBPScriptObject) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 49 with DBNDatabaseNode

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

the class NNAHDataSourceReadOnly method handleNodeAction.

@Override
public void handleNodeAction(INavigatorModelView view, DBNNode node, Event event, boolean defaultAction) {
    if (node instanceof DBNDatabaseNode) {
        DBPDataSourceContainer dataSourceContainer = ((DBNDatabaseNode) node).getDataSourceContainer();
        UIServiceConnections serviceConnections = DBWorkbench.getService(UIServiceConnections.class);
        if (serviceConnections != null) {
            serviceConnections.openConnectionEditor(dataSourceContainer, "ConnectionPageGeneral");
        }
    }
}
Also used : DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) UIServiceConnections(org.jkiss.dbeaver.runtime.ui.UIServiceConnections)

Example 50 with DBNDatabaseNode

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

the class EntityAddCommand method execute.

@Override
public void execute() {
    VoidProgressMonitor monitor = new VoidProgressMonitor();
    Point curLocation = location == null ? null : new Point(location);
    for (ERDEntity entity : entities) {
        boolean resolveRelations = false;
        if (entity.getObject() == null) {
            // Entity is not initialized
            if (entity.getDataSource() != null) {
                DBSObject selectedObject = DBUtils.getSelectedObject(DBUtils.getDefaultContext(entity.getDataSource(), false));
                DBNDatabaseNode dsNode = DBNUtils.getNodeByObject(selectedObject != null ? selectedObject : entity.getDataSource().getContainer());
                if (dsNode != null) {
                    DBNNode tableNode = DBWorkbench.getPlatformUI().selectObject(UIUtils.getActiveWorkbenchShell(), "Select a table", dsNode, null, new Class[] { DBSTable.class }, new Class[] { DBSTable.class }, null);
                    if (tableNode instanceof DBNDatabaseNode && ((DBNDatabaseNode) tableNode).getObject() instanceof DBSEntity) {
                        entity = ERDUtils.makeEntityFromObject(monitor, diagramPart.getDiagram(), Collections.emptyList(), (DBSEntity) ((DBNDatabaseNode) tableNode).getObject(), null);
                        // This actually only loads unresolved relations.
                        // This happens only with entities added on diagram during editing
                        entity.addModelRelations(monitor, diagramPart.getDiagram(), false, false);
                    }
                }
            }
        }
        if (entity.getObject() == null) {
            continue;
        }
        diagramPart.getDiagram().addEntity(entity, true);
        if (curLocation != null) {
            // Put new entities in specified location
            for (Object diagramChild : diagramPart.getChildren()) {
                if (diagramChild instanceof EntityPart) {
                    EntityPart entityPart = (EntityPart) diagramChild;
                    if (entityPart.getEntity() == entity) {
                        final Rectangle newBounds = new Rectangle();
                        final Dimension size = entityPart.getFigure().getPreferredSize();
                        newBounds.x = curLocation.x;
                        newBounds.y = curLocation.y;
                        newBounds.width = size.width;
                        newBounds.height = size.height;
                        entityPart.modifyBounds(newBounds);
                        curLocation.x += size.width + (size.width / 2);
                        break;
                    }
                }
            }
        }
        handleEntityChange(entity, false);
    }
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ERDEntity(org.jkiss.dbeaver.erd.model.ERDEntity) Rectangle(org.eclipse.draw2d.geometry.Rectangle) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) Point(org.eclipse.draw2d.geometry.Point) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) Dimension(org.eclipse.draw2d.geometry.Dimension) EntityPart(org.jkiss.dbeaver.erd.ui.part.EntityPart) 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