diff options
author | Jonathan Bauer | 2015-08-17 17:34:02 +0200 |
---|---|---|
committer | Jonathan Bauer | 2015-08-17 17:34:02 +0200 |
commit | fd861012451d85f0e6f01efa4ad9620217ebb86a (patch) | |
tree | 28262f680dd95953516512506dfc834d09dd6116 /dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java | |
parent | [client] minor fix (diff) | |
download | tutor-module-fd861012451d85f0e6f01efa4ad9620217ebb86a.tar.gz tutor-module-fd861012451d85f0e6f01efa4ad9620217ebb86a.tar.xz tutor-module-fd861012451d85f0e6f01efa4ad9620217ebb86a.zip |
[client] cleanup ImageDetailsWindow
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java | 146 |
1 files changed, 95 insertions, 51 deletions
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 a8091383..22b69f8d 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 @@ -50,36 +50,53 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe private static final Logger LOGGER = Logger.getLogger(ImageDetailsWindow.class); + /** + * Self-reference + */ private final ImageDetailsWindow me = this; + /** + * Callback interface to refresh image list after changing image details + */ public interface ImageUpdatedCallback { public void updated(); } + /** + * Callback instance + */ private ImageUpdatedCallback callback = null; + /** + * Image that this window shows the details of + */ private ImageDetailsRead image = null; + /** + * Popup menu items + */ private JMenuItem popupItemNew = new JMenuItem("Neue Veranstaltung"); private JMenuItem popupItemDownload = new JMenuItem("Download"); private JMenuItem popupItemDelete = new JMenuItem("Löschen"); + /** + * Constructor + * + * @param modalParent parent of this popup window + * @param callback callback to be called when the image details changed + */ public ImageDetailsWindow(Frame modalParent, ImageUpdatedCallback callback) { super(modalParent); this.callback = callback; - setFocusable(true); - btnSaveChanges.setEnabled(false); - txtVersion.setEditable(false); - txtId.setEditable(false); - // Close button closes window + /** + * Button listeners + */ btnClose.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dispose(); } }); - - // nothing to save at first since nothing changed btnSaveChanges.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -87,7 +104,6 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe saveChanges(); } }); - btnChangeOwner.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -103,7 +119,9 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe } }); - // Setup popup menu for the right panel + /** + * Popup menu for the version table on the right side + */ final PopupMenu pop = new PopupMenu(new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getSource().equals(popupItemNew)) { @@ -129,25 +147,24 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe } }); - // add them to the popup menu pop.addMenuItem(popupItemNew); pop.addMenuItem(popupItemDownload); pop.addSeparator(); pop.addMenuItem(popupItemDelete); // TODO check permissions and disable them if needed - // mouse adapter to register clicks and react on the right panel + /** + * Mouse adapter for the version table + */ final MouseAdapter ma = new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { processClick(e); } - @Override public void mouseReleased(MouseEvent e) { processClick(e); } - private void processClick(MouseEvent e) { int r = versionTable.rowAtPoint(e.getPoint()); if (r >= 0 && r < versionTable.getRowCount()) { @@ -161,19 +178,29 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe } } }; - // register mouse adapter for the right panel versionTableScrollPane.addMouseListener(ma); versionTable.addMouseListener(ma); + /** + * Initial state of GUI elements + */ + setFocusable(true); + btnSaveChanges.setEnabled(false); + txtVersion.setEditable(false); + txtId.setEditable(false); chkIsTemplate.setEnabled(Session.isSuperUser()); makeEditable(false); } + /******************************************************************************** + * + * Helper triggering the actual thrift calls + * + ********************************************************************************/ /** * @param imageBaseId the id of the image to be displayed */ public void setImage(final String imageBaseId) { - QuickTimer.scheduleOnce(new Task() { @Override public void fire() { @@ -209,7 +236,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe } /** - * Push the changes to the satellite + * Push the changes of the image details to the satellite */ private void saveChanges() { // first we build an ImageBaseWrite @@ -274,6 +301,28 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe } /** + * Triggers the download of the given image version + * + * @param selected image to download + */ + private void performImageDownload(ImageVersionDetails selected) { + if (selected == null) + return; + if (selected.getVersionId() == null) { + Gui.showMessageBox(this, "Ausgewählte Version ist ungültig", MessageType.ERROR, + null, null); + return; + } + TransferHelper.initDownload(JOptionPane.getFrameForComponent(this), selected.versionId, + image.imageName, image.virtId, selected.fileSize); + } + + /******************************************************************************** + * + * General UI helpers + * + ********************************************************************************/ + /** * callback function when we received the image's details from the server */ private void fill() { @@ -363,16 +412,6 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe setVisible(true); } - @SuppressWarnings("deprecation") - @Override - public void show() { - if (!isVisible()) { - pack(); - MainWindow.centerShell(this); - } - super.show(); - } - /** * Enables/disables the editable fields based on 'editable' * @@ -389,18 +428,6 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe } /** - * Opens a new ImageDetailsWindow showing the details of the image with ID = - * imageBaseId - * - * @param modalParent parent of this window - * @param imageBaseId id of the image to set the details of - */ - public static void open(Frame modalParent, String imageBaseId, ImageUpdatedCallback callback) { - ImageDetailsWindow win = new ImageDetailsWindow(modalParent, callback); - win.setImage(imageBaseId); - } - - /** * Checks whether the user changed any fields of the image details and * enables the save button if so. */ @@ -423,7 +450,37 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe // TODO TAGS btnSaveChanges.setEnabled(changed); } + /** + * Opens a new ImageDetailsWindow showing the details of the image with ID = + * imageBaseId + * + * @param modalParent parent of this window + * @param imageBaseId id of the image to set the details of + */ + public static void open(Frame modalParent, String imageBaseId, ImageUpdatedCallback callback) { + ImageDetailsWindow win = new ImageDetailsWindow(modalParent, callback); + win.setImage(imageBaseId); + } + /******************************************************************************** + * + * Dialog class overrides + * + ********************************************************************************/ + @SuppressWarnings("deprecation") + @Override + public void show() { + if (!isVisible()) { + pack(); + MainWindow.centerShell(this); + } + super.show(); + } + /******************************************************************************** + * + * UIFeedback implementation + * + ********************************************************************************/ @Override public boolean wantConfirmQuit() { return btnSaveChanges.isEnabled(); @@ -434,17 +491,4 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe // Also ask if applicable this.dispose(); } - - private void performImageDownload(ImageVersionDetails selected) { - if (selected == null) - return; - if (selected.getVersionId() == null) { - Gui.showMessageBox(this, "Ausgewählte Version ist ungültig", MessageType.ERROR, - null, null); - return; - } - TransferHelper.initDownload(JOptionPane.getFrameForComponent(this), selected.versionId, - image.imageName, image.virtId, selected.fileSize); - } - } |