diff options
Diffstat (limited to 'dozentenmodul/src')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java | 103 |
1 files changed, 75 insertions, 28 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 7705f792..5f9a5767 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 @@ -10,6 +10,7 @@ import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -142,7 +143,8 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe } /** - * @param imageBaseId the id of the image to be displayed + * @param imageBaseId + * the id of the image to be displayed */ public void setImage(final String imageBaseId) { @@ -154,8 +156,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe synchronized (me) { if (image != null) return; - image = ThriftManager.getSatClient().getImageDetails(Session.getSatelliteToken(), - imageBaseId); + image = ThriftManager.getSatClient().getImageDetails(Session.getSatelliteToken(), imageBaseId); } } catch (Exception e) { error = e; @@ -168,8 +169,8 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe @Override public void run() { if (e != null || image == null) { - Gui.showMessageBox(null, "Konnte Daten des Images nicht abrufen", - MessageType.ERROR, LOGGER, e); + Gui.showMessageBox(null, "Konnte Daten des Images nicht abrufen", MessageType.ERROR, LOGGER, + e); dispose(); } else { fill(); @@ -226,22 +227,24 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe pack(); MainWindow.centerShell(this); - // final step, add listen - // the document stuff + // final step, add listeners final DocumentListener docListener = new DocumentListener() { @Override - public void removeUpdate(DocumentEvent e) { changedUpdate(e); } + public void removeUpdate(DocumentEvent e) { + changedUpdate(e); + } + @Override - public void insertUpdate(DocumentEvent e) { changedUpdate(e); } + public void insertUpdate(DocumentEvent e) { + changedUpdate(e); + } + @Override public void changedUpdate(DocumentEvent e) { - - btnSaveChanges.setEnabled( - txtDescription.getText() != image.getDescription() - // TODO TAGS - ); + reactToChange(); } }; + txtTitle.getDocument().addDocumentListener(docListener); txtDescription.getDocument().addDocumentListener(docListener); txtTags.getDocument().addDocumentListener(docListener); @@ -250,19 +253,20 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { - // get new selected object - // the ugly: - OperatingSystem newOs = cboOperatingSystem.getItemAt(cboOperatingSystem.getSelectedIndex()); - ShareMode newShareMode = cboShareMode.getItemAt(cboShareMode.getSelectedIndex()); - // change occured, make the save button active - btnSaveChanges.setEnabled( - newOs != null && newOs.getOsId() != image.getOsId() - || newShareMode != null && newShareMode.equals(image.shareMode)); + reactToChange(); } } }; cboOperatingSystem.addItemListener(comboItemListener); cboShareMode.addItemListener(comboItemListener); + btnIsTemplate.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + reactToChange(); + + } + }); // finally do show it setVisible(true); } @@ -270,7 +274,8 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe /** * Enables/disables the editable fields based on 'editable' * - * @param editable true to make fields editable, false otherwise. + * @param editable + * true to make fields editable, false otherwise. */ private void makeEditable(boolean editable) { txtTitle.setEditable(editable); @@ -284,20 +289,62 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe } /** - * Opens a new ImageDetailsWindow showing the details of the - * image with ID = imageBaseId + * 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 + * @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) { ImageDetailsWindow win = new ImageDetailsWindow(modalParent); win.setImage(imageBaseId); } + /** + * Checks whether the user changed any fields of the image details and + * enables the save button if so. + * + */ + private void reactToChange() { + boolean changed = false; + // Image name: + if (!txtTitle.getText().equals(image.getImageName())) { + LOGGER.debug("Title changed to: " + txtTitle.getText()); + changed =true; + } + // Image description: + if (!txtDescription.getText().equals(image.getDescription())) { + LOGGER.debug("Description changed to: " + txtDescription.getText()); + changed = true; + } + // OS: + OperatingSystem newOs = cboOperatingSystem.getItemAt(cboOperatingSystem.getSelectedIndex()); + if (newOs != null && newOs.getOsId() != image.getOsId()) { + LOGGER.debug("OS changed to: " + newOs.getOsName()); + changed = true; + } + // TODO TAGS + // ShareMode: + ShareMode newShareMode = cboShareMode.getItemAt(cboShareMode.getSelectedIndex()); + if (newShareMode != null && !newShareMode.equals(image.shareMode)) { + LOGGER.debug("ShareMode changed to: " + newShareMode); + changed = true; + } + // Template: + if (btnIsTemplate.isSelected() != image.isTemplate) { + LOGGER.debug("Template changed to: " + btnIsTemplate.isSelected()); + changed = true; + } + btnSaveChanges.setEnabled(changed); + + } + @Override public boolean wantConfirmQuit() { - // Maybe return true if the user changed one of the fields, but not really a priority + // Maybe return true if the user changed one of the fields, but not + // really a priority return false; } |