| | 1283 | if (!memberTableModel.hasSameMembersAs(getRelationSnapshot()) || tagEditorPanel.getModel().isDirty()) { |
| | 1284 | //give the user a chance to save the changes |
| | 1285 | int ret = confirmClosingByCancel(); |
| | 1286 | if (ret == 0) { //Yes, save the changes |
| | 1287 | //copied from OKAction.run() |
| | 1288 | Main.pref.put("relation.editor.generic.lastrole", tfRole.getText()); |
| | 1289 | if (getRelation() == null) { |
| | 1290 | applyNewRelation(); |
| | 1291 | } else if (!memberTableModel.hasSameMembersAs(getRelationSnapshot()) |
| | 1292 | || tagEditorPanel.getModel().isDirty()) { |
| | 1293 | if (isDirtyRelation()) { |
| | 1294 | if (confirmClosingBecauseOfDirtyState()) { |
| | 1295 | if (getLayer().getConflicts().hasConflictForMy(getRelation())) { |
| | 1296 | warnDoubleConflict(); |
| | 1297 | return; |
| | 1298 | } |
| | 1299 | applyExistingConflictingRelation(); |
| | 1300 | } else |
| | 1301 | return; |
| | 1302 | } else { |
| | 1303 | applyExistingNonConflictingRelation(); |
| | 1304 | } |
| | 1305 | } |
| | 1306 | } |
| | 1307 | else if (ret == 2) //Cancel, continue editing |
| | 1308 | return; |
| | 1309 | //in case of "No, discard", there is no extra action to be performed here. |
| | 1310 | } |
| | 1313 | |
| | 1314 | protected int confirmClosingByCancel() { |
| | 1315 | ButtonSpec [] options = new ButtonSpec[] { |
| | 1316 | new ButtonSpec( |
| | 1317 | tr("Yes, save the changes and close"), |
| | 1318 | ImageProvider.get("ok"), |
| | 1319 | tr("Click to save the changes and close this relation editor") , |
| | 1320 | null /* no specific help topic */ |
| | 1321 | ), |
| | 1322 | new ButtonSpec( |
| | 1323 | tr("No, discard the changes and close"), |
| | 1324 | ImageProvider.get("cancel"), |
| | 1325 | tr("Click to discard the changes and close this relation editor") , |
| | 1326 | null /* no specific help topic */ |
| | 1327 | ), |
| | 1328 | new ButtonSpec( |
| | 1329 | tr("Cancel, continue editing"), |
| | 1330 | ImageProvider.get("cancel"), |
| | 1331 | tr("Click to return to the relation editor and to resume relation editing") , |
| | 1332 | null /* no specific help topic */ |
| | 1333 | ) |
| | 1334 | }; |
| | 1335 | |
| | 1336 | int ret = HelpAwareOptionPane.showOptionDialog( |
| | 1337 | Main.parent, |
| | 1338 | tr("<html>The relation has been changed.<br>" |
| | 1339 | + "<br>" |
| | 1340 | + "Do you want to save your changes?</html>"), |
| | 1341 | tr("Unsaved changes"), |
| | 1342 | JOptionPane.WARNING_MESSAGE, |
| | 1343 | null, |
| | 1344 | options, |
| | 1345 | options[0], // OK is default, |
| | 1346 | "/Dialog/RelationEditor#DiscardChanges" |
| | 1347 | ); |
| | 1348 | return ret; |
| | 1349 | } |