2 * Copyright (C) 2015 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.model
;
11 import java
.util
.ArrayList
;
12 import java
.util
.Iterator
;
13 import java
.util
.List
;
15 import org
.eclipse
.core
.runtime
.IStatus
;
16 import org
.eclipse
.core
.runtime
.Status
;
18 import eu
.etaxonomy
.cdm
.api
.service
.DeleteResult
;
19 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
20 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
27 public class DeleteResultMessagingUtils
extends MessagingUtils
{
29 * Displays a message {@link org.eclipse.jface.dialogs.MessageDialog}.
35 public static void messageDialogWithDetails(DeleteResult result
, String message
, String pluginId
) {
36 if (result
.isOk() && result
.getExceptions().isEmpty()){
39 List
<String
> details
= new ArrayList
<String
>();
42 if (result
.getExceptions().size() > 0){
43 for (Exception e
:result
.getExceptions()){
44 details
.add(e
.getMessage());
47 title
= "Delete was successfull";
49 title
= "Delete was aborted";
52 StringBuffer relatedObjectsString
= new StringBuffer();
53 List
<String
> relatedObjects
= new ArrayList
<String
>();
54 if (result
.getUpdatedObjects().size() > 0){
55 Iterator
<CdmBase
> objects
= result
.getRelatedObjects().iterator();
56 while (objects
.hasNext()){
57 CdmBase object
= objects
.next();
58 if (object
instanceof IdentifiableEntity
){
60 relatedObjects
.add(((IdentifiableEntity
)object
).getTitleCache() );
62 relatedObjects
.add(object
.getUserFriendlyTypeName());
67 for (String relatedObject
: relatedObjects
){
69 relatedObjectsString
.append(relatedObject
);
70 relatedObjectsString
.append(System
.lineSeparator());
73 message
= message
+ "\n" ;
74 String stackTraceWithContext
= getContextInfo(details
);
75 CdmDeleteErrorDialog ced
= new CdmDeleteErrorDialog(AbstractUtility
.getShell(), title
, message
,new Status(IStatus
.INFO
, pluginId
, relatedObjectsString
.toString(), result
.getExceptions().iterator().next()), stackTraceWithContext
, result
.getUpdatedObjects().toArray());
83 public static void messageDialogWithDetails(IStatus result
, String message
, String pluginId
) {
85 List
<String
> details
= new ArrayList
<String
>();
88 if (result
.isMultiStatus()){
89 for (IStatus childStatus
:result
.getChildren()){
90 details
.add(childStatus
.getMessage());
92 e
= result
.getChildren()[0].getException();
93 if (result
.equals(Status
.OK_STATUS
)|| result
.equals(Status
.WARNING
)){
94 title
= "Delete was successfull";
96 title
= "Delete was aborted";
99 StringBuffer relatedObjectsString
= new StringBuffer();
100 Object
[] relatedObjects
= new ArrayList
<Object
>().toArray();
104 String stackTraceWithContext
= getContextInfo(details
);
105 CdmDeleteErrorDialog ced
= new CdmDeleteErrorDialog(AbstractUtility
.getShell(), title
, message
,new Status(IStatus
.INFO
, pluginId
, null, e
), stackTraceWithContext
, relatedObjects
);