diff options
author | Stephan Schwaer | 2015-08-03 18:11:39 +0200 |
---|---|---|
committer | Stephan Schwaer | 2015-08-03 18:11:39 +0200 |
commit | ba9eadf7288cbc697c6a82884e2d590e81ed88ed (patch) | |
tree | 8cf1c86975e13fe949a87fba11ec69ac55499650 /dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java | |
parent | [client] Remove debug output from LoginWindow (diff) | |
download | tutor-module-ba9eadf7288cbc697c6a82884e2d590e81ed88ed.tar.gz tutor-module-ba9eadf7288cbc697c6a82884e2d590e81ed88ed.tar.xz tutor-module-ba9eadf7288cbc697c6a82884e2d590e81ed88ed.zip |
[client] Added lecture details layout and window. (not working yet)
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.java | 147 |
1 files changed, 147 insertions, 0 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 new file mode 100644 index 00000000..ee7f5db8 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java @@ -0,0 +1,147 @@ +package org.openslx.dozmod.gui.window; + +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import org.apache.log4j.Logger; +import org.openslx.bwlp.thrift.iface.ImageDetailsRead; +import org.openslx.bwlp.thrift.iface.LectureRead; +import org.openslx.bwlp.thrift.iface.OperatingSystem; +import org.openslx.bwlp.thrift.iface.Virtualizer; +import org.openslx.dozmod.gui.Gui; +import org.openslx.dozmod.gui.MainWindow; +import org.openslx.dozmod.gui.helper.MessageType; +import org.openslx.dozmod.gui.window.layout.LectureDetailsWindowLayout; +import org.openslx.dozmod.permissions.ImagePerms; +import org.openslx.dozmod.thrift.MetaDataCache; +import org.openslx.dozmod.thrift.Session; +import org.openslx.dozmod.thrift.UserCache; +import org.openslx.dozmod.util.FormatHelper; +import org.openslx.thrifthelper.ThriftManager; +import org.openslx.util.QuickTimer; +import org.openslx.util.QuickTimer.Task; + +@SuppressWarnings("serial") +public class LectureDetailsWindow extends LectureDetailsWindowLayout { + + private static final Logger LOGGER = Logger.getLogger(LectureDetailsWindow.class); + + private final LectureDetailsWindow me = this; + + private LectureRead lecture = null; + + public LectureDetailsWindow(Frame modalParent) { + super(modalParent); + + // Close button closes window + btnClose.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + dispose(); + } + }); + // ESC closes this window + addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + LOGGER.debug("he"); + if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { + dispose(); + } + } + }); + setFocusable(true); + } + + /** + * @param lectureId the id of the image to be displayed + */ + public void setLecture(final String lectureId) { + + QuickTimer.scheduleOnce(new Task() { + @Override + public void fire() { + Exception error = null; + try { + synchronized (me) { + if (lecture != null) + return; + lecture = ThriftManager.getSatClient().getLectureDetails(Session.getSatelliteToken(), lectureId); + } + } catch (Exception e) { + error = e; + } + final Exception e = error; + Gui.asyncExec(new Runnable() { + @Override + public void run() { + if (e != null || lecture == null) { + Gui.showMessageBox(null, "Konnte Daten der Vorlesung nicht abrufen", + MessageType.ERROR, LOGGER, e); + dispose(); + } else { + fill(); + } + } + }); + } + }); + } + + /** + * callback function when we received the image's details from the server + */ + private void fill() { + if (lecture == null) + return; + txtTitle.setText(lecture.getLectureName()); + txtDescription.setText(lecture.getDescription()); + if (lecture.image != null) + txtImageName.setText(lecture.image.getImageName()); + lblOwner.setUser(UserCache.find(lecture.getOwnerId())); + lblUpdater.setUser(UserCache.find(lecture.getUpdaterId())); + lblCreateTime.setText(FormatHelper.longDate(lecture.getCreateTime())); + lblUpdateTime.setText(FormatHelper.longDate(lecture.getUpdateTime())); + lblStartTime.setText(FormatHelper.longDate(lecture.getStartTime())); + lblEndTime.setText(FormatHelper.longDate(lecture.getEndTime())); + + txtId.setText(lecture.getLectureId()); + + btnIsEnabled.setSelected(lecture.isEnabled); + btnIsExam.setSelected(lecture.isExam); + // TODO grey out non editable components + //makeEditable(ImagePerms.canEdit(lecture)); + pack(); + MainWindow.centerShell(this); + setVisible(true); + } + + /** + * Enables/disables the editable fields based on 'editable' + * + * @param editable true to make fields editable, false otherwise. + */ + private void makeEditable(boolean editable) { + txtTitle.setEnabled(editable); + txtDescription.setEnabled(editable); + txtId.setEnabled(editable); + } + + /** + * Opens a new LectureDetailsWindow showing the details of the + * lecture with ID = lectureId + * + * @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); + win.setLecture(lectureId); + } +} |