Project

General

Profile

Download (2.2 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.view;
11

    
12
import java.util.HashMap;
13
import java.util.Map;
14
import java.util.Map.Entry;
15

    
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.IConfigurationElement;
18
import org.eclipse.core.runtime.IExtensionRegistry;
19
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.Platform;
21
import org.eclipse.core.runtime.Status;
22

    
23
import eu.etaxonomy.taxeditor.model.MessagingUtils;
24
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
25

    
26
/**
27
 * @author pplitzner
28
 * @date Jul 7, 2015
29
 *
30
 */
31
public class CdmViewerUtil {
32

    
33
    public static  Map<Entry<Class<?>, String>, ICdmViewer> getNameViewerMap(Object input){
34
        Map<Entry<Class<?>, String>, ICdmViewer> nameViewerMap = new HashMap<Entry<Class<?>, String>, ICdmViewer>();
35
    
36
        IExtensionRegistry reg = Platform.getExtensionRegistry();
37
        IConfigurationElement[] extensions = reg
38
                .getConfigurationElementsFor("eu.etaxonomy.taxeditor.store.cdmViewer");
39
        for (IConfigurationElement configElement : extensions) {
40
            try {
41
                Object object = configElement.createExecutableExtension("class");
42
                if(object instanceof ICdmViewer){
43
                    ICdmViewer cdmViewer = (ICdmViewer)object;
44
                    Map<Class<?>, String> viewerClasses = cdmViewer.getViewerClasses(input);
45
                    for (Entry<Class<?>, String> entry : viewerClasses.entrySet()) {
46
                        nameViewerMap.put(entry, cdmViewer);
47
                    }
48
                }
49
                else{
50
                    MessagingUtils.error(CdmViewerChooser.class, new Status(IStatus.ERROR, TaxeditorStorePlugin.PLUGIN_ID, "Could not load cdmViewer extension"));
51
                }
52
            } catch (CoreException e) {
53
                MessagingUtils.error(CdmViewerChooser.class, "Could not load cdmViewer extension", e);
54
            }
55
        }
56
        return nameViewerMap;
57
    }
58

    
59
}
(8-8/9)