Search in sources :

Example 51 with DBSObject

use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.

the class EntityEditor method addContributions.

private void addContributions(String position) {
    EntityEditorsRegistry editorsRegistry = EntityEditorsRegistry.getInstance();
    final DBSObject databaseObject = getEditorInput().getDatabaseObject();
    DBPObject object;
    if (databaseObject instanceof DBPDataSourceContainer && databaseObject.getDataSource() != null) {
        object = databaseObject.getDataSource();
    } else {
        object = databaseObject;
    }
    List<EntityEditorDescriptor> descriptors = editorsRegistry.getEntityEditors(object, position);
    for (EntityEditorDescriptor descriptor : descriptors) {
        if (descriptor.getType() == EntityEditorDescriptor.Type.editor) {
            addEditorTab(descriptor);
        }
    }
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) EntityEditorDescriptor(org.jkiss.dbeaver.registry.editor.EntityEditorDescriptor) EntityEditorsRegistry(org.jkiss.dbeaver.registry.editor.EntityEditorsRegistry)

Example 52 with DBSObject

use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.

the class EditForeignKeyPage method createSchemaSelector.

private void createSchemaSelector(Composite tableGroup) throws DBException {
    // Here is a trick - we need to find schema/catalog container node and list its children
    DBNDatabaseNode schemaContainerNode = null;
    for (DBNNode node = ownerTableNode.getParentNode(); node != null; node = node.getParentNode()) {
        if (node instanceof DBNDatabaseNode) {
            DBSObject nodeObject = ((DBNDatabaseNode) node).getObject();
            if (nodeObject instanceof DBSSchema || nodeObject instanceof DBSCatalog) {
                if (node.getParentNode() instanceof DBNDatabaseNode) {
                    schemaContainerNode = (DBNDatabaseNode) node.getParentNode();
                    break;
                }
            }
        }
    }
    if (schemaContainerNode != null) {
        ILabelProvider labelProvider = new LabelProvider() {

            @Override
            public Image getImage(Object element) {
                return DBeaverIcons.getImage(((DBNDatabaseNode) element).getNodeIcon());
            }

            @Override
            public String getText(Object element) {
                return ((DBNDatabaseNode) element).getNodeName();
            }
        };
        boolean isSchema = (ownTable.getParentObject() instanceof DBSSchema);
        DBPDataSourceInfo dsInfo = ownTable.getDataSource().getInfo();
        UIUtils.createControlLabel(tableGroup, isSchema ? dsInfo.getSchemaTerm() : dsInfo.getCatalogTerm());
        final CSmartCombo<DBNDatabaseNode> schemaCombo = new CSmartCombo<>(tableGroup, SWT.BORDER, labelProvider);
        schemaCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        DBNDatabaseNode selectedNode = null;
        for (DBNNode node : schemaContainerNode.getChildren(VoidProgressMonitor.INSTANCE)) {
            if (node instanceof DBNDatabaseNode && ((DBNDatabaseNode) node).getObject() instanceof DBSObjectContainer) {
                schemaCombo.addItem((DBNDatabaseNode) node);
                if (((DBNDatabaseNode) node).getObject() == ownTable.getParentObject()) {
                    selectedNode = (DBNDatabaseNode) node;
                }
            }
        }
        if (selectedNode != null) {
            schemaCombo.select(selectedNode);
        }
        schemaCombo.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                // Here is another trick
                // We need to find table container node
                // This node is a child of schema node and has the same meta as our original table parent node
                DBNDatabaseNode newContainerNode = null;
                DBXTreeNode tableContainerMeta = ((DBNDatabaseNode) ownerTableNode.getParentNode()).getMeta();
                DBNDatabaseNode schemaNode = schemaCombo.getSelectedItem();
                if (schemaNode.getMeta() == tableContainerMeta) {
                    newContainerNode = schemaNode;
                } else {
                    try {
                        for (DBNNode child : schemaNode.getChildren(VoidProgressMonitor.INSTANCE)) {
                            if (child instanceof DBNDatabaseNode && ((DBNDatabaseNode) child).getMeta() == tableContainerMeta) {
                                newContainerNode = (DBNDatabaseNode) child;
                                break;
                            }
                        }
                    } catch (DBException e1) {
                        log.debug(e1);
                    // Shouldn't be here
                    }
                }
                if (newContainerNode != null) {
                    tableList.setRootNode(newContainerNode);
                    tableList.loadData();
                }
            }
        });
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBXTreeNode(org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode) CSmartCombo(org.jkiss.dbeaver.ui.controls.CSmartCombo) GridData(org.eclipse.swt.layout.GridData) DBSObjectContainer(org.jkiss.dbeaver.model.struct.DBSObjectContainer) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 53 with DBSObject

