Project

General

Profile

Download (2.14 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.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
            return group;
52
        } else{
53
            MessagingUtils.messageDialog(Messages.GROUP_CREATOR_group_exists_title, text, Messages.GROUP_CREATOR_group_exists);
54
            return null;
55
        }
56

    
57

    
58
	}
59

    
60
	/* (non-Javadoc)
61
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#getKeyLabelPairs()
62
	 */
63
	@Override
64
	public Map<Object, String> getKeyLabelPairs() {
65
		Map<Object, String> result = new HashMap<Object, String>();
66
		result.put(Group.class, GROUP);
67
		return result;
68
	}
69

    
70
	@Override
71
	public boolean savesEntity() {
72
		// TODO Auto-generated method stub
73
		return false;
74
	}
75

    
76
}
(2-2/8)