diff options
author | Simon Rettberg | 2015-09-03 18:41:00 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-09-03 18:41:00 +0200 |
commit | 8e6d9a0f347a258538d3a84ecb9123f39a7a9154 (patch) | |
tree | cffcfb2382cadc0023f0af4440833e683a6fab30 /dozentenmodul/src/main/java/org/openslx/dozmod | |
parent | Merge branch 'v1.1' of git.openslx.org:openslx-ng/tutor-module into v1.1 (diff) | |
download | tutor-module-8e6d9a0f347a258538d3a84ecb9123f39a7a9154.tar.gz tutor-module-8e6d9a0f347a258538d3a84ecb9123f39a7a9154.tar.xz tutor-module-8e6d9a0f347a258538d3a84ecb9123f39a7a9154.zip |
[client] Don't go crazy on lectures without an image
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod')
3 files changed, 128 insertions, 94 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 8c7b2b24..991c934d 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 @@ -8,6 +8,7 @@ import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.Comparator; @@ -118,6 +119,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements public void windowClosing(WindowEvent e) { safeClose(); } + @Override public void windowClosed(WindowEvent e) { dateChecker.cancel(); @@ -128,9 +130,10 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements @Override public void actionPerformed(ActionEvent e) { ImageSummaryRead newImage = LectureChangeLinkedImage.open(me); - if(newImage != null) { + if (newImage != null) { try { - image = ThriftManager.getSatClient().getImageDetails(Session.getSatelliteToken(), newImage.imageBaseId); + image = ThriftManager.getSatClient().getImageDetails(Session.getSatelliteToken(), + newImage.imageBaseId); } catch (TException e1) { LOGGER.error("Failed to retrieve details of new image: ", e1); return; @@ -139,7 +142,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements lecture.imageVersionId = newImage.latestVersionId; fillVersionsCombo(); cboVersions.setEnabled(false); - btnAutoUpdate.setSelected(true); + chkAutoUpdate.setSelected(true); imageLinkChanged = true; reactToChange(); } @@ -151,11 +154,12 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements btnClose.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - if (reactToChange() && - !Gui.showMessageBox(me, - "Änderungen werden verworfen, wollen Sie wirklich abbrechen?", MessageType.QUESTION_YESNO, LOGGER, null)) - return; - dispose(); + if (reactToChange() + && !Gui.showMessageBox(me, + "Änderungen werden verworfen, wollen Sie wirklich abbrechen?", + MessageType.QUESTION_YESNO, LOGGER, null)) + return; + dispose(); } }); btnDownloadImage.addActionListener(new ActionListener() { @@ -164,17 +168,16 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements performImageDownload(); } }); - btnAutoUpdate.addActionListener(new ActionListener() { + chkAutoUpdate.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - cboVersions.setEnabled(!btnAutoUpdate.isSelected()); + cboVersions.setEnabled(!chkAutoUpdate.isSelected()); } }); btnChangeOwner.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - UserListWindow.open(me, - new UserAddedCallback() { + UserListWindow.open(me, new UserAddedCallback() { @Override public void userAdded(UserInfo user, UserListWindow window) { window.dispose(); @@ -188,8 +191,8 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements public void actionPerformed(ActionEvent arg0) { LOGGER.info(permissionMap); LOGGER.info(lecture.defaultPermissions); - PermissionDefaultToCustomLink<LecturePermissions> pl = LectureCustomPermissionWindow.open( - me, permissionMap, lecture.defaultPermissions, lecture.ownerId); + PermissionDefaultToCustomLink<LecturePermissions> pl = LectureCustomPermissionWindow.open(me, + permissionMap, lecture.defaultPermissions, lecture.ownerId); if (pl != null && pl.defaultPermissions != null && pl.customPermissions != null) { lecture.defaultPermissions = pl.defaultPermissions; permissionMap = pl.customPermissions; @@ -227,27 +230,33 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements public void setLecture(final String lectureId) { ThriftActions.getLectureAndImageDetails(JOptionPane.getFrameForComponent(me), lectureId, new LectureMetaCallback() { - @Override - public void fetchedLectureAndImageDetails(LectureRead lectureDetails, - ImageDetailsRead imageDetails) { - synchronized (me) { - lecture = lectureDetails; - image = imageDetails; - permissionMap = ThriftActions.getLecturePermissions( - JOptionPane.getFrameForComponent(me), lecture.lectureId); - } - fill(); - } - }); + @Override + public void fetchedLectureAndImageDetails(LectureRead lectureDetails, + ImageDetailsRead imageDetails) { + synchronized (me) { + lecture = lectureDetails; + image = imageDetails; + permissionMap = ThriftActions.getLecturePermissions( + JOptionPane.getFrameForComponent(me), lecture.lectureId); + } + fill(); + } + }); } /** * callback function when we received the lecture's details from the server */ private void fill() { - if (lecture == null || image == null) + if (lecture == null) { + makeEditable(false); return; - txtImageName.setText(image.getImageName()); + } + if (image == null) { + txtImageName.setText("-"); + } else { + txtImageName.setText(image.getImageName()); + } txtTitle.setText(lecture.getLectureName()); txtDescription.setText(lecture.getDescription()); lblOwner.setUser(UserCache.find(lecture.getOwnerId())); @@ -258,10 +267,10 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements lblEndTime.setText(FormatHelper.longDate(lecture.getEndTime())); txtId.setText(lecture.getLectureId()); - btnIsActive.setSelected(lecture.isEnabled); - btnHasInternetAccess.setSelected(lecture.hasInternetAccess); - btnIsExam.setSelected(lecture.isExam); - btnAutoUpdate.setSelected(lecture.autoUpdate); + chkIsActive.setSelected(lecture.isEnabled); + chkHasInternetAccess.setSelected(lecture.hasInternetAccess); + chkIsExam.setSelected(lecture.isExam); + chkAutoUpdate.setSelected(lecture.autoUpdate); cboVersions.setEnabled(!lecture.autoUpdate); lblUseCount.setText(Integer.toString(lecture.useCount)); @@ -287,13 +296,18 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements } /** - * Helper to fill the combobox with the versions of the image. The list will be sorted by - * creation timestamp + * Helper to fill the combobox with the versions of the image. The list will + * be sorted by creation timestamp */ - private void fillVersionsCombo(){ + private void fillVersionsCombo() { + List<ImageVersionDetails> versions; + if (image == null) { + versions = new ArrayList<>(0); + } else { + versions = image.getVersions(); + } // version combo - List<ImageVersionDetails> versions = image.getVersions(); - for (Iterator<ImageVersionDetails> it = image.getVersions().iterator(); it.hasNext();) { + for (Iterator<ImageVersionDetails> it = versions.iterator(); it.hasNext();) { ImageVersionDetails version = it.next(); if (!version.isValid && !lecture.imageVersionId.equals(version.versionId)) { it.remove(); @@ -347,7 +361,12 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements long versionSize = 0; for (ImageVersionDetails version : image.versions) { if (version.versionId.equals(lecture.imageVersionId)) { + if (!version.isValid) { + Gui.showMessageBox(this, "Ungültiges Image gewählt", MessageType.ERROR, null, null); + return; + } versionSize = version.fileSize; + break; } } if (versionSize == 0) { @@ -377,7 +396,10 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements private void saveChanges() { // check, whether autoupdate is selected and choose version accordingly - lecture.imageVersionId = btnAutoUpdate.isSelected() ? image.latestVersionId : cboVersions.getItemAt(cboVersions.getSelectedIndex()).versionId; + if (image != null) { + lecture.imageVersionId = chkAutoUpdate.isSelected() ? image.latestVersionId + : cboVersions.getItemAt(cboVersions.getSelectedIndex()).versionId; + } // date valid TODO sat max time if (!isPeriodValid(DateTimeHelper.getDateFrom(startDate, startTime), @@ -386,10 +408,10 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements } // first build the ImageBaseWrite from the GUI fields final LectureWrite lectureWrite = new LectureWrite(txtTitle.getText(), txtDescription.getText(), - lecture.getImageVersionId(), btnAutoUpdate.isSelected(), btnIsActive.isSelected(), + lecture.getImageVersionId(), chkAutoUpdate.isSelected(), chkIsActive.isSelected(), DateTimeHelper.getDateFrom(startDate, startTime).getTime() / 1000L, DateTimeHelper.getDateFrom(endDate, endTime).getTime() / 1000L, null, null, - btnIsExam.isSelected(), btnHasInternetAccess.isSelected(), lecture.getDefaultPermissions()); + chkIsExam.isSelected(), chkHasInternetAccess.isSelected(), lecture.getDefaultPermissions()); // now trigger the actual action btnSaveChanges.setEnabled(false); try { @@ -461,10 +483,10 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements reactToChange(); } }; - btnAutoUpdate.addActionListener(checkBoxListener); - btnIsExam.addActionListener(checkBoxListener); - btnHasInternetAccess.addActionListener(checkBoxListener); - btnIsActive.addActionListener(checkBoxListener); + chkAutoUpdate.addActionListener(checkBoxListener); + chkIsExam.addActionListener(checkBoxListener); + chkHasInternetAccess.addActionListener(checkBoxListener); + chkIsActive.addActionListener(checkBoxListener); dateChecker = new Task() { @Override @@ -483,7 +505,8 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements * * @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 + * @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) { @@ -493,7 +516,8 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements if (start.after(end)) { startDate.setForeground(Color.red); if (feedback) - Gui.showMessageBox(me, "Start der Veranstaltung ist nach dem Enddatum!", MessageType.ERROR, LOGGER, null); + Gui.showMessageBox(me, "Start der Veranstaltung ist nach dem Enddatum!", MessageType.ERROR, + LOGGER, null); } else { startDate.setForeground(dateTimeTextColor); final Date now = new Date(); @@ -528,17 +552,17 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements } else if (!txtDescription.getText().isEmpty() && !txtDescription.getText().equals(lecture.getDescription())) { changed = true; - } else if (btnAutoUpdate.isSelected() != lecture.autoUpdate) { + } else if (chkAutoUpdate.isSelected() != lecture.autoUpdate) { changed = true; - } else if (btnIsExam.isSelected() != lecture.isExam) { + } else if (chkIsExam.isSelected() != lecture.isExam) { changed = true; - } else if (btnHasInternetAccess.isSelected() != lecture.hasInternetAccess) { + } else if (chkHasInternetAccess.isSelected() != lecture.hasInternetAccess) { changed = true; - } else if (btnIsActive.isSelected() != lecture.isEnabled) { + } else if (chkIsActive.isSelected() != lecture.isEnabled) { changed = true; } else if (permissionsChanged) { changed = true; - } else if(imageLinkChanged) { + } else if (imageLinkChanged) { changed = true; } @@ -556,9 +580,9 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements txtTitle.setEditable(editable); txtDescription.setEditable(editable); btnLinkImage.setEnabled(editable); - btnIsExam.setEnabled(editable); - btnAutoUpdate.setEnabled(editable); - cboVersions.setEnabled(editable && !lecture.autoUpdate); + chkIsExam.setEnabled(editable); + chkAutoUpdate.setEnabled(editable); + cboVersions.setEnabled(editable && !lecture.autoUpdate && image != null); btnChangeOwner.setEnabled(editable && LecturePerms.canAdmin(lecture)); btnPermissions.setEnabled(editable && LecturePerms.canAdmin(lecture)); startDate.setEnabled(editable); @@ -605,15 +629,16 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements // Also ask if applicable 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; + if (reactToChange() + && !Gui.showMessageBox(me, "Änderungen werden verworfen, wollen Sie wirklich abbrechen?", + MessageType.QUESTION_YESNO, LOGGER, null)) + return; dispose(); } } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java index de8867d1..f2c5f881 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java @@ -53,11 +53,11 @@ public abstract class LectureDetailsWindowLayout extends JDialog { protected final QLabel lblUpdateTime; protected final QLabel lblStartTime; protected final QLabel lblEndTime; - protected final JCheckBox btnAutoUpdate; + protected final JCheckBox chkAutoUpdate; protected final JComboBox<ImageVersionDetails> cboVersions; - protected final JCheckBox btnIsExam; - protected final JCheckBox btnHasInternetAccess; - protected final JCheckBox btnIsActive; + protected final JCheckBox chkIsExam; + protected final JCheckBox chkHasInternetAccess; + protected final JCheckBox chkIsActive; protected final JTextField txtId; protected final QLabel lblUseCount; @@ -118,12 +118,12 @@ public abstract class LectureDetailsWindowLayout extends JDialog { grid.add(txtImageName).expand(true, false); // link button for image btnLinkImage = new JButton("Ändern"); - grid.add(btnLinkImage); + grid.add(btnLinkImage).fill(true, false); grid.nextRow(); // image version handling // auto update - btnAutoUpdate = new JCheckBox("Immer aktuellste Version verwenden"); + chkAutoUpdate = new JCheckBox("Immer aktuellste Version verwenden"); // versions combo cboVersions = new ComboBox<>(Comparators.imageVersionDetails, new ComboBoxRenderer<ImageVersionDetails>() { @@ -141,11 +141,11 @@ public abstract class LectureDetailsWindowLayout extends JDialog { btnDownloadImage = new JButton("Download"); btnDownloadImage.setToolTipText("Momentan verwendete Version herunterladen"); JPanel versionPanel = new JPanel(new BorderLayout()); - versionPanel.add(btnDownloadImage, BorderLayout.EAST); versionPanel.add(cboVersions, BorderLayout.CENTER); - versionPanel.add(btnAutoUpdate, BorderLayout.SOUTH); + versionPanel.add(chkAutoUpdate, BorderLayout.SOUTH); grid.add(new QLabel("Image-Version")); - grid.add(versionPanel, 2); + grid.add(versionPanel); + grid.add(btnDownloadImage).fill(true, false); grid.nextRow(); // start time of the lecture @@ -177,7 +177,7 @@ public abstract class LectureDetailsWindowLayout extends JDialog { btnChangeOwner = new JButton("Ändern"); grid.add(new QLabel("Besitzer")); grid.add(lblOwner).expand(true, false); - grid.add(btnChangeOwner); + grid.add(btnChangeOwner).fill(true, false); grid.nextRow(); // creation time @@ -199,19 +199,19 @@ public abstract class LectureDetailsWindowLayout extends JDialog { grid.nextRow(); // is exam - btnIsExam = new JCheckBox("Klausur"); + chkIsExam = new JCheckBox("Klausur"); grid.skip(); - grid.add(btnIsExam, 2); + grid.add(chkIsExam, 2); grid.nextRow(); - btnHasInternetAccess = new JCheckBox("Internetzugriff"); + chkHasInternetAccess = new JCheckBox("Internetzugriff"); grid.skip(); - grid.add(btnHasInternetAccess, 2); + grid.add(chkHasInternetAccess, 2); grid.nextRow(); - btnIsActive = new JCheckBox("Aktiv"); + chkIsActive = new JCheckBox("Aktiv"); grid.skip(); - grid.add(btnIsActive, 2); + grid.add(chkIsActive, 2); grid.nextRow(); // id diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java index ca13e4c6..9022534c 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java @@ -524,12 +524,14 @@ public class ThriftActions { } /** - * Helper to generate a directory name for the given imageName and imageVersionId. - * Uses the given parameters to build a hopefully unique name as it takes the first 8 + * Helper to generate a directory name for the given imageName and + * imageVersionId. + * Uses the given parameters to build a hopefully unique name as it takes + * the first 8 * chars of the version id... * * @param imageName name of the image - * @param imageVersionId version id + * @param imageVersionId version id * @return generated directory name as String */ private static String generateDirname(String imageName, String imageVersionId) { @@ -555,7 +557,8 @@ public class ThriftActions { } /** - * BLOCKING Gets the image details (w/o permissions) of the given imageBaseID + * BLOCKING Gets the image details (w/o permissions) of the given + * imageBaseID * * @param frame to display user feedback on * @param imageBaseId image's id to get the details of @@ -572,8 +575,10 @@ public class ThriftActions { } /** - * NON-BLOCKING Gets the image details (without permissions) of the given imageBaseId. - * Will return the details (or null if fetching failed) back to the gui-thread + * NON-BLOCKING Gets the image details (without permissions) of the given + * imageBaseId. + * Will return the details (or null if fetching failed) back to the + * gui-thread * through the given callback * * @param frame to display user feedback on @@ -601,7 +606,8 @@ public class ThriftActions { } /** - * NON-BLOCKING Gets the image details and the user-specific permission list of + * NON-BLOCKING Gets the image details and the user-specific permission list + * of * the given imageBaseId. Will return the objects through the given callback * * @param frame to display user feedback on @@ -631,7 +637,8 @@ public class ThriftActions { } /** - * NON-BLOCKING Gets the user-specific permission list for the given imageBaseId + * NON-BLOCKING Gets the user-specific permission list for the given + * imageBaseId * * @param frame to display user feedback on * @param imageBaseId image's id to get the permission list of @@ -719,7 +726,7 @@ public class ThriftActions { * * @param frame to display user feedback on * @param imageBaseId image base id to delete - * @param callback interface to report the outcome to the gui + * @param callback interface to report the outcome to the gui */ public static void deleteImageBase(final Frame frame, final String imageBaseId, final DeleteCallback callback) { @@ -907,8 +914,6 @@ public class ThriftActions { * * *******************************************************************************/ - - /** * Interface for GUI-classes running async lecture meta calls */ @@ -917,7 +922,10 @@ public class ThriftActions { } /** - * NON-BLOCKING Gets the lecture and image details of the given lectureId + * NON-BLOCKING Gets the lecture and image details of the given lectureId. + * IF the lecture does not exist, both fields returned will be null. If the + * lecture exists, the image can still be null, since not all lectures link + * to an image at all times. * * @param frame to display user feedback on * @param lectureId lecture to get the full details of @@ -929,13 +937,12 @@ public class ThriftActions { @Override public void fire() { final LectureRead lecture = ThriftActions.getLectureDetails(frame, lectureId); - ImageDetailsRead image = null; - if (lecture != null) { - image = ThriftActions.getImageDetails(frame, lecture.getImageBaseId()); + final ImageDetailsRead fImage; + if (lecture != null && lecture.imageBaseId != null) { + fImage = ThriftActions.getImageDetails(frame, lecture.getImageBaseId()); + } else { + fImage = null; } - if (image == null) - return; - final ImageDetailsRead fImage = image; Gui.asyncExec(new Runnable() { @Override public void run() { @@ -985,12 +992,14 @@ public class ThriftActions { } /** - * BLOCKING Gets the list of user-specific permission for the lecture with the + * BLOCKING Gets the list of user-specific permission for the lecture with + * the * given lectureId * * @param frame to display user feedback on * @param lectureId lecture's id to get the permission list of - * @return the map of the userid-permissions if fetching worked, null otherwise + * @return the map of the userid-permissions if fetching worked, null + * otherwise */ public static Map<String, LecturePermissions> getLecturePermissions(final Frame frame, final String lectureId) { |