use of org.jkiss.dbeaver.model.struct.DBSObject 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);
        DBeaverUI.run(getContainer(), true, true, creator);
        NavigatorHandlerObjectOpen.openResource(creator.diagramFile, DBeaverUI.getActiveWorkbenchWindow());
    } catch (InterruptedException ex) {
        return false;
    } catch (InvocationTargetException ex) {
        UIUtils.showErrorDialog(getShell(), "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 54 with DBSObject

use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.

the class DiagramCreateWizardPage method createControl.

@Override
public void createControl(Composite parent) {
    Composite placeholder = UIUtils.createPlaceholder(parent, 1);
    Composite configGroup = UIUtils.createControlGroup(placeholder, ERDMessages.wizard_page_diagram_create_group_settings, 2, GridData.FILL_BOTH, 0);
    //$NON-NLS-1$
    final Text projectNameText = UIUtils.createLabelText(configGroup, "Name", null);
    projectNameText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            diagram.setName(projectNameText.getText());
            updateState();
        }
    });
    Label contentLabel = UIUtils.createControlLabel(configGroup, ERDMessages.wizard_page_diagram_create_label_init_content);
    GridData gd = new GridData(GridData.BEGINNING);
    gd.horizontalSpan = 2;
    contentLabel.setLayoutData(gd);
    final DBNProject rootNode = DBeaverCore.getInstance().getNavigatorModel().getRoot().getProject(DBeaverCore.getInstance().getProjectRegistry().getActiveProject());
    if (rootNode == null) {
        setControl(placeholder);
        return;
    }
    contentTree = new DatabaseNavigatorTree(configGroup, rootNode.getDatabases(), SWT.SINGLE | SWT.CHECK);
    gd = new GridData(GridData.FILL_BOTH);
    gd.horizontalSpan = 2;
    gd.heightHint = 400;
    contentTree.setLayoutData(gd);
    CheckboxTreeViewer viewer = (CheckboxTreeViewer) contentTree.getViewer();
    viewer.setCheckStateProvider(new ICheckStateProvider() {

        @Override
        public boolean isChecked(Object element) {
            return false;
        }

        @Override
        public boolean isGrayed(Object element) {
            if (element instanceof DBNDatabaseNode && !(element instanceof DBNDataSource)) {
                DBSObject object = ((DBNDatabaseNode) element).getObject();
                if (object instanceof DBSTable) {
                    return false;
                }
            }
            return true;
        }
    });
    setControl(placeholder);
}
Also used : DBNProject(org.jkiss.dbeaver.model.navigator.DBNProject) DBSTable(org.jkiss.dbeaver.model.struct.rdb.DBSTable) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) ICheckStateProvider(org.eclipse.jface.viewers.ICheckStateProvider) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) DatabaseNavigatorTree(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridData(org.eclipse.swt.layout.GridData) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 55 with DBSObject

use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.

the class PropertySourceAbstract method collectProperties.

public boolean collectProperties() {
    lazyValues.clear();
    props.clear();
    propValues.clear();
    final Object editableValue = getEditableValue();
    IPropertyFilter filter;
    if (editableValue instanceof DBSObject) {
        filter = new DataSourcePropertyFilter(((DBSObject) editableValue).getDataSource());
    } else if (editableValue instanceof DBPContextProvider) {
        DBCExecutionContext context = ((DBPContextProvider) editableValue).getExecutionContext();
        filter = context == null ? new DataSourcePropertyFilter() : new DataSourcePropertyFilter(context.getDataSource());
    } else {
        filter = new DataSourcePropertyFilter();
    }
    List<ObjectPropertyDescriptor> annoProps = ObjectAttributeDescriptor.extractAnnotations(this, editableValue.getClass(), filter);
    for (final ObjectPropertyDescriptor desc : annoProps) {
        addProperty(desc);
    }
    if (editableValue instanceof DBPPropertySource) {
        DBPPropertySource ownPropSource = (DBPPropertySource) editableValue;
        DBPPropertyDescriptor[] ownProperties = ownPropSource.getPropertyDescriptors2();
        if (!ArrayUtils.isEmpty(ownProperties)) {
            for (DBPPropertyDescriptor prop : ownProperties) {
                props.add(prop);
                propValues.put(prop.getId(), ownPropSource.getPropertyValue(null, prop.getId()));
            }
        }
    }
    return !props.isEmpty();
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) DBPPropertySource(org.jkiss.dbeaver.model.preferences.DBPPropertySource) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPPropertyDescriptor(org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor)

Aggregations

DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)68 DBException (org.jkiss.dbeaver.DBException)19 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)13 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)12 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)9 ISelection (org.eclipse.jface.viewers.ISelection)8 JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)8 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)8 AbstractObjectReference (org.jkiss.dbeaver.model.impl.struct.AbstractObjectReference)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)7 ArrayList (java.util.ArrayList)6 GridData (org.eclipse.swt.layout.GridData)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)5 DBEObjectMaker (org.jkiss.dbeaver.model.edit.DBEObjectMaker)4 DBSObjectContainer (org.jkiss.dbeaver.model.struct.DBSObjectContainer)4 DBSObjectSelector (org.jkiss.dbeaver.model.struct.DBSObjectSelector)4 DBSWrapper (org.jkiss.dbeaver.model.struct.DBSWrapper)4 ToolWizardDialog (org.jkiss.dbeaver.ui.dialogs.tools.ToolWizardDialog)4