String clipboardData = ClipboardUtil.getStringContent();
if (clipboardData != null) {
Document xmlDocument = CommonUtil.createXMLDocument(new ReaderInputStream(new StringReader(clipboardData), "UTF-8"));
Element rootElement = xmlDocument.getRootElement();
List<Element> configElements = rootElement.getChildren();
ConnectionListModel model = (ConnectionListModel) list.getModel();
int selectedIndex = list.getSelectedIndex();
List<Integer> selectedIndexes = new ArrayList<Integer>();
for (Element configElement : configElements) {
selectedIndex++;
ConnectionSettings clone = new ConnectionSettings(connectionBundle);
clone.readConfiguration(configElement);
clone.getDatabaseSettings().setNew(true);
connectionBundle.setModified(true);
clone.getDatabaseSettings().setNew(true);
String name = clone.getDatabaseSettings().getName();
while (model.getConnectionConfig(name) != null) {
name = NamingUtil.getNextNumberedName(name, true);
}
clone.getDatabaseSettings().setName(name);
model.add(selectedIndex, clone);
selectedIndexes.add(selectedIndex);
}
list.setSelectedIndices(ArrayUtils.toPrimitive(selectedIndexes.toArray(new Integer[selectedIndexes.size()])));
}