Project

General

Profile

Download (2.94 KB) Statistics
| Branch: | Tag: | Revision:
1 28b3f4aa Andreas Kohlbecker
/**
2
* Copyright (C) 2007 EDIT
3 f0a072ff Patric Plitzner
* European Distributed Institute of Taxonomy
4 28b3f4aa Andreas Kohlbecker
* http://www.e-taxonomy.eu
5 f0a072ff Patric Plitzner
*
6 28b3f4aa Andreas Kohlbecker
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
10
package eu.etaxonomy.taxeditor.ui.dialog.selection;
11
12
import java.util.ArrayList;
13
import java.util.List;
14
import java.util.UUID;
15
16
import org.eclipse.swt.widgets.Shell;
17
import org.springframework.security.core.GrantedAuthority;
18
19
import eu.etaxonomy.cdm.api.service.IGrantedAuthorityService;
20 f4935f27 Patrick Plitzner
import eu.etaxonomy.cdm.common.CdmUtils;
21 d9054fe5 Andreas Müller
import eu.etaxonomy.cdm.model.permission.GrantedAuthorityImpl;
22 48d1a460 Andreas M��ller
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
23 28b3f4aa Andreas Kohlbecker
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
24 30a27c33 Andreas Kohlbecker
import eu.etaxonomy.taxeditor.newWizard.NewGrantedAuthorityWizard;
25 28b3f4aa Andreas Kohlbecker
import eu.etaxonomy.taxeditor.store.CdmStore;
26 4e59c9c1 Andreas Kohlbecker
import eu.etaxonomy.taxeditor.ui.section.grantedAuthority.GrantedAuthorityLabelTextProvider;
27 28b3f4aa Andreas Kohlbecker
28
/**
29
 * @author a.kohlbecker
30
 * @created Sept 12, 2011
31
 */
32 84527493 Andreas Müller
public class GrantedAuthoritySelectionDialog
33
        extends AbstractFilteredCdmResourceSelectionDialog<GrantedAuthorityImpl> {
34 28b3f4aa Andreas Kohlbecker
35 f5979052 Katja Luther
	public static GrantedAuthority select(Shell shell, //ConversationHolder conversation,
36
	        GrantedAuthorityImpl authority){
37 f0a072ff Patric Plitzner
38 f5979052 Katja Luther
		GrantedAuthoritySelectionDialog dialog = new GrantedAuthoritySelectionDialog(shell,//conversation,
39 28b3f4aa Andreas Kohlbecker
				"Choose Granted Authority", false, GrantedAuthoritySelectionDialog.class.getCanonicalName(), authority);
40 f0a072ff Patric Plitzner
41 28b3f4aa Andreas Kohlbecker
		return getSelectionFromDialog(dialog);
42
	}
43 f0a072ff Patric Plitzner
44 f5979052 Katja Luther
	protected GrantedAuthoritySelectionDialog(Shell shell,//ConversationHolder conversation,
45
	        String title, boolean multi,
46 28b3f4aa Andreas Kohlbecker
			String settings, GrantedAuthorityImpl cdmObject) {
47 f5979052 Katja Luther
		super(shell, //conversation,
48
		        title, multi, settings, cdmObject);
49 28b3f4aa Andreas Kohlbecker
	}
50
51
	@Override
52 0ce80af9 Katja Luther
	protected void callService(String pattern) {
53 28b3f4aa Andreas Kohlbecker
		List<GrantedAuthorityImpl> authorities = CdmStore.getService(IGrantedAuthorityService.class).list(GrantedAuthorityImpl.class, null, null, null, null);
54 f0a072ff Patric Plitzner
55 0c40f20e Andreas Müller
		model = new ArrayList<>();
56 f0a072ff Patric Plitzner
57 28b3f4aa Andreas Kohlbecker
		for(GrantedAuthorityImpl authority : authorities){
58 f4935f27 Patrick Plitzner
		    if ( pattern == null || authority.getAuthority().matches(CdmUtils.quoteRegExWithWildcard(pattern) +".*")){
59 0c40f20e Andreas Müller
		        model.add(new UuidAndTitleCache<>(GrantedAuthorityImpl.class, authority.getUuid(), authority.getId(), String.format("%s", GrantedAuthorityLabelTextProvider.getText(authority))));
60 0ce80af9 Katja Luther
		    }
61 f0a072ff Patric Plitzner
		}
62 28b3f4aa Andreas Kohlbecker
	}
63
64
	@Override
65 5aeccadc Katja Luther
	protected String[] getNewWizardText() {
66 142a6b70 Andreas Müller
		return new String[]{"New Granted Authority"};
67 28b3f4aa Andreas Kohlbecker
	}
68
69
	@Override
70 84527493 Andreas Müller
	protected AbstractNewEntityWizard<GrantedAuthorityImpl> getNewEntityWizard(String parameter) {
71 30a27c33 Andreas Kohlbecker
		return new NewGrantedAuthorityWizard();
72 28b3f4aa Andreas Kohlbecker
	}
73
74
	@Override
75
	protected GrantedAuthorityImpl getPersistentObject(UUID uuid) {
76
		return CdmStore.getService(IGrantedAuthorityService.class).load(uuid);
77
	}
78 f0a072ff Patric Plitzner
79 28b3f4aa Andreas Kohlbecker
	@Override
80
	protected String getTitle(GrantedAuthorityImpl authority) {
81 4e59c9c1 Andreas Kohlbecker
		return authority != null ? GrantedAuthorityLabelTextProvider.getText(authority) : "";
82 28b3f4aa Andreas Kohlbecker
	}
83
}