diff options
author | Jonathan Bauer | 2016-09-02 15:04:01 +0200 |
---|---|---|
committer | Jonathan Bauer | 2016-09-02 15:04:01 +0200 |
commit | c4a693230a2e0e2c918d838d9370499f90570fac (patch) | |
tree | f4098f17f14907516bb154c22821879b7c480841 /dozentenmodul/src/main/java/org | |
parent | [client] vm-config editor finished, accessible from the popup menu of image's... (diff) | |
download | tutor-module-c4a693230a2e0e2c918d838d9370499f90570fac.tar.gz tutor-module-c4a693230a2e0e2c918d838d9370499f90570fac.tar.xz tutor-module-c4a693230a2e0e2c918d838d9370499f90570fac.zip |
[client] reworked vmx editor
Diffstat (limited to 'dozentenmodul/src/main/java/org')
9 files changed, 94 insertions, 59 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 47022be9..211b6999 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 @@ -11,8 +11,6 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; -import java.io.BufferedReader; -import java.io.IOException; import java.nio.ByteBuffer; import java.util.Collections; import java.util.Comparator; @@ -49,7 +47,6 @@ import org.openslx.dozmod.gui.helper.PopupMenu; import org.openslx.dozmod.gui.helper.TextChangeListener; import org.openslx.dozmod.gui.helper.UiFeedback; import org.openslx.dozmod.gui.window.UserListWindow.UserAddedCallback; -import org.openslx.dozmod.gui.window.VirtConfigEditorWindow.VirtConfigChanged; import org.openslx.dozmod.gui.window.layout.ImageDetailsWindowLayout; import org.openslx.dozmod.gui.wizard.ImageUpdateWizard; import org.openslx.dozmod.gui.wizard.LectureWizard; @@ -68,9 +65,7 @@ import org.openslx.dozmod.util.MapHelper; import org.openslx.thrifthelper.ThriftManager; import org.openslx.util.QuickTimer; import org.openslx.util.QuickTimer.Task; -import org.openslx.util.ThriftUtil; import org.openslx.util.Util; -import org.openslx.util.vm.VmwareConfig; /** * Window for displaying and editing the details of an image. @@ -394,27 +389,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe Gui.showMessageBox("Konnte VM-Konfiguration nicht abrufen.", MessageType.ERROR, LOGGER, null); return; } - byte[] bytes = ThriftUtil.unwrapByteBuffer(machineDescription); - BufferedReader reader; - StringBuffer content = new StringBuffer(""); - try { - reader = VmwareConfig.getVmxReader(bytes, bytes.length); - String line=""; - while ((line=reader.readLine()) != null) { - content.append(line + "\n"); - } - reader.close(); - } catch (IOException e) { - LOGGER.error("Could not get a reader for byte[] !?"); - } - VirtConfigEditorWindow.open(me, new VirtConfigChanged() { - @Override - public void virtConfigChanged(String newMachineDescription) { - if (newMachineDescription == null || newMachineDescription.isEmpty()) - return; - actionHandler.setVirtualizerConfig(selected.versionId, newMachineDescription); - } - }, content.toString()); + VirtConfigEditorWindow.open(me, actionHandler, selected.versionId, machineDescription); } }); } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtConfigEditorWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtConfigEditorWindow.java index 4a10e776..6bfb6e1f 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtConfigEditorWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtConfigEditorWindow.java @@ -3,6 +3,13 @@ package org.openslx.dozmod.gui.window; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.TreeSet; import org.apache.log4j.Logger; import org.openslx.dozmod.gui.Gui; @@ -10,6 +17,12 @@ import org.openslx.dozmod.gui.helper.MessageType; import org.openslx.dozmod.gui.helper.TextChangeListener; import org.openslx.dozmod.gui.helper.UiFeedback; import org.openslx.dozmod.gui.window.layout.VirtConfigEditorWindowLayout; +import org.openslx.dozmod.thrift.ImageDetailsActions; +import org.openslx.dozmod.thrift.ImageDetailsActions.VirtConfCallback; +import org.openslx.dozmod.thrift.cache.MetaDataCache; +import org.openslx.util.ThriftUtil; +import org.openslx.util.vm.VmwareConfig; +import org.openslx.util.vm.VmwareMetaData; @SuppressWarnings("serial") @@ -20,12 +33,15 @@ public class VirtConfigEditorWindow extends VirtConfigEditorWindowLayout impleme public interface VirtConfigChanged { public void virtConfigChanged(String newVmx); } - private final String originalMachineDescription; + private final String imageVersionId; + private final ByteBuffer originalMachineDescription; private final VirtConfigEditorWindow me = this; - - protected VirtConfigEditorWindow(Window modalParent, final VirtConfigChanged cb, final String machineDescription) { + private final ImageDetailsActions actionHandler; + protected VirtConfigEditorWindow(Window modalParent, final ImageDetailsActions actionHandler, final String imageVersionId, final ByteBuffer machineDescription) { super(modalParent); - originalMachineDescription = machineDescription; + this.originalMachineDescription = machineDescription; + this.actionHandler = actionHandler; + this.imageVersionId = imageVersionId; // listener for the text fields pnlEditor.getDocument().addDocumentListener(new TextChangeListener() { @@ -38,9 +54,7 @@ public class VirtConfigEditorWindow extends VirtConfigEditorWindowLayout impleme btnSave.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - cb.virtConfigChanged(pnlEditor.getText()); - // above command throws exception - dispose(); + saveClicked(); } }); @@ -50,20 +64,66 @@ public class VirtConfigEditorWindow extends VirtConfigEditorWindowLayout impleme safeClose(); } }); + // now build the editor's content from the given buffer + String mdString = ThriftUtil.byteBufferToString(machineDescription); // finally set the editor's content to the vmx - pnlEditor.setText(machineDescription); + pnlEditor.setText(mdString); pnlEditor.setCaretPosition(0); } - public static void open(Window modalParent, final VirtConfigChanged cb, final String machineDescription) { - VirtConfigEditorWindow win = new VirtConfigEditorWindow(modalParent, cb, machineDescription); + private void saveClicked() { + // we make use of the fact that we saved the BB here! + final String userInput = pnlEditor.getText(); + byte[] uiBytes = userInput.getBytes(StandardCharsets.ISO_8859_1); + Charset cs = VmwareConfig.getCharset(uiBytes, uiBytes.length); + // cs is now either the detected encoding, or latin1 as a default + uiBytes = userInput.getBytes(cs); + // now we should have the correct bytes.... + VmwareMetaData meta = new VmwareMetaData(MetaDataCache.getOperatingSystems(), uiBytes, uiBytes.length); + byte[] uiBytesFiltered = meta.getDefinitionArray(); + final String userInputFiltered = new String(uiBytesFiltered, cs); + // So here we have: + // - uiBytes is the unfiltered user input + // - uiBytesFiltered is the user input filtered by VmwareMetaData + TreeSet<String> unfilteredSet = stringToTreeSet(userInput); + TreeSet<String> filteredSet = stringToTreeSet(userInputFiltered); + if (!filteredSet.equals(unfilteredSet)) { + unfilteredSet.removeAll(filteredSet); + // not equals, means there was some invalid input + String errorText = "Invalide Eingaben:" + System.lineSeparator(); + for (String s : unfilteredSet) { + errorText += s + System.lineSeparator(); + } + errorText += System.lineSeparator() + "Wollen Sie trotzdem speichern? (Die invaliden Zeilen werden dabei automatisch gelöscht.)"; + if (!Gui.showMessageBox(errorText, MessageType.ERROR_RETRY, LOGGER, null)) + return; + } + // we have a valid vmx or the user accepted to push the filtered input + actionHandler.setVirtualizerConfig(imageVersionId, ByteBuffer.wrap(uiBytesFiltered), new VirtConfCallback() { + @Override + public void virtConfCallback(boolean success) { + if (success) { + dispose(); + } + } + }); + } + private TreeSet<String> stringToTreeSet(final String s) { + String[] split = s.split(System.lineSeparator()); + List<String> splitList = new ArrayList<String>(Arrays.asList(split)); + splitList.removeAll(Arrays.asList("", null)); + TreeSet<String> set = new TreeSet<String>(splitList); + return set; + } + public static void open(Window modalParent, final ImageDetailsActions handler, final String imageVersionId, final ByteBuffer machineDescription) { + VirtConfigEditorWindow win = new VirtConfigEditorWindow(modalParent, handler, imageVersionId, machineDescription); win.setVisible(true); } private void safeClose() { - if (originalMachineDescription.equals(pnlEditor.getText()) || + if (ThriftUtil.byteBufferToString(originalMachineDescription).equals(pnlEditor.getText()) || Gui.showMessageBox(me, "Ihre Änderungen werden verloren gehen, wollen Sie trotzdem abbrechen?", MessageType.QUESTION_YESNO, - LOGGER, null)) + null, null)) 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 d75c1eed..26d03f21 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 @@ -374,13 +374,13 @@ public abstract class LectureDetailsWindowLayout extends JDialog { pnlTabs = new JTabbedPane(); pnlTabs.addTab("Übersicht", pnlTabInfo); pnlTabs.addTab("Allgemein", pnlTabGeneral); - if (Session.isNetrulesSupported()) { + if (Session.isLectureRestrictionsSupported()) { pnlTabs.addTab("Beschränkungen", pnlTabRestrictions); } if (MetaDataCache.getLocations() != null && !MetaDataCache.getLocations().isEmpty()) { pnlTabs.addTab("Raumauswahl", pnlTabLocations); } - if (Session.isNetrulesSupported()) { + if (Session.isLectureRestrictionsSupported()) { pnlTabs.addTab("Erweitert", pnlTabAdvanced); } pnlTabs.addTab("Berechtigungen", pnlTabPermissions); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadPage.java index 0e868b81..b580ce5e 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadPage.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadPage.java @@ -102,7 +102,6 @@ public class ImageUploadPage extends ImageUploadPageLayout { setPageComplete(false); return; } - LOGGER.info(new String(state.meta.getFilteredDefinition().array(), StandardCharsets.UTF_8)); if (state.meta == null || state.meta.getDisplayName() == null) { setErrorMessage("Ungültige vmx-Datei ausgewählt!"); setPageComplete(false); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureOptionsPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureOptionsPage.java index b81fc97a..a100ab05 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureOptionsPage.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureOptionsPage.java @@ -39,7 +39,7 @@ public class LectureOptionsPage extends LectureOptionsPageLayout { } } }); - if (!Session.isNetrulesSupported()) { + if (!Session.isLectureRestrictionsSupported()) { chkIsExam.setEnabled(false); chkInternetEnabled.setEnabled(false); chkUsbEnabled.setEnabled(false); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageDetailsActions.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageDetailsActions.java index 8d10abab..f3a57c50 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageDetailsActions.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageDetailsActions.java @@ -1,5 +1,6 @@ package org.openslx.dozmod.thrift; +import java.nio.ByteBuffer; import java.util.Map; import org.apache.thrift.TException; @@ -17,8 +18,12 @@ public interface ImageDetailsActions { public void getImageDetails(final String imageBaseId, final ImageMetaCallback callback); public boolean setImageOwner(final String imageBaseId, final UserInfo user); public void updateImageBase(final String imageBaseId, final ImageBaseWrite data) throws TException, TAuthorizationException, TNotFoundException, TInvocationException; - public void setVirtualizerConfig(final String imageVersionId, final String machineDescription); + public void setVirtualizerConfig(final String imageVersionId, final ByteBuffer machineDescription, final VirtConfCallback callback); public void writeImagePermissions(final String imageBaseId, Map<String, ImagePermissions> customPermissions) throws TException, TAuthorizationException, TNotFoundException, TInvocationException; public void deleteImageVersion(final ImageVersionDetails version, final DeleteCallback callback); public boolean isImagePublishSupported(); + + public interface VirtConfCallback { + public void virtConfCallback(boolean success); + } } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageLocalDetailsActions.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageLocalDetailsActions.java index 1070017d..11feba74 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageLocalDetailsActions.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageLocalDetailsActions.java @@ -2,7 +2,6 @@ package org.openslx.dozmod.thrift; import java.awt.Frame; import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; import java.util.Map; import org.apache.log4j.Logger; @@ -16,7 +15,6 @@ import org.openslx.bwlp.thrift.iface.TInvocationException; import org.openslx.bwlp.thrift.iface.TNotFoundException; import org.openslx.bwlp.thrift.iface.UserInfo; import org.openslx.dozmod.gui.Gui; -import org.openslx.dozmod.gui.helper.MessageType; import org.openslx.dozmod.thrift.ThriftActions.DeleteCallback; import org.openslx.dozmod.thrift.ThriftActions.ImageMetaCallback; import org.openslx.thrifthelper.ThriftManager; @@ -98,26 +96,23 @@ public class ImageLocalDetailsActions implements ImageDetailsActions { } @Override - public void setVirtualizerConfig(final String imageVersionId, final String machineDescription) { - final ByteBuffer bufferToSave; - bufferToSave = ByteBuffer.wrap(machineDescription.getBytes(StandardCharsets.ISO_8859_1)); + public void setVirtualizerConfig(final String imageVersionId, final ByteBuffer machineDescription, final VirtConfCallback callback) { QuickTimer.scheduleOnce(new Task() { - ByteBuffer bufferSaved = null; + boolean success = false; @Override public void fire() { try { - bufferSaved = ThriftManager.getSatClient().setImageVersionVirtConfig(Session.getSatelliteToken(), imageVersionId, bufferToSave); + ThriftManager.getSatClient().setImageVersionVirtConfig(Session.getSatelliteToken(), imageVersionId, machineDescription); + success = true; } catch (TException e) { ThriftError.showMessage(parent, LOGGER, e, "Fehler beim Speichern der VM-Konfiguration!"); } Gui.asyncExec(new Runnable() { @Override public void run() { - // check the returned bytebuffer to check if the transfer worked as intended - if (!bufferSaved.equals(bufferToSave)) // tested this, seems to works good enough... - Gui.showMessageBox("Unvorhergesehener Fehler! Bitte wenden Sie sich an dem Support.", - MessageType.ERROR , LOGGER, null); - // else we're good. + if (success && callback != null) { + callback.virtConfCallback(success); + } } }); } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImagePublishedDetailsActions.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImagePublishedDetailsActions.java index 99ebf107..28ed3391 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImagePublishedDetailsActions.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImagePublishedDetailsActions.java @@ -1,6 +1,7 @@ package org.openslx.dozmod.thrift; import java.awt.Frame; +import java.nio.ByteBuffer; import java.util.Map; import org.openslx.bwlp.thrift.iface.ImageBaseWrite; @@ -69,7 +70,7 @@ public class ImagePublishedDetailsActions implements ImageDetailsActions { @Override public void setVirtualizerConfig(String imageVersionId, - String machineDescription) { + ByteBuffer machineDescription, VirtConfCallback cb) { return; } } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Session.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Session.java index 6eb91fe7..6fa5c3bc 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Session.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Session.java @@ -143,10 +143,10 @@ public class Session { } /** - * @return true if the satellite's API version supports netrules, internet - * blocking, exam mode (version 4 and above), false otherwise + * @return true if the satellite's API version supports usb, netrules, internet + * blocking, exam mode restrictions (version 4 and above), false otherwise */ - public static boolean isNetrulesSupported() { + public static boolean isLectureRestrictionsSupported() { return satelliteApiVersion >= 4; } |