2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
15 import java
.util
.UUID
;
17 import org
.eclipse
.swt
.widgets
.Shell
;
19 import eu
.etaxonomy
.cdm
.api
.service
.IUserService
;
20 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
21 import eu
.etaxonomy
.cdm
.model
.permission
.Group
;
22 import eu
.etaxonomy
.cdm
.model
.permission
.User
;
23 import eu
.etaxonomy
.cdm
.persistence
.dto
.UuidAndTitleCache
;
24 import eu
.etaxonomy
.taxeditor
.newWizard
.AbstractNewEntityWizard
;
25 import eu
.etaxonomy
.taxeditor
.newWizard
.NewUserWizard
;
26 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
30 * @created Mar 10, 2011
33 public class UserSelectionDialog
extends
34 AbstractFilteredCdmResourceSelectionDialog
<User
> {
37 Set
<User
> groupMembers
;
46 public static User
select(Shell shell
, //ConversationHolder conversation,
47 User user
, Group group
){
48 UserSelectionDialog dialog
= new UserSelectionDialog(shell
, //conversation,
49 "Choose User", false, UserSelectionDialog
.class.getCanonicalName(), user
, group
);
50 return getSelectionFromDialog(dialog
);
61 protected UserSelectionDialog(Shell shell
, //ConversationHolder conversation,
62 String title
, boolean multi
, String settings
, User cdmObject
, Group group
) {
63 super(shell
, //conversation,
64 title
, multi
, settings
, cdmObject
);
66 groupMembers
= group
.getMembers();
70 * @see eu.etaxonomy.taxeditor.ui.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#search
73 protected void callService(String pattern
) {
74 List
<User
> users
= CdmStore
.getService(IUserService
.class).list(User
.class, null, null, null, null);
76 model
= new ArrayList
<UuidAndTitleCache
<User
>>();
78 for(User user
: users
){
79 if (pattern
== null || user
.getUsername().matches(CdmUtils
.quoteRegExWithWildcard(pattern
) + ".*")) {
80 if (groupMembers
!= null && !groupMembers
.isEmpty() && groupMembers
.contains(user
)){
83 model
.add(new UuidAndTitleCache
<User
>(User
.class, user
.getUuid(), user
.getId(), String
.format("%s, %s", user
.getUsername(), user
.getPerson())));
89 * @see eu.etaxonomy.taxeditor.ui.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#getNewWizardLinkText()
92 protected String
[] getNewWizardText() {
97 * @see eu.etaxonomy.taxeditor.ui.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#getNewEntityWizard(java.lang.String)
100 protected AbstractNewEntityWizard
getNewEntityWizard(String parameter
) {
101 return new NewUserWizard();
105 * @see eu.etaxonomy.taxeditor.ui.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#getPersistentObject(java.util.UUID)
108 protected User
getPersistentObject(UUID uuid
) {
109 return CdmStore
.getService(IUserService
.class).load(uuid
);
113 protected String
getTitle(User user
) {
114 return user
!= null ? user
.getUsername() : "";