1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
package eu.etaxonomy.taxeditor.bulkeditor.input;
|
11
|
|
12
|
import java.util.Arrays;
|
13
|
import java.util.List;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.eclipse.core.commands.ExecutionException;
|
17
|
|
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;
|
38
|
|
39
|
|
40
|
/**
|
41
|
* <p>AgentEditorInput class.</p>
|
42
|
*
|
43
|
* @author p.ciardelli
|
44
|
* @created 25.06.2009
|
45
|
* @version 1.0
|
46
|
*/
|
47
|
public class AgentEditorInput extends AbstractBulkEditorInput<TeamOrPersonBase> {
|
48
|
|
49
|
/**
|
50
|
*
|
51
|
*/
|
52
|
private static final long serialVersionUID = 3387950621617078479L;
|
53
|
|
54
|
/** Constant <code>ID="bulkeditor.input.author"</code> */
|
55
|
public static final String ID = "bulkeditor.input.author";
|
56
|
|
57
|
private static AgentEditorInput instance;
|
58
|
|
59
|
/**
|
60
|
* <p>getID</p>
|
61
|
*
|
62
|
* @return the iD
|
63
|
*/
|
64
|
public static String getID() {
|
65
|
return ID;
|
66
|
}
|
67
|
|
68
|
/* (non-Javadoc)
|
69
|
* @see org.eclipse.ui.IEditorInput#getName()
|
70
|
*/
|
71
|
/**
|
72
|
* <p>getName</p>
|
73
|
*
|
74
|
* @return a {@link java.lang.String} object.
|
75
|
*/
|
76
|
public String getName() {
|
77
|
return BulkEditorInputType.AGENT.label;
|
78
|
}
|
79
|
|
80
|
/* (non-Javadoc)
|
81
|
* @see org.eclipse.ui.IEditorInput#getToolTipText()
|
82
|
*/
|
83
|
/**
|
84
|
* <p>getToolTipText</p>
|
85
|
*
|
86
|
* @return a {@link java.lang.String} object.
|
87
|
*/
|
88
|
public String getToolTipText() {
|
89
|
return getName();
|
90
|
}
|
91
|
|
92
|
/**
|
93
|
* <p>Getter for the field <code>instance</code>.</p>
|
94
|
*
|
95
|
* @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
|
96
|
*/
|
97
|
public static AbstractBulkEditorInput getInstance() {
|
98
|
if (instance == null) {
|
99
|
instance = new AgentEditorInput();
|
100
|
}
|
101
|
return instance;
|
102
|
}
|
103
|
|
104
|
/* (non-Javadoc)
|
105
|
* @see eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInput#isMergingEnabled()
|
106
|
*/
|
107
|
/** {@inheritDoc} */
|
108
|
@Override
|
109
|
public boolean isMergingEnabled() {
|
110
|
return true;
|
111
|
}
|
112
|
|
113
|
/* (non-Javadoc)
|
114
|
* @see eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInput#isMergingEnabled()
|
115
|
*/
|
116
|
/** {@inheritDoc} */
|
117
|
@Override
|
118
|
public boolean isConvertingEnabled() {
|
119
|
return true;
|
120
|
}
|
121
|
|
122
|
/** {@inheritDoc} */
|
123
|
@Override
|
124
|
public boolean merge(TeamOrPersonBase entity, TeamOrPersonBase mergeTarget) {
|
125
|
if (entity instanceof IMergable) {
|
126
|
try {
|
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",
|
132
|
this,
|
133
|
"Could not merge chosen objects of type " + entity.getClass().getName(),
|
134
|
TaxeditorBulkeditorPlugin.PLUGIN_ID,
|
135
|
e,
|
136
|
true);
|
137
|
}
|
138
|
}
|
139
|
return true;
|
140
|
}
|
141
|
|
142
|
/** {@inheritDoc} */
|
143
|
@Override
|
144
|
public List<TeamOrPersonBase> listEntities(IIdentifiableEntityServiceConfigurator configurator) {
|
145
|
return CdmStore.getSearchManager().findTeamOrPersons(configurator);
|
146
|
}
|
147
|
|
148
|
/** {@inheritDoc}
|
149
|
@Override
|
150
|
public AgentBase loadEntity(UUID uuid) {
|
151
|
List<String> propertyPaths = Arrays.asList(new String[]{});
|
152
|
return CdmStore.getService(IAgentService.class).load(uuid, propertyPaths);
|
153
|
}*/
|
154
|
|
155
|
|
156
|
public boolean delete(AgentBase entity) throws ReferencedObjectUndeletableException {
|
157
|
|
158
|
return CdmStore.getService(IAgentService.class).delete(entity) != null;
|
159
|
|
160
|
}
|
161
|
|
162
|
/** {@inheritDoc} */
|
163
|
public boolean save(AgentBase entity) {
|
164
|
|
165
|
return CdmStore.getService(IAgentService.class).saveOrUpdate(entity) != null;
|
166
|
}
|
167
|
|
168
|
/* (non-Javadoc)
|
169
|
* @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#getSortProviders()
|
170
|
*/
|
171
|
@Override
|
172
|
public List<IBulkEditorSortProvider<TeamOrPersonBase>> getSortProviders() {
|
173
|
List<IBulkEditorSortProvider<TeamOrPersonBase>> sortProviders = super.getSortProviders();
|
174
|
|
175
|
sortProviders.add(0, new IdentifiableEntitySortProvider<TeamOrPersonBase>());
|
176
|
|
177
|
return sortProviders;
|
178
|
}
|
179
|
|
180
|
/* (non-Javadoc)
|
181
|
* @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#createEntityCreator()
|
182
|
*/
|
183
|
@Override
|
184
|
protected IEntityCreator<TeamOrPersonBase> createEntityCreator() {
|
185
|
return new AgentCreator();
|
186
|
}
|
187
|
|
188
|
@Override
|
189
|
public boolean save(TeamOrPersonBase entity) {
|
190
|
// TODO Auto-generated method stub
|
191
|
return false;
|
192
|
}
|
193
|
|
194
|
@Override
|
195
|
public boolean delete(TeamOrPersonBase entity)
|
196
|
throws ReferencedObjectUndeletableException {
|
197
|
// TODO Auto-generated method stub
|
198
|
return false;
|
199
|
}
|
200
|
|
201
|
}
|