Project

General

Profile

Download (2.7 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.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
}
(11-11/38)