Search in sources :

Example 6 with EntityEditor

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

the class ItemListControl method fillCustomActions.

@Override
public void fillCustomActions(IContributionManager contributionManager) {
    super.fillCustomActions(contributionManager);
    final DBNNode rootNode = getRootNode();
    if (rootNode instanceof DBNDatabaseFolder && ((DBNDatabaseFolder) rootNode).getItemsMeta() != null) {
        contributionManager.add(new Action(UINavigatorMessages.obj_editor_properties_control_action_filter_setting, DBeaverIcons.getImageDescriptor(UIIcon.FILTER)) {

            @Override
            public void run() {
                NavigatorHandlerFilterConfig.configureFilters(getShell(), rootNode);
            }
        });
    }
    addColumnConfigAction(contributionManager);
    IWorkbenchSite workbenchSite = getWorkbenchSite();
    if (rootNode instanceof DBNDatabaseFolder) {
        contributionManager.add(new Separator());
        contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_OPEN));
        {
            if (ObjectPropertyTester.canCreateObject(rootNode, true)) {
                contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_CREATE));
            } else if (ObjectPropertyTester.canCreateObject(rootNode, false)) {
                contributionManager.add(new Action(null, Action.AS_DROP_DOWN_MENU) {

                    {
                        setActionDefinitionId(NavigatorCommands.CMD_OBJECT_CREATE);
                    }

                    @Override
                    public void run() {
                        super.run();
                    }

                    @Override
                    public IMenuCreator getMenuCreator() {
                        return new MenuCreator(control -> {
                            List<IContributionItem> items = NavigatorHandlerObjectCreateNew.fillCreateMenuItems((IWorkbenchPartSite) workbenchSite, rootNode);
                            MenuManager menuManager = new MenuManager();
                            for (IContributionItem cc : items) {
                                menuManager.add(cc);
                            }
                            return menuManager;
                        });
                    }
                });
            }
        }
        contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_DELETE));
    }
    if (rootNode instanceof DBNDatabaseNode && rootNode.isPersisted()) {
        boolean hasReorder = false;
        List<Class<?>> childrenTypes = ((DBNDatabaseNode) rootNode).getChildrenTypes(null);
        for (Class<?> chilType : childrenTypes) {
            if (DBWorkbench.getPlatform().getEditorsRegistry().getObjectManager(chilType, DBEObjectReorderer.class) != null) {
                hasReorder = true;
                break;
            }
        }
        if (hasReorder) {
            contributionManager.add(new Separator());
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_MOVE_UP));
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_MOVE_DOWN));
        }
    }
    if (rootNode instanceof DBNDatabaseNode) {
        // Expand/collapse
        final List<DBXTreeNode> inlineMetas = collectInlineMetas((DBNDatabaseNode) rootNode, ((DBNDatabaseNode) rootNode).getMeta());
        if (!inlineMetas.isEmpty()) {
            contributionManager.add(new Separator());
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.NAVIGATE_COLLAPSE_ALL, null, UIIcon.TREE_COLLAPSE_ALL));
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.NAVIGATE_EXPAND_ALL, null, UIIcon.TREE_EXPAND_ALL));
        }
    }
    // Save/revert
    if (workbenchSite instanceof MultiPageEditorSite) {
        final MultiPageEditorPart editor = ((MultiPageEditorSite) workbenchSite).getMultiPageEditor();
        if (editor instanceof EntityEditor) {
            contributionManager.add(new Separator());
            DatabaseEditorUtils.contributeStandardEditorActions(workbenchSite, contributionManager);
        }
    }
}
Also used : IWorkbenchSite(org.eclipse.ui.IWorkbenchSite) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) DatabaseLoadService(org.jkiss.dbeaver.model.runtime.load.DatabaseLoadService) ObjectPropertyTester(org.jkiss.dbeaver.ui.actions.ObjectPropertyTester) Arrays(java.util.Arrays) org.eclipse.jface.action(org.eclipse.jface.action) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) org.jkiss.dbeaver.ui(org.jkiss.dbeaver.ui) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) IWorkbenchCommandConstants(org.eclipse.ui.IWorkbenchCommandConstants) NavigatorCommands(org.jkiss.dbeaver.ui.navigator.NavigatorCommands) PropertyEditorUtils(org.jkiss.dbeaver.ui.properties.PropertyEditorUtils) ArrayList(java.util.ArrayList) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) DBNUtils(org.jkiss.dbeaver.model.navigator.DBNUtils) Composite(org.eclipse.swt.widgets.Composite) NavigatorHandlerFilterConfig(org.jkiss.dbeaver.ui.navigator.actions.NavigatorHandlerFilterConfig) Log(org.jkiss.dbeaver.Log) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) ObjectPropertyDescriptor(org.jkiss.dbeaver.runtime.properties.ObjectPropertyDescriptor) Font(org.eclipse.swt.graphics.Font) DBPObjectStatisticsCollector(org.jkiss.dbeaver.model.DBPObjectStatisticsCollector) DBUtils(org.jkiss.dbeaver.model.DBUtils) IWorkbenchSite(org.eclipse.ui.IWorkbenchSite) Collection(java.util.Collection) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) ArrayUtils(org.jkiss.utils.ArrayUtils) org.eclipse.jface.viewers(org.eclipse.jface.viewers) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) UINavigatorMessages(org.jkiss.dbeaver.ui.internal.UINavigatorMessages) InvocationTargetException(java.lang.reflect.InvocationTargetException) MultiPageEditorSite(org.eclipse.ui.part.MultiPageEditorSite) List(java.util.List) Color(org.eclipse.swt.graphics.Color) SWT(org.eclipse.swt.SWT) DatabaseEditorUtils(org.jkiss.dbeaver.ui.editors.DatabaseEditorUtils) DBXTreeNode(org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode) NavigatorHandlerObjectCreateNew(org.jkiss.dbeaver.ui.navigator.actions.NavigatorHandlerObjectCreateNew) DBEObjectReorderer(org.jkiss.dbeaver.model.edit.DBEObjectReorderer) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) DBXTreeNode(org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode) DBEObjectReorderer(org.jkiss.dbeaver.model.edit.DBEObjectReorderer) ArrayList(java.util.ArrayList) List(java.util.List) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) MultiPageEditorSite(org.eclipse.ui.part.MultiPageEditorSite)

