Search in sources :

Example 1 with IValueEditor

use of org.jkiss.dbeaver.ui.data.IValueEditor in project dbeaver by serge-rider.

the class ColorSettingsDialog method createValueEditor.

private IValueEditor createValueEditor(Composite editorPlaceholder, int index) {
    try {
        UIUtils.disposeChildControls(editorPlaceholder);
        IValueManager valueManager = ValueManagerRegistry.findValueManager(resultSetViewer.getDataSource(), attribute, attribute.getValueHandler().getValueObjectType(attribute));
        ColorValueController valueController = new ColorValueController(settingsGroup) {

            @Override
            public Object getValue() {
                if (curOverride == null) {
                    return null;
                }
                Object[] attributeValues = curOverride.getAttributeValues();
                if (attributeValues == null || index > attributeValues.length - 1) {
                    return null;
                }
                return attributeValues[index];
            }
        };
        valueController.setInlinePlaceholder(editorPlaceholder);
        IValueEditor editor = valueManager.createEditor(valueController);
        if (editor == null) {
            Label errorLabel = new Label(editorPlaceholder, SWT.NONE);
            errorLabel.setText("N/A");
        } else {
            editor.createControl();
            // if (attribute.getValueHandler() instanceof DBDValueDefaultGenerator) {
            // Object defaultValue = ((DBDValueDefaultGenerator) attribute.getValueHandler()).generateDefaultValue(attribute);
            // editor.primeEditorValue(defaultValue);
            // }
            editor.getControl().addListener(SWT.Modify, event -> {
                if (curOverride != null) {
                    try {
                        Object value = editor.extractEditorValue();
                        Object[] attributeValues = curOverride.getAttributeValues();
                        int valueCount = index + 1;
                        if (attributeValues == null) {
                            attributeValues = new Object[valueCount];
                        } else if (attributeValues.length < valueCount) {
                            Object[] newAttributeValues = new Object[valueCount];
                            System.arraycopy(attributeValues, 0, newAttributeValues, 0, attributeValues.length);
                            attributeValues = newAttributeValues;
                        }
                        attributeValues[index] = value;
                        curOverride.setAttributeValues(attributeValues);
                        updateCurrentTreeItem();
                    // updateColumnItem(attributeTable.getSelection()[0]);
                    } catch (Exception e) {
                        log.error(e);
                    }
                }
            });
        }
        return editor;
    } catch (DBException e) {
        log.error(e);
    }
    return null;
}
Also used : DBException(org.jkiss.dbeaver.DBException) IValueManager(org.jkiss.dbeaver.ui.data.IValueManager) IValueEditor(org.jkiss.dbeaver.ui.data.IValueEditor) Point(org.eclipse.swt.graphics.Point) DBException(org.jkiss.dbeaver.DBException)

Example 2 with IValueEditor

use of org.jkiss.dbeaver.ui.data.IValueEditor in project dbeaver by serge-rider.

the class FilterValueEditDialog method createSingleValueEditor.

