summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/ExpiryDateChooser.java
diff options
context:
space:
mode:
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/ExpiryDateChooser.java')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/ExpiryDateChooser.java101
1 files changed, 52 insertions, 49 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/ExpiryDateChooser.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/ExpiryDateChooser.java
index a4810d24..d77e6f9a 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/ExpiryDateChooser.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/ExpiryDateChooser.java
@@ -1,7 +1,6 @@
package org.openslx.dozmod.gui.helper;
import java.awt.Component;
-import java.util.Calendar;
import java.util.Date;
import javax.swing.Box;
@@ -21,77 +20,81 @@ public class ExpiryDateChooser {
private static final Logger LOGGER = Logger.getLogger(ExpiryDateChooser.class);
- public final static int DEFAULT_EXTENSION_DURATION = 14;
+ /**
+ * Helper to ask the user for the number of days to extend a date with. If
+ * startingDate is given, it will preview the starting date + selected
+ * number of days. If startingDate is null, no preview will be done.
+ * Returns the numbers of days selected.
+ *
+ * @param parent component to center the dialog on.
+ * @param starting date to add the user selected duration on to. Only needed
+ * for live preview of the future date.
+ * @return the number of days the user selected.
+ */
+ public static int askFutureExpiryDuration(final Component parent, final Date startingDate) {
- private final static JPanel pane = new JPanel();
- private final static GridManager grdPane = new GridManager(pane, 3, true);
- private final static JSlider sldDaysToExtend = new JSlider(JSlider.HORIZONTAL);
- private final static QLabel lblNewDate = new QLabel();
- private final static QLabel lblNewDateLabel = new QLabel();
- private final static String txtNewDateLevel = "Neues Ablaufdatum: ";
- static {
+ ExpiryDateChooserWindow win = new ExpiryDateChooserWindow(parent);
+ int ret = win.query(startingDate);
+ if (ret <= 0
+ || ret > Session.getSatelliteConfig().maxImageValidityDays) {
+ LOGGER.error("Invalid date returned after asking user extension duration: "
+ + ret);
+ return -1;
+ }
+ return ret;
+ }
+}
+
+/**
+ * Internal layout class.
+ */
+class ExpiryDateChooserWindow extends JPanel {
+
+ private static final Logger LOGGER = Logger.getLogger(ExpiryDateChooser.class);
+
+ public static final int DEFAULT_EXTENSION_DURATION = 14;
+
+ private final JPanel pane = new JPanel();
+ private final GridManager grdPane = new GridManager(pane, 3, true);
+ private final JSlider sldDaysToExtend = new JSlider(JSlider.HORIZONTAL);
+ private final QLabel lblNewDate = new QLabel();
+ private final QLabel lblNewDateLabel = new QLabel("Neues Ablaufdatum: ");
+ private final Component parent;
+ public ExpiryDateChooserWindow(final Component parent) {
+ this.parent = parent;
grdPane.add(new QLabel("Geben Sie ein um wieviele Tage diese Version(en) verlängert werden soll:"), 3)
.fill(true, true)
.expand(true, true);
grdPane.nextRow();
-
sldDaysToExtend.setModel(new DefaultBoundedRangeModel(DEFAULT_EXTENSION_DURATION, 0, 1,
Session.getSatelliteConfig().maxImageValidityDays));
grdPane.add(sldDaysToExtend, 3).fill(true, false).expand(true, false);
grdPane.nextRow();
-
grdPane.add(lblNewDateLabel);
grdPane.add(Box.createGlue()).fill(true, false).expand(true, false);
grdPane.add(lblNewDate).fill(true, true).expand(true, true);
grdPane.finish(true);
}
- /**
- * Helper to ask the user for the number of days to extend a date with. If
- * startingDate is given, it will preview the starting date + selected
- * number of days. If startingDate is null, no preview will be done.
- * Returns the numbers of days selected.
- *
- * @param parent component to center the dialog on.
- * @param starting date to add the user selected duration on to. Only needed
- * for live preview of the future date.
- * @return the number of days the user selected.
- */
- public static int askFutureExpiryDate(final Component parent, final Date startingDate) {
- final Calendar startingDayMidnight = Calendar.getInstance();
- if (startingDate != null) {
- startingDayMidnight.setTime(startingDate);
- startingDayMidnight.set(Calendar.HOUR_OF_DAY, 23);
- startingDayMidnight.set(Calendar.MINUTE, 59);
- startingDayMidnight.set(Calendar.SECOND, 59);
- lblNewDate.setText(FormatHelper.longDate(
- DateTimeHelper.addDaysTo(startingDayMidnight.getTime(), DEFAULT_EXTENSION_DURATION)));
- lblNewDateLabel.setText(txtNewDateLevel);
- }
- sldDaysToExtend.setValue(DEFAULT_EXTENSION_DURATION);
+ public int query(final Date startingDate) {
+ // show bottom date preview if only one version was selected
+ lblNewDate.setText(startingDate == null ? ""
+ : FormatHelper.longDate(
+ DateTimeHelper.addDaysTo(startingDate, DEFAULT_EXTENSION_DURATION)));
sldDaysToExtend.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
- if (startingDate != null) {
- Date newExpiryDate = DateTimeHelper.addDaysTo(startingDayMidnight.getTime(),
- sldDaysToExtend.getValue());
- lblNewDate.setText(FormatHelper.longDate(newExpiryDate));
- }
+ if (startingDate == null)
+ return;
+ Date current = DateTimeHelper.addDaysTo(startingDate, sldDaysToExtend.getValue());
+ lblNewDate.setText(FormatHelper.longDate(current));
}
});
-
+ sldDaysToExtend.setValue(DEFAULT_EXTENSION_DURATION);
int ret = JOptionPane.showConfirmDialog(parent, pane, "Ablaufdatum verlängern",
JOptionPane.OK_CANCEL_OPTION);
- if (ret != 0) {
- LOGGER.info("Canceled by user.");
+ if (ret != 0)
return -1;
- }
- if (sldDaysToExtend.getValue() <= 0
- || sldDaysToExtend.getValue() > Session.getSatelliteConfig().maxImageValidityDays) {
- LOGGER.error("Invalid date returned after asking user extension duration: "
- + sldDaysToExtend.getValue());
- return -1;
- }
return sldDaysToExtend.getValue();
}
} \ No newline at end of file