From df384521339018afb69a4a3271b29393e335bb37 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Thu, 3 Sep 2015 12:55:53 +0200 Subject: [client] add close hooks in LectureDetails --- .../dozmod/gui/window/LectureDetailsWindow.java | 44 ++++++++++++++++++++-- 1 file 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,9 +111,13 @@ 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 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(); } } -- cgit v1.2.3-55-g7522