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
.MultiStatus
;
17 import org
.eclipse
.core
.runtime
.Status
;
19 import eu
.etaxonomy
.cdm
.api
.service
.DeleteResult
;
20 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
21 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
28 public class DeleteResultMessagingUtils
extends MessagingUtils
{
30 * Displays a message {@link org.eclipse.jface.dialogs.MessageDialog}.
36 public static void messageDialogWithDetails(DeleteResult result
, String message
, String pluginId
) {
37 if (result
.isOk() && result
.getExceptions().isEmpty()){
40 List
<String
> details
= new ArrayList
<String
>();
43 if (result
.getExceptions().size() > 0){
44 for (Exception e
:result
.getExceptions()){
45 details
.add(e
.getMessage());
48 title
= "Delete was successfull.";
50 title
= "Delete was aborted.";
53 StringBuffer relatedObjectsString
= new StringBuffer();
54 List
<String
> relatedObjects
= new ArrayList
<String
>();
55 if (result
.getUpdatedObjects().size() > 0){
56 Iterator
<CdmBase
> objects
= result
.getRelatedObjects().iterator();
57 while (objects
.hasNext()){
58 CdmBase object
= objects
.next();
59 if (object
instanceof IdentifiableEntity
){
61 relatedObjects
.add(((IdentifiableEntity
)object
).getTitleCache() );
63 relatedObjects
.add(object
.getUserFriendlyTypeName());
68 for (String relatedObject
: relatedObjects
){
70 relatedObjectsString
.append(relatedObject
);
71 relatedObjectsString
.append(System
.lineSeparator());
74 message
= message
+ "\n" ;
75 String stackTraceWithContext
= getContextInfo(details
);
76 CdmDeleteErrorDialog ced
= new CdmDeleteErrorDialog(AbstractUtility
.getShell(), title
, message
,new Status(IStatus
.INFO
, pluginId
, relatedObjectsString
.toString(), result
.getExceptions().iterator().next()), stackTraceWithContext
, result
.getUpdatedObjects().toArray());
84 public static void messageDialogWithDetails(IStatus result
, String message
, String pluginId
) {
86 List
<String
> details
= new ArrayList
<String
>();
89 if (result
.isMultiStatus()){
90 for (IStatus childStatus
:result
.getChildren()){
91 details
.add(childStatus
.getMessage());
93 e
= result
.getChildren()[0].getException();
94 if (result
.equals(Status
.OK_STATUS
)|| result
.equals(Status
.WARNING
)){
95 title
= "Delete was successfull.";
97 title
= "Delete was aborted.";
100 StringBuffer relatedObjectsString
= new StringBuffer();
101 Object
[] relatedObjects
= new ArrayList
<Object
>().toArray();
105 String stackTraceWithContext
= getContextInfo(details
);
106 CdmDeleteErrorDialog ced
= new CdmDeleteErrorDialog(AbstractUtility
.getShell(), title
, message
,new Status(IStatus
.INFO
, pluginId
, null, e
), stackTraceWithContext
, relatedObjects
);