summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageCustomPermissionPage.java
blob: 566e75dce0031d01e1ef4d8860ec9686a6c559b6 (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
package org.openslx.dozmod.gui.wizard.page;

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

import org.apache.log4j.Logger;
import org.openslx.bwlp.thrift.iface.ImagePermissions;
import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.dozmod.gui.control.table.ImagePermissionTable.UserImagePermissions;
import org.openslx.dozmod.gui.wizard.Wizard;
import org.openslx.dozmod.gui.wizard.layout.ImageCustomPermissionPageLayout;
import org.openslx.dozmod.state.UploadWizardState;
import org.openslx.dozmod.thrift.UserCache;

@SuppressWarnings("serial")
public class ImageCustomPermissionPage extends ImageCustomPermissionPageLayout {

	private final static Logger LOGGER = Logger.getLogger(ImageCustomPermissionPage.class);

	private UploadWizardState state = null;
	private ArrayList<UserImagePermissions> permissionList = null;

	/**
	 * wizard page for setting custom permissions
	 * 
	 * @param wizard
	 */
	public ImageCustomPermissionPage(Wizard wizard, UploadWizardState uploadWizardState) {
		super(wizard);
		setPageComplete(true);
		this.state = uploadWizardState;

		// setup permission list for the table
		permissionList = new ArrayList<>();
		for (UserInfo user : UserCache.getAll()) {
			// check if we have a default permission
			if (state.permissions != null) {
				permissionList.add(new UserImagePermissions(user.getUserId(), state.permissions));
			}
		}
		permissionTable.setData(permissionList, true);
		

		// add user button adapter
		addUser.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				LOGGER.debug("addUser clicked"); // TODO
			}
		});
		// delete user button adapter
		removeUser.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				LOGGER.debug("removeUser clicked"); // TODO
			}
		});
	}

	@Override
	protected void onPageLeave() {
		LOGGER.debug("Saving permissions to state ...");
		// save the table stuff to our upload wizard state
		if (permissionList == null || permissionList.isEmpty())
			return;
		// stuff in our list, clear old list in state before continuing
		if (state.permissionList == null) {
			state.permissionList = new HashMap<String, ImagePermissions>();
		} else {
			state.permissionList.clear();
		}

		// add them one by one
		for (UserImagePermissions perm : permissionList) {
			// for now just overwrite the saved permission list of the state
			state.permissionList.put(perm.userId, perm.permissions);
		}
	}
}