From c728881ddcd978511dd317a74971fbacc329ee2a Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 22 Jan 2016 10:36:54 +0100 Subject: [client] Save locations selected in winzard; check location count; default to "prioritize" --- .../openslx/dozmod/gui/control/JCheckBoxTree.java | 15 ++++++++-- .../dozmod/gui/control/LocationSelector.java | 32 ++++++++++++++++------ .../wizard/page/LectureLocationSelectionPage.java | 15 +++++++++- 3 files changed, 50 insertions(+), 12 deletions(-) (limited to 'dozentenmodul/src/main/java') diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/JCheckBoxTree.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/JCheckBoxTree.java index 0936e584..7406ce69 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/JCheckBoxTree.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/JCheckBoxTree.java @@ -9,6 +9,7 @@ import java.util.EventObject; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map.Entry; import javax.swing.JCheckBox; import javax.swing.JPanel; @@ -98,12 +99,12 @@ public class JCheckBoxTree extends JTree { } } // Preselection stuff - public void setCheckedState(List paths) { + public void setCheckedState(List paths, boolean check) { if (paths == null) return; for (TreePath path : paths) { if (path != null) - checkSubTree(path, true); + checkSubTree(path, check); } } @@ -119,6 +120,16 @@ public class JCheckBoxTree extends JTree { CheckedNode cn = nodesCheckingState.get(path); return cn.isSelected && cn.hasChildren && !cn.allChildrenSelected; } + + public void collapseFullySelectedNodes() { + for (Entry it : nodesCheckingState.entrySet()) { + TreePath path = it.getKey(); + CheckedNode cn = it.getValue(); + if (cn.hasChildren && cn.allChildrenSelected) { + collapsePath(path); + } + } + } private void resetCheckingState() { nodesCheckingState = new HashMap(); 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 52fe9753..ec1865f0 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 @@ -72,9 +72,7 @@ public class LocationSelector extends JPanel { grid.add(locationTree, 3).fill(true, true).expand(true, true); grid.nextRow(); - // the radio buttons, default is to show the lecture exclusively in the - // selected locations - exclusivelyButton.setSelected(true); + prioritizedButton.setSelected(true); ButtonGroup group = new ButtonGroup(); group.add(exclusivelyButton); group.add(prioritizedButton); @@ -101,7 +99,7 @@ public class LocationSelector extends JPanel { /** * Async fetching of the list of the locations from the server */ - public void init() { + private void init() { QuickTimer.scheduleOnce(new Task() { List locsList = null; @@ -202,8 +200,9 @@ public class LocationSelector extends JPanel { } preselection = list; // if we are initialised, we need to explicitly set the selection - if (initDone) + if (initDone) { setSelectionInternal(preselection); + } } /** @@ -240,6 +239,10 @@ public class LocationSelector extends JPanel { Collections.sort(idList); return idList; } + + public void collapseFullySelectedNodes() { + locationTree.collapseFullySelectedNodes(); + } private List minify(final TreePath[] paths) { // transform the array of paths to a list of leaf nodes @@ -319,16 +322,26 @@ public class LocationSelector extends JPanel { * Internal helper to set the selection of the list of location * corresponding the the given list of ids * - * @param list - * of id's to set the selected locations to + * @param list ids to set the selected locations to */ private void setSelectionInternal(List list) { if (list == null || list.isEmpty()) { LOGGER.error("No list given for preselection!"); return; } + // first, deselect everything + List selectedPathsList = new ArrayList<>(Math.max(MetaDataCache.getLocations().size(), + list.size())); + for (Location location : MetaDataCache.getLocations()) { + DefaultMutableTreeNode current = locationNodesMap.get(location.locationId); + if (current == null) + continue; + TreePath path = new TreePath(current.getPath()); + selectedPathsList.add(path); + } + locationTree.setCheckedState(selectedPathsList, false); // get the paths in the tree of the given id list of nodes - List selectedPathsList = new ArrayList(list.size()); + selectedPathsList.clear(); for (Integer id : list) { DefaultMutableTreeNode current = locationNodesMap.get(id); if (current == null) @@ -336,7 +349,8 @@ public class LocationSelector extends JPanel { TreePath path = new TreePath(current.getPath()); selectedPathsList.add(path); } - locationTree.setCheckedState(selectedPathsList); + locationTree.setCheckedState(selectedPathsList, true); + locationTree.repaint(); } } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureLocationSelectionPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureLocationSelectionPage.java index f8f10d27..7d25eb59 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureLocationSelectionPage.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureLocationSelectionPage.java @@ -1,9 +1,12 @@ package org.openslx.dozmod.gui.wizard.page; +import java.util.List; + import org.apache.log4j.Logger; import org.openslx.dozmod.gui.wizard.Wizard; import org.openslx.dozmod.gui.wizard.layout.LectureLocationSelectionPageLayout; import org.openslx.dozmod.state.LectureWizardState; +import org.openslx.dozmod.thrift.Session; @SuppressWarnings("serial") public class LectureLocationSelectionPage extends LectureLocationSelectionPageLayout { @@ -24,7 +27,17 @@ public class LectureLocationSelectionPage extends LectureLocationSelectionPageLa } private boolean updateState() { - // TODO + List locations = locationSelector.getSelectedLocationsAsIds(); + boolean locationExclusive = locationSelector.getOnlyInSelection(); + if (locations.size() > Session.getSatelliteConfig().maxLocationsPerLecture) { + setErrorMessage("Zu viele Räume/Orte ausgewählt"); + locationSelector.setSelectedLocationsAsIds(locations); + locationSelector.collapseFullySelectedNodes(); + return false; + } + state.locations = locations; + state.onlyInSelectedLocations = locationExclusive; + setErrorMessage(null); return true; } -- cgit v1.2.3-55-g7522