Search in sources :

Example 1 with PropertySourceAbstract

use of org.jkiss.dbeaver.runtime.properties.PropertySourceAbstract in project dbeaver by serge-rider.

the class AttributeEditPage method createPageContents.

@Override
protected Control createPageContents(Composite parent) {
    Composite propsGroup = new Composite(parent, SWT.NONE);
    propsGroup.setLayout(new GridLayout(2, false));
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    propsGroup.setLayoutData(gd);
    //$NON-NLS-2$
    final Text nameText = UIUtils.createLabelText(propsGroup, "Name", attribute.getName());
    nameText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            if (attribute instanceof DBPNamedObject2) {
                ((DBPNamedObject2) attribute).setName(nameText.getText());
            }
        }
    });
    UIUtils.createControlLabel(propsGroup, "Properties").setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    final PropertyTreeViewer propertyViewer = new PropertyTreeViewer(propsGroup, SWT.BORDER);
    gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 400;
    propertyViewer.getControl().setLayoutData(gd);
    propertyViewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            return true;
        }
    });
    PropertySourceAbstract pc = new PropertySourceEditable(commandContext, attribute, attribute) {

        @Override
        public void setPropertyValue(@Nullable DBRProgressMonitor monitor, Object editableValue, ObjectPropertyDescriptor prop, Object newValue) throws IllegalArgumentException {
            super.setPropertyValue(monitor, editableValue, prop, newValue);
        /*
                if (prop.getId().equals("dataType")) {
                    newValue = getPropertyValue(monitor, editableValue, prop);
                    if (newValue instanceof DBSDataType) {
                        DBPPropertyDescriptor lengthProp = getProperty("maxLength");
                        if (lengthProp instanceof ObjectPropertyDescriptor) {
                            DBPDataKind dataKind = ((DBSDataType) newValue).getDataKind();
                            if (dataKind == DBPDataKind.STRING) {
                                setPropertyValue(monitor, editableValue, (ObjectPropertyDescriptor) lengthProp, 100);
                            } else {
                                setPropertyValue(monitor, editableValue, (ObjectPropertyDescriptor) lengthProp, null);
                            }
                            propertyViewer.update(lengthProp, null);
                        }
                    }
                }
*/
        }
    };
    pc.collectProperties();
    for (DBPPropertyDescriptor prop : pc.getProperties()) {
        if (prop instanceof ObjectPropertyDescriptor) {
            if (((ObjectPropertyDescriptor) prop).isEditPossible() && !((ObjectPropertyDescriptor) prop).isNameProperty()) {
                continue;
            }
        }
        pc.removeProperty(prop);
    }
    propertyViewer.loadProperties(pc);
    return propsGroup;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) PropertyTreeViewer(org.jkiss.dbeaver.ui.properties.PropertyTreeViewer) Text(org.eclipse.swt.widgets.Text) Viewer(org.eclipse.jface.viewers.Viewer) PropertyTreeViewer(org.jkiss.dbeaver.ui.properties.PropertyTreeViewer) DBPPropertyDescriptor(org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) PropertySourceEditable(org.jkiss.dbeaver.runtime.properties.PropertySourceEditable) GridData(org.eclipse.swt.layout.GridData) PropertySourceAbstract(org.jkiss.dbeaver.runtime.properties.PropertySourceAbstract) ObjectPropertyDescriptor(org.jkiss.dbeaver.runtime.properties.ObjectPropertyDescriptor) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) Nullable(org.jkiss.code.Nullable)

Aggregations

Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Text (org.eclipse.swt.widgets.Text)1 Nullable (org.jkiss.code.Nullable)1 DBPPropertyDescriptor (org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor)1 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)1 ObjectPropertyDescriptor (org.jkiss.dbeaver.runtime.properties.ObjectPropertyDescriptor)1 PropertySourceAbstract (org.jkiss.dbeaver.runtime.properties.PropertySourceAbstract)1 PropertySourceEditable (org.jkiss.dbeaver.runtime.properties.PropertySourceEditable)1 PropertyTreeViewer (org.jkiss.dbeaver.ui.properties.PropertyTreeViewer)1