use of org.jkiss.dbeaver.model.meta.IPropertyValueListProvider in project dbeaver by serge-rider.
the class TabbedFolderPageForm method setEditorValue.
public void setEditorValue(Object object, DBPPropertyDescriptor property, Object value) {
Control editorControl = editorMap.get(property);
Class<?> propertyType = property.getDataType();
// List
String stringValue = objectValueToString(value);
if (editorControl instanceof Combo) {
Combo combo = (Combo) editorControl;
if (property instanceof IPropertyValueListProvider) {
final IPropertyValueListProvider listProvider = (IPropertyValueListProvider) property;
final Object[] items = listProvider.getPossibleValues(object);
final Object[] oldItems = (Object[]) combo.getData(LIST_VALUE_KEY);
combo.setData(LIST_VALUE_KEY, items);
if (items != null) {
if (oldItems == null || !Arrays.equals(items, oldItems)) {
final String[] strings = new String[items.length];
for (int i = 0, itemsLength = items.length; i < itemsLength; i++) {
strings[i] = items[i] instanceof DBPNamedObject ? ((DBPNamedObject) items[i]).getName() : CommonUtils.toString(items[i]);
}
combo.setItems(strings);
}
combo.setText(stringValue);
}
} else if (propertyType.isEnum()) {
if (combo.getItemCount() == 0) {
// Do not refresh enum values - they are static
final Object[] enumConstants = propertyType.getEnumConstants();
final String[] strings = new String[enumConstants.length];
for (int i = 0, itemsLength = enumConstants.length; i < itemsLength; i++) {
strings[i] = ((Enum<?>) enumConstants[i]).name();
}
combo.setItems(strings);
}
combo.setText(stringValue);
}
} else {
if (editorControl instanceof Text) {
Text text = (Text) editorControl;
if (!CommonUtils.equalObjects(text.getText(), stringValue)) {
text.setText(stringValue);
}
} else if (editorControl instanceof Button) {
((Button) editorControl).setSelection(CommonUtils.toBoolean(value));
} else if (editorControl instanceof Link) {
Link link = (Link) editorControl;
link.setData(value);
link.setText(getLinktitle(value));
}
}
}
use of org.jkiss.dbeaver.model.meta.IPropertyValueListProvider in project dbeaver by dbeaver.
the class TabbedFolderPageForm method createEditorControl.
/**
* Supported editors:
* Combo (lists)
* Text (strings, numbers, dates)
* Button (booleans)
*/
public Control createEditorControl(Composite parent, Object object, DBPPropertyDescriptor property, Object value, boolean readOnly) {
// List
if (!readOnly && property instanceof IPropertyValueListProvider) {
final IPropertyValueListProvider listProvider = (IPropertyValueListProvider) property;
Object[] items = listProvider.getPossibleValues(object);
if (items == null && property instanceof ObjectPropertyDescriptor && ((ObjectPropertyDescriptor) property).hasListValueProvider()) {
// It is a list provider but it seems to be lazy and not yet initialized
items = new Object[0];
}
if (items != null) {
final String[] strings = new String[items.length];
for (int i = 0, itemsLength = items.length; i < itemsLength; i++) {
strings[i] = objectValueToString(items[i]);
}
Combo combo = UIUtils.createLabelCombo(parent, property.getDisplayName(), SWT.BORDER | SWT.DROP_DOWN | (listProvider.allowCustomValue() ? SWT.NONE : SWT.READ_ONLY) | (readOnly ? SWT.READ_ONLY : SWT.NONE));
combo.setItems(strings);
combo.setText(objectValueToString(value));
combo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING));
if ((combo.getStyle() & SWT.READ_ONLY) == 0) {
StringContentProposalProvider proposalProvider = new StringContentProposalProvider(strings);
ContentAssistUtils.installContentProposal(combo, new ComboContentAdapter(), proposalProvider);
}
return combo;
}
}
Class<?> propType = property.getDataType();
if (isTextPropertyType(propType)) {
if (property instanceof ObjectPropertyDescriptor && ((ObjectPropertyDescriptor) property).isMultiLine()) {
Label label = UIUtils.createControlLabel(parent, property.getDisplayName());
label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
Text editor = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.WRAP | (readOnly ? SWT.READ_ONLY : SWT.NONE));
editor.setText(objectValueToString(value));
GridData gd = new GridData(GridData.FILL_BOTH);
// Make multline editor at least two lines height
gd.heightHint = (UIUtils.getTextHeight(editor) + editor.getBorderWidth()) * 2;
editor.setLayoutData(gd);
return editor;
} else {
Text text = UIUtils.createLabelText(parent, property.getDisplayName(), objectValueToString(value), SWT.BORDER | (readOnly ? SWT.READ_ONLY : SWT.NONE) | (property instanceof ObjectPropertyDescriptor && ((ObjectPropertyDescriptor) property).isPassword() ? SWT.PASSWORD : SWT.NONE));
text.setLayoutData(new GridData((BeanUtils.isNumericType(propType) ? GridData.HORIZONTAL_ALIGN_BEGINNING : GridData.FILL_HORIZONTAL) | GridData.VERTICAL_ALIGN_BEGINNING));
return text;
}
} else if (BeanUtils.isBooleanType(propType)) {
if (curButtonsContainer == null) {
UIUtils.createEmptyLabel(parent, 1, 1);
curButtonsContainer = new Composite(parent, SWT.NONE);
RowLayout layout = new RowLayout(SWT.HORIZONTAL);
curButtonsContainer.setLayout(layout);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
curButtonsContainer.setLayoutData(gd);
}
Button editor = UIUtils.createCheckbox(curButtonsContainer, property.getDisplayName(), "", CommonUtils.toBoolean(value), 1);
if (readOnly) {
editor.setEnabled(false);
}
return editor;
} else if (!readOnly && propType.isEnum()) {
final Object[] enumConstants = propType.getEnumConstants();
final String[] strings = new String[enumConstants.length];
for (int i = 0, itemsLength = enumConstants.length; i < itemsLength; i++) {
strings[i] = ((Enum) enumConstants[i]).name();
}
Combo combo = UIUtils.createLabelCombo(parent, property.getDisplayName(), SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY | (readOnly ? SWT.READ_ONLY : SWT.NONE));
combo.setItems(strings);
combo.setText(objectValueToString(value));
combo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING));
return combo;
} else if (DBSObject.class.isAssignableFrom(propType) || (property instanceof ObjectPropertyDescriptor && ((ObjectPropertyDescriptor) property).isLinkPossible())) {
UIUtils.createControlLabel(parent, property.getDisplayName());
Composite linkPH = new Composite(parent, SWT.NONE);
{
linkPH.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}
GridLayout layout = new GridLayout(1, false);
layout.marginHeight = 1;
linkPH.setLayout(layout);
Link link = new Link(linkPH, SWT.NONE);
link.setText(getLinktitle(value));
link.setData(value);
link.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DBSObject object = (DBSObject) link.getData();
if (object != null) {
NavigatorHandlerObjectOpen.openEntityEditor(object);
}
}
});
link.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
return link;
} else {
return UIUtils.createLabelText(parent, property.getDisplayName(), objectValueToString(value), SWT.BORDER | SWT.READ_ONLY);
}
}
use of org.jkiss.dbeaver.model.meta.IPropertyValueListProvider in project dbeaver by dbeaver.
the class TabbedFolderPageForm method setEditorValue.
public void setEditorValue(Object object, DBPPropertyDescriptor property, Object value) {
Control editorControl = editorMap.get(property);
Class<?> propertyType = property.getDataType();
// List
String stringValue = objectValueToString(value);
if (editorControl instanceof Combo) {
Combo combo = (Combo) editorControl;
if (property instanceof IPropertyValueListProvider) {
final IPropertyValueListProvider listProvider = (IPropertyValueListProvider) property;
final Object[] items = listProvider.getPossibleValues(object);
final Object[] oldItems = (Object[]) combo.getData(LIST_VALUE_KEY);
combo.setData(LIST_VALUE_KEY, items);
if (items != null) {
if (oldItems == null || !Arrays.equals(items, oldItems)) {
final String[] strings = new String[items.length];
for (int i = 0, itemsLength = items.length; i < itemsLength; i++) {
strings[i] = items[i] instanceof DBPNamedObject ? ((DBPNamedObject) items[i]).getName() : CommonUtils.toString(items[i]);
}
combo.setItems(strings);
}
combo.setText(stringValue);
}
} else if (propertyType.isEnum()) {
if (combo.getItemCount() == 0) {
// Do not refresh enum values - they are static
final Object[] enumConstants = propertyType.getEnumConstants();
final String[] strings = new String[enumConstants.length];
for (int i = 0, itemsLength = enumConstants.length; i < itemsLength; i++) {
strings[i] = ((Enum<?>) enumConstants[i]).name();
}
combo.setItems(strings);
}
combo.setText(stringValue);
}
} else {
if (editorControl instanceof Text) {
Text text = (Text) editorControl;
if (!CommonUtils.equalObjects(text.getText(), stringValue)) {
text.setText(stringValue);
}
} else if (editorControl instanceof Button) {
((Button) editorControl).setSelection(CommonUtils.toBoolean(value));
} else if (editorControl instanceof Link) {
Link link = (Link) editorControl;
link.setData(value);
link.setText(getLinktitle(value));
}
}
}
use of org.jkiss.dbeaver.model.meta.IPropertyValueListProvider in project dbeaver by serge-rider.
the class UIUtils method createCellEditor.
public static CellEditor createCellEditor(Composite parent, Object object, DBPPropertyDescriptor property) {
// List
if (property instanceof IPropertyValueListProvider) {
final IPropertyValueListProvider listProvider = (IPropertyValueListProvider) property;
final Object[] items = listProvider.getPossibleValues(object);
if (items != null) {
final String[] strings = new String[items.length];
for (int i = 0, itemsLength = items.length; i < itemsLength; i++) {
strings[i] = items[i] instanceof DBPNamedObject ? ((DBPNamedObject) items[i]).getName() : CommonUtils.toString(items[i]);
}
final CustomComboBoxCellEditor editor = new CustomComboBoxCellEditor(parent, strings, SWT.DROP_DOWN | (listProvider.allowCustomValue() ? SWT.NONE : SWT.READ_ONLY));
return editor;
}
}
Class<?> propertyType = property.getDataType();
if (propertyType == null || CharSequence.class.isAssignableFrom(propertyType)) {
return new CustomTextCellEditor(parent);
} else if (BeanUtils.isNumericType(propertyType)) {
return new CustomNumberCellEditor(parent, propertyType);
} else if (BeanUtils.isBooleanType(propertyType)) {
return new CustomCheckboxCellEditor(parent);
//return new CheckboxCellEditor(parent);
} else if (propertyType.isEnum()) {
final Object[] enumConstants = propertyType.getEnumConstants();
final String[] strings = new String[enumConstants.length];
for (int i = 0, itemsLength = enumConstants.length; i < itemsLength; i++) {
strings[i] = ((Enum) enumConstants[i]).name();
}
return new CustomComboBoxCellEditor(parent, strings, SWT.DROP_DOWN | SWT.READ_ONLY);
} else {
log.warn("Unsupported property type: " + propertyType.getName());
return null;
}
}
use of org.jkiss.dbeaver.model.meta.IPropertyValueListProvider in project dbeaver by dbeaver.
the class UIUtils method createCellEditor.
public static CellEditor createCellEditor(Composite parent, Object object, DBPPropertyDescriptor property, int style) {
// List
if (property instanceof IPropertyValueListProvider) {
final IPropertyValueListProvider listProvider = (IPropertyValueListProvider) property;
final Object[] items = listProvider.getPossibleValues(object);
if (items != null) {
final String[] strings = new String[items.length];
for (int i = 0, itemsLength = items.length; i < itemsLength; i++) {
strings[i] = items[i] instanceof DBPNamedObject ? ((DBPNamedObject) items[i]).getName() : CommonUtils.toString(items[i]);
}
final CustomComboBoxCellEditor editor = new CustomComboBoxCellEditor(parent, strings, SWT.DROP_DOWN | (listProvider.allowCustomValue() ? SWT.NONE : SWT.READ_ONLY));
return editor;
}
}
Class<?> propertyType = property.getDataType();
if (propertyType == null || CharSequence.class.isAssignableFrom(propertyType)) {
return new CustomTextCellEditor(parent);
} else if (BeanUtils.isNumericType(propertyType)) {
return new CustomNumberCellEditor(parent, propertyType);
} else if (BeanUtils.isBooleanType(propertyType)) {
return new CustomCheckboxCellEditor(parent, style);
// return new CheckboxCellEditor(parent);
} else if (propertyType.isEnum()) {
final Object[] enumConstants = propertyType.getEnumConstants();
final String[] strings = new String[enumConstants.length];
for (int i = 0, itemsLength = enumConstants.length; i < itemsLength; i++) {
strings[i] = ((Enum) enumConstants[i]).name();
}
return new CustomComboBoxCellEditor(parent, strings, SWT.DROP_DOWN | SWT.READ_ONLY);
} else {
log.warn("Unsupported property type: " + propertyType.getName());
return null;
}
}
Aggregations