diff options
author | Victor Mocanu | 2016-10-31 12:32:12 +0100 |
---|---|---|
committer | Victor Mocanu | 2016-10-31 12:32:12 +0100 |
commit | 9c257071f181cce99d1fbbd1884fe2a676d3baec (patch) | |
tree | 1b27783c21cd6021089a01317d91d90e6e060010 /dozentenmodul/src/main/java/org/openslx/dozmod | |
parent | [client] improved shift handling for custom sat on login (diff) | |
download | tutor-module-9c257071f181cce99d1fbbd1884fe2a676d3baec.tar.gz tutor-module-9c257071f181cce99d1fbbd1884fe2a676d3baec.tar.xz tutor-module-9c257071f181cce99d1fbbd1884fe2a676d3baec.zip |
[client] added simple vmx editor
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod')
5 files changed, 386 insertions, 34 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 ce04e35e..974cc997 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 @@ -390,7 +390,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe Gui.showMessageBox("Konnte VM-Konfiguration nicht abrufen.", MessageType.ERROR, LOGGER, null); return; } - VirtConfigEditorWindow.open(me, actionHandler, selected.versionId, machineDescription); + VirtDropDownConfigEditorWindow.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 a409bb2a..67febdd9 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 @@ -24,22 +24,25 @@ import org.openslx.util.ThriftUtil; import org.openslx.util.vm.VmwareConfig; import org.openslx.util.vm.VmwareMetaData; - @SuppressWarnings("serial") public class VirtConfigEditorWindow extends VirtConfigEditorWindowLayout implements UiFeedback { - + private final static Logger LOGGER = Logger.getLogger(VirtConfigEditorWindow.class); - + public interface VirtConfigChanged { public void virtConfigChanged(String newVmx); } + private final String imageVersionId; - private final ByteBuffer originalMachineDescription; + private final String originalMachineDescription; private final VirtConfigEditorWindow me = this; private final ImageDetailsActions actionHandler; - protected VirtConfigEditorWindow(Window modalParent, final ImageDetailsActions actionHandler, final String imageVersionId, final ByteBuffer machineDescription) { + + protected VirtConfigEditorWindow(Window modalParent, final ImageDetailsActions actionHandler, + final String imageVersionId, final ByteBuffer currentMachineDescription, + final String originalmachineDescription) { super(modalParent); - this.originalMachineDescription = machineDescription; + this.actionHandler = actionHandler; this.imageVersionId = imageVersionId; @@ -47,10 +50,10 @@ public class VirtConfigEditorWindow extends VirtConfigEditorWindowLayout impleme pnlEditor.getDocument().addDocumentListener(new TextChangeListener() { @Override public void changed() { - btnSave.setEnabled(!originalMachineDescription.equals(pnlEditor.getText()));; + btnSave.setEnabled(!originalMachineDescription.equals(pnlEditor.getText())); } }); - + btnSave.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -64,10 +67,11 @@ 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(mdString); + // save original description for later use + this.originalMachineDescription = originalmachineDescription; + // finally set the editor's content to the new given description + String cmdString = ThriftUtil.byteBufferToString(currentMachineDescription); + pnlEditor.setText(cmdString); pnlEditor.setCaretPosition(0); } @@ -79,7 +83,8 @@ public class VirtConfigEditorWindow extends VirtConfigEditorWindowLayout impleme // 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); + VmwareMetaData meta = new VmwareMetaData(MetaDataCache.getOperatingSystems(), uiBytes, + uiBytes.length); byte[] uiBytesFiltered = meta.getDefinitionArray(); final String userInputFiltered = new String(uiBytesFiltered, cs); // So here we have: @@ -94,20 +99,24 @@ public class VirtConfigEditorWindow extends VirtConfigEditorWindowLayout impleme for (String s : unfilteredSet) { errorText += s + "\n"; } - errorText += System.lineSeparator() + "Wollen Sie trotzdem speichern? (Die invaliden Zeilen werden dabei automatisch gelöscht.)"; + 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(); - } - } - }); + 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("[\\r\\n]+"); List<String> splitList = new ArrayList<String>(Arrays.asList(split)); @@ -115,15 +124,19 @@ public class VirtConfigEditorWindow extends VirtConfigEditorWindowLayout impleme 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); + + public static void open(Window modalParent, final ImageDetailsActions handler, + final String imageVersionId, final ByteBuffer currentmachineDescription, + final String originalMachineDescription) { + VirtConfigEditorWindow win = new VirtConfigEditorWindow(modalParent, handler, imageVersionId, + currentmachineDescription, originalMachineDescription); win.setVisible(true); } private void safeClose() { - if (ThriftUtil.byteBufferToString(originalMachineDescription).equals(pnlEditor.getText()) || - Gui.showMessageBox(me, "Ihre Änderungen werden verloren gehen, wollen Sie trotzdem abbrechen?", MessageType.QUESTION_YESNO, - null, null)) + if (originalMachineDescription.equals(pnlEditor.getText()) || Gui.showMessageBox(me, + "Ihre Änderungen, in diesem Fenster, werden verloren gehen, wollen Sie trotzdem abbrechen?", + MessageType.QUESTION_YESNO, null, null)) dispose(); } @@ -136,5 +149,4 @@ public class VirtConfigEditorWindow extends VirtConfigEditorWindowLayout impleme public void escapePressed() { safeClose(); } - -}
\ No newline at end of file +} diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtDropDownConfigEditorWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtDropDownConfigEditorWindow.java new file mode 100644 index 00000000..0bc0e020 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtDropDownConfigEditorWindow.java @@ -0,0 +1,187 @@ +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 org.openslx.dozmod.gui.Gui; +import org.openslx.dozmod.gui.helper.MessageType; +import org.openslx.dozmod.gui.helper.UiFeedback; +import org.openslx.dozmod.gui.window.layout.VirtDropDownConfigEditorWindowLayout; +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.VmwareMetaData; +import org.openslx.util.vm.VmwareMetaData.DDAcceleration; +import org.openslx.util.vm.VmwareMetaData.E0VirtDev; +import org.openslx.util.vm.VmwareMetaData.HWVersion; +import org.openslx.util.vm.VmwareMetaData.SoundCardType; + +@SuppressWarnings("serial") +public class VirtDropDownConfigEditorWindow extends VirtDropDownConfigEditorWindowLayout + implements UiFeedback { + + public interface VirtConfigChanged { + public void virtConfigChanged(String newVmx); + } + + private final String imageVersionId; + private final String originalMachineDescription; + private final VirtDropDownConfigEditorWindow me = this; + private final VmwareMetaData meta; + private final ImageDetailsActions actionHandler; + + protected VirtDropDownConfigEditorWindow(Window modalParent, final ImageDetailsActions actionHandler, + final String imageVersionId, final ByteBuffer machineDescription) { + super(modalParent); + + this.actionHandler = actionHandler; + this.imageVersionId = imageVersionId; + + // and now for the meta data + meta = new VmwareMetaData(MetaDataCache.getOperatingSystems(), machineDescription.array(), + machineDescription.array().length); + + //set the initial state of the buttons + setTheBoxes(meta); + + // listener for the sound card drop box + cboSound.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + SoundCardType selected = (SoundCardType) cboSound.getSelectedItem(); + meta.setSoundCard(selected); + checkForChange(); + } + }); + + // listener for the 3Dacceleration drop box + cbo3DAcceleration.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + DDAcceleration selected = (DDAcceleration) cbo3DAcceleration.getSelectedItem(); + meta.setDDAcceleration(selected); + checkForChange(); + } + }); + + // listener for the Hardware version drop box + cboHWVersion.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + HWVersion selected = (HWVersion) cboHWVersion.getSelectedItem(); + meta.setHWVersion(selected); + checkForChange(); + } + }); + + // listener for the Virtual Ethernet device drop box + cboE0VirtDev.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + E0VirtDev selected = (E0VirtDev) cboE0VirtDev.getSelectedItem(); + meta.setE0VirtDev(selected); + checkForChange(); + } + }); + + // listener for the save button + btnSave.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + saveClicked(); + } + }); + + // listener for the cancel button + btnCancel.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + safeClose(); + } + }); + + //listener for the profi button + btnMore.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (Gui.showMessageBox(me, + "Bitte beachten Sie: dieser Modus ist für erfahrene Nutzer geeignet. \n Möchten Sie wirklich diesen Modus fortsetzen?", + MessageType.QUESTION_YESNO, null, null)) + me.dispose(); + VirtConfigEditorWindow.open(me, actionHandler, imageVersionId, + ByteBuffer.wrap(meta.getDefinitionArray()), originalMachineDescription); + + } + }); + + this.originalMachineDescription = ThriftUtil.byteBufferToString(machineDescription); + btnSave.setEnabled(false); + } + + protected void checkForChange() { + if (!originalMachineDescription + .equals(ThriftUtil.byteBufferToString(ByteBuffer.wrap(meta.getDefinitionArray())))) { + btnSave.setEnabled(true); + } else { + btnSave.setEnabled(false); + } + + } + + /* setting the boxes to their initial value...value is read from the given metaData + * @param: given VmwareMetaData + */ + private void setTheBoxes(VmwareMetaData m) { + SoundCardType SCT = m.getSoundCard(); + cboSound.setSelectedItem(SCT); + DDAcceleration DDA = m.getDDAcceleration(); + cbo3DAcceleration.setSelectedItem(DDA); + HWVersion HWV = m.getHWVersion(); + cboHWVersion.setSelectedItem(HWV); + E0VirtDev E0VD = m.getE0VirtDev(); + cboE0VirtDev.setSelectedItem(E0VD); + } + + private void saveClicked() { + // we have a valid vmx or the user accepted to push the filtered input + actionHandler.setVirtualizerConfig(imageVersionId, ByteBuffer.wrap(meta.getDefinitionArray()), + new VirtConfCallback() { + @Override + public void virtConfCallback(boolean success) { + if (success) { + dispose(); + } + } + }); + } + + public static void open(Window modalParent, final ImageDetailsActions handler, + final String imageVersionId, final ByteBuffer machineDescription) { + VirtDropDownConfigEditorWindow win = new VirtDropDownConfigEditorWindow(modalParent, handler, + imageVersionId, machineDescription); + win.setVisible(true); + } + + private void safeClose() { + if (originalMachineDescription + .equals(ThriftUtil.byteBufferToString(ByteBuffer.wrap(meta.getDefinitionArray()))) + || Gui.showMessageBox(me, + "Wollen Sie wirklich abbrechen?\n" + "Ihre Änderungen werden verworfen.", + MessageType.QUESTION_YESNO, null, null)) + dispose(); + } + + @Override + public boolean wantConfirmQuit() { + return !originalMachineDescription + .equals(ThriftUtil.byteBufferToString(ByteBuffer.wrap(meta.getDefinitionArray()))); + } + + @Override + public void escapePressed() { + safeClose(); + } +}
\ No newline at end of file diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtConfigEditorWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtConfigEditorWindowLayout.java index 7611f870..af06b5fe 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtConfigEditorWindowLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtConfigEditorWindowLayout.java @@ -27,13 +27,14 @@ public class VirtConfigEditorWindowLayout extends JDialog { protected final JButton btnCancel; protected VirtConfigEditorWindowLayout(Window modalParent) { - super(modalParent, title, modalParent != null ? ModalityType.APPLICATION_MODAL - : ModalityType.MODELESS); + super(modalParent, title, + modalParent != null ? ModalityType.APPLICATION_MODAL : ModalityType.MODELESS); GridManager grid = new GridManager(this, 1, true, new Insets(2, 2, 2, 2)); JPanel pnlWarning = new JPanel(); pnlWarning.setBorder(BorderFactory.createTitledBorder("WARNUNG")); - pnlWarning.add(new JLabel("<html>Änderungen an der VM-Konfiguration können zu Funktionsstörungen führen.<br>Benutzung auf eigene Gefahr!</html>")); + pnlWarning.add(new JLabel( + "<html>Änderungen an der VM-Konfiguration können zu Funktionsstörungen führen.<br>Benutzung auf eigene Gefahr!</html>")); pnlEditor = new JEditorPane("text/plain", null); pnlScrollPane = new JScrollPane(pnlEditor, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); @@ -51,7 +52,8 @@ public class VirtConfigEditorWindowLayout extends JDialog { buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); btnSave = new JButton("Speichern"); buttonPane.add(btnSave); - grid.add(buttonPane).fill(true, false).expand(true, false);; + grid.add(buttonPane).fill(true, false).expand(true, false); + ; grid.finish(false); setPreferredSize(Gui.getScaledDimension(650, 750)); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtDropDownConfigEditorWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtDropDownConfigEditorWindowLayout.java new file mode 100644 index 00000000..621d6b56 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtDropDownConfigEditorWindowLayout.java @@ -0,0 +1,151 @@ +package org.openslx.dozmod.gui.window.layout; + +import java.awt.Dimension; +import java.awt.Insets; +import java.awt.Window; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JDialog; +import javax.swing.JEditorPane; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; + +import org.openslx.dozmod.gui.Gui; +import org.openslx.dozmod.gui.control.ComboBox; +import org.openslx.dozmod.gui.control.ComboBox.ComboBoxRenderer; +import org.openslx.dozmod.gui.helper.GridManager; +import org.openslx.util.vm.VmwareMetaData.DDAcceleration; +import org.openslx.util.vm.VmwareMetaData.E0VirtDev; +import org.openslx.util.vm.VmwareMetaData.HWVersion; +import org.openslx.util.vm.VmwareMetaData.SoundCardType; + +@SuppressWarnings("serial") +public class VirtDropDownConfigEditorWindowLayout extends JDialog { + + private static String title = "VM-Konfiguration Editor"; + protected final JScrollPane pnlScrollPane; + protected final JEditorPane pnlEditor; + protected final JButton btnSave; + protected final JButton btnCancel; + protected final JButton btnMore; + protected final JComboBox<SoundCardType> cboSound; + protected final JComboBox<DDAcceleration> cbo3DAcceleration; + protected final JComboBox<HWVersion> cboHWVersion; + protected final JComboBox<E0VirtDev> cboE0VirtDev; + + protected VirtDropDownConfigEditorWindowLayout(Window modalParent) { + super(modalParent, title, + modalParent != null ? ModalityType.APPLICATION_MODAL : ModalityType.MODELESS); + + GridManager grid = new GridManager(this, 3, true, new Insets(2, 2, 2, 2)); + + /* + * extra JPanel for the Warning message + */ + JPanel pnlWarning = new JPanel(); + pnlWarning.setBorder(BorderFactory.createTitledBorder("WARNUNG")); + pnlWarning.add( + new JLabel("<html>Änderungen an der VM-Konfiguration können zu Funktionsstörungen führen." + + "<br>Benutzung auf eigene Gefahr!" + + "<br>Erweiterungen clicken um die alte interface zu benutzen</html>")); + + /* + * ComboBoxes - one for each device + */ + + // SoundBox + cboSound = new ComboBox<>(new ComboBoxRenderer<SoundCardType>() { + @Override + public String renderItem(SoundCardType item) { + return item.displayName; + } + }); + + for (SoundCardType i : SoundCardType.values()) { + cboSound.addItem(i); + } + + // 3D accelerationBox + cbo3DAcceleration = new ComboBox<>(new ComboBoxRenderer<DDAcceleration>() { + @Override + public String renderItem(DDAcceleration item) { + return item.displayName; + } + }); + + for (DDAcceleration i : DDAcceleration.values()) { + cbo3DAcceleration.addItem(i); + } + + // HardwareVersioBox + cboHWVersion = new ComboBox<>(new ComboBoxRenderer<HWVersion>() { + @Override + public String renderItem(HWVersion item) { + return item.displayName; + } + }); + + for (HWVersion i : HWVersion.values()) { + cboHWVersion.addItem(i); + } + + // HardwareVersioBox + cboE0VirtDev = new ComboBox<>(new ComboBoxRenderer<E0VirtDev>() { + @Override + public String renderItem(E0VirtDev item) { + return item.displayName; + } + }); + + for (E0VirtDev i : E0VirtDev.values()) { + cboE0VirtDev.addItem(i); + } + + pnlEditor = new JEditorPane("text/plain", null); + pnlScrollPane = new JScrollPane(pnlEditor, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + + grid.add(pnlWarning, 3).fill(true, false).expand(true, false); + grid.nextRow(); + grid.add(new JLabel("Soundkarte")).fill(true, false).expand(false, false); + grid.add(new JLabel(" ")).fill(false, false).expand(false, false); + grid.add(cboSound).fill(true, false).expand(false, false); + grid.nextRow(); + grid.add(new JLabel("3D-Beschleunigung")).fill(true, false).expand(false, false); + grid.add(new JLabel(" ")).fill(false, false).expand(false, false); + grid.add(cbo3DAcceleration).fill(true, false).expand(true, false); + grid.nextRow(); + grid.add(new JLabel("Hardware Version Nummer")).fill(true, false).expand(false, false); + grid.add(new JLabel(" ")).fill(false, false).expand(false, false); + grid.add(cboHWVersion).fill(true, false).expand(true, false); + grid.nextRow(); + grid.add(new JLabel("Virtuelle Netzwerkkarte")).fill(true, false).expand(false, false); + grid.add(new JLabel(" ")).fill(false, false).expand(false, false); + grid.add(cboE0VirtDev).fill(true, false).expand(true, false); + grid.nextRow(); + + JPanel buttonPane = new JPanel(); + buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); + buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); + buttonPane.add(Box.createHorizontalGlue()); + btnMore = new JButton("Erweiterungen"); + buttonPane.add(btnMore); + buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); + btnCancel = new JButton("Abbrechen"); + buttonPane.add(btnCancel); + buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); + btnSave = new JButton("Speichern"); + buttonPane.add(btnSave); + grid.add(buttonPane, 3).fill(true, false).expand(true, false); + grid.finish(false); + + setPreferredSize(Gui.getScaledDimension(850, 250)); + setMinimumSize(Gui.getScaledDimension(550, 300)); + Gui.centerShellOverShell(modalParent, this); + } +} |