From d85ee0495619121d263d722fb5546237696f0e3c Mon Sep 17 00:00:00 2001 From: ralph isenmann Date: Thu, 11 Mar 2021 08:22:36 +0100 Subject: [client] Fix switch between container and vm in lecture --- .../dozmod/gui/window/LectureDetailsWindow.java | 66 ++++++++++------------ .../window/layout/LectureDetailsWindowLayout.java | 14 ++++- .../openslx/dozmod/gui/wizard/LectureWizard.java | 27 +++++---- .../gui/wizard/page/LectureImageListPage.java | 7 ++- .../org/openslx/dozmod/util/ContainerUtils.java | 32 +++++++++++ 5 files changed, 96 insertions(+), 50 deletions(-) create mode 100644 dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod') diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java index 6825d644..97301092 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java @@ -1,36 +1,8 @@ package org.openslx.dozmod.gui.window; -import java.awt.Frame; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collections; -import java.util.Comparator; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import javax.swing.DefaultComboBoxModel; -import javax.swing.JFrame; -import javax.swing.JOptionPane; -import javax.swing.JPanel; - import org.apache.log4j.Logger; import org.apache.thrift.TException; -import org.openslx.bwlp.thrift.iface.ImageDetailsRead; -import org.openslx.bwlp.thrift.iface.ImagePermissions; -import org.openslx.bwlp.thrift.iface.ImageSummaryRead; -import org.openslx.bwlp.thrift.iface.ImageVersionDetails; -import org.openslx.bwlp.thrift.iface.LecturePermissions; -import org.openslx.bwlp.thrift.iface.LectureRead; -import org.openslx.bwlp.thrift.iface.LectureWrite; -import org.openslx.bwlp.thrift.iface.UserInfo; +import org.openslx.bwlp.thrift.iface.*; import org.openslx.dozmod.gui.Gui; import org.openslx.dozmod.gui.MainWindow; import org.openslx.dozmod.gui.changemonitor.AbstractControlWrapper; @@ -58,10 +30,17 @@ import org.openslx.dozmod.thrift.ThriftActions.LectureMetaCallback; import org.openslx.dozmod.thrift.ThriftError; import org.openslx.dozmod.thrift.cache.UserCache; import org.openslx.dozmod.util.FormatHelper; +import org.openslx.dozmod.util.ContainerUtils; import org.openslx.thrifthelper.Comparators; import org.openslx.thrifthelper.TConst; import org.openslx.thrifthelper.ThriftManager; +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import java.util.List; +import java.util.*; + /** * Window to display and edit the details of a lecture */ @@ -218,6 +197,11 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements final ImageSummaryRead newImage = LectureChangeImage.open(LectureDetailsWindow.this, changeMonitor); if (newImage == null) return; + if (ContainerUtils.isContainerImageLinked(newImage)) { + Gui.showMessageBox(me, I18n.WINDOW.getString("LectureDetails.Message.error.containerLinkedWithLecture"), + MessageType.WARNING, LOGGER, null); + return; + } final ImageMetaCallback callback = new ImageMetaCallback() { @Override public void fetchedImageDetails(ImageDetailsRead imageDetails, @@ -234,6 +218,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements cboVersions.setEnabled(false); chkAutoUpdate.setSelected(true); txtImageName.setText(newImage.getImageName()); + initContainerPanel(); } }; actionHandler.getImageDetails(newImage.imageBaseId, callback); @@ -347,14 +332,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements lblImageNameInfo.setText(image.getImageName()); } - // init container info panel - if (image != null && image.getVirtId().equals(TConst.VIRT_DOCKER) ) - { - showContainerTab(); - pnlTabContainer.init(Session.getSatelliteToken(), image, ContainerPanel.CONTAINER_CONTEXT); - - pnlTabContainer.addToChangeMonitor(changeMonitor); - } + initContainerPanel(); // init permission info adminRightsFromDefaultPermissions = lecture.defaultPermissions.admin; @@ -412,6 +390,20 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements changeMonitor.reset(); } + private void initContainerPanel() { + + if (image != null) { + if (image.getVirtId().equals(TConst.VIRT_DOCKER)) { + addContainerTab(); + pnlTabContainer.init(Session.getSatelliteToken(), image, ContainerPanel.CONTAINER_CONTEXT); + pnlTabContainer.addToChangeMonitor(changeMonitor); + } + else { + removeContainerTab(); + } + } + } + /** * Helper to fill the combobox with the versions of the image. The list will be * sorted by creation timestamp 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 cfc1b581..2b134ba0 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 @@ -51,6 +51,7 @@ public abstract class LectureDetailsWindowLayout extends JDialog { * Version for serialization. */ private static final long serialVersionUID = -8773468375105202314L; + private static final String PANEL_TAB_CONTAINER = "Container"; // stuff ending in '...Info' are supposed to be the read-only labels for the information tab protected final QLabel lblTitleInfo; @@ -444,10 +445,19 @@ public abstract class LectureDetailsWindowLayout extends JDialog { add(buttonPanel, BorderLayout.SOUTH); } - protected void showContainerTab() { - pnlTabs.addTab("Container", pnlTabContainer); + protected void addContainerTab() { + pnlTabs.addTab(PANEL_TAB_CONTAINER, pnlTabContainer); } + + public void removeContainerTab() { + + int index = pnlTabs.indexOfTab(PANEL_TAB_CONTAINER); + if(index != -1) + pnlTabs.remove(index); + } + + private JSpinner makeTimeSpinner(int h, int m) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, h); 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 86ae6dad..018c0206 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 @@ -1,9 +1,5 @@ package org.openslx.dozmod.gui.wizard; -import java.awt.Window; - -import javax.swing.JOptionPane; - import org.apache.log4j.Logger; import org.openslx.bwlp.thrift.iface.ImageSummaryRead; import org.openslx.bwlp.thrift.iface.LectureWrite; @@ -13,16 +9,16 @@ 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.LectureListWindow; -import org.openslx.dozmod.gui.wizard.page.LectureCreationPage; -import org.openslx.dozmod.gui.wizard.page.LectureCustomPermissionPage; -import org.openslx.dozmod.gui.wizard.page.LectureImageListPage; -import org.openslx.dozmod.gui.wizard.page.LectureLocationSelectionPage; -import org.openslx.dozmod.gui.wizard.page.LectureOptionsPage; +import org.openslx.dozmod.gui.wizard.page.*; import org.openslx.dozmod.state.LectureWizardState; import org.openslx.dozmod.thrift.Session; import org.openslx.dozmod.thrift.ThriftActions; import org.openslx.dozmod.thrift.cache.LectureCache; import org.openslx.dozmod.thrift.cache.MetaDataCache; +import org.openslx.dozmod.util.ContainerUtils; + +import javax.swing.*; +import java.awt.*; public class LectureWizard extends Wizard implements UiFeedback { @@ -37,7 +33,7 @@ public class LectureWizard extends Wizard implements UiFeedback { /** * Wizard for creating or editing a lecture. - * + * * @param parent window of this wizard * @param image ImageSummaryRead of the image to link this lecture to, * if this is null it will add the LectureImageListPage to @@ -64,6 +60,17 @@ public class LectureWizard extends Wizard implements UiFeedback { } } + @Override public void setVisible(boolean b) { + if (state.image != null && state.imageVersionId != null) { + if (ContainerUtils.isContainerImageLinked(state.image)) { + dispose(); + super.setVisible(false); + return; + } + } + super.setVisible(true); + } + @Override public String getWindowTitle() { return I18n.WIZARD.getString("Lecture.Wizard.title"); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureImageListPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureImageListPage.java index 3b4935cb..1c35df7b 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureImageListPage.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureImageListPage.java @@ -15,6 +15,7 @@ import org.openslx.dozmod.gui.wizard.layout.LectureImageListPageLayout; import org.openslx.dozmod.permissions.ImagePerms; import org.openslx.dozmod.state.LectureWizardState; import org.openslx.dozmod.thrift.cache.ImageCache; +import org.openslx.dozmod.util.ContainerUtils; import org.openslx.util.QuickTimer; import org.openslx.util.QuickTimer.Task; @@ -90,7 +91,11 @@ public class LectureImageListPage extends LectureImageListPageLayout { private boolean isPageValid() { ImageSummaryRead selected = imageTable.getSelectedItem(); - if (selected != null && selected.isValid && ImagePerms.canLink(selected)) { + if (ContainerUtils.isContainerImageLinked(selected)) { + setErrorMessage(I18n.PAGE.getString("LectureImageList.WizardPage.errorMessage.containerLinkedWithLecture")); + return false; + } + else if (selected != null && selected.isValid && ImagePerms.canLink(selected)) { state.image = selected; state.imageVersionId = selected.getLatestVersionId(); setDescription(I18n.PAGE.getString("LectureImageList.WizardPage.description")); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java new file mode 100644 index 00000000..1b83fdfc --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java @@ -0,0 +1,32 @@ +package org.openslx.dozmod.util; + +import org.openslx.bwlp.thrift.iface.ImageSummaryRead; +import org.openslx.bwlp.thrift.iface.LectureSummary; +import org.openslx.dozmod.thrift.cache.LectureCache; +import org.openslx.thrifthelper.TConst; + +import java.util.List; + +/** + * Class with some temporally Helper Functions. + */ +public class ContainerUtils { + + /** + * Checks ImageBaseId of image if already linked with existing Lectures in LectureCache. + * + * @param image The image to check. + * @return true if the images imageBaseId is already linked with a lecture. + */ + public static boolean isContainerImageLinked(ImageSummaryRead image) { + if (image != null && image.getVirtId().equals(TConst.VIRT_DOCKER)) { + List lectureSummaries = LectureCache.get(true); + for (LectureSummary lecture : lectureSummaries) { + if (lecture.imageBaseId.equals(image.imageBaseId)) { + return true; + } + } + } + return false; + } +} -- cgit v1.2.3-55-g7522