From 5ff8f2ad3276b66f70077c8f4ee042bd4c77c670 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Thu, 25 Aug 2016 14:51:11 +0200 Subject: [client] started rudimentary VMX editor --- .../dozmod/gui/window/ImageDetailsWindow.java | 39 +++++++++++++ .../openslx/dozmod/gui/window/VmxEditorWindow.java | 67 ++++++++++++++++++++++ .../window/layout/ImageDetailsWindowLayout.java | 5 +- .../gui/window/layout/VmxEditorWindowLayout.java | 51 ++++++++++++++++ .../org/openslx/dozmod/thrift/ThriftActions.java | 19 +++++- 5 files changed, 178 insertions(+), 3 deletions(-) create mode 100644 dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VmxEditorWindow.java create mode 100644 dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VmxEditorWindowLayout.java (limited to 'dozentenmodul/src/main/java/org') 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 32adaf24..e2d55f29 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 @@ -32,6 +32,7 @@ import org.apache.thrift.TException; import org.openslx.bwlp.thrift.iface.ImageBaseWrite; import org.openslx.bwlp.thrift.iface.ImageDetailsRead; import org.openslx.bwlp.thrift.iface.ImagePermissions; +import org.openslx.bwlp.thrift.iface.ImagePublishData; import org.openslx.bwlp.thrift.iface.ImageSummaryRead; import org.openslx.bwlp.thrift.iface.ImageVersionDetails; import org.openslx.bwlp.thrift.iface.LectureSummary; @@ -46,6 +47,7 @@ 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.VmxEditorWindow.VmxChangedCallback; import org.openslx.dozmod.gui.window.layout.ImageDetailsWindowLayout; import org.openslx.dozmod.gui.wizard.ImageUpdateWizard; import org.openslx.dozmod.gui.wizard.LectureWizard; @@ -185,6 +187,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe if (safeClose()) { LectureListWindow page = MainWindow.showPage(LectureListWindow.class); page.filterByImageBaseId(image.imageBaseId); + } } }); @@ -205,6 +208,42 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe }, "Besitzer festlegen", image.ownerId); } }); + btnEditVmx.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + QuickTimer.scheduleOnce(new Task() { + ImagePublishData data = null; + @Override + public void fire() { + data = ThriftActions.getImageData(image.imageBaseId); + Gui.asyncExec(new Runnable() { + @Override + public void run() { + if (data == null) { + // TODO warn user about failure + return; + } + // open basic vmx editor + byte[] bytes; + if(data.machineDescription.hasArray()) { + bytes = data.machineDescription.array(); + } else { + bytes = new byte[data.machineDescription.remaining()]; + data.machineDescription.get(bytes); + } + String dataString = new String(bytes, java.nio.charset.StandardCharsets.UTF_8); + VmxEditorWindow.open(me, new VmxChangedCallback() { + @Override + public void vmxChanged(String newVmx) { + // TODO save it + } + }, dataString); + } + }); + } + }); + } + }); btnPermissions.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VmxEditorWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VmxEditorWindow.java new file mode 100644 index 00000000..a1502356 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VmxEditorWindow.java @@ -0,0 +1,67 @@ +package org.openslx.dozmod.gui.window; + +import java.awt.Window; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import org.apache.log4j.Logger; +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.VmxEditorWindowLayout; + + +@SuppressWarnings("serial") +public class VmxEditorWindow extends VmxEditorWindowLayout implements UiFeedback { + + private final static Logger LOGGER = Logger.getLogger(VmxEditorWindow.class); + + public interface VmxChangedCallback { + public void vmxChanged(String newVmx); + } + private final String originalVmx; + private final VmxEditorWindow me = this; + + protected VmxEditorWindow(Window modalParent, final VmxChangedCallback cb, String vmx) { + super(modalParent, vmx); + originalVmx = vmx; + btnSave.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + // TODO callback to the main window to save the contents + cb.vmxChanged(pnlEditor.getText()); + } + }); + + btnCancel.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String newData = pnlEditor.getText(); + if (newData == null) { + LOGGER.debug("Error while getting the text from the editor..."); + return; + } + if (originalVmx != pnlEditor.getText()) { + if (Gui.showMessageBox(me, "Ihre Änderungen werden verloren gehen, wollen Sie trotzdem fortfahren?", MessageType.QUESTION_YESNO, + LOGGER, null)) + dispose(); + } + } + }); + } + + public static void open(Window modalParent, final VmxChangedCallback cb, String vmx) { + VmxEditorWindow win = new VmxEditorWindow(modalParent, cb, vmx); + win.setVisible(true); + } + + @Override + public boolean wantConfirmQuit() { + return false; + } + + @Override + public void escapePressed() { + dispose(); + } +} \ No newline at end of file diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java index 03dc3566..311f8f47 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java @@ -64,6 +64,7 @@ public abstract class ImageDetailsWindowLayout extends JDialog { protected final JButton btnUploadToMaster; protected final JButton btnClose; + protected final JButton btnEditVmx; protected final JButton btnShowLinkingLectures; protected final QLabel lblLinkedLectureCount; @@ -178,8 +179,10 @@ public abstract class ImageDetailsWindowLayout extends JDialog { // virtualizer lblVirtualizer = new QLabel(); + btnEditVmx = new JButton("VMX Editieren"); grid.add(new QLabel("Virtualisierer")); - grid.add(lblVirtualizer, 2); + grid.add(lblVirtualizer, 2).expand(true, false).fill(true, false); + //grid.add(btnEditVmx); grid.nextRow(); btnPermissions = new JButton("Berechtigungen"); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VmxEditorWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VmxEditorWindowLayout.java new file mode 100644 index 00000000..4b502d16 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VmxEditorWindowLayout.java @@ -0,0 +1,51 @@ +package org.openslx.dozmod.gui.window.layout; + +import java.awt.Dimension; +import java.awt.Window; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JEditorPane; +import javax.swing.JPanel; + +import org.openslx.dozmod.gui.Gui; +import org.openslx.dozmod.gui.helper.GridManager; + +@SuppressWarnings("serial") +public class VmxEditorWindowLayout extends JDialog { + + private static String title = "VMX Editor (nur für erfahrene Anwender!)"; + protected final JEditorPane pnlEditor; + protected final JButton btnSave; + protected final JButton btnCancel; + + protected VmxEditorWindowLayout(Window modalParent, String vmx) { + super(modalParent, title, modalParent != null ? ModalityType.APPLICATION_MODAL + : ModalityType.MODELESS); + + GridManager grid = new GridManager(this, 1); + + pnlEditor = new JEditorPane("text/plain", vmx); + grid.add(pnlEditor).expand(true, true).fill(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()); + btnCancel = new JButton("Abbrechen"); + buttonPane.add(btnCancel); + buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); + btnSave = new JButton("Übernehmen"); + buttonPane.add(btnSave); + grid.add(buttonPane).fill(true, false).expand(true, false);; + grid.finish(false); + + setPreferredSize(Gui.getScaledDimension(500, 400)); + setMinimumSize(Gui.getScaledDimension(350, 300)); + Gui.centerShellOverShell(modalParent, this); + } +} diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java index 78d2e416..fc5af070 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java @@ -19,6 +19,7 @@ import org.apache.thrift.transport.TTransportException; import org.openslx.bwlp.thrift.iface.ImageBaseWrite; import org.openslx.bwlp.thrift.iface.ImageDetailsRead; import org.openslx.bwlp.thrift.iface.ImagePermissions; +import org.openslx.bwlp.thrift.iface.ImagePublishData; import org.openslx.bwlp.thrift.iface.ImageVersionDetails; import org.openslx.bwlp.thrift.iface.ImageVersionWrite; import org.openslx.bwlp.thrift.iface.LecturePermissions; @@ -595,7 +596,21 @@ public class ThriftActions { } }); } - + /** + * BLOCKING Gets the data for image with UUID imageBaseId + * + * @param imageBaseId + * @return ImagePublishData image's data if sucessful, null otherwise. + */ + public static ImagePublishData getImageData(final String imageBaseId) { + ImagePublishData data = null; + try { + data = ThriftManager.getMasterClient().getImageData(Session.getSatelliteToken(), imageBaseId); + } catch (TException e) { + LOGGER.error("Could not query sat for ImagePublishData for '" + imageBaseId + "':", e); + } + return data; + } /** * NON-BLOCKING Gets the user-specific permission list for the given * imageBaseId @@ -1058,7 +1073,7 @@ public class ThriftActions { try { data = ThriftManager.getMasterClient().getImageDetails(Session.getMasterToken(), imageBaseId); } catch (TException e) { - LOGGER.error("Could not query masterserver for ImagePublishData for version '" + imageBaseId + "':", e); + LOGGER.error("Could not query masterserver for ImageDetailsRead for version '" + imageBaseId + "':", e); } return data; } -- cgit v1.2.3-55-g7522