diff options
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtDropDownConfigEditorWindow.java')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtDropDownConfigEditorWindow.java | 224 |
1 files changed, 120 insertions, 104 deletions
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 index 680b9b7c..f30ece91 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtDropDownConfigEditorWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtDropDownConfigEditorWindow.java @@ -1,36 +1,58 @@ package org.openslx.dozmod.gui.window; +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.Insets; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.ByteArrayInputStream; import java.io.IOException; import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; + +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.apache.log4j.Logger; 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.control.WordWrapLabel; +import org.openslx.dozmod.gui.helper.GridManager; import org.openslx.dozmod.gui.helper.I18n; 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.Session; import org.openslx.dozmod.thrift.ImageDetailsActions.VirtConfCallback; import org.openslx.dozmod.thrift.cache.MetaDataCache; -import org.openslx.sat.thrift.version.Feature; import org.openslx.util.ThriftUtil; import org.openslx.util.XmlHelper; -import org.openslx.virtualization.configuration.VirtualizationConfigurationVirtualBox; -import org.openslx.virtualization.Version; import org.openslx.virtualization.configuration.VirtualizationConfiguration; -import org.openslx.virtualization.configuration.VirtualizationConfiguration.DDAcceleration; -import org.openslx.virtualization.configuration.VirtualizationConfiguration.EthernetDevType; -import org.openslx.virtualization.configuration.VirtualizationConfiguration.SoundCardType; -import org.openslx.virtualization.configuration.VirtualizationConfiguration.UsbSpeed; +import org.openslx.virtualization.configuration.VirtualizationConfiguration.ConfigurableOptionGroup; +import org.openslx.virtualization.configuration.VirtualizationConfigurationException; +import org.openslx.virtualization.configuration.VirtualizationConfigurationVirtualBox; +import org.openslx.virtualization.hardware.AbstractConfigurableOption; -public class VirtDropDownConfigEditorWindow extends VirtDropDownConfigEditorWindowLayout +public class VirtDropDownConfigEditorWindow extends JDialog implements UiFeedback { + protected final JScrollPane pnlScrollPane; + protected final JEditorPane pnlEditor; + protected final JButton btnSave; + protected final JButton btnCancel; + protected final JButton btnMore; + protected final List<JComboBox<AbstractConfigurableOption>> cboHardwareOptions; + /** * Version for serialization. */ @@ -45,91 +67,106 @@ public class VirtDropDownConfigEditorWindow extends VirtDropDownConfigEditorWind private final String imageVersionId; private final String originalMachineDescription; private final VirtDropDownConfigEditorWindow me = this; - private VirtualizationConfiguration<?, ?, ?, ?> virtualizationConfig = null; + private final VirtualizationConfiguration virtualizationConfig; private final ImageDetailsActions actionHandler; protected VirtDropDownConfigEditorWindow(Window modalParent, final ImageDetailsActions actionHandler, - final String imageVersionId, final ByteBuffer machineDescription) { - super(modalParent); + final String imageVersionId, final ByteBuffer machineDescription) + throws IOException, VirtualizationConfigurationException { + super(modalParent, I18n.WINDOW_LAYOUT.getString("VirtDropDownConfigEditor.Dialog.title"), + modalParent != null ? ModalityType.APPLICATION_MODAL : ModalityType.MODELESS); + + byte[] machineData = ThriftUtil.unwrapByteBuffer(machineDescription); + virtualizationConfig = VirtualizationConfiguration.getInstance(MetaDataCache.getOperatingSystems(), + machineData, machineData.length); this.actionHandler = actionHandler; this.imageVersionId = imageVersionId; - // and now for the meta data - byte[] machineData = ThriftUtil.unwrapByteBuffer(machineDescription); - try { - virtualizationConfig = VirtualizationConfiguration.getInstance(MetaDataCache.getOperatingSystems(), - machineData, machineData.length); - } catch (IOException e) { - LOGGER.error("Could not get VmMetaData instance from given machine description: ", e); - } - - if (virtualizationConfig == null) { - this.originalMachineDescription = null; - dispose(); - return; - } + // Configurable options, list of groups, each containing all valid options for group + List<ConfigurableOptionGroup> groups = virtualizationConfig.getConfigurableOptions(); + cboHardwareOptions = new ArrayList<JComboBox<AbstractConfigurableOption>>(groups.size()); - initializeSoundBox(virtualizationConfig.getSupportedSoundCards()); - initializeDDABox(virtualizationConfig.getSupportedDDAccs()); - initializeHWVersBox(virtualizationConfig.getVirtualizer().getSupportedVersions()); - initializeEDTBox(virtualizationConfig.getSupportedEthernetDevices()); - initializeUsbBox(virtualizationConfig.getSupportedUsbSpeeds()); + GridManager grid = new GridManager(getContentPane(), 2, true, new Insets(2, 2, 2, 2)); - //set the initial state of the buttons - initializeComboBoxes(virtualizationConfig); + /* + * extra JPanel for the Warning message + */ + JPanel pnlWarning = new JPanel(); + pnlWarning.setBorder(BorderFactory.createTitledBorder( + I18n.WINDOW_LAYOUT.getString("VirtDropDownConfigEditor.TitledBorder.pnlWarning.title"))); + pnlWarning.setLayout(new BorderLayout()); + pnlWarning.add(new WordWrapLabel( + I18n.WINDOW_LAYOUT.getString("VirtDropDownConfigEditor.Label.pnlWarning.text")), + BorderLayout.CENTER); - // listener for the sound card drop box - cboSound.addActionListener(new ActionListener() { + ComboBoxRenderer<AbstractConfigurableOption> renderer = new ComboBoxRenderer<AbstractConfigurableOption>() { @Override - public void actionPerformed(ActionEvent e) { - SoundCardType selected = (SoundCardType) cboSound.getSelectedItem(); - virtualizationConfig.setSoundCard(selected); - btnSave.setEnabled(hasChanged()); + public String renderItem(AbstractConfigurableOption item) { + if (item == null) + return "???"; + return item.getDisplayName(); } - }); + }; - // listener for the 3Dacceleration drop box - cbo3DAcceleration.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - DDAcceleration selected = (DDAcceleration) cbo3DAcceleration.getSelectedItem(); - virtualizationConfig.setDDAcceleration(selected); - btnSave.setEnabled(hasChanged()); - } - }); + pnlEditor = new JEditorPane("text/plain", null); + pnlScrollPane = new JScrollPane(pnlEditor, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); - // listener for the Hardware version drop box - cboHWVersion.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - Version selected = (Version) cboHWVersion.getSelectedItem(); - virtualizationConfig.setVirtualizerVersion(selected); - btnSave.setEnabled(hasChanged()); + grid.add(pnlWarning, 2).fill(true, false).expand(true, false); + grid.nextRow(); + + for (ConfigurableOptionGroup group : groups) { + ComboBox<AbstractConfigurableOption> box = new ComboBox<AbstractConfigurableOption>(renderer, AbstractConfigurableOption.class); + for (AbstractConfigurableOption option : group.availableOptions) { + box.addItem(option); } - }); + box.setSelectedItem(group.getSelected()); + cboHardwareOptions.add(box); + grid.add(new JLabel(I18n.WINDOW_LAYOUT.getString("VirtDropDownConfigEditor.Label." + + group.groupIdentifier.i18n + ".text"))) + .fill(true, false).expand(false, false); + grid.add(box).fill(true, false).expand(true, false); + grid.nextRow(); + } + + grid.add(Box.createVerticalGlue(), 2).expand(true, true); + 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(I18n.WINDOW_LAYOUT.getString("VirtDropDownConfigEditor.Button.more.text")); + buttonPane.add(btnMore); + buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); + btnCancel = new JButton(I18n.WINDOW_LAYOUT.getString("VirtDropDownConfigEditor.Button.cancel.text")); + buttonPane.add(btnCancel); + buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); + btnSave = new JButton(I18n.WINDOW_LAYOUT.getString("VirtDropDownConfigEditor.Button.save.text")); + buttonPane.add(btnSave); + grid.add(buttonPane, 2).fill(true, false).expand(true, false); + grid.finish(false); + + setPreferredSize(Gui.getScaledDimension(600, 400)); + setMinimumSize(Gui.getScaledDimension(450, 375)); + if (modalParent != null) { + Gui.centerShellOverShell(modalParent, this); + } // listener for the Virtual Ethernet device drop box - cboE0VirtDev.addActionListener(new ActionListener() { + ActionListener hwListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - EthernetDevType selected = (EthernetDevType) cboE0VirtDev.getSelectedItem(); - virtualizationConfig.setEthernetDevType(0, selected); + AbstractConfigurableOption selected = (AbstractConfigurableOption) ((JComboBox<AbstractConfigurableOption>) e.getSource()).getSelectedItem(); + selected.apply(); btnSave.setEnabled(hasChanged()); } - }); - - if (Session.hasFeature(Feature.CONFIGURE_USB)) { - cboMaxUsbSpeed.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - UsbSpeed selected = (UsbSpeed) cboMaxUsbSpeed.getSelectedItem(); - virtualizationConfig.setMaxUsbSpeed(selected); - btnSave.setEnabled(hasChanged()); - } - }); + }; + for (JComboBox<AbstractConfigurableOption> box : cboHardwareOptions) { + box.addActionListener(hwListener); } - + // listener for the save button btnSave.addActionListener(new ActionListener() { @Override @@ -172,34 +209,6 @@ public class VirtDropDownConfigEditorWindow extends VirtDropDownConfigEditorWind btnSave.setEnabled(false); } - /* - * setting the boxes to their initial value...value is read from the given virtualization configuration - */ - private void initializeComboBoxes(VirtualizationConfiguration<?, ?, ?, ?> m) { - try { - SoundCardType SCT = m.getSoundCard(); - cboSound.setSelectedItem(SCT); - DDAcceleration DDA = m.getDDAcceleration(); - cbo3DAcceleration.setSelectedItem(DDA); - - // initialize version value in combobox - Version HWV = m.getVirtualizerVersion(); - if (HWV != null) { - // set version value specified in the virtualization configuration as default if specified - cboHWVersion.setSelectedItem(HWV); - } - - EthernetDevType E0VD = m.getEthernetDevType(0); - cboE0VirtDev.setSelectedItem(E0VD); - UsbSpeed usbSpeed = m.getMaxUsbSpeed(); - cboMaxUsbSpeed.setSelectedItem(usbSpeed); - } catch (IllegalArgumentException e) { - // TODO improve user message - Gui.showMessageBox(I18n.WINDOW.getString("VirtDropDownConfigEditor.Message.warning.initializeComboBoxes"), - MessageType.WARNING, null, e); - } - } - private void saveClicked() { // we have a valid vmx or the user accepted to push the filtered input actionHandler.setVirtualizerConfig(imageVersionId, ByteBuffer.wrap(virtualizationConfig.getConfigurationAsByteArray()), @@ -215,13 +224,20 @@ public class VirtDropDownConfigEditorWindow extends VirtDropDownConfigEditorWind public static void open(Window modalParent, final ImageDetailsActions handler, final String imageVersionId, final ByteBuffer machineDescription) { - VirtDropDownConfigEditorWindow win = new VirtDropDownConfigEditorWindow(modalParent, handler, - imageVersionId, machineDescription); + VirtDropDownConfigEditorWindow win; + try { + win = new VirtDropDownConfigEditorWindow(modalParent, handler, + imageVersionId, machineDescription); + } catch (IOException | VirtualizationConfigurationException e) { + Gui.showMessageBox(I18n.WINDOW.getString("VirtDropDownConfigEditor.Message.error.loadMachineConfig"), + MessageType.WARNING, LOGGER, e); + return; + } win.setVisible(true); } private boolean hasChanged() { - return !originalMachineDescription + return originalMachineDescription != null && !originalMachineDescription .equals(ThriftUtil.byteBufferToString(ByteBuffer.wrap(virtualizationConfig.getConfigurationAsByteArray()))); } |