summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Bauer2018-12-07 17:11:17 +0100
committerJonathan Bauer2018-12-07 17:11:17 +0100
commitddc20c3a33dd6a26b70fffb1d8980d1103a042e5 (patch)
tree0ab17b1382021915acb40a162540d659630f02b5
parent[client] Show total size and version count in image table (diff)
downloadtutor-module-ddc20c3a33dd6a26b70fffb1d8980d1103a042e5.tar.gz
tutor-module-ddc20c3a33dd6a26b70fffb1d8980d1103a042e5.tar.xz
tutor-module-ddc20c3a33dd6a26b70fffb1d8980d1103a042e5.zip
[client] date woes... *g*
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/DateTimeHelper.java14
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/ExpiryDateChooser.java101
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java16
3 files changed, 73 insertions, 58 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/DateTimeHelper.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/DateTimeHelper.java
index bd54a33c..e03aa939 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/DateTimeHelper.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/DateTimeHelper.java
@@ -62,4 +62,18 @@ public class DateTimeHelper {
return Math.round((end.getTime() - start.getTime()) / 86400000f);
}
+ /**
+ * Helper to set the given date's time to midnight.
+ *
+ * @param date
+ * @return date with hour, minute and seconds set to 23:59:59
+ */
+ public static Date endOfDay(final Date date) {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(date);
+ cal.set(Calendar.HOUR_OF_DAY, 23);
+ cal.set(Calendar.MINUTE, 59);
+ cal.set(Calendar.SECOND, 59);
+ return cal.getTime();
+ }
}
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
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java
index 212e92b0..241656f6 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java
@@ -45,6 +45,7 @@ import org.openslx.dozmod.gui.MainWindow;
import org.openslx.dozmod.gui.changemonitor.AbstractControlWrapper;
import org.openslx.dozmod.gui.changemonitor.DialogChangeMonitor;
import org.openslx.dozmod.gui.changemonitor.DialogChangeMonitor.TextNotEmptyConstraint;
+import org.openslx.dozmod.gui.helper.DateTimeHelper;
import org.openslx.dozmod.gui.helper.ExpiryDateChooser;
import org.openslx.dozmod.gui.helper.MessageType;
import org.openslx.dozmod.gui.helper.PopupMenu;
@@ -675,26 +676,23 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe
int daysToExtend = -1;
if (versions.size() > 1) {
// more than one version given, ask the user once and use the value for all versions.
- daysToExtend = ExpiryDateChooser.askFutureExpiryDate(this, null);
+ daysToExtend = ExpiryDateChooser.askFutureExpiryDuration(this, null);
if (daysToExtend == -1)
return;
}
int count = 0;
for (ImageVersionDetails img : versions) {
- long currentExpireDate = img.expireTime;
- if (currentExpireDate < Util.unixTime()) {
- // already expired, use today as starting date for the extension
- currentExpireDate = Util.unixTime();
- }
+ long currentExpiryTime = img.expireTime < Util.unixTime() ? Util.unixTime() : img.expireTime;
+ Date currentExpiryTimeAsDate = DateTimeHelper.endOfDay(new Date(currentExpiryTime * 1000l));
if (daysToExtend == -1) {
- daysToExtend = ExpiryDateChooser.askFutureExpiryDate(this, new Date(currentExpireDate * 1000));
+ daysToExtend = ExpiryDateChooser.askFutureExpiryDuration(this, currentExpiryTimeAsDate);
if (daysToExtend == -1)
return;
}
- currentExpireDate += daysToExtend * 86400L;
+ currentExpiryTimeAsDate = DateTimeHelper.addDaysTo(currentExpiryTimeAsDate, daysToExtend);
try {
ThriftManager.getSatClient().setImageVersionExpiry(Session.getSatelliteToken(), img.versionId,
- currentExpireDate);
+ currentExpiryTimeAsDate.getTime() / 1000L);
count++;
} catch (TException e) {
ThriftError.showMessage(this, LOGGER, e,