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 +++++++++++ .../src/main/properties/i18n/page.properties | 2 + .../src/main/properties/i18n/page_de_DE.properties | 2 + .../src/main/properties/i18n/page_tr_TR.properties | 1 + .../src/main/properties/i18n/window.properties | 2 + .../main/properties/i18n/window_de_DE.properties | 2 + .../main/properties/i18n/window_tr_TR.properties | 1 + 11 files changed, 106 insertions(+), 50 deletions(-) create mode 100644 dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java 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; + } +} diff --git a/dozentenmodul/src/main/properties/i18n/page.properties b/dozentenmodul/src/main/properties/i18n/page.properties index cea6bcdd..f9c094a2 100644 --- a/dozentenmodul/src/main/properties/i18n/page.properties +++ b/dozentenmodul/src/main/properties/i18n/page.properties @@ -104,6 +104,8 @@ LectureCreation.WizardPage.description.1=Click on ''Next'' to set permissions \ # LectureImageListPage LectureImageList.WizardPage.description=Click on ''Next'' +LectureImageList.WizardPage.errorMessage.containerLinkedWithLecture=This image is already linked with a lecture. \ + Please create a new image. LectureImageList.WizardPage.errorMessage.noPerms=Insufficient permissions to link to this VM. LectureImageList.WizardPage.errorMessage.invalidVM=Invalid VM selected diff --git a/dozentenmodul/src/main/properties/i18n/page_de_DE.properties b/dozentenmodul/src/main/properties/i18n/page_de_DE.properties index cf27df34..24382b0b 100644 --- a/dozentenmodul/src/main/properties/i18n/page_de_DE.properties +++ b/dozentenmodul/src/main/properties/i18n/page_de_DE.properties @@ -101,6 +101,8 @@ LectureCreation.WizardPage.description.1=Klicken Sie auf ''Weiter'', um Berechti # LectureImageListPage LectureImageList.WizardPage.description=Klicken Sie auf ''Weiter'' +LectureImageList.WizardPage.errorMessage.containerLinkedWithLecture=Dieses Image ist bereits mit einer Veranstaltung \ + verlinkt. Bitte erstellen sie ein neues Image. LectureImageList.WizardPage.errorMessage.noPerms=Unzureichende Berechtigungen, um auf diese VM zu verlinken. LectureImageList.WizardPage.errorMessage.invalidVM=Ungültige VM ausgewählt diff --git a/dozentenmodul/src/main/properties/i18n/page_tr_TR.properties b/dozentenmodul/src/main/properties/i18n/page_tr_TR.properties index 766e7881..678bd5f4 100644 --- a/dozentenmodul/src/main/properties/i18n/page_tr_TR.properties +++ b/dozentenmodul/src/main/properties/i18n/page_tr_TR.properties @@ -96,6 +96,7 @@ LectureCreation.WizardPage.description.1=Erişim izinlerini ayarlamak için ''İ # LectureImageListPage LectureImageList.WizardPage.description=''İleri'' butonuna tıklayın +LectureImageList.WizardPage.errorMessage.containerLinkedWithLecture= LectureImageList.WizardPage.errorMessage.noPerms=Bu sanal makineye bağlantı eklemek için yeterli erişim izni yok. LectureImageList.WizardPage.errorMessage.invalidVM=Geçersiz sanal makine seçildi diff --git a/dozentenmodul/src/main/properties/i18n/window.properties b/dozentenmodul/src/main/properties/i18n/window.properties index ed908af3..180db3fc 100644 --- a/dozentenmodul/src/main/properties/i18n/window.properties +++ b/dozentenmodul/src/main/properties/i18n/window.properties @@ -75,6 +75,8 @@ LectureChangeImage.Message.error.canNotLinkToVM=No permissions to link to the se LectureDetails.ComboBox.versions.error=No/invalid VM version selected LectureDetails.Message.error.endAfterStart=End date must not be before the start date LectureDetails.Message.error.endAfterMaxValidity=End date is after the {0} +LectureDetails.Message.error.containerLinkedWithLecture=This image is already linked with a lecture. \ + Please create a new image. LectureDetails.TextField.title.error=Lecture name must not be empty LectureDetails.TextField.description.error=Description must not be empty LectureDetails.NetRulesConfigurator.error=Incorrect network rules diff --git a/dozentenmodul/src/main/properties/i18n/window_de_DE.properties b/dozentenmodul/src/main/properties/i18n/window_de_DE.properties index 96c7efb1..160227aa 100644 --- a/dozentenmodul/src/main/properties/i18n/window_de_DE.properties +++ b/dozentenmodul/src/main/properties/i18n/window_de_DE.properties @@ -75,6 +75,8 @@ LectureChangeImage.Message.error.canNotLinkToVM=Keine Rechte zum Verlinken auf d LectureDetails.ComboBox.versions.error=Keine/Ungültige VM-Version ausgewählt LectureDetails.Message.error.endAfterStart=Enddatum darf nicht vor dem Startdatum liegen LectureDetails.Message.error.endAfterMaxValidity=Enddatum liegt nach dem {0} +LectureDetails.Message.error.containerLinkedWithLecture=Dieses Image ist bereits mit einer Veranstaltung \ + verlinkt. Bitte erstellen sie ein neues Image. LectureDetails.TextField.title.error=Veranstaltungsname darf nicht leer sein LectureDetails.TextField.description.error=Beschreibung darf nicht leer sein LectureDetails.NetRulesConfigurator.error=Fehlerhafte Netzwerkregeln diff --git a/dozentenmodul/src/main/properties/i18n/window_tr_TR.properties b/dozentenmodul/src/main/properties/i18n/window_tr_TR.properties index 8d22cf05..99116e78 100644 --- a/dozentenmodul/src/main/properties/i18n/window_tr_TR.properties +++ b/dozentenmodul/src/main/properties/i18n/window_tr_TR.properties @@ -75,6 +75,7 @@ LectureChangeImage.Message.error.canNotLinkToVM=Seçilen sanal makineye bağlant LectureDetails.ComboBox.versions.error=Hiçbir sanal makine sürümü seçilmedi yada geçersiz sanal makine sürümü seçildi LectureDetails.Message.error.endAfterStart=Bitiş tarihi başlangıç tarihinden önce olmamalıdır LectureDetails.Message.error.endAfterMaxValidity=Bitiş tarihi {0} tarihinden sonra +LectureDetails.Message.error.containerLinkedWithLecture= LectureDetails.TextField.title.error=Etkinlik adı boş bırakılamaz LectureDetails.TextField.description.error=Açıklama boş bırakılamaz LectureDetails.NetRulesConfigurator.error=Hatalı ağ kuralları -- cgit v1.2.3-55-g7522