use of org.jkiss.dbeaver.ui.data.IValueEditorStandalone in project dbeaver by serge-rider.
the class SpreadsheetPresentation method openValueEditor.
@Override
@Nullable
public Control openValueEditor(final boolean inline) {
// The control that will be the editor must be a child of the Table
DBDAttributeBinding attr = getFocusAttribute();
ResultSetRow row = getFocusRow();
if (attr == null || row == null) {
return null;
}
if (!inline) {
for (Iterator<SpreadsheetValueController> iterator = openEditors.keySet().iterator(); iterator.hasNext(); ) {
SpreadsheetValueController valueController = iterator.next();
if (attr == valueController.getBinding() && row == valueController.getCurRow()) {
IValueEditorStandalone editor = openEditors.get(valueController);
if (editor.getControl() != null && !editor.getControl().isDisposed()) {
editor.showValueEditor();
return null;
} else {
// Remove disposed editor from the list
iterator.remove();
}
}
}
}
// if (controller.isAttributeReadOnly(attr) && inline) {
// // No inline editors for readonly columns
// return null;
// }
Composite placeholder = null;
if (inline) {
if (controller.isReadOnly()) {
return null;
}
spreadsheet.cancelInlineEditor();
placeholder = new Composite(spreadsheet, SWT.NONE);
placeholder.setFont(spreadsheet.getFont());
placeholder.setLayout(new FillLayout());
GridData gd = new GridData(GridData.FILL_BOTH);
gd.horizontalIndent = 0;
gd.verticalIndent = 0;
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
placeholder.setLayoutData(gd);
controller.lockActionsByControl(placeholder);
}
SpreadsheetValueController valueController = new SpreadsheetValueController(controller, attr, row, inline ? IValueController.EditType.INLINE : IValueController.EditType.EDITOR, placeholder);
IValueController.EditType[] supportedEditTypes = valueController.getValueManager().getSupportedEditTypes();
if (supportedEditTypes.length == 0) {
if (placeholder != null) {
placeholder.dispose();
}
return null;
}
/*
if (inline &&
(!ArrayUtils.contains(supportedEditTypes, IValueController.EditType.INLINE) || controller.isAttributeReadOnly(attr)) &&
ArrayUtils.contains(supportedEditTypes, IValueController.EditType.PANEL))
{
// Inline editor isn't supported but panel viewer is
// Enable panel
if (!isPreviewVisible()) {
togglePreview();
}
placeholder.dispose();
return null;
}
*/
final IValueEditor editor;
try {
editor = valueController.getValueManager().createEditor(valueController);
} catch (Exception e) {
UIUtils.showErrorDialog(spreadsheet.getShell(), "Cannot edit value", null, e);
return null;
}
if (editor != null) {
editor.createControl();
}
if (editor instanceof IValueEditorStandalone) {
valueController.registerEditor((IValueEditorStandalone) editor);
// show dialog in separate job to avoid block
new UIJob("Open separate editor") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
((IValueEditorStandalone) editor).showValueEditor();
return Status.OK_STATUS;
}
}.schedule();
//((IValueEditorStandalone)editor).showValueEditor();
} else {
// Set editable value
if (editor != null) {
try {
editor.primeEditorValue(valueController.getValue());
} catch (DBException e) {
log.error(e);
}
editor.setDirty(false);
}
}
if (inline) {
if (editor != null) {
spreadsheet.showCellEditor(placeholder);
return editor.getControl();
} else {
// No editor was created so just drop placeholder
placeholder.dispose();
// Probably we can just show preview panel
if (ArrayUtils.contains(supportedEditTypes, IValueController.EditType.PANEL)) {
// Inline editor isn't supported but panel viewer is
// Enable panel
controller.activatePanel(ViewValuePanel.PANEL_ID, true, true);
return null;
}
}
}
return null;
}
use of org.jkiss.dbeaver.ui.data.IValueEditorStandalone in project dbeaver by serge-rider.
the class SpreadsheetPresentation method closeEditors.
/////////////////////////////////////////////////
// Edit
private void closeEditors() {
List<IValueEditorStandalone> editors = new ArrayList<>(openEditors.values());
for (IValueEditorStandalone editor : editors) {
if (editor.getControl() != null && !editor.getControl().isDisposed()) {
editor.closeValueEditor();
}
}
openEditors.clear();
}
Aggregations