1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.cosylab.gui.components.customizer;
21
22 import java.beans.BeanInfo;
23 import java.beans.Customizer;
24 import java.beans.IntrospectionException;
25 import java.beans.Introspector;
26 import java.beans.PropertyDescriptor;
27 import java.util.ArrayList;
28 import java.util.HashMap;
29
30
31
32
33
34
35
36 public class CustomizerFactory {
37
38
39
40
41
42
43
44
45 public static Customizer createCustomizer(String[] properties) {
46 return new PropertiesTableCustomizer(properties);
47 }
48
49
50
51
52
53
54
55
56 public static Customizer createCustomizer(PropertyDescriptor[] properties) {
57 return new PropertiesTableCustomizer(properties);
58 }
59
60
61
62
63
64
65
66
67 public static PropertyDescriptor[] propertyStringsToDescriptors(String[] properties,
68 Class type) {
69 if (properties == null || properties.length == 0) {
70
71 return null;
72 }
73
74 HashMap<String, PropertyDescriptor> nameToDescriptor = new HashMap<String, PropertyDescriptor>();
75
76
77 try {
78 BeanInfo beanInfo = Introspector.getBeanInfo(type);
79
80 PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
81
82 for (PropertyDescriptor descriptor : propertyDescriptors) {
83 nameToDescriptor.put(descriptor.getName(), descriptor);
84 }
85 } catch (IntrospectionException e) {
86
87 return null;
88 }
89
90
91
92 ArrayList<PropertyDescriptor> descriptors = new ArrayList<PropertyDescriptor>();
93
94 PropertyDescriptor temp = null;
95
96 for (String property : properties) {
97 temp = nameToDescriptor.get(property);
98 if (temp != null) {
99 descriptors.add(temp);
100 }
101 }
102
103 return descriptors.toArray(new PropertyDescriptor[] {});
104 }
105 }