3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.bulkeditor
.input
;
12 import java
.util
.List
;
14 import eu
.etaxonomy
.cdm
.api
.service
.IAgentService
;
15 import eu
.etaxonomy
.cdm
.api
.service
.config
.IIdentifiableEntityServiceConfigurator
;
16 import eu
.etaxonomy
.cdm
.api
.service
.exception
.ReferencedObjectUndeletableException
;
17 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
18 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
19 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
20 import eu
.etaxonomy
.cdm
.strategy
.merge
.DefaultMergeStrategy
;
21 import eu
.etaxonomy
.cdm
.strategy
.merge
.IMergable
;
22 import eu
.etaxonomy
.cdm
.strategy
.merge
.IMergeStrategy
;
23 import eu
.etaxonomy
.cdm
.strategy
.merge
.MergeException
;
24 import eu
.etaxonomy
.cdm
.strategy
.merge
.MergeMode
;
25 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IEntityCreator
;
26 import eu
.etaxonomy
.taxeditor
.bulkeditor
.IBulkEditorSortProvider
;
27 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.entitycreator
.AgentCreator
;
28 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.sortprovider
.IdentifiableEntitySortProvider
;
29 import eu
.etaxonomy
.taxeditor
.bulkeditor
.internal
.TaxeditorBulkeditorPlugin
;
30 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
31 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
39 public class AgentEditorInput
extends AbstractBulkEditorInput
<TeamOrPersonBase
> {
41 private static final long serialVersionUID
= 3387950621617078479L;
43 public static final String ID
= "bulkeditor.input.author";
45 private static AgentEditorInput instance
;
47 public static String
getID() {
52 public String
getName() {
53 return BulkEditorInputType
.AGENT
.label
;
57 public String
getToolTipText() {
61 public static AbstractBulkEditorInput
getInstance() {
62 if (instance
== null) {
63 instance
= new AgentEditorInput();
70 public boolean isMergingEnabled() {
76 public boolean isConvertingEnabled() {
82 public boolean merge(TeamOrPersonBase entity
, TeamOrPersonBase mergeTarget
) {
83 if (entity
instanceof IMergable
) {
85 IMergeStrategy strategy
= DefaultMergeStrategy
.NewInstance(Person
.class);
86 strategy
.setMergeMode("institutionalMemberships", MergeMode
.FIRST
);
87 CdmStore
.getCommonService().merge((IMergable
)mergeTarget
, (IMergable
)entity
, strategy
);
88 } catch (MergeException e
) {
89 MessagingUtils
.errorDialog("Bulk Editor Merge Error",
91 "Could not merge chosen objects of type " + entity
.getClass().getName(),
92 TaxeditorBulkeditorPlugin
.PLUGIN_ID
,
102 public List
<TeamOrPersonBase
> listEntities(IIdentifiableEntityServiceConfigurator configurator
) {
103 return CdmStore
.getSearchManager().findTeamOrPersons(configurator
);
108 public AgentBase loadEntity(UUID uuid) {
109 List<String> propertyPaths = Arrays.asList(new String[]{});
110 return CdmStore.getService(IAgentService.class).load(uuid, propertyPaths);
114 public boolean delete(AgentBase entity
) throws ReferencedObjectUndeletableException
{
116 return CdmStore
.getService(IAgentService
.class).delete(entity
) != null;
121 public boolean save(AgentBase entity
) {
123 return CdmStore
.getService(IAgentService
.class).saveOrUpdate(entity
) != null;
127 public List
<IBulkEditorSortProvider
<TeamOrPersonBase
>> getSortProviders() {
128 List
<IBulkEditorSortProvider
<TeamOrPersonBase
>> sortProviders
= super.getSortProviders();
130 sortProviders
.add(0, new IdentifiableEntitySortProvider
<TeamOrPersonBase
>());
132 return sortProviders
;
136 protected IEntityCreator
<TeamOrPersonBase
> createEntityCreator() {
137 return new AgentCreator();
141 public boolean save(TeamOrPersonBase entity
) {
142 return CdmStore
.getService(IAgentService
.class).saveOrUpdate(entity
) != null;
146 public boolean delete(TeamOrPersonBase entity
)
147 throws ReferencedObjectUndeletableException
{
148 // TODO Auto-generated method stub