summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCustomPermissionPage.java
blob: f19563c234b6ea6a1fa475ee085e79c17710e063 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package org.openslx.dozmod.gui.wizard.page;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JOptionPane;

import org.apache.log4j.Logger;
import org.openslx.bwlp.thrift.iface.LecturePermissions;
import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.dozmod.gui.control.table.LecturePermissionTable.UserLecturePermissions;
import org.openslx.dozmod.gui.window.UserListWindow;
import org.openslx.dozmod.gui.window.UserListWindow.UserAddedCallback;
import org.openslx.dozmod.gui.wizard.Wizard;
import org.openslx.dozmod.gui.wizard.layout.LectureCustomPermissionPageLayout;
import org.openslx.dozmod.state.LectureWizardState;

@SuppressWarnings("serial")
public class LectureCustomPermissionPage extends LectureCustomPermissionPageLayout {

	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, LectureWizardState state) {
		super(wizard);
		this.state = state;

		addUser.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO again: which frame to giev? JOptionPane.getFrameForComponent(me) sounds cool at least :)
				UserListWindow.open(JOptionPane.getFrameForComponent(me), new UserAddedCallback() {
					@Override
					public void userAdded(final UserInfo newUser, UserListWindow window) {

						// check if we have this user already
						for (UserLecturePermissions current : permissionList) {
							if (current.userId.equals(newUser.userId)) {
								// user already in the list, skip it
								LOGGER.debug("User already present in the list, skipping!");
								return;
							}
						}
						// add it to the list with either default permissions if set, or none
						permissionList.add(new UserLecturePermissions(newUser.userId, new LecturePermissions(
								true, false)));
						LOGGER.debug("User added: " + newUser);
						permissionTableViewer.setData(permissionList, false);
					}
				}, "Hinzufügen");
			}
		});
		// delete user button adapter
		removeUser.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				final UserLecturePermissions selected = permissionTableViewer.getSelectedItem();
				LOGGER.debug("Removing: " + selected);
				if (!permissionList.remove(selected)) {
					LOGGER.debug("Could not remove: " + selected);
				}
				permissionTableViewer.setData(permissionList, false);
			}
		});
		// no requirements before finishing
		setPageComplete(true);
	}
}