Search in sources :

Example 26 with DBECommandContext

use of org.jkiss.dbeaver.model.edit.DBECommandContext 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 27 with DBECommandContext

use of org.jkiss.dbeaver.model.edit.DBECommandContext in project dbeaver by dbeaver.

the class EntityEditor method redoChanges.

public void redoChanges() {
    IUndoManager undoManager = getAdapter(IUndoManager.class);
    if (undoManager != null) {
        undoManager.redo();
    } else {
        DBECommandContext commandContext = getCommandContext();
        if (commandContext != null && commandContext.getRedoCommand() != null) {
            commandContext.redoCommand();
            firePropertyChange(IEditorPart.PROP_DIRTY);
        }
    }
}
Also used : IUndoManager(org.eclipse.jface.text.IUndoManager) DBECommandContext(org.jkiss.dbeaver.model.edit.DBECommandContext)

Example 28 with DBECommandContext

use of org.jkiss.dbeaver.model.edit.DBECommandContext in project dbeaver by dbeaver.

the class EntityEditor method refreshPart.

@Override
public void refreshPart(final Object source, boolean force) {
    if (getContainer() == null || getContainer().isDisposed() || isSaveInProgress()) {
        return;
    }
    if (force && isDirty()) {
        if (ConfirmationDialog.showConfirmDialog(ResourceBundle.getBundle(UINavigatorMessages.BUNDLE_NAME), null, NavigatorPreferences.CONFIRM_ENTITY_REVERT, ConfirmationDialog.QUESTION, getTitle()) != IDialogConstants.YES_ID) {
            return;
        }
    }
    if (source instanceof DBNEvent && ((DBNEvent) source).getNodeChange() == DBNEvent.NodeChange.REFRESH) {
    // This may happen if editor was refreshed indirectly (it is a child of refreshed node)
    // force = true;
    }
    if (force && getDatabaseObject().isPersisted()) {
        // Lists and commands should be refreshed only if we make real refresh from remote storage
        // Otherwise just update object's properties
        DBECommandContext commandContext = getCommandContext();
        if (commandContext != null && commandContext.isDirty()) {
            // Just clear command context. Do not undo because object state was already refreshed
            commandContext.resetChanges(true);
        }
    }
    DBSObject databaseObject = getEditorInput().getDatabaseObject();
    if (databaseObject != null) {
        // Refresh visual content in parts
        for (IEditorPart editor : editorMap.values()) {
            if (editor instanceof IRefreshablePart) {
                ((IRefreshablePart) editor).refreshPart(source, force);
            }
        }
    }
    setPartName(getEditorInput().getName());
    setTitleImage(getEditorInput().getImageDescriptor());
    if (hasPropertiesEditor) {
        // Update main editor image
        setPageImage(0, DBeaverIcons.getImage(getEditorInput().getNavigatorNode().getNodeIconDefault()));
    }
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBECommandContext(org.jkiss.dbeaver.model.edit.DBECommandContext)

Example 29 with DBECommandContext

use of org.jkiss.dbeaver.model.edit.DBECommandContext in project dbeaver by dbeaver.

the class EntityEditor method promptToSaveOnClose.

@Override
public int promptToSaveOnClose() {
    List<String> changedSubEditors = new ArrayList<>();
    final DBECommandContext commandContext = getCommandContext();
    if (commandContext != null && commandContext.isDirty()) {
        changedSubEditors.add(UINavigatorMessages.registry_entity_editor_descriptor_name);
    }
    for (IEditorPart editor : editorMap.values()) {
        if (editor.isDirty()) {
            EntityEditorDescriptor editorDescriptor = EntityEditorsRegistry.getInstance().getEntityEditor(editor);
            if (editorDescriptor != null) {
                changedSubEditors.add(editorDescriptor.getName());
            }
        }
    }
    String subEditorsString = changedSubEditors.isEmpty() ? "" : "(" + String.join(", ", changedSubEditors) + ")";
    final int result = ConfirmationDialog.showConfirmDialog(ResourceBundle.getBundle(UINavigatorMessages.BUNDLE_NAME), getSite().getShell(), NavigatorPreferences.CONFIRM_ENTITY_EDIT_CLOSE, ConfirmationDialog.QUESTION_WITH_CANCEL, getEditorInput().getNavigatorNode().getNodeName(), subEditorsString);
    if (result == IDialogConstants.YES_ID) {
        // getWorkbenchPart().getSite().getPage().saveEditor(this, false);
        return ISaveablePart2.YES;
    } else if (result == IDialogConstants.NO_ID) {
        return ISaveablePart2.NO;
    } else {
        return ISaveablePart2.CANCEL;
    }
}
Also used : DBECommandContext(org.jkiss.dbeaver.model.edit.DBECommandContext) Point(org.eclipse.swt.graphics.Point)

Example 30 with DBECommandContext

use of org.jkiss.dbeaver.model.edit.DBECommandContext in project dbeaver by dbeaver.

the class EntityEditor method undoChanges.

public void undoChanges() {
    IUndoManager undoManager = getAdapter(IUndoManager.class);
    if (undoManager != null) {
        undoManager.undo();
    } else {
        DBECommandContext commandContext = getCommandContext();
        if (commandContext != null && commandContext.getUndoCommand() != null) {
            if (!getDatabaseObject().isPersisted() && commandContext.getUndoCommands().size() == 1) {
                // Let's ask user about it
                if (ConfirmationDialog.showConfirmDialog(ResourceBundle.getBundle(UINavigatorMessages.BUNDLE_NAME), null, NavigatorPreferences.CONFIRM_ENTITY_REJECT, ConfirmationDialog.QUESTION, getDatabaseObject().getName()) != IDialogConstants.YES_ID) {
                    return;
                }
            }
            commandContext.undoCommand();
            firePropertyChange(IEditorPart.PROP_DIRTY);
        }
    }
}
Also used : IUndoManager(org.eclipse.jface.text.IUndoManager) DBECommandContext(org.jkiss.dbeaver.model.edit.DBECommandContext)

Aggregations

DBECommandContext (org.jkiss.dbeaver.model.edit.DBECommandContext)33 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 DBException (org.jkiss.dbeaver.DBException)7 IUndoManager (org.eclipse.jface.text.IUndoManager)6 DBECommand (org.jkiss.dbeaver.model.edit.DBECommand)6 DBEPersistAction (org.jkiss.dbeaver.model.edit.DBEPersistAction)6 Point (org.eclipse.swt.graphics.Point)5 IEditorPart (org.eclipse.ui.IEditorPart)4 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)4 DBECommandAdapter (org.jkiss.dbeaver.model.impl.edit.DBECommandAdapter)4 EntityEditor (org.jkiss.dbeaver.ui.editors.entity.EntityEditor)4 DBCException (org.jkiss.dbeaver.model.exec.DBCException)3 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)3 CTabFolder (org.eclipse.swt.custom.CTabFolder)2 Image (org.eclipse.swt.graphics.Image)2 PostgreForeignTableManager (org.jkiss.dbeaver.ext.postgresql.edit.PostgreForeignTableManager)2 PostgreTableColumnManager (org.jkiss.dbeaver.ext.postgresql.edit.PostgreTableColumnManager)2 DBPNamedObject (org.jkiss.dbeaver.model.DBPNamedObject)2 DBEObjectMaker (org.jkiss.dbeaver.model.edit.DBEObjectMaker)2