Search in sources :

Example 21 with DBECommandContext

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();
}
Also used : DBException(org.jkiss.dbeaver.DBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBECommand(org.jkiss.dbeaver.model.edit.DBECommand) DBECommandContext(org.jkiss.dbeaver.model.edit.DBECommandContext) DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject)

Example 22 with DBECommandContext

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);
    }
}
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 23 with DBECommandContext

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();
}
Also used : DBECommandProperty(org.jkiss.dbeaver.model.edit.prop.DBECommandProperty) DBECommandContext(org.jkiss.dbeaver.model.edit.DBECommandContext) DBECommandAdapter(org.jkiss.dbeaver.model.impl.edit.DBECommandAdapter) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject)

Example 24 with DBECommandContext

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);
    }
}
Also used : DBECommandContext(org.jkiss.dbeaver.model.edit.DBECommandContext)

Example 25 with DBECommandContext

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);
}
Also used : 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