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