Search in sources :

Example 11 with EntityEditor

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

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

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

the class ItemListControl method fillCustomActions.

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

            @Override
            public void run() {
                NavigatorHandlerFilterConfig.configureFilters(getShell(), rootNode);
            }
        });
    }
    IWorkbenchSite workbenchSite = getWorkbenchSite();
    if (workbenchSite != null) {
        contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.FILE_REFRESH));
    }
    if (rootNode instanceof DBNDatabaseNode) {
        contributionManager.add(new Separator());
        contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, CoreCommands.CMD_OBJECT_OPEN));
        contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, CoreCommands.CMD_OBJECT_CREATE));
        contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, CoreCommands.CMD_OBJECT_DELETE));
    }
    if (rootNode instanceof DBNDatabaseNode && rootNode.isPersisted()) {
        boolean hasReorder = false;
        List<Class<?>> childrenTypes = ((DBNDatabaseNode) rootNode).getChildrenTypes(null);
        for (Class<?> chilType : childrenTypes) {
            if (EntityEditorsRegistry.getInstance().getObjectManager(chilType, DBEObjectReorderer.class) != null) {
                hasReorder = true;
                break;
            }
        }
        if (hasReorder) {
            contributionManager.add(new Separator());
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, CoreCommands.CMD_OBJECT_MOVE_UP));
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, CoreCommands.CMD_OBJECT_MOVE_DOWN));
        }
    }
    if (workbenchSite instanceof MultiPageEditorSite) {
        final MultiPageEditorPart editor = ((MultiPageEditorSite) workbenchSite).getMultiPageEditor();
        if (editor instanceof EntityEditor) {
            contributionManager.add(new Separator());
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.FILE_SAVE, null, UIIcon.SAVE, null, true));
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.FILE_REVERT, null, UIIcon.RESET, null, true));
        }
    }
}
Also used : IWorkbenchSite(org.eclipse.ui.IWorkbenchSite) Action(org.eclipse.jface.action.Action) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder) DBEObjectReorderer(org.jkiss.dbeaver.model.edit.DBEObjectReorderer) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) MultiPageEditorSite(org.eclipse.ui.part.MultiPageEditorSite) Separator(org.eclipse.jface.action.Separator)

Example 13 with EntityEditor

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

the class CompileHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchPart activePart = HandlerUtil.getActiveEditor(event);
    final List<OracleSourceObject> objects = getSelectedObjects(event);
    if (!objects.isEmpty()) {
        if (activePart instanceof EntityEditor) {
            // Save editor before compile
            // USe null monitor as entity editor has its own detached job for save
            EntityEditor entityEditor = (EntityEditor) activePart;
            if (entityEditor.isDirty()) {
                NullProgressMonitor monitor = new NullProgressMonitor();
                entityEditor.doSave(monitor);
                if (monitor.isCanceled()) {
                    // Save failed - doesn't make sense to compile
                    return null;
                }
            }
        }
        final Shell activeShell = HandlerUtil.getActiveShell(event);
        if (objects.size() == 1) {
            final OracleSourceObject unit = objects.get(0);
            DBCSourceHost sourceHost = null;
            if (activePart != null) {
                sourceHost = RuntimeUtils.getObjectAdapter(activePart, DBCSourceHost.class);
                if (sourceHost == null) {
                    sourceHost = activePart.getAdapter(DBCSourceHost.class);
                }
            }
            if (sourceHost != null && sourceHost.getSourceObject() != unit) {
                sourceHost = null;
            }
            final DBCCompileLog compileLog = sourceHost == null ? new DBCCompileLogBase() : sourceHost.getCompileLog();
            compileLog.clearLog();
            Throwable error = null;
            try {
                DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {

                    @Override
                    public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        try {
                            compileUnit(monitor, compileLog, unit);
                        } catch (DBCException e) {
                            throw new InvocationTargetException(e);
                        }
                    }
                });
                if (compileLog.getError() != null) {
                    error = compileLog.getError();
                }
            } catch (InvocationTargetException e) {
                error = e.getTargetException();
            } catch (InterruptedException e) {
                return null;
            }
            if (error != null) {
                DBUserInterface.getInstance().showError("Unexpected compilation error", null, error);
            } else if (!CommonUtils.isEmpty(compileLog.getErrorStack())) {
                // Show compile errors
                int line = -1, position = -1;
                StringBuilder fullMessage = new StringBuilder();
                for (DBCCompileError oce : compileLog.getErrorStack()) {
                    fullMessage.append(oce.toString()).append(GeneralUtils.getDefaultLineSeparator());
                    if (line < 0) {
                        line = oce.getLine();
                        position = oce.getPosition();
                    }
                }
                // If compiled object is currently open in editor - try to position on error line
                if (sourceHost != null && sourceHost.getSourceObject() == unit && line > 0 && position > 0) {
                    sourceHost.positionSource(line, position);
                    activePart.getSite().getPage().activate(activePart);
                }
                String errorTitle = unit.getName() + " compilation failed";
                if (sourceHost != null) {
                    sourceHost.setCompileInfo(errorTitle, true);
                    sourceHost.showCompileLog();
                }
                DBUserInterface.getInstance().showError(errorTitle, fullMessage.toString());
            } else {
                String message = unit.getName() + " compiled successfully";
                if (sourceHost != null) {
                    sourceHost.setCompileInfo(message, true);
                }
                UIUtils.showMessageBox(activeShell, "Done", message, SWT.ICON_INFORMATION);
            }
        } else {
            OracleCompilerDialog dialog = new OracleCompilerDialog(activeShell, objects);
            dialog.open();
        }
    }
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) DBCSourceHost(org.jkiss.dbeaver.model.exec.compile.DBCSourceHost) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBCCompileError(org.jkiss.dbeaver.model.exec.compile.DBCCompileError) InvocationTargetException(java.lang.reflect.InvocationTargetException) OracleCompilerDialog(org.jkiss.dbeaver.ext.oracle.views.OracleCompilerDialog) DBCCompileLogBase(org.jkiss.dbeaver.model.exec.compile.DBCCompileLogBase) Shell(org.eclipse.swt.widgets.Shell) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) DBCCompileLog(org.jkiss.dbeaver.model.exec.compile.DBCCompileLog) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) OracleSourceObject(org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject)

Example 14 with EntityEditor

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

the class PackageNavigateHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final OracleProcedurePackaged procedure = getSelectedProcedure(event);
    if (procedure != null) {
        OraclePackage procPackage = procedure.getParentObject();
        IEditorPart entityEditor = NavigatorHandlerObjectOpen.openEntityEditor(procPackage);
        if (entityEditor instanceof EntityEditor) {
            ((EntityEditor) entityEditor).switchFolder("source.definition");
            SQLEditorBase sqlEditor = entityEditor.getAdapter(SQLEditorBase.class);
            if (sqlEditor != null) {
                new NavigateJob(procedure, sqlEditor).schedule();
            }
        }
    }
    return null;
}
Also used : OracleProcedurePackaged(org.jkiss.dbeaver.ext.oracle.model.OracleProcedurePackaged) OraclePackage(org.jkiss.dbeaver.ext.oracle.model.OraclePackage) SQLEditorBase(org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) IEditorPart(org.eclipse.ui.IEditorPart)

Example 15 with EntityEditor

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

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