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
;
35 * <p>AgentEditorInput class.</p>
41 public class AgentEditorInput
extends AbstractBulkEditorInput
<TeamOrPersonBase
> {
46 private static final long serialVersionUID
= 3387950621617078479L;
48 /** Constant <code>ID="bulkeditor.input.author"</code> */
49 public static final String ID
= "bulkeditor.input.author";
51 private static AgentEditorInput instance
;
58 public static String
getID() {
63 * @see org.eclipse.ui.IEditorInput#getName()
68 * @return a {@link java.lang.String} object.
71 public String
getName() {
72 return BulkEditorInputType
.AGENT
.label
;
76 * @see org.eclipse.ui.IEditorInput#getToolTipText()
79 * <p>getToolTipText</p>
81 * @return a {@link java.lang.String} object.
84 public String
getToolTipText() {
89 * <p>Getter for the field <code>instance</code>.</p>
91 * @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
93 public static AbstractBulkEditorInput
getInstance() {
94 if (instance
== null) {
95 instance
= new AgentEditorInput();
101 * @see eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInput#isMergingEnabled()
105 public boolean isMergingEnabled() {
110 * @see eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInput#isMergingEnabled()
114 public boolean isConvertingEnabled() {
120 public boolean merge(TeamOrPersonBase entity
, TeamOrPersonBase mergeTarget
) {
121 if (entity
instanceof IMergable
) {
123 if(entity
instanceof Person
) {
124 IMergeStrategy strategy
= DefaultMergeStrategy
.NewInstance(Person
.class);
125 strategy
.setMergeMode("institutionalMemberships", MergeMode
.FIRST
);
126 CdmStore
.getCommonService().merge(mergeTarget
.getId(), entity
.getId(), Person
.class);
128 IMergeStrategy strategy
= DefaultMergeStrategy
.NewInstance(TeamOrPersonBase
.class);
129 CdmStore
.getCommonService().merge(mergeTarget
.getId(), entity
.getId(), TeamOrPersonBase
.class);
132 } catch (MergeException e
) {
133 MessagingUtils
.errorDialog("Bulk Editor Merge Error",
135 "Could not merge chosen objects of type " + entity
.getClass().getName(),
136 TaxeditorBulkeditorPlugin
.PLUGIN_ID
,
146 public List
<TeamOrPersonBase
> listEntities(IIdentifiableEntityServiceConfigurator configurator
) {
147 return CdmStore
.getSearchManager().findTeamOrPersons(configurator
);
152 public AgentBase loadEntity(UUID uuid) {
153 List<String> propertyPaths = Arrays.asList(new String[]{});
154 return CdmStore.getService(IAgentService.class).load(uuid, propertyPaths);
158 public boolean delete(AgentBase entity
) throws ReferencedObjectUndeletableException
{
160 return CdmStore
.getService(IAgentService
.class).delete(entity
) != null;
164 // /** {@inheritDoc} */
165 // public boolean save(AgentBase entity) {
167 // return CdmStore.getService(IAgentService.class).saveOrUpdate(entity) != null;
171 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#getSortProviders()
174 public List
<IBulkEditorSortProvider
<TeamOrPersonBase
>> getSortProviders() {
175 List
<IBulkEditorSortProvider
<TeamOrPersonBase
>> sortProviders
= super.getSortProviders();
177 sortProviders
.add(0, new IdentifiableEntitySortProvider
<TeamOrPersonBase
>());
179 return sortProviders
;
183 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#createEntityCreator()
186 protected IEntityCreator
<TeamOrPersonBase
> createEntityCreator() {
187 return new AgentCreator();
191 public boolean save(TeamOrPersonBase entity
) {
192 if(CdmStore
.getCurrentSessionManager().isRemoting()) {
193 return CdmStore
.getService(IAgentService
.class).merge(entity
) != null;
195 return CdmStore
.getService(IAgentService
.class).saveOrUpdate(entity
) != null;
200 public boolean delete(TeamOrPersonBase entity
)
201 throws ReferencedObjectUndeletableException
{
202 // TODO Auto-generated method stub
207 * @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#merge()
210 public void merge() {