diff options
author | Simon Rettberg | 2016-01-22 10:36:54 +0100 |
---|---|---|
committer | Simon Rettberg | 2016-01-22 10:36:54 +0100 |
commit | c728881ddcd978511dd317a74971fbacc329ee2a (patch) | |
tree | 93fd50c85aea4ea866b74f5289d96dfde43edee7 /dozentenmodul | |
parent | [client] Cleanup & formatting (diff) | |
download | tutor-module-c728881ddcd978511dd317a74971fbacc329ee2a.tar.gz tutor-module-c728881ddcd978511dd317a74971fbacc329ee2a.tar.xz tutor-module-c728881ddcd978511dd317a74971fbacc329ee2a.zip |
[client] Save locations selected in winzard; check location count; default to "prioritize"
Diffstat (limited to 'dozentenmodul')
3 files changed, 50 insertions, 12 deletions
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<TreePath> paths) { + public void setCheckedState(List<TreePath> 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<TreePath, CheckedNode> it : nodesCheckingState.entrySet()) { + TreePath path = it.getKey(); + CheckedNode cn = it.getValue(); + if (cn.hasChildren && cn.allChildrenSelected) { + collapsePath(path); + } + } + } private void resetCheckingState() { nodesCheckingState = new HashMap<TreePath, CheckedNode>(); 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<Location> 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<TreePath> 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<Integer> list) { if (list == null || list.isEmpty()) { LOGGER.error("No list given for preselection!"); return; } + // first, deselect everything + List<TreePath> 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<TreePath> selectedPathsList = new ArrayList<TreePath>(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<Integer> 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; } |