Project

General

Profile

Download (3.74 KB) Statistics
| Branch: | Tag: | Revision:
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.Status;
17

    
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

    
22
/**
23
 * @author k.luther
24
 * @date Oct 5, 2015
25
 *
26
 */
27
public class DeleteResultMessagingUtils extends MessagingUtils {
28
    /**
29
     * Displays a message {@link org.eclipse.jface.dialogs.MessageDialog}.
30
     *
31
     * @param title
32
     * @param source
33
     * @param message
34
     */
35
    public static void messageDialogWithDetails(DeleteResult result, String message, String pluginId) {
36
        if (result.isOk() && result.getExceptions().isEmpty()){
37
            return;
38
        }
39
        List<String> details = new ArrayList<String>();
40
        String title= "";
41

    
42
        if (result.getExceptions().size() > 0){
43
            for (Exception e:result.getExceptions()){
44
                details.add(e.getMessage());
45
            }
46
            if (result.isOk()){
47
                title = "Delete was successfull";
48
            } else {
49
                title = "Delete was aborted";
50
            }
51
        }
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){
59

    
60
                    relatedObjects.add(((IdentifiableEntity)object).getTitleCache() );
61
                } else{
62
                    relatedObjects.add(object.getUserFriendlyTypeName());
63
                }
64

    
65
            }
66

    
67
            for (String relatedObject: relatedObjects){
68

    
69
                relatedObjectsString.append(relatedObject);
70
                relatedObjectsString.append(System.lineSeparator());
71
            }
72
        }
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());
76

    
77
        ced.open();
78

    
79

    
80

    
81
    }
82

    
83
    public static void messageDialogWithDetails(IStatus result, String message, String pluginId) {
84

    
85
        List<String> details = new ArrayList<String>();
86
        String title= "";
87
        Throwable e = null;
88
        if (result.isMultiStatus()){
89
            for (IStatus childStatus:result.getChildren()){
90
                details.add(childStatus.getMessage());
91
            }
92
            e = result.getChildren()[0].getException();
93
            if (result.equals(Status.OK_STATUS)|| result.equals(Status.WARNING)){
94
                title = "Delete was successfull";
95
            } else {
96
                title = "Delete was aborted";
97
            }
98
        }
99
        StringBuffer relatedObjectsString = new StringBuffer();
100
        Object[] relatedObjects = new ArrayList<Object>().toArray();
101

    
102

    
103

    
104
        String stackTraceWithContext = getContextInfo(details);
105
        CdmDeleteErrorDialog ced = new CdmDeleteErrorDialog(AbstractUtility.getShell(), title, message,new Status(IStatus.INFO, pluginId, null, e), stackTraceWithContext, relatedObjects);
106

    
107
        ced.open();
108

    
109

    
110

    
111
    }
112

    
113
}
(11-11/38)