Changeset 3135 for DataCleaner
- Timestamp:
- 02/03/12 16:50:56 (4 months ago)
- Location:
- DataCleaner/trunk/core/src/main/java/org/eobjects/datacleaner
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
DataCleaner/trunk/core/src/main/java/org/eobjects/datacleaner/panels/datastructures/BuildMapJobBuilderPresenter.java
r3120 r3135 25 25 import org.eobjects.analyzer.beans.datastructures.BuildMapTransformer; 26 26 import org.eobjects.analyzer.configuration.AnalyzerBeansConfiguration; 27 import org.eobjects.analyzer.data.InputColumn; 27 28 import org.eobjects.analyzer.descriptors.ConfiguredPropertyDescriptor; 28 29 import org.eobjects.analyzer.descriptors.TransformerBeanDescriptor; … … 46 47 private final Map<ConfiguredPropertyDescriptor, PropertyWidget<?>> _overriddenPropertyWidgets; 47 48 48 public BuildMapJobBuilderPresenter(TransformerJobBuilder<BuildMapTransformer> tjb, WindowContext windowContext, 49 PropertyWidgetFactory propertyWidgetFactory, AnalyzerBeansConfiguration configuration) { 49 public BuildMapJobBuilderPresenter( 50 TransformerJobBuilder<BuildMapTransformer> tjb, 51 WindowContext windowContext, 52 PropertyWidgetFactory propertyWidgetFactory, 53 AnalyzerBeansConfiguration configuration) { 50 54 super(tjb, windowContext, propertyWidgetFactory, configuration); 51 55 52 56 _overriddenPropertyWidgets = new HashMap<ConfiguredPropertyDescriptor, PropertyWidget<?>>(); 53 57 54 final TransformerBeanDescriptor<BuildMapTransformer> descriptor = tjb.getDescriptor(); 55 final ConfiguredPropertyDescriptor valuesProperty = descriptor.getConfiguredProperty("Values"); 56 final ConfiguredPropertyDescriptor keysProperty = descriptor.getConfiguredProperty("Keys"); 58 final TransformerBeanDescriptor<BuildMapTransformer> descriptor = tjb 59 .getDescriptor(); 60 final ConfiguredPropertyDescriptor valuesProperty = descriptor 61 .getConfiguredProperty("Values"); 62 final ConfiguredPropertyDescriptor keysProperty = descriptor 63 .getConfiguredProperty("Keys"); 57 64 58 MultipleMappedStringsPropertyWidget propertyWidget = new MultipleMappedStringsPropertyWidget(tjb, valuesProperty, 59 keysProperty); 65 MultipleMappedStringsPropertyWidget propertyWidget = new MultipleMappedStringsPropertyWidget( 66 tjb, valuesProperty, keysProperty) { 67 @Override 68 protected String getDefaultMappedString(InputColumn<?> inputColumn) { 69 return inputColumn.getName(); 70 } 71 }; 60 72 _overriddenPropertyWidgets.put(valuesProperty, propertyWidget); 61 _overriddenPropertyWidgets.put(keysProperty, propertyWidget.getMappedStringsPropertyWidget()); 73 _overriddenPropertyWidgets.put(keysProperty, 74 propertyWidget.getMappedStringsPropertyWidget()); 62 75 } 63 76 64 77 @Override 65 protected PropertyWidget<?> createPropertyWidget(AbstractBeanJobBuilder<?, ?, ?> beanJobBuilder, 78 protected PropertyWidget<?> createPropertyWidget( 79 AbstractBeanJobBuilder<?, ?, ?> beanJobBuilder, 66 80 ConfiguredPropertyDescriptor propertyDescriptor) { 67 81 if (_overriddenPropertyWidgets.containsKey(propertyDescriptor)) { -
DataCleaner/trunk/core/src/main/java/org/eobjects/datacleaner/panels/datastructures/KeysAndTypesPropertyWidget.java
r3120 r3135 48 48 private final MinimalPropertyWidget<Class<?>[]> _typesPropertyWidget; 49 49 50 public KeysAndTypesPropertyWidget(ConfiguredPropertyDescriptor keysProperty, ConfiguredPropertyDescriptor typesProperty, 50 public KeysAndTypesPropertyWidget( 51 ConfiguredPropertyDescriptor keysProperty, 52 ConfiguredPropertyDescriptor typesProperty, 51 53 AbstractBeanJobBuilder<?, ?, ?> beanJobBuilder) { 52 54 super(keysProperty, beanJobBuilder); 53 55 _comboBoxes = new ArrayList<DCComboBox<Class<?>>>(); 54 56 _typesProperty = typesProperty; 55 _typesPropertyWidget = new MinimalPropertyWidget<Class<?>[]>(getBeanJobBuilder(), _typesProperty) { 57 _typesPropertyWidget = new MinimalPropertyWidget<Class<?>[]>( 58 getBeanJobBuilder(), _typesProperty) { 56 59 57 60 @Override … … 80 83 @Override 81 84 protected JComponent decorateTextField(JXTextField textField) { 82 final DCPanel panel = new DCPanel(); 83 panel.setLayout(new BorderLayout()); 84 panel.add(textField, BorderLayout.CENTER); 85 86 final DCComboBox<Class<?>> comboBox = SingleClassPropertyWidget.createClassComboBox(true); 85 final DCComboBox<Class<?>> comboBox = SingleClassPropertyWidget 86 .createClassComboBox(true); 87 87 comboBox.addListener(new Listener<Class<?>>() { 88 88 @Override … … 91 91 } 92 92 }); 93 93 94 _comboBoxes.add(comboBox); 94 95 96 final DCPanel panel = new DCPanel(); 97 panel.setLayout(new BorderLayout()); 98 panel.add(textField, BorderLayout.CENTER); 95 99 panel.add(comboBox, BorderLayout.EAST); 96 100 -
DataCleaner/trunk/core/src/main/java/org/eobjects/datacleaner/widgets/properties/MultipleMappedStringsPropertyWidget.java
r3120 r3135 47 47 * @author Kasper SÞrensen 48 48 */ 49 public class MultipleMappedStringsPropertyWidget extends MultipleInputColumnsPropertyWidget { 49 public class MultipleMappedStringsPropertyWidget extends 50 MultipleInputColumnsPropertyWidget { 50 51 51 52 private final WeakHashMap<InputColumn<?>, JXTextField> _mappedTextFields; 52 53 private final ConfiguredPropertyDescriptor _mappedStringsProperty; 53 54 private final MinimalPropertyWidget<String[]> _mappedStringPropertyWidget; 55 56 // indicates whether there is currently undergoing a string listener action 57 private volatile boolean _stringsUpdating; 54 58 55 59 /** … … 64 68 * the property representing the mapped strings (String[]) 65 69 */ 66 public MultipleMappedStringsPropertyWidget(AbstractBeanJobBuilder<?, ?, ?> beanJobBuilder, 67 ConfiguredPropertyDescriptor inputColumnsProperty, ConfiguredPropertyDescriptor mappedStringsProperty) { 70 public MultipleMappedStringsPropertyWidget( 71 AbstractBeanJobBuilder<?, ?, ?> beanJobBuilder, 72 ConfiguredPropertyDescriptor inputColumnsProperty, 73 ConfiguredPropertyDescriptor mappedStringsProperty) { 68 74 super(beanJobBuilder, inputColumnsProperty); 69 75 _mappedTextFields = new WeakHashMap<InputColumn<?>, JXTextField>(); … … 72 78 _mappedStringPropertyWidget = createMappedStringsPropertyWidget(); 73 79 74 InputColumn<?>[] currentValue = getCurrentValue(); 75 if (currentValue != null) { 80 _stringsUpdating = false; 81 82 final InputColumn<?>[] currentValue = getCurrentValue(); 83 final String[] currentMappedStringsValue = (String[]) beanJobBuilder 84 .getConfiguredProperty(mappedStringsProperty); 85 if (currentValue != null && currentMappedStringsValue != null) { 86 // first create combo's, then set value (so combo is ready before it 87 // is requested) 88 89 _mappedStringPropertyWidget.setValue(currentMappedStringsValue); 90 final int minLength = Math.min(currentValue.length, 91 currentMappedStringsValue.length); 92 for (int i = 0; i < minLength; i++) { 93 final InputColumn<?> inputColumn = currentValue[i]; 94 final String mappedString = currentMappedStringsValue[i]; 95 createTextField(inputColumn, mappedString); 96 } 97 76 98 setValue(currentValue); 77 }78 79 String[] currentMappedStrings = (String[]) beanJobBuilder.getConfiguredProperty(mappedStringsProperty);80 if (currentValue != null && currentMappedStrings != null) {81 int minLength = Math.min(currentValue.length, currentMappedStrings.length);82 for (int i = 0; i < minLength; i++) {83 InputColumn<?> inputColumn = currentValue[i];84 String mappedString = currentMappedStrings[i];85 createTextField(inputColumn, mappedString);86 }87 99 } 88 100 } … … 93 105 } 94 106 95 private JXTextField createTextField(InputColumn<?> inputColumn, String mappedString) { 107 private JXTextField createTextField(InputColumn<?> inputColumn, 108 String mappedString) { 96 109 final JXTextField textField = WidgetFactory.createTextField(); 97 110 _mappedTextFields.put(inputColumn, textField); 111 112 if (mappedString == null) { 113 mappedString = getDefaultMappedString(inputColumn); 114 } 98 115 if (mappedString != null) { 99 116 textField.setText(mappedString); 100 117 } 101 118 textField.getDocument().addDocumentListener(new DCDocumentListener() { 102 103 119 @Override 104 120 protected void onChange(DocumentEvent event) { 121 _stringsUpdating = true; 105 122 fireValueChanged(); 106 123 _mappedStringPropertyWidget.fireValueChanged(); 124 _stringsUpdating = false; 107 125 } 108 126 }); … … 110 128 } 111 129 112 @Override 113 protected JComponent decorateCheckBox(final DCCheckBox<InputColumn<?>> checkBox) { 130 /** 131 * Subclasses can override this method to set a default value for a column 132 * when it is selected. 133 * 134 * @param inputColumn 135 * @return 136 */ 137 protected String getDefaultMappedString(InputColumn<?> inputColumn) { 138 return ""; 139 } 140 141 @Override 142 protected JComponent decorateCheckBox( 143 final DCCheckBox<InputColumn<?>> checkBox) { 114 144 final JXTextField textField; 115 145 if (_mappedTextFields.containsKey(checkBox.getValue())) { … … 118 148 textField = createTextField(checkBox.getValue(), null); 119 149 } 120 checkBox.addListener (new DCCheckBox.Listener<InputColumn<?>>() {150 checkBox.addListenerToHead(new DCCheckBox.Listener<InputColumn<?>>() { 121 151 @Override 122 152 public void onItemSelected(InputColumn<?> item, boolean selected) { 123 153 textField.setVisible(selected); 154 updateUI(); 155 } 156 }); 157 checkBox.addListener(new DCCheckBox.Listener<InputColumn<?>>() { 158 @Override 159 public void onItemSelected(InputColumn<?> item, boolean selected) { 160 _mappedStringPropertyWidget.fireValueChanged(); 124 161 } 125 162 }); … … 129 166 final DCPanel panel = new DCPanel(); 130 167 panel.setLayout(new BorderLayout()); 131 panel.add(checkBox, BorderLayout. WEST);168 panel.add(checkBox, BorderLayout.CENTER); 132 169 panel.add(textField, BorderLayout.EAST); 133 170 return panel; … … 139 176 140 177 private MinimalPropertyWidget<String[]> createMappedStringsPropertyWidget() { 141 return new MinimalPropertyWidget<String[]>(getBeanJobBuilder(), _mappedStringsProperty) { 178 return new MinimalPropertyWidget<String[]>(getBeanJobBuilder(), 179 _mappedStringsProperty) { 142 180 143 181 @Override … … 149 187 @Override 150 188 public boolean isSet() { 151 final InputColumn<?>[] inputColumns = MultipleMappedStringsPropertyWidget.this.getValue(); 189 final InputColumn<?>[] inputColumns = MultipleMappedStringsPropertyWidget.this 190 .getValue(); 152 191 for (InputColumn<?> inputColumn : inputColumns) { 153 192 JXTextField textField = _mappedTextFields.get(inputColumn); … … 166 205 @Override 167 206 protected void setValue(String[] value) { 207 if (_stringsUpdating) { 208 // setValue of the strings will be called prematurely 209 // (with previous value) by change notifications of the 210 // input columns property. 211 return; 212 } 213 168 214 if (EqualsBuilder.equals(value, getValue())) { 169 215 return; 170 216 } 171 final InputColumn<?>[] inputColumns = MultipleMappedStringsPropertyWidget.this.getValue(); 217 final InputColumn<?>[] inputColumns = MultipleMappedStringsPropertyWidget.this 218 .getValue(); 219 220 if (value != null && inputColumns.length != value.length) { 221 // disregard this invalid value update 222 return; 223 } 224 172 225 for (int i = 0; i < inputColumns.length; i++) { 173 226 final InputColumn<?> inputColumn = inputColumns[i]; 174 final String mapped ColumnName;227 final String mappedString; 175 228 if (value == null) { 176 mapped ColumnName = "";229 mappedString = getDefaultMappedString(inputColumn); 177 230 } else if (i < value.length) { 178 mapped ColumnName= value[i];231 mappedString = value[i]; 179 232 } else { 180 mapped ColumnName = "";233 mappedString = getDefaultMappedString(inputColumn); 181 234 } 182 final JXTextField textField = _mappedTextFields.get(inputColumn); 183 textField.setText(mappedColumnName); 235 final JXTextField textField = _mappedTextFields 236 .get(inputColumn); 237 238 final String previousText = textField.getText(); 239 if (!mappedString.equals(previousText)) { 240 textField.setText(mappedString); 241 } 184 242 } 185 243 } … … 194 252 // exclude input columns that have not been mapped yet 195 253 final JXTextField textField = _mappedTextFields.get(inputColumn); 196 if (textField != null ) {254 if (textField != null && textField.isVisible()) { 197 255 if (!StringUtils.isNullOrEmpty(textField.getText())) { 198 256 result.add(inputColumn); … … 204 262 205 263 private String[] getMappedStrings() { 206 final InputColumn<?>[] inputColumns = MultipleMappedStringsPropertyWidget.this.getValue(); 264 final InputColumn<?>[] inputColumns = MultipleMappedStringsPropertyWidget.this 265 .getValue(); 207 266 final List<String> result = new ArrayList<String>(); 208 267 for (InputColumn<?> inputColumn : inputColumns) {
Note: See TracChangeset
for help on using the changeset viewer.
