Search in sources :

Example 1 with IDatabaseEditor

use of org.jkiss.dbeaver.ui.editors.IDatabaseEditor in project dbeaver by serge-rider.

the class NavigatorHandlerObjectBase method getCommandTarget.

protected static CommandTarget getCommandTarget(IWorkbenchWindow workbenchWindow, DBNContainer container, Class<?> childType, boolean openEditor) throws DBException {
    final Object parentObject = container.getValueObject();
    DBSObject objectToSeek = null;
    if (parentObject instanceof DBSObject) {
        final DBEStructEditor parentStructEditor = EntityEditorsRegistry.getInstance().getObjectManager(parentObject.getClass(), DBEStructEditor.class);
        if (parentStructEditor != null && RuntimeUtils.isTypeSupported(childType, parentStructEditor.getChildTypes())) {
            objectToSeek = (DBSObject) parentObject;
        }
    }
    if (objectToSeek != null) {
        for (final IEditorReference editorRef : workbenchWindow.getActivePage().getEditorReferences()) {
            final IEditorPart editor = editorRef.getEditor(false);
            if (editor instanceof IDatabaseEditor) {
                final IDatabaseEditorInput editorInput = ((IDatabaseEditor) editor).getEditorInput();
                if (editorInput.getDatabaseObject() == objectToSeek) {
                    workbenchWindow.getActivePage().activate(editor);
                    switchEditorFolder(container, editor);
                    return new CommandTarget((IDatabaseEditor) editor);
                }
            }
        }
        if (openEditor && container instanceof DBNDatabaseNode) {
            final IDatabaseEditor editor = (IDatabaseEditor) NavigatorHandlerObjectOpen.openEntityEditor((DBNDatabaseNode) container, null, workbenchWindow);
            if (editor != null) {
                switchEditorFolder(container, editor);
                return new CommandTarget(editor);
            }
        }
    }
    if (container instanceof DBNDatabaseNode) {
        // No editor found - create new command context
        DBPDataSource dataSource = ((DBNDatabaseNode) container).getObject().getDataSource();
        if (dataSource != null) {
            return new CommandTarget(new SimpleCommandContext(dataSource.getDefaultContext(true), !openEditor));
        }
    }
    return new CommandTarget();
}
Also used : IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IEditorReference(org.eclipse.ui.IEditorReference) SimpleCommandContext(org.jkiss.dbeaver.ui.SimpleCommandContext) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBEStructEditor(org.jkiss.dbeaver.model.edit.DBEStructEditor) IEditorPart(org.eclipse.ui.IEditorPart) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) IDatabaseEditor(org.jkiss.dbeaver.ui.editors.IDatabaseEditor)

Example 2 with IDatabaseEditor

use of org.jkiss.dbeaver.ui.editors.IDatabaseEditor in project dbeaver by serge-rider.

the class NavigatorHandlerObjectDelete method deleteNewObject.

private boolean deleteNewObject(IWorkbenchWindow workbenchWindow, DBNDatabaseNode node) throws DBException {
    for (final IEditorReference editorRef : workbenchWindow.getActivePage().getEditorReferences()) {
        final IEditorPart editor = editorRef.getEditor(false);
        if (editor instanceof IDatabaseEditor) {
            final IDatabaseEditorInput editorInput = ((IDatabaseEditor) editor).getEditorInput();
            if (editorInput.getDatabaseObject() == node.getObject()) {
                ConfirmResult confirmResult = confirmObjectDelete(workbenchWindow, node, false);
                if (confirmResult == ConfirmResult.NO) {
                    return true;
                }
                // Just close editor
                // It should dismiss new object and remove navigator node
                workbenchWindow.getActivePage().closeEditor(editor, false);
                return true;
            }
        }
    }
    return false;
}
Also used : IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) IEditorReference(org.eclipse.ui.IEditorReference) IEditorPart(org.eclipse.ui.IEditorPart) IDatabaseEditor(org.jkiss.dbeaver.ui.editors.IDatabaseEditor)

Aggregations

IEditorPart (org.eclipse.ui.IEditorPart)2 IEditorReference (org.eclipse.ui.IEditorReference)2 IDatabaseEditor (org.jkiss.dbeaver.ui.editors.IDatabaseEditor)2 IDatabaseEditorInput (org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput)2 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)1 DBEStructEditor (org.jkiss.dbeaver.model.edit.DBEStructEditor)1 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)1 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)1 SimpleCommandContext (org.jkiss.dbeaver.ui.SimpleCommandContext)1