summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org
diff options
context:
space:
mode:
authorSimon Rettberg2018-06-14 16:18:42 +0200
committerSimon Rettberg2018-06-14 16:18:42 +0200
commitade450e19527dbf377d945ca7bae7a145cf44196 (patch)
treeaa6098a0a6b907fd39b3ca7591b9fe8670b08567 /dozentenmodul/src/main/java/org
parent[server] Don't wipe network shares if client didn't set field (diff)
downloadtutor-module-ade450e19527dbf377d945ca7bae7a145cf44196.tar.gz
tutor-module-ade450e19527dbf377d945ca7bae7a145cf44196.tar.xz
tutor-module-ade450e19527dbf377d945ca7bae7a145cf44196.zip
Add support for LDAP lecture filters
Diffstat (limited to 'dozentenmodul/src/main/java/org')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/LdapFilterConfigurator.java214
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/LectureLdapFilterTable.java24
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java17
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java20
4 files changed, 271 insertions, 4 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/LdapFilterConfigurator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/LdapFilterConfigurator.java
new file mode 100644
index 00000000..7028deb1
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/LdapFilterConfigurator.java
@@ -0,0 +1,214 @@
+package org.openslx.dozmod.gui.control;
+
+import java.awt.GridBagConstraints;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.BorderFactory;
+import javax.swing.JButton;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.event.ChangeListener;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+import javax.swing.event.TableModelEvent;
+import javax.swing.event.TableModelListener;
+
+import org.apache.log4j.Logger;
+import org.openslx.bwlp.thrift.iface.LdapFilter;
+import org.openslx.dozmod.gui.Gui;
+import org.openslx.dozmod.gui.control.table.LectureLdapFilterTable;
+import org.openslx.dozmod.gui.control.table.QScrollPane;
+import org.openslx.dozmod.gui.helper.GridManager;
+import org.openslx.dozmod.gui.helper.MessageType;
+
+/**
+ * Widget for network share configuration of lectures
+ */
+public class LdapFilterConfigurator extends LdapFilterConfiguratorLayout {
+
+ private static final long serialVersionUID = -3336605759245603655L;
+ private final static Logger LOGGER = Logger.getLogger(LdapFilterConfigurator.class);
+ private List<LdapFilter> filterList = null;
+
+ public LdapFilterConfigurator() {
+
+ super();
+
+ tblFilters.getModel().addTableModelListener(new TableModelListener() {
+ @Override
+ public void tableChanged(TableModelEvent e) {
+ fireChangeEvent();
+ }
+ });
+
+ tblFilters.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
+ @Override
+ public void valueChanged(ListSelectionEvent e) {
+ LdapFilter item = tblFilters.getSelectedItem();
+ if (item == null) {
+ clearInputFields();
+ return;
+ }
+ // share from the list is selected: fill bottom form and change "Add" to "Apply"
+ btnDel.setEnabled(true);
+ txtAttribute.setText(item.attribute);
+ txtValue.setText(item.value);
+ btnAdd.setText("Ändern");
+ }
+ });
+
+ btnAdd.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ // check if we are editing an existing share entry or
+ // creating a new one, check for input either way
+ LdapFilter input = new LdapFilter();
+
+ input.attribute = txtAttribute.getText();
+ if (input.attribute == null || input.attribute.isEmpty()) {
+ Gui.showMessageBox("Kein Attribut angegeben", MessageType.ERROR, null, null);
+ return;
+ }
+ input.value = txtValue.getText();
+ if (input.value == null) {
+ input.value = "";
+ }
+
+ // either we delete the existing share from the data or we are
+ // creating a new one, either way add it to the list and update
+ // the table, if its not present already
+ if (filterList.contains(input)) {
+ Gui.showMessageBox("Eintrag bereits vorhanden", MessageType.ERROR, null, null);
+ return;
+ }
+ // now decide whether to create a new entry or update existing one
+ LdapFilter oldEntry = tblFilters.getSelectedItem();
+ if (oldEntry != null) {
+ // editing existing one, delete it from the internal data
+ filterList.remove(oldEntry);
+ }
+ filterList.add(input);
+ tblFilters.getModel().setData(filterList);
+ clearInputFields();
+ }
+ });
+
+ btnDel.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ // try to delete the selected share
+ LdapFilter selection = tblFilters.getSelectedItem();
+ if (selection == null) {
+ return;
+ }
+ try {
+ if (!filterList.remove(selection)) {
+ // false if it was not found
+ LOGGER.error("Could not remove non-existent filter '" + selection.toString()
+ + "' from the table data: " + filterList.toString());
+ return;
+ }
+ // refresh table data
+ tblFilters.getModel().setData(filterList);
+ } catch (Exception ex) {
+ LOGGER.debug("Failed to remove " + selection.toString() + " from the table data.", ex);
+ return;
+ }
+ }
+ });
+ btnDel.setEnabled(false);
+ }
+
+ private void clearInputFields() {
+ btnDel.setEnabled(false);
+ txtAttribute.setText(null);
+ txtValue.setText(null);
+ btnAdd.setText("Hinzufügen");
+ }
+
+ public List<LdapFilter> getState() {
+ return filterList;
+ }
+
+ public boolean setState(List<LdapFilter> data) {
+ if (data == null)
+ return false;
+ if (filterList == null) {
+ filterList = new ArrayList<>();
+ }
+ filterList = data;
+ tblFilters.getModel().setData(filterList);
+ return true;
+ }
+
+ protected List<ChangeListener> listenerList = new ArrayList<>();
+
+ public void addLdapFilterListTableContentConfigurationChangeEventListener(ChangeListener listener) {
+ listenerList.add(listener);
+ }
+
+ public void removeNetshareConfigurationChangeEventListener(ChangeListener listener) {
+ listenerList.remove(listener);
+ }
+
+ void fireChangeEvent() {
+ for (ChangeListener listener : new ArrayList<>(listenerList)) {
+ listener.stateChanged(null);
+ }
+ }
+}
+
+/**
+ * Internal layout class for this widget
+ */
+class LdapFilterConfiguratorLayout extends JPanel {
+
+ private static final long serialVersionUID = 6479838641542743622L;
+
+ private final static String HELPTEXT = "Geben Sie hier LDAP Filter ein, die die Sichtbarkeit"
+ + " der Veranstaltung abhängig vom angemeldeten Benutzer einschränken. Eine Veranstaltung"
+ + " ist sichtbar, sobald einer der angegebenen Filter zutrifft. Zusätzliche Raumbeschränkungen"
+ + " greifen weiterhin.";
+
+ protected final LectureLdapFilterTable tblFilters = new LectureLdapFilterTable();
+ protected final JTextField txtAttribute, txtValue;
+ protected final JButton btnAdd, btnDel;
+
+ public LdapFilterConfiguratorLayout() {
+ GridManager grid = new GridManager(this, 1, true, new Insets(3, 3, 3, 3));
+ // top info panel
+ grid.add(new QLabel(HELPTEXT)).fill(true, false).expand(true, false);
+ grid.nextRow();
+ // middle filter list
+ grid.add(new QScrollPane(tblFilters)).fill(true, true).expand(true, true);
+ grid.nextRow();
+
+ btnDel = new JButton("Entfernen");
+ grid.add(btnDel).anchor(GridBagConstraints.EAST);
+ grid.nextRow();
+
+ JPanel pnlNewShare = new JPanel();
+ GridManager gridNewFilter = new GridManager(pnlNewShare, 2, true);
+ pnlNewShare.setBorder(BorderFactory.createTitledBorder("Filter definieren"));
+ gridNewFilter.add(new QLabel("Attribut"));
+ txtAttribute = new JTextField();
+ gridNewFilter.add(txtAttribute).fill(true, false).expand(true, false);
+ gridNewFilter.nextRow();
+ gridNewFilter.add(new QLabel("Wert"));
+ txtValue = new JTextField();
+ gridNewFilter.add(txtValue).fill(true, false).expand(true, false);
+ gridNewFilter.nextRow();
+ btnAdd = new JButton("Hinzufügen");
+ gridNewFilter.add(btnAdd, 2).anchor(GridBagConstraints.EAST);
+ gridNewFilter.nextRow();
+ gridNewFilter.finish(false);
+ grid.add(pnlNewShare).fill(true, false).expand(true, false);
+ grid.nextRow();
+ grid.finish(false);
+ }
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/LectureLdapFilterTable.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/LectureLdapFilterTable.java
new file mode 100644
index 00000000..ac5e8e0f
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/LectureLdapFilterTable.java
@@ -0,0 +1,24 @@
+package org.openslx.dozmod.gui.control.table;
+
+import org.openslx.bwlp.thrift.iface.LdapFilter;
+
+@SuppressWarnings("serial")
+public class LectureLdapFilterTable extends ListTable<LdapFilter> {
+
+ public static final ListTableColumn COL_ATTRIBUTE = new ListTableColumn("Attribut");
+ public static final ListTableColumn COL_VALUE = new ListTableColumn("Wert");
+
+ public LectureLdapFilterTable() {
+ super(COL_ATTRIBUTE, COL_VALUE);
+ }
+
+ @Override
+ protected Object getValueAtInternal(LdapFilter item, ListTableColumn columnIndex) {
+ if (columnIndex == COL_ATTRIBUTE)
+ return item.attribute;
+ if (columnIndex == COL_VALUE)
+ return item.value;
+ throw new IndexOutOfBoundsException();
+ }
+
+}
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 b7dce83a..4ae8af93 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
@@ -145,7 +145,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements
private String originalRunscript = null;
private List<NetShare> currentNetshares = null;
private List<NetShare> originalNetshares = null;
-
+
/**
* Constructor
*
@@ -331,6 +331,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements
dtpEndDate.addActionListener(actionListener);
spnStartTime.addChangeListener(changeListener);
spnEndTime.addChangeListener(changeListener);
+ ctlLdapFilterConfigurator.addLdapFilterListTableContentConfigurationChangeEventListener(changeListener);
// save default color of date/time stuff to reset the background later
dateTimeTextColor = dtpStartDate.getForeground();
@@ -431,6 +432,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements
// init advanced info
ctlRunscriptConfigurator.setState(lecture.runscript);
ctlNetshareConfigurator.setState(lecture.networkShares);
+ ctlLdapFilterConfigurator.setState(lecture.ldapFilters);
txtTitle.setText(lecture.getLectureName());
lblTitleInfo.setText(lecture.getLectureName());
@@ -640,7 +642,13 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements
}
// done with mandatory checks, remove error message
lblError.setText(null);
+
+
+ // TODO: Refactor change detection and error display so you don't lose your mind when
+ // trying to work with it.
+ return true;
+ /*
// check for changes in all fields
changed = !txtTitle.getText().equals(lecture.getLectureName())
|| !txtDescription.getText().equals(lecture.getDescription())
@@ -660,6 +668,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements
|| (currentNetshares != null && !currentNetshares.equals(originalNetshares))
|| imageLinkChanged;
return changed;
+ */
}
/**
@@ -669,10 +678,11 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements
private void saveChanges() {
boolean saved = saveChangesInternal();
callback.updated(saved);
- if (saved)
+ if (saved) {
dispose();
- else
+ } else {
btnSaveChanges.setEnabled(true);
+ }
}
/**
@@ -703,6 +713,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements
false, chkHasUsbAccess.isSelected());
metadata.setNetworkExceptions(currentNetrules);
metadata.setNetworkShares(currentNetshares);
+ metadata.setLdapFilters(ctlLdapFilterConfigurator.getState());
// now trigger the actual action
try {
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 57a82b6d..ab20567c 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
@@ -30,6 +30,7 @@ import org.openslx.bwlp.thrift.iface.ImageVersionDetails;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.control.ComboBox;
import org.openslx.dozmod.gui.control.ComboBox.ComboBoxRenderer;
+import org.openslx.dozmod.gui.control.LdapFilterConfigurator;
import org.openslx.dozmod.gui.control.LectureCustomPermissionManager;
import org.openslx.dozmod.gui.control.LocationSelector;
import org.openslx.dozmod.gui.control.NetshareConfigurator;
@@ -93,6 +94,7 @@ public abstract class LectureDetailsWindowLayout extends JDialog {
protected final LocationSelector ctlLocationSelector;
protected final RunscriptConfigurator ctlRunscriptConfigurator;
protected final NetshareConfigurator ctlNetshareConfigurator;
+ protected final LdapFilterConfigurator ctlLdapFilterConfigurator;
private static final Properties pickerStrings = new Properties();
@@ -104,7 +106,8 @@ public abstract class LectureDetailsWindowLayout extends JDialog {
protected JPanel pnlTabPermissions;
protected JPanel pnlTabLocations;
protected JPanel pnlTabRunscript;
- private JPanel pnlTabNetshare;
+ protected JPanel pnlTabNetshare;
+ protected JPanel pnlTabLdapFilter;
static {
pickerStrings.put("text.today", "Heute");
@@ -375,6 +378,18 @@ public abstract class LectureDetailsWindowLayout extends JDialog {
GridManager grdNetshare = new GridManager(pnlTabNetshare, 1, false, new Insets(8, 2, 8, 2));
grdNetshare.add(ctlNetshareConfigurator).fill(true, true).expand(true, true);
grdNetshare.finish(false);
+
+ /* *******************************************************************************
+ *
+ * Tab "LDAP-Filters"
+ *
+ ********************************************************************************/
+ ctlLdapFilterConfigurator = new LdapFilterConfigurator();
+ pnlTabLdapFilter = new JPanel();
+ GridManager grdLdap = new GridManager(pnlTabLdapFilter, 1, false, new Insets(8, 2, 8, 2));
+ grdLdap.add(ctlLdapFilterConfigurator).fill(true, true).expand(true, true);
+ grdLdap.finish(false);
+
/* *******************************************************************************
*
* Main panel containing the tabs
@@ -397,6 +412,9 @@ public abstract class LectureDetailsWindowLayout extends JDialog {
if (Session.hasFeature(Feature.NETWORK_SHARES)) {
pnlTabs.addTab("Netzlaufwerke", pnlTabNetshare);
}
+ if (Session.hasFeature(Feature.LECTURE_FILTER_LDAP)) {
+ pnlTabs.addTab("LDAP-Filter", pnlTabLdapFilter);
+ }
add(pnlTabs, BorderLayout.CENTER);
// usage counter + button panel on the bottom
JPanel buttonPanel = new JPanel();