use of org.apache.pivot.beans.BeanMonitor in project pivot by apache.
the class ComponentPropertyInspectorSkin method sourceChanged.
@Override
public void sourceChanged(ComponentInspector componentInspector, Component previousSource) {
Component source = componentInspector.getSource();
clearControls();
Form.SectionSequence sections = form.getSections();
sections.remove(0, sections.getLength());
if (previousSource != null) {
beanMonitor.getPropertyChangeListeners().remove(propertyChangeListener);
}
if (source == null) {
beanMonitor = null;
} else {
beanMonitor = new BeanMonitor(source);
beanMonitor.getPropertyChangeListeners().add(propertyChangeListener);
Class<?> sourceType = source.getClass();
HashMap<Class<?>, List<String>> declaringClassPartitions = new HashMap<>(classComparator);
// Partition the properties by their declaring class
BeanAdapter beanAdapter = new BeanAdapter(source);
for (String propertyName : beanAdapter) {
if (beanMonitor.isNotifying(propertyName) && !beanAdapter.isReadOnly(propertyName)) {
Method method = BeanAdapter.getGetterMethod(sourceType, propertyName);
Class<?> declaringClass = method.getDeclaringClass();
List<String> propertyNames = declaringClassPartitions.get(declaringClass);
if (propertyNames == null) {
propertyNames = new ArrayList<>(nameComparator);
declaringClassPartitions.put(declaringClass, propertyNames);
}
propertyNames.add(propertyName);
}
}
// Add the controls
for (Class<?> declaringClass : declaringClassPartitions) {
Form.Section section = new Form.Section();
section.setHeading(declaringClass.getSimpleName());
sections.add(section);
List<String> propertyNames = declaringClassPartitions.get(declaringClass);
for (String propertyName : propertyNames) {
Class<?> type = beanAdapter.getType(propertyName);
addControl(beanAdapter, propertyName, type, section);
}
}
}
}
Aggregations