Merge branch 'develop' into LibrAlign
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / model / DeleteResultMessagingUtils.java
1 /**
2 * Copyright (C) 2015 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9 package eu.etaxonomy.taxeditor.model;
10
11 import java.util.ArrayList;
12 import java.util.Iterator;
13 import java.util.List;
14
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.MultiStatus;
17 import org.eclipse.core.runtime.Status;
18
19 import eu.etaxonomy.cdm.api.service.DeleteResult;
20 import eu.etaxonomy.cdm.model.common.CdmBase;
21 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
22
23 /**
24 * @author k.luther
25 * @date Oct 5, 2015
26 *
27 */
28 public class DeleteResultMessagingUtils extends MessagingUtils {
29 /**
30 * Displays a message {@link org.eclipse.jface.dialogs.MessageDialog}.
31 *
32 * @param title
33 * @param source
34 * @param message
35 */
36 public static void messageDialogWithDetails(DeleteResult result, String message, String pluginId) {
37 if (result.isOk() && result.getExceptions().isEmpty()){
38 return;
39 }
40 List<String> details = new ArrayList<String>();
41 String title= "";
42
43 if (result.getExceptions().size() > 0){
44 for (Exception e:result.getExceptions()){
45 details.add(e.getMessage());
46 }
47 if (result.isOk()){
48 title = "Delete was successfull.";
49 } else {
50 title = "Delete was aborted.";
51 }
52 }
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){
60
61 relatedObjects.add(((IdentifiableEntity)object).getTitleCache() );
62 } else{
63 relatedObjects.add(object.getUserFriendlyTypeName());
64 }
65
66 }
67
68 for (String relatedObject: relatedObjects){
69
70 relatedObjectsString.append(relatedObject);
71 relatedObjectsString.append(System.lineSeparator());
72 }
73 }
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());
77
78 ced.open();
79
80
81
82 }
83
84 public static void messageDialogWithDetails(IStatus result, String message, String pluginId) {
85
86 List<String> details = new ArrayList<String>();
87 String title= "";
88 Throwable e = null;
89 if (result.isMultiStatus()){
90 for (IStatus childStatus:result.getChildren()){
91 details.add(childStatus.getMessage());
92 }
93 e = result.getChildren()[0].getException();
94 if (result.equals(Status.OK_STATUS)|| result.equals(Status.WARNING)){
95 title = "Delete was successfull.";
96 } else {
97 title = "Delete was aborted.";
98 }
99 }
100 StringBuffer relatedObjectsString = new StringBuffer();
101 Object[] relatedObjects = new ArrayList<Object>().toArray();
102
103
104
105 String stackTraceWithContext = getContextInfo(details);
106 CdmDeleteErrorDialog ced = new CdmDeleteErrorDialog(AbstractUtility.getShell(), title, message,new Status(IStatus.INFO, pluginId, null, e), stackTraceWithContext, relatedObjects);
107
108 ced.open();
109
110
111
112 }
113
114 }