Search in sources :

Example 16 with EntityEditor

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

the class UndoChangesHandler method updateElement.

@Override
public void updateElement(UIElement element, Map parameters) {
    IWorkbenchWindow workbenchWindow = element.getServiceLocator().getService(IWorkbenchWindow.class);
    if (workbenchWindow == null || workbenchWindow.getActivePage() == null) {
        return;
    }
    final IEditorPart activeEditor = workbenchWindow.getActivePage().getActiveEditor();
    if (activeEditor instanceof EntityEditor) {
        final DBECommandContext commandContext = ((EntityEditor) activeEditor).getCommandContext();
        String text = WorkbenchMessages.Workbench_undo;
        if (commandContext != null && commandContext.getUndoCommand() != null) {
            text += " " + commandContext.getUndoCommand().getTitle();
        }
        element.setText(text);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DBECommandContext(org.jkiss.dbeaver.model.edit.DBECommandContext) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) IEditorPart(org.eclipse.ui.IEditorPart)

Example 17 with EntityEditor

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

the class NavigatorHandlerObjectOpen method openEntityEditor.

public static IEditorPart openEntityEditor(@NotNull DBNNode selectedNode, @Nullable String defaultPageId, @Nullable String defaultFolderId, @Nullable Map<String, Object> attributes, IWorkbenchWindow workbenchWindow, boolean activate) {
    if (selectedNode instanceof DBNDataSource) {
        final DBPDataSourceContainer dataSourceContainer = ((DBNDataSource) selectedNode).getDataSourceContainer();
        openConnectionEditor(workbenchWindow, dataSourceContainer);
        return null;
    }
    try {
        if (selectedNode instanceof DBNDatabaseFolder && !(selectedNode.getParentNode() instanceof DBNDatabaseFolder) && selectedNode.getParentNode() instanceof DBNDatabaseNode) {
            if (defaultFolderId == null) {
                defaultFolderId = selectedNode.getNodeType();
            }
            selectedNode = selectedNode.getParentNode();
        }
        IEditorPart editor = findEntityEditor(workbenchWindow, selectedNode);
        if (editor != null) {
            boolean settingsChanged = false;
            IEditorInput editorInput = editor.getEditorInput();
            if (editorInput instanceof DatabaseEditorInput) {
                settingsChanged = setInputAttributes((DatabaseEditorInput<?>) editorInput, defaultPageId, defaultFolderId, attributes);
            }
            if (editor instanceof EntityEditor && defaultPageId != null) {
                // Set active page
                IEditorPart pageEditor = ((EntityEditor) editor).getPageEditor(defaultPageId);
                if (pageEditor != null && pageEditor != ((EntityEditor) editor).getActiveEditor()) {
                    ((EntityEditor) editor).setActiveEditor(pageEditor);
                }
            }
            if (editor instanceof ITabbedFolderContainer && defaultFolderId != null) {
                // Activate default folder
                if (((ITabbedFolderContainer) editor).switchFolder(defaultFolderId)) {
                    settingsChanged = true;
                }
            }
            if (settingsChanged) {
                if (editor instanceof IRefreshablePart) {
                    ((IRefreshablePart) editor).refreshPart(selectedNode, true);
                }
            }
            if (workbenchWindow.getActivePage().getActiveEditor() != editor || activate) {
                workbenchWindow.getActivePage().activate(editor);
            }
            return editor;
        }
        if (selectedNode instanceof DBNDatabaseNode) {
            DBNDatabaseNode dnNode = (DBNDatabaseNode) selectedNode;
            DBSObject databaseObject = dnNode.getObject();
            if (databaseObject != null) {
                if (!databaseObject.isPersisted()) {
                    return null;
                }
                try {
                    DBUtils.getOrOpenDefaultContext(databaseObject, false);
                } catch (DBCException ignored) {
                    return null;
                }
                if (selectedNode instanceof DBNDatabaseObject) {
                    DBNDatabaseObject objectNode = (DBNDatabaseObject) selectedNode;
                    if (!objectNode.isPersisted()) {
                        return null;
                    }
                    ObjectEditorInput objectInput = new ObjectEditorInput(objectNode);
                    setInputAttributes(objectInput, defaultPageId, defaultFolderId, attributes);
                    return workbenchWindow.getActivePage().openEditor(objectInput, objectNode.getMeta().getEditorId());
                } else {
                    DatabaseNodeEditorInput editorInput = new DatabaseNodeEditorInput(dnNode);
                    if (DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.NAVIGATOR_REFRESH_EDITORS_ON_OPEN)) {
                        refreshDatabaseNode(dnNode);
                    }
                    setInputAttributes(editorInput, defaultPageId, defaultFolderId, attributes);
                    return workbenchWindow.getActivePage().openEditor(editorInput, EntityEditor.class.getName());
                }
            } else {
                DBWorkbench.getPlatformUI().showError("No object", "Node has no associated database object");
                return null;
            }
        } else {
            NodeEditorInput folderInput = new NodeEditorInput(selectedNode);
            return workbenchWindow.getActivePage().openEditor(folderInput, FolderEditor.class.getName());
        }
    } catch (Exception ex) {
        DBWorkbench.getPlatformUI().showError(UINavigatorMessages.actions_navigator_error_dialog_open_entity_title, "Can't open entity '" + selectedNode.getNodeName() + "'", ex);
        return null;
    }
}
Also used : DBCException(org.jkiss.dbeaver.model.exec.DBCException) IEditorPart(org.eclipse.ui.IEditorPart) DBCException(org.jkiss.dbeaver.model.exec.DBCException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ITabbedFolderContainer(org.jkiss.dbeaver.ui.controls.folders.ITabbedFolderContainer) IRefreshablePart(org.jkiss.dbeaver.ui.IRefreshablePart) ObjectEditorInput(org.jkiss.dbeaver.ui.editors.object.ObjectEditorInput) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) FolderEditor(org.jkiss.dbeaver.ui.editors.entity.FolderEditor) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) IEditorInput(org.eclipse.ui.IEditorInput)

