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.beans.PropertyChangeSupport;
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.Collections;
|
15
|
import java.util.Comparator;
|
16
|
import java.util.List;
|
17
|
import java.util.UUID;
|
18
|
|
19
|
import org.apache.log4j.Logger;
|
20
|
import org.eclipse.jface.resource.ImageDescriptor;
|
21
|
import org.eclipse.ui.IEditorInput;
|
22
|
import org.eclipse.ui.IPersistableElement;
|
23
|
|
24
|
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
|
25
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
26
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
27
|
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
|
28
|
import eu.etaxonomy.cdm.strategy.merge.MergeException;
|
29
|
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService;
|
30
|
import eu.etaxonomy.taxeditor.annotatedlineeditor.IdentifiableEntityComparator;
|
31
|
import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorQuery;
|
32
|
import eu.etaxonomy.taxeditor.bulkeditor.command.BulkEditorInputTypeValues.BulkEditorInputType;
|
33
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
34
|
|
35
|
/**
|
36
|
* <p>Abstract AbstractBulkEditorInput class.</p>
|
37
|
*
|
38
|
* @author p.ciardelli
|
39
|
* @created 25.06.2009
|
40
|
* @version 1.0
|
41
|
* @param <T>
|
42
|
*/
|
43
|
public abstract class AbstractBulkEditorInput<T> extends PropertyChangeSupport implements IEditorInput, IEntityPersistenceService {
|
44
|
private static final Logger logger = Logger
|
45
|
.getLogger(AbstractBulkEditorInput.class);
|
46
|
/**
|
47
|
*
|
48
|
*/
|
49
|
private static final long serialVersionUID = 416414530232743735L;
|
50
|
private String mode;
|
51
|
private UUID entityUuid;
|
52
|
|
53
|
/**
|
54
|
* <p>Constructor for AbstractBulkEditorInput.</p>
|
55
|
*
|
56
|
* @param sourceBean a {@link java.lang.Object} object.
|
57
|
* @param <T> a T object.
|
58
|
*/
|
59
|
public AbstractBulkEditorInput(Object sourceBean) {
|
60
|
super(sourceBean);
|
61
|
}
|
62
|
|
63
|
/** Constant <code>QUERY_CHANGED="query_changed"</code> */
|
64
|
public static final String QUERY_CHANGED = "query_changed";
|
65
|
|
66
|
/**
|
67
|
* <p>NewInstance</p>
|
68
|
*
|
69
|
* @param inputType a {@link eu.etaxonomy.taxeditor.bulkeditor.command.BulkEditorInputTypeValues.BulkEditorInputType} object.
|
70
|
* @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
|
71
|
*/
|
72
|
static public AbstractBulkEditorInput NewInstance(BulkEditorInputType inputType) {
|
73
|
return BulkEditorInputType.getInput(inputType);
|
74
|
}
|
75
|
|
76
|
/**
|
77
|
* <p>NewInstance</p>
|
78
|
*
|
79
|
* @param entity a {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity} object.
|
80
|
* @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
|
81
|
*/
|
82
|
public static AbstractBulkEditorInput NewInstance(IdentifiableEntity entity) {
|
83
|
|
84
|
|
85
|
BulkEditorInputType inputType = BulkEditorInputType.getByType(entity.getClass());
|
86
|
|
87
|
AbstractBulkEditorInput editorInput = NewInstance(inputType);
|
88
|
|
89
|
editorInput.setEntityUuid(entity.getUuid());
|
90
|
|
91
|
return editorInput;
|
92
|
}
|
93
|
|
94
|
/**
|
95
|
* Queries the service for entities that match the criterias defined in the given
|
96
|
* search configurator
|
97
|
*
|
98
|
* @return a {@link java.util.List} object.
|
99
|
*/
|
100
|
public List<T> listEntities(){
|
101
|
if(getEntityUuid() != null){
|
102
|
List<T> entityList = new ArrayList<T>();
|
103
|
T entity = loadEntity(getEntityUuid());
|
104
|
entityList.add(entity);
|
105
|
return entityList;
|
106
|
}
|
107
|
|
108
|
if(query != null){
|
109
|
|
110
|
String queryString = query.getSearchString();
|
111
|
IIdentifiableEntityServiceConfigurator configurator = query.getSearchConfigurator();
|
112
|
Comparator queryComparator = (query.getComparator() != null) ? query.getComparator() : new IdentifiableEntityComparator();
|
113
|
|
114
|
List<T> entityList = listEntities(configurator);
|
115
|
|
116
|
Collections.sort(entityList, queryComparator);
|
117
|
|
118
|
// reset query
|
119
|
setQuery(null);
|
120
|
|
121
|
return entityList;
|
122
|
}
|
123
|
return null;
|
124
|
}
|
125
|
|
126
|
/**
|
127
|
* <p>listEntities</p>
|
128
|
*
|
129
|
* @param configurator a {@link eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator} object.
|
130
|
* @return a {@link java.util.List} object.
|
131
|
*/
|
132
|
protected abstract List<T> listEntities(IIdentifiableEntityServiceConfigurator configurator);
|
133
|
|
134
|
/**
|
135
|
* <p>loadEntity</p>
|
136
|
*
|
137
|
* @param entityUuid a {@link java.util.UUID} object.
|
138
|
* @return a T object.
|
139
|
*/
|
140
|
protected abstract T loadEntity(UUID entityUuid);
|
141
|
|
142
|
private void setEntityUuid(UUID entityUuid){
|
143
|
this.entityUuid = entityUuid;
|
144
|
}
|
145
|
|
146
|
/**
|
147
|
* <p>Getter for the field <code>entityUuid</code>.</p>
|
148
|
*
|
149
|
* @return a {@link java.util.UUID} object.
|
150
|
*/
|
151
|
public UUID getEntityUuid() {
|
152
|
return entityUuid;
|
153
|
}
|
154
|
|
155
|
private IBulkEditorQuery query;
|
156
|
|
157
|
/* (non-Javadoc)
|
158
|
* @see org.eclipse.ui.IEditorInput#exists()
|
159
|
*/
|
160
|
/**
|
161
|
* <p>exists</p>
|
162
|
*
|
163
|
* @return a boolean.
|
164
|
*/
|
165
|
public boolean exists() {
|
166
|
// TODO Auto-generated method stub
|
167
|
return false;
|
168
|
}
|
169
|
|
170
|
/* (non-Javadoc)
|
171
|
* @see org.eclipse.ui.IEditorInput#getImageDescriptor()
|
172
|
*/
|
173
|
/**
|
174
|
* <p>getImageDescriptor</p>
|
175
|
*
|
176
|
* @return a {@link org.eclipse.jface.resource.ImageDescriptor} object.
|
177
|
*/
|
178
|
public ImageDescriptor getImageDescriptor() {
|
179
|
// TODO Auto-generated method stub
|
180
|
return null;
|
181
|
}
|
182
|
|
183
|
/* (non-Javadoc)
|
184
|
* @see org.eclipse.ui.IEditorInput#getPersistable()
|
185
|
*/
|
186
|
/**
|
187
|
* <p>getPersistable</p>
|
188
|
*
|
189
|
* @return a {@link org.eclipse.ui.IPersistableElement} object.
|
190
|
*/
|
191
|
public IPersistableElement getPersistable() {
|
192
|
return null;
|
193
|
}
|
194
|
|
195
|
/* (non-Javadoc)
|
196
|
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
|
197
|
*/
|
198
|
/** {@inheritDoc} */
|
199
|
@SuppressWarnings("unchecked")
|
200
|
public Object getAdapter(Class adapter) {
|
201
|
return null;
|
202
|
}
|
203
|
|
204
|
/**
|
205
|
* <p>Setter for the field <code>query</code>.</p>
|
206
|
*
|
207
|
* @param bulkEditorQuery a {@link eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorQuery} object.
|
208
|
*/
|
209
|
public void setQuery(IBulkEditorQuery bulkEditorQuery) {
|
210
|
|
211
|
this.query = bulkEditorQuery;
|
212
|
|
213
|
if (query != null) {
|
214
|
firePropertyChange(QUERY_CHANGED, null, null);
|
215
|
}
|
216
|
}
|
217
|
|
218
|
/**
|
219
|
* <p>Getter for the field <code>query</code>.</p>
|
220
|
*
|
221
|
* @return a {@link eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorQuery} object.
|
222
|
*/
|
223
|
public IBulkEditorQuery getQuery() {
|
224
|
return query;
|
225
|
}
|
226
|
|
227
|
/**
|
228
|
* <p>isMergingEnabled</p>
|
229
|
*
|
230
|
* @return a boolean.
|
231
|
*/
|
232
|
public boolean isMergingEnabled() {
|
233
|
return false;
|
234
|
}
|
235
|
|
236
|
/**
|
237
|
* <p>isMarkerTypeEditingEnabled</p>
|
238
|
*
|
239
|
* @param markerType a {@link eu.etaxonomy.cdm.model.common.MarkerType} object.
|
240
|
* @return a boolean.
|
241
|
*/
|
242
|
public boolean isMarkerTypeEditingEnabled(MarkerType markerType) {
|
243
|
return false;
|
244
|
}
|
245
|
|
246
|
/**
|
247
|
* <p>isSingleEntityMode</p>
|
248
|
*
|
249
|
* @return a boolean.
|
250
|
*/
|
251
|
public boolean isSingleEntityMode(){
|
252
|
return getEntityUuid() != null;
|
253
|
}
|
254
|
|
255
|
/*
|
256
|
* (non-Javadoc)
|
257
|
* @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#merge(eu.etaxonomy.cdm.model.common.IdentifiableEntity, eu.etaxonomy.cdm.model.common.IdentifiableEntity)
|
258
|
*/
|
259
|
/** {@inheritDoc} */
|
260
|
public boolean merge(Object entity, Object mergeTarget) {
|
261
|
logger.info("Merge " + entity + " into " + mergeTarget);
|
262
|
if (entity instanceof ReferenceBase) {
|
263
|
try {
|
264
|
CdmStore.getCommonService().merge((ReferenceBase) mergeTarget, (ReferenceBase) entity, null);
|
265
|
} catch (MergeException e) {
|
266
|
logger.error("Problems merging objects", e);
|
267
|
}
|
268
|
}
|
269
|
return true;
|
270
|
};
|
271
|
|
272
|
/*
|
273
|
* (non-Javadoc)
|
274
|
* @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#create(eu.etaxonomy.cdm.model.common.IdentifiableEntity)
|
275
|
*/
|
276
|
/** {@inheritDoc} */
|
277
|
public boolean create(Object entity) {
|
278
|
return save(entity);
|
279
|
};
|
280
|
}
|