Search in sources :

Example 1 with IValueEditorStandalone

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;
}
Also used : DBException(org.jkiss.dbeaver.DBException) IStatus(org.eclipse.core.runtime.IStatus) Composite(org.eclipse.swt.widgets.Composite) FillLayout(org.eclipse.swt.layout.FillLayout) IValueEditor(org.jkiss.dbeaver.ui.data.IValueEditor) DBException(org.jkiss.dbeaver.DBException) MalformedURLException(java.net.MalformedURLException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GridData(org.eclipse.swt.layout.GridData) UIJob(org.eclipse.ui.progress.UIJob) IValueEditorStandalone(org.jkiss.dbeaver.ui.data.IValueEditorStandalone) Nullable(org.jkiss.code.Nullable)

Example 2 with IValueEditorStandalone

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();
}
Also used : IValueEditorStandalone(org.jkiss.dbeaver.ui.data.IValueEditorStandalone)

Aggregations

IValueEditorStandalone (org.jkiss.dbeaver.ui.data.IValueEditorStandalone)2 MalformedURLException (java.net.MalformedURLException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 GridData (org.eclipse.swt.layout.GridData)1 Composite (org.eclipse.swt.widgets.Composite)1 UIJob (org.eclipse.ui.progress.UIJob)1 Nullable (org.jkiss.code.Nullable)1 DBException (org.jkiss.dbeaver.DBException)1 IValueEditor (org.jkiss.dbeaver.ui.data.IValueEditor)1