Search in sources :

Example 66 with DBNDatabaseNode

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode 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) {
        DBWorkbench.getPlatformUI().showError("Just one object selected", "At least two objects must be selected to perform structure 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) {
                DBWorkbench.getPlatformUI().showError("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 67 with DBNDatabaseNode

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

the class CompareObjectsPageSettings method createControl.

@Override
public void createControl(Composite parent) {
    initializeDialogUnits(parent);
    Composite composite = new Composite(parent, SWT.NULL);
    GridLayout gl = new GridLayout();
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    composite.setLayout(gl);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    final CompareObjectsSettings settings = getWizard().getSettings();
    {
        Group sourceSettings = new Group(composite, SWT.NONE);
        sourceSettings.setText("Objects");
        gl = new GridLayout(1, false);
        sourceSettings.setLayout(gl);
        sourceSettings.setLayoutData(new GridData(GridData.FILL_BOTH));
        nodesTable = new Table(sourceSettings, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
        nodesTable.setLayoutData(new GridData(GridData.FILL_BOTH));
        nodesTable.setHeaderVisible(true);
        UIUtils.createTableColumn(nodesTable, SWT.LEFT, "Name");
        UIUtils.createTableColumn(nodesTable, SWT.LEFT, "Type");
        UIUtils.createTableColumn(nodesTable, SWT.LEFT, "Full qualified name");
        for (DBNDatabaseNode node : settings.getNodes()) {
            TableItem item = new TableItem(nodesTable, SWT.NONE);
            item.setImage(DBeaverIcons.getImage(node.getNodeIconDefault()));
            item.setText(0, node.getNodeName());
            item.setText(1, node.getNodeType());
            item.setText(2, node.getNodeFullName());
        }
    }
    {
        Group compareSettings = new Group(composite, SWT.NONE);
        compareSettings.setText("Compare settings");
        compareSettings.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        compareSettings.setLayout(new GridLayout(1, false));
        skipSystemObjects = UIUtils.createCheckbox(compareSettings, "Skip system objects", settings.isSkipSystemObjects());
        skipSystemObjects.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                settings.setSkipSystemObjects(skipSystemObjects.getSelection());
            }
        });
        compareLazyProperties = UIUtils.createCheckbox(compareSettings, "Compare expensive properties", settings.isCompareLazyProperties());
        compareLazyProperties.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                settings.setCompareLazyProperties(compareLazyProperties.getSelection());
            }
        });
        compareOnlyStructure = UIUtils.createCheckbox(compareSettings, "Compare only structure (ignore properties)", settings.isCompareOnlyStructure());
        compareOnlyStructure.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                settings.setCompareOnlyStructure(compareOnlyStructure.getSelection());
            }
        });
        compareScriptProperties = UIUtils.createCheckbox(compareSettings, "Compare scripts/procedures", settings.isCompareScripts());
        compareScriptProperties.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                settings.setCompareScripts(compareScriptProperties.getSelection());
            }
        });
    }
    setControl(composite);
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) CompareObjectsSettings(org.jkiss.dbeaver.tools.compare.simple.CompareObjectsSettings) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 68 with DBNDatabaseNode

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

the class DebugUtils method getSourceName.

public static String getSourceName(Object object) throws CoreException {
    if (object instanceof DatabaseStackFrame) {
        DatabaseStackFrame frame = (DatabaseStackFrame) object;
        Object sourceIdentifier = frame.getSourceIdentifier();
        DBSObject dbsObject;
        try {
            dbsObject = findDatabaseObject(frame.getController(), sourceIdentifier, new VoidProgressMonitor());
        } catch (DBException e) {
            Status error = DebugUtils.newErrorStatus(e.getMessage(), e);
            throw new CoreException(error);
        }
        if (dbsObject == null) {
            return null;
        }
        final DBNModel navigatorModel = DBWorkbench.getPlatform().getNavigatorModel();
        DBNDatabaseNode node = navigatorModel.getNodeByObject(new VoidProgressMonitor(), dbsObject, false);
        if (node != null) {
            return node.getNodeItemPath();
        }
    }
    if (object instanceof String) {
        // well, let's be positive and assume it's a node path already
        return (String) object;
    }
    return null;
}
Also used : DatabaseStackFrame(org.jkiss.dbeaver.debug.core.model.DatabaseStackFrame) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBException(org.jkiss.dbeaver.DBException) CoreException(org.eclipse.core.runtime.CoreException) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel)

