Search in sources :

Example 21 with EntityEditor

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

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 22 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 23 with EntityEditor

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

the class JobRunHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchPart activePart = HandlerUtil.getActiveEditor(event);
    final List<OracleSchedulerJob> objects = getSelectedJobs(event);
    if (!objects.isEmpty()) {
        if (activePart instanceof EntityEditor) {
            // Save editor before run
            // 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 OracleSchedulerJob job = objects.get(0);
            final DBCCompileLog compileLog = new DBCCompileLogBase();
            compileLog.clearLog();
            Throwable error = null;
            try {
                UIUtils.runInProgressService(monitor -> {
                    try {
                        runJob(monitor, compileLog, job);
                    } 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) {
                DBWorkbench.getPlatformUI().showError("Unexpected run schedule 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();
                    }
                }
                String errorTitle = job.getName() + " run schedule failed";
                DBWorkbench.getPlatformUI().showError(errorTitle, fullMessage.toString());
            } else {
                String message = job.getName() + " successfully scheduled to run";
                UIUtils.showMessageBox(activeShell, "Done", message, SWT.ICON_INFORMATION);
            }
        }
    }
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OracleSchedulerJob(org.jkiss.dbeaver.ext.oracle.model.OracleSchedulerJob) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBCCompileError(org.jkiss.dbeaver.model.exec.compile.DBCCompileError) InvocationTargetException(java.lang.reflect.InvocationTargetException) 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) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor)

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