diff options
author | Jonathan Bauer | 2015-08-11 13:03:26 +0200 |
---|---|---|
committer | Jonathan Bauer | 2015-08-11 13:03:26 +0200 |
commit | 653ffc7439f14e9674ecdcf5375f7d09295523ed (patch) | |
tree | ea0f1338488ffebb2eb45b56c9399d44e7495a0c /dozentenmodul/src/main/java/org/openslx/dozmod | |
parent | [server] Overhaul permission checking, precalc user permissions, implement do... (diff) | |
download | tutor-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')
6 files changed, 186 insertions, 10 deletions
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 cf54c22a..de024a30 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 @@ -90,7 +90,7 @@ public class LectureListWindow extends LectureListWindowLayout { newButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - new LectureWizard(SwingUtilities.getWindowAncestor(me), false).setVisible(true); + new LectureWizard(SwingUtilities.getWindowAncestor(me)).setVisible(true); } }); 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 1ca2ccff..9cae3809 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,28 +3,31 @@ package org.openslx.dozmod.gui.wizard; import java.awt.Window; import org.apache.log4j.Logger; +import org.openslx.dozmod.gui.Gui; +import org.openslx.dozmod.gui.helper.MessageType; +import org.openslx.dozmod.gui.helper.UiFeedback; import org.openslx.dozmod.gui.wizard.page.LectureCreationPage; import org.openslx.dozmod.gui.wizard.page.LectureCustomPermissionPage; +import org.openslx.dozmod.state.LectureWizardState; @SuppressWarnings("serial") -public class LectureWizard extends Wizard { +public class LectureWizard extends Wizard implements UiFeedback { private final static Logger LOGGER = Logger.getLogger(LectureWizard.class); - protected boolean editExistingLecture; + public final LectureWizardState state = new LectureWizardState(); /** * Wizard for creating or editing a lecture * * @param editExistingLecture whether to create new or edit existing lecture */ - public LectureWizard(Window parent, boolean editExistingLecture) { + public LectureWizard(Window parent) { super(parent); - this.editExistingLecture = editExistingLecture; // create the shared object for all pages of the wizard - addPage(new LectureCreationPage(this)); - addPage(new LectureCustomPermissionPage(this)); + addPage(new LectureCreationPage(this, state)); + addPage(new LectureCustomPermissionPage(this, state)); } @Override @@ -32,4 +35,19 @@ public class LectureWizard extends Wizard { return "Neue Veranstaltung erzeugen"; } + @Override + protected boolean onCancelRequest() { + return Gui.showMessageBox(this, "Möchten Sie den Vorgang wirklich abbrechen?", + MessageType.QUESTION_YESNO, null, null); + } + + @Override + public boolean wantConfirmQuit() { + return state.uuid != null; + } + + @Override + public void escapePressed() { + doCancel(); + } } 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 13b71011..63cc92a8 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,6 +1,5 @@ package org.openslx.dozmod.gui.wizard.layout; -import java.awt.Dimension; import java.awt.GridBagLayout; import java.util.Calendar; import java.util.Date; 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 diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/state/LectureWizardState.java b/dozentenmodul/src/main/java/org/openslx/dozmod/state/LectureWizardState.java new file mode 100644 index 00000000..dd9039f7 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/state/LectureWizardState.java @@ -0,0 +1,15 @@ +package org.openslx.dozmod.state; + +import java.util.Date; + +public class LectureWizardState { + + public String name = null; + public String description = null; + public String uuid = null; + public boolean autoUpdate = false; + public boolean isEnabled = false; + public Date start = null; + public Date end = null; + +} |