buttonSave.setLayoutData(data);
buttonSave.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
FileDialog dlg = new FileDialog(shell, SWT.SAVE);
Config config = controller.getConfig();
dlg.setFileName(config.getString(Config.MAPPING_FILE));
dlg.setFilterPath(config.getString(Config.MAPPING_FILE));
dlg.setFilterExtensions(new String[] { "*.sdl" });
String filename = dlg.open();
boolean cancel = false;
if (filename == null || "".equals(filename)) { //$NON-NLS-1$
cancel = true;
}
// check if file already exists
while (!cancel && new File(filename).exists()) {
int selectedButton = UIUtils.warningConfMessageBox(shell, Labels.getString("UI.fileAlreadyExists"));
if (selectedButton == SWT.YES) {
break;
} else if (selectedButton == SWT.NO) {
filename = dlg.open();
if (filename == null || "".equals(filename)) { //$NON-NLS-1$
cancel = true;
}
}
}
if (!cancel) {
config.setValue(Config.MAPPING_FILE, filename);
try {
mapper.save(filename);
} catch (IOException e1) {
logger.error(Labels.getString("MappingDialog.errorSave"), e1); //$NON-NLS-1$
}