/**
- *
- */
+ * Copyright (C) 2007 EDIT
+ * European Distributed Institute of Taxonomy
+ * http://www.e-taxonomy.eu
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * See LICENSE.TXT at the top of this package for the full license terms.
+ */
package eu.etaxonomy.taxeditor.newWizard;
import java.util.Map;
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.cdm.model.taxon.TaxonNodeStatus;
+import eu.etaxonomy.cdm.persistence.dto.MergeResult;
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
import eu.etaxonomy.taxeditor.l10n.Messages;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeWizardPage;
/**
- * <p>NewTaxonNodeWizard class.</p>
+ * NewTaxonNodeWizard class.
*
* @author n.hoffmann
* @created Sep 15, 2009
if (status == null){
notes = null;
}
- result = CdmStore.getService(ITaxonNodeService.class).createNewTaxonNode(parent.getUuid(), taxon, source, parent.getMicroReference(),
+
+ result = CdmStore.getService(ITaxonNodeService.class).createNewTaxonNode(parent.getUuid(), taxon, source, parent.getMicroReference(),
status, notes);
+
if (result.isOk()){
this.setEntity((TaxonNode)result.getCdmEntity());
- this.getEntity().getTaxon().setPublish(taxon.isPublish());
- MergeResult<TaxonNode> mergeResult = CdmStore.getService(ITaxonNodeService.class).merge(this.getEntity(), true);
- this.setEntity(mergeResult.getMergedEntity());
CdmApplicationState.getCurrentDataChangeService()
.fireChangeEvent(new CdmChangeEvent(Action.Create, result.getUpdatedObjects(), NewTaxonNodeWizard.class), true);
- CdmApplicationState.getCurrentDataChangeService()
- .fireChangeEvent(new CdmChangeEvent(Action.Create, mergeResult.getMergedEntity(), NewTaxonNodeWizard.class), true);
}else{
setSuccess(false);
}
}
- // @Override
- // protected TaxonNode createNewEntity() {
- // if(getSelection() != null){
- // Object selectedObject = getSelection().getFirstElement();
- // if(selectedObject instanceof TaxonNodeDto){
- // TaxonNodeDto taxonNodeDto = (TaxonNodeDto) selectedObject;
- // TaxonNode node = CdmStore.getService(ITaxonNodeService.class).load(taxonNodeDto.getUuid());
- // Reference sec = node.getTaxon() != null? node.getTaxon().getSec():null;
- // Taxon newTaxon = Taxon.NewInstance(TaxonNameFactory.NewNameInstance(PreferencesUtil.getPreferredNomenclaturalCode(), null), sec);
- // TaxonNode child = node.addChildTaxon(newTaxon, null, null);
- //
- // return child;
- //
- // }
- // }
- //
- // return null;
- // }
-
public boolean openInEditor() {
return isOpenInEditor ;
}
}
}
}
- }
+ }
+ /**
+ * Copyright (C) 2007 EDIT
+ * European Distributed Institute of Taxonomy
+ * http://www.e-taxonomy.eu
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * See LICENSE.TXT at the top of this package for the full license terms.
+ */
package eu.etaxonomy.taxeditor.ui.section.description;
-
import java.util.Comparator;
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
/**
* @author pplitzner
* @date Apr 13, 2016
- *
*/
public class SourceComparator <T extends OriginalSourceBase> implements Comparator<T> {
+
@Override
public int compare(T o1, T o2) {
- int id1 = o1.getId();
- int id2 = o2.getId();
+
+ //same and null compare, to be on the save side
+ if (o1 == o2){
+ return 0;
+ }else if (o1 == null){
+ return -1;
+ }else if (o2 == null){
+ return 1;
+ }
+
boolean isDescriptionElementSource1 = false;
boolean isDescriptionElementSource2 = false;
- if (o1 instanceof DescriptionElementSource){
+ if (o1.isInstanceOf(DescriptionElementSource.class)){
isDescriptionElementSource1 = true;
}
- if (o2 instanceof DescriptionElementSource){
+ if (o2.isInstanceOf(DescriptionElementSource.class)){
isDescriptionElementSource2 = true;
}
+ int result = 0;
if (isDescriptionElementSource1 != isDescriptionElementSource2){
if (isDescriptionElementSource1){
return -1;
return 1;
}
}
- OriginalSourceType type1 = o1.getType();
- OriginalSourceType type2 = o2.getType();
- Reference citation1 = o1.getCitation();
- Reference citation2 = o2.getCitation();
-
-
// the newly created should always be on top
- if (id1 == 0){
- if(id2!=0) {
- return -1;
- }
- else{
- result = 0;
- }
- } else if(id2==0){
+ if (!o1.isPersited() && o2.isPersited()) {
+ return -1;
+ } else if(o1.isPersited() && !o2.isPersited()){
return 1;
}
// sort by type (Primary taxonomic > Primary Media > others
// alphabetically by reference title cache)
- else if (type1 == null){
- if(type2==null){
- result = 0;
- }
- else{
- result = -1;
+ OriginalSourceType type1 = o1.getType();
+ OriginalSourceType type2 = o2.getType();
+ if (type1 == null){
+ if (type2!=null){
+ return -1;
}
} else if (type2 == null){
- result = 1;
+ return 1;
} else if(type1.equals(type2)){
- result = 0;
+ //continue with citation compare
} else if (type1.equals(OriginalSourceType.PrimaryTaxonomicSource)){
- result = 1;
+ return 1;
} else if (type2.equals(OriginalSourceType.PrimaryTaxonomicSource)){
- result = -1;
+ return -1;
} else if (type1.equals(OriginalSourceType.PrimaryMediaSource)){
- result = 1;
+ return 1;
} else if (type2.equals(OriginalSourceType.PrimaryMediaSource)){
- result = -1;
+ return -1;
}
+ int result;
+
//sort by citation title cache if types are equal
- if (result == 0){
- if(citation1!=null && citation2!=null){
- result = citation1.getTitleCache().compareTo(citation2.getTitleCache());
+ Reference citation1 = o1.getCitation();
+ Reference citation2 = o2.getCitation();
+ if(citation1!=null && citation2!=null){
+ result = citation1.getTitleCache().compareTo(citation2.getTitleCache());
+ if (result != 0){
+ return result;
}
+ }
- if(o2.getCreated()!=null && o1.getCreated()!=null){
- result = o1.getCreated().compareTo(o2.getCreated());
- }else if (o1.getCreated() == null ){
- if (o2.getCreated() == null){
- result = 0;
- }else{
- return -1;
- }
- }else if (o2.getCreated() == null){
- return 1;
+ //sort by created
+ if(o2.getCreated()!=null && o1.getCreated()!=null){
+ result = o1.getCreated().compareTo(o2.getCreated());
+ if (result != 0){
+ return result;
}
- if (result == 0){
- //default fallback
- return o1.getUuid().compareTo(o2.getUuid());
+ }else if (o1.getCreated() == null){
+ if (o2.getCreated() != null){
+ return -1;
}
+ }else if (o2.getCreated() == null){
+ return 1;
}
- return result;
-
+ //default fallback
+ return o1.getUuid().compareTo(o2.getUuid());
}
- }
+ }