diff options
author | ralph isenmann | 2020-10-26 17:33:30 +0100 |
---|---|---|
committer | ralph isenmann | 2020-10-26 17:33:30 +0100 |
commit | e190c59074b679a53c12338796f30c36772eec9d (patch) | |
tree | eb3524fed71f84c0b1325f93e5eb7f416b8bddd6 /dozentenmodul/src/main/java/org/openslx/dozmod/gui | |
parent | [client] refactoring (diff) | |
download | tutor-module-e190c59074b679a53c12338796f30c36772eec9d.tar.gz tutor-module-e190c59074b679a53c12338796f30c36772eec9d.tar.xz tutor-module-e190c59074b679a53c12338796f30c36772eec9d.zip |
[client] update ImageDetailsWindow for Container
- update the height for the ContainerRecipe Textarea and the ContainerBindMountConfig
- ContainerBindMount can now updatet in the ImageDetailsWindow
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui')
3 files changed, 117 insertions, 38 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/ContainerBindMountConfigurator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/ContainerBindMountConfigurator.java new file mode 100644 index 00000000..c337dc03 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/ContainerBindMountConfigurator.java @@ -0,0 +1,98 @@ +package org.openslx.dozmod.gui.configurator; + +import org.apache.log4j.Logger; +import org.openslx.dozmod.gui.Gui; +import org.openslx.dozmod.gui.changemonitor.GenericControlWindow; +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.window.ContainerBindMountWindow; +import org.openslx.dozmod.model.ContainerBindMount; + +import javax.swing.*; +import javax.swing.event.ChangeListener; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.List; + +public class ContainerBindMountConfigurator extends JPanel implements GenericControlWindow<List<ContainerBindMount>> { + private final Logger LOGGER = Logger.getLogger(ContainerBindMountConfigurator.class); + + private final ContainerBindMountTable bindMountTable; + + public ContainerBindMountConfigurator() { + super(); + + GridManager grid = new GridManager(this,3); + bindMountTable = new ContainerBindMountTable(); + QScrollPane scrollPaneTable = new QScrollPane(bindMountTable); + scrollPaneTable.setMinimumSize(Gui.getScaledDimension(0, 70)); + scrollPaneTable.setPreferredSize(Gui.getScaledDimension(0, 70)); + grid.add(scrollPaneTable, 3).fill(true, true).expand(true, true); + grid.nextRow(); + + JButton btnAddBindMount = new JButton("Add Bind Mount"); + JButton btnDelBindMount = new JButton("Remove Bind Mount"); + grid.add(Box.createHorizontalBox()).fill(true, false).expand(true, false); + grid.add(btnAddBindMount); + grid.add(btnDelBindMount); + grid.nextRow(); + grid.finish(true); + + btnAddBindMount.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { + addBindMount(); + } + }); + btnDelBindMount.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { + deleteBindMount(); + } + }); + } + + private void addBindMount() { + ContainerBindMountWindow.open(SwingUtilities.getWindowAncestor(this), bindMountTable); + fireUserChangeEvent(); + } + + private void deleteBindMount() { + 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); + fireUserChangeEvent(); + } + + public void setData(List<ContainerBindMount> bindMountConfig, boolean sort) { + bindMountTable.setData(bindMountConfig, sort); + } + + public List<ContainerBindMount> getData() { + return bindMountTable.getData(); + } + + + /* ################################ + For dialog change monitor + ################################### */ + + @Override public List<ContainerBindMount> getState() { + return bindMountTable.getData(); + } + + void fireUserChangeEvent() { + for (ChangeListener cl : listeners) { + cl.stateChanged(null); + } + } + + private final List<ChangeListener> listeners = new ArrayList<>(1); + + @Override public void addChangeListener(ChangeListener l) { + listeners.add(l); + } +} 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 e12506e1..8dd97bda 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 @@ -631,6 +631,7 @@ import org.openslx.util.Util; conDev.getContainerMeta().setImageName(txtContainerImageName.getText()); conDev.getContainerMeta().setRunOptions(txtContainerRun.getText()); + conDev.getContainerMeta().setBindMountConfig(bindMountConfigurator.getData()); if (!conDev.equals(containerDefinition)) { uploadContainerDef(image.versions.get(0).versionId, conDev.toByteBuffer()); @@ -825,7 +826,7 @@ import org.openslx.util.Util; txtContainerImageName.setText(containerMeta.getImageName()); txtContainerRun.setText(containerMeta.getRunOptions()); - bindMountTable.setData(containerMeta.getBindMountConfig(), true); + bindMountConfigurator.setData(containerMeta.getBindMountConfig(), true); changeMonitor.add(txtContainerRecipe). addConstraint(new TextNotEmptyConstraint("Empty Dockerfile not allowed!")); @@ -833,6 +834,7 @@ import org.openslx.util.Util; .addConstraint(new TextNotEmptyConstraint("Empty Name not allowed!")); changeMonitor.add(txtContainerRun) .addConstraint(new TextNotEmptyConstraint("No Container Run Options provided!")); + changeMonitor.add(bindMountConfigurator); } // fill share mode combo, if not already done 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 29d19778..73e981c8 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,24 +1,9 @@ package org.openslx.dozmod.gui.window.layout; -import java.awt.*; - -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JDialog; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTabbedPane; -import javax.swing.JTextArea; -import javax.swing.JTextField; - import org.openslx.bwlp.thrift.iface.OperatingSystem; import org.openslx.bwlp.thrift.iface.ShareMode; import org.openslx.dozmod.gui.Gui; +import org.openslx.dozmod.gui.configurator.ContainerBindMountConfigurator; import org.openslx.dozmod.gui.configurator.ImagePermissionConfigurator; import org.openslx.dozmod.gui.control.ComboBox; import org.openslx.dozmod.gui.control.ComboBox.ComboBoxRenderer; @@ -30,6 +15,9 @@ import org.openslx.dozmod.gui.control.table.QScrollPane; import org.openslx.dozmod.gui.helper.GridManager; import org.openslx.thrifthelper.Comparators; +import javax.swing.*; +import java.awt.*; + @SuppressWarnings("serial") public abstract class ImageDetailsWindowLayout extends JDialog { private static final int ICON_SIZE_Y = 24; @@ -41,9 +29,7 @@ import org.openslx.thrifthelper.Comparators; protected final JTextArea txtContainerRecipe; protected final JTextField txtContainerRun; protected final JTextField txtContainerImageName; - protected final ContainerBindMountTable bindMountTable; - protected final JButton btnAddBindMount; - protected final JButton btnDelBindMount; + protected ContainerBindMountConfigurator bindMountConfigurator; protected QLabel lblError; protected final PersonLabel lblOwner; @@ -283,39 +269,32 @@ import org.openslx.thrifthelper.Comparators; pnlTabContainer = new JPanel(); txtContainerRecipe = new JTextArea(); JScrollPane scrollableTextArea = new JScrollPane(txtContainerRecipe); + scrollableTextArea.setMinimumSize(Gui.getScaledDimension(0, 200)); + scrollableTextArea.setPreferredSize(Gui.getScaledDimension(0, 200)); JPanel pnlContainerMeta = new JPanel(); - GridManager grdContainerMeta = new GridManager(pnlContainerMeta, 3, false, new Insets(8, 2, 8, 2)); + GridManager grdContainerMeta = new GridManager(pnlContainerMeta, 3); 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).expand(true, false); grdContainerMeta.nextRow(); grdContainerMeta.add(new QLabel("Container Run Options")); txtContainerRun = new JTextField(); - grdContainerMeta.add(txtContainerRun, 2).fill(true, false); - grdContainerMeta.nextRow(); - - bindMountTable = new ContainerBindMountTable(); - QScrollPane scrollPaneTable = new QScrollPane(bindMountTable); - grdContainerMeta.add(scrollPaneTable, 3).fill(true, true).expand(true, true); + grdContainerMeta.add(txtContainerRun, 2).fill(true, false).expand(true, false); grdContainerMeta.nextRow(); - btnAddBindMount = new JButton("Add Bind Mount"); - btnDelBindMount = new JButton("Remove Bind Mount"); - grdContainerMeta.add(Box.createHorizontalBox(), 1).fill(true, false).expand(true, false); - grdContainerMeta.add(btnAddBindMount); - grdContainerMeta.add(btnDelBindMount); - grdContainerMeta.nextRow(); + bindMountConfigurator = new ContainerBindMountConfigurator(); + grdContainerMeta.add(bindMountConfigurator,3).fill(true,true).expand(true,true); grdContainerMeta.finish(true); - GridManager grdContainer = new GridManager(pnlTabContainer, 1, false, new Insets(8, 2, 8, 2)); + 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(Box.createVerticalGlue()).fill(true, true); - grdContainer.finish(false); + grdContainer.add(pnlContainerMeta, 1).fill(true, true).expand(true, true); + //grdContainer.add(Box.createVerticalGlue()).fill(true, true).expand(true,true); + grdContainer.finish(true); |