From 9f39514b6bcf72b8e211aef9ad43d2e9a60145a9 Mon Sep 17 00:00:00 2001 From: "serge@jkiss.org" Date: Fri, 8 Jun 2018 23:25:02 +0300 Subject: [PATCH] Save edit value in RSV Former-commit-id: 341955a2286233e87128ed1dbf0b9f7022be1ef3 --- .../resultset/AbstractPresentation.java | 6 +++ .../resultset/IResultSetPresentation.java | 2 + .../controls/resultset/ResultSetViewer.java | 1 + .../spreadsheet/SpreadsheetPresentation.java | 48 +++++++++++++------ 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/controls/resultset/AbstractPresentation.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/controls/resultset/AbstractPresentation.java index 8edd5acdcc..8614f36448 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/controls/resultset/AbstractPresentation.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/controls/resultset/AbstractPresentation.java @@ -49,6 +49,7 @@ public abstract class AbstractPresentation implements IResultSetPresentation, IS public static final String RESULTS_CONTROL_CONTEXT_ID = "org.jkiss.dbeaver.ui.context.resultset.focused"; public static final StructuredSelection EMPTY_SELECTION = new StructuredSelection(); public static final String RESULT_SET_PRESENTATION_CONTEXT_MENU = "org.jkiss.dbeaver.ui.controls.resultset.conext.menu"; + public static final String DATA_VALUE_CONTROLLER = "org.jkiss.dbeaver.resultset.value-controller"; @NotNull protected IResultSetController controller; @@ -62,6 +63,11 @@ public abstract class AbstractPresentation implements IResultSetPresentation, IS return controller; } + @Override + public void applyChanges() { + // Do nothing + } + @Override public void createPresentation(@NotNull final IResultSetController controller, @NotNull Composite parent) { this.controller = controller; diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/controls/resultset/IResultSetPresentation.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/controls/resultset/IResultSetPresentation.java index 4cdf6af0e1..f7d8870cb0 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/controls/resultset/IResultSetPresentation.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/controls/resultset/IResultSetPresentation.java @@ -71,6 +71,8 @@ public interface IResultSetPresentation { void updateValueView(); + void applyChanges(); + /** * Called by controller to fill context menu. * Note: context menu invocation must be initiated by presentation, then it should call controller's diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/controls/resultset/ResultSetViewer.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/controls/resultset/ResultSetViewer.java index f3006c9d19..200567cbf3 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/controls/resultset/ResultSetViewer.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/controls/resultset/ResultSetViewer.java @@ -2891,6 +2891,7 @@ public class ResultSetViewer extends Viewer */ private boolean applyChanges(@Nullable final DBRProgressMonitor monitor, @Nullable final ResultSetPersister.DataUpdateListener listener) { + //getActivePresentation(). try { final ResultSetPersister persister = createDataPersister(false); final ResultSetPersister.DataUpdateListener applyListener = success -> { diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/controls/resultset/spreadsheet/SpreadsheetPresentation.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/controls/resultset/spreadsheet/SpreadsheetPresentation.java index 5ee0581c03..f938de49bd 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/controls/resultset/spreadsheet/SpreadsheetPresentation.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/controls/resultset/spreadsheet/SpreadsheetPresentation.java @@ -139,6 +139,7 @@ public class SpreadsheetPresentation extends AbstractPresentation implements IRe private boolean showCelIcons = true; private boolean colorizeDataTypes = true; private boolean rightJustifyNumbers = true; + private IValueEditor activeInlineEditor; public SpreadsheetPresentation() { findReplaceTarget = new SpreadsheetFindReplaceTarget(this); @@ -155,6 +156,22 @@ public class SpreadsheetPresentation extends AbstractPresentation implements IRe return dataContainer == null ? null : dataContainer.getDataSource(); } + @Override + public void applyChanges() { + if (activeInlineEditor != null && activeInlineEditor.getControl() != null && !activeInlineEditor.getControl().isDisposed()) { + IValueController valueController = (IValueController) activeInlineEditor.getControl().getData(DATA_VALUE_CONTROLLER); + if (valueController != null) { + try { + Object value = activeInlineEditor.extractEditorValue(); + valueController.updateValue(value, true); + } catch (DBException e) { + DBUserInterface.getInstance().showError("Error extracting editor value", null, e); + } + } + spreadsheet.cancelInlineEditor(); + } + } + @Override public void createPresentation(@NotNull IResultSetController controller, @NotNull Composite parent) { super.createPresentation(controller, parent); @@ -820,6 +837,7 @@ public class SpreadsheetPresentation extends AbstractPresentation implements IRe return null; } spreadsheet.cancelInlineEditor(); + activeInlineEditor = null; placeholder = new Composite(spreadsheet, SWT.NONE); placeholder.setFont(spreadsheet.getFont()); @@ -865,48 +883,50 @@ public class SpreadsheetPresentation extends AbstractPresentation implements IRe } */ - final IValueEditor editor; try { - editor = valueController.getValueManager().createEditor(valueController); + activeInlineEditor = valueController.getValueManager().createEditor(valueController); } catch (Exception e) { DBUserInterface.getInstance().showError("Cannot edit value", null, e); return null; } - if (editor != null) { - editor.createControl(); + if (activeInlineEditor != null) { + activeInlineEditor.createControl(); + if (activeInlineEditor.getControl() != null) { + activeInlineEditor.getControl().setData(DATA_VALUE_CONTROLLER, valueController); + } } - if (editor instanceof IValueEditorStandalone) { - valueController.registerEditor((IValueEditorStandalone)editor); - Control editorControl = editor.getControl(); + if (activeInlineEditor instanceof IValueEditorStandalone) { + valueController.registerEditor((IValueEditorStandalone) activeInlineEditor); + Control editorControl = activeInlineEditor.getControl(); if (editorControl != null) { - editorControl.addDisposeListener(e -> valueController.unregisterEditor((IValueEditorStandalone)editor)); + editorControl.addDisposeListener(e -> valueController.unregisterEditor((IValueEditorStandalone) activeInlineEditor)); } // show dialog in separate job to avoid block new UIJob("Open separate editor") { @Override public IStatus runInUIThread(IProgressMonitor monitor) { - ((IValueEditorStandalone)editor).showValueEditor(); + ((IValueEditorStandalone) activeInlineEditor).showValueEditor(); return Status.OK_STATUS; } }.schedule(); //((IValueEditorStandalone)editor).showValueEditor(); } else { // Set editable value - if (editor != null) { + if (activeInlineEditor != null) { try { - editor.primeEditorValue(valueController.getValue()); + activeInlineEditor.primeEditorValue(valueController.getValue()); } catch (DBException e) { log.error(e); } - editor.setDirty(false); + activeInlineEditor.setDirty(false); } } if (inline) { - if (editor != null) { + if (activeInlineEditor != null) { spreadsheet.showCellEditor(placeholder); - return editor.getControl(); + return activeInlineEditor.getControl(); } else { // No editor was created so just drop placeholder placeholder.dispose(); -- GitLab