diff options
author | Jonathan Bauer | 2015-09-03 12:55:53 +0200 |
---|---|---|
committer | Jonathan Bauer | 2015-09-03 12:55:53 +0200 |
commit | df384521339018afb69a4a3271b29393e335bb37 (patch) | |
tree | 0110aa4d6aae0eea8859c9bdfeccec4c729d3af9 /dozentenmodul/src/main/java/org/openslx | |
parent | [client] add hooks to all potential ways to close ImageDetails and ask user f... (diff) | |
download | tutor-module-df384521339018afb69a4a3271b29393e335bb37.tar.gz tutor-module-df384521339018afb69a4a3271b29393e335bb37.tar.xz tutor-module-df384521339018afb69a4a3271b29393e335bb37.zip |
[client] add close hooks in LectureDetails
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java index fa9de2a6..c14af6dd 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java @@ -17,6 +17,7 @@ import java.util.List; import java.util.Map; import javax.swing.DefaultComboBoxModel; +import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; @@ -110,10 +111,14 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements super(modalParent); // save callback this.callback = callback; - // save default color of date/time stuff to reset the background later - dateTimeTextColor = startDate.getForeground(); + + setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @Override + public void windowClosing(WindowEvent e) { + safeClose(); + } + @Override public void windowClosed(WindowEvent e) { dateChecker.cancel(); } @@ -201,6 +206,8 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements }); btnSaveChanges.setEnabled(false); makeEditable(false); + // save default color of date/time stuff to reset the background later + dateTimeTextColor = startDate.getForeground(); } /** @@ -285,6 +292,10 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements setVisible(true); } + /** + * Helper to fill the combobox with the versions of the image. The list will be sorted by + * creation timestamp + */ private void fillVersionsCombo(){ // version combo List<ImageVersionDetails> versions = image.getVersions(); @@ -472,6 +483,15 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements } + /** + * Checks if the given start and end date represent a valid time period. + * This is the case, if start < end and if current time < end + * + * @param start date of the period to check + * @param end date of the period to check + * @param feedback true if the user should be shown feedback, false otherwise + * @return true if the period is valid, false otherwise + */ private boolean isPeriodValid(final Date start, final Date end, boolean feedback) { if (start == null || end == null) return false; @@ -576,14 +596,30 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements super.show(); } + /* ******************************************************************************* + * + * UIFeedback implementation + * + ********************************************************************************/ @Override public boolean wantConfirmQuit() { - return btnSaveChanges.isEnabled(); + return reactToChange() && btnSaveChanges.isEnabled(); } @Override public void escapePressed() { // Also ask if applicable - this.dispose(); + safeClose(); + } + /* + * Safe close helper: checks if we have unsaved work and prompt the user for + * confirmation if so + */ + private void safeClose() { + if (reactToChange() && + !Gui.showMessageBox(me, + "Ă„nderungen werden verworfen, wollen Sie wirklich abbrechen?", MessageType.QUESTION_YESNO, LOGGER, null)) + return; + dispose(); } } |