use of org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor in project dbeaver by serge-rider.
the class PropertyTreeViewer method loadTreeNodes.
private Map<String, TreeNode> loadTreeNodes(@Nullable DBRProgressMonitor monitor, TreeNode parent, DBPPropertySource propertySource) {
Map<String, TreeNode> categories = new LinkedHashMap<>();
final DBPPropertyDescriptor[] props = propertySource.getPropertyDescriptors2();
for (DBPPropertyDescriptor prop : props) {
String categoryName = prop.getCategory();
if (CommonUtils.isEmpty(categoryName)) {
categoryName = CATEGORY_GENERAL;
}
TreeNode category = (parent != null ? parent : categories.get(categoryName));
if (category == null) {
category = new TreeNode(null, propertySource, categoryName);
categories.put(categoryName, category);
}
TreeNode propNode = new TreeNode(category, propertySource, prop);
// Load nested object's properties
if (!(propertySource instanceof IPropertySourceEditable)) {
Class<?> propType = ((DBPPropertyDescriptor) prop).getDataType();
if (propType != null) {
if (DBPObject.class.isAssignableFrom(propType)) {
Object propertyValue = propertySource.getPropertyValue(monitor, prop.getId());
if (propertyValue != null) {
PropertyCollector nestedCollector = new PropertyCollector(propertyValue, true);
if (nestedCollector.collectProperties()) {
categories.putAll(loadTreeNodes(monitor, propNode, nestedCollector));
}
}
} else if (BeanUtils.isCollectionType(propType)) {
Object propertyValue = propertySource.getPropertyValue(monitor, prop.getId());
if (propertyValue != null) {
Collection<?> collection;
if (BeanUtils.isArrayType(propType)) {
collection = Arrays.asList((Object[]) propertyValue);
} else {
collection = (Collection<?>) propertyValue;
}
PropertySourceCollection psc = new PropertySourceCollection(collection);
for (DBPPropertyDescriptor pd : psc.getPropertyDescriptors2()) {
new TreeNode(propNode, psc, pd);
}
}
}
}
}
}
return categories;
}
use of org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor in project dbeaver by serge-rider.
the class WMIPropertySource method getPropertyDescriptors2.
@Override
public DBPPropertyDescriptor[] getPropertyDescriptors2() {
try {
WMIQualifiedObject qualifiedObject = getQualifiedObject();
if (qualifiedObject == null) {
return EMPTY_PROPERTIES;
}
Collection<WMIQualifier> qualifiers = qualifiedObject.getQualifiers();
DBPPropertyDescriptor[] result = new DBPPropertyDescriptor[qualifiers.size()];
int index = 0;
for (WMIQualifier qualifier : qualifiers) {
String name = qualifier.getName();
PropertyDescriptor prop = new PropertyDescriptor("WMI", name, name, null, null, false, null, null, false);
result[index++] = prop;
}
return result;
} catch (WMIException e) {
log.error(e);
return EMPTY_PROPERTIES;
}
}
use of org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor in project dbeaver by serge-rider.
the class PropertyDescriptor method extractProperties.
public static List<DBPPropertyDescriptor> extractProperties(IConfigurationElement config) {
String category = NAME_UNDEFINED;
if (TAG_PROPERTY_GROUP.equals(config.getName())) {
category = config.getAttribute(ATTR_LABEL);
if (CommonUtils.isEmpty(category)) {
category = NAME_UNDEFINED;
}
}
List<DBPPropertyDescriptor> properties = new ArrayList<>();
IConfigurationElement[] propElements = config.getChildren(PropertyDescriptor.TAG_PROPERTY);
for (IConfigurationElement prop : propElements) {
properties.add(new PropertyDescriptor(category, prop));
}
return properties;
}
use of org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor 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;
}
use of org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor in project dbeaver by serge-rider.
the class PropertySourceAbstract method collectProperties.
public boolean collectProperties() {
lazyValues.clear();
props.clear();
propValues.clear();
final Object editableValue = getEditableValue();
IPropertyFilter filter;
if (editableValue instanceof DBSObject) {
filter = new DataSourcePropertyFilter(((DBSObject) editableValue).getDataSource());
} else if (editableValue instanceof DBPContextProvider) {
DBCExecutionContext context = ((DBPContextProvider) editableValue).getExecutionContext();
filter = context == null ? new DataSourcePropertyFilter() : new DataSourcePropertyFilter(context.getDataSource());
} else {
filter = new DataSourcePropertyFilter();
}
List<ObjectPropertyDescriptor> annoProps = ObjectAttributeDescriptor.extractAnnotations(this, editableValue.getClass(), filter);
for (final ObjectPropertyDescriptor desc : annoProps) {
addProperty(desc);
}
if (editableValue instanceof DBPPropertySource) {
DBPPropertySource ownPropSource = (DBPPropertySource) editableValue;
DBPPropertyDescriptor[] ownProperties = ownPropSource.getPropertyDescriptors2();
if (!ArrayUtils.isEmpty(ownProperties)) {
for (DBPPropertyDescriptor prop : ownProperties) {
props.add(prop);
propValues.put(prop.getId(), ownPropSource.getPropertyValue(null, prop.getId()));
}
}
}
return !props.isEmpty();
}
Aggregations