Project

General

Profile

Download (3.82 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2015 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
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.
9
*/
10
package eu.etaxonomy.taxeditor.model;
11

    
12
import java.util.ArrayList;
13
import java.util.Iterator;
14
import java.util.List;
15

    
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.MultiStatus;
18
import org.eclipse.core.runtime.Status;
19

    
20
import eu.etaxonomy.cdm.api.service.DeleteResult;
21
import eu.etaxonomy.cdm.model.common.CdmBase;
22
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
23

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

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

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

    
67
            }
68

    
69
            for (String relatedObject: relatedObjects){
70

    
71
                relatedObjectsString.append(relatedObject);
72
                relatedObjectsString.append(System.lineSeparator());
73
            }
74
        }
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());
78

    
79
        ced.open();
80

    
81

    
82

    
83
    }
84
    
85
    public static void messageDialogWithDetails(IStatus result, String message, String pluginId) {
86
       
87
        List<String> details = new ArrayList<String>();
88
        String title= "";
89
        Throwable e = null;
90
        if (result.isMultiStatus()){
91
            for (IStatus childStatus:result.getChildren()){
92
                details.add(childStatus.getMessage());
93
            }
94
            e = result.getChildren()[0].getException();
95
            if (result.equals(Status.OK_STATUS)|| result.equals(Status.WARNING)){
96
                title = "Delete was successfull.";
97
            } else {
98
                title = "Delete was aborted.";
99
            }
100
        }
101
        StringBuffer relatedObjectsString = new StringBuffer();
102
        Object[] relatedObjects = new ArrayList<Object>().toArray(); 
103
      
104
       
105
    
106
        String stackTraceWithContext = getContextInfo(details);
107
        CdmDeleteErrorDialog ced = new CdmDeleteErrorDialog(AbstractUtility.getShell(), title, message,new Status(IStatus.INFO, pluginId, null, e), stackTraceWithContext, relatedObjects);
108

    
109
        ced.open();
110

    
111

    
112

    
113
    }
114
    
115
}
(11-11/38)