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;
}
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);
}
}
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;
}
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);
}
}
Aggregations