Revision dda1d525
Added by Katja Luther about 7 years ago
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/referencingobjects/ReferencingObjectsView.java | ||
---|---|---|
39 | 39 |
import org.eclipse.swt.widgets.Menu; |
40 | 40 |
import org.eclipse.swt.widgets.Table; |
41 | 41 |
import org.eclipse.ui.IWorkbenchPart; |
42 |
import org.springframework.remoting.RemoteAccessException; |
|
42 | 43 |
|
43 | 44 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
44 | 45 |
import eu.etaxonomy.cdm.api.service.IAgentService; |
... | ... | |
94 | 95 |
private String referencedObjectTitleCache; |
95 | 96 |
private ConversationHolder conversation; |
96 | 97 |
private final ICdmEntitySession cdmEntitySession; |
98 |
private UUID actualUuid; |
|
99 |
List<CdmBase> referencingObjects = null; |
|
100 |
Set<CdmBase> referencingObjectsSet = null; |
|
101 |
IProgressMonitor actualMonitor = null; |
|
97 | 102 |
|
98 | 103 |
public ReferencingObjectsView() { |
99 | 104 |
cdmEntitySession = CdmStore.getCurrentSessionManager().bindNullSession(); |
... | ... | |
178 | 183 |
} |
179 | 184 |
|
180 | 185 |
public void updateReferencingObjects(final UUID entityUUID, final Class objectClass) { |
186 |
if (actualUuid == entityUUID){ |
|
187 |
return ; |
|
188 |
} |
|
181 | 189 |
|
182 |
final Display display = Display.getCurrent(); |
|
183 |
|
|
184 |
Job job = new Job("Update Referencing Objects") { |
|
190 |
Job job = new Job("Update Referencing Objects " + entityUUID) { |
|
185 | 191 |
|
186 | 192 |
@Override |
187 | 193 |
protected IStatus run(IProgressMonitor monitor) { |
188 |
monitor.beginTask("Calculating referencing objects", 10); |
|
189 |
|
|
190 |
monitor.worked(3); |
|
191 |
|
|
192 |
display.asyncExec(new Runnable() { |
|
193 |
|
|
194 |
@Override |
|
195 |
public void run() { |
|
196 |
if (entityUUID != null){ |
|
197 |
ICdmEntitySession previousCdmEntitySession = CdmStore.getCurrentSessionManager().getActiveSession(); |
|
198 |
cdmEntitySession.bind(); |
|
199 |
List<CdmBase> referencingObjects = getReferencingObjects(entityUUID, objectClass); |
|
200 |
if(previousCdmEntitySession != null) { |
|
201 |
previousCdmEntitySession.bind(); |
|
202 |
} |
|
203 |
updateView(referencingObjects); |
|
204 |
|
|
205 |
} |
|
206 |
} |
|
207 |
}); |
|
194 |
monitor.beginTask("Calculating referencing objects", 100); |
|
208 | 195 |
|
196 |
monitor.worked(5); |
|
197 |
referencingObjects = new ArrayList<>(); |
|
198 |
if(monitor.isCanceled()) { |
|
199 |
return Status.CANCEL_STATUS; |
|
200 |
} |
|
201 |
if (actualMonitor != null){ |
|
202 |
actualMonitor.setCanceled(true); |
|
203 |
updateView(); |
|
204 |
} |
|
205 |
actualMonitor = monitor; |
|
206 |
if (entityUUID != null){ |
|
207 |
ICdmEntitySession previousCdmEntitySession = CdmStore.getCurrentSessionManager().getActiveSession(); |
|
208 |
cdmEntitySession.bind(); |
|
209 |
referencingObjectsSet = getReferencingObjects(entityUUID, objectClass); |
|
210 |
|
|
211 |
if(monitor.isCanceled()) { |
|
212 |
return Status.CANCEL_STATUS; |
|
213 |
} |
|
214 |
monitor.worked(30); |
|
215 |
referencingObjects = sortReferencing(); |
|
216 |
if (referencingObjects == null){ |
|
217 |
if (monitor.isCanceled()){ |
|
218 |
return Status.CANCEL_STATUS; |
|
219 |
} |
|
220 |
} |
|
221 |
|
|
222 |
if(monitor.isCanceled()) { |
|
223 |
|
|
224 |
return Status.CANCEL_STATUS; |
|
225 |
} |
|
226 |
monitor.worked(80); |
|
227 |
updateView(); |
|
228 |
|
|
229 |
if(previousCdmEntitySession != null) { |
|
230 |
previousCdmEntitySession.bind(); |
|
231 |
} |
|
232 |
actualUuid = entityUUID; |
|
233 |
} |
|
209 | 234 |
monitor.done(); |
210 | 235 |
|
211 | 236 |
|
212 | 237 |
return Status.OK_STATUS; |
238 |
|
|
239 |
|
|
213 | 240 |
} |
214 | 241 |
}; |
242 |
//job.setUser(true); |
|
215 | 243 |
|
216 |
job.setPriority(Job.DECORATE); |
|
217 | 244 |
job.schedule(); |
245 |
// final IJobChangeListener listener; |
|
246 |
// listener = new JobChangeAdapter() { |
|
247 |
// @Override |
|
248 |
// public void done(IJobChangeEvent event) { |
|
249 |
// System.err.println("Job is done"); |
|
250 |
// event.getJob().cancel(); |
|
251 |
// } |
|
252 |
// |
|
253 |
// }; |
|
254 |
// job.addJobChangeListener(listener); |
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
|
218 | 259 |
} |
219 | 260 |
|
220 |
private List<CdmBase> getReferencingObjects(UUID entity, Class objectClass) {
|
|
261 |
private Set<CdmBase> getReferencingObjects(UUID entity, Class objectClass) {
|
|
221 | 262 |
CdmBase referencedObject = null; |
222 | 263 |
try { |
223 | 264 |
if (objectClass.getSuperclass().equals(TeamOrPersonBase.class) ){ |
... | ... | |
268 | 309 |
else if(referencedObject.isInstanceOf(DescriptionElementBase.class)){ |
269 | 310 |
referencedObjectTitleCache = DescriptionHelper.getLabel(referencedObject); |
270 | 311 |
} |
271 |
else{ |
|
312 |
else if (referencedObject.isInstanceOf(User.class)){ |
|
313 |
referencedObjectTitleCache = ((User)referencedObject).getUsername(); |
|
314 |
}else{ |
|
272 | 315 |
referencedObjectTitleCache = null; |
273 | 316 |
} |
274 | 317 |
setOfReferencingObjects = CdmStore.getCommonService().getReferencingObjects(referencedObject); |
318 |
return setOfReferencingObjects; |
|
275 | 319 |
} |
276 |
if (setOfReferencingObjects != null){ |
|
277 |
List<CdmBase> referencingObjects = new ArrayList<CdmBase>(setOfReferencingObjects); |
|
278 | 320 |
|
279 |
Collections.sort(referencingObjects, new ReferencingClassComparator()); |
|
280 |
|
|
281 |
return referencingObjects; |
|
282 |
|
|
283 |
} |
|
284 | 321 |
} catch (Exception e) { |
285 | 322 |
logger.error("Error retrieving referencing objects", e); |
323 |
e.printStackTrace(); |
|
286 | 324 |
setContentDescription("The referencing objects view could not be loaded completely. Some Problems occured."); |
287 | 325 |
} |
288 | 326 |
return null; |
289 | 327 |
} |
328 |
private List<CdmBase> sortReferencing(){ |
|
329 |
|
|
330 |
if (referencingObjectsSet != null){ |
|
331 |
List<CdmBase> referencingObjects = new ArrayList<CdmBase>(referencingObjectsSet); |
|
332 |
try{ |
|
333 |
Collections.sort(referencingObjects, new ReferencingClassComparator()); |
|
334 |
}catch (RemoteAccessException e){ |
|
335 |
return null; |
|
336 |
} |
|
337 |
return referencingObjects; |
|
338 |
|
|
339 |
} |
|
340 |
|
|
341 |
return null; |
|
342 |
} |
|
343 |
|
|
290 | 344 |
|
291 | 345 |
class ReferencingClassComparator implements Comparator<CdmBase> { |
292 | 346 |
|
... | ... | |
298 | 352 |
if (classCompare == 0) { |
299 | 353 |
string1 = DescriptionHelper.getObjectDescription(o1); |
300 | 354 |
string2 = DescriptionHelper.getObjectDescription(o2); |
355 |
|
|
301 | 356 |
return string1.compareToIgnoreCase(string2); |
302 | 357 |
} else { |
303 | 358 |
return classCompare; |
... | ... | |
305 | 360 |
} |
306 | 361 |
} |
307 | 362 |
|
308 |
private void updateView(List<CdmBase> referencingObjects) { |
|
309 |
if (viewer != null && !viewer.getControl().isDisposed()){ |
|
310 |
try{ |
|
311 |
viewer.setInput(referencingObjects); |
|
312 |
if (referencedObjectTitleCache != null){ |
|
313 |
setContentDescription("'" + referencedObjectTitleCache + "' is referenced by:"); |
|
314 |
} else { |
|
315 |
setContentDescription(""); |
|
316 |
} |
|
317 |
showViewer(); |
|
318 |
//enable/disable table |
|
319 |
viewer.getControl().setEnabled(referencingObjects!=null); |
|
320 |
}catch(Exception e){ |
|
321 |
setContentDescription("The referencing objects view could not be loaded completely. Some Problems occured."); |
|
322 |
} |
|
323 |
|
|
324 |
} |
|
363 |
private void updateView() { |
|
364 |
Display.getDefault().asyncExec(new Runnable() { |
|
365 |
@Override |
|
366 |
public void run() { |
|
367 |
if (viewer != null && !viewer.getControl().isDisposed()){ |
|
368 |
try{ |
|
369 |
viewer.setInput(referencingObjects); |
|
370 |
if (referencedObjectTitleCache != null){ |
|
371 |
setContentDescription("'" + referencedObjectTitleCache + "' is referenced by:"); |
|
372 |
} else { |
|
373 |
setContentDescription(""); |
|
374 |
} |
|
375 |
showViewer(); |
|
376 |
getViewSite().getActionBars().getStatusLineManager(). |
|
377 |
setMessage("End Updating Referencing Objects"); |
|
378 |
//enable/disable table |
|
379 |
viewer.getControl().setEnabled(referencingObjects!=null); |
|
380 |
|
|
381 |
}catch(Exception e){ |
|
382 |
e.printStackTrace(); |
|
383 |
setContentDescription("The referencing objects view could not be loaded completely. Some Problems occured."); |
|
384 |
} |
|
385 |
|
|
386 |
} |
|
387 |
} |
|
388 |
}); |
|
325 | 389 |
} |
326 | 390 |
|
327 | 391 |
/** {@inheritDoc} */ |
... | ... | |
330 | 394 |
if(part == this){ |
331 | 395 |
return; |
332 | 396 |
} |
397 |
|
|
333 | 398 |
if(selection instanceof IStructuredSelection){ |
334 | 399 |
referencedObjectTitleCache = null; |
335 | 400 |
showViewer(part, (IStructuredSelection) selection); |
... | ... | |
346 | 411 |
firstElement = ((TreeNode) firstElement).getValue(); |
347 | 412 |
} |
348 | 413 |
if(firstElement instanceof CdmBase){ |
349 |
updateReferencingObjects(((CdmBase) firstElement).getUuid(),firstElement.getClass() ); |
|
414 |
CdmBase referencedCdmObject = (CdmBase) firstElement; |
|
415 |
if (referencedCdmObject != null){ |
|
416 |
if(referencedCdmObject.isInstanceOf(IdentifiableEntity.class)){ |
|
417 |
referencedObjectTitleCache = (HibernateProxyHelper.deproxy(referencedCdmObject, IdentifiableEntity.class)).getTitleCache(); |
|
418 |
} |
|
419 |
else if(referencedCdmObject.isInstanceOf(DescriptionElementBase.class)){ |
|
420 |
referencedObjectTitleCache = DescriptionHelper.getLabel(referencedCdmObject); |
|
421 |
} |
|
422 |
else if (referencedCdmObject.isInstanceOf(User.class)){ |
|
423 |
referencedObjectTitleCache = ((User)referencedCdmObject).getUsername(); |
|
424 |
}else{ |
|
425 |
referencedObjectTitleCache = null; |
|
426 |
} |
|
427 |
} |
|
428 |
updateReferencingObjects(referencedCdmObject.getUuid(),firstElement.getClass() ); |
|
429 |
|
|
350 | 430 |
} |
351 | 431 |
else{ |
352 |
updateView(null);
|
|
432 |
updateView(); |
|
353 | 433 |
setContentDescription(""); |
354 | 434 |
} |
355 | 435 |
} |
Also available in: Unified diff
ref #5691: fix the problem that ref. objects view does not has its own thread