Example 18 with EntityEditor

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

the class SQLEditorNested method refreshPart.

@Override
public void refreshPart(Object source, boolean force) {
    // Check if we are in saving process
    // If so then no refresh needed (source text was updated during save)
    IEditorSite editorSite = getEditorSite();
    if (editorSite instanceof MultiPageEditorSite && ((MultiPageEditorSite) editorSite).getMultiPageEditor() instanceof EntityEditor && ((EntityEditor) ((MultiPageEditorSite) editorSite).getMultiPageEditor()).isSaveInProgress()) {
        return;
    }
    final IDocumentProvider documentProvider = getDocumentProvider();
    if (documentProvider instanceof SQLEditorNested.ObjectDocumentProvider) {
        ((SQLEditorNested.ObjectDocumentProvider) documentProvider).sourceText = null;
    }
    if (force) {
        int caretOffset = getEditorControl().getCaretOffset();
        super.setInput(getEditorInput());
        // Try to keep cursor position
        if (caretOffset < getEditorControl().getCharCount()) {
            getEditorControl().setCaretOffset(caretOffset);
        }
    }
    reloadSyntaxRules();
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) MultiPageEditorSite(org.eclipse.ui.part.MultiPageEditorSite) IEditorSite(org.eclipse.ui.IEditorSite)

Example 19 with EntityEditor

use of org.jkiss.dbeaver.ui.editors.entity.EntityEditor in project dbeaver by dbeaver.

the class RedoChangesHandler method updateElement.

