package org.openslx.dozmod.gui.window; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.List; import org.openslx.dozmod.gui.Gui; import org.openslx.dozmod.gui.Gui.GuiCallable; import org.openslx.dozmod.gui.control.JCheckBoxTree.CheckChangeEvent; import org.openslx.dozmod.gui.control.JCheckBoxTree.CheckChangeEventListener; import org.openslx.dozmod.gui.helper.MessageType; import org.openslx.dozmod.gui.helper.UiFeedback; import org.openslx.dozmod.gui.window.layout.LocationSelectionWindowLayout; import org.openslx.dozmod.thrift.Session; /** * Minimal window containing a LocationSelector widget * * @author Jonathan Bauer * */ public class LocationSelectionWindow extends LocationSelectionWindowLayout implements UiFeedback { /** * */ private static final long serialVersionUID = -5898656786160024212L; private boolean apply = false; /** * @param modalParent * parent to this window * @param list * of locations to preselect in the LocationSelector */ public LocationSelectionWindow(Window modalParent, List locations, boolean limitToLocations) { super(modalParent, locations, limitToLocations); ctlLocationSelector.setSelectedLocationsAsIds(locations); ctlLocationSelector.setOnlyInSelection(limitToLocations); // listeners for the buttons btnClose.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO safe close? (unsaved changes -> user must confirm) dispose(); } }); // disable "Save" button at first since nothing changed btnSaveChanges.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { List tempIntList = ctlLocationSelector.getSelectedLocationsAsIds(); if (tempIntList != null && tempIntList.size() > Session.getSatelliteConfig().maxLocationsPerLecture) { ctlLocationSelector.setSelectedLocationsAsIds(tempIntList); Gui.showMessageBox("Bitten reduzieren Sie die Anzahl gewählter Orte", MessageType.WARNING, null, null); return; } apply = true; dispose(); } }); // addCheckChangeEventListener ctlLocationSelector.addCheckChangeEventListener(new CheckChangeEventListener() { @Override public void checkStateChanged(CheckChangeEvent event) { List tempIntList = ctlLocationSelector.getSelectedLocationsAsIds(); if (tempIntList != null) { if (tempIntList.size() > Session.getSatelliteConfig().maxLocationsPerLecture) { // add error lblError.setText("Zu viele Orte ausgewählt!"); } else { lblError.setText(""); } } } }); Gui.centerShellOverShell(modalParent, this); } /** * @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 LocationInfo runAndReturn() { setVisible(true); if (!apply) return null; return new LocationInfo(ctlLocationSelector.getSelectedLocationsAsIds(), ctlLocationSelector.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 */ public static LocationInfo open(final Window modalParent, final List locations, final boolean limitToLocations) { return Gui.syncExec(new GuiCallable() { @Override public LocationInfo run() { return new LocationSelectionWindow(modalParent, locations, limitToLocations).runAndReturn(); } }); } @Override public boolean wantConfirmQuit() { return false; } @Override public void escapePressed() { dispose(); } } class LocationInfo { public List locationList; public boolean limitToLocations; public LocationInfo(List locs, boolean limited) { this.locationList = locs; this.limitToLocations = limited; } }