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
|
|
18
|
import eu.etaxonomy.cdm.api.service.IUserService;
|
19
|
import eu.etaxonomy.cdm.model.common.User;
|
20
|
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
|
21
|
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
|
22
|
import eu.etaxonomy.taxeditor.newWizard.NewUserWizard;
|
23
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
24
|
|
25
|
/**
|
26
|
* @author n.hoffmann
|
27
|
* @created Mar 10, 2011
|
28
|
* @version 1.0
|
29
|
*/
|
30
|
public class UserSelectionDialog extends
|
31
|
AbstractFilteredCdmResourceSelectionDialog<User> {
|
32
|
|
33
|
/**
|
34
|
*
|
35
|
* @param shell
|
36
|
* @param conversation
|
37
|
* @param user
|
38
|
* @return
|
39
|
*/
|
40
|
public static User select(Shell shell, //ConversationHolder conversation,
|
41
|
User user){
|
42
|
UserSelectionDialog dialog = new UserSelectionDialog(shell, //conversation,
|
43
|
"Choose User", false, UserSelectionDialog.class.getCanonicalName(), user);
|
44
|
return getSelectionFromDialog(dialog);
|
45
|
}
|
46
|
|
47
|
/**
|
48
|
* @param shell
|
49
|
* @param conversation
|
50
|
* @param title
|
51
|
* @param multi
|
52
|
* @param settings
|
53
|
* @param cdmObject
|
54
|
*/
|
55
|
protected UserSelectionDialog(Shell shell, //ConversationHolder conversation,
|
56
|
String title, boolean multi, String settings, User cdmObject) {
|
57
|
super(shell, //conversation,
|
58
|
title, multi, settings, cdmObject);
|
59
|
}
|
60
|
|
61
|
/* (non-Javadoc)
|
62
|
* @see eu.etaxonomy.taxeditor.ui.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#search
|
63
|
*/
|
64
|
@Override
|
65
|
protected void callService(String pattern) {
|
66
|
List<User> users = CdmStore.getService(IUserService.class).list(User.class, null, null, null, null);
|
67
|
|
68
|
model = new ArrayList<UuidAndTitleCache<User>>();
|
69
|
|
70
|
for(User user : users){
|
71
|
if (pattern == null || user.getUsername().matches(pattern + ".*")) {
|
72
|
model.add(new UuidAndTitleCache<User>(User.class, user.getUuid(), user.getId(), String.format("%s, %s", user.getUsername(), user.getPerson())));
|
73
|
}
|
74
|
}
|
75
|
}
|
76
|
|
77
|
/* (non-Javadoc)
|
78
|
* @see eu.etaxonomy.taxeditor.ui.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#getNewWizardLinkText()
|
79
|
*/
|
80
|
@Override
|
81
|
protected String[] getNewWizardText() {
|
82
|
return new String[]{"New User"};
|
83
|
}
|
84
|
|
85
|
/* (non-Javadoc)
|
86
|
* @see eu.etaxonomy.taxeditor.ui.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#getNewEntityWizard(java.lang.String)
|
87
|
*/
|
88
|
@Override
|
89
|
protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
|
90
|
return new NewUserWizard();
|
91
|
}
|
92
|
|
93
|
/* (non-Javadoc)
|
94
|
* @see eu.etaxonomy.taxeditor.ui.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#getPersistentObject(java.util.UUID)
|
95
|
*/
|
96
|
@Override
|
97
|
protected User getPersistentObject(UUID uuid) {
|
98
|
return CdmStore.getService(IUserService.class).load(uuid);
|
99
|
}
|
100
|
|
101
|
@Override
|
102
|
protected String getTitle(User user) {
|
103
|
return user != null ? user.getUsername() : "";
|
104
|
}
|
105
|
|
106
|
}
|