summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src
diff options
context:
space:
mode:
authorJonathan Bauer2015-08-11 15:36:45 +0200
committerJonathan Bauer2015-08-11 15:36:45 +0200
commit53f1e1b9eb6bf23525d88c28a63c52c143777fe5 (patch)
tree9f48f6bce1e45a4ceece48524b06aeb0aa24bbb6 /dozentenmodul/src
parent[client] added combo and filter to filter imagelist for editable and own images. (diff)
downloadtutor-module-53f1e1b9eb6bf23525d88c28a63c52c143777fe5.tar.gz
tutor-module-53f1e1b9eb6bf23525d88c28a63c52c143777fe5.tar.xz
tutor-module-53f1e1b9eb6bf23525d88c28a63c52c143777fe5.zip
[client] lecture wizard quasi complete
Diffstat (limited to 'dozentenmodul/src')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java2
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java35
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java6
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/LectureWizard.java84
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/LectureCreationPageLayout.java21
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCreationPage.java87
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCustomPermissionPage.java2
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/state/LectureWizardState.java16
8 files changed, 195 insertions, 58 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java
index 10c3e8fd..c5e124a2 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java
@@ -26,6 +26,7 @@ import org.openslx.dozmod.gui.helper.MessageType;
import org.openslx.dozmod.gui.helper.PopupMenu;
import org.openslx.dozmod.gui.helper.UiFeedback;
import org.openslx.dozmod.gui.window.layout.ImageDetailsWindowLayout;
+import org.openslx.dozmod.gui.wizard.LectureWizard;
import org.openslx.dozmod.permissions.ImagePerms;
import org.openslx.dozmod.thrift.MetaDataCache;
import org.openslx.dozmod.thrift.Session;
@@ -83,6 +84,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe
if (e.getSource().equals(popupItemNew)) {
// TODO new lecture wizard with this image preset
LOGGER.debug("New lecture clicked");
+ new LectureWizard(me, versionTable.getSelectedItem()).setVisible(true);
}
if (e.getSource().equals(popupItemDownload)) {
// TODO delete that image
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java
index 340b320d..0e000011 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java
@@ -8,6 +8,7 @@ import java.awt.event.MouseEvent;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import javax.swing.JFileChooser;
@@ -21,11 +22,12 @@ import javax.swing.event.DocumentListener;
import org.apache.log4j.Logger;
import org.apache.thrift.TException;
+import org.openslx.bwlp.thrift.iface.ImageDetailsRead;
import org.openslx.bwlp.thrift.iface.ImageSummaryRead;
+import org.openslx.bwlp.thrift.iface.ImageVersionDetails;
import org.openslx.bwlp.thrift.iface.TAuthorizationException;
import org.openslx.bwlp.thrift.iface.TNotFoundException;
import org.openslx.bwlp.thrift.iface.TransferInformation;
-import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.dozmod.filetransfer.DownloadTask;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.MainWindow;
@@ -34,6 +36,7 @@ import org.openslx.dozmod.gui.helper.MessageType;
import org.openslx.dozmod.gui.helper.PopupMenu;
import org.openslx.dozmod.gui.window.layout.ImageListWindowLayout;
import org.openslx.dozmod.gui.wizard.ImageWizard;
+import org.openslx.dozmod.gui.wizard.LectureWizard;
import org.openslx.dozmod.thrift.ImageCache;
import org.openslx.dozmod.thrift.Session;
import org.openslx.dozmod.thrift.UserCache;
@@ -82,6 +85,7 @@ public class ImageListWindow extends ImageListWindowLayout {
if (e.getSource().equals(popupItemNewLecture)) {
// TODO new lecture
LOGGER.debug("New lecture clicked");
+ startLectureWizard();
}
if (e.getSource().equals(popupItemDownload)) {
performImageDownload();
@@ -181,6 +185,14 @@ public class ImageListWindow extends ImageListWindowLayout {
}
});
+ newLectureButton.addActionListener(new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ startLectureWizard();
+
+ }
+ });
// return to mainMenu
backButton.addActionListener(new ActionListener() {
@Override
@@ -191,6 +203,27 @@ public class ImageListWindow extends ImageListWindowLayout {
}
+ private void startLectureWizard() {
+ // determine latest version of the selected image
+ final ImageSummaryRead image = getSelectedImage();
+ if (image == null) return;
+ ImageDetailsRead idr;
+ try {
+ idr = ThriftManager.getSatClient().getImageDetails(Session.getSatelliteToken(), image.getImageBaseId());
+ } catch (Exception e) {
+ LOGGER.debug("Failed to get image details read from image base id: ", e);
+ return;
+ }
+
+ Iterator<ImageVersionDetails> it = idr.getVersions().iterator();
+ ImageVersionDetails latest = it.next();
+ while (it.hasNext()) {
+ ImageVersionDetails current = it.next();
+ if (current.getCreateTime() > latest.getCreateTime())
+ latest = current;
+ }
+ new LectureWizard(SwingUtilities.getWindowAncestor(this), latest).setVisible(true);
+ }
private void refreshList(final boolean forceRefresh) {
QuickTimer.scheduleOnce(new Task() {
@Override
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java
index de024a30..2512d3ea 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java
@@ -18,6 +18,7 @@ import org.apache.log4j.Logger;
import org.openslx.bwlp.thrift.iface.LectureSummary;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.MainWindow;
+import org.openslx.dozmod.gui.helper.MessageType;
import org.openslx.dozmod.gui.window.layout.LectureListWindowLayout;
import org.openslx.dozmod.gui.wizard.LectureWizard;
import org.openslx.dozmod.thrift.LectureCache;
@@ -90,7 +91,10 @@ public class LectureListWindow extends LectureListWindowLayout {
newButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
- new LectureWizard(SwingUtilities.getWindowAncestor(me)).setVisible(true);
+ if (Gui.showMessageBox(me, "Um eine Veranstaltung zu erstellen, müssen Sie ein Image auswählen. Zur Imageauswahl wechseln?",
+ MessageType.QUESTION_YESNO, LOGGER, null)) {
+ MainWindow.showPage(ImageListWindow.class);
+ }
}
});
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 9cae3809..6189fa96 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
@@ -3,12 +3,21 @@ package org.openslx.dozmod.gui.wizard;
import java.awt.Window;
import org.apache.log4j.Logger;
+import org.apache.thrift.TException;
+import org.openslx.bwlp.thrift.iface.ImageVersionDetails;
+import org.openslx.bwlp.thrift.iface.ImageVersionWrite;
+import org.openslx.bwlp.thrift.iface.LecturePermissions;
+import org.openslx.bwlp.thrift.iface.LectureWrite;
import org.openslx.dozmod.gui.Gui;
+import org.openslx.dozmod.gui.MainWindow;
import org.openslx.dozmod.gui.helper.MessageType;
import org.openslx.dozmod.gui.helper.UiFeedback;
+import org.openslx.dozmod.gui.window.LectureListWindow;
import org.openslx.dozmod.gui.wizard.page.LectureCreationPage;
import org.openslx.dozmod.gui.wizard.page.LectureCustomPermissionPage;
import org.openslx.dozmod.state.LectureWizardState;
+import org.openslx.dozmod.thrift.Session;
+import org.openslx.thrifthelper.ThriftManager;
@SuppressWarnings("serial")
public class LectureWizard extends Wizard implements UiFeedback {
@@ -22,9 +31,16 @@ public class LectureWizard extends Wizard implements UiFeedback {
*
* @param editExistingLecture whether to create new or edit existing lecture
*/
- public LectureWizard(Window parent) {
+ public LectureWizard(Window parent, ImageVersionDetails image) {
super(parent);
+ // sanity check on the image
+ if (image == null) {
+ throw new NullPointerException("LectureWizard needs an ImageVersionDetails!");
+ }
+ this.state.image = image;
+
+
// create the shared object for all pages of the wizard
addPage(new LectureCreationPage(this, state));
addPage(new LectureCustomPermissionPage(this, state));
@@ -50,4 +66,70 @@ public class LectureWizard extends Wizard implements UiFeedback {
public void escapePressed() {
doCancel();
}
+ @Override
+ public boolean wantFinish() {
+ // since we only started the upload and created a "blank" image entry
+ // we can here do all the sanity checks on the fields of UploadWizardState
+ // and react accordingly.
+ return isStateValid();
+ }
+
+ @Override
+ public void performFinish() {
+ // TODO evaluate table state and create the map of permissions
+ // TODO run the actually request over external threaded class
+ if (state.uuid != null) {
+ // already got a uuid, this is bad as we were about to do it!
+ LOGGER.error("UUID for new lecture already present, something's bad...");
+ return;
+ }
+ // ok, lets create it
+ try {
+ // push to sat
+ state.uuid = ThriftManager.getSatClient().createLecture(Session.getSatelliteToken(), lectureWriteFromState());
+ } catch (Exception e) {
+ Gui.showMessageBox(this, "Fail to create lecture: ", MessageType.ERROR, LOGGER, e);
+ return;
+ }
+ if (Gui.showMessageBox(this, "Veranstaltung erstellt! Wollen Sie zur Übersicht wechseln?", MessageType.QUESTION_YESNO, LOGGER, null)) {
+ MainWindow.showPage(LectureListWindow.class);
+ }
+ }
+
+ private boolean isStateValid() {
+ // debug purposes
+ if (state.name == null || state.name.isEmpty()) {
+ LOGGER.error("No name set in state!");
+ return false;
+ }
+ if (state.description == null || state.description.isEmpty()) {
+ LOGGER.error("No description set in state!");
+ return false;
+ }
+ if (state.start == null) {
+ LOGGER.error("No start date set in state!");
+ return false;
+ }
+ if (state.end == null) {
+ LOGGER.error("No start date set in state!");
+ return false;
+ }
+ return true;
+ }
+
+ private LectureWrite lectureWriteFromState() {
+ return new LectureWrite(
+ state.name,
+ state.description,
+ state.image.getVersionId(),
+ state.autoUpdate,
+ state.isEnabled,
+ state.start.getTime() / 1000L,
+ state.end.getTime() / 1000L,
+ null,
+ null,
+ state.isExam,
+ state.internetAccess,
+ state.defaultPermissions);
+ }
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/LectureCreationPageLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/LectureCreationPageLayout.java
index 63cc92a8..4f917352 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/LectureCreationPageLayout.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/LectureCreationPageLayout.java
@@ -1,5 +1,6 @@
package org.openslx.dozmod.gui.wizard.layout;
+import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.util.Calendar;
import java.util.Date;
@@ -8,11 +9,13 @@ import java.util.Properties;
import javax.swing.Box;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
+import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SpinnerDateModel;
+import javax.swing.border.TitledBorder;
import javax.swing.text.DateFormatter;
import org.jdatepicker.impl.JDatePanelImpl;
@@ -35,6 +38,10 @@ public abstract class LectureCreationPageLayout extends WizardPage {
protected JCheckBox networkAccessCheck;
protected JCheckBox examCheck;
protected JCheckBox autoUpdate;
+ // permissions checks
+ protected JCheckBox editPermissionsCheck;
+ protected JCheckBox adminPermissionsCheck;
+ protected JCheckBox enabledCheck;
private static final Properties pickerStrings = new Properties();
@@ -53,7 +60,6 @@ public abstract class LectureCreationPageLayout extends WizardPage {
public LectureCreationPageLayout(Wizard wizard) {
super(wizard, "Eingabe Ihrer Daten");
setDescription("Geben Sie bitte einen aussagekräftigen Namen für die neue Veranstaltung ein");
-
setLayout(new GridBagLayout());
// helper index
@@ -102,7 +108,18 @@ public abstract class LectureCreationPageLayout extends WizardPage {
autoUpdate = new JCheckBox("Aktuellste Imageversion verwenden");
add(autoUpdate, GridPos.get(1, row++, 2, 1));
-
+ add(Box.createRigidArea(new Dimension(0, 20)));
+ // -- default permissions group --
+ JPanel permissionsGroup = new JPanel();
+ permissionsGroup.setBorder(new TitledBorder("Standardberechtigungen"));
+
+ editPermissionsCheck = new JCheckBox("Bearbeiten");
+ adminPermissionsCheck = new JCheckBox("Administrieren");
+ permissionsGroup.add(editPermissionsCheck);
+ permissionsGroup.add(adminPermissionsCheck);
+ add(permissionsGroup, GridPos.get(1, row++, 2, 1));
+ enabledCheck = new JCheckBox("Aktiviert");
+ add(enabledCheck, GridPos.get(1, row++, 2, 1));
add(Box.createVerticalGlue(), GridPos.get(0, row++, true, true));
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCreationPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCreationPage.java
index e9eeb3bf..0e1e7465 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCreationPage.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCreationPage.java
@@ -2,18 +2,18 @@ package org.openslx.dozmod.gui.wizard.page;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
+import javax.swing.JSpinner;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import org.apache.log4j.Logger;
+import org.jdatepicker.impl.JDatePickerImpl;
+import org.openslx.bwlp.thrift.iface.LecturePermissions;
import org.openslx.dozmod.gui.wizard.Wizard;
import org.openslx.dozmod.gui.wizard.layout.LectureCreationPageLayout;
import org.openslx.dozmod.state.LectureWizardState;
@@ -55,23 +55,25 @@ public class LectureCreationPage extends LectureCreationPageLayout {
descriptionText.getDocument().addDocumentListener(docListener);
// listeners for the date pickers
- ActionListener dateListener = new ActionListener() {
+ final ActionListener actionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
reactToUserInput();
}
};
// listeners for the time pickers
- ChangeListener timeListener = new ChangeListener() {
+ final ChangeListener changeListener = new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
reactToUserInput();
}
};
- startTime.addChangeListener(timeListener);
- endTime.addChangeListener(timeListener);
- startDate.addActionListener(dateListener);
- endDate.addActionListener(dateListener);
+ startTime.addChangeListener(changeListener);
+ endTime.addChangeListener(changeListener);
+ startDate.addActionListener(actionListener);
+ endDate.addActionListener(actionListener);
+ editPermissionsCheck.addActionListener(actionListener);
+ adminPermissionsCheck.addActionListener(actionListener);
}
/**
* Called by event listeners. This will set guidance message or error
@@ -93,9 +95,12 @@ public class LectureCreationPage extends LectureCreationPageLayout {
} else {
state.description = descriptionText.getText();
}
- Date now = new Date();
- Date start = getStartDate();
- Date end = getEndDate();
+ // TODO max <sat config> months checks
+ final Date now = new Date();
+ final Date start = getDateFrom(startDate, startTime);
+ final Date end = getDateFrom(endDate, endTime);
+ LOGGER.debug(start);
+ LOGGER.debug(end);
if (start.after(end)) {
setWarningMessage("Startzeit is nach Endzeit!");
setPageComplete(false);
@@ -108,56 +113,36 @@ public class LectureCreationPage extends LectureCreationPageLayout {
state.start = start;
state.end = end;
}
- setWarningMessage("Sie können jetzt fortfahren.");
+ // always save checkboxes if we get this far
+ state.autoUpdate = autoUpdate.isSelected();
+ state.isEnabled = enabledCheck.isSelected();
+ state.isExam = examCheck.isSelected();
+ state.internetAccess = networkAccessCheck.isSelected();
+ state.defaultPermissions = new LecturePermissions(editPermissionsCheck.isSelected(), adminPermissionsCheck.isSelected());
+ setWarningMessage("Clicken Sie auf 'Weiter' für Berechtigungen oder 'Fertigstellen'.");
setPageComplete(true);
}
/**
- * @return the Date object representing the user's input for the start date
+ * TODO
+ * @param datePicker
+ * @param timeSpinner
+ * @return
*/
- private Date getStartDate() {
+ private Date getDateFrom(JDatePickerImpl datePicker, JSpinner timeSpinner) {
// start date from the DatePicker
- int years = startDate.getModel().getYear();
- int months = startDate.getModel().getMonth() + 1;
- int days = startDate.getModel().getDay();
+ int years = datePicker.getModel().getYear();
+ int months = datePicker.getModel().getMonth();
+ int days = datePicker.getModel().getDay();
// start time from the Spinner
- Date starttime = (Date) startTime.getValue();
+ Date time = (Date) timeSpinner.getValue();
Calendar cal = Calendar.getInstance();
- cal.setTime(starttime);
+ cal.setTime(time);
int hours = cal.get(Calendar.HOUR_OF_DAY);
int minutes = cal.get(Calendar.MINUTE);
// build the time from the single values
- DateFormat format = new SimpleDateFormat("dd-MM-yyyy kk:mm");
- Date date = null;
- try {
- date = format.parse(days + "-" + months + "-" + years + " " + hours + ":" + minutes);
- } catch (ParseException e) {
- LOGGER.error("Parsing error while converting date: ", e);
- }
- return date;
- }
- /**
- * @return the Date object representing the user's input for the end date
- */
- private Date getEndDate() {
- // end date from the DatePicker
- int years = endDate.getModel().getYear();
- int months = endDate.getModel().getMonth() + 1;
- int days = endDate.getModel().getDay();
- // end time from the Spinner
- Date endtime = (Date) endTime.getValue();
- Calendar cal = Calendar.getInstance();
- cal.setTime(endtime);
- int hours = cal.get(Calendar.HOUR_OF_DAY);
- int minutes = cal.get(Calendar.MINUTE);
- // build the time from the single values
- DateFormat format = new SimpleDateFormat("dd-MM-yyyy kk:mm");
- Date date = null;
- try {
- date = format.parse(days + "-" + months + "-" + years + " " + hours + ":" + minutes);
- } catch (ParseException e) {
- LOGGER.error("Parsing error while converting date: ", e);
- }
+ cal.set(years, months, days, hours, minutes);
+ Date date = cal.getTime();
return date;
}
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCustomPermissionPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCustomPermissionPage.java
index d0c3da06..94bd8f72 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCustomPermissionPage.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCustomPermissionPage.java
@@ -76,5 +76,7 @@ public class LectureCustomPermissionPage extends LectureCustomPermissionPageLayo
permissionTableViewer.setData(permissionList, false);
}
});
+ // no requirements before finishing
+ setPageComplete(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 dd9039f7..c63fb041 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/state/LectureWizardState.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/state/LectureWizardState.java
@@ -1,15 +1,27 @@
package org.openslx.dozmod.state;
import java.util.Date;
+import java.util.Map;
+
+import org.openslx.bwlp.thrift.iface.ImageVersionDetails;
+import org.openslx.bwlp.thrift.iface.LecturePermissions;
public class LectureWizardState {
+ public ImageVersionDetails image = null;
public String name = null;
public String description = null;
- public String uuid = null;
public boolean autoUpdate = false;
public boolean isEnabled = false;
+ public boolean isExam = false;
+ public boolean internetAccess = false;
public Date start = null;
public Date end = null;
-
+ // default permissions assigned to that lecture by the user
+ // TODO: defaults per sat
+ public LecturePermissions defaultPermissions = null;
+ // explicit permissions per user as set by the creator
+ public Map<String, LecturePermissions> permissionList = null;
+ // -- thrift internal stuff --
+ public String uuid = null;
}