Project

General

Profile

Download (3.94 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
import eu.etaxonomy.taxeditor.l10n.Messages;
22

    
23
/**
24
 * @author k.luther
25
 * @date Oct 5, 2015
26
 *
27
 */
28
public class DeleteResultMessagingUtils extends MessagingUtils {
29

    
30
    private static final String DELETE_WAS_ABORTED = Messages.DeleteResultMessagingUtils_ABORT;
31
    private static final String DELETE_WAS_SUCCESSFULL = Messages.DeleteResultMessagingUtils_SUCCES;
32

    
33
    /**
34
     * Displays a message {@link org.eclipse.jface.dialogs.MessageDialog}.
35
     *
36
     * @param title
37
     * @param source
38
     * @param message
39
     */
40
    public static void messageDialogWithDetails(DeleteResult result, String message, String pluginId) {
41
        if (result.isOk() && result.getExceptions().isEmpty()){
42
            return;
43
        }
44
        List<String> details = new ArrayList<String>();
45
        String title= ""; //$NON-NLS-1$
46

    
47
        if (result.getExceptions().size() > 0){
48
            for (Exception e:result.getExceptions()){
49
                details.add(e.getMessage());
50
            }
51
            if (result.isOk()){
52
                title = DELETE_WAS_SUCCESSFULL;
53
            } else {
54
                title = DELETE_WAS_ABORTED;
55
            }
56
        }
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){
64

    
65
                    relatedObjects.add(((IdentifiableEntity)object).getTitleCache() );
66
                } else{
67
                    relatedObjects.add(object.getUserFriendlyTypeName());
68
                }
69
            }
70

    
71
            for (String relatedObject: relatedObjects){
72

    
73
                relatedObjectsString.append(relatedObject);
74
                relatedObjectsString.append(System.lineSeparator());
75
            }
76
        }
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());
80

    
81
        ced.open();
82
    }
83

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

    
86
        List<String> details = new ArrayList<String>();
87
        String title= ""; //$NON-NLS-1$
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(IStatus.WARNING)){
95
                title = DELETE_WAS_SUCCESSFULL;
96
            } else {
97
                title = DELETE_WAS_ABORTED;
98
            }
99
        }
100
        Object[] relatedObjects = new ArrayList<Object>().toArray();
101

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

    
105
        ced.open();
106
    }
107

    
108
}
(13-13/41)