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.bulkeditor.input.entitycreator;
|
11
|
|
12
|
import java.util.HashMap;
|
13
|
import java.util.List;
|
14
|
import java.util.Map;
|
15
|
|
16
|
import eu.etaxonomy.cdm.api.service.IGroupService;
|
17
|
import eu.etaxonomy.cdm.model.common.Group;
|
18
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
19
|
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
|
20
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
21
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
22
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
23
|
|
24
|
/**
|
25
|
* @author n.hoffmann
|
26
|
* @created Mar 9, 2011
|
27
|
* @version 1.0
|
28
|
*/
|
29
|
public class GroupCreator implements IEntityCreator<Group> {
|
30
|
|
31
|
public static final String GROUP = "Group";
|
32
|
|
33
|
/* (non-Javadoc)
|
34
|
* @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#createEntity(java.lang.String)
|
35
|
*/
|
36
|
@Override
|
37
|
public Group createEntity(String text) {
|
38
|
Group group = createEntity(null, text);
|
39
|
return group;
|
40
|
}
|
41
|
|
42
|
/* (non-Javadoc)
|
43
|
* @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#createEntity(java.lang.Object, java.lang.String)
|
44
|
*/
|
45
|
@Override
|
46
|
public Group createEntity(Object key, String text) {
|
47
|
List<Group> groupList =CdmStore.getService(IGroupService.class).listByName(text, MatchMode.EXACT, null, 100, 0, null, null);
|
48
|
|
49
|
if (groupList.isEmpty()){
|
50
|
Group group = Group.NewInstance(text);
|
51
|
// UUID groupUuid = CdmStore.getService(IGroupService.class).saveGroup(group);
|
52
|
// group = CdmStore.getService(IGroupService.class).loadWithUpdate(groupUuid);
|
53
|
return group;
|
54
|
} else{
|
55
|
MessagingUtils.messageDialog(Messages.GROUP_CREATOR_group_exists_title, text, Messages.GROUP_CREATOR_group_exists);
|
56
|
return null;
|
57
|
}
|
58
|
|
59
|
|
60
|
}
|
61
|
|
62
|
/* (non-Javadoc)
|
63
|
* @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#getKeyLabelPairs()
|
64
|
*/
|
65
|
@Override
|
66
|
public Map<Object, String> getKeyLabelPairs() {
|
67
|
Map<Object, String> result = new HashMap<Object, String>();
|
68
|
result.put(Group.class, GROUP);
|
69
|
return result;
|
70
|
}
|
71
|
|
72
|
@Override
|
73
|
public boolean savesEntity() {
|
74
|
// TODO Auto-generated method stub
|
75
|
return false;
|
76
|
}
|
77
|
|
78
|
}
|