diff options
| author | ralph isenmann | 2020-10-05 15:36:21 +0200 |
|---|---|---|
| committer | ralph isenmann | 2020-10-05 15:36:21 +0200 |
| commit | c09bb7450bf7a0aa3d7b1f61c3b4caeb14efd63c (patch) | |
| tree | ba801a6b803827d3da28b3ae8ca0fe472beafd93 /dozentenmodul/src/main/java/org | |
| parent | [client] Allow User to use Git Repos as Input for a ContainerDefinition (diff) | |
| download | tutor-module-c09bb7450bf7a0aa3d7b1f61c3b4caeb14efd63c.tar.gz tutor-module-c09bb7450bf7a0aa3d7b1f61c3b4caeb14efd63c.tar.xz tutor-module-c09bb7450bf7a0aa3d7b1f61c3b4caeb14efd63c.zip | |
[client] allow user to define bind mounts for container
- update gui with table that can be modified by user with entrys for bind mounts
- update ContainerMeta to use these ContainerBindMount
- remove older bind mount solution (gui elements)
- TODO: update ImageDetailsList to allow modification on bind mounts
Diffstat (limited to 'dozentenmodul/src/main/java/org')
9 files changed, 384 insertions, 174 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ContainerBindMountTable.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ContainerBindMountTable.java new file mode 100644 index 00000000..6796e21a --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ContainerBindMountTable.java @@ -0,0 +1,28 @@ +package org.openslx.dozmod.gui.control.table; + +import org.openslx.dozmod.model.ContainerBindMount; + +import java.util.ArrayList; + +public class ContainerBindMountTable extends ListTable<ContainerBindMount> { + + public static final ListTableColumn COL_SOURCE = new ListTableColumn("SOURCE"); + public static final ListTableColumn COL_TARGET = new ListTableColumn("TARGET"); + public static final ListTableColumn COL_OPTIONS = new ListTableColumn("OPTINONS"); + + public ContainerBindMountTable() { + super(COL_SOURCE, COL_TARGET, COL_OPTIONS); + // init with empty data list + this.setData(new ArrayList<ContainerBindMount>(), false); + } + + @Override protected Object getValueAtInternal(ContainerBindMount item, ListTableColumn column) { + if (COL_SOURCE == column) + return item.getSource(); + if (COL_TARGET == column) + return item.getTarget(); + if (COL_OPTIONS == column) + return item.getOptions(); + throw new IndexOutOfBoundsException(); + } +} diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ContainerBindMountWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ContainerBindMountWindow.java new file mode 100644 index 00000000..a7c141fb --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ContainerBindMountWindow.java @@ -0,0 +1,78 @@ +package org.openslx.dozmod.gui.window; + +import org.openslx.dozmod.gui.control.table.ContainerBindMountTable; +import org.openslx.dozmod.gui.helper.TextChangeListener; +import org.openslx.dozmod.gui.window.layout.ContainerBindMountWindowLayout; +import org.openslx.dozmod.model.ContainerBindMount; + +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.List; + +public class ContainerBindMountWindow extends ContainerBindMountWindowLayout { + + private ContainerBindMountTable bindMountTable; + + public ContainerBindMountWindow(Window modalParent, ContainerBindMountTable bindMountTable) { + super(modalParent); + + this.bindMountTable = bindMountTable; + + this.btnSave.setEnabled(false); + this.btnSave.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { + saveEntry(); + } + }); + this.btnCancel.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { + dispose(); + } + }); + this.txtBmSource.getDocument().addDocumentListener(new TextChangeListener() { + @Override public void changed() { + isInputComplete(); + } + }); + this.txtBmTarget.getDocument().addDocumentListener(new TextChangeListener() { + @Override public void changed() { + isInputComplete(); + } + }); + + } + + // TODO add text if input not finished + private boolean isInputComplete() { + btnSave.setEnabled(false); + if (txtBmSource == null || txtBmSource.getText().isEmpty()) + return false; + if (txtBmTarget == null || txtBmTarget.getText().isEmpty()) { + return false; + } + btnSave.setEnabled(true); + return true; + } + + private void saveEntry() { + ContainerBindMount bindMount = new ContainerBindMount(); + bindMount.setSource(this.txtBmSource.getText()); + bindMount.setTarget(this.txtBmTarget.getText()); + bindMount.setOptions(this.txtBmOptions.getText()); + + List<ContainerBindMount> oldData = bindMountTable.getData(); + List<ContainerBindMount> data = new ArrayList<>(oldData); + + data.add(bindMount); + bindMountTable.setData(data, true); + dispose(); + } + + public static void open(Window modalParent, ContainerBindMountTable bindMountTable) { + ContainerBindMountWindow win = new ContainerBindMountWindow(modalParent, bindMountTable); + win.setVisible(true); + } + +} 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 b1378852..a392d7b8 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 @@ -64,8 +64,8 @@ import org.openslx.util.Util; /** * Window for displaying and editing the details of an image. */ -@SuppressWarnings("serial") -public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFeedback { +@SuppressWarnings("serial") public class ImageDetailsWindow extends ImageDetailsWindowLayout + implements UiFeedback { private static final Logger LOGGER = Logger.getLogger(ImageDetailsWindow.class); @@ -124,9 +124,9 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe /** * Constructor - * + * * @param modalParent parent of this popup window - * @param callback callback to be called when the image details have changed + * @param callback callback to be called when the image details have changed */ public ImageDetailsWindow(Frame modalParent, ImageUpdatedCallback callback, ImageDetailsActions actionHandler) { @@ -136,15 +136,13 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe // Set up change monitor changeMonitor = new DialogChangeMonitor(new DialogChangeMonitor.Callback() { - @Override - public void validityChanged(String errorMessage) { + @Override public void validityChanged(String errorMessage) { lblError.setText(errorMessage); btnSaveChanges.setEnabled(changeMonitor.isValid() && changeMonitor.wasEverModified()); LOGGER.info("Valid: " + changeMonitor.isValid()); } - @Override - public void modificationChanged() { + @Override public void modificationChanged() { btnSaveChanges.setEnabled(changeMonitor.isValid() && changeMonitor.wasEverModified()); LOGGER.info("Changed: " + changeMonitor.isCurrentlyModified()); } @@ -152,8 +150,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe // Hook when user presses X (top right) setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { + @Override public void windowClosing(WindowEvent e) { safeClose(); } }); @@ -162,36 +159,31 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe * Button listeners */ btnClose.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { + @Override public void actionPerformed(ActionEvent e) { safeClose(); } }); btnSaveChanges.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { + @Override public void actionPerformed(ActionEvent e) { saveChanges(); } }); btnUpdateImage.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { + @Override public void actionPerformed(ActionEvent e) { // FIXME: This will always discard all changes even if you cancel right away new ImageUpdateWizard(me, image).setVisible(true); refresh(); } }); btnUploadToMaster.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { + @Override public void actionPerformed(ActionEvent e) { uploadToMaster(); } }); btnShowLinkingLectures.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { + @Override public void actionPerformed(ActionEvent e) { if (safeClose()) { LectureListWindow page = MainWindow.showPage(LectureListWindow.class); page.filterByImageBaseId(image.imageBaseId); @@ -201,16 +193,13 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe }); btnChangeOwner.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { + @Override public void actionPerformed(ActionEvent e) { UserListWindow.open(me, new UserAddedCallback() { - @Override - public void userAdded(UserInfo user, UserListWindow window) { + @Override public void userAdded(UserInfo user, UserListWindow window) { window.dispose(); - if (Gui.showMessageBox(me, - "Sind Sie sicher, dass sie die Besitzerrechte an " - + "einen anderen Benutzer übertragen wollen?", - MessageType.QUESTION_YESNO, LOGGER, null)) + if (Gui.showMessageBox(me, "Sind Sie sicher, dass sie die Besitzerrechte an " + + "einen anderen Benutzer übertragen wollen?", MessageType.QUESTION_YESNO, + LOGGER, null)) setImageOwner(user); } @@ -230,7 +219,8 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe return; if (e.getSource().equals(mnuNewLecture)) { ImageSummaryRead summary = new ImageSummaryRead(); - summary.setImageName(image.getImageName()); // Maybe create a helper class/function some day that transforms all fields + summary.setImageName( + image.getImageName()); // Maybe create a helper class/function some day that transforms all fields new LectureWizard(me, summary, selected.getVersionId()).setVisible(true); } if (e.getSource().equals(mnuDownload)) { @@ -263,8 +253,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe tblVersions.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "delete"); tblVersions.getActionMap().put("delete", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent ae) { + @Override public void actionPerformed(ActionEvent ae) { if (ImagePerms.canEdit(image)) { deleteVersions(tblVersions.getSelectedItems()); } @@ -275,13 +264,11 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe * Mouse adapter for the version table */ final MouseAdapter ma = new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { + @Override public void mousePressed(MouseEvent e) { processClick(e); } - @Override - public void mouseReleased(MouseEvent e) { + @Override public void mouseReleased(MouseEvent e) { processClick(e); } @@ -310,11 +297,13 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe mnuNewLecture.setEnabled( !multiSelection && selectedVersion.isValid && ImagePerms.canLink(image)); mnuDownload.setEnabled(!multiSelection && ImagePerms.canDownload(image)); - mnuVmConfig.setEnabled(!multiSelection && selectedVersion.isValid - && ImagePerms.canEdit(image)); // Allow VMX edition for downloaded VMs for now + mnuVmConfig.setEnabled( + !multiSelection && selectedVersion.isValid && ImagePerms.canEdit( + image)); // Allow VMX edition for downloaded VMs for now mnuDelete.setEnabled(ImagePerms.canEdit(image)); - mnuExtendExpiryDate.setEnabled(!multiSelection && (selectedVersion.isValid - || Session.hasFeature(Feature.EXTEND_EXPIRED_VM))); + mnuExtendExpiryDate.setEnabled( + !multiSelection && (selectedVersion.isValid || Session.hasFeature( + Feature.EXTEND_EXPIRED_VM))); pop.show(e.getComponent(), e.getX(), e.getY()); } } @@ -332,7 +321,8 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe changeMonitor.addFixedCombo(cboOperatingSystem, Comparators.operatingSystem) .addConstraint(new DialogChangeMonitor.ValidationConstraint<OperatingSystem>() { public String checkStateValid(OperatingSystem userInput) { - if (userInput != null && MetaDataCache.getOsById(userInput.osId) != null) // validating OS coming from the cache makes no sense? + if (userInput != null && MetaDataCache.getOsById(userInput.osId) + != null) // validating OS coming from the cache makes no sense? return null; return "Ungültiges Betriebssystem ausgewählt!"; } @@ -354,8 +344,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe // update default permissions hook for the permission configurator to apply to newly added users final ItemListener updateDefaultPermissionsListener = new ItemListener() { - @Override - public void itemStateChanged(ItemEvent e) { + @Override public void itemStateChanged(ItemEvent e) { if (e.getSource() == chkDefaultPermLink) image.defaultPermissions.link = chkDefaultPermLink.isSelected(); if (e.getSource() == chkDefaultPermDownload) @@ -389,8 +378,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe QuickTimer.scheduleOnce(new Task() { ByteBuffer machineDescription = null; - @Override - public void fire() { + @Override public void fire() { try { machineDescription = ThriftManager.getSatClient() .getImageVersionVirtConfig(Session.getSatelliteToken(), selected.versionId); @@ -400,8 +388,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe return; } Gui.asyncExec(new Runnable() { - @Override - public void run() { + @Override public void run() { if (machineDescription == null) { Gui.showMessageBox("Konnte VM-Konfiguration nicht abrufen.", MessageType.ERROR, LOGGER, null); @@ -422,14 +409,12 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe }); } - - /** * Uploads ByteBuffer data to satellite server and stores it in ImageVersion.VirtConfig * for the given imageVersionId. * * @param imageVersionId Id of the image version, which will be updated. - * @param data New virtConfig to store in database. + * @param data New virtConfig to store in database. */ private void uploadContainerDef(final String imageVersionId, ByteBuffer data) { @@ -448,31 +433,31 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe */ private byte[] loadContainerDef(final ImageVersionDetails selected) { - byte[] rawVirtConfig = null; try { ByteBuffer byteBuffer = ThriftManager.getSatClient() .getImageVersionVirtConfig(Session.getSatelliteToken(), selected.versionId); - rawVirtConfig = ThriftUtil.unwrapByteBuffer(byteBuffer); + rawVirtConfig = ThriftUtil.unwrapByteBuffer(byteBuffer); } catch (TException e) { - LOGGER.error("Failed to retrieve virtualizer config for image version " + "'" - + image.latestVersionId + ", see trace: ", e); + LOGGER.error( + "Failed to retrieve virtualizer config for image version " + "'" + image.latestVersionId + + ", see trace: ", e); } - return rawVirtConfig; + return rawVirtConfig; } /******************************************************************************** - * + * * Helper triggering the actual thrift calls - * + * ********************************************************************************/ /** * Sets the image to the given imageBaseId. This will also trigger fill() * which will set the image details fields to the values represented by this * image. - * + * * @param imageBaseId the id of the image to be displayed */ public void setImage(final String imageBaseId) { @@ -480,8 +465,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe MetaDataCache.getOperatingSystems(); MetaDataCache.getVirtualizers(); final ImageMetaCallback callback = new ImageMetaCallback() { - @Override - public void fetchedImageDetails(ImageDetailsRead imageDetails, + @Override public void fetchedImageDetails(ImageDetailsRead imageDetails, Map<String, ImagePermissions> permissions) { if (imageDetails == null) { return; @@ -504,7 +488,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe /** * Sets the owner of the selected image to the given user. - * + * * @param user UserInfo to set the owner to */ private void setImageOwner(final UserInfo user) { @@ -524,10 +508,9 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe private void uploadToMaster() { // 04.2018: bail if we the user tries to publish a non-vmware image. if (Session.hasFeature(Feature.MULTIPLE_HYPERVISORS) && !TConst.VIRT_VMWARE.equals(image.virtId)) { - Gui.showMessageBox( - MetaDataCache.getVirtualizerById(image.virtId).virtName - + " ist derzeit nicht für den öffentlichen Austausch freigegeben.", - MessageType.ERROR, null, null); + Gui.showMessageBox(MetaDataCache.getVirtualizerById(image.virtId).virtName + + " ist derzeit nicht für den öffentlichen Austausch freigegeben.", MessageType.ERROR, + null, null); return; } if (changeMonitor.isCurrentlyModified()) { @@ -544,12 +527,11 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe return; // start upload to masterserver QuickTimer.scheduleOnce(new Task() { - @Override - public void fire() { + @Override public void fire() { final String transferId; try { - transferId = ThriftManager.getSatClient().publishImageVersion(Session.getSatelliteToken(), - image.latestVersionId); + transferId = ThriftManager.getSatClient() + .publishImageVersion(Session.getSatelliteToken(), image.latestVersionId); } catch (TException e1) { ThriftError.showMessage(me, LOGGER, e1, "Upload der VM auf den Masterserver fehlgeschlagen." @@ -559,15 +541,14 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe return; } Gui.asyncExec(new Runnable() { - @Override - public void run() { + @Override public void run() { MainWindow.addPassiveTransfer(transferId, image.imageName, true); // Inform user Gui.showMessageBox(ImageDetailsWindow.this, - "Die Übertragung läuft direkt zwischen Satellitenserver und" - + " dem " + Branding.getServiceName() + " Zentral-Server.\n" - + "Wenn Sie die " + Branding.getApplicationName() + " schließen, wird der Transfer trotzdem" - + "weiterlaufen.", + "Die Übertragung läuft direkt zwischen Satellitenserver und" + " dem " + + Branding.getServiceName() + " Zentral-Server.\n" + "Wenn Sie die " + + Branding.getApplicationName() + + " schließen, wird der Transfer trotzdem" + "weiterlaufen.", MessageType.INFO, null, null); } }); @@ -633,7 +614,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe // if image is container // prepare to upload container definition to local satellite server. // TODO - if(image.getVirtId().equals(TConst.VIRT_DOCKER)) + if (image.getVirtId().equals(TConst.VIRT_DOCKER)) saveContainerDefinition(); changeMonitor.reset(); @@ -648,11 +629,9 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe conDev.getContainerMeta().setImageName(txtContainerImageName.getText()); conDev.getContainerMeta().setRunOptions(txtContainerRun.getText()); - conDev.getContainerMeta().mountUserDir(chkContainerMountUserDir.isSelected()); - conDev.getContainerMeta().setUserMountPath(txtContainerMountUserDir.getText()); - if(!conDev.equals(containerDefinition)) { - uploadContainerDef(image.versions.get(0).versionId,conDev.toByteBuffer()); + if (!conDev.equals(containerDefinition)) { + uploadContainerDef(image.versions.get(0).versionId, conDev.toByteBuffer()); LOGGER.info("Upload new DockerDefinition"); } } @@ -701,8 +680,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe if (version == null) return; actionHandler.deleteImageVersion(version, new DeleteCallback() { - @Override - public void isDeleted(boolean success) { + @Override public void isDeleted(boolean success) { refresh(); } }); @@ -710,7 +688,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe /** * Triggers the deletion of a list of versions. - * + * * @param versions to delete */ private void deleteVersions(List<ImageVersionDetails> versions) { @@ -744,10 +722,11 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe if (daysToExtend == -1) return; } - currentExpiryTimeAsDate = DateTimeHelper.addDaysTo(currentExpiryTimeAsDate, daysToExtend); + currentExpiryTimeAsDate = DateTimeHelper.addDaysTo(currentExpiryTimeAsDate, daysToExtend); try { - ThriftManager.getSatClient().setImageVersionExpiry(Session.getSatelliteToken(), img.versionId, - currentExpiryTimeAsDate.getTime() / 1000L); + ThriftManager.getSatClient() + .setImageVersionExpiry(Session.getSatelliteToken(), img.versionId, + currentExpiryTimeAsDate.getTime() / 1000L); count++; } catch (TException e) { ThriftError.showMessage(this, LOGGER, e, @@ -768,6 +747,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe ********************************************************************************/ /** + * */ private void refresh() { String baseId = image.getImageBaseId(); @@ -815,12 +795,10 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe if (virt != null) lblVirtualizer.setText(virt.getVirtName()); - - if(TConst.VIRT_DOCKER.equals(image.getVirtId())){ + if (TConst.VIRT_DOCKER.equals(image.getVirtId())) { lblVirtualizer.setText(TConst.VIRT_DOCKER); showContainerTab(); - if (image.versions.isEmpty()) { LOGGER.info("Close Window because no ImageVersions available!"); dispose(); @@ -832,9 +810,6 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe txtContainerDescription.setText(containerDefinition.getDescription()); txtContainerImageName.setText(containerDefinition.getContainerMeta().getImageName()); txtContainerRun.setText(containerDefinition.getContainerMeta().getRunOptions()); - chkContainerMountUserDir.setSelected(containerDefinition.getContainerMeta().mountUserDir()); - txtContainerMountUserDir.setEnabled(chkContainerMountUserDir.isSelected()); - txtContainerMountUserDir.setText(containerDefinition.getContainerMeta().getUserMountPath()); changeMonitor.add(txtContainerDescription). addConstraint(new TextNotEmptyConstraint("Empty Dockerfile not allowed!")); @@ -844,13 +819,6 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe .addConstraint(new TextNotEmptyConstraint("No Container Run Options provided!")); // TODO txtContainerMountUserDir txt Field needs a Constraint, only when chkContainerMountUserDir is selected; changeMonitor.add(txtContainerMountUserDir); - - chkContainerMountUserDir.addActionListener(new ActionListener() { - @Override public void actionPerformed(ActionEvent e) { - containerDefinition.getContainerMeta().mountUserDir(chkContainerMountUserDir.isSelected()); - txtContainerMountUserDir.setEnabled(chkContainerMountUserDir.isSelected()); - } - }); } // fill share mode combo, if not already done @@ -900,7 +868,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe /** * Enables/disables the editable fields based on 'editable' - * + * * @param editable true to make fields editable, false otherwise. */ private void makeEditable(boolean editable) { @@ -924,7 +892,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe /** * Opens a new ImageDetailsWindow showing the details of the image with ID = * imageBaseId - * + * * @param modalParent parent of this window * @param imageBaseId id of the image to set the details of */ @@ -936,14 +904,12 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe } /* ******************************************************************************* - * + * * Dialog class overrides - * + * * ******************************************************************************* */ - @SuppressWarnings("deprecation") - @Override - public void show() { + @SuppressWarnings("deprecation") @Override public void show() { if (!isVisible()) { pack(); MainWindow.centerShell(this); @@ -952,18 +918,16 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe } /* ******************************************************************************* - * + * * UIFeedback implementation - * + * * ******************************************************************************* */ - @Override - public boolean wantConfirmQuit() { + @Override public boolean wantConfirmQuit() { return changeMonitor.isCurrentlyModified(); } - @Override - public void escapePressed() { + @Override public void escapePressed() { safeClose(); } @@ -972,9 +936,9 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe * confirmation if so */ private boolean safeClose() { - if (changeMonitor.isCurrentlyModified() - && !Gui.showMessageBox(me, "Änderungen werden verworfen, wollen Sie wirklich schließen?", - MessageType.QUESTION_YESNO, null, null)) + if (changeMonitor.isCurrentlyModified() && !Gui.showMessageBox(me, + "Änderungen werden verworfen, wollen Sie wirklich schließen?", MessageType.QUESTION_YESNO, + null, null)) return false; dispose(); return true; diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ContainerBindMountWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ContainerBindMountWindowLayout.java new file mode 100644 index 00000000..2e5432b8 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ContainerBindMountWindowLayout.java @@ -0,0 +1,69 @@ +package org.openslx.dozmod.gui.window.layout; + +import org.openslx.dozmod.gui.Gui; +import org.openslx.dozmod.gui.control.QLabel; +import org.openslx.dozmod.gui.helper.GridManager; + +import javax.swing.*; +import java.awt.*; + +public class ContainerBindMountWindowLayout extends JDialog { + + private static final String title = "Add Bind Mount"; + + protected final QLabel lblBmSource; + protected final JTextField txtBmSource; + protected final QLabel lblBmTarget; + protected final JTextField txtBmTarget; + protected final QLabel lblBmOptions; + protected final JTextField txtBmOptions; + protected final JButton btnSave; + protected final JButton btnCancel; + + public ContainerBindMountWindowLayout(Window modalParent) { + super(modalParent, title, + modalParent != null ? ModalityType.APPLICATION_MODAL : ModalityType.MODELESS); + + GridManager grid = new GridManager(this, 2, true, new Insets(2, 2, 2, 2)); + + lblBmSource = new QLabel("Source"); + txtBmSource = new JTextField(); + + grid.add(lblBmSource); + grid.add(txtBmSource).fill(true, false).expand(true, false); + grid.nextRow(); + + lblBmTarget = new QLabel("Target"); + txtBmTarget = new JTextField(); + grid.add(lblBmTarget); + grid.add(txtBmTarget).fill(true, false).expand(true, false); + grid.nextRow(); + + lblBmOptions = new QLabel("Options"); + txtBmOptions = new JTextField(); + grid.add(lblBmOptions); + grid.add(txtBmOptions).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()); + btnCancel = new JButton("Cancel"); + buttonPane.add(btnCancel); + buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); + btnSave = new JButton("Save"); + buttonPane.add(btnSave); + grid.add(buttonPane, 2).fill(true, false).expand(true, false); + grid.finish(false); + + //setPreferredSize(Gui.getScaledDimension(650, 350)); + + setSize(350, 150); + setResizable(false); + //setMinimumSize(Gui.getScaledDimension(550, 650)); + if (modalParent != null) { + Gui.centerShellOverShell(modalParent, this); + } + } +} 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 86034171..f47d95e8 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 @@ -1,8 +1,6 @@ package org.openslx.dozmod.gui.window.layout; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import javax.swing.BorderFactory; import javax.swing.Box; @@ -17,7 +15,6 @@ import javax.swing.JScrollPane; import javax.swing.JTabbedPane; import javax.swing.JTextArea; import javax.swing.JTextField; -import javax.swing.event.*; import org.openslx.bwlp.thrift.iface.OperatingSystem; import org.openslx.bwlp.thrift.iface.ShareMode; @@ -32,8 +29,7 @@ import org.openslx.dozmod.gui.control.table.QScrollPane; import org.openslx.dozmod.gui.helper.GridManager; import org.openslx.thrifthelper.Comparators; -@SuppressWarnings("serial") -public abstract class ImageDetailsWindowLayout extends JDialog { +@SuppressWarnings("serial") public abstract class ImageDetailsWindowLayout extends JDialog { private static final int ICON_SIZE_Y = 24; @@ -47,7 +43,6 @@ public abstract class ImageDetailsWindowLayout extends JDialog { protected final JTextField txtContainerImageName; protected final JTextField txtContainerMountUserDir; - protected QLabel lblError; protected final PersonLabel lblOwner; protected final JButton btnChangeOwner; @@ -148,8 +143,7 @@ public abstract class ImageDetailsWindowLayout extends JDialog { cboOperatingSystem = new ComboBox<OperatingSystem>(Comparators.operatingSystem, new ComboBoxRenderer<OperatingSystem>() { - @Override - public String renderItem(OperatingSystem item) { + @Override public String renderItem(OperatingSystem item) { if (item == null) return null; return item.getOsName(); @@ -166,8 +160,7 @@ public abstract class ImageDetailsWindowLayout extends JDialog { // share mode cboShareMode = new ComboBox<ShareMode>(new ComboBoxRenderer<ShareMode>() { - @Override - public String renderItem(ShareMode item) { + @Override public String renderItem(ShareMode item) { if (item == null) return "null"; return item.name(); @@ -222,7 +215,7 @@ public abstract class ImageDetailsWindowLayout extends JDialog { buttonBar.add(btnUploadToMaster); grid.add(buttonBar, 3).fill(true, false).expand(true, false); grid.nextRow(); - + grid.finish(false); /* ******************************************************************************* @@ -244,8 +237,11 @@ public abstract class ImageDetailsWindowLayout extends JDialog { ********************************************************************************/ JPanel pnlTabPermissions = new JPanel(); ctlImagePermissionConfigurator = new ImagePermissionConfigurator(); - GridManager grdImagePermissionConfigurator = new GridManager(pnlTabPermissions, 1, false, new Insets(8, 2, 8, 2)); - grdImagePermissionConfigurator.add(ctlImagePermissionConfigurator).fill(true, true).expand(true, true); + GridManager grdImagePermissionConfigurator = new GridManager(pnlTabPermissions, 1, false, + new Insets(8, 2, 8, 2)); + grdImagePermissionConfigurator.add(ctlImagePermissionConfigurator) + .fill(true, true) + .expand(true, true); // Panel with the permissions for other users JPanel defaultPermissionPane = new JPanel(); defaultPermissionPane.setBorder(BorderFactory.createTitledBorder("Andere Nutzer")); @@ -292,26 +288,24 @@ public abstract class ImageDetailsWindowLayout extends JDialog { grdContainerMeta.add(new QLabel("Image Name")); txtContainerImageName = new JTextField(); txtContainerImageName.setDocument(txtTitle.getDocument()); - grdContainerMeta.add(txtContainerImageName,2).fill(true,false); + grdContainerMeta.add(txtContainerImageName, 2).fill(true, false); grdContainerMeta.nextRow(); grdContainerMeta.add(new QLabel("Container Run Options")); txtContainerRun = new JTextField(); - grdContainerMeta.add(txtContainerRun,2).fill(true,false); + grdContainerMeta.add(txtContainerRun, 2).fill(true, false); grdContainerMeta.nextRow(); - grdContainerMeta.add(new QLabel("Mount User Directory"),1); + grdContainerMeta.add(new QLabel("Mount User Directory"), 1); chkContainerMountUserDir = new JCheckBox(); txtContainerMountUserDir = new JTextField(); - grdContainerMeta.add(chkContainerMountUserDir,1); - grdContainerMeta.add(txtContainerMountUserDir,1).fill(true,false); + grdContainerMeta.add(chkContainerMountUserDir, 1); + grdContainerMeta.add(txtContainerMountUserDir, 1).fill(true, false); grdContainerMeta.finish(true); - GridManager grdContainer = new GridManager(pnlTabContainer, 1, false, new Insets(8, 2, 8, 2)); - grdContainer.add(scrollableTextArea,1).fill(true, true).expand(true,true); - grdContainer.add(pnlContainerMeta,1).fill(true, false) - .anchor(GridBagConstraints.FIRST_LINE_START); + grdContainer.add(scrollableTextArea, 1).fill(true, true).expand(true, true); + grdContainer.add(pnlContainerMeta, 1).fill(true, false).anchor(GridBagConstraints.FIRST_LINE_START); grdContainer.add(Box.createVerticalGlue()).fill(true, true); grdContainer.finish(false); @@ -344,7 +338,7 @@ public abstract class ImageDetailsWindowLayout extends JDialog { pnlTabs.addTab("Übersicht", pnlTabOverview); pnlTabs.addTab("VM-Versionen", pnlTabVersions); pnlTabs.addTab("Berechtigungen", pnlTabPermissions); - + add(pnlTabs, BorderLayout.CENTER); add(pnlButtons, BorderLayout.PAGE_END); } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ContainerUploadPageLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ContainerUploadPageLayout.java index bbb85850..3533d38f 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ContainerUploadPageLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ContainerUploadPageLayout.java @@ -1,6 +1,8 @@ package org.openslx.dozmod.gui.wizard.layout; import org.openslx.dozmod.gui.control.QLabel; +import org.openslx.dozmod.gui.control.table.ContainerBindMountTable; +import org.openslx.dozmod.gui.control.table.QScrollPane; import org.openslx.dozmod.gui.helper.GridManager; import org.openslx.dozmod.gui.wizard.Wizard; import org.openslx.dozmod.gui.wizard.WizardPage; @@ -24,6 +26,10 @@ public class ContainerUploadPageLayout extends WizardPage { protected final JTabbedPane tpInput; protected final JTextField txtGitRepo; + protected final ContainerBindMountTable bindMountTable; + protected final JButton btnAddBindMount; + protected final JButton btnDelBindMount; + public enum BuildContextMethod { FILE, GIT_REPOSITORY; } @@ -58,7 +64,11 @@ public class ContainerUploadPageLayout extends WizardPage { p2.setVisible(false); GridManager g2 = new GridManager(p2, 2, true, new Insets(5, 0, 5, 0)); QLabel lblGitRepo = new QLabel("Git Repository"); + lblGitRepo.setToolTipText( + "Set clone address of Git Repository [git@ | http://] [.git]. Currently no Checks!"); txtGitRepo = new JTextField(); + txtGitRepo.setToolTipText( + "Set clone address of Git Repository [git@ | http://] [.git]. Currently no Checks!"); g2.add(lblGitRepo); g2.add(txtGitRepo).fill(true, false).expand(true, false); g2.finish(false); @@ -73,7 +83,7 @@ public class ContainerUploadPageLayout extends WizardPage { tpInput = new JTabbedPane(); tpInput.addTab("Dockerfile", p1); tpInput.addTab("Git Repository", p2); -// tpInput.addTab("Simple Input", p3); + // tpInput.addTab("Simple Input", p3); tpInput.setSelectedIndex(BuildContextMethod.FILE.ordinal()); grid.add(tpInput, 3).fill(true, false); @@ -94,19 +104,24 @@ public class ContainerUploadPageLayout extends WizardPage { grid.add(chkLicenseRestricted, 2, 1).fill(false, false).expand(true, false); grid.nextRow(); - grid.add(new JSeparator(), 3); - grid.nextRow(); - lblContainerRun = new QLabel("Container Start Optionen"); lblContainerRun.setToolTipText("Geben Sie die Container Run Optionen an (Port, Name, Env,...)"); txtContainerRun = new JTextField(); grid.add(lblContainerRun); grid.add(txtContainerRun, 2, 1).fill(true, false).expand(true, false); - grid.nextRow(); - grid.add(Box.createVerticalGlue(), 3).expand(true, true); + bindMountTable = new ContainerBindMountTable(); + QScrollPane jsp = new QScrollPane(bindMountTable); + grid.add(jsp, 3).fill(true, true).expand(true, true); + grid.nextRow(); + btnAddBindMount = new JButton("Add Bind Mount"); + btnDelBindMount = new JButton("Remove Bind Mount"); + grid.add(Box.createHorizontalBox(), 1).fill(true, false).expand(true, false); + grid.add(btnAddBindMount); + grid.add(btnDelBindMount); + //grid.add(Box.createVerticalGlue(), 3).expand(true, true); txtInfoText = new JTextArea(); txtInfoText.setBorder(BorderFactory.createTitledBorder("Hinweis")); txtInfoText.setLineWrap(true); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/DockerfileUploadPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/DockerfileUploadPage.java index af025783..9e6e65ec 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/DockerfileUploadPage.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/DockerfileUploadPage.java @@ -6,8 +6,10 @@ import org.openslx.bwlp.thrift.iface.ImageDetailsRead; import org.openslx.dozmod.Config; import org.openslx.dozmod.gui.Gui; import org.openslx.dozmod.gui.helper.*; +import org.openslx.dozmod.gui.window.ContainerBindMountWindow; import org.openslx.dozmod.gui.wizard.Wizard; import org.openslx.dozmod.gui.wizard.layout.ContainerUploadPageLayout; +import org.openslx.dozmod.model.ContainerBindMount; import org.openslx.dozmod.model.ContainerDefinition; import org.openslx.dozmod.model.ContainerMeta; import org.openslx.dozmod.state.UploadWizardState; @@ -21,6 +23,8 @@ import javax.swing.event.ChangeListener; import javax.swing.filechooser.FileFilter; import java.awt.event.*; import java.io.*; +import java.util.ArrayList; +import java.util.List; public class DockerfileUploadPage extends ContainerUploadPageLayout { @@ -34,7 +38,6 @@ public class DockerfileUploadPage extends ContainerUploadPageLayout { private final UploadWizardState state; private final ImageDetailsRead existingImage; - public DockerfileUploadPage(Wizard wizard, final UploadWizardState state_) { super(wizard); @@ -106,10 +109,34 @@ public class DockerfileUploadPage extends ContainerUploadPageLayout { } }); + btnAddBindMount.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { + addBindMount(); + } + }); + btnDelBindMount.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { + btnDelBindMount(); + } + }); + btnBrowseForImage.requestFocus(); txtInfoText.setText("Many Text"); } + private void addBindMount() { + ContainerBindMountWindow.open(wizard, bindMountTable); + } + + private void btnDelBindMount() { + if (null == bindMountTable.getSelectedItem()) + return; + List<ContainerBindMount> data = new ArrayList<>(bindMountTable.getData()); + if (data.remove(bindMountTable.getSelectedItem())) + LOGGER.info("Bind Mount Entry Deleted"); + bindMountTable.setData(data, true); + } + private void browseFile() { QFileChooser fc = new QFileChooser(Config.getUploadPath(), false); @@ -165,8 +192,6 @@ public class DockerfileUploadPage extends ContainerUploadPageLayout { return zeroFile; } - - private void reactOnUserInput() { boolean completed = checkUserInput(); if (completed) @@ -211,6 +236,7 @@ public class DockerfileUploadPage extends ContainerUploadPageLayout { containerMeta.setBuildContextMethod(getBuildContextMethod().ordinal()); containerMeta.setImageName(txtImageName.getText()); containerMeta.setRunOptions(txtContainerRun.getText()); + containerMeta.setBindMountConfig(bindMountTable.getData()); switch (getBuildContextMethod()) { case FILE: cd = new ContainerDefinition(state.descriptionFile, containerMeta); @@ -265,7 +291,6 @@ public class DockerfileUploadPage extends ContainerUploadPageLayout { return true; } - private static class DockerfileFilter extends FileFilter { @Override public boolean accept(File f) { diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerBindMount.java b/dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerBindMount.java new file mode 100644 index 00000000..2bfb93f6 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerBindMount.java @@ -0,0 +1,51 @@ +package org.openslx.dozmod.model; + +import java.util.Objects; + +public class ContainerBindMount { + + private String source; + private String target; + private String options; + + public ContainerBindMount() { + } + + public String getSource() { + return source; + } + + public void setSource(String source) { + this.source = source; + } + + public String getTarget() { + return target; + } + + public void setTarget(String target) { + this.target = target; + } + + public String getOptions() { + return options; + } + + public void setOptions(String options) { + this.options = options; + } + + @Override public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + ContainerBindMount that = (ContainerBindMount) o; + return Objects.equals(source, that.source) && Objects.equals(target, that.target) && Objects.equals( + options, that.options); + } + + @Override public int hashCode() { + return Objects.hash(source, target, options); + } +} diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerMeta.java b/dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerMeta.java index 4522aab8..56bbf3c1 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerMeta.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerMeta.java @@ -2,6 +2,9 @@ package org.openslx.dozmod.model; import org.openslx.dozmod.gui.wizard.layout.ContainerUploadPageLayout; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; import java.util.Objects; /** @@ -14,9 +17,7 @@ public class ContainerMeta { private String build_context_url; private String image_name; private String run_options; - private Boolean mount_user_dir; - - private String user_mount_path; + private Collection<ContainerBindMount> bind_mount_config; public ContainerMeta() { @@ -24,11 +25,9 @@ public class ContainerMeta { build_context_url = ""; image_name = ""; run_options = ""; - mount_user_dir = false; - user_mount_path = ""; + bind_mount_config = new ArrayList<>(); } - public int getBuildContextMethod() { return build_context_method; } @@ -61,25 +60,15 @@ public class ContainerMeta { this.image_name = image_name; } - // TODO (Ralph) i dont like that naming - public Boolean mountUserDir() { - return mount_user_dir; - } - - public void mountUserDir(Boolean mountUserDir) { - this.mount_user_dir = mountUserDir; + public Collection<ContainerBindMount> getBindMountConfig() { + return bind_mount_config; } - public String getUserMountPath() { - return user_mount_path; + public void setBindMountConfig(List<ContainerBindMount> bindMountConfig) { + this.bind_mount_config = bindMountConfig; } - public void setUserMountPath(String userMountPath) { - user_mount_path = userMountPath; - } - - @Override - public boolean equals(Object o) { + @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) @@ -87,13 +76,10 @@ public class ContainerMeta { ContainerMeta that = (ContainerMeta) o; return Objects.equals(build_context_url, that.build_context_url) && Objects.equals(image_name, that.image_name) && Objects.equals(run_options, that.run_options) && Objects.equals( - mount_user_dir, that.mount_user_dir) && Objects.equals(user_mount_path, - that.user_mount_path); + bind_mount_config, that.bind_mount_config); } - @Override - public int hashCode() { - return Objects.hash(build_context_url, image_name, run_options, mount_user_dir, user_mount_path); + @Override public int hashCode() { + return Objects.hash(build_context_url, image_name, run_options); } - } |