@Override
public void updateElement(UIElement element, Map parameters) {
    IWorkbenchWindow workbenchWindow = element.getServiceLocator().getService(IWorkbenchWindow.class);
    if (workbenchWindow == null || workbenchWindow.getActivePage() == null) {
        return;
    }
    final IEditorPart activeEditor = workbenchWindow.getActivePage().getActiveEditor();
    if (activeEditor instanceof EntityEditor) {
        final DBECommandContext commandContext = ((EntityEditor) activeEditor).getCommandContext();
        String text = WorkbenchMessages.Workbench_redo;
        if (commandContext != null && commandContext.getRedoCommand() != null) {
            text += " " + commandContext.getRedoCommand().getTitle();
        }
        element.setText(text);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DBECommandContext(org.jkiss.dbeaver.model.edit.DBECommandContext) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) IEditorPart(org.eclipse.ui.IEditorPart)

Example 20 with EntityEditor

use of org.jkiss.dbeaver.ui.editors.entity.EntityEditor in project dbeaver by dbeaver.

the class NavigatorHandlerObjectOpen method openEntityEditor.

public static IEditorPart openEntityEditor(@NotNull DBNNode selectedNode, @Nullable String defaultPageId, @Nullable String defaultFolderId, @Nullable Map<String, Object> attributes, IWorkbenchWindow workbenchWindow, boolean activate) {
    if (selectedNode instanceof DBNDataSource) {
        final DBPDataSourceContainer dataSourceContainer = ((DBNDataSource) selectedNode).getDataSourceContainer();
        openConnectionEditor(workbenchWindow, dataSourceContainer);
        return null;
    }
    try {
        if (selectedNode instanceof DBNDatabaseFolder && !(selectedNode.getParentNode() instanceof DBNDatabaseFolder) && selectedNode.getParentNode() instanceof DBNDatabaseNode) {
            if (defaultFolderId == null) {
                defaultFolderId = selectedNode.getNodeType();
            }
            selectedNode = selectedNode.getParentNode();
        }
        IEditorPart editor = findEntityEditor(workbenchWindow, selectedNode);
        if (editor != null) {
            boolean settingsChanged = false;
            IEditorInput editorInput = editor.getEditorInput();
            if (editorInput instanceof DatabaseEditorInput) {
                settingsChanged = setInputAttributes((DatabaseEditorInput<?>) editorInput, defaultPageId, defaultFolderId, attributes);
            }
            if (editor instanceof EntityEditor && defaultPageId != null) {
                // Set active page
                IEditorPart pageEditor = ((EntityEditor) editor).getPageEditor(defaultPageId);
                if (pageEditor != null && pageEditor != ((EntityEditor) editor).getActiveEditor()) {
                    ((EntityEditor) editor).setActiveEditor(pageEditor);
                }
            }
            if (editor instanceof ITabbedFolderContainer && defaultFolderId != null) {
                // Activate default folder
                if (((ITabbedFolderContainer) editor).switchFolder(defaultFolderId)) {
                    settingsChanged = true;
                }
            }
            if (settingsChanged) {
                if (editor instanceof IRefreshablePart) {
                    ((IRefreshablePart) editor).refreshPart(selectedNode, true);
                }
            }
            if (workbenchWindow.getActivePage().getActiveEditor() != editor || activate) {
                workbenchWindow.getActivePage().activate(editor);
            }
            return editor;
        }
        if (selectedNode instanceof DBNDatabaseNode) {
            DBNDatabaseNode dnNode = (DBNDatabaseNode) selectedNode;
            DBSObject databaseObject = dnNode.getObject();
            if (databaseObject != null) {
                if (!databaseObject.isPersisted()) {
                    return null;
                }
                try {
                    DBUtils.getOrOpenDefaultContext(databaseObject, false);
                } catch (DBCException ignored) {
                    return null;
                }
                if (selectedNode instanceof DBNDatabaseObject) {
                    DBNDatabaseObject objectNode = (DBNDatabaseObject) selectedNode;
                    if (!objectNode.isPersisted()) {
                        return null;
                    }
                    ObjectEditorInput objectInput = new ObjectEditorInput(objectNode);
                    setInputAttributes(objectInput, defaultPageId, defaultFolderId, attributes);
                    return workbenchWindow.getActivePage().openEditor(objectInput, objectNode.getMeta().getEditorId());
                } else {
                    DatabaseNodeEditorInput editorInput = new DatabaseNodeEditorInput(dnNode);
                    if (DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.NAVIGATOR_REFRESH_EDITORS_ON_OPEN)) {
                        refreshDatabaseNode(dnNode);
                    }
                    setInputAttributes(editorInput, defaultPageId, defaultFolderId, attributes);
                    return workbenchWindow.getActivePage().openEditor(editorInput, EntityEditor.class.getName());
                }
            } else {
                DBWorkbench.getPlatformUI().showError("No object", "Node has no associated database object");
                return null;
            }
        } else {
            NodeEditorInput folderInput = new NodeEditorInput(selectedNode);
            return workbenchWindow.getActivePage().openEditor(folderInput, FolderEditor.class.getName());
        }
    } catch (Exception ex) {
        DBWorkbench.getPlatformUI().showError(UINavigatorMessages.actions_navigator_error_dialog_open_entity_title, "Can't open entity '" + selectedNode.getNodeName() + "'", ex);
        return null;
    }
}
Also used : DBCException(org.jkiss.dbeaver.model.exec.DBCException) IEditorPart(org.eclipse.ui.IEditorPart) DBCException(org.jkiss.dbeaver.model.exec.DBCException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ITabbedFolderContainer(org.jkiss.dbeaver.ui.controls.folders.ITabbedFolderContainer) IRefreshablePart(org.jkiss.dbeaver.ui.IRefreshablePart) ObjectEditorInput(org.jkiss.dbeaver.ui.editors.object.ObjectEditorInput) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) FolderEditor(org.jkiss.dbeaver.ui.editors.entity.FolderEditor) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

EntityEditor (org.jkiss.dbeaver.ui.editors.entity.EntityEditor)23 IEditorPart (org.eclipse.ui.IEditorPart)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 MultiPageEditorSite (org.eclipse.ui.part.MultiPageEditorSite)8 DBCException (org.jkiss.dbeaver.model.exec.DBCException)7 SQLEditorBase (org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase)6 ArrayList (java.util.ArrayList)4 IWorkbenchSite (org.eclipse.ui.IWorkbenchSite)4 MultiPageEditorPart (org.eclipse.ui.part.MultiPageEditorPart)4 OraclePackage (org.jkiss.dbeaver.ext.oracle.model.OraclePackage)4 OracleProcedurePackaged (org.jkiss.dbeaver.ext.oracle.model.OracleProcedurePackaged)4 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)4 DBEObjectReorderer (org.jkiss.dbeaver.model.edit.DBEObjectReorderer)4 DBNDatabaseFolder (org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)4 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)4 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)4 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)3 DBException (org.jkiss.dbeaver.DBException)3 DBECommandContext (org.jkiss.dbeaver.model.edit.DBECommandContext)3 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)3