Revision bbae6889
Added by Katja Luther almost 3 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/handler/NameEditorMenuPropertyTester.java | ||
---|---|---|
12 | 12 |
import org.eclipse.core.expressions.PropertyTester; |
13 | 13 |
import org.eclipse.jface.viewers.IStructuredSelection; |
14 | 14 |
|
15 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
|
15 | 16 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
16 | 17 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
17 | 18 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
... | ... | |
142 | 143 |
|
143 | 144 |
public static boolean isSynonymOrTaxonInHomotypicalGroupWithMoreSynonyms(Object selectedElement) { |
144 | 145 |
if (isSynonym(selectedElement) || isAccepted(selectedElement)){ |
145 |
TaxonBase<?> synonym = (TaxonBase<?>) selectedElement;
|
|
146 |
TaxonBase<?> synonym = HibernateProxyHelper.deproxy(selectedElement, TaxonBase.class);
|
|
146 | 147 |
return synonym.getHomotypicGroup().getTypifiedNames().size()>1; |
147 | 148 |
} |
148 | 149 |
return false; |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java | ||
---|---|---|
458 | 458 |
@Override |
459 | 459 |
public void changed(Object element) { |
460 | 460 |
setDirty(true); |
461 |
//firePropertyChange(IEditorPart.PROP_DIRTY); |
|
462 | 461 |
viewer.update(new TreeNode(element), null); |
463 | 462 |
viewer.refresh(); |
464 | 463 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java | ||
---|---|---|
84 | 84 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
85 | 85 |
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin; |
86 | 86 |
import eu.etaxonomy.taxeditor.ui.dialog.ReportTextDialog; |
87 |
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmDataViewerE4;
|
|
87 |
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmDataViewer; |
|
88 | 88 |
import eu.etaxonomy.taxeditor.view.e4.details.DetailsPartE4; |
89 | 89 |
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart; |
90 | 90 |
|
... | ... | |
417 | 417 |
|
418 | 418 |
public static void refreshDetailsViewer(EPartService partService) { |
419 | 419 |
if (getDetailsView(partService) != null) { |
420 |
((AbstractCdmDataViewerE4) getDetailsView(partService).getViewer()).refresh();
|
|
420 |
((AbstractCdmDataViewer) getDetailsView(partService).getViewer()).refresh(); |
|
421 | 421 |
} |
422 | 422 |
} |
423 | 423 |
|
424 | 424 |
public static void reflowDetailsViewer(EPartService partService) { |
425 | 425 |
if (getDetailsView(partService) != null) { |
426 |
((AbstractCdmDataViewerE4) getDetailsView(partService).getViewer()).reflow();
|
|
426 |
((AbstractCdmDataViewer) getDetailsView(partService).getViewer()).reflow(); |
|
427 | 427 |
} |
428 | 428 |
} |
429 | 429 |
|
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/AppModelId.java | ||
---|---|---|
349 | 349 |
public static final String PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_STORE_PARTDESCRIPTOR_OCCURENCESEARCH = "eu.etaxonomy.taxeditor.store.partdescriptor.occurencesearch"; |
350 | 350 |
public static final String PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_STORE_PARTDESCRIPTOR_SEARCHDIALOG = "eu.etaxonomy.taxeditor.store.partdescriptor.SearchDialog"; |
351 | 351 |
public static final String PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_STORE_PARTDESCRIPTOR_TERMSEARCH = "eu.etaxonomy.taxeditor.store.partdescriptor.termsearch"; |
352 |
public static final String PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_VIEW_DATAIMPORT_E4_GBIFRESPONSEIMPORTVIEWE4 = "eu.etaxonomy.taxeditor.view.dataimport.e4.GbifResponseImportViewE4";
|
|
353 |
public static final String PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_VIEW_DATAIMPORT_E4_SPECIMENIMPORTVIEWE4 = "eu.etaxonomy.taxeditor.view.dataimport.e4.SpecimenImportViewE4";
|
|
352 |
public static final String PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_VIEW_DATAIMPORT_E4_GBIFRESPONSEIMPORTVIEWE4 = "eu.etaxonomy.taxeditor.view.dataimport.e4.GbifResponseImportView"; |
|
353 |
public static final String PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_VIEW_DATAIMPORT_E4_SPECIMENIMPORTVIEWE4 = "eu.etaxonomy.taxeditor.view.dataimport.e4.SpecimenImportView"; |
|
354 | 354 |
public static final String PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_VIEW_DATASOURCE = "eu.etaxonomy.taxeditor.view.datasource"; |
355 | 355 |
public static final String PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_VIEW_E4_DETAILS_DETAILSPARTE4 = "eu.etaxonomy.taxeditor.view.e4.details.DetailsPartE4"; |
356 | 356 |
public static final String PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_VIEW_E4_SUPPLEMENTALDATA_SUPPLEMENTALDATAPARTE4 = "eu.etaxonomy.taxeditor.view.e4.supplementaldata.SupplementalDataPartE4"; |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/ImageElement.java | ||
---|---|---|
36 | 36 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
37 | 37 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
38 | 38 |
import eu.etaxonomy.taxeditor.store.StoreUtil; |
39 |
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmDataViewerE4;
|
|
39 |
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmDataViewer; |
|
40 | 40 |
import eu.etaxonomy.taxeditor.view.e4.details.DetailsPartE4; |
41 | 41 |
import eu.etaxonomy.taxeditor.view.e4.supplementaldata.SupplementalDataPartE4; |
42 | 42 |
|
... | ... | |
82 | 82 |
IEclipseContext context = getFormFactory().getContext().getActiveChild(); |
83 | 83 |
DetailsPartE4 detailsView = AbstractUtility.getDetailsView(partService); |
84 | 84 |
if(detailsView!=null){ |
85 |
AbstractCdmDataViewerE4 viewer = (AbstractCdmDataViewerE4) detailsView.getViewer();
|
|
85 |
AbstractCdmDataViewer viewer = (AbstractCdmDataViewer) detailsView.getViewer();
|
|
86 | 86 |
if(viewer!=null){ |
87 | 87 |
viewer.reflow(); |
88 | 88 |
} |
... | ... | |
92 | 92 |
if(mPartSupplemental!=null){ |
93 | 93 |
SupplementalDataPartE4 supplementalPart = (SupplementalDataPartE4)mPartSupplemental.getObject(); |
94 | 94 |
if(supplementalPart!=null){ |
95 |
AbstractCdmDataViewerE4 viewer = (AbstractCdmDataViewerE4) (supplementalPart).getViewer();
|
|
95 |
AbstractCdmDataViewer viewer = (AbstractCdmDataViewer) (supplementalPart).getViewer();
|
|
96 | 96 |
if(viewer!=null){ |
97 | 97 |
viewer.refresh(); |
98 | 98 |
} |
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 = CdmViewerUtilE4.getAvailableViewers(input);
|
|
77 |
this.nameViewerMap = CdmViewerUtil.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/CdmViewerContextMenuE4.java | ||
---|---|---|
50 | 50 |
return; |
51 | 51 |
} |
52 | 52 |
|
53 |
List<UuidAndTitleCache<? extends ICdmBase>> uuidTypes = CdmViewerUtilE4.transformSelectionToUuidAndTitleCacheList(selectedObject);
|
|
53 |
List<UuidAndTitleCache<? extends ICdmBase>> uuidTypes = CdmViewerUtil.transformSelectionToUuidAndTitleCacheList(selectedObject); |
|
54 | 54 |
|
55 |
Map<Command, String> enabledCommands = CdmViewerUtilE4.getAvailableViewers(uuidTypes, commandService, handlerService);
|
|
55 |
Map<Command, String> enabledCommands = CdmViewerUtil.getAvailableViewers(uuidTypes, commandService, handlerService); |
|
56 | 56 |
|
57 | 57 |
//check if only one or multiple viewers/commands are available |
58 | 58 |
if (!enabledCommands.isEmpty()){ |
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.ArrayList; |
|
12 |
import java.util.HashMap; |
|
13 |
import java.util.HashSet; |
|
14 |
import java.util.List; |
|
15 |
import java.util.Map; |
|
16 |
import java.util.Set; |
|
17 |
|
|
18 |
import org.eclipse.core.commands.Command; |
|
19 |
import org.eclipse.core.runtime.IConfigurationElement; |
|
20 |
import org.eclipse.core.runtime.IExtensionRegistry; |
|
21 |
import org.eclipse.core.runtime.Platform; |
|
22 |
import org.eclipse.e4.core.commands.ECommandService; |
|
23 |
import org.eclipse.e4.core.commands.EHandlerService; |
|
24 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
25 |
import org.eclipse.jface.viewers.TreeNode; |
|
26 |
import org.eclipse.ui.PlatformUI; |
|
27 |
import org.eclipse.ui.commands.ICommandService; |
|
28 |
|
|
29 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
30 |
import eu.etaxonomy.cdm.model.common.ICdmBase; |
|
31 |
import eu.etaxonomy.cdm.model.name.NomenclaturalSource; |
|
32 |
import eu.etaxonomy.cdm.persistence.dto.ReferencingObjectDto; |
|
33 |
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache; |
|
34 |
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer; |
|
35 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
36 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
37 |
|
|
38 |
/** |
|
39 |
* Scans eu.etaxonomy.taxeditor.store.cdmViewer extension point. |
|
40 |
* @author pplitzner |
|
41 |
* @date Jul 7, 2015 |
|
42 |
*/ |
|
43 |
public class CdmViewerUtil { |
|
44 |
|
|
45 |
/** |
|
46 |
* Returns a map of available commands to open the given input. Keys are the |
|
47 |
* command IDs and values are their string representations. |
|
48 |
* |
|
49 |
* @param input |
|
50 |
* the object which should be handled by the available commands |
|
51 |
* @return a key-value map of available commands and their string |
|
52 |
* representation |
|
53 |
*/ |
|
54 |
public static Map<Command, String> getAvailableViewers(List<UuidAndTitleCache<? extends ICdmBase>> input, ECommandService commandService, |
|
55 |
EHandlerService handlerService){ |
|
56 |
|
|
57 |
Map<Command, String> commandViewerNameMap = new HashMap<>(); |
|
58 |
|
|
59 |
Set<Class<?>> inputClasses = new HashSet<>(); |
|
60 |
if(input!=null){ |
|
61 |
input.stream() |
|
62 |
.filter(uuid->uuid.getType()!= null) |
|
63 |
.forEach(uuid->inputClasses.add(uuid.getType())); |
|
64 |
|
|
65 |
inputClasses.forEach(ic->{ |
|
66 |
IExtensionRegistry reg = Platform.getExtensionRegistry(); |
|
67 |
IConfigurationElement[] extensions = reg |
|
68 |
.getConfigurationElementsFor("eu.etaxonomy.taxeditor.store.cdmViewer"); //$NON-NLS-1$ |
|
69 |
for (IConfigurationElement configElement : extensions) { |
|
70 |
try { |
|
71 |
if(configElement.getName().equals("viewCommandMapping")){ //$NON-NLS-1$ |
|
72 |
String commandId = configElement.getAttribute("commandId"); //$NON-NLS-1$ |
|
73 |
String viewerName = configElement.getAttribute("viewerName"); //$NON-NLS-1$ |
|
74 |
Class<?> selectionClass = Class.forName(configElement.getAttribute("selection")); //$NON-NLS-1$ |
|
75 |
if(selectionClass!=null |
|
76 |
&& commandId!=null |
|
77 |
&& viewerName!=null |
|
78 |
&& selectionClass.isAssignableFrom(ic)){ |
|
79 |
Command command = commandService.getCommand(commandId); |
|
80 |
commandViewerNameMap.put(command, viewerName); |
|
81 |
} |
|
82 |
} |
|
83 |
} catch (ClassNotFoundException e) { |
|
84 |
MessagingUtils.error(CdmViewerChooser.class, "Could not initalize selection class element of cdmViewer extension", e); //$NON-NLS-1$ |
|
85 |
} |
|
86 |
} |
|
87 |
}); |
|
88 |
} |
|
89 |
|
|
90 |
return commandViewerNameMap; |
|
91 |
} |
|
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 |
|
|
149 |
/** |
|
150 |
* Trys to create a List of {@link UuidAndTitleCache} from the selection.<BR> |
|
151 |
* Selections which are not recognized are not included in the list.<BR> |
|
152 |
* As a minimum each returned element contains the type and the uuid. |
|
153 |
* If available also the label and the CdmBase entity is added (later by using the subclass {@link DtoWithEntity}. |
|
154 |
* Label creation is not forced (TODO maybe in future we should have a parameter forceLabelCreation) |
|
155 |
* @param |
|
156 |
* @return list of {@link UuidAndTitleCache} |
|
157 |
*/ |
|
158 |
public static List<UuidAndTitleCache<? extends ICdmBase>> transformSelectionToUuidAndTitleCacheList(Object selection) { |
|
159 |
|
|
160 |
//make it all a list |
|
161 |
List<Object> multipleSelection = new ArrayList<>(); |
|
162 |
if(selection instanceof IStructuredSelection){ |
|
163 |
IStructuredSelection structuredSelection = ((IStructuredSelection) selection); |
|
164 |
((List<?>)structuredSelection.toList()).forEach(o->multipleSelection.add(o)); |
|
165 |
}else if(selection.getClass().isArray()){ |
|
166 |
for (Object o : ((Object[])selection)){ |
|
167 |
multipleSelection.add(o); |
|
168 |
} |
|
169 |
}else if(selection instanceof List){ |
|
170 |
multipleSelection.addAll((List<?>)selection); |
|
171 |
}else{ |
|
172 |
multipleSelection.add(selection); |
|
173 |
} |
|
174 |
|
|
175 |
//filter all as uuidIdAndTitleCache |
|
176 |
List<UuidAndTitleCache<? extends ICdmBase>> uuidTypes = new ArrayList<>(); |
|
177 |
|
|
178 |
for (Object o : multipleSelection){ |
|
179 |
if (o instanceof FeatureNodeContainer){ |
|
180 |
continue ; |
|
181 |
} |
|
182 |
if(o instanceof TreeNode){ |
|
183 |
o = ((TreeNode)o).getValue(); |
|
184 |
} |
|
185 |
o = CdmBase.deproxy(o); |
|
186 |
|
|
187 |
UuidAndTitleCache<? extends ICdmBase> uuidAndTitleCache; |
|
188 |
if (o instanceof CdmBase){ |
|
189 |
CdmBase cdmBase = (CdmBase)o; |
|
190 |
uuidAndTitleCache = new DtoWithEntity<>(cdmBase); |
|
191 |
}else if (o instanceof ReferencingObjectDto){ |
|
192 |
ReferencingObjectDto dto = (ReferencingObjectDto)o; |
|
193 |
uuidAndTitleCache = dto.getOpenInTarget() != null ? dto.getOpenInTarget() : dto; |
|
194 |
}else if (o instanceof UuidAndTitleCache){ |
|
195 |
uuidAndTitleCache = (UuidAndTitleCache<CdmBase>)o; |
|
196 |
}else{ |
|
197 |
continue; |
|
198 |
} |
|
199 |
uuidTypes.add(uuidAndTitleCache); |
|
200 |
} |
|
201 |
return uuidTypes; |
|
202 |
} |
|
203 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerUtilE4.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.ArrayList; |
|
12 |
import java.util.HashMap; |
|
13 |
import java.util.HashSet; |
|
14 |
import java.util.List; |
|
15 |
import java.util.Map; |
|
16 |
import java.util.Set; |
|
17 |
|
|
18 |
import org.eclipse.core.commands.Command; |
|
19 |
import org.eclipse.core.runtime.IConfigurationElement; |
|
20 |
import org.eclipse.core.runtime.IExtensionRegistry; |
|
21 |
import org.eclipse.core.runtime.Platform; |
|
22 |
import org.eclipse.e4.core.commands.ECommandService; |
|
23 |
import org.eclipse.e4.core.commands.EHandlerService; |
|
24 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
25 |
import org.eclipse.jface.viewers.TreeNode; |
|
26 |
import org.eclipse.ui.PlatformUI; |
|
27 |
import org.eclipse.ui.commands.ICommandService; |
|
28 |
|
|
29 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
30 |
import eu.etaxonomy.cdm.model.common.ICdmBase; |
|
31 |
import eu.etaxonomy.cdm.model.name.NomenclaturalSource; |
|
32 |
import eu.etaxonomy.cdm.persistence.dto.ReferencingObjectDto; |
|
33 |
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache; |
|
34 |
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer; |
|
35 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
36 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
37 |
|
|
38 |
/** |
|
39 |
* Scans eu.etaxonomy.taxeditor.store.cdmViewer extension point. |
|
40 |
* @author pplitzner |
|
41 |
* @date Jul 7, 2015 |
|
42 |
*/ |
|
43 |
public class CdmViewerUtilE4 { |
|
44 |
|
|
45 |
/** |
|
46 |
* Returns a map of available commands to open the given input. Keys are the |
|
47 |
* command IDs and values are their string representations. |
|
48 |
* |
|
49 |
* @param input |
|
50 |
* the object which should be handled by the available commands |
|
51 |
* @return a key-value map of available commands and their string |
|
52 |
* representation |
|
53 |
*/ |
|
54 |
public static Map<Command, String> getAvailableViewers(List<UuidAndTitleCache<? extends ICdmBase>> input, ECommandService commandService, |
|
55 |
EHandlerService handlerService){ |
|
56 |
|
|
57 |
Map<Command, String> commandViewerNameMap = new HashMap<>(); |
|
58 |
|
|
59 |
Set<Class<?>> inputClasses = new HashSet<>(); |
|
60 |
if(input!=null){ |
|
61 |
input.stream() |
|
62 |
.filter(uuid->uuid.getType()!= null) |
|
63 |
.forEach(uuid->inputClasses.add(uuid.getType())); |
|
64 |
|
|
65 |
inputClasses.forEach(ic->{ |
|
66 |
IExtensionRegistry reg = Platform.getExtensionRegistry(); |
|
67 |
IConfigurationElement[] extensions = reg |
|
68 |
.getConfigurationElementsFor("eu.etaxonomy.taxeditor.store.cdmViewer"); //$NON-NLS-1$ |
|
69 |
for (IConfigurationElement configElement : extensions) { |
|
70 |
try { |
|
71 |
if(configElement.getName().equals("viewCommandMapping")){ //$NON-NLS-1$ |
|
72 |
String commandId = configElement.getAttribute("commandId"); //$NON-NLS-1$ |
|
73 |
String viewerName = configElement.getAttribute("viewerName"); //$NON-NLS-1$ |
|
74 |
Class<?> selectionClass = Class.forName(configElement.getAttribute("selection")); //$NON-NLS-1$ |
|
75 |
if(selectionClass!=null |
|
76 |
&& commandId!=null |
|
77 |
&& viewerName!=null |
|
78 |
&& selectionClass.isAssignableFrom(ic)){ |
|
79 |
Command command = commandService.getCommand(commandId); |
|
80 |
commandViewerNameMap.put(command, viewerName); |
|
81 |
} |
|
82 |
} |
|
83 |
} catch (ClassNotFoundException e) { |
|
84 |
MessagingUtils.error(CdmViewerChooser.class, "Could not initalize selection class element of cdmViewer extension", e); //$NON-NLS-1$ |
|
85 |
} |
|
86 |
} |
|
87 |
}); |
|
88 |
} |
|
89 |
|
|
90 |
return commandViewerNameMap; |
|
91 |
} |
|
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 |
|
|
149 |
/** |
|
150 |
* Trys to create a List of {@link UuidAndTitleCache} from the selection.<BR> |
|
151 |
* Selections which are not recognized are not included in the list.<BR> |
|
152 |
* As a minimum each returned element contains the type and the uuid. |
|
153 |
* If available also the label and the CdmBase entity is added (later by using the subclass {@link DtoWithEntity}. |
|
154 |
* Label creation is not forced (TODO maybe in future we should have a parameter forceLabelCreation) |
|
155 |
* @param |
|
156 |
* @return list of {@link UuidAndTitleCache} |
|
157 |
*/ |
|
158 |
public static List<UuidAndTitleCache<? extends ICdmBase>> transformSelectionToUuidAndTitleCacheList(Object selection) { |
|
159 |
|
|
160 |
//make it all a list |
|
161 |
List<Object> multipleSelection = new ArrayList<>(); |
|
162 |
if(selection instanceof IStructuredSelection){ |
|
163 |
IStructuredSelection structuredSelection = ((IStructuredSelection) selection); |
|
164 |
((List<?>)structuredSelection.toList()).forEach(o->multipleSelection.add(o)); |
|
165 |
}else if(selection.getClass().isArray()){ |
|
166 |
for (Object o : ((Object[])selection)){ |
|
167 |
multipleSelection.add(o); |
|
168 |
} |
|
169 |
}else if(selection instanceof List){ |
|
170 |
multipleSelection.addAll((List<?>)selection); |
|
171 |
}else{ |
|
172 |
multipleSelection.add(selection); |
|
173 |
} |
|
174 |
|
|
175 |
//filter all as uuidIdAndTitleCache |
|
176 |
List<UuidAndTitleCache<? extends ICdmBase>> uuidTypes = new ArrayList<>(); |
|
177 |
|
|
178 |
for (Object o : multipleSelection){ |
|
179 |
if (o instanceof FeatureNodeContainer){ |
|
180 |
continue ; |
|
181 |
} |
|
182 |
if(o instanceof TreeNode){ |
|
183 |
o = ((TreeNode)o).getValue(); |
|
184 |
} |
|
185 |
o = CdmBase.deproxy(o); |
|
186 |
|
|
187 |
UuidAndTitleCache<? extends ICdmBase> uuidAndTitleCache; |
|
188 |
if (o instanceof CdmBase){ |
|
189 |
CdmBase cdmBase = (CdmBase)o; |
|
190 |
uuidAndTitleCache = new DtoWithEntity<>(cdmBase); |
|
191 |
}else if (o instanceof ReferencingObjectDto){ |
|
192 |
ReferencingObjectDto dto = (ReferencingObjectDto)o; |
|
193 |
uuidAndTitleCache = dto.getOpenInTarget() != null ? dto.getOpenInTarget() : dto; |
|
194 |
}else if (o instanceof UuidAndTitleCache){ |
|
195 |
uuidAndTitleCache = (UuidAndTitleCache<CdmBase>)o; |
|
196 |
}else{ |
|
197 |
continue; |
|
198 |
} |
|
199 |
uuidTypes.add(uuidAndTitleCache); |
|
200 |
} |
|
201 |
return uuidTypes; |
|
202 |
} |
|
203 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/details/DetailsViewerE4.java | ||
---|---|---|
145 | 145 |
import eu.etaxonomy.taxeditor.ui.section.vocabulary.TermMediaSection; |
146 | 146 |
import eu.etaxonomy.taxeditor.ui.section.vocabulary.TermVocabularyDetailSection; |
147 | 147 |
import eu.etaxonomy.taxeditor.view.detail.CdmSectionPart; |
148 |
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmDataViewerE4;
|
|
148 |
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmDataViewer; |
|
149 | 149 |
|
150 | 150 |
/** |
151 | 151 |
* The DetailsViewer handles the content of the details view ( |
... | ... | |
156 | 156 |
* @author pplitzner |
157 | 157 |
* @date 18.07.2017 |
158 | 158 |
*/ |
159 |
public class DetailsViewerE4 extends AbstractCdmDataViewerE4 {
|
|
159 |
public class DetailsViewerE4 extends AbstractCdmDataViewer { |
|
160 | 160 |
|
161 | 161 |
private ISelection selection; |
162 | 162 |
private boolean detailsEnabled = true; |
Also available in: Unified diff
ref #9448: remove E4 from file names - coninue and cleanup