summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureCustomPermissionWindow.java
blob: f18c9668c5b6ddb9acc2c62727d048fbd2d2be5e (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package org.openslx.dozmod.gui.window;

import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Map;

import org.apache.log4j.Logger;
import org.openslx.bwlp.thrift.iface.LecturePermissions;
import org.openslx.dozmod.gui.helper.UiFeedback;
import org.openslx.dozmod.gui.window.layout.LectureCustomPermissionWindowLayout;
import org.openslx.dozmod.permissions.PermissionDefaultToCustomLink;

/**
 * Window for modifying the custom permissions of an lecture.  
 */
@SuppressWarnings("serial")
public class LectureCustomPermissionWindow extends LectureCustomPermissionWindowLayout implements UiFeedback {

	private static final Logger LOGGER = Logger.getLogger(LectureCustomPermissionWindow.class);
	
	private boolean okUsed = false;

	/**
	 * Don't use this constructor, use static function LectureCustomPermissionWindow.open instead.
	 */
	protected LectureCustomPermissionWindow(final Window modalParent, final Map<String, LecturePermissions> permissionMap, final LecturePermissions defaultPermissions, String ownerId) {
		super(modalParent);

		/**
		 * 	initialise the lecturePermissionManager 
		 */
		lecturePermissionManager.initPanel(permissionMap, defaultPermissions, ownerId);
		
		chkCustomPermAdmin.setSelected(defaultPermissions.admin);
		chkCustomPermEdit.setSelected(defaultPermissions.edit);

		
		ActionListener updateDefaultPermissionListener = new ActionListener() {	
			@Override
			public void actionPerformed(ActionEvent e) {
				lecturePermissionManager.updateDefaultPermissions(chkCustomPermAdmin.isSelected(), chkCustomPermEdit.isSelected());
			}
		};
		
		chkCustomPermAdmin.addActionListener(updateDefaultPermissionListener);
		chkCustomPermEdit.addActionListener(updateDefaultPermissionListener);
		
		/**
		 * ActionListeners for the buttons.
		 */
		btnOk.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				okUsed = true;
				dispose();
			}
		});
		btnClose.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				dispose();				
			}
		});
	}

	/**
	 * Set a created ImageCustomPermissionWindow visible and return resulting permissions
	 * 
	 * @return PermissionDefaultToCustomLink with default- and customPermissions when using OK button, null otherwise
	 */
	private PermissionDefaultToCustomLink<LecturePermissions> runAndReturn(){
		setVisible(true);
		if (okUsed){
			return new PermissionDefaultToCustomLink<LecturePermissions>(lecturePermissionManager.getMap(), new LecturePermissions(chkCustomPermEdit.isSelected(), chkCustomPermAdmin.isSelected()));
		} else {
			return null;
		}
	}


	/**
	 * Create new LecturePermissionWindow dialog
	 * 
	 * @param modalParent parentwindow of the popup window
	 * @param permissionMap the permissions of the lecture
	 * @param defaultPermissions default permissions of the lecture
	 * @param ownerId Id not to be shown in the list to add new users. Can be null.
	 * @return PermissionDefaultToCustomLink with new permissions of null, if abort button has been used
	 */

	public static PermissionDefaultToCustomLink<LecturePermissions> open(
			Window modalParent, Map<String, LecturePermissions> permissionMap, LecturePermissions defaultPermissions, String ownerId) {
		return new LectureCustomPermissionWindow(modalParent, permissionMap, defaultPermissions, ownerId).runAndReturn();
	}

	@Override
	public boolean wantConfirmQuit() {
		// TODO only return true if user added something new in the list
		return false;
	}

	@Override
	public void escapePressed() {
		dispose();
	}
}