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
.Arrays
;
13 import java
.util
.List
;
14 import java
.util
.UUID
;
16 import org
.eclipse
.core
.commands
.ExecutionException
;
18 import eu
.etaxonomy
.cdm
.api
.service
.IAgentService
;
19 import eu
.etaxonomy
.cdm
.api
.service
.config
.IIdentifiableEntityServiceConfigurator
;
20 import eu
.etaxonomy
.cdm
.api
.service
.exception
.DataChangeNoRollbackException
;
21 import eu
.etaxonomy
.cdm
.api
.service
.exception
.ReferencedObjectUndeletableException
;
22 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
23 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
24 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
25 import eu
.etaxonomy
.cdm
.strategy
.merge
.DefaultMergeStrategy
;
26 import eu
.etaxonomy
.cdm
.strategy
.merge
.IMergable
;
27 import eu
.etaxonomy
.cdm
.strategy
.merge
.IMergeStrategy
;
28 import eu
.etaxonomy
.cdm
.strategy
.merge
.MergeException
;
29 import eu
.etaxonomy
.cdm
.strategy
.merge
.MergeMode
;
30 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IEntityCreator
;
31 import eu
.etaxonomy
.taxeditor
.bulkeditor
.IBulkEditorSortProvider
;
32 import eu
.etaxonomy
.taxeditor
.bulkeditor
.handler
.MergeGroupHandler
;
33 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.entitycreator
.AgentCreator
;
34 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.sortprovider
.IdentifiableEntitySortProvider
;
35 import eu
.etaxonomy
.taxeditor
.bulkeditor
.internal
.TaxeditorBulkeditorPlugin
;
36 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
37 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
41 * <p>AgentEditorInput class.</p>
47 public class AgentEditorInput
extends AbstractBulkEditorInput
<TeamOrPersonBase
> {
52 private static final long serialVersionUID
= 3387950621617078479L;
54 /** Constant <code>ID="bulkeditor.input.author"</code> */
55 public static final String ID
= "bulkeditor.input.author";
57 private static AgentEditorInput instance
;
64 public static String
getID() {
69 * @see org.eclipse.ui.IEditorInput#getName()
74 * @return a {@link java.lang.String} object.
76 public String
getName() {
77 return BulkEditorInputType
.AGENT
.label
;
81 * @see org.eclipse.ui.IEditorInput#getToolTipText()
84 * <p>getToolTipText</p>
86 * @return a {@link java.lang.String} object.
88 public String
getToolTipText() {
93 * <p>Getter for the field <code>instance</code>.</p>
95 * @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
97 public static AbstractBulkEditorInput
getInstance() {
98 if (instance
== null) {
99 instance
= new AgentEditorInput();
105 * @see eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInput#isMergingEnabled()
109 public boolean isMergingEnabled() {
114 * @see eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInput#isMergingEnabled()
118 public boolean isConvertingEnabled() {
124 public boolean merge(TeamOrPersonBase entity
, TeamOrPersonBase mergeTarget
) {
125 if (entity
instanceof IMergable
) {
127 IMergeStrategy strategy
= DefaultMergeStrategy
.NewInstance(Person
.class);
128 strategy
.setMergeMode("institutionalMemberships", MergeMode
.FIRST
);
129 CdmStore
.getCommonService().merge((IMergable
)mergeTarget
, (IMergable
)entity
, strategy
);
130 } catch (MergeException e
) {
131 MessagingUtils
.errorDialog("Bulk Editor Merge Error",
133 "Could not merge chosen objects of type " + entity
.getClass().getName(),
134 TaxeditorBulkeditorPlugin
.PLUGIN_ID
,
144 public List
<TeamOrPersonBase
> listEntities(IIdentifiableEntityServiceConfigurator configurator
) {
145 return CdmStore
.getSearchManager().findTeamOrPersons(configurator
);
150 public AgentBase loadEntity(UUID uuid) {
151 List<String> propertyPaths = Arrays.asList(new String[]{});
152 return CdmStore.getService(IAgentService.class).load(uuid, propertyPaths);
156 public boolean delete(AgentBase entity
) throws ReferencedObjectUndeletableException
{
158 return CdmStore
.getService(IAgentService
.class).delete(entity
) != null;
163 public boolean save(AgentBase entity
) {
165 return CdmStore
.getService(IAgentService
.class).saveOrUpdate(entity
) != null;
169 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#getSortProviders()
172 public List
<IBulkEditorSortProvider
<TeamOrPersonBase
>> getSortProviders() {
173 List
<IBulkEditorSortProvider
<TeamOrPersonBase
>> sortProviders
= super.getSortProviders();
175 sortProviders
.add(0, new IdentifiableEntitySortProvider
<TeamOrPersonBase
>());
177 return sortProviders
;
181 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#createEntityCreator()
184 protected IEntityCreator
<TeamOrPersonBase
> createEntityCreator() {
185 return new AgentCreator();
189 public boolean save(TeamOrPersonBase entity
) {
190 return CdmStore
.getService(IAgentService
.class).saveOrUpdate(entity
) != null;
194 public boolean delete(TeamOrPersonBase entity
)
195 throws ReferencedObjectUndeletableException
{
196 // TODO Auto-generated method stub