Example 7 with EntityEditor

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

the class WorkbenchContextListener method activatePartContexts.

void activatePartContexts(IWorkbenchPart part) {
    IContextService contextService = PlatformUI.getWorkbench().getService(IContextService.class);
    if (contextService == null) {
        return;
    }
    try {
        contextService.deferUpdates(true);
        if (part instanceof INavigatorModelView) {
        // We check for instanceof (do not use adapter) because otherwise it become active
        // for all entity editor and clashes with SQL editor and other complex stuff.
        // if (activationNavigator != null) {
        // //log.debug("Double activation of navigator context");
        // contextService.deactivateContext(activationNavigator);
        // }
        // activationNavigator = contextService.activateContext(INavigatorModelView.NAVIGATOR_CONTEXT_ID);
        }
        if (part instanceof SQLEditorBase || part.getAdapter(SQLEditorBase.class) != null) {
            if (activationSQL != null) {
                // log.debug("Double activation of SQL context");
                contextService.deactivateContext(activationSQL);
            }
            activationSQL = contextService.activateContext(SQLEditorContributions.SQL_EDITOR_CONTEXT);
        }
        if (part.getAdapter(ResultSetViewer.class) != null || (part instanceof SQLEditor) || (part instanceof EntityEditor && ((EntityEditor) part).getDatabaseObject() instanceof DBSDataContainer)) {
            if (activationResults != null) {
                contextService.deactivateContext(activationResults);
            }
            activationResults = contextService.activateContext(RESULTS_CONTEXT_ID);
        }
        // Refresh auto-commit element state (#3315)
        // Refresh OpenSeparateConnection
        ActionUtils.fireCommandRefresh(ConnectionCommands.CMD_TOGGLE_AUTOCOMMIT, SQLEditorCommands.CMD_TOGGLE_SEPARATE_CONNECTION);
    } finally {
        contextService.deferUpdates(false);
    }
}
Also used : SQLEditor(org.jkiss.dbeaver.ui.editors.sql.SQLEditor) SQLEditorBase(org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase) IContextService(org.eclipse.ui.contexts.IContextService) INavigatorModelView(org.jkiss.dbeaver.ui.navigator.INavigatorModelView) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) ResultSetViewer(org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer)

Example 8 with EntityEditor

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

the class WorkbenchContextListener method activatePartContexts.

