use of org.jkiss.dbeaver.model.impl.data.DBDValueError in project dbeaver by dbeaver.
the class ValueViewerPanel method viewValue.
private void viewValue(boolean forceRefresh) {
if (valueSaving) {
return;
}
if (valueManager == null || valueEditor == null) {
forceRefresh = true;
}
if (forceRefresh) {
cleanupPanel();
referenceValueEditor = new ReferenceValueEditor(previewController, valueEditor);
final boolean referenceValue = referenceValueEditor.isReferenceValue();
if (referenceValue) {
previewController.setEditType(IValueController.EditType.INLINE);
} else {
previewController.setEditType(IValueController.EditType.PANEL);
}
// Create a new one
valueManager = previewController.getValueManager();
try {
valueEditor = valueManager.createEditor(previewController);
} catch (Throwable e) {
DBWorkbench.getPlatformUI().showError("Value preview", "Can't create value viewer", e);
return;
}
if (valueEditor != null) {
try {
valueEditor.createControl();
} catch (Exception e) {
log.error(e);
}
boolean singleLineEditor = false;
Control control = valueEditor.getControl();
if (control != null) {
singleLineEditor = control instanceof Combo || control instanceof CCombo || control instanceof Button || (control instanceof Text && (control.getStyle() & SWT.MULTI) == 0);
UIUtils.addFocusTracker(presentation.getController().getSite(), VALUE_VIEW_CONTROL_ID, control);
presentation.getController().lockActionsByFocus(control);
}
if (referenceValue || singleLineEditor) {
GridLayout gl = new GridLayout(1, false);
viewPlaceholder.setLayout(gl);
valueEditor.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
referenceValueEditor.setValueEditor(valueEditor);
referenceValueEditor.createEditorSelector(viewPlaceholder);
} else {
viewPlaceholder.setLayout(new FillLayout());
}
} else {
final Composite placeholder = UIUtils.createPlaceholder(viewPlaceholder, 1);
placeholder.setBackground(placeholder.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
placeholder.addPaintListener(e -> {
Rectangle bounds = placeholder.getBounds();
String message = "No editor for [" + previewController.getValueType().getTypeName() + "]";
Point ext = e.gc.textExtent(message);
e.gc.drawText(message, (bounds.width - ext.x) / 2, bounds.height / 3 + 20);
});
referenceValueEditor = null;
}
viewPlaceholder.layout();
}
if (valueEditor instanceof BaseValueEditor) {
((BaseValueEditor) valueEditor).setAutoSaveEnabled(false);
}
if (valueEditor != null) {
try {
Object newValue = previewController.getValue();
if (newValue instanceof DBDValueError) {
// Error value. Do not populate it in value viewer
} else if (newValue instanceof DBDValue) {
// Do not check for difference
valueEditor.primeEditorValue(newValue);
} else {
Object oldValue = null;
try {
if (previewController.getExecutionContext() != null) {
oldValue = valueEditor.extractEditorValue();
}
} catch (Throwable e) {
// Some error extracting current value
// This may happen if we were disconnected
}
if (forceRefresh || !CommonUtils.equalObjects(oldValue, newValue)) {
valueEditor.primeEditorValue(newValue);
}
}
} catch (DBException e) {
log.error(e);
}
valueEditor.setDirty(false);
}
if (valueEditor instanceof BaseValueEditor) {
((BaseValueEditor) valueEditor).setAutoSaveEnabled(true);
}
}
Aggregations