summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java
diff options
context:
space:
mode:
authorJonathan Bauer2015-08-24 16:49:07 +0200
committerJonathan Bauer2015-08-24 16:49:07 +0200
commit149f0ea2c8e5aee9b5e4901c93b844799c0150e0 (patch)
tree9ad67d6bc1e47bc6dfbdc5baf50bf5501f9186f1 /dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java
parent[client] listenToInput() in ImageDetailsWindow adds listeners to detail pane (diff)
downloadtutor-module-149f0ea2c8e5aee9b5e4901c93b844799c0150e0.tar.gz
tutor-module-149f0ea2c8e5aee9b5e4901c93b844799c0150e0.tar.xz
tutor-module-149f0ea2c8e5aee9b5e4901c93b844799c0150e0.zip
[client] LectureDetails saving things [wip]
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java267
1 files changed, 236 insertions, 31 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 eb922e99..cca7ed90 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
@@ -1,8 +1,11 @@
package org.openslx.dozmod.gui.window;
+import java.awt.Color;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
@@ -12,26 +15,32 @@ import java.util.Map;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
import org.apache.log4j.Logger;
+import org.apache.thrift.TException;
import org.openslx.bwlp.thrift.iface.ImageDetailsRead;
-import org.openslx.bwlp.thrift.iface.ImagePermissions;
import org.openslx.bwlp.thrift.iface.ImageVersionDetails;
import org.openslx.bwlp.thrift.iface.LecturePermissions;
import org.openslx.bwlp.thrift.iface.LectureRead;
+import org.openslx.bwlp.thrift.iface.LectureWrite;
import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.MainWindow;
+import org.openslx.dozmod.gui.helper.DateTimeHelper;
import org.openslx.dozmod.gui.helper.MessageType;
import org.openslx.dozmod.gui.helper.UiFeedback;
import org.openslx.dozmod.gui.window.UserListWindow.UserAddedCallback;
import org.openslx.dozmod.gui.window.layout.LectureDetailsWindowLayout;
import org.openslx.dozmod.permissions.LecturePerms;
+import org.openslx.dozmod.thrift.Session;
import org.openslx.dozmod.thrift.ThriftActions;
-import org.openslx.dozmod.thrift.ThriftActions.ImageMetaCallback;
import org.openslx.dozmod.thrift.ThriftActions.LectureMetaCallback;
+import org.openslx.dozmod.thrift.ThriftError;
import org.openslx.dozmod.thrift.cache.UserCache;
import org.openslx.dozmod.util.FormatHelper;
+import org.openslx.thrifthelper.ThriftManager;
@SuppressWarnings("serial")
public class LectureDetailsWindow extends LectureDetailsWindowLayout implements UiFeedback {
@@ -44,6 +53,17 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements
private final LectureDetailsWindow me = this;
/**
+ * Callback interface to refresh lecture list after changing lecture details
+ */
+ public interface LectureUpdatedCallback {
+ public void updated(boolean success);
+ }
+ /**
+ * Callback to be called when changing lecture details on the server
+ */
+ private LectureUpdatedCallback callback = null;
+
+ /**
* Lecture that this window shows the details of
*/
private LectureRead lecture = null;
@@ -63,9 +83,12 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements
*
* @param modalParent parent of this popup window
*/
- public LectureDetailsWindow(Frame modalParent) {
+ public LectureDetailsWindow(Frame modalParent, LectureUpdatedCallback callback) {
super(modalParent);
-
+ // save callback
+ this.callback = callback;
+ // save default color of date/time stuff to reset the background later
+ dateTimeTextColor = startDate.getForeground();
/**
* Button listeners
*/
@@ -106,10 +129,28 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements
LectureCustomPermissionWindow.open(JOptionPane.getFrameForComponent(me), permissionMap, lecture.defaultPermissions, lecture.lectureId);
}
});
+ btnSaveChanges.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ saveChanges();
+ }
+ });
+ btnSaveChanges.setEnabled(false);
makeEditable(false);
}
/**
+ * @param forceRefresh
+ */
+ private void refresh(boolean forceRefresh) {
+ String lectureId = lecture.getLectureId();
+ synchronized (me) {
+ lecture = null;
+ }
+ setLecture(lectureId);
+ }
+
+ /**
* @param lectureId the id of the lecture to be displayed
*/
public void setLecture(final String lectureId) {
@@ -179,12 +220,16 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements
endCal.get(Calendar.DATE));
endTime.getModel().setValue(endCal.getTime());
+ listenToChange();
makeEditable(true);
- pack();
- MainWindow.centerShell(this);
setVisible(true);
}
+ /**
+ * Sets the lecture's owner to the given user
+ *
+ * @param user UserInfo representation of the new owner
+ */
private void setLectureOwner(final UserInfo user) {
if (!ThriftActions.setLectureOwner(JOptionPane.getFrameForComponent(this),
lecture.getLectureId(), user)) {
@@ -203,6 +248,182 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements
}
/**
+ * Triggers the download of the currently used image version of the lecture
+ */
+ private void performImageDownload() {
+ if (image == null){
+ Gui.showMessageBox(this, "Image ungültig.", MessageType.ERROR,
+ null, null);
+ return;
+ }
+ btnDownloadImage.setEnabled(false);
+ long versionSize = 0;
+ for (ImageVersionDetails version : image.versions) {
+ if(version.versionId.equals(lecture.imageVersionId)){
+ versionSize = version.fileSize;
+ }
+ }
+ if (versionSize == 0){
+ Gui.showMessageBox(this, "Fehler bei der Abfrag der Größe des Images.", MessageType.ERROR,
+ null, null);
+ return;
+ }
+ ThriftActions.initDownload(JOptionPane.getFrameForComponent(this), lecture.imageVersionId,
+ image.imageName, image.virtId, versionSize, null);
+ }
+ /**
+ * Push the changes of the image details to the satellite
+ */
+ private void saveChanges() {
+
+ // date valid TODO sat max time
+ if (!isPeriodValid(DateTimeHelper.getDateFrom(startDate, startTime), DateTimeHelper.getDateFrom(endDate, endTime), true)) {
+ return;
+ }
+ // first build the ImageBaseWrite from the GUI fields
+ final LectureWrite lectureWrite = new LectureWrite(
+ txtTitle.getText(),
+ txtDescription.getText(),
+ lecture.getImageVersionId(),
+ btnAutoUpdate.isSelected(),
+ btnIsActive.isSelected(),
+ DateTimeHelper.getDateFrom(startDate, startTime).getTime() / 1000L,
+ DateTimeHelper.getDateFrom(endDate, endTime).getTime() / 1000L,
+ null,
+ null,
+ btnIsExam.isSelected(),
+ btnHasInternetAccess.isSelected(),
+ lecture.getDefaultPermissions());
+ // now trigger the actual action
+ btnSaveChanges.setEnabled(false);
+ try {
+ ThriftManager.getSatClient().updateLecture(Session.getSatelliteToken(),
+ lecture.getLectureId(), lectureWrite);
+ } catch (TException e) {
+ ThriftError.showMessage(JOptionPane.getFrameForComponent(this), LOGGER, e, "Fehler beim Updaten der Veranstaltung");
+ callback.updated(true);
+ return;
+ }
+ btnSaveChanges.setEnabled(true);
+ refresh(true);
+ callback.updated(true);
+ // success
+ }
+
+ private void listenToChange() {
+ // final step, add listeners to react to change
+ final DocumentListener docListener = new DocumentListener() {
+ @Override
+ public void removeUpdate(DocumentEvent e) {
+ changedUpdate(e);
+ }
+ @Override
+ public void insertUpdate(DocumentEvent e) {
+ changedUpdate(e);
+ }
+ @Override
+ public void changedUpdate(DocumentEvent e) {
+ reactToChange();
+ }
+ };
+ txtTitle.getDocument().addDocumentListener(docListener);
+ txtDescription.getDocument().addDocumentListener(docListener);
+
+ // Comboboxes
+ final ItemListener comboItemListener = new ItemListener() {
+ @Override
+ public void itemStateChanged(ItemEvent e) {
+ if (e.getStateChange() == ItemEvent.SELECTED) {
+ reactToChange();
+ }
+ }
+ };
+ cboVersions.addItemListener(comboItemListener);
+
+ // Listener to detect changes in checkboxes
+ final ActionListener checkBoxListener = new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ reactToChange();
+ }
+ };
+ chkCustomPermAdmin.addActionListener(checkBoxListener);
+ chkCustomPermEdit.addActionListener(checkBoxListener);
+ btnAutoUpdate.addActionListener(checkBoxListener);
+ btnIsExam.addActionListener(checkBoxListener);
+ btnHasInternetAccess.addActionListener(checkBoxListener);
+ btnIsActive.addActionListener(checkBoxListener);
+
+ final ActionListener dateTimeListener = new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if (!isPeriodValid(DateTimeHelper.getDateFrom(startDate, startTime), DateTimeHelper.getDateFrom(endDate, endTime), false))
+ return;
+ reactToChange();
+ }
+ };
+
+ startDate.addActionListener(dateTimeListener);
+ endDate.addActionListener(dateTimeListener);
+
+ }
+ private boolean isPeriodValid(final Date start, final Date end, boolean feedback) {
+ if (start == null || end == null)
+ return false;
+ // analyse time stuff to see if its valid
+ if (start.after(end)) {
+ startDate.setForeground(Color.red);
+ if (feedback)
+ Gui.showMessageBox(me, "Startzeit is nach Endzeit!", MessageType.ERROR, LOGGER, null);
+ } else {
+ startDate.setForeground(dateTimeTextColor);
+ final Date now = new Date();
+ if (now.after(end)) {
+ if (feedback)
+ Gui.showMessageBox(me, "Endzeit liegt in die Vergangenheit!", MessageType.ERROR, LOGGER, null);
+ endDate.setForeground(Color.red);
+ } else {
+ endDate.setForeground(dateTimeTextColor);
+ return true;
+ }
+ }
+ return false;
+ }
+ /**
+ * Checks whether the user changed any fields of the image details and
+ * enables the save button if so.
+ */
+ private void reactToChange() {
+
+ boolean changed = false;
+ // version checkbox changed?
+ ImageVersionDetails currentVersion = cboVersions.getItemAt(cboVersions.getSelectedIndex());
+ if (currentVersion != null && !currentVersion.getVersionId().equals(lecture.getImageVersionId())) {
+ changed = true;
+ } else if ((DateTimeHelper.getDateFrom(startDate, startTime).getTime() / 1000L) != lecture.getStartTime()
+ || (DateTimeHelper.getDateFrom(endDate, endTime).getTime() / 1000L) != lecture.getEndTime()) {
+ changed = true;
+ } else if (!txtTitle.getText().isEmpty() && !txtTitle.getText().equals(lecture.getLectureName())) {
+ changed = true;
+ } else if (!txtDescription.getText().isEmpty() && !txtDescription.getText().equals(lecture.getDescription())) {
+ changed = true;
+ } else if (btnAutoUpdate.isSelected() != lecture.autoUpdate) {
+ changed = true;
+ } else if (btnIsExam.isSelected() != lecture.isExam) {
+ changed = true;
+ } else if (btnHasInternetAccess.isSelected() != lecture.hasInternetAccess) {
+ changed = true;
+ } else if (btnIsActive.isSelected() != lecture.isEnabled) {
+ changed = true;
+ } else if (chkCustomPermAdmin.isSelected() != lecture.defaultPermissions.admin) {
+ changed = true;
+ } else if (chkCustomPermEdit.isSelected() != lecture.defaultPermissions.edit) {
+ changed = true;
+ }
+
+ btnSaveChanges.setEnabled(changed);
+ }
+ /**
* Enables/disables the editable fields based on 'editable'
*
* @param editable true to make fields editable, false otherwise.
@@ -215,7 +436,6 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements
btnIsExam.setEnabled(editable);
btnAutoUpdate.setEnabled(editable);
cboVersions.setEnabled(editable && !lecture.autoUpdate);
- btnSaveChanges.setEnabled(editable);
btnChangeOwner.setEnabled(editable && LecturePerms.canAdmin(lecture));
startDate.setEnabled(editable); // TODO
startTime.setEnabled(editable);
@@ -230,34 +450,19 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements
* @param modalParent parent of this window
* @param lectureId id of the lecture to set the details of
*/
- public static void open(Frame modalParent, String lectureId) {
- LectureDetailsWindow win = new LectureDetailsWindow(modalParent);
+ public static void open(Frame modalParent, String lectureId, LectureUpdatedCallback callback) {
+ LectureDetailsWindow win = new LectureDetailsWindow(modalParent, callback);
win.setLecture(lectureId);
}
- /**
- * Triggers the download of the currently used image version of the lecture
- */
- private void performImageDownload() {
- if (image == null){
- Gui.showMessageBox(this, "Image ungültig.", MessageType.ERROR,
- null, null);
- return;
- }
- btnDownloadImage.setEnabled(false);
- long versionSize = 0;
- for (ImageVersionDetails version : image.versions) {
- if(version.versionId.equals(lecture.imageVersionId)){
- versionSize = version.fileSize;
- }
- }
- if (versionSize == 0){
- Gui.showMessageBox(this, "Fehler bei der Abfrag der Größe des Images.", MessageType.ERROR,
- null, null);
- return;
+ @SuppressWarnings("deprecation")
+ @Override
+ public void show() {
+ if (!isVisible()) {
+ pack();
+ MainWindow.centerShell(this);
}
- ThriftActions.initDownload(JOptionPane.getFrameForComponent(this), lecture.imageVersionId,
- image.imageName, image.virtId, versionSize, null);
+ super.show();
}
@Override