diff options
author | Simon Rettberg | 2015-08-11 17:50:41 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-08-11 17:50:41 +0200 |
commit | 67d6892eaa5f004674c8641438d09ffc6baade18 (patch) | |
tree | 1d147fbf7dcd8c49fcf214fa5d3234374f241215 | |
parent | [server] Don't try to deserialize null (diff) | |
download | tutor-module-67d6892eaa5f004674c8641438d09ffc6baade18.tar.gz tutor-module-67d6892eaa5f004674c8641438d09ffc6baade18.tar.xz tutor-module-67d6892eaa5f004674c8641438d09ffc6baade18.zip |
[client] Show image name in lecture wizard; check form validity on "Next"
8 files changed, 66 insertions, 79 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 c5e124a2..3c9ccf56 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 @@ -17,6 +17,8 @@ import javax.swing.event.DocumentListener; import org.apache.log4j.Logger; import org.openslx.bwlp.thrift.iface.ImageDetailsRead; +import org.openslx.bwlp.thrift.iface.ImageSummaryRead; +import org.openslx.bwlp.thrift.iface.ImageVersionDetails; import org.openslx.bwlp.thrift.iface.OperatingSystem; import org.openslx.bwlp.thrift.iface.ShareMode; import org.openslx.bwlp.thrift.iface.Virtualizer; @@ -84,7 +86,12 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe if (e.getSource().equals(popupItemNew)) { // TODO new lecture wizard with this image preset LOGGER.debug("New lecture clicked"); - new LectureWizard(me, versionTable.getSelectedItem()).setVisible(true); + ImageVersionDetails selected = versionTable.getSelectedItem(); + if (selected == null) + return; + ImageSummaryRead summary = new ImageSummaryRead(); + summary.setImageName(image.getImageName()); // Maybe create a helper class/function some day that transforms all fields + new LectureWizard(me, summary, selected.getVersionId()).setVisible(true); } if (e.getSource().equals(popupItemDownload)) { // TODO delete that image @@ -149,7 +156,8 @@ 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; @@ -162,8 +170,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(); @@ -306,7 +314,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe // Image name: if (!txtTitle.getText().equals(image.getImageName())) { LOGGER.debug("Title changed to: " + txtTitle.getText()); - changed =true; + changed = true; } // Image description: if (!txtDescription.getText().equals(image.getDescription())) { 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 2c3af7ce..c8385cd3 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 @@ -8,7 +8,6 @@ import java.awt.event.MouseEvent; import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import javax.swing.JFileChooser; @@ -22,9 +21,7 @@ import javax.swing.event.DocumentListener; import org.apache.log4j.Logger; import org.apache.thrift.TException; -import org.openslx.bwlp.thrift.iface.ImageDetailsRead; import org.openslx.bwlp.thrift.iface.ImageSummaryRead; -import org.openslx.bwlp.thrift.iface.ImageVersionDetails; import org.openslx.bwlp.thrift.iface.TAuthorizationException; import org.openslx.bwlp.thrift.iface.TNotFoundException; import org.openslx.bwlp.thrift.iface.TransferInformation; @@ -220,23 +217,7 @@ public class ImageListWindow extends ImageListWindowLayout { final ImageSummaryRead image = getSelectedImage(); if (image == null) return; - ImageDetailsRead idr; - try { - idr = ThriftManager.getSatClient().getImageDetails(Session.getSatelliteToken(), - image.getImageBaseId()); - } catch (Exception e) { - LOGGER.debug("Failed to get image details read from image base id: ", e); - return; - } - - Iterator<ImageVersionDetails> it = idr.getVersions().iterator(); - ImageVersionDetails latest = it.next(); - while (it.hasNext()) { - ImageVersionDetails current = it.next(); - if (current.getCreateTime() > latest.getCreateTime()) - latest = current; - } - new LectureWizard(SwingUtilities.getWindowAncestor(this), latest).setVisible(true); + new LectureWizard(SwingUtilities.getWindowAncestor(this), image, image.getLatestVersionId()).setVisible(true); } private void refreshList(final boolean forceRefresh) { diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageWizard.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageWizard.java index 191eecdb..2475b137 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageWizard.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageWizard.java @@ -7,10 +7,8 @@ import org.apache.thrift.TException; import org.openslx.bwlp.thrift.iface.ImageBaseWrite; import org.openslx.bwlp.thrift.iface.ImageVersionWrite; import org.openslx.dozmod.gui.Gui; -import org.openslx.dozmod.gui.MainWindow; import org.openslx.dozmod.gui.helper.MessageType; import org.openslx.dozmod.gui.helper.UiFeedback; -import org.openslx.dozmod.gui.window.ImageListWindow; import org.openslx.dozmod.gui.wizard.page.ImageCustomPermissionPage; import org.openslx.dozmod.gui.wizard.page.ImageMetaDataPage; import org.openslx.dozmod.gui.wizard.page.ImageUploadPage; diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/LectureWizard.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/LectureWizard.java index 6189fa96..061edc98 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/LectureWizard.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/LectureWizard.java @@ -3,10 +3,7 @@ package org.openslx.dozmod.gui.wizard; import java.awt.Window; import org.apache.log4j.Logger; -import org.apache.thrift.TException; -import org.openslx.bwlp.thrift.iface.ImageVersionDetails; -import org.openslx.bwlp.thrift.iface.ImageVersionWrite; -import org.openslx.bwlp.thrift.iface.LecturePermissions; +import org.openslx.bwlp.thrift.iface.ImageSummaryRead; import org.openslx.bwlp.thrift.iface.LectureWrite; import org.openslx.dozmod.gui.Gui; import org.openslx.dozmod.gui.MainWindow; @@ -31,15 +28,15 @@ public class LectureWizard extends Wizard implements UiFeedback { * * @param editExistingLecture whether to create new or edit existing lecture */ - public LectureWizard(Window parent, ImageVersionDetails image) { + public LectureWizard(Window parent, ImageSummaryRead image, String imageVersionId) { super(parent); // sanity check on the image - if (image == null) { - throw new NullPointerException("LectureWizard needs an ImageVersionDetails!"); + if (image == null || imageVersionId == null) { + throw new NullPointerException("LectureWizard needs ImageSummaryRead + imageVersionId!"); } this.state.image = image; - + this.state.imageVersionId = imageVersionId; // create the shared object for all pages of the wizard addPage(new LectureCreationPage(this, state)); @@ -66,6 +63,7 @@ public class LectureWizard extends Wizard implements UiFeedback { public void escapePressed() { doCancel(); } + @Override public boolean wantFinish() { // since we only started the upload and created a "blank" image entry @@ -86,12 +84,14 @@ public class LectureWizard extends Wizard implements UiFeedback { // ok, lets create it try { // push to sat - state.uuid = ThriftManager.getSatClient().createLecture(Session.getSatelliteToken(), lectureWriteFromState()); + state.uuid = ThriftManager.getSatClient().createLecture(Session.getSatelliteToken(), + lectureWriteFromState()); } catch (Exception e) { - Gui.showMessageBox(this, "Fail to create lecture: ", MessageType.ERROR, LOGGER, e); + Gui.showMessageBox(this, "Fail to create lecture: ", MessageType.ERROR, LOGGER, e); return; } - if (Gui.showMessageBox(this, "Veranstaltung erstellt! Wollen Sie zur Übersicht wechseln?", MessageType.QUESTION_YESNO, LOGGER, null)) { + if (Gui.showMessageBox(this, "Veranstaltung erstellt! Wollen Sie zur Übersicht wechseln?", + MessageType.QUESTION_YESNO, LOGGER, null)) { MainWindow.showPage(LectureListWindow.class); } } @@ -116,20 +116,10 @@ public class LectureWizard extends Wizard implements UiFeedback { } return true; } - + private LectureWrite lectureWriteFromState() { - return new LectureWrite( - state.name, - state.description, - state.image.getVersionId(), - state.autoUpdate, - state.isEnabled, - state.start.getTime() / 1000L, - state.end.getTime() / 1000L, - null, - null, - state.isExam, - state.internetAccess, - state.defaultPermissions); + return new LectureWrite(state.name, state.description, state.imageVersionId, state.autoUpdate, + state.isEnabled, state.start.getTime() / 1000L, state.end.getTime() / 1000L, null, null, + state.isExam, state.internetAccess, state.defaultPermissions); } } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/Wizard.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/Wizard.java index bcacdde3..d2c5019c 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/Wizard.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/Wizard.java @@ -28,7 +28,7 @@ import org.openslx.dozmod.gui.MainWindow; import org.openslx.dozmod.gui.helper.GridPos; @SuppressWarnings("serial") -public class Wizard extends JDialog { +public abstract class Wizard extends JDialog { private final JLabel titleLabel; private final JLabel messageLabel; @@ -168,10 +168,7 @@ public class Wizard extends JDialog { setTitle(getWindowTitle() + " - " + pageTitle); } - public String getWindowTitle() { - // TODO Auto-generated method stub - return null; - } + public abstract String getWindowTitle(); protected final void addPage(WizardPage page) { contentPanel.add(page); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/LectureCreationPageLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/LectureCreationPageLayout.java index 4f917352..b7684a1f 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/LectureCreationPageLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/LectureCreationPageLayout.java @@ -57,8 +57,8 @@ public abstract class LectureCreationPageLayout extends WizardPage { * @param editExistingLecture whether to edit existing lecture or create new * one */ - public LectureCreationPageLayout(Wizard wizard) { - super(wizard, "Eingabe Ihrer Daten"); + public LectureCreationPageLayout(Wizard wizard, String title) { + super(wizard, title); setDescription("Geben Sie bitte einen aussagekräftigen Namen für die neue Veranstaltung ein"); setLayout(new GridBagLayout()); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCreationPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCreationPage.java index 0e1e7465..2bd9c98f 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCreationPage.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCreationPage.java @@ -32,25 +32,27 @@ public class LectureCreationPage extends LectureCreationPageLayout { * one */ public LectureCreationPage(Wizard wizard, LectureWizardState state) { - super(wizard); + super(wizard, state.image.imageName); this.state = state; - + // listener for the text fields final DocumentListener docListener = new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { changedUpdate(e); } + @Override public void insertUpdate(DocumentEvent e) { changedUpdate(e); } + @Override public void changedUpdate(DocumentEvent e) { reactToUserInput(); } }; - + lectureNameTextField.getDocument().addDocumentListener(docListener); descriptionText.getDocument().addDocumentListener(docListener); @@ -62,7 +64,7 @@ public class LectureCreationPage extends LectureCreationPageLayout { } }; // listeners for the time pickers - final ChangeListener changeListener = new ChangeListener() { + final ChangeListener changeListener = new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { reactToUserInput(); @@ -75,23 +77,33 @@ public class LectureCreationPage extends LectureCreationPageLayout { editPermissionsCheck.addActionListener(actionListener); adminPermissionsCheck.addActionListener(actionListener); } + + @Override + protected boolean wantNextOrFinish() { + return reactToUserInput(); + } + /** * Called by event listeners. This will set guidance message or error * message and call setPageComplete(bool) accordingly. * The state will be updated if the fields are valid. */ - private void reactToUserInput() { + private boolean reactToUserInput() { + boolean b = isPageValid(); + setPageComplete(b); + return b; + } + + private boolean isPageValid() { if (lectureNameTextField.getText().isEmpty()) { setWarningMessage("Geben Sie einen Veranstaltungsnamen ein."); - setPageComplete(false); - return; - } else { + return false; + } else { state.name = lectureNameTextField.getText(); } if (descriptionText.getText().isEmpty()) { setWarningMessage("Fügen Sie eine Beschreibung hinzu."); - setPageComplete(false); - return; + return false; } else { state.description = descriptionText.getText(); } @@ -103,12 +115,10 @@ public class LectureCreationPage extends LectureCreationPageLayout { LOGGER.debug(end); if (start.after(end)) { setWarningMessage("Startzeit is nach Endzeit!"); - setPageComplete(false); - return; - } else if (now.after(end)) { + return false; + } else if (now.after(end)) { setWarningMessage("Endzeit liegt in die Vergangenheit!"); - setPageComplete(false); - return; + return false; } else { // all good, save them both state.start = start; state.end = end; @@ -118,13 +128,15 @@ public class LectureCreationPage extends LectureCreationPageLayout { state.isEnabled = enabledCheck.isSelected(); state.isExam = examCheck.isSelected(); state.internetAccess = networkAccessCheck.isSelected(); - state.defaultPermissions = new LecturePermissions(editPermissionsCheck.isSelected(), adminPermissionsCheck.isSelected()); - setWarningMessage("Clicken Sie auf 'Weiter' für Berechtigungen oder 'Fertigstellen'."); - setPageComplete(true); + state.defaultPermissions = new LecturePermissions(editPermissionsCheck.isSelected(), + adminPermissionsCheck.isSelected()); + setDescription("Klicken Sie auf 'Weiter' für Berechtigungen oder 'Fertigstellen'"); + return true; } /** * TODO + * * @param datePicker * @param timeSpinner * @return diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/state/LectureWizardState.java b/dozentenmodul/src/main/java/org/openslx/dozmod/state/LectureWizardState.java index c63fb041..f506ce8d 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/state/LectureWizardState.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/state/LectureWizardState.java @@ -3,12 +3,13 @@ package org.openslx.dozmod.state; import java.util.Date; import java.util.Map; -import org.openslx.bwlp.thrift.iface.ImageVersionDetails; +import org.openslx.bwlp.thrift.iface.ImageSummaryRead; import org.openslx.bwlp.thrift.iface.LecturePermissions; public class LectureWizardState { - public ImageVersionDetails image = null; + public ImageSummaryRead image = null; + public String imageVersionId = null; public String name = null; public String description = null; public boolean autoUpdate = false; |