ref #9448: remove E4 from file names - coninue and cleanup
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / CdmViewerUtilE4.java
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerUtilE4.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerUtilE4.java
deleted file mode 100644 (file)
index 4724514..0000000
+++ /dev/null
@@ -1,203 +0,0 @@
-/**
-* Copyright (C) 2015 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-package eu.etaxonomy.taxeditor.view;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.core.commands.Command;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtensionRegistry;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.e4.core.commands.ECommandService;
-import org.eclipse.e4.core.commands.EHandlerService;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.TreeNode;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.commands.ICommandService;
-
-import eu.etaxonomy.cdm.model.common.CdmBase;
-import eu.etaxonomy.cdm.model.common.ICdmBase;
-import eu.etaxonomy.cdm.model.name.NomenclaturalSource;
-import eu.etaxonomy.cdm.persistence.dto.ReferencingObjectDto;
-import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
-import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
-import eu.etaxonomy.taxeditor.model.MessagingUtils;
-import eu.etaxonomy.taxeditor.store.CdmStore;
-
-/**
- * Scans eu.etaxonomy.taxeditor.store.cdmViewer extension point.
- * @author pplitzner
- * @date Jul 7, 2015
- */
-public class CdmViewerUtilE4 {
-
-    /**
-     * Returns a map of available commands to open the given input. Keys are the
-     * command IDs and values are their string representations.
-     *
-     * @param input
-     *            the object which should be handled by the available commands
-     * @return a key-value map of available commands and their string
-     *         representation
-     */
-    public static Map<Command, String> getAvailableViewers(List<UuidAndTitleCache<? extends ICdmBase>> input, ECommandService commandService,
-            EHandlerService handlerService){
-
-        Map<Command, String> commandViewerNameMap = new HashMap<>();
-
-        Set<Class<?>> inputClasses = new HashSet<>();
-        if(input!=null){
-            input.stream()
-                .filter(uuid->uuid.getType()!= null)
-                .forEach(uuid->inputClasses.add(uuid.getType()));
-
-            inputClasses.forEach(ic->{
-                IExtensionRegistry reg = Platform.getExtensionRegistry();
-                IConfigurationElement[] extensions = reg
-                        .getConfigurationElementsFor("eu.etaxonomy.taxeditor.store.cdmViewer"); //$NON-NLS-1$
-                for (IConfigurationElement configElement : extensions) {
-                    try {
-                        if(configElement.getName().equals("viewCommandMapping")){ //$NON-NLS-1$
-                            String commandId = configElement.getAttribute("commandId"); //$NON-NLS-1$
-                            String viewerName = configElement.getAttribute("viewerName"); //$NON-NLS-1$
-                            Class<?> selectionClass = Class.forName(configElement.getAttribute("selection")); //$NON-NLS-1$
-                            if(selectionClass!=null
-                                    && commandId!=null
-                                    && viewerName!=null
-                                    && selectionClass.isAssignableFrom(ic)){
-                                Command command = commandService.getCommand(commandId);
-                                commandViewerNameMap.put(command, viewerName);
-                            }
-                        }
-                    } catch (ClassNotFoundException e) {
-                        MessagingUtils.error(CdmViewerChooser.class, "Could not initalize selection class element of cdmViewer extension", e); //$NON-NLS-1$
-                    }
-                }
-            });
-        }
-
-        return commandViewerNameMap;
-    }
-
-    /**
-     * Returns a map of available commands to open the given input.
-     * Keys are the command IDs and values are their string representations.
-     *
-     * @param input
-     *            the object which should be handled by the available commands
-     * @return a key-value map of available commands and their string
-     *         representation
-     */
-    public static  Map<Command, String> getAvailableViewers(Object input){
-                Map<Command, String> commandViewerNameMap = new HashMap<>();
-
-        if(input!=null){
-            //for generic UuidAndTitleCache objects try to load the object
-            if (input instanceof UuidAndTitleCache){
-                UuidAndTitleCache<? extends CdmBase> uuidAndTitleCache = (UuidAndTitleCache<? extends CdmBase>)input;
-                input = CdmStore.getCommonService().find(uuidAndTitleCache.getType(), uuidAndTitleCache.getUuid());
-            }
-            //for tree nodes get the value resp. the object of the node
-            else if (input instanceof TreeNode){
-                TreeNode treeNode = (TreeNode)input;
-                input = treeNode.getValue();
-            }
-            if(input==null){
-                return commandViewerNameMap;
-            }
-            if (input instanceof NomenclaturalSource){
-                input = ((NomenclaturalSource)input).getSourcedName();
-            }
-
-            IExtensionRegistry reg = Platform.getExtensionRegistry();
-            IConfigurationElement[] extensions = reg
-                    .getConfigurationElementsFor("eu.etaxonomy.taxeditor.store.cdmViewer"); //$NON-NLS-1$
-            for (IConfigurationElement configElement : extensions) {
-                if(configElement.getName().equals("viewCommandMapping")){ //$NON-NLS-1$
-                    try {
-                        String commandId = configElement.getAttribute("commandId"); //$NON-NLS-1$
-                        String viewerName = configElement.getAttribute("viewerName"); //$NON-NLS-1$
-                        Class<?> selectionClass = Class.forName(configElement.getAttribute("selection")); //$NON-NLS-1$
-                        if(selectionClass.isAssignableFrom(input.getClass())){
-                            ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
-                            Command command = commandService.getCommand(commandId);
-                            if(command.isEnabled()){
-                                commandViewerNameMap.put(command, viewerName);
-                            }
-                        }
-                    } catch (ClassNotFoundException e) {
-                        MessagingUtils.error(CdmViewerChooser.class, "Could not initalize selection class element of cdmViewer extension", e); //$NON-NLS-1$
-                    }
-                }
-            }
-        }
-        return commandViewerNameMap;
-    }
-
-
-    /**
-     * Trys to create a List of {@link UuidAndTitleCache} from the selection.<BR>
-     * Selections which are not recognized are not included in the list.<BR>
-     * As a minimum each returned element contains the type and the uuid.
-     * If available also the label and the CdmBase entity is added (later by using the subclass {@link DtoWithEntity}.
-     * Label creation is not forced (TODO maybe in future we should have a parameter forceLabelCreation)
-     * @param
-     * @return list of {@link UuidAndTitleCache}
-     */
-    public static List<UuidAndTitleCache<? extends ICdmBase>> transformSelectionToUuidAndTitleCacheList(Object selection) {
-
-        //make it all a list
-        List<Object> multipleSelection = new ArrayList<>();
-        if(selection instanceof IStructuredSelection){
-            IStructuredSelection structuredSelection = ((IStructuredSelection) selection);
-            ((List<?>)structuredSelection.toList()).forEach(o->multipleSelection.add(o));
-        }else if(selection.getClass().isArray()){
-            for (Object o : ((Object[])selection)){
-                multipleSelection.add(o);
-            }
-        }else if(selection instanceof List){
-            multipleSelection.addAll((List<?>)selection);
-        }else{
-            multipleSelection.add(selection);
-        }
-
-        //filter all as uuidIdAndTitleCache
-        List<UuidAndTitleCache<? extends ICdmBase>> uuidTypes = new ArrayList<>();
-
-        for (Object o : multipleSelection){
-            if (o instanceof FeatureNodeContainer){
-                continue ;
-            }
-            if(o instanceof TreeNode){
-                o = ((TreeNode)o).getValue();
-            }
-            o = CdmBase.deproxy(o);
-
-            UuidAndTitleCache<? extends ICdmBase> uuidAndTitleCache;
-            if (o instanceof CdmBase){
-                CdmBase cdmBase = (CdmBase)o;
-                uuidAndTitleCache = new DtoWithEntity<>(cdmBase);
-            }else if (o instanceof ReferencingObjectDto){
-                ReferencingObjectDto dto = (ReferencingObjectDto)o;
-                uuidAndTitleCache = dto.getOpenInTarget() != null ? dto.getOpenInTarget() : dto;
-            }else if (o instanceof UuidAndTitleCache){
-                uuidAndTitleCache = (UuidAndTitleCache<CdmBase>)o;
-            }else{
-                continue;
-            }
-            uuidTypes.add(uuidAndTitleCache);
-        }
-        return uuidTypes;
-    }
-}
\ No newline at end of file