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);
}
}
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);
}
}
}
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()));
}
}
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;
}
}
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);
}
}
}
Aggregations