Merge branch 'develop' of ssh://dev.e-taxonomy.eu/var/git/taxeditor into develop
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / CdmViewerUtil.java
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
15 import org.eclipse.core.runtime.IConfigurationElement;
16 import org.eclipse.core.runtime.IExtensionRegistry;
17 import org.eclipse.core.runtime.Platform;
18
19 import eu.etaxonomy.taxeditor.model.MessagingUtils;
20
21 /**
22 * Scans eu.etaxonomy.taxeditor.store.cdmViewer extension point.
23 * @author pplitzner
24 * @date Jul 7, 2015
25 *
26 */
27 public class CdmViewerUtil {
28
29 /**
30 * Returns a map of available commands to open the given input.
31 * Keys are the command IDs and values are their string representations.
32 *
33 * @param input
34 * the object which should be handled by the available commands
35 * @return a key-value map of available commands and their string
36 * representation
37 */
38 public static Map<String, String> getAvailableViewers(Object input){
39 Map<String, String> commandViewerNameMap = new HashMap<String, String>();
40
41 if(input!=null){
42 IExtensionRegistry reg = Platform.getExtensionRegistry();
43 IConfigurationElement[] extensions = reg
44 .getConfigurationElementsFor("eu.etaxonomy.taxeditor.store.cdmViewer");
45 for (IConfigurationElement configElement : extensions) {
46 if(configElement.getName().equals("viewCommandMapping")){
47 try {
48 String commandId = configElement.getAttribute("commandId");
49 String viewerName = configElement.getAttribute("viewerName");
50 Class<?> selectionClass = Class.forName(configElement.getAttribute("selection"));
51 if(selectionClass.isAssignableFrom(input.getClass())){
52 commandViewerNameMap.put(commandId, viewerName);
53 }
54 } catch (ClassNotFoundException e) {
55 MessagingUtils.error(CdmViewerChooser.class, "Could not initalize selection class element of cdmViewer extension", e);
56 }
57 }
58 }
59 }
60 return commandViewerNameMap;
61 }
62
63 }