private void createSingleValueEditor(Composite composite) {
    Composite editorPlaceholder = UIUtils.createPlaceholder(composite, 1);
    editorPlaceholder.setLayoutData(new GridData(GridData.FILL_BOTH));
    editorPlaceholder.setLayout(new FillLayout());
    ResultSetRow singleRow = handler.getRows()[0];
    final ResultSetValueController valueController = new ResultSetValueController(handler.getViewer(), handler.getAttribute(), singleRow, IValueController.EditType.INLINE, editorPlaceholder) {

        @Override
        public boolean isReadOnly() {
            // Filter value is never read-only
            return false;
        }
    };
    IValueEditor editor = null;
    try {
        editor = valueController.getValueManager().createEditor(valueController);
    } catch (Exception e) {
        log.error("Can't create inline value editor", e);
    }
    if (editor == null) {
        editor = new StringInlineEditor(valueController);
    }
    handler.setEditor(editor);
    editor.createControl();
    try {
        editor.primeEditorValue(valueController.getValue());
    } catch (DBException e) {
        log.error("Error populating filter value", e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) ResultSetValueController(org.jkiss.dbeaver.ui.controls.resultset.ResultSetValueController) StringInlineEditor(org.jkiss.dbeaver.ui.data.editors.StringInlineEditor) ResultSetRow(org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow) FillLayout(org.eclipse.swt.layout.FillLayout) IValueEditor(org.jkiss.dbeaver.ui.data.IValueEditor) DBException(org.jkiss.dbeaver.DBException)

Example 3 with IValueEditor

use of org.jkiss.dbeaver.ui.data.IValueEditor in project dbeaver by dbeaver.

the class ColorSettingsDialog method createValueEditor.

private IValueEditor createValueEditor(Composite editorPlaceholder, int index) {
    try {
        UIUtils.disposeChildControls(editorPlaceholder);
        IValueManager valueManager = ValueManagerRegistry.findValueManager(resultSetViewer.getDataSource(), attribute, attribute.getValueHandler().getValueObjectType(attribute));
        ColorValueController valueController = new ColorValueController(settingsGroup) {

            @Override
            public Object getValue() {
                if (curOverride == null) {
                    return null;
                }
                Object[] attributeValues = curOverride.getAttributeValues();
                if (attributeValues == null || index > attributeValues.length - 1) {
                    return null;
                }
                return attributeValues[index];
            }
        };
        valueController.setInlinePlaceholder(editorPlaceholder);
        IValueEditor editor = valueManager.createEditor(valueController);
        if (editor == null) {
            Label errorLabel = new Label(editorPlaceholder, SWT.NONE);
            errorLabel.setText("N/A");
        } else {
            editor.createControl();
            // if (attribute.getValueHandler() instanceof DBDValueDefaultGenerator) {
            // Object defaultValue = ((DBDValueDefaultGenerator) attribute.getValueHandler()).generateDefaultValue(attribute);
            // editor.primeEditorValue(defaultValue);
            // }
            editor.getControl().addListener(SWT.Modify, event -> {
                if (curOverride != null) {
                    try {
                        Object value = editor.extractEditorValue();
                        Object[] attributeValues = curOverride.getAttributeValues();
                        int valueCount = index + 1;
                        if (attributeValues == null) {
                            attributeValues = new Object[valueCount];
                        } else if (attributeValues.length < valueCount) {
                            Object[] newAttributeValues = new Object[valueCount];
                            System.arraycopy(attributeValues, 0, newAttributeValues, 0, attributeValues.length);
                            attributeValues = newAttributeValues;
                        }
                        attributeValues[index] = value;
                        curOverride.setAttributeValues(attributeValues);
                        updateCurrentTreeItem();
                    // updateColumnItem(attributeTable.getSelection()[0]);
                    } catch (Exception e) {
                        log.error(e);
                    }
                }
            });
        }
        return editor;
    } catch (DBException e) {
        log.error(e);
    }
    return null;
}
Also used : DBException(org.jkiss.dbeaver.DBException) IValueManager(org.jkiss.dbeaver.ui.data.IValueManager) IValueEditor(org.jkiss.dbeaver.ui.data.IValueEditor) Point(org.eclipse.swt.graphics.Point) DBException(org.jkiss.dbeaver.DBException)

Example 4 with IValueEditor

use of org.jkiss.dbeaver.ui.data.IValueEditor in project dbeaver by dbeaver.

the class FilterValueEditDialog method createSingleValueEditor.

private void createSingleValueEditor(Composite composite) {
    Composite editorPlaceholder = UIUtils.createPlaceholder(composite, 1);
    editorPlaceholder.setLayoutData(new GridData(GridData.FILL_BOTH));
    editorPlaceholder.setLayout(new FillLayout());
    ResultSetRow singleRow = handler.getRows()[0];
    final ResultSetValueController valueController = new ResultSetValueController(handler.getViewer(), handler.getAttribute(), singleRow, IValueController.EditType.INLINE, editorPlaceholder) {

        @Override
        public boolean isReadOnly() {
            // Filter value is never read-only
            return false;
        }
    };
    IValueEditor editor = null;
    try {
        editor = valueController.getValueManager().createEditor(valueController);
    } catch (Exception e) {
        log.error("Can't create inline value editor", e);
    }
    if (editor == null) {
        editor = new StringInlineEditor(valueController);
    }
    handler.setEditor(editor);
    editor.createControl();
    try {
        editor.primeEditorValue(valueController.getValue());
    } catch (DBException e) {
        log.error("Error populating filter value", e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) ResultSetValueController(org.jkiss.dbeaver.ui.controls.resultset.ResultSetValueController) StringInlineEditor(org.jkiss.dbeaver.ui.data.editors.StringInlineEditor) ResultSetRow(org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow) FillLayout(org.eclipse.swt.layout.FillLayout) IValueEditor(org.jkiss.dbeaver.ui.data.IValueEditor) DBException(org.jkiss.dbeaver.DBException)

Aggregations

DBException (org.jkiss.dbeaver.DBException)4 IValueEditor (org.jkiss.dbeaver.ui.data.IValueEditor)4 Point (org.eclipse.swt.graphics.Point)2 FillLayout (org.eclipse.swt.layout.FillLayout)2 GridData (org.eclipse.swt.layout.GridData)2 Composite (org.eclipse.swt.widgets.Composite)2 ResultSetRow (org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow)2 ResultSetValueController (org.jkiss.dbeaver.ui.controls.resultset.ResultSetValueController)2 IValueManager (org.jkiss.dbeaver.ui.data.IValueManager)2 StringInlineEditor (org.jkiss.dbeaver.ui.data.editors.StringInlineEditor)2