Search in sources :

Example 6 with IPropertyValueListProvider

use of org.jkiss.dbeaver.model.meta.IPropertyValueListProvider in project dbeaver by serge-rider.

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);
    }
}
Also used : ComboContentAdapter(org.eclipse.jface.fieldassist.ComboContentAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) GridLayout(org.eclipse.swt.layout.GridLayout) IPropertyValueListProvider(org.jkiss.dbeaver.model.meta.IPropertyValueListProvider) StringContentProposalProvider(org.jkiss.dbeaver.ui.contentassist.StringContentProposalProvider) RowLayout(org.eclipse.swt.layout.RowLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ObjectPropertyDescriptor(org.jkiss.dbeaver.runtime.properties.ObjectPropertyDescriptor) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject)

Example 7 with IPropertyValueListProvider

use of org.jkiss.dbeaver.model.meta.IPropertyValueListProvider in project dbeaver by serge-rider.

the class PropertyEditorUtils 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)) {
        if (property instanceof ObjectPropertyDescriptor && ((ObjectPropertyDescriptor) property).isMultiLine()) {
            AdvancedTextCellEditor editor = new AdvancedTextCellEditor(parent);
            setValidator(editor, property, object);
            return editor;
        } else {
            CustomTextCellEditor editor = new CustomTextCellEditor(parent, SWT.SINGLE | ((style & SWT.PASSWORD) != 0 ? SWT.PASSWORD : SWT.NONE));
            setValidator(editor, property, object);
            return editor;
        }
    } else if (BeanUtils.isNumericType(propertyType)) {
        CustomNumberCellEditor editor = new CustomNumberCellEditor(parent, propertyType);
        setValidator(editor, property, object);
        return editor;
    } 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;
    }
}
Also used : DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) IPropertyValueListProvider(org.jkiss.dbeaver.model.meta.IPropertyValueListProvider) ObjectPropertyDescriptor(org.jkiss.dbeaver.runtime.properties.ObjectPropertyDescriptor) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject)

Example 8 with IPropertyValueListProvider

use of org.jkiss.dbeaver.model.meta.IPropertyValueListProvider in project dbeaver by dbeaver.

the class PropertyEditorUtils 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)) {
        if (property instanceof ObjectPropertyDescriptor && ((ObjectPropertyDescriptor) property).isMultiLine()) {
            AdvancedTextCellEditor editor = new AdvancedTextCellEditor(parent);
            setValidator(editor, property, object);
            return editor;
        } else {
            CustomTextCellEditor editor = new CustomTextCellEditor(parent, SWT.SINGLE | ((style & SWT.PASSWORD) != 0 ? SWT.PASSWORD : SWT.NONE));
            setValidator(editor, property, object);
            return editor;
        }
    } else if (BeanUtils.isNumericType(propertyType)) {
        CustomNumberCellEditor editor = new CustomNumberCellEditor(parent, propertyType);
        setValidator(editor, property, object);
        return editor;
    } 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;
    }
}
Also used : DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) IPropertyValueListProvider(org.jkiss.dbeaver.model.meta.IPropertyValueListProvider) ObjectPropertyDescriptor(org.jkiss.dbeaver.runtime.properties.ObjectPropertyDescriptor) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject)

Aggregations

IPropertyValueListProvider (org.jkiss.dbeaver.model.meta.IPropertyValueListProvider)8 DBPNamedObject (org.jkiss.dbeaver.model.DBPNamedObject)7 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)4 ObjectPropertyDescriptor (org.jkiss.dbeaver.runtime.properties.ObjectPropertyDescriptor)4 ComboContentAdapter (org.eclipse.jface.fieldassist.ComboContentAdapter)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 RowLayout (org.eclipse.swt.layout.RowLayout)2 StringContentProposalProvider (org.jkiss.dbeaver.ui.contentassist.StringContentProposalProvider)2 ObjectEditorPageControl (org.jkiss.dbeaver.ui.controls.ObjectEditorPageControl)2