Search in sources :

Example 1 with IValueManager

use of org.jkiss.dbeaver.ui.data.IValueManager 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 IValueManager

use of org.jkiss.dbeaver.ui.data.IValueManager 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)

Aggregations

Point (org.eclipse.swt.graphics.Point)2 DBException (org.jkiss.dbeaver.DBException)2 IValueEditor (org.jkiss.dbeaver.ui.data.IValueEditor)2 IValueManager (org.jkiss.dbeaver.ui.data.IValueManager)2