Search in sources :

Example 1 with SimpleCommandContext

use of org.jkiss.dbeaver.ui.SimpleCommandContext 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 SimpleCommandContext

use of org.jkiss.dbeaver.ui.SimpleCommandContext in project dbeaver by dbeaver.

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)

Aggregations

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