use of org.jkiss.dbeaver.model.edit.DBECommandContext in project dbeaver by serge-rider.
the class NavigatorObjectsDeleter method appendScript.
private void appendScript(final DBRProgressMonitor monitor, final StringBuilder sql, final DBNDatabaseNode node) throws InvocationTargetException {
if (!(node.getParentNode() instanceof DBNContainer)) {
return;
}
final DBSObject object = node.getObject();
if (object == null) {
return;
}
final DBEObjectMaker objectMaker = DBWorkbench.getPlatform().getEditorsRegistry().getObjectManager(object.getClass(), DBEObjectMaker.class);
if (objectMaker == null) {
return;
}
final boolean supportsCascade = (objectMaker.getMakerOptions(object.getDataSource()) & DBEObjectMaker.FEATURE_DELETE_CASCADE) != 0;
final NavigatorHandlerObjectBase.CommandTarget commandTarget;
try {
commandTarget = NavigatorHandlerObjectBase.getCommandTarget(window, node.getParentNode(), object.getClass(), false);
} catch (DBException e) {
log.warn(e);
return;
}
if (commandContext == null) {
commandContext = commandTarget.getContext();
}
if (!object.isPersisted() || commandTarget.getEditor() != null) {
return;
}
final Map<String, Object> deleteOptions;
if (supportsCascade && deleteCascade) {
deleteOptions = OPTIONS_CASCADE;
} else {
deleteOptions = Collections.emptyMap();
}
try {
objectMaker.deleteObject(commandTarget.getContext(), node.getObject(), deleteOptions);
} catch (DBException e) {
log.warn(e);
return;
}
final StringBuilder script = new StringBuilder();
final DBECommandContext commandContext = commandTarget.getContext();
Collection<? extends DBECommand> commands = commandContext.getFinalCommands();
try {
for (DBECommand command : commands) {
final DBEPersistAction[] persistActions = command.getPersistActions(monitor, commandContext.getExecutionContext(), deleteOptions);
script.append(SQLUtils.generateScript(commandContext.getExecutionContext().getDataSource(), persistActions, false));
if (script.length() == 0) {
script.append(SQLUtils.generateComments(commandContext.getExecutionContext().getDataSource(), persistActions, false));
}
}
} catch (DBException e) {
throw new InvocationTargetException(e);
}
commandTarget.getContext().resetChanges(true);
if (sql.length() != 0) {
sql.append("\n");
}
sql.append(script);
}
use of org.jkiss.dbeaver.model.edit.DBECommandContext in project dbeaver by serge-rider.
the class EntityEditor method dispose.
@Override
public void dispose() {
if (breadcrumbsMenu != null) {
breadcrumbsMenu.dispose();
breadcrumbsMenu = null;
}
for (Map.Entry<IEditorPart, IEditorActionBarContributor> entry : actionContributors.entrySet()) {
GlobalContributorManager.getInstance().removeContributor(entry.getValue(), entry.getKey());
}
actionContributors.clear();
DBECommandContext commandContext = getCommandContext();
if (commandListener != null && commandContext != null) {
commandContext.removeCommandListener(commandListener);
commandListener = null;
}
super.dispose();
if (getDatabaseObject() != null && commandContext != null) {
commandContext.resetChanges(true);
// // Remove all non-persisted objects
// for (DBPObject object : getCommandContext().getEditedObjects()) {
// if (object instanceof DBPPersistedObject && !((DBPPersistedObject)object).isPersisted()) {
// dataSource.getContainer().fireEvent(new DBPEvent(DBPEvent.Action.OBJECT_REMOVE, (DBSObject) object));
// }
// }
}
this.editorMap.clear();
this.activeEditor = null;
}
use of org.jkiss.dbeaver.model.edit.DBECommandContext in project dbeaver by serge-rider.
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 serge-rider.
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 serge-rider.
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;
}
}
Aggregations