Project

General

Profile

« Previous | Next » 

Revision 38e9eb06

Added by Katja Luther about 3 years ago

ref #9448: remove E4 from file names - cdmViewer

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java
74 74
     */
75 75
    public void chooseViewer(Object input){
76 76
        this.input = input;
77
        this.nameViewerMap = CdmViewerUtil.getAvailableViewers(input);
77
        this.nameViewerMap = CdmViewerUtilE4.getAvailableViewers(input);
78 78

  
79 79
        //if only one editor is available then open it
80 80
        if(nameViewerMap.size()==1){
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerUtil.java
1
/**
2
* Copyright (C) 2015 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.view;
10

  
11
import java.util.HashMap;
12
import java.util.Map;
13

  
14
import org.eclipse.core.commands.Command;
15
import org.eclipse.core.runtime.IConfigurationElement;
16
import org.eclipse.core.runtime.IExtensionRegistry;
17
import org.eclipse.core.runtime.Platform;
18
import org.eclipse.jface.viewers.TreeNode;
19
import org.eclipse.ui.PlatformUI;
20
import org.eclipse.ui.commands.ICommandService;
21

  
22
import eu.etaxonomy.cdm.model.common.CdmBase;
23
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
24
import eu.etaxonomy.taxeditor.model.MessagingUtils;
25
import eu.etaxonomy.taxeditor.store.CdmStore;
26

  
27
/**
28
 * Scans eu.etaxonomy.taxeditor.store.cdmViewer extension point.
29
 * @author pplitzner
30
 * @date Jul 7, 2015
31
 *
32
 */
33
public class CdmViewerUtil {
34

  
35
    /**
36
     * Returns a map of available commands to open the given input.
37
     * Keys are the command IDs and values are their string representations.
38
     *
39
     * @param input
40
     *            the object which should be handled by the available commands
41
     * @return a key-value map of available commands and their string
42
     *         representation
43
     */
44
    public static  Map<Command, String> getAvailableViewers(Object input){
45
                Map<Command, String> commandViewerNameMap = new HashMap<>();
46

  
47
        if(input!=null){
48
            //for generic UuidAndTitleCache objects try to load the object
49
            if (input instanceof UuidAndTitleCache){
50
                UuidAndTitleCache<? extends CdmBase> uuidAndTitleCache = (UuidAndTitleCache<? extends CdmBase>)input;
51
                input = CdmStore.getCommonService().find(uuidAndTitleCache.getType(), uuidAndTitleCache.getUuid());
52
            }
53
            //for tree nodes get the value resp. the object of the node
54
            else if (input instanceof TreeNode){
55
                TreeNode treeNode = (TreeNode)input;
56
                input = treeNode.getValue();
57
            }
58
            if(input==null){
59
                return commandViewerNameMap;
60
            }
61
            IExtensionRegistry reg = Platform.getExtensionRegistry();
62
            IConfigurationElement[] extensions = reg
63
                    .getConfigurationElementsFor("eu.etaxonomy.taxeditor.store.cdmViewer"); //$NON-NLS-1$
64
            for (IConfigurationElement configElement : extensions) {
65
                if(configElement.getName().equals("viewCommandMapping")){ //$NON-NLS-1$
66
                    try {
67
                        String commandId = configElement.getAttribute("commandId"); //$NON-NLS-1$
68
                        String viewerName = configElement.getAttribute("viewerName"); //$NON-NLS-1$
69
                        Class<?> selectionClass = Class.forName(configElement.getAttribute("selection")); //$NON-NLS-1$
70
                        if(selectionClass.isAssignableFrom(input.getClass())){
71
                            ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
72
                            Command command = commandService.getCommand(commandId);
73
                            if(command.isEnabled()){
74
                                commandViewerNameMap.put(command, viewerName);
75
                            }
76
                        }
77
                    } catch (ClassNotFoundException e) {
78
                        MessagingUtils.error(CdmViewerChooser.class, "Could not initalize selection class element of cdmViewer extension", e); //$NON-NLS-1$
79
                    }
80
                }
81
            }
82
        }
83
        return commandViewerNameMap;
84
    }
85

  
86
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerUtilE4.java
23 23
import org.eclipse.e4.core.commands.EHandlerService;
24 24
import org.eclipse.jface.viewers.IStructuredSelection;
25 25
import org.eclipse.jface.viewers.TreeNode;
26
import org.eclipse.ui.PlatformUI;
27
import org.eclipse.ui.commands.ICommandService;
26 28

  
27 29
import eu.etaxonomy.cdm.model.common.CdmBase;
28 30
import eu.etaxonomy.cdm.model.common.ICdmBase;
31
import eu.etaxonomy.cdm.model.name.NomenclaturalSource;
29 32
import eu.etaxonomy.cdm.persistence.dto.ReferencingObjectDto;
30 33
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
31 34
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
32 35
import eu.etaxonomy.taxeditor.model.MessagingUtils;
36
import eu.etaxonomy.taxeditor.store.CdmStore;
33 37

  
34 38
/**
35 39
 * Scans eu.etaxonomy.taxeditor.store.cdmViewer extension point.
......
86 90
        return commandViewerNameMap;
87 91
    }
88 92

  
93
    /**
94
     * Returns a map of available commands to open the given input.
95
     * Keys are the command IDs and values are their string representations.
96
     *
97
     * @param input
98
     *            the object which should be handled by the available commands
99
     * @return a key-value map of available commands and their string
100
     *         representation
101
     */
102
    public static  Map<Command, String> getAvailableViewers(Object input){
103
                Map<Command, String> commandViewerNameMap = new HashMap<>();
104

  
105
        if(input!=null){
106
            //for generic UuidAndTitleCache objects try to load the object
107
            if (input instanceof UuidAndTitleCache){
108
                UuidAndTitleCache<? extends CdmBase> uuidAndTitleCache = (UuidAndTitleCache<? extends CdmBase>)input;
109
                input = CdmStore.getCommonService().find(uuidAndTitleCache.getType(), uuidAndTitleCache.getUuid());
110
            }
111
            //for tree nodes get the value resp. the object of the node
112
            else if (input instanceof TreeNode){
113
                TreeNode treeNode = (TreeNode)input;
114
                input = treeNode.getValue();
115
            }
116
            if(input==null){
117
                return commandViewerNameMap;
118
            }
119
            if (input instanceof NomenclaturalSource){
120
                input = ((NomenclaturalSource)input).getSourcedName();
121
            }
122

  
123
            IExtensionRegistry reg = Platform.getExtensionRegistry();
124
            IConfigurationElement[] extensions = reg
125
                    .getConfigurationElementsFor("eu.etaxonomy.taxeditor.store.cdmViewer"); //$NON-NLS-1$
126
            for (IConfigurationElement configElement : extensions) {
127
                if(configElement.getName().equals("viewCommandMapping")){ //$NON-NLS-1$
128
                    try {
129
                        String commandId = configElement.getAttribute("commandId"); //$NON-NLS-1$
130
                        String viewerName = configElement.getAttribute("viewerName"); //$NON-NLS-1$
131
                        Class<?> selectionClass = Class.forName(configElement.getAttribute("selection")); //$NON-NLS-1$
132
                        if(selectionClass.isAssignableFrom(input.getClass())){
133
                            ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
134
                            Command command = commandService.getCommand(commandId);
135
                            if(command.isEnabled()){
136
                                commandViewerNameMap.put(command, viewerName);
137
                            }
138
                        }
139
                    } catch (ClassNotFoundException e) {
140
                        MessagingUtils.error(CdmViewerChooser.class, "Could not initalize selection class element of cdmViewer extension", e); //$NON-NLS-1$
141
                    }
142
                }
143
            }
144
        }
145
        return commandViewerNameMap;
146
    }
147

  
148

  
89 149
    /**
90 150
     * Trys to create a List of {@link UuidAndTitleCache} from the selection.<BR>
91 151
     * Selections which are not recognized are not included in the list.<BR>

Also available in: Unified diff