summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Bauer2015-12-18 16:57:26 +0100
committerJonathan Bauer2015-12-18 16:57:26 +0100
commitca397e4a2ca4b4983d6546ce6dfafcf8a4c55b56 (patch)
treeea03c8adc4cffb5e5a50932f209de03f62c73b94
parent[client] don't scroll the pane for the changelog to the bottom, always force ... (diff)
downloadtutor-module-ca397e4a2ca4b4983d6546ce6dfafcf8a4c55b56.tar.gz
tutor-module-ca397e4a2ca4b4983d6546ce6dfafcf8a4c55b56.tar.xz
tutor-module-ca397e4a2ca4b4983d6546ce6dfafcf8a4c55b56.zip
[client] room selection widget [wip]
new wizard page in the lecture wizard new button "Raumauswahl" LectureDetailsWindow
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/RoomSelector.java294
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java13
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/RoomSelectorWindow.java41
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java7
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/RoomSelectorWindowLayout.java37
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/LectureWizard.java8
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/LectureRoomSelectionPageLayout.java23
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureRoomSelectionPage.java57
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/state/LectureWizardState.java4
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/state/UploadWizardState.java6
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/MetaDataCache.java58
11 files changed, 543 insertions, 5 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/RoomSelector.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/RoomSelector.java
new file mode 100644
index 00000000..ae1afc5e
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/RoomSelector.java
@@ -0,0 +1,294 @@
+package org.openslx.dozmod.gui.control;
+
+import java.awt.Component;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+
+import javax.swing.DefaultListCellRenderer;
+import javax.swing.DefaultListModel;
+import javax.swing.JButton;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+
+import org.apache.log4j.Logger;
+import org.openslx.bwlp.thrift.iface.Location;
+import org.openslx.dozmod.gui.Gui;
+import org.openslx.dozmod.gui.helper.GridManager;
+import org.openslx.dozmod.thrift.cache.MetaDataCache;
+import org.openslx.util.QuickTimer;
+import org.openslx.util.QuickTimer.Task;
+
+public class RoomSelector extends QLabel {
+ private final static Logger LOGGER = Logger.getLogger(RoomSelector.class);
+
+ private DefaultListModel<Location> roomModel = new DefaultListModel<Location>();
+ private DefaultListModel<Location> selectedRoomModel = new DefaultListModel<Location>();
+
+ private JButton addAllButton = new JButton(">>");
+ private JButton addButton = new JButton(">");
+ private JButton removeButton = new JButton("<");
+ private JButton removeAllButton = new JButton("<<");
+
+ private boolean initDone = false;
+ private List<Integer> preselection;
+
+ public RoomSelector() {
+ GridManager grid = new GridManager(this, 3);
+ LocationRenderer locationRenderer = new LocationRenderer();
+
+ // the available list of rooms
+ final JList<Location> roomList = new JList<Location>();
+ roomList.setCellRenderer(locationRenderer);
+ roomList.setModel(roomModel);
+
+ // the selected list of rooms
+ final JList<Location> selectedRoomList = new JList<Location>();
+ selectedRoomList.setCellRenderer(locationRenderer);
+ selectedRoomList.setModel(selectedRoomModel);
+
+ // the listeners
+ selectedRoomList.addMouseListener(new MouseAdapter() {
+ public void mouseClicked(MouseEvent e) {
+ if (e.getClickCount() == 2) {
+ Location selection = selectedRoomList.getSelectedValue();
+ if (selection != null) {
+ // LOGGER.debug("Removing: " + selection);
+ if (selectedRoomModel.contains(selection)) {
+ selectedRoomModel.removeElement(selection);
+ if (!roomModel.contains(selection)) {
+ roomModel.addElement(selection);
+ }
+ sortLists();
+ }
+ }
+ }
+ }
+ });
+
+ roomList.addMouseListener(new MouseAdapter() {
+ public void mouseClicked(MouseEvent e) {
+ if (e.getClickCount() == 2) {
+ Location selection = roomList.getSelectedValue();
+ if (selection != null) {
+ // LOGGER.debug("Adding: " + selection);
+ if (!selectedRoomModel.contains(selection)) {
+ selectedRoomModel.addElement(selection);
+ roomModel.removeElement(selection);
+ }
+ sortLists();
+ }
+ }
+ }
+ });
+
+ addAllButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ moveAll(roomModel, selectedRoomModel);
+ }
+ });
+ addButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ addToSelection(roomList.getSelectedValuesList());
+
+ }
+ });
+ removeButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ removeFromSelection(selectedRoomList.getSelectedValuesList());
+
+ }
+ });
+ removeAllButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ moveAll(selectedRoomModel, roomModel);
+ }
+ });
+
+ grid.add(new QLabel("Verfügbare Räume"));
+ grid.skip();
+ grid.add(new QLabel("Ausgewählte Räume"));
+ grid.nextRow();
+ grid.add(new JScrollPane(roomList)).fill(true, true).expand(true, true);
+ // Vertical BoxLayout for buttons
+ JPanel buttonPanel = new JPanel();
+ GridManager buttonGrid = new GridManager(buttonPanel, 1);
+ buttonGrid.add(addAllButton).fill(true, false);
+ buttonGrid.nextRow();
+ buttonGrid.add(addButton).fill(true, false);
+ buttonGrid.nextRow();
+ buttonGrid.add(removeButton).fill(true, false);
+ buttonGrid.nextRow();
+ buttonGrid.add(removeAllButton).fill(true, false);
+ buttonGrid.nextRow();
+ buttonGrid.finish(true);
+ grid.add(buttonPanel).fill(false, false).expand(false, false);
+ grid.add(new JScrollPane(selectedRoomList)).fill(true, true)
+ .expand(true, true);
+ grid.nextRow();
+ grid.finish(true);
+
+ // initialise the data
+ init();
+ }
+
+ public void init() {
+ QuickTimer.scheduleOnce(new Task() {
+ List<Location> locsList = null;
+
+ @Override
+ public void fire() {
+ locsList = MetaDataCache.getLocations();
+ Gui.asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ initDone = fillRoomList(locsList);
+ // check if preselection was set before we were done initialising
+ if (initDone && preselection != null) {
+ setSelectionInternal(preselection);
+ }
+ }
+ });
+ }
+ });
+ }
+
+ public boolean fillRoomList(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) {
+ LOGGER.debug("Adding: " + loc.getLocationName());
+ roomModel.addElement(loc);
+ } else {
+ LOGGER.error("One location returned from the server was null");
+ }
+ }
+ return true;
+ }
+
+ private void moveAll(DefaultListModel<Location> from,
+ DefaultListModel<Location> to) {
+ for (Enumeration<Location> rooms = from.elements(); rooms
+ .hasMoreElements();) {
+ Location current = rooms.nextElement();
+ to.addElement(current);
+ }
+ from.clear();
+ sortLists();
+ }
+
+ // convenience
+ private void addToSelection(Location location) {
+ if (location == null) {
+ return;
+ }
+ List<Location> newLocations = new ArrayList<Location>();
+ newLocations.add(location);
+ addToSelection(newLocations);
+ }
+
+ private void addToSelection(List<Location> locations) {
+ if (locations == null)
+ return;
+ // LOGGER.debug("AddToSelection: " + locations);
+ for (Location location : locations) {
+ selectedRoomModel.addElement(location);
+ roomModel.removeElement(location);
+ }
+ sortLists();
+ }
+
+ private void removeFromSelection(List<Location> locations) {
+ if (locations == null)
+ return;
+ // LOGGER.debug("RemoveFromSelection: " + locations);
+ for (Location location : locations) {
+ selectedRoomModel.removeElement(location);
+ roomModel.addElement(location);
+ }
+ sortLists();
+ }
+
+ private void sortLists() {
+ // sort the available room list
+ List<Location> list = Collections.list(roomModel.elements());
+ Collections.sort(list);
+ roomModel.clear();
+ for (Location loc : list) {
+ roomModel.addElement(loc);
+ }
+ // sort the selected room list
+ list = Collections.list(selectedRoomModel.elements());
+ Collections.sort(list);
+ selectedRoomModel.clear();
+ for (Location loc : list) {
+ selectedRoomModel.addElement(loc);
+ }
+ }
+
+ public DefaultListModel<Location> getRoomModel() {
+ return roomModel;
+ }
+
+ public DefaultListModel<Location> getSelectedRoomModel() {
+ return selectedRoomModel;
+ }
+
+ public void setSelectedRoomsAsIds(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);
+ }
+ private void setSelectionInternal(List<Integer> list){
+ if (list == null || list.isEmpty()) {
+ LOGGER.error("No list given for preselection!");
+ return;
+ }
+ LOGGER.debug("Setting to: " + preselection);
+ moveAll(selectedRoomModel, roomModel);
+
+ for (Integer id : preselection) {
+ LOGGER.debug("Searching: " + id);
+ Location loc = MetaDataCache
+ .getLocationById(id);
+ LOGGER.debug("Found: " + loc);
+ if (loc != null) {
+ addToSelection(loc);
+ LOGGER.debug("Added: " + loc);
+ }
+ }
+ }
+}
+
+@SuppressWarnings("serial")
+class LocationRenderer extends DefaultListCellRenderer {
+ @Override
+ public Component getListCellRendererComponent(JList<? extends Object> list,
+ Object value, int index, boolean isSelected, boolean cellHasFocus) {
+ if (value instanceof Location) {
+ return super.getListCellRendererComponent(list,
+ ((Location) value).getLocationName(), index, isSelected,
+ cellHasFocus);
+ }
+ return super.getListCellRendererComponent(list, value, index,
+ isSelected, cellHasFocus);
+ }
+} \ No newline at end of file
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 46ff6c0f..5118ebcf 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
@@ -196,6 +196,15 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements
reactToChange();
}
});
+ btnRooms.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ List<Integer> roomList = new ArrayList<Integer>();
+ // TODO load the room list from the LectureSummary
+ List<Integer> newRoomList = RoomSelectorWindow.open(me, roomList);
+ // TODO check if something changed and if so save the change
+ }
+ });
btnSaveChanges.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@@ -468,7 +477,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());
+ lecture.getDefaultPermissions(), null);
// now trigger the actual action
try {
ThriftManager.getSatClient().updateLecture(Session.getSatelliteToken(),
@@ -585,7 +594,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements
lblError.setText("Ungültiger Zeitraum!");
return false;
}
-
+ // TODO check if rooms changed
// done with mandatory checks, remove error message
lblError.setText(null);
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/RoomSelectorWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/RoomSelectorWindow.java
new file mode 100644
index 00000000..00c74251
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/RoomSelectorWindow.java
@@ -0,0 +1,41 @@
+package org.openslx.dozmod.gui.window;
+
+import java.awt.Window;
+import java.util.ArrayList;
+import java.util.List;
+
+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.RoomSelectorWindowLayout;
+
+public class RoomSelectorWindow extends RoomSelectorWindowLayout implements UiFeedback {
+
+ public RoomSelectorWindow(Window modalParent, List<Integer> roomList) {
+ super(modalParent, roomList);
+ Gui.centerShellOverShell(modalParent, this);
+ }
+ public List<Integer> runAndReturn() {
+ setVisible(true);
+ return new ArrayList<Integer>();
+ }
+
+ public static List<Integer> open(final Window modalParent, final List<Integer> roomList) {
+ return Gui.syncExec(new GuiCallable<List<Integer>>() {
+ @Override
+ public List<Integer> run() {
+ return new RoomSelectorWindow(modalParent, roomList).runAndReturn();
+ }
+ });
+ }
+
+ @Override
+ public boolean wantConfirmQuit() {
+ return false;
+ }
+
+ @Override
+ public void escapePressed() {
+ dispose();
+ }
+}
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 b3aedb1c..388f3605 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
@@ -63,6 +63,7 @@ public abstract class LectureDetailsWindowLayout extends JDialog {
protected final QLabel lblUseCount;
protected final JButton btnPermissions;
+ protected final JButton btnRooms;
protected QLabel lblError;
protected final JButton btnSaveChanges;
@@ -237,9 +238,13 @@ public abstract class LectureDetailsWindowLayout extends JDialog {
grid.nextRow();
// button for the custom permissions
+ JPanel bottomButtonPanel = new JPanel();
btnPermissions = new JButton("Berechtigungen");
+ btnRooms = new JButton("Raumauswahl");
grid.skip();
- grid.add(btnPermissions);
+ bottomButtonPanel.add(btnPermissions);
+ bottomButtonPanel.add(btnRooms);
+ grid.add(bottomButtonPanel);
grid.skip();
grid.nextRow();
grid.finish(true);
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/RoomSelectorWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/RoomSelectorWindowLayout.java
new file mode 100644
index 00000000..e00d00a7
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/RoomSelectorWindowLayout.java
@@ -0,0 +1,37 @@
+package org.openslx.dozmod.gui.window.layout;
+
+import java.awt.Window;
+import java.util.List;
+
+import javax.swing.BorderFactory;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JSeparator;
+
+import org.openslx.dozmod.gui.Gui;
+import org.openslx.dozmod.gui.control.RoomSelector;
+import org.openslx.dozmod.gui.helper.GridManager;
+
+public class RoomSelectorWindowLayout extends JDialog {
+
+ protected RoomSelector roomSelector;
+
+ public RoomSelectorWindowLayout(Window modalParent, List<Integer> roomList) {
+ super(modalParent);
+
+ getRootPane().setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
+ GridManager grid = new GridManager(this, 1);
+ JLabel header = new JLabel("<html>Hier können Sie die Räume auswählen, in denen diese Veranstaltung sichtbar sein soll.<html>");
+ roomSelector = new RoomSelector();
+ roomSelector.setSelectedRoomsAsIds(roomList);
+ grid.add(header).fill(true, false).expand(true, false);
+ grid.nextRow();
+ grid.add(new JSeparator());
+ grid.nextRow();
+ grid.add(roomSelector).fill(true, true).expand(true, true);
+ grid.finish(false);
+ setPreferredSize(Gui.getScaledDimension(480, 350));
+ pack();
+ Gui.centerShellOverShell(modalParent, this);
+ }
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/LectureWizard.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/LectureWizard.java
index d8d63165..11797d2a 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/LectureWizard.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/LectureWizard.java
@@ -16,6 +16,7 @@ import org.openslx.dozmod.gui.wizard.page.LectureCreationPage;
import org.openslx.dozmod.gui.wizard.page.LectureCustomPermissionPage;
import org.openslx.dozmod.gui.wizard.page.LectureImageListPage;
import org.openslx.dozmod.gui.wizard.page.LectureOptionsPage;
+import org.openslx.dozmod.gui.wizard.page.LectureRoomSelectionPage;
import org.openslx.dozmod.state.LectureWizardState;
import org.openslx.dozmod.thrift.Session;
import org.openslx.dozmod.thrift.ThriftActions;
@@ -52,6 +53,7 @@ public class LectureWizard extends Wizard implements UiFeedback {
addPage(new LectureImageListPage(this, state));
addPage(new LectureOptionsPage(this, state));
addPage(new LectureCustomPermissionPage(this, state));
+ addPage(new LectureRoomSelectionPage(this, state));
}
@Override
@@ -126,12 +128,16 @@ public class LectureWizard extends Wizard implements UiFeedback {
LOGGER.error("No start date set in state!");
return false;
}
+ if (state.locations == null) {
+ LOGGER.error("No locations set in state!");
+ return false;
+ }
return true;
}
private LectureWrite lectureWriteFromState() {
return new LectureWrite(state.name, state.description, state.imageVersionId, state.autoUpdate,
state.isEnabled, state.start.getTime() / 1000L, state.end.getTime() / 1000L, null, null,
- state.isExam, state.internetAccess, state.defaultPermissions);
+ state.isExam, state.internetAccess, state.defaultPermissions, state.locations);
}
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/LectureRoomSelectionPageLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/LectureRoomSelectionPageLayout.java
new file mode 100644
index 00000000..b0c00ea7
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/LectureRoomSelectionPageLayout.java
@@ -0,0 +1,23 @@
+package org.openslx.dozmod.gui.wizard.layout;
+
+import org.apache.log4j.Logger;
+import org.openslx.dozmod.gui.control.RoomSelector;
+import org.openslx.dozmod.gui.helper.GridManager;
+import org.openslx.dozmod.gui.wizard.Wizard;
+import org.openslx.dozmod.gui.wizard.WizardPage;
+
+@SuppressWarnings("serial")
+public class LectureRoomSelectionPageLayout extends WizardPage {
+
+ private final static Logger LOGGER = Logger.getLogger(LectureRoomSelectionPageLayout.class);
+
+ protected RoomSelector roomSelector = new RoomSelector();
+
+ public LectureRoomSelectionPageLayout(Wizard wizard) {
+ super(wizard, "Raumauswahl");
+ setDescription("Bitte wählen Sie die Räume für diese Veranstaltung aus");
+ GridManager grid = new GridManager(this, 1);
+ grid.add(roomSelector).fill(true, true).expand(true, true);
+ grid.finish(false);
+ }
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureRoomSelectionPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureRoomSelectionPage.java
new file mode 100644
index 00000000..7ea2e46b
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureRoomSelectionPage.java
@@ -0,0 +1,57 @@
+package org.openslx.dozmod.gui.wizard.page;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.swing.DefaultListModel;
+
+import org.apache.log4j.Logger;
+import org.openslx.bwlp.thrift.iface.Location;
+import org.openslx.dozmod.gui.Gui;
+import org.openslx.dozmod.gui.wizard.Wizard;
+import org.openslx.dozmod.gui.wizard.layout.LectureRoomSelectionPageLayout;
+import org.openslx.dozmod.state.LectureWizardState;
+import org.openslx.dozmod.thrift.cache.MetaDataCache;
+import org.openslx.util.QuickTimer;
+import org.openslx.util.QuickTimer.Task;
+
+@SuppressWarnings("serial")
+public class LectureRoomSelectionPage extends LectureRoomSelectionPageLayout {
+
+ private final static Logger LOGGER = Logger.getLogger(LectureRoomSelectionPage.class);
+
+ private LectureWizardState state = null;
+
+ public LectureRoomSelectionPage(Wizard wizard, LectureWizardState state) {
+ super(wizard);
+ setPageComplete(true);
+ this.state = state;
+
+ }
+
+ @Override
+ protected boolean wantNextOrFinish() {
+ return updateState();
+ }
+
+ private boolean updateState() {
+ DefaultListModel<Location> selectedRoomModel = roomSelector.getSelectedRoomModel();
+ if (selectedRoomModel != null && selectedRoomModel.elements() != null) {
+ // prepare the final list
+ if (state.locations == null) {
+ state.locations = new ArrayList<Integer>();
+ } else {
+ state.locations.clear();
+ }
+ List<Location> selectedRoomList = Collections.list(selectedRoomModel.elements());
+ for (Location loc : selectedRoomList) {
+ state.locations.add(loc.getLocationId());
+ }
+ } else {
+ // allow empty room selection?
+ return false;
+ }
+ return true;
+ }
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/state/LectureWizardState.java b/dozentenmodul/src/main/java/org/openslx/dozmod/state/LectureWizardState.java
index 559a7bb3..54d462ac 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/state/LectureWizardState.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/state/LectureWizardState.java
@@ -1,10 +1,12 @@
package org.openslx.dozmod.state;
import java.util.Date;
+import java.util.List;
import java.util.Map;
import org.openslx.bwlp.thrift.iface.ImageSummaryRead;
import org.openslx.bwlp.thrift.iface.LecturePermissions;
+import org.openslx.bwlp.thrift.iface.Location;
import org.openslx.dozmod.thrift.Session;
public class LectureWizardState {
@@ -23,6 +25,8 @@ public class LectureWizardState {
public LecturePermissions defaultPermissions = Session.getSatelliteConfig().defaultLecturePermissions;
// explicit permissions per user as set by the creator
public Map<String, LecturePermissions> permissionMap = null;
+ // list of rooms for the lecture
+ public List<Integer> locations;
// -- thrift internal stuff --
public String uuid = null;
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/state/UploadWizardState.java b/dozentenmodul/src/main/java/org/openslx/dozmod/state/UploadWizardState.java
index 252cb190..46810096 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/state/UploadWizardState.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/state/UploadWizardState.java
@@ -1,6 +1,7 @@
package org.openslx.dozmod.state;
import java.io.File;
+import java.util.List;
import java.util.Map;
import org.openslx.bwlp.thrift.iface.ImagePermissions;
@@ -34,7 +35,10 @@ public class UploadWizardState {
public boolean isRestricted = true;
// flags an image as a template
public boolean isTemplate = false;
-
+ /**
+ * list of strings for tags
+ */
+ public List<String> tags = null;
// -- Objects returned by thrift calls --
// UUID given returned by the satellite after creating the image
public String uuid = null;
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/MetaDataCache.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/MetaDataCache.java
index 0e9f8ea4..6c3d2be5 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/MetaDataCache.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/MetaDataCache.java
@@ -1,9 +1,11 @@
package org.openslx.dozmod.thrift.cache;
+import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import org.apache.thrift.TException;
+import org.openslx.bwlp.thrift.iface.Location;
import org.openslx.bwlp.thrift.iface.OperatingSystem;
import org.openslx.bwlp.thrift.iface.Virtualizer;
import org.openslx.thrifthelper.ThriftManager;
@@ -44,6 +46,26 @@ public class MetaDataCache {
return ThriftManager.getMasterClient().getVirtualizers();
}
};
+
+ private static final GenericDataCache<List<Location>> locationCache = new GenericDataCache<List<Location>>(
+ CACHE_TIME_MS) {
+ @Override
+ protected List<Location> update() throws TException {
+ List<Location> testLocationList = new ArrayList<Location>();
+ testLocationList.add(new Location(1, "RZ - Raum 100"));
+ testLocationList.add(new Location(2, "RZ - Raum 101"));
+ testLocationList.add(new Location(3, "RZ - Raum 113"));
+ testLocationList.add(new Location(4, "RZ - Raum 114"));
+ return testLocationList;
+ // enable this code when the server call is implemented
+// try {
+// return ThriftManager.getSatClient().getLocations();
+// } catch (TException e) {
+// LOGGER.warn("Could not get location list from satellite, trying master for backup...", e);
+// }
+// return null; // HACK
+ }
+ };
/**
* Get all known/valid operating systems an image can be marked as.
@@ -117,4 +139,40 @@ public class MetaDataCache {
return null;
}
+ /**
+ * Get all known/valid locations a lecture can be assigned to.
+ *
+ * @return
+ */
+ public static List<Location> getLocations() {
+ return locationCache.get();
+ }
+
+ public static Location getLocationById(int id) {
+ return getLocationById(id, false);
+ }
+
+ public static Location getLocationById(int id, boolean forceCache) {
+ // First, try in "always cached" mode
+ List<Location> list = locationCache.get(CacheMode.FORCE_CACHED);
+ Location location = getLocationById(id, list);
+ if (location != null || forceCache)
+ return location;
+ // Try again with a potential refresh
+ List<Location> newList = locationCache.get(CacheMode.DEFAULT);
+ if (list == newList) // Returned list from cache as it was still recent enough
+ return null;
+ return getLocationById(id, newList);
+ }
+
+ private static Location getLocationById(int id, List<Location> list) {
+ if (list != null) {
+ for (Location loc : list) {
+ if (loc.getLocationId() == id)
+ return loc;
+ }
+ }
+ return null;
+ }
+
} \ No newline at end of file