blob: d0c3da06fc728743298007eab352f28c84dfe716 (
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
79
80
|
package org.openslx.dozmod.gui.wizard.page;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.JOptionPane;
import org.apache.log4j.Logger;
import org.openslx.bwlp.thrift.iface.ImagePermissions;
import org.openslx.bwlp.thrift.iface.LecturePermissions;
import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.dozmod.gui.control.table.ImagePermissionTable.UserImagePermissions;
import org.openslx.dozmod.gui.control.table.LecturePermissionTable.UserLecturePermissions;
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")
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) {
// looks if we have this user already
Iterator<UserLecturePermissions> it = permissionList.iterator();
while (it.hasNext()) {
UserLecturePermissions current = it.next();
if (current.userId == 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);
}
});
}
});
// 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);
}
});
}
}
|