Example 69 with DBNDatabaseNode

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

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);
        UIUtils.run(getContainer(), true, true, creator);
        DBPResourceHandler handler = DBWorkbench.getPlatform().getWorkspace().getResourceHandler(creator.diagramFile);
        if (handler != null) {
            handler.openResource(creator.diagramFile);
        }
    } catch (InterruptedException ex) {
        return false;
    } catch (Throwable ex) {
        if (ex instanceof InvocationTargetException) {
            ex = ((InvocationTargetException) ex).getTargetException();
        }
        DBWorkbench.getPlatformUI().showError("Create error", "Cannot create diagram", ex);
        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) DBPResourceHandler(org.jkiss.dbeaver.model.app.DBPResourceHandler) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 70 with DBNDatabaseNode

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

the class PostgreDebugPanelFunction method createFunctionGroup.

private void createFunctionGroup(Composite parent) {
    Group functionGroup = UIUtils.createControlGroup(parent, "Function", 2, GridData.VERTICAL_ALIGN_BEGINNING, SWT.DEFAULT);
    UIUtils.createControlLabel(functionGroup, "Function");
    functionCombo = new CSmartSelector<PostgreProcedure>(functionGroup, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY, new LabelProvider() {

        @Override
        public Image getImage(Object element) {
            return DBeaverIcons.getImage(DBIcon.TREE_PROCEDURE);
        }

        @Override
        public String getText(Object element) {
            if (element == null) {
                return "N/A";
            }
            return ((PostgreProcedure) element).getFullQualifiedSignature();
        }
    }) {

        @Override
        protected void dropDown(boolean drop) {
            if (drop) {
                DBNModel navigatorModel = DBWorkbench.getPlatform().getNavigatorModel();
                DBNDatabaseNode dsNode = navigatorModel.getNodeByObject(container.getDataSource());
                if (dsNode != null) {
                    DBNNode curNode = selectedFunction == null ? null : navigatorModel.getNodeByObject(selectedFunction);
                    DBNNode node = DBWorkbench.getPlatformUI().selectObject(parent.getShell(), "Select function to debug", dsNode, curNode, new Class[] { DBSInstance.class, DBSObjectContainer.class, PostgreProcedure.class }, new Class[] { PostgreProcedure.class }, null);
                    if (node instanceof DBNDatabaseNode && ((DBNDatabaseNode) node).getObject() instanceof PostgreProcedure) {
                        functionCombo.removeAll();
                        selectedFunction = (PostgreProcedure) ((DBNDatabaseNode) node).getObject();
                        functionCombo.addItem(selectedFunction);
                        functionCombo.select(selectedFunction);
                        updateParametersTable();
                        container.updateDialogState();
                    }
                    parametersTable.setEnabled(selectedFunction != null);
                }
            }
        }
    };
    functionCombo.addItem(null);
    GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.widthHint = UIUtils.getFontHeight(functionCombo) * 40 + 10;
    functionCombo.setLayoutData(gd);
    processIdText = UIUtils.createLabelText(functionGroup, "Process ID", "", SWT.BORDER, new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.widthHint = UIUtils.getFontHeight(processIdText) * 10 + 10;
    processIdText.setLayoutData(gd);
}
Also used : DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBSInstance(org.jkiss.dbeaver.model.struct.DBSInstance) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel) PostgreProcedure(org.jkiss.dbeaver.ext.postgresql.model.PostgreProcedure) DBSObjectContainer(org.jkiss.dbeaver.model.struct.DBSObjectContainer) GridData(org.eclipse.swt.layout.GridData) LabelProvider(org.eclipse.jface.viewers.LabelProvider) 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