use OrderIndexComparator for distributionEditor
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / EditorUtil.java
1 /**
2 * Copyright (C) 2007 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
10 package eu.etaxonomy.taxeditor.editor;
11
12 import java.util.Collection;
13 import java.util.HashSet;
14 import java.util.List;
15 import java.util.UUID;
16
17 import org.eclipse.core.commands.ExecutionEvent;
18 import org.eclipse.core.commands.operations.IOperationHistory;
19 import org.eclipse.core.commands.operations.IUndoContext;
20 import org.eclipse.e4.ui.model.application.MApplication;
21 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
22 import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
23 import org.eclipse.e4.ui.workbench.modeling.EModelService;
24 import org.eclipse.e4.ui.workbench.modeling.EPartService;
25 import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
26 import org.eclipse.jface.dialogs.MessageDialog;
27 import org.eclipse.jface.viewers.ISelection;
28 import org.eclipse.jface.viewers.IStructuredSelection;
29 import org.eclipse.jface.viewers.TreeNode;
30 import org.eclipse.swt.widgets.Shell;
31 import org.eclipse.ui.IEditorPart;
32 import org.eclipse.ui.handlers.HandlerUtil;
33
34 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
35 import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
36 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
37 import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
38 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
39 import eu.etaxonomy.cdm.model.taxon.Synonym;
40 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
41 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
42 import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
43 import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
44 import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
45 import eu.etaxonomy.taxeditor.bulkeditor.input.TaxonEditorInput;
46 import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.DescriptiveDataSetEditor;
47 import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrixPart;
48 import eu.etaxonomy.taxeditor.editor.e4.TaxonEditorInputE4;
49 import eu.etaxonomy.taxeditor.editor.group.authority.CdmAuthorityEditorInput;
50 import eu.etaxonomy.taxeditor.editor.group.authority.e4.CdmAuthorityEditorE4;
51 import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
52 import eu.etaxonomy.taxeditor.editor.l10n.Messages;
53 import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
54 import eu.etaxonomy.taxeditor.editor.view.checklist.e4.DistributionEditorPart;
55 import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
56 import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewEditorInput;
57 import eu.etaxonomy.taxeditor.model.AbstractUtility;
58 import eu.etaxonomy.taxeditor.model.MessagingUtils;
59 import eu.etaxonomy.taxeditor.security.RequiredPermissions;
60 import eu.etaxonomy.taxeditor.store.CdmStore;
61 import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
62 import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
63
64 /**
65 * Utility for the editor package
66 *
67 * @author n.hoffmann
68 * @created 20.01.2009
69 * @version 1.0
70 */
71 public class EditorUtil extends AbstractUtility {
72
73 private static final String NAME_EDITOR_ID = "eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4";
74
75 private static boolean factsVisible = true;
76
77 private static boolean mediaVisible = true;
78
79 public static void openDescriptiveDataSetEditor(UUID descriptiveDataSetUuid, EModelService modelService, EPartService partService, MApplication application){
80 Collection<MPart> parts = partService.getParts();
81 for (MPart part : parts) {
82 if(part.getObject() instanceof DescriptiveDataSetEditor
83 && ((DescriptiveDataSetEditor) part.getObject()).getDescriptiveDataSet().getUuid().equals(descriptiveDataSetUuid)){
84 partService.showPart(part, PartState.ACTIVATE);
85 return;
86 }
87 }
88 String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DESCRIPTIVEDATASET_DESCRIPTIVEDATASETEDITOR;
89 MPart part = showPart(partId, modelService, partService, application);
90 DescriptiveDataSetEditor editor = (DescriptiveDataSetEditor) part.getObject();
91 editor.init(descriptiveDataSetUuid);
92 }
93
94 public static void openCharacterMatrix(UUID descriptiveDataSetUuid, EModelService modelService, EPartService partService, MApplication application){
95 Collection<MPart> parts = partService.getParts();
96 for (MPart part : parts) {
97 if(part.getObject() instanceof CharacterMatrixPart
98 && ((CharacterMatrixPart) part.getObject()).getDescriptiveDataSet().getUuid().equals(descriptiveDataSetUuid)){
99 partService.showPart(part, PartState.ACTIVATE);
100 return;
101 }
102 }
103 String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_DESCRIPTIVEDATASET_MATRIX_CHARACTERMATRIXPART;
104 MPart part = showPart(partId, modelService, partService, application);
105 CharacterMatrixPart editor = (CharacterMatrixPart) part.getObject();
106 editor.init(descriptiveDataSetUuid, true);
107 }
108
109 public static void openDistributionEditor(UuidAndTitleCache parentUuidAndTitleCache, EModelService modelService, EPartService partService, MApplication application){
110 Collection<MPart> parts = partService.getParts();
111 String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_CHECKLIST_E4_DISTRIBUTIONEDITORPART;
112 checkAndCloseFactsAndMediaParts(partService);
113 MPart part = showPart(partId, modelService, partService, application);
114 DistributionEditorPart editor = (DistributionEditorPart) part.getObject();
115 editor.init(parentUuidAndTitleCache);
116 }
117
118 public static void openDistributionEditor(List<UuidAndTitleCache> parentTaxonUuidList, EModelService modelService, EPartService partService, MApplication application){
119 Collection<MPart> parts = partService.getParts();
120 String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_CHECKLIST_E4_DISTRIBUTIONEDITORPART;
121 checkAndCloseFactsAndMediaParts(partService);
122 MPart part = showPart(partId, modelService, partService, application);
123 DistributionEditorPart editor = (DistributionEditorPart) part.getObject();
124 editor.init(parentTaxonUuidList);
125 }
126
127 public static void checkAndCloseFactsAndMediaParts(EPartService partService) {
128 String partIdFactualData = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DESCRIPTIVE_E4_FACTUALDATAPARTE4;
129 String partIdMedia = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_MEDIA_E4_MEDIAVIEWPARTE4;
130 MPart part1 = partService.findPart(AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DESCRIPTIVE_E4_FACTUALDATAPARTE4);
131 if (factsVisible || (part1!=null && part1.getWidget() != null && partService.isPartVisible(part1))){
132 factsVisible = true;
133 }else{
134 factsVisible = false;
135 }
136 part1 = partService.findPart(AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_MEDIA_E4_MEDIAVIEWPARTE4);
137 if (mediaVisible || (part1!=null && part1.getWidget() != null && partService.isPartVisible(part1))){
138 mediaVisible = true;
139 }else{
140 mediaVisible = false;
141 }
142 closePart(partIdMedia, partService);
143 closePart(partIdFactualData, partService);
144 }
145
146
147 public static void openSpecimenEditor(DerivateViewEditorInput input, EModelService modelService, EPartService partService, MApplication application){
148 String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DERIVATE_DERIVATEVIEW;
149 MPart part = showPart(partId, modelService, partService, application);
150 DerivateView derivateView = (DerivateView) part.getObject();
151 derivateView.init(input);
152 }
153
154 public static void openRightsEditor(CdmAuthorityEditorInput input, EModelService modelService, EPartService partService, MApplication application){
155 Collection<MPart> parts = partService.getParts();
156 for (MPart part : parts) {
157 if(part.getObject() instanceof CdmAuthorityEditorE4
158 && ((CdmAuthorityEditorE4) part.getObject()).getInput().getGroup().equals(input.getGroup())){
159 partService.showPart(part, PartState.ACTIVATE);
160 return;
161 }
162 }
163 String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_GROUP_AUTHORITY_E4_CDMAUTHORITYEDITORE4;
164 MPart part = showPart(partId, modelService, partService, application);
165 CdmAuthorityEditorE4 authorityView = (CdmAuthorityEditorE4) part.getObject();
166 authorityView.init(input);
167 }
168
169 public static MPart showPart(String partId, EModelService modelService, EPartService partService, MApplication application){
170 MPart part = partService.findPart(partId);
171 if(part==null || modelService.getPartDescriptor(partId).isAllowMultiple()){
172 part = partService.createPart(partId);
173 }
174 MPartStack editorAreaPartStack = WorkbenchUtility.getEditorAreaPartStack(application, modelService);
175 if(editorAreaPartStack!=null){
176 editorAreaPartStack.getChildren().add(part);
177 }
178
179 return partService.showPart(part, PartState.ACTIVATE);
180
181 }
182
183 public static MPart showPart(String partId, EModelService modelService, EPartService partService){
184 MPart part = partService.findPart(partId);
185 if(part==null || modelService.getPartDescriptor(partId).isAllowMultiple()){
186 part = partService.createPart(partId);
187 partService.activate(part);
188 }else{
189 partService.activate(part);
190 }
191
192 return part;
193 }
194
195 public static void openTaxonNodeE4(UUID taxonNodeUuid, EModelService modelService, EPartService partService, MApplication application) {
196 TaxonEditorInputE4 input = TaxonEditorInputE4.NewInstance(taxonNodeUuid);
197 openNameEditor_internal(input, modelService, partService, application);
198 }
199
200 public static void openTaxonBaseE4(UUID taxonBaseUuid, EModelService modelService, EPartService partService, MApplication application) {
201 TaxonEditorInputE4 input = TaxonEditorInputE4.NewInstanceFromTaxonBase(taxonBaseUuid);
202 openNameEditor_internal(input, modelService, partService, application);
203 }
204
205 public static void openTaxonBaseE4(UUID taxonBaseUuid) {
206 //FIXME E4 this can probably be removed when fully migrated
207 TaxonEditorInputE4 input = TaxonEditorInputE4.NewInstanceFromTaxonBase(taxonBaseUuid);
208
209 EPartService partService = TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getService(EPartService.class);
210 EModelService modelService = TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getService(EModelService.class);
211 openNameEditor_internal(input, modelService, partService, null);
212 }
213
214 private static void openNameEditor_internal(TaxonEditorInputE4 input, EModelService modelService, EPartService partService, MApplication application) {
215 TaxonBase taxonBase = input.getTaxon();
216 TaxonNode node = input.getTaxonNode();
217 if(taxonBase==null){
218 return;
219 }
220 boolean hasPermission = false;
221 // if (node != null){
222 hasPermission = CdmStore.currentAuthentiationHasPermission(node, RequiredPermissions.TAXON_EDIT);
223 // }
224 // if (!hasPermission){
225 // MessagingUtils.warningDialog(Messages.EditorUtil_MISSING_PERMISSION, TaxonEditorInputE4.class, Messages.EditorUtil_MISSING_PERMISSION_MESSAGE);
226 // return;
227 // }
228 if (taxonBase.isOrphaned()) {
229 if(taxonBase.isInstanceOf(Synonym.class)){
230 MessagingUtils.warningDialog(Messages.EditorUtil_ORPHAN_ACCEPTED_TAXON, TaxonEditorInputE4.class, Messages.EditorUtil_ORPHAN_ACCEPTED_TAXON_MESSAGE);
231 return;
232 }
233 else{
234 MessagingUtils.warningDialog(Messages.EditorUtil_ORPHAN_TAXON, TaxonEditorInputE4.class, Messages.EditorUtil_ORPHAN_TAXON_MESSAGE);
235 return;
236 }
237 }
238
239
240 Collection<MPart> parts = partService.getParts();
241 //check if part is already opened
242 for (MPart part : parts) {
243 if(part.getObject() instanceof TaxonNameEditorE4
244 && ((TaxonNameEditorE4) part.getObject()).getTaxon()!=null
245 && ((TaxonNameEditorE4) part.getObject()).getTaxon().getUuid().equals(input.getTaxon().getUuid())){
246 if (part.isDirty()){
247 forceUserSaveE4Editor(((TaxonNameEditorE4) part.getObject()), getShell());
248 }
249 partService.hidePart(part);
250 break;
251 }
252 }
253 MPart part = showPart(NAME_EDITOR_ID, modelService, partService, application);
254
255 TaxonNameEditorE4 editor = (TaxonNameEditorE4) part.getObject();
256 // editor.setDisabled();
257 editor.init(input);
258 // editor.setEnabled();
259 editor.setFocus();
260 if (factsVisible){
261 showFacts(modelService, partService);
262 factsVisible = false;
263 }
264
265 if (mediaVisible){
266 showMedia(modelService, partService);
267 mediaVisible = false;
268 }
269
270
271 }
272
273 public static void showMedia(EModelService modelService, EPartService partService) {
274 String partIdFactualData = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_MEDIA_E4_MEDIAVIEWPARTE4;
275 showPart(partIdFactualData, modelService, partService);
276
277 }
278
279 public static void showFacts(EModelService modelService, EPartService partService) {
280 String partIdFactualData = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DESCRIPTIVE_E4_FACTUALDATAPARTE4;
281 showPart(partIdFactualData, modelService, partService);
282
283 }
284
285 public static Collection<MPart> checkForChanges(UUID taxonUUID, EPartService partService ){
286 Collection<MPart> parts = partService.getParts();
287 Collection<MPart> dirtyParts = new HashSet();
288 //check if part is already opened
289 boolean isDirty = false;
290 for (MPart part : parts) {
291 if(part.getObject() instanceof TaxonNameEditorE4
292 && ((TaxonNameEditorE4) part.getObject()).getTaxon()!=null
293 && ((TaxonNameEditorE4) part.getObject()).getTaxon().getUuid().equals(taxonUUID)){
294 if (part.isDirty()){
295 dirtyParts.add(part);
296 }
297
298 break;
299 }else if (taxonUUID == null){
300 if (part.isDirty()){
301 dirtyParts.add(part);
302 }
303 }
304 }
305 return dirtyParts;
306 }
307
308 public static Collection<IE4SavablePart> checkForTaxonChanges(UUID taxonUUID, EPartService partService ){
309 Collection<MPart> parts = partService.getParts();
310 Collection<IE4SavablePart> dirtyParts = new HashSet<>();
311 //check if part is already opened
312 for (MPart part : parts) {
313 if(part.getObject() instanceof TaxonNameEditorE4
314 && ((TaxonNameEditorE4) part.getObject()).getTaxon()!=null
315 && ((TaxonNameEditorE4) part.getObject()).getTaxon().getUuid().equals(taxonUUID)){
316 if (part.isDirty()){
317 dirtyParts.add((IE4SavablePart) part);
318 }
319
320 break;
321 }else if (taxonUUID == null){
322 if (part.isDirty() && (part.getObject() instanceof TaxonNameEditorE4 || (part.getObject() instanceof BulkEditorE4 && ((BulkEditorE4)part.getObject()).getEditorInput() instanceof TaxonEditorInput))){
323 dirtyParts.add((IE4SavablePart) part.getObject());
324 }
325 }
326 }
327 return dirtyParts;
328 }
329
330 /**
331 * An uninitialized taxon is one that hasn't been saved yet. As such, it
332 * should appear in neither the list of recent names nor in the taxonomic
333 * tree when opened.
334 *
335 * @param parentNodeUuid
336 * a {@link java.util.UUID} object.
337 */
338 public static void openEmptyE4(UUID parentNodeUuid) {
339 TaxonEditorInputE4 input = TaxonEditorInputE4
340 .NewEmptyInstance(parentNodeUuid);
341 EPartService partService = TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getService(EPartService.class);
342 MPart part = partService.createPart(NAME_EDITOR_ID);
343 part = partService.showPart(part, PartState.ACTIVATE);
344 TaxonNameEditorE4 editor = (TaxonNameEditorE4) part.getObject();
345 editor.init(input);
346 }
347
348 /**
349 * <p>
350 * getUndoContext
351 * </p>
352 *
353 * @return a {@link org.eclipse.core.commands.operations.IUndoContext}
354 * object.
355 */
356 public static IUndoContext getUndoContext() {
357 return IOperationHistory.GLOBAL_UNDO_CONTEXT;
358 }
359
360 public static boolean isFactsVisible() {
361 return factsVisible;
362 }
363
364 public static void setFactsVisible(boolean factsVisible) {
365 EditorUtil.factsVisible = factsVisible;
366 }
367
368 public static boolean isMediaVisible() {
369 return mediaVisible;
370 }
371
372 public static void setMediaVisible(boolean mediaVisible) {
373 EditorUtil.mediaVisible = mediaVisible;
374 }
375
376 /**
377 * <p>
378 * forceUserSave
379 * </p>
380 *
381 * @param editor
382 * a {@link org.eclipse.ui.IEditorPart} object.
383 * @param shell
384 * a {@link org.eclipse.swt.widgets.Shell} object.
385 * @return a boolean.
386 */
387 public static boolean forceUserSave(IEditorPart editor, Shell shell) {
388 if (editor.isDirty()) {
389
390 boolean doSave = MessageDialog
391 .openConfirm(shell, Messages.EditorUtil_COMFIRM_SAVE,
392 Messages.EditorUtil_CONFIRM_SAVE_MESSAGE);
393
394 if (!doSave) {
395 return false;
396 }
397
398 editor.doSave(AbstractUtility.getMonitor());
399 }
400 return true;
401 }
402
403 public static boolean forceUserSaveE4Editor(IE4SavablePart editor, Shell shell) {
404 if (editor.isDirty()) {
405
406 boolean doSave = MessageDialog
407 .openConfirm(shell, Messages.EditorUtil_COMFIRM_SAVE,
408 Messages.EditorUtil_CONFIRM_SAVE_MESSAGE);
409
410 if (!doSave) {
411 return false;
412 }
413
414 editor.save(AbstractUtility.getMonitor());
415 }
416 return true;
417 }
418
419 /**
420 * <p>
421 * getSelection
422 * </p>
423 *
424 * @param event
425 * a {@link org.eclipse.core.commands.ExecutionEvent} object.
426 * @return a {@link org.eclipse.jface.viewers.IStructuredSelection} object.
427 */
428 public static IStructuredSelection getSelection(ExecutionEvent event) {
429 IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
430
431 return (IStructuredSelection) activeEditor.getSite()
432 .getSelectionProvider().getSelection();
433 }
434
435 /**
436 * <p>
437 * getPluginId
438 * </p>
439 *
440 * @return a {@link java.lang.String} object.
441 */
442 public static String getPluginId() {
443 return TaxeditorEditorPlugin.PLUGIN_ID;
444 }
445
446 /**
447 * Iterates recursively over all originals having the given specimen as a derivate.
448 * The first {@link DerivedUnit} with no more originals or the first {@link FieldUnit} is returned
449 * @param specimen the start element for which the originals are iterated recursively
450 * @return either a FieldUnit or a the topmost DerivedUnit (which can be itself)
451 */
452 public static SpecimenOrObservationBase<?> getTopMostDerivate(SpecimenOrObservationBase<?> specimen){
453 if(specimen==null){
454 return null;
455 }
456 if(specimen.isInstanceOf(FieldUnit.class)){
457 return specimen;
458 }
459 else if(specimen.isInstanceOf(DerivedUnit.class)){
460 DerivedUnit derivedUnit = HibernateProxyHelper.deproxy(specimen, DerivedUnit.class);
461 if(derivedUnit.getOriginals()!=null
462 && !(derivedUnit.getOriginals().isEmpty())){
463 for(SpecimenOrObservationBase<?> original:((DerivedUnit) specimen).getOriginals()){
464 return getTopMostDerivate(original);
465 }
466 }
467 }
468 return specimen;
469 }
470
471 /**
472 * If the current selection is a single {@link TreeNode} it will be returned.
473 * @param selection the selection to check
474 * @return the selected TreeNode or <code>null</code> if no TreeNode selected
475 */
476 public static TreeNode getTreeNodeOfSelection(ISelection selection){
477 if(selection instanceof IStructuredSelection
478 && ((IStructuredSelection) selection).size()==1
479 && ((IStructuredSelection) selection).getFirstElement() instanceof TreeNode){
480 return (TreeNode) ((IStructuredSelection) selection).getFirstElement();
481
482 }
483 return null;
484 }
485
486 public static void closeObsoleteEditor(TaxonNodeDto taxonNode, EPartService partService){
487 String treeIndex = taxonNode.getTreeIndex();
488 Collection<MPart> parts = partService.getParts();
489 for (MPart part : parts) {
490 Object object = part.getObject();
491 if(object instanceof TaxonNameEditorE4){
492 TaxonNameEditorE4 taxonEditor = (TaxonNameEditorE4)object;
493 TaxonNode node = taxonEditor.getEditorInput().getTaxonNode();
494 if (node.treeIndex()!= null){
495 if(node.treeIndex().startsWith(treeIndex)){
496 if (part.isDirty()){
497 forceUserSaveE4Editor(taxonEditor, getShell());
498 }
499 partService.hidePart(part);
500 }
501 }else{
502 logger.debug("The taxonnode of taxon " + node.getTaxon().getTitleCache() + " uuid: " + node.getUuid() + " has no treeindex");;
503 }
504 }
505 }
506 }
507
508 public static void closeObsoleteEditorWithChildren(TaxonNodeDto taxonNode, EPartService partService){
509 String treeIndex = taxonNode.getTreeIndex();
510 Collection<MPart> parts = partService.getParts();
511 for (MPart part : parts) {
512 Object object = part.getObject();
513 if(object instanceof TaxonNameEditorE4){
514 TaxonNameEditorE4 taxonEditor = (TaxonNameEditorE4)object;
515 TaxonNode node = taxonEditor.getEditorInput().getTaxonNode();
516 if (node.treeIndex()!= null){
517 if(node.treeIndex().startsWith(treeIndex)){
518 if (part.isDirty()){
519 forceUserSaveE4Editor(taxonEditor, getShell());
520 }
521 partService.hidePart(part);
522 }
523 }else{
524 logger.debug("The taxonnode of taxon " + node.getTaxon().getTitleCache() + " uuid: " + node.getUuid() + " has no treeindex");;
525 }
526 }
527 }
528 }
529
530
531 public static void closeObsoleteDescriptiveDatasetEditor(UUID datasetUuid, EPartService partService){
532
533 Collection<MPart> parts = partService.getParts();
534 for (MPart part : parts) {
535 Object object = part.getObject();
536 if(object instanceof DescriptiveDataSetEditor){
537 DescriptiveDataSetEditor editor = (DescriptiveDataSetEditor)object;
538 DescriptiveDataSet descDataSet = editor.getDescriptiveDataSet();
539 if(descDataSet.getUuid().equals(datasetUuid)){
540 if (part.isDirty()){
541 forceUserSaveE4Editor(editor, getShell());
542 }
543 partService.hidePart(part);
544 }
545
546 }
547 }
548 }
549
550
551 public static void closePart(String partID, EPartService partService){
552
553 Collection<MPart> parts = partService.getParts();
554 for (MPart part : parts) {
555 String elementId = part.getElementId();
556 if (elementId.equals(partID)){
557 partService.hidePart(part);
558 }
559 }
560 }
561
562 public static void updateEditor(TaxonNode taxonNode, TaxonNameEditorE4 editor){
563 String treeIndex = taxonNode.treeIndex();
564 TaxonNode node = editor.getEditorInput().getTaxonNode();
565 if(node.treeIndex().equals(treeIndex)){
566 TaxonEditorInputE4 input = TaxonEditorInputE4.NewInstance(node.getUuid());
567 editor.init(input);
568 }
569 }
570
571 }