summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page
diff options
context:
space:
mode:
authorJonathan Bauer2015-08-11 13:03:26 +0200
committerJonathan Bauer2015-08-11 13:03:26 +0200
commit653ffc7439f14e9674ecdcf5375f7d09295523ed (patch)
treeea0f1338488ffebb2eb45b56c9399d44e7495a0c /dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page
parent[server] Overhaul permission checking, precalc user permissions, implement do... (diff)
downloadtutor-module-653ffc7439f14e9674ecdcf5375f7d09295523ed.tar.gz
tutor-module-653ffc7439f14e9674ecdcf5375f7d09295523ed.tar.xz
tutor-module-653ffc7439f14e9674ecdcf5375f7d09295523ed.zip
[client] lecture wizard stuff (state, removed old bool, added date/time parsing/listener stuff)
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCreationPage.java142
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCustomPermissionPage.java6
2 files changed, 146 insertions, 2 deletions
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 078e2ba7..e9eeb3bf 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
@@ -1,23 +1,163 @@
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.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+
import org.apache.log4j.Logger;
import org.openslx.dozmod.gui.wizard.Wizard;
import org.openslx.dozmod.gui.wizard.layout.LectureCreationPageLayout;
+import org.openslx.dozmod.state.LectureWizardState;
@SuppressWarnings("serial")
public class LectureCreationPage extends LectureCreationPageLayout {
private final static Logger LOGGER = Logger.getLogger(LectureCreationPage.class);
+ private LectureWizardState state = null;
+
/**
* Page for creating lectures
*
* @param editExistingLecture whether to edit existing lecture or create new
* one
*/
- public LectureCreationPage(Wizard wizard) {
+ public LectureCreationPage(Wizard wizard, LectureWizardState state) {
super(wizard);
+ this.state = state;
+
+ // listener for the text fields
+ final DocumentListener docListener = new DocumentListener() {
+ @Override
+ public void removeUpdate(DocumentEvent e) {
+ changedUpdate(e);
+ }
+ @Override
+ public void insertUpdate(DocumentEvent e) {
+ changedUpdate(e);
+ }
+ @Override
+ public void changedUpdate(DocumentEvent e) {
+ reactToUserInput();
+ }
+ };
+
+ lectureNameTextField.getDocument().addDocumentListener(docListener);
+ descriptionText.getDocument().addDocumentListener(docListener);
+
+ // listeners for the date pickers
+ ActionListener dateListener = new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ reactToUserInput();
+ }
+ };
+ // listeners for the time pickers
+ ChangeListener timeListener = new ChangeListener() {
+ @Override
+ public void stateChanged(ChangeEvent e) {
+ reactToUserInput();
+ }
+ };
+ startTime.addChangeListener(timeListener);
+ endTime.addChangeListener(timeListener);
+ startDate.addActionListener(dateListener);
+ endDate.addActionListener(dateListener);
+ }
+ /**
+ * Called by event listeners. This will set guidance message or error
+ * message and call setPageComplete(bool) accordingly.
+ * The state will be updated if the fields are valid.
+ */
+ private void reactToUserInput() {
+ if (lectureNameTextField.getText().isEmpty()) {
+ setWarningMessage("Geben Sie einen Veranstaltungsnamen ein.");
+ setPageComplete(false);
+ return;
+ } else {
+ state.name = lectureNameTextField.getText();
+ }
+ if (descriptionText.getText().isEmpty()) {
+ setWarningMessage("Fügen Sie eine Beschreibung hinzu.");
+ setPageComplete(false);
+ return;
+ } else {
+ state.description = descriptionText.getText();
+ }
+ Date now = new Date();
+ Date start = getStartDate();
+ Date end = getEndDate();
+ if (start.after(end)) {
+ setWarningMessage("Startzeit is nach Endzeit!");
+ setPageComplete(false);
+ return;
+ } else if (now.after(end)) {
+ setWarningMessage("Endzeit liegt in die Vergangenheit!");
+ setPageComplete(false);
+ return;
+ } else { // all good, save them both
+ state.start = start;
+ state.end = end;
+ }
+ setWarningMessage("Sie können jetzt fortfahren.");
setPageComplete(true);
}
+ /**
+ * @return the Date object representing the user's input for the start date
+ */
+ private Date getStartDate() {
+ // start date from the DatePicker
+ int years = startDate.getModel().getYear();
+ int months = startDate.getModel().getMonth() + 1;
+ int days = startDate.getModel().getDay();
+ // start time from the Spinner
+ Date starttime = (Date) startTime.getValue();
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(starttime);
+ 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);
+ }
+ 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 8e243864..d0c3da06 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
@@ -17,6 +17,7 @@ import org.openslx.dozmod.gui.window.UserListWindow;
import org.openslx.dozmod.gui.window.layout.UserListWindowLayout.UserAddedCallback;
import org.openslx.dozmod.gui.wizard.Wizard;
import org.openslx.dozmod.gui.wizard.layout.LectureCustomPermissionPageLayout;
+import org.openslx.dozmod.state.LectureWizardState;
import org.openslx.dozmod.state.UploadWizardState;
@SuppressWarnings("serial")
@@ -24,14 +25,17 @@ public class LectureCustomPermissionPage extends LectureCustomPermissionPageLayo
private final static Logger LOGGER = Logger.getLogger(LectureCustomPermissionPage.class);
+ private LectureWizardState state = null;
+
private final LectureCustomPermissionPage me = this;
private ArrayList<UserLecturePermissions> permissionList = new ArrayList<>();
/**
* Page for setting custom permissions of a lecture
*/
- public LectureCustomPermissionPage(Wizard wizard) {
+ public LectureCustomPermissionPage(Wizard wizard, LectureWizardState state) {
super(wizard);
+ this.state = state;
addUser.addActionListener(new ActionListener() {
@Override