提交 9f39514b 编写于 作者: S serge@jkiss.org

Save edit value in RSV


Former-commit-id: 341955a2
上级 abddd270
......@@ -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;
......
......@@ -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
......
......@@ -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 -> {
......
......@@ -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();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册