// this tablePath will be used to group together columns from the
// same original table
final String tablePath = columnPath.substring(0, columnDelim);
final SourceColumnComboBox comboBox = new SourceColumnComboBox();
comboBox.setEnabled(false);
comboBox.setName(columnPath);
comboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Column col = comboBox.getSelectedItem();
if (col != null) {
// make sure all comboboxes in a group use the same
// table
List<SourceColumnComboBox> comboBoxes = _sourceColumnComboBoxes.get(tablePath);
for (SourceColumnComboBox sameTableComboBox : comboBoxes) {
sameTableComboBox.setModel(_datastore, col.getTable());
}
}
refreshOpenButtonVisibility();
}
});
if (!_sourceColumnComboBoxes.containsKey(tablePath)) {
_sourceColumnComboBoxes.put(tablePath, new ArrayList<SourceColumnComboBox>());
}
_sourceColumnComboBoxes.get(tablePath).add(comboBox);
}
for (Entry<String, String> variableEntry : metadata.getVariables().entrySet()) {
String id = variableEntry.getKey();
String value = variableEntry.getValue();
JXTextField textField = WidgetFactory.createTextField("Original: " + value);
textField.setText(value);
_variableTextFields.put(id, textField);
}
_openButton.setEnabled(false);
_datastoreCatalog = configuration.getDatastoreCatalog();
final String[] datastoreNames = _datastoreCatalog.getDatastoreNames();
// the combobox will contain all datastore names and a null for
// "not selected"
final String[] comboBoxModel = CollectionUtils.array(new String[1], datastoreNames);
_datastoreCombobox = new JComboBox(comboBoxModel);
_datastoreCombobox.setEditable(false);
_datastoreCombobox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final String datastoreName = (String) _datastoreCombobox.getSelectedItem();
_datastore = _datastoreCatalog.getDatastore(datastoreName);
_sourceColumnMapping.setDatastore(_datastore);
refreshOpenButtonVisibility();
for (List<SourceColumnComboBox> comboBoxes : _sourceColumnComboBoxes.values()) {
for (SourceColumnComboBox comboBox : comboBoxes) {
comboBox.setModel(_datastore);
if (_datastore == null) {
// no datastore selected
comboBox.setEnabled(false);
} else {
comboBox.setEnabled(true);
}
}
}
if (_datastore == null) {
_autoMapButton.setVisible(false);
} else {
_autoMapButton.setVisible(true);
}
}
});
_autoMapButton = new JButton("Map automatically");
_autoMapButton.setVisible(false);
_autoMapButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_sourceColumnMapping.autoMap(_datastore);
Set<String> paths = _sourceColumnMapping.getPaths();
for (String path : paths) {
for (List<SourceColumnComboBox> comboBoxes : _sourceColumnComboBoxes.values()) {
for (SourceColumnComboBox comboBox : comboBoxes) {
if (path.equals(comboBox.getName())) {
comboBox.setSelectedItem(_sourceColumnMapping.getColumn(path));
}
}
}
}
}