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
.commands
.Command
;
16 import org
.eclipse
.core
.runtime
.IConfigurationElement
;
17 import org
.eclipse
.core
.runtime
.IExtensionRegistry
;
18 import org
.eclipse
.core
.runtime
.Platform
;
19 import org
.eclipse
.ui
.PlatformUI
;
20 import org
.eclipse
.ui
.commands
.ICommandService
;
22 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
23 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
24 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
27 import eu
.etaxonomy
.cdm
.persistence
.dto
.UuidAndTitleCache
;
28 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
29 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
32 * Scans eu.etaxonomy.taxeditor.store.cdmViewer extension point.
37 public class CdmViewerUtil
{
40 * Returns a map of available commands to open the given input.
41 * Keys are the command IDs and values are their string representations.
44 * the object which should be handled by the available commands
45 * @return a key-value map of available commands and their string
48 public static Map
<Command
, String
> getAvailableViewers(Object input
){
49 Map
<Command
, String
> commandViewerNameMap
= new HashMap
<Command
, String
>();
52 //for generic UuidAndTitleCache objects try to load the object
53 if (input
instanceof UuidAndTitleCache
){
54 UuidAndTitleCache uuidAndTitleCache
= (UuidAndTitleCache
)input
;
55 Class type
= uuidAndTitleCache
.getType();
56 if(type
== Taxon
.class || type
== Synonym
.class){
57 input
= CdmStore
.getService(ITaxonService
.class).load(uuidAndTitleCache
.getUuid());
59 else if(SpecimenOrObservationBase
.class.isAssignableFrom(type
)){
60 input
= CdmStore
.getService(IOccurrenceService
.class).load(uuidAndTitleCache
.getUuid());
65 IExtensionRegistry reg
= Platform
.getExtensionRegistry();
66 IConfigurationElement
[] extensions
= reg
67 .getConfigurationElementsFor("eu.etaxonomy.taxeditor.store.cdmViewer"); //$NON-NLS-1$
68 for (IConfigurationElement configElement
: extensions
) {
69 if(configElement
.getName().equals("viewCommandMapping")){ //$NON-NLS-1$
71 String commandId
= configElement
.getAttribute("commandId"); //$NON-NLS-1$
72 String viewerName
= configElement
.getAttribute("viewerName"); //$NON-NLS-1$
73 Class
<?
> selectionClass
= Class
.forName(configElement
.getAttribute("selection")); //$NON-NLS-1$
74 if(selectionClass
.isAssignableFrom(input
.getClass())){
75 ICommandService commandService
= (ICommandService
)PlatformUI
.getWorkbench().getService(ICommandService
.class);
76 Command command
= commandService
.getCommand(commandId
);
77 if(command
.isEnabled()){
78 commandViewerNameMap
.put(command
, viewerName
);
81 } catch (ClassNotFoundException e
) {
82 MessagingUtils
.error(CdmViewerChooser
.class, "Could not initalize selection class element of cdmViewer extension", e
); //$NON-NLS-1$
87 return commandViewerNameMap
;