3 * Copyright (C) 2015 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.model
;
12 import java
.util
.ArrayList
;
13 import java
.util
.Iterator
;
14 import java
.util
.List
;
16 import org
.eclipse
.core
.runtime
.IStatus
;
17 import org
.eclipse
.core
.runtime
.MultiStatus
;
18 import org
.eclipse
.core
.runtime
.Status
;
20 import eu
.etaxonomy
.cdm
.api
.service
.DeleteResult
;
21 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
22 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
29 public class DeleteResultMessagingUtils
extends MessagingUtils
{
31 * Displays a message {@link org.eclipse.jface.dialogs.MessageDialog}.
37 public static void messageDialogWithDetails(DeleteResult result
, String message
, String pluginId
) {
38 if (result
.isOk() && result
.getExceptions().isEmpty()){
41 List
<String
> details
= new ArrayList
<String
>();
44 if (result
.getExceptions().size() > 0){
45 for (Exception e
:result
.getExceptions()){
46 details
.add(e
.getMessage());
49 title
= "Delete was successfull.";
51 title
= "Delete was aborted.";
54 StringBuffer relatedObjectsString
= new StringBuffer();
55 List
<String
> relatedObjects
= new ArrayList
<String
>();
56 if (result
.getUpdatedObjects().size() > 0){
57 Iterator
<CdmBase
> objects
= result
.getRelatedObjects().iterator();
58 while (objects
.hasNext()){
59 CdmBase object
= objects
.next();
60 if (object
instanceof IdentifiableEntity
){
62 relatedObjects
.add(((IdentifiableEntity
)object
).getTitleCache() );
64 relatedObjects
.add(object
.getUserFriendlyTypeName());
69 for (String relatedObject
: relatedObjects
){
71 relatedObjectsString
.append(relatedObject
);
72 relatedObjectsString
.append(System
.lineSeparator());
75 message
= message
+ "\n" ;
76 String stackTraceWithContext
= getContextInfo(details
);
77 CdmDeleteErrorDialog ced
= new CdmDeleteErrorDialog(AbstractUtility
.getShell(), title
, message
,new Status(IStatus
.INFO
, pluginId
, relatedObjectsString
.toString(), result
.getExceptions().iterator().next()), stackTraceWithContext
, result
.getUpdatedObjects().toArray());
85 public static void messageDialogWithDetails(IStatus result
, String message
, String pluginId
) {
87 List
<String
> details
= new ArrayList
<String
>();
90 if (result
.isMultiStatus()){
91 for (IStatus childStatus
:result
.getChildren()){
92 details
.add(childStatus
.getMessage());
94 e
= result
.getChildren()[0].getException();
95 if (result
.equals(Status
.OK_STATUS
)|| result
.equals(Status
.WARNING
)){
96 title
= "Delete was successfull.";
98 title
= "Delete was aborted.";
101 StringBuffer relatedObjectsString
= new StringBuffer();
102 Object
[] relatedObjects
= new ArrayList
<Object
>().toArray();
106 String stackTraceWithContext
= getContextInfo(details
);
107 CdmDeleteErrorDialog ced
= new CdmDeleteErrorDialog(AbstractUtility
.getShell(), title
, message
,new Status(IStatus
.INFO
, pluginId
, null, e
), stackTraceWithContext
, relatedObjects
);