diff options
4 files changed, 182 insertions, 110 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/LocationSelector.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/LocationSelector.java index d5da8e60..cf2553e1 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/LocationSelector.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/LocationSelector.java @@ -15,6 +15,7 @@ import javax.swing.ButtonGroup; import javax.swing.DefaultListCellRenderer; import javax.swing.DefaultListModel; import javax.swing.JButton; +import javax.swing.JCheckBox; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JRadioButton; @@ -52,6 +53,7 @@ public class LocationSelector extends JPanel { private JButton removeAllButton = new JButton("<<"); private JRadioButton exclusivelyButton = new JRadioButton("Veranstaltung ausschließlich in den ausgewählten Räumen anzeigen"); private JRadioButton prioritizedButton = new JRadioButton("Veranstaltung mit höherer Priorität in den ausgewählten Räumen anzeigen"); +// private JCheckBox limitToAllowedUsers = new JCheckBox("Nur für die ausgewählten Benutzern anzeigen", false); /** * Flag for the initialization state @@ -64,74 +66,6 @@ public class LocationSelector extends JPanel { private List<Integer> preselection; /** - * Getter for the available location model - * - * @return the locationModel of the "available location" list - */ - public DefaultListModel<Location> getLocationModel() { - return availableLocationModel; - } - - /** - * Getter for the selected location model - * - * @return the locationModel of the "selected location" list - */ - public DefaultListModel<Location> getSelectedLocationModel() { - return selectedLocationModel; - } - - /** - * Getter for the "show only in selection" checkbox - * - * @return true if checked, false otherwise - */ - public boolean getOnlyInSelection() { - return exclusivelyButton.isSelected(); - } - - /** - * Sets the selection to the locations corresponding to the given list of - * id's - * - * @param list - * of integers to set the locations to - */ - public void setSelectedLocationsAsIds(List<Integer> list) { - if (list == null) { - LOGGER.error("No list given!"); - return; - } - preselection = list; - // if we are initialised, we need to explicitly set the selection - if (initDone) - setSelectionInternal(preselection); - } - - /** - * Sets the list of available locations. Should be called with the list - * given by the server - * - * @param list - * of locations to set the available list to - * @return true if setting the list worked, false otherwise - */ - public boolean fillLocationsList(final List<Location> locations) { - if (locations == null) { - LOGGER.error("No locations returned from the metadata cache."); - return false; - } - for (Location loc : locations) { - if (loc != null) { - availableLocationModel.addElement(loc); - } else { - LOGGER.error("A location returned from the server was null"); - } - } - return true; - } - - /** * Constructor. Initializes the grid layout, the location lists and * initializes the data */ @@ -251,6 +185,8 @@ public class LocationSelector extends JPanel { radioPanel.add(exclusivelyButton); radioPanel.add(prioritizedButton); grid.add(radioPanel, 3); + grid.nextRow(); +// grid.add(limitToAllowedUsers, 3); grid.finish(true); // initialise the data @@ -283,6 +219,105 @@ public class LocationSelector extends JPanel { } /** + * Getter for the available location model + * + * @return the locationModel of the "available location" list + */ + public DefaultListModel<Location> getLocationModel() { + return availableLocationModel; + } + + /** + * Getter for the selected location model + * + * @return the locationModel of the "selected location" list + */ + public DefaultListModel<Location> getSelectedLocationModel() { + return selectedLocationModel; + } + + /** + * Setter for the "show only in selection" checkbox + * + * @param true to enable the "limited" radio button, false to enable the other + */ + public void setOnlyInSelection(boolean limited) { + exclusivelyButton.setSelected(limited); + } + /** + * Getter for the "show only in selection" checkbox + * + * @return true if checked, false otherwise + */ + public boolean getOnlyInSelection() { + return exclusivelyButton.isSelected(); + } + + /** + * Sets the selection to the locations corresponding to the given list of + * id's + * + * @param list + * of integers to set the locations to + */ + public void setSelectedLocationsAsIds(List<Integer> list) { + if (list == null) { + LOGGER.error("No list given!"); + return; + } + preselection = list; + // if we are initialised, we need to explicitly set the selection + if (initDone) + setSelectionInternal(preselection); + } + + /** + * Gets the selected locations as a list of id's + * + * @return list of ids of the selection as Integer, empty list if the selection is empty + */ + public List<Integer> getSelectedLocationsAsIds() { + if (selectedLocationModel == null || selectedLocationModel.getSize() == 0) + return null; + + // prepare integer list to be returned + List<Integer> idList = new ArrayList<Integer>(selectedLocationModel.getSize()); + // iterate over the selected location model + Enumeration<Location> selection = selectedLocationModel.elements(); + while (selection.hasMoreElements()) { + Location current = selection.nextElement(); + if (current == null) + continue; + idList.add(current.getLocationId()); + } + Collections.sort(idList); + return idList; + } + + /** + * Sets the list of available locations. Should be called with the list + * given by the server + * + * @param list + * of locations to set the available list to + * @return true if setting the list worked, false otherwise + */ + public boolean fillLocationsList(final List<Location> locations) { + if (locations == null) { + LOGGER.error("No locations returned from the metadata cache."); + return false; + } + for (Location loc : locations) { + if (loc != null) { + availableLocationModel.addElement(loc); + } else { + LOGGER.error("A location returned from the server was null"); + } + } + return true; + } + + /** * Moves all elements from the available to the selected list * * @param model @@ -391,6 +426,10 @@ public class LocationSelector extends JPanel { } } } + + public List<Integer> getPreselection() { + return preselection; + } } @SuppressWarnings("serial") 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 21f41d15..ad5deb0c 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 @@ -107,7 +107,9 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements private boolean metadataChanged = false; - private boolean permissionsChanged; + private boolean permissionsChanged = false; + + private LocationInfo locationInfo = null; /** * Constructor @@ -199,10 +201,13 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements btnLocations.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - List<Integer> locationsList = new ArrayList<Integer>(); - // TODO load the location list from the LectureSummary - List<Integer> newLocationsList = LocationSelectionWindow.open(me, locationsList); - // TODO check if something changed and if so save the change + locationInfo = LocationSelectionWindow.open(me, lecture.locationIds, lecture.limitToLocations); + if (locationInfo == null) { + // nothing changed + return; + } + LOGGER.debug("New location info: " + locationInfo); + reactToChange(); } }); btnSaveChanges.addActionListener(new ActionListener() { @@ -320,6 +325,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements originalCustomPermissions.put(entry.getKey(), new LecturePermissions(entry.getValue())); } } + txtTitle.setText(lecture.getLectureName()); txtDescription.setText(lecture.getDescription()); lblOwner.setUser(UserCache.find(lecture.getOwnerId())); @@ -477,7 +483,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements DateTimeHelper.getDateFrom(startDate, startTime).getTime() / 1000L, DateTimeHelper.getDateFrom(endDate, endTime).getTime() / 1000L, null, null, chkIsExam.isSelected(), chkHasInternetAccess.isSelected(), - lecture.getDefaultPermissions(), null, false, false); // TODO: Location related + lecture.getDefaultPermissions(), locationInfo.locationList, locationInfo.limitToLocations, false); // TODO: Location related // now trigger the actual action try { ThriftManager.getSatClient().updateLecture(Session.getSatelliteToken(), @@ -594,7 +600,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements lblError.setText("Ungültiger Zeitraum!"); return false; } - // TODO check if locations changed + // done with mandatory checks, remove error message lblError.setText(null); @@ -608,7 +614,10 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements || chkIsExam.isSelected() != lecture.isExam || chkHasInternetAccess.isSelected() != lecture.hasInternetAccess || chkIsActive.isSelected() != lecture.isEnabled - || !lecture.defaultPermissions.equals(originalDefaultPermissions) || imageLinkChanged; + || !lecture.defaultPermissions.equals(originalDefaultPermissions) + || (lecture.locationIds != null && !lecture.locationIds.equals(locationInfo.locationList)) + || (locationInfo != null && lecture.limitToLocations != locationInfo.limitToLocations) + || imageLinkChanged; return changed; } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LocationSelectionWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LocationSelectionWindow.java index b7807cd5..adc48cda 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LocationSelectionWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LocationSelectionWindow.java @@ -3,75 +3,91 @@ package org.openslx.dozmod.gui.window; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.util.ArrayList; import java.util.List; +import org.apache.log4j.Logger; import org.openslx.dozmod.gui.Gui; import org.openslx.dozmod.gui.Gui.GuiCallable; import org.openslx.dozmod.gui.helper.UiFeedback; import org.openslx.dozmod.gui.window.layout.LocationSelectionWindowLayout; /** - * Minimal window containing a LocationSelector widget + * Minimal window containing a LocationSelector widget * * @author Jonathan Bauer - * + * */ -public class LocationSelectionWindow extends LocationSelectionWindowLayout implements UiFeedback { +public class LocationSelectionWindow extends LocationSelectionWindowLayout + implements UiFeedback { + + private static final Logger LOGGER = Logger + .getLogger(LocationSelectionWindow.class); + private boolean apply = false; /** - * @param modalParent parent to this window - * @param list of locations to preselect in the LocationSelector + * @param modalParent + * parent to this window + * @param list + * of locations to preselect in the LocationSelector */ - public LocationSelectionWindow(Window modalParent, List<Integer> locations) { - super(modalParent, locations); + public LocationSelectionWindow(Window modalParent, List<Integer> locations, boolean limitToLocations) { + super(modalParent, locations, limitToLocations); + + locationSelector.setSelectedLocationsAsIds(locations); + locationSelector.setOnlyInSelection(limitToLocations); // listeners for the buttons btnClose.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - safeClose(); + // TODO safe close? (unsaved changes -> user must confirm) + dispose(); } }); // disable "Save" button at first since nothing changed - btnSaveChanges.setEnabled(false); + btnSaveChanges.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + apply = true; + dispose(); + } + }); + // btnSaveChanges.setEnabled(false); Gui.centerShellOverShell(modalParent, this); } /** - * @return list of ids of the selected locations + * @return list of ids of the selected locations. Will be either a new list + * if the user clicked apply or the list received from the sat. */ - public List<Integer> runAndReturn() { + public LocationInfo runAndReturn() { setVisible(true); - return new ArrayList<Integer>(); + if (!apply) + return null; + return new LocationInfo(locationSelector.getSelectedLocationsAsIds(), locationSelector.getOnlyInSelection()); } /** * Static method to open this window with * - * @param modalParent parent to this window - * @param locations locations to preselect in the LocationSelector - * @return forwards the return value of the window itself: list of ids of the selected locations + * @param modalParent + * parent to this window + * @param locations + * locations to preselect in the LocationSelector + * @return forwards the return value of the window itself: list of ids of + * the selected locations */ - public static List<Integer> open(final Window modalParent, final List<Integer> locations) { - return Gui.syncExec(new GuiCallable<List<Integer>>() { + public static LocationInfo open(final Window modalParent, + final List<Integer> locations, final boolean limitToLocations) { + return Gui.syncExec(new GuiCallable<LocationInfo>() { @Override - public List<Integer> run() { - return new LocationSelectionWindow(modalParent, locations).runAndReturn(); + public LocationInfo run() { + return new LocationSelectionWindow(modalParent, locations, limitToLocations) + .runAndReturn(); } }); } - /** - * Helper called during the closing of this window to check. - * Checks for unsaved changes and ask for confirmation to quit if any are - * detected. - */ - private void safeClose() { - // TODO check for changes and ask for confirmation if there are any - dispose(); - } - @Override public boolean wantConfirmQuit() { return false; @@ -82,3 +98,12 @@ public class LocationSelectionWindow extends LocationSelectionWindowLayout imple dispose(); } } + +class LocationInfo { + public List<Integer> locationList; + public boolean limitToLocations; + public LocationInfo(List<Integer> locs, boolean limited) { + this.locationList = locs; + this.limitToLocations = limited; + } +} diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LocationSelectionWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LocationSelectionWindowLayout.java index 60e1e8c4..47ac1691 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LocationSelectionWindowLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LocationSelectionWindowLayout.java @@ -24,7 +24,7 @@ public class LocationSelectionWindowLayout extends JDialog { protected JButton btnClose; public LocationSelectionWindowLayout(Window modalParent, - List<Integer> locationList) { + List<Integer> locationList, boolean limitToLocations) { super(modalParent, modalParent != null ? ModalityType.APPLICATION_MODAL : ModalityType.MODELESS); @@ -34,7 +34,6 @@ public class LocationSelectionWindowLayout extends JDialog { WordWrapLabel header = new WordWrapLabel( "Hier können Sie die Räume auswählen, in denen diese Veranstaltung sichtbar sein soll."); locationSelector = new LocationSelector(); - locationSelector.setSelectedLocationsAsIds(locationList); grid.add(header).fill(true, false).expand(true, false); grid.nextRow(); grid.add(new JSeparator()); @@ -44,8 +43,8 @@ public class LocationSelectionWindowLayout extends JDialog { // button panel on the bottom JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); - btnClose = new JButton("Schließen"); - btnSaveChanges = new JButton("Speichern"); + btnClose = new JButton("Abbrechen"); + btnSaveChanges = new JButton("Übernehmen"); buttonPanel.add(Box.createHorizontalGlue()); buttonPanel.add(btnClose); buttonPanel.add(btnSaveChanges); |
