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