summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java
diff options
context:
space:
mode:
authorJonathan Bauer2015-08-17 16:59:42 +0200
committerJonathan Bauer2015-08-17 16:59:42 +0200
commita1d59dfdce06d8dcdfa8c01435013e2e1e7b6c51 (patch)
tree166c61131410d41f9f7063a4b41b948a31171ae4 /dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java
parentMerge branch 'v1.1' of git.openslx.org:openslx-ng/tutor-module into v1.1 (diff)
downloadtutor-module-a1d59dfdce06d8dcdfa8c01435013e2e1e7b6c51.tar.gz
tutor-module-a1d59dfdce06d8dcdfa8c01435013e2e1e7b6c51.tar.xz
tutor-module-a1d59dfdce06d8dcdfa8c01435013e2e1e7b6c51.zip
[client] cleanup the messy image list code...
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java169
1 files changed, 114 insertions, 55 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java
index 8e953375..8f338e5f 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java
@@ -42,6 +42,10 @@ import org.openslx.thrifthelper.ThriftManager;
import org.openslx.util.QuickTimer;
import org.openslx.util.QuickTimer.Task;
+/**
+ * @author joe
+ *
+ */
@SuppressWarnings("serial")
public class ImageListWindow extends ImageListWindowLayout {
@@ -172,30 +176,7 @@ public class ImageListWindow extends ImageListWindowLayout {
deleteButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
- final ImageSummaryRead image = getSelectedImage();
- if (image == null)
- return;
- // check if we have a version
- if (image.isSetLatestVersionId()) {
- // try to actually delete this version of the image
- try {
- ThriftManager.getSatClient().deleteImageVersion(Session.getSatelliteToken(),
- image.getLatestVersionId());
- LOGGER.info("Deleted version '" + image.getLatestVersionId() + "' of image '"
- + image.getImageBaseId() + "'.");
- refreshList(true);
- } catch (TAuthorizationException e) {
- Gui.showMessageBox(me, "Sie sind nicht autorisiert dieses Image zu löschen!",
- MessageType.ERROR, LOGGER, e);
- } catch (TNotFoundException e) {
- Gui.showMessageBox(me, "Diese Image existiert nicht auf dem Satelliten!",
- MessageType.ERROR, LOGGER, e);
- } catch (TException e) {
- Gui.showMessageBox(me, "Interner Fehler! Siehe Logs.", MessageType.ERROR, LOGGER, e);
- }
- } else {
- Gui.showMessageBox(me, "Keine Version für diese Image!", MessageType.ERROR, LOGGER, null);
- }
+ deleteLatestVersion(getSelectedImage());
}
});
@@ -216,18 +197,17 @@ public class ImageListWindow extends ImageListWindowLayout {
updateAvailableOptions(null);
}
-
- private void startLectureWizard(ImageSummaryRead image) {
- if (image == null)
- return;
- if (image.getLatestVersionId() == null) {
- Gui.showMessageBox(me, "Das gewählte Image besitzt keine gültige Image-Version",
- MessageType.ERROR, null, null);
- return;
- }
- new LectureWizard(SwingUtilities.getWindowAncestor(this), image, image.getLatestVersionId()).setVisible(true);
- }
-
+ /********************************************************************************
+ *
+ * General GUI and table helpers
+ *
+ ********************************************************************************/
+
+ /**
+ * Refreshes the image list in the table
+ *
+ * @param forceRefresh true to force a refresh, false to use the cached list
+ */
private void refreshList(final boolean forceRefresh) {
QuickTimer.scheduleOnce(new Task() {
@Override
@@ -243,6 +223,11 @@ public class ImageListWindow extends ImageListWindowLayout {
});
}
+ /**
+ * Helper to return the selected image from the table or show an error to the user if none is selected
+ *
+ * @return the image selected in the table, null if there is no selection
+ */
private final ImageSummaryRead getSelectedImage() {
final ImageSummaryRead image = imageTable.getSelectedItem();
if (image == null) {
@@ -253,29 +238,26 @@ public class ImageListWindow extends ImageListWindowLayout {
}
}
- @Override
- public boolean requestHide() {
- return true;
- }
-
- @Override
- public void requestShow() {
- refreshList(false);
- }
-
- private void performImageDownload(ImageSummaryRead image) {
+ /**
+ * Helper to check if the given image has a latest version
+ *
+ * @param image the image to check for a latest version
+ * @return true if the image has a latest version, false otherwise
+ */
+ private boolean hasLatestVersion(ImageSummaryRead image) {
if (image == null)
- return;
- if (image.latestVersionId == null) {
- Gui.showMessageBox(this, "Das ausgewählte Image hat keine gültige Version", MessageType.ERROR,
- null, null);
- return;
+ return false;
+ if (image.getLatestVersionId() == null) {
+ Gui.showMessageBox(me, "Das gewählte Image besitzt keine gültige Image-Version",
+ MessageType.ERROR, null, null);
+ return false;
}
- downloadButton.setEnabled(false);
- TransferHelper.initDownload(JOptionPane.getFrameForComponent(this), image.latestVersionId,
- image.imageName, image.virtId, image.fileSize);
+ return true;
}
+ /**
+ * Filters the image list according to the filter text entered by the user
+ */
private void applyFilterOnTable() {
try {
// List for filters
@@ -325,6 +307,11 @@ public class ImageListWindow extends ImageListWindowLayout {
}
}
+ /**
+ * Updates the buttons/popup menu items according to the user's permissions
+ *
+ * @param item the image to check the user's permissions for
+ */
private void updateAvailableOptions(ImageSummaryRead item) {
boolean download = ImagePerms.canDownload(item);
boolean link = ImagePerms.canLink(item);
@@ -336,5 +323,77 @@ public class ImageListWindow extends ImageListWindowLayout {
popupItemNewLecture.setEnabled(link);
popupItemDelete.setEnabled(admin);
}
+ /********************************************************************************
+ *
+ * Helpers triggering the remote thrift calls
+ *
+ ********************************************************************************/
+
+ /**
+ * Starts a lecture wizard for the given image if it has a valid version
+ *
+ * @param image image to link the new lecture to
+ */
+ private void startLectureWizard(ImageSummaryRead image) {
+ if (!hasLatestVersion(image))
+ return;
+ new LectureWizard(SwingUtilities.getWindowAncestor(this), image, image.getLatestVersionId()).setVisible(true);
+ }
+
+ /**
+ * Triggers a download of the given image's latest version
+ *
+ * @param image the image to download
+ */
+ private void performImageDownload(ImageSummaryRead image) {
+ if (!hasLatestVersion(image))
+ return;
+ downloadButton.setEnabled(false);
+ TransferHelper.initDownload(JOptionPane.getFrameForComponent(this), image.latestVersionId,
+ image.imageName, image.virtId, image.fileSize);
+ }
+ /**
+ * Deletes the latest version of the given image if it has one
+ *
+ * @param image image to delete
+ */
+ private void deleteLatestVersion(final ImageSummaryRead image) {
+ if (!hasLatestVersion(image))
+ return;
+ // requires confirmation of the user
+ if (!Gui.showMessageBox(me, "Wollen Sie die letzte Version von dieses Image wirklich löschen?", MessageType.QUESTION_YESNO, LOGGER, null))
+ return;
+ // try to actually delete this version of the image
+ try {
+ ThriftManager.getSatClient().deleteImageVersion(Session.getSatelliteToken(),
+ image.getLatestVersionId());
+ LOGGER.info("Deleted version '" + image.getLatestVersionId() + "' of image '"
+ + image.getImageBaseId() + "'.");
+ refreshList(true);
+ } catch (TAuthorizationException e) {
+ Gui.showMessageBox(me, "Sie sind nicht autorisiert dieses Image zu löschen!",
+ MessageType.ERROR, LOGGER, e);
+ } catch (TNotFoundException e) {
+ Gui.showMessageBox(me, "Diese Image existiert nicht auf dem Satelliten!",
+ MessageType.ERROR, LOGGER, e);
+ } catch (TException e) {
+ Gui.showMessageBox(me, "Interner Fehler! Siehe Logs.", MessageType.ERROR, LOGGER, e);
+ }
+ }
+
+ /********************************************************************************
+ *
+ * CompositePage abstract methods implementation
+ *
+ ********************************************************************************/
+ @Override
+ public boolean requestHide() {
+ return true;
+ }
+
+ @Override
+ public void requestShow() {
+ refreshList(false);
+ }
}