Revision 3be6ef3e
Added by Niels Hoffmann over 13 years ago
taxeditor-bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/AbstractBulkEditorInput.java | ||
---|---|---|
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 |
* @author p.ciardelli |
|
37 |
* @created 25.06.2009 |
|
38 |
* @version 1.0 |
|
39 |
* @param <T> |
|
40 |
*/ |
|
41 |
public abstract class AbstractBulkEditorInput<T> extends PropertyChangeSupport implements IEditorInput, IEntityPersistenceService { |
|
42 |
private static final Logger logger = Logger |
|
43 |
.getLogger(AbstractBulkEditorInput.class); |
|
44 |
/** |
|
45 |
* |
|
46 |
*/ |
|
47 |
private static final long serialVersionUID = 416414530232743735L; |
|
48 |
private String mode; |
|
49 |
private UUID entityUuid; |
|
50 |
|
|
51 |
/** |
|
52 |
* @param sourceBean |
|
53 |
*/ |
|
54 |
public AbstractBulkEditorInput(Object sourceBean) { |
|
55 |
super(sourceBean); |
|
56 |
} |
|
57 |
|
|
58 |
public static final String QUERY_CHANGED = "query_changed"; |
|
59 |
|
|
60 |
static public AbstractBulkEditorInput NewInstance(BulkEditorInputType inputType) { |
|
61 |
return BulkEditorInputType.getInput(inputType); |
|
62 |
} |
|
63 |
|
|
64 |
public static AbstractBulkEditorInput NewInstance(IdentifiableEntity entity) { |
|
65 |
|
|
66 |
|
|
67 |
BulkEditorInputType inputType = BulkEditorInputType.getByType(entity.getClass()); |
|
68 |
|
|
69 |
AbstractBulkEditorInput editorInput = NewInstance(inputType); |
|
70 |
|
|
71 |
editorInput.setEntityUuid(entity.getUuid()); |
|
72 |
|
|
73 |
return editorInput; |
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* Queries the service for entities that match the criterias defined in the given |
|
78 |
* search configurator |
|
79 |
* |
|
80 |
* @param configurator |
|
81 |
* @return |
|
82 |
*/ |
|
83 |
public List<T> listEntities(){ |
|
84 |
if(getEntityUuid() != null){ |
|
85 |
List<T> entityList = new ArrayList<T>(); |
|
86 |
T entity = loadEntity(getEntityUuid()); |
|
87 |
entityList.add(entity); |
|
88 |
return entityList; |
|
89 |
} |
|
90 |
|
|
91 |
if(query != null){ |
|
92 |
|
|
93 |
String queryString = query.getSearchString(); |
|
94 |
IIdentifiableEntityServiceConfigurator configurator = query.getSearchConfigurator(); |
|
95 |
Comparator queryComparator = (query.getComparator() != null) ? query.getComparator() : new IdentifiableEntityComparator(); |
|
96 |
|
|
97 |
List<T> entityList = listEntities(configurator); |
|
98 |
|
|
99 |
Collections.sort(entityList, queryComparator); |
|
100 |
|
|
101 |
// reset query |
|
102 |
setQuery(null); |
|
103 |
|
|
104 |
return entityList; |
|
105 |
} |
|
106 |
return null; |
|
107 |
} |
|
108 |
|
|
109 |
protected abstract List<T> listEntities(IIdentifiableEntityServiceConfigurator configurator); |
|
110 |
|
|
111 |
protected abstract T loadEntity(UUID entityUuid); |
|
112 |
|
|
113 |
private void setEntityUuid(UUID entityUuid){ |
|
114 |
this.entityUuid = entityUuid; |
|
115 |
} |
|
116 |
|
|
117 |
public UUID getEntityUuid() { |
|
118 |
return entityUuid; |
|
119 |
} |
|
120 |
|
|
121 |
private IBulkEditorQuery query; |
|
122 |
|
|
123 |
/* (non-Javadoc) |
|
124 |
* @see org.eclipse.ui.IEditorInput#exists() |
|
125 |
*/ |
|
126 |
public boolean exists() { |
|
127 |
// TODO Auto-generated method stub |
|
128 |
return false; |
|
129 |
} |
|
130 |
|
|
131 |
/* (non-Javadoc) |
|
132 |
* @see org.eclipse.ui.IEditorInput#getImageDescriptor() |
|
133 |
*/ |
|
134 |
public ImageDescriptor getImageDescriptor() { |
|
135 |
// TODO Auto-generated method stub |
|
136 |
return null; |
|
137 |
} |
|
138 |
|
|
139 |
/* (non-Javadoc) |
|
140 |
* @see org.eclipse.ui.IEditorInput#getPersistable() |
|
141 |
*/ |
|
142 |
public IPersistableElement getPersistable() { |
|
143 |
return null; |
|
144 |
} |
|
145 |
|
|
146 |
/* (non-Javadoc) |
|
147 |
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) |
|
148 |
*/ |
|
149 |
@SuppressWarnings("unchecked") |
|
150 |
public Object getAdapter(Class adapter) { |
|
151 |
return null; |
|
152 |
} |
|
153 |
|
|
154 |
/** |
|
155 |
* @param bulkEditorQuery |
|
156 |
*/ |
|
157 |
public void setQuery(IBulkEditorQuery bulkEditorQuery) { |
|
158 |
|
|
159 |
this.query = bulkEditorQuery; |
|
160 |
|
|
161 |
if (query != null) { |
|
162 |
firePropertyChange(QUERY_CHANGED, null, null); |
|
163 |
} |
|
164 |
} |
|
165 |
|
|
166 |
public IBulkEditorQuery getQuery() { |
|
167 |
return query; |
|
168 |
} |
|
169 |
|
|
170 |
public boolean isMergingEnabled() { |
|
171 |
return false; |
|
172 |
} |
|
173 |
|
|
174 |
/** |
|
175 |
* @param markerType |
|
176 |
* @return |
|
177 |
*/ |
|
178 |
public boolean isMarkerTypeEditingEnabled(MarkerType markerType) { |
|
179 |
return false; |
|
180 |
} |
|
181 |
|
|
182 |
public boolean isSingleEntityMode(){ |
|
183 |
return getEntityUuid() != null; |
|
184 |
} |
|
185 |
|
|
186 |
/* |
|
187 |
* (non-Javadoc) |
|
188 |
* @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#merge(eu.etaxonomy.cdm.model.common.IdentifiableEntity, eu.etaxonomy.cdm.model.common.IdentifiableEntity) |
|
189 |
*/ |
|
190 |
public boolean merge(Object entity, Object mergeTarget) { |
|
191 |
logger.info("Merge " + entity + " into " + mergeTarget); |
|
192 |
if (entity instanceof ReferenceBase) { |
|
193 |
try { |
|
194 |
CdmStore.getCommonService().merge((ReferenceBase) mergeTarget, (ReferenceBase) entity, null); |
|
195 |
} catch (MergeException e) { |
|
196 |
logger.error("Problems merging objects", e); |
|
197 |
} |
|
198 |
} |
|
199 |
return true; |
|
200 |
}; |
|
201 |
|
|
202 |
/* |
|
203 |
* (non-Javadoc) |
|
204 |
* @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#create(eu.etaxonomy.cdm.model.common.IdentifiableEntity) |
|
205 |
*/ |
|
206 |
public boolean create(Object entity) { |
|
207 |
return save(entity); |
|
208 |
}; |
|
209 |
} |
|
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 |
} |
Also available in: Unified diff
performed javacscript:fix and worked on documentation