From 89bfd10b84af304926df839c370ae07abba37edd Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Thu, 4 Apr 2019 15:39:49 +0200 Subject: [client] netshare: fix username/password not disabled when predef share is selected --- .../gui/configurator/NetshareConfigurator.java | 29 ++++++++++++++-------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/NetshareConfigurator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/NetshareConfigurator.java index 27d9b5ab..77f2e381 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/NetshareConfigurator.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/NetshareConfigurator.java @@ -53,7 +53,7 @@ public class NetshareConfigurator extends NetshareConfiguratorLayout { public static final Character EMPTY_MARKER = '-'; public static final String PRINTER_MARKER = "PRINTER"; - // mount points / win drive letters - ideally, we would check whether the image is linux or windows based + // mount points / win drive letters - ideally, we would check whether the image is linux- or windows-based // and either show a drive selection list like this one, or a textfield for a user-defined mount point... private Character[] mountPoints = { EMPTY_MARKER, 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' }; @@ -64,9 +64,10 @@ public class NetshareConfigurator extends NetshareConfiguratorLayout { @Override public void valueChanged(ListSelectionEvent e) { NetShare item = tblNetshare.getSelectedItem2(); - // only activate form fields if netshare is not predefined + // activate form fields when nothing is selected (to add a new one) + // or when not predefined by the satellite boolean editable = (item == null || item.shareId == 0); - // now disable as needed + btnDel.setEnabled(editable); btnAdd.setEnabled(editable); tfSharePath.setEnabled(editable); @@ -77,20 +78,25 @@ public class NetshareConfigurator extends NetshareConfiguratorLayout { cboNetshareMountPoint.setEnabled(editable); chkIsPrinter.setEnabled(editable); chkShowPass.setEnabled(editable); + if (editable) + btnAdd.setText("Ändern"); + // clear the contents of the fields and return, if no share was selected. if (item == null) { clearInputFields(); return; } - // first set the fields to let any listener trigger + // some share was selected, fill in the details tfSharePath.setText(item.path); + cboNetshareAuth.setSelectedItem(item.auth); + tfUsername.setText(item.username); + tfPassword.setText(item.password); + if (item.displayname != null) tfShareName.setText( String.valueOf(EMPTY_MARKER).equals(item.displayname) ? "" : item.displayname); - tfUsername.setText(item.username); - tfPassword.setText(item.password); - cboNetshareAuth.setSelectedItem(item.auth); + if (item.mountpoint != null) { boolean isPrinter = item.mountpoint.equals(PRINTER_MARKER); chkIsPrinter.setSelected(isPrinter); @@ -99,8 +105,6 @@ public class NetshareConfigurator extends NetshareConfiguratorLayout { : Character.valueOf(item.mountpoint.charAt(0))); cboNetshareMountPoint.setEnabled(editable && !isPrinter); } - if (editable) - btnAdd.setText("Ändern"); } }); @@ -120,8 +124,11 @@ public class NetshareConfigurator extends NetshareConfiguratorLayout { @Override public void actionPerformed(ActionEvent e) { NetShareAuth selectedAuth = cboNetshareAuth.getItemAt(cboNetshareAuth.getSelectedIndex()); - boolean activate = selectedAuth != null && selectedAuth == NetShareAuth.OTHER_USER; - // username field is needed to either special or guest user + // check what kind of share is selected + NetShare item = tblNetshare.getSelectedItem2(); + boolean editable = (item == null || item.shareId == 0); + // only active if it is editable and a username and a password is required to access the share + boolean activate = editable && selectedAuth != null && selectedAuth == NetShareAuth.OTHER_USER; tfUsername.setEnabled(activate); tfPassword.setEnabled(activate); chkShowPass.setEnabled(activate); -- cgit v1.2.3-55-g7522