3 * Copyright (C) 2015 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.view
;
12 import java
.util
.HashMap
;
15 import org
.eclipse
.core
.runtime
.IConfigurationElement
;
16 import org
.eclipse
.core
.runtime
.IExtensionRegistry
;
17 import org
.eclipse
.core
.runtime
.Platform
;
19 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
22 * Scans eu.etaxonomy.taxeditor.store.cdmViewer extension point.
27 public class CdmViewerUtil
{
30 * Returns a map of available commands to open the given input.
31 * Keys are the command IDs and values are their string representations.
34 * the object which should be handled by the available commands
35 * @return a key-value map of available commands and their string
38 public static Map
<String
, String
> getAvailableViewers(Object input
){
39 Map
<String
, String
> commandViewerNameMap
= new HashMap
<String
, String
>();
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")){
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
);
54 } catch (ClassNotFoundException e
) {
55 MessagingUtils
.error(CdmViewerChooser
.class, "Could not initalize selection class element of cdmViewer extension", e
);
60 return commandViewerNameMap
;