2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.editor
.handler
;
14 import org
.apache
.log4j
.Logger
;
15 import org
.eclipse
.core
.commands
.AbstractHandler
;
16 import org
.eclipse
.core
.commands
.ExecutionEvent
;
17 import org
.eclipse
.core
.commands
.ExecutionException
;
18 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
19 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
21 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
25 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
26 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
27 import eu
.etaxonomy
.taxeditor
.editor
.name
.IterableSynonymyList
;
34 public class SaveTaxonHandler
extends AbstractHandler
{
35 private static final Logger logger
= Logger
36 .getLogger(SaveTaxonHandler
.class);
39 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
41 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
43 MultiPageTaxonEditor editor
= EditorUtil
.getActiveEditor();
44 // check for non zero length of taxon name
45 if(isNameZeroLength(editor
.getTaxon().getName())){
46 MessageDialog
.openWarning(HandlerUtil
.getActiveShell(event
), "No Name Specified", "An attempt was made to save a taxon with " +
47 "an empty name. Operation was cancelled.");
51 if (!areRelatedNamesNonZeroLength(editor
.getTaxon())) {
52 MessageDialog
.openWarning(HandlerUtil
.getActiveShell(event
), "Zero-Length Name", "One of this taxon's relationships " +
53 "has a zero-length name. Operation was cancelled.");
54 logger
.trace("Tero length name detected.");
58 return EditorUtil
.getActivePage().saveEditor(editor
, false);
66 private boolean isNameZeroLength(TaxonNameBase
<?
, ?
> name
) {
70 return (name
.getFullTitleCache().length() == 0);
77 private boolean areRelatedNamesNonZeroLength(Taxon taxon
) {
78 for (TaxonBase
<?
> taxonBase
: new IterableSynonymyList(taxon
)) {
79 if (isNameZeroLength(taxonBase
.getName()) ) {
83 Set
<TaxonRelationship
> taxonRelations
= taxon
.getTaxonRelations();
84 for (TaxonRelationship relationship
: taxonRelations
) {
85 if (isNameZeroLength(relationship
.getToTaxon().getName()) ||
86 isNameZeroLength(relationship
.getFromTaxon().getName())) {