void activatePartContexts(IWorkbenchPart part) {
    IContextService contextService = PlatformUI.getWorkbench().getService(IContextService.class);
    if (contextService == null) {
        return;
    }
    try {
        contextService.deferUpdates(true);
        if (part instanceof INavigatorModelView) {
        // We check for instanceof (do not use adapter) because otherwise it become active
        // for all entity editor and clashes with SQL editor and other complex stuff.
        // if (activationNavigator != null) {
        // //log.debug("Double activation of navigator context");
        // contextService.deactivateContext(activationNavigator);
        // }
        // activationNavigator = contextService.activateContext(INavigatorModelView.NAVIGATOR_CONTEXT_ID);
        }
        if (part instanceof SQLEditorBase || part.getAdapter(SQLEditorBase.class) != null) {
            if (activationSQL != null) {
                // log.debug("Double activation of SQL context");
                contextService.deactivateContext(activationSQL);
            }
            activationSQL = contextService.activateContext(SQLEditorContributions.SQL_EDITOR_CONTEXT);
        }
        if (part.getAdapter(ResultSetViewer.class) != null || (part instanceof SQLEditor) || (part instanceof EntityEditor && ((EntityEditor) part).getDatabaseObject() instanceof DBSDataContainer)) {
            if (activationResults != null) {
                contextService.deactivateContext(activationResults);
            }
            activationResults = contextService.activateContext(RESULTS_CONTEXT_ID);
        }
        // Refresh auto-commit element state (#3315)
        // Refresh OpenSeparateConnection
        ActionUtils.fireCommandRefresh(ConnectionCommands.CMD_TOGGLE_AUTOCOMMIT, SQLEditorCommands.CMD_TOGGLE_SEPARATE_CONNECTION);
    } finally {
        contextService.deferUpdates(false);
    }
}
Also used : SQLEditor(org.jkiss.dbeaver.ui.editors.sql.SQLEditor) SQLEditorBase(org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase) IContextService(org.eclipse.ui.contexts.IContextService) INavigatorModelView(org.jkiss.dbeaver.ui.navigator.INavigatorModelView) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) ResultSetViewer(org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer)

Example 9 with EntityEditor

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

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 10 with EntityEditor

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

the class ContentEditor method doSave.

@Override
public void doSave(final IProgressMonitor monitor) {
    if (!isDirty()) {
        // Nothing to save
        return;
    }
    // Execute save in UI thread
    UIUtils.syncExec(() -> {
        try {
            // Check for dirty parts
            final List<IEditorPart> dirtyParts = new ArrayList<>();
            for (ContentPartInfo partInfo : contentParts) {
                if (partInfo.activated && partInfo.editorPart.isDirty()) {
                    dirtyParts.add(partInfo.editorPart);
                }
            }
            IEditorPart dirtyPart = null;
            if (dirtyParts.isEmpty()) {
            // No modified parts - no additional save required
            } else if (dirtyParts.size() == 1) {
                // Single part modified - save it
                dirtyPart = dirtyParts.get(0);
            } else {
                // Multiple parts modified - need to choose one
                dirtyPart = SelectContentPartDialog.selectContentPart(getSite().getShell(), dirtyParts);
            }
            if (dirtyPart != null) {
                saveInProgress = true;
                try {
                    dirtyPart.doSave(monitor);
                } finally {
                    saveInProgress = false;
                }
            }
            // Set dirty flag - if error will occur during content save
            // then document remains dirty
            ContentEditor.this.dirty = true;
            ContentEditorInput editorInput = getEditorInput();
            editorInput.updateContentFromFile(new DefaultProgressMonitor(monitor), editorInput.getValue());
            editorInput.getValueController().updateValue(editorInput.getValue(), true);
            // Activate owner editor and focus on cell corresponding to this content editor
            IWorkbenchPartSite parentEditorSite = editorInput.getValueController().getValueSite();
            IWorkbenchPart parentEditor;
            if (parentEditorSite instanceof MultiPageEditorSite) {
                parentEditor = ((MultiPageEditorSite) parentEditorSite).getMultiPageEditor();
                if (parentEditor instanceof EntityEditor) {
                    ((EntityEditor) parentEditor).setActiveEditor(IEntityDataEditor.class);
                }
            } else {
                parentEditor = parentEditorSite.getPart();
            }
            parentEditorSite.getWorkbenchWindow().getActivePage().activate(parentEditor);
            // Close editor
            closeValueEditor();
        } catch (Exception e) {
            DBWorkbench.getPlatformUI().showError("Can't save content", "Can't save content to database", e);
        }
    });
}
Also used : ArrayList(java.util.ArrayList) DefaultProgressMonitor(org.jkiss.dbeaver.model.runtime.DefaultProgressMonitor) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) MultiPageEditorSite(org.eclipse.ui.part.MultiPageEditorSite) CoreException(org.eclipse.core.runtime.CoreException) DBCException(org.jkiss.dbeaver.model.exec.DBCException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException)

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