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
;
21 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
28 public class DeleteResultMessagingUtils
extends MessagingUtils
{
30 private static final String DELETE_WAS_ABORTED
= Messages
.DeleteResultMessagingUtils_ABORT
;
31 private static final String DELETE_WAS_SUCCESSFULL
= Messages
.DeleteResultMessagingUtils_SUCCES
;
34 * Displays a message {@link org.eclipse.jface.dialogs.MessageDialog}.
40 public static void messageDialogWithDetails(DeleteResult result
, String message
, String pluginId
) {
41 if (result
.isOk() && result
.getExceptions().isEmpty()){
44 List
<String
> details
= new ArrayList
<String
>();
45 String title
= ""; //$NON-NLS-1$
47 if (result
.getExceptions().size() > 0){
48 for (Exception e
:result
.getExceptions()){
49 details
.add(e
.getMessage());
52 title
= DELETE_WAS_SUCCESSFULL
;
54 title
= DELETE_WAS_ABORTED
;
57 StringBuffer relatedObjectsString
= new StringBuffer();
58 List
<String
> relatedObjects
= new ArrayList
<String
>();
59 if (result
.getUpdatedObjects().size() > 0){
60 Iterator
<CdmBase
> objects
= result
.getRelatedObjects().iterator();
61 while (objects
.hasNext()){
62 CdmBase object
= objects
.next();
63 if (object
instanceof IdentifiableEntity
){
65 relatedObjects
.add(((IdentifiableEntity
)object
).getTitleCache() );
67 relatedObjects
.add(object
.getUserFriendlyTypeName());
71 for (String relatedObject
: relatedObjects
){
73 relatedObjectsString
.append(relatedObject
);
74 relatedObjectsString
.append(System
.lineSeparator());
77 message
= message
+ "\n" ; //$NON-NLS-1$
78 String stackTraceWithContext
= getContextInfo(details
);
79 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
>();
87 String title
= ""; //$NON-NLS-1$
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(IStatus
.WARNING
)){
95 title
= DELETE_WAS_SUCCESSFULL
;
97 title
= DELETE_WAS_ABORTED
;
100 Object
[] relatedObjects
= new ArrayList
<Object
>().toArray();
102 String stackTraceWithContext
= getContextInfo(details
);
103 CdmDeleteErrorDialog ced
= new CdmDeleteErrorDialog(AbstractUtility
.getShell(), title
, message
,new Status(IStatus
.INFO
, pluginId
, null, e
), stackTraceWithContext
, relatedObjects
);