use of org.jkiss.dbeaver.model.edit.DBECommandContext in project dbeaver by serge-rider.
the class EntityEditor method showChanges.
public int showChanges(boolean allowSave) {
DBECommandContext commandContext = getCommandContext();
if (commandContext == null) {
return IDialogConstants.CANCEL_ID;
}
Collection<? extends DBECommand> commands = commandContext.getFinalCommands();
if (CommonUtils.isEmpty(commands)) {
return IDialogConstants.IGNORE_ID;
}
StringBuilder script = new StringBuilder();
try {
saveInProgress = true;
UIUtils.runInProgressService(monitor -> {
monitor.beginTask("Generate SQL script", commands.size());
Map<String, Object> validateOptions = new HashMap<>();
for (DBECommand command : commands) {
monitor.subTask(command.getTitle());
try {
command.validateCommand(monitor, validateOptions);
} catch (final DBException e) {
throw new InvocationTargetException(e);
}
Map<String, Object> options = new HashMap<>();
options.put(DBPScriptObject.OPTION_OBJECT_SAVE, true);
DBPDataSource dataSource = getDatabaseObject().getDataSource();
try {
DBEPersistAction[] persistActions = command.getPersistActions(monitor, getExecutionContext(), options);
script.append(SQLUtils.generateScript(dataSource, persistActions, false));
} catch (DBException e) {
throw new InvocationTargetException(e);
}
monitor.worked(1);
}
monitor.done();
});
} catch (InterruptedException e) {
return IDialogConstants.CANCEL_ID;
} catch (InvocationTargetException e) {
log.error(e);
DBWorkbench.getPlatformUI().showError("Script generate error", "Couldn't generate alter script", e.getTargetException());
return IDialogConstants.CANCEL_ID;
} finally {
saveInProgress = false;
}
if (script.length() == 0) {
return IDialogConstants.PROCEED_ID;
}
ChangesPreviewer changesPreviewer = new ChangesPreviewer(script, allowSave);
UIUtils.syncExec(changesPreviewer);
return changesPreviewer.getResult();
}
use of org.jkiss.dbeaver.model.edit.DBECommandContext in project dbeaver by serge-rider.
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);
}
}
use of org.jkiss.dbeaver.model.edit.DBECommandContext in project dbeaver by serge-rider.
the class TabbedFolderPageForm method createControl.
@Override
public void createControl(Composite parent) {
this.boldFont = UIUtils.makeBoldFont(parent.getFont());
// ScrolledComposite scrolled = new ScrolledComposite(parent, SWT.V_SCROLL);
// scrolled.setLayout(new GridLayout(1, false));
propertiesGroup = new Composite(parent, SWT.NONE);
// CSSUtils.setCSSClass(propertiesGroup, DBStyles.COLORED_BY_CONNECTION_TYPE);
curPropertySource = input.getPropertySource();
DBECommandContext commandContext = input.getCommandContext();
if (commandContext != null) {
commandContext.addCommandListener(new DBECommandAdapter() {
@Override
public void onCommandChange(DBECommand<?> command) {
UIUtils.asyncExec(() -> {
updateEditButtonsState();
if (command instanceof DBECommandProperty) {
// We need to exclude current prop from update
// Simple value compare on update is not enough because value can be transformed (e.g. uppercased)
// and it will differ from the value in edit control
Object propId = ((DBECommandProperty<?>) command).getHandler().getId();
updateOtherPropertyValues(propId);
}
});
}
@Override
public void onSave() {
UIUtils.asyncExec(() -> updateEditButtonsState());
}
@Override
public void onReset() {
UIUtils.asyncExec(() -> {
refreshProperties();
updateEditButtonsState();
});
}
});
}
propertiesGroup.addDisposeListener(e -> dispose());
refreshProperties();
}
use of org.jkiss.dbeaver.model.edit.DBECommandContext in project dbeaver by serge-rider.
the class EntityEditor method revertChanges.
public void revertChanges() {
if (isDirty()) {
if (ConfirmationDialog.showConfirmDialog(ResourceBundle.getBundle(UINavigatorMessages.BUNDLE_NAME), null, NavigatorPreferences.CONFIRM_ENTITY_REVERT, ConfirmationDialog.QUESTION, getDatabaseObject().getName()) != IDialogConstants.YES_ID) {
return;
}
DBECommandContext commandContext = getCommandContext();
if (commandContext != null) {
commandContext.resetChanges(true);
}
refreshPart(this, false);
firePropertyChange(IEditorPart.PROP_DIRTY);
}
}
use of org.jkiss.dbeaver.model.edit.DBECommandContext in project dbeaver by serge-rider.
the class TabbedFolderPageForm method updateEditButtonsState.
private void updateEditButtonsState() {
if (saveButton == null || saveButton.isDisposed()) {
return;
}
DBECommandContext commandContext = input.getCommandContext();
boolean isDirty = commandContext != null && commandContext.isDirty();
saveButton.setEnabled(isDirty);
revertButton.setEnabled(isDirty);
scriptButton.setEnabled(isDirty);
}
Aggregations