Project

General

Profile

Download (2.96 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* 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
import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl;
21
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
22
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
23
import eu.etaxonomy.taxeditor.newWizard.NewGrantedAuthorityWizard;
24
import eu.etaxonomy.taxeditor.store.CdmStore;
25
import eu.etaxonomy.taxeditor.ui.section.grantedAuthority.GrantedAuthorityLabelTextProvider;
26

    
27
/**
28
 * @author a.kohlbecker
29
 * @created Sept 12, 2011
30
 */
31
public class GrantedAuthoritySelectionDialog extends	AbstractFilteredCdmResourceSelectionDialog<GrantedAuthorityImpl> {
32

    
33
	public static GrantedAuthority select(Shell shell, //ConversationHolder conversation,
34
	        GrantedAuthorityImpl authority){
35

    
36
		GrantedAuthoritySelectionDialog dialog = new GrantedAuthoritySelectionDialog(shell,//conversation,
37
				"Choose Granted Authority", false, GrantedAuthoritySelectionDialog.class.getCanonicalName(), authority);
38

    
39
		return getSelectionFromDialog(dialog);
40
	}
41

    
42
	/**
43
	 * @param shell
44
	 * @param conversation
45
	 * @param title
46
	 * @param multi
47
	 * @param settings
48
	 * @param cdmObject
49
	 */
50
	protected GrantedAuthoritySelectionDialog(Shell shell,//ConversationHolder conversation,
51
	        String title, boolean multi,
52
			String settings, GrantedAuthorityImpl cdmObject) {
53
		super(shell, //conversation,
54
		        title, multi, settings, cdmObject);
55
	}
56

    
57
	@Override
58
	protected void callService(String pattern) {
59
		List<GrantedAuthorityImpl> authorities = CdmStore.getService(IGrantedAuthorityService.class).list(GrantedAuthorityImpl.class, null, null, null, null);
60

    
61
		model = new ArrayList<>();
62

    
63
		for(GrantedAuthorityImpl authority : authorities){
64
		    if ( pattern == null || authority.getAuthority().matches(pattern +".*")){
65
		        model.add(new UuidAndTitleCache<>(GrantedAuthorityImpl.class, authority.getUuid(), authority.getId(), String.format("%s", GrantedAuthorityLabelTextProvider.getText(authority))));
66
		    }
67
		}
68

    
69
	}
70

    
71
	@Override
72
	protected String[] getNewWizardText() {
73
		return new String[]{"New GrantedAuthority"};
74
	}
75

    
76
	@Override
77
	protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
78
		return new NewGrantedAuthorityWizard();
79
	}
80

    
81
	@Override
82
	protected GrantedAuthorityImpl getPersistentObject(UUID uuid) {
83
		return CdmStore.getService(IGrantedAuthorityService.class).load(uuid);
84
	}
85

    
86
	@Override
87
	protected String getTitle(GrantedAuthorityImpl authority) {
88
		return authority != null ? GrantedAuthorityLabelTextProvider.getText(authority) : "";
89
	}
90

    
91
}
(18-18/44)