X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/blobdiff_plain/a455b8b5b4ba1690bdc0051656964d58b420169e..f9dc4154daee1d76939294ee45a40f577485eb12:/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/NonViralNamePropertySource.java?ds=sidebyside diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/NonViralNamePropertySource.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/NonViralNamePropertySource.java index a55cfb07d..2fcbbe8e3 100644 --- a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/NonViralNamePropertySource.java +++ b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/NonViralNamePropertySource.java @@ -9,10 +9,10 @@ package eu.etaxonomy.taxeditor.propertysheet.name; +import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.util.ArrayList; -import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.Set; @@ -26,25 +26,23 @@ import org.eclipse.ui.views.properties.PropertyDescriptor; import org.eclipse.ui.views.properties.TextPropertyDescriptor; import eu.etaxonomy.cdm.common.CdmUtils; -import eu.etaxonomy.cdm.model.common.Annotation; +import eu.etaxonomy.cdm.model.common.IIdentifiableEntity; import eu.etaxonomy.cdm.model.common.TermVocabulary; -import eu.etaxonomy.cdm.model.common.TimePeriod; import eu.etaxonomy.cdm.model.name.NomenclaturalStatus; import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType; import eu.etaxonomy.cdm.model.name.NonViralName; import eu.etaxonomy.cdm.model.name.Rank; -import eu.etaxonomy.cdm.model.reference.Article; -import eu.etaxonomy.cdm.model.reference.BibtexReference; -import eu.etaxonomy.cdm.model.reference.Book; -import eu.etaxonomy.cdm.model.reference.BookSection; import eu.etaxonomy.cdm.model.reference.Generic; import eu.etaxonomy.cdm.model.reference.INomenclaturalReference; +import eu.etaxonomy.cdm.model.reference.ReferenceBase; import eu.etaxonomy.taxeditor.ITaxEditorConstants; -import eu.etaxonomy.taxeditor.TaxEditorPlugin; -import eu.etaxonomy.taxeditor.UiUtil; +import eu.etaxonomy.taxeditor.controller.PreferencesController; +import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository; import eu.etaxonomy.taxeditor.propertysheet.AnnotationPropertySource; import eu.etaxonomy.taxeditor.propertysheet.AnnotationsPropertyDescriptor; import eu.etaxonomy.taxeditor.propertysheet.MarkersPropertySource; +import eu.etaxonomy.taxeditor.propertysheet.reference.NomenclaturalReferencePropertySource; +import eu.etaxonomy.taxeditor.propertysheet.reference.ReferencePropertySource; /** * @author p.ciardelli @@ -59,7 +57,7 @@ public class NonViralNamePropertySource implements IPropertySource { NonViralName name; // If this is a property with a parent, the parent's property ID - private String parentid; + private String parentid = ""; PropertyChangeSupport propertyChangeSupport; @@ -67,13 +65,7 @@ public class NonViralNamePropertySource implements IPropertySource { public static final String P_ID_PARSED = "parsed"; public static final String P_ID_RANK = "rank"; public static final String P_ID_TITLECACHE = "titlecache"; - public static final String P_ID_UNINOMIAL = "uninomial"; - public static final String P_ID_INFRAGENERICEP = "infragenericep"; - public static final String P_ID_SPECIESEP = "speciesep"; - public static final String P_ID_INFRASPECIFICEP = "infraspecificep"; - public static final String P_ID_APPENDEDPHRASE = "appendedphrase"; public static final String P_ID_HOMOTYPICALGROUP = "homogroup"; - public static final String P_ID_AUTHORSHIPCACHE = "authorshipcache"; public static final String P_ID_NAMERELATIONS = "namerelations"; public static final String P_ID_TYPE = "type"; public static final String P_ID_ANNOTATIONS = "annotations"; @@ -86,10 +78,6 @@ public class NonViralNamePropertySource implements IPropertySource { public static final String P_ID_NOMENCLATURAL_CODE = "nomenclaturalcode"; public static final String P_ID_NOMENCLATURAL_REF = "nomenclaturalref"; public static final String P_ID_NOMENCLATURAL_MICROREF = "nomenclaturalmicroref"; - public static final String P_ID_REFERENCEYEAR = "referenceyear"; - public static final String P_ID_NOMREF_TYPE = "nomreftype"; - public static final String P_ID_NOMREF_YEAR = "nomrefyear"; - public static final String P_ID_NOMREF_TITLE = "nomreftitle"; // Property display keys // Note: for an explanation of the sorting prefixes ("04:"), @@ -97,17 +85,11 @@ public class NonViralNamePropertySource implements IPropertySource { public static final String P_PARSED = "00:Parsing Status"; public static final String P_RANK = "02:Rank"; public static final String P_TITLECACHE = "03:Name Cache"; - public static final String P_UNINOMIAL = "04:Uninomial"; - public static final String P_INFRAGENERICEP = "05:Infrageneric Epithet"; - public static final String P_SPECIESEP = "06:Specific Epithet"; - public static final String P_INFRASPECIFICEP = "07:Infraspecific Epithet"; - public static final String P_APPENDEDPHRASE = "09:Appended Phrase"; public static final String P_HOMOTYPICALGROUP = "09:Homotypical Group"; - public static final String P_AUTHORSHIPCACHE = "08:Authorship"; public static final String P_NAMERELATIONS = "11:Name Relations"; public static final String P_TYPE = "12:Type"; public static final String P_ANNOTATIONS = "14:Annotations"; - public static final String P_NOMSTATUS = "10:Nomenclatural Status"; + public static final String P_NOMSTATUS = "100:Nomenclatural Status"; public static final String P_UUID = "01:UUID"; public static final String P_NUM_OF_BASES = "12:Number of Bases"; public static final String P_MARKERS = "13:Markers"; @@ -115,14 +97,12 @@ public class NonViralNamePropertySource implements IPropertySource { public static final String P_CREATEDBY = "16:Created By"; public static final String P_NOMENCLATURAL_CODE = "02:Nomenclatural Code"; public static final String P_NOMENCLATURAL_REF = "09:Nomenclatural Reference"; - public static final String P_NOMENCLATURAL_MICROREF = "10:Micro Reference"; - public static final String P_NOMREF_TYPE = "00:Reference Type"; - public static final String P_NOMREF_YEAR = "02:Year"; - public static final String P_NOMREF_TITLE = "01:Title"; + public static final String P_NOMENCLATURAL_MICROREF = "10:Reference Detail"; - protected static final String[] TOP_LEVEL_PROPERTIES = new String[] {P_ID_PARSED, P_ID_RANK, P_ID_TITLECACHE, - P_ID_ANNOTATIONS, P_ID_NOMSTATUS, P_ID_NAMERELATIONS, P_ID_UUID, P_ID_NOMENCLATURAL_REF, - P_ID_TYPE, P_ID_CREATED, P_ID_CREATEDBY, P_ID_NOMENCLATURAL_CODE }; + protected static final String[] TOP_LEVEL_PROPERTIES = new String[] { + P_ID_PARSED, P_ID_RANK, P_ID_TITLECACHE, P_ID_ANNOTATIONS, P_ID_NOMSTATUS, + P_ID_NAMERELATIONS, P_ID_UUID, P_ID_NOMENCLATURAL_REF, P_ID_NOMENCLATURAL_MICROREF, + P_ID_CREATED, P_ID_CREATEDBY, P_ID_NOMENCLATURAL_CODE }; // *********************************************************** // RANKS @@ -133,7 +113,7 @@ public class NonViralNamePropertySource implements IPropertySource { // Get terms from rank vocabulary List ranksList = new ArrayList(); - ranksList.addAll(UiUtil.getPreferredRanks()); + ranksList.addAll(PreferencesController.getPreferredRanks()); // Populate ranks menu labels List ranksMenuList = new ArrayList(); @@ -150,21 +130,28 @@ public class NonViralNamePropertySource implements IPropertySource { P_RANK_MENU = ranksMenuList.toArray(new String[ranksMenuList.size()]); } - static String[] P_NOMENCLATURALCODE_MENU = new String[] { "ICZN", "ICBN" }; - static String[] P_NOMREF_TYPE_MENU = new String[] { "Article", "Bibtex", "Book", "Book Section", "Generic" }; - // *********************************************************** // NOMENCLATURAL STATUS // *********************************************************** - static TermVocabulary nomStatusVocabulary = - TaxEditorPlugin.getDefault().getNomStatusVocabulary(); - static NomenclaturalStatusType[] nomStatusTypes = null; - static String[] P_NOMSTATUS_MENU = null; - private static void populateNomStatusTypes() { +// static TermVocabulary nomStatusVocabulary = +// TaxEditorPlugin.getDefault().getNomStatusVocabulary(); + NomenclaturalStatusType[] nomStatusTypes = null; + String[] P_NOMSTATUS_MENU = null; + private void populateNomStatusTypes() { // Get terms from nom status vocabulary List nomStatusTypesList = new ArrayList(); - nomStatusTypesList.addAll(nomStatusVocabulary.getTerms()); + TermVocabulary statusVocab = + CdmSessionDataRepository.getDefault().getNomStatus(); + + // If there is no status vocabulary, init type and status w empty arrays and return + if (statusVocab == null) { + nomStatusTypes = new NomenclaturalStatusType[]{}; + P_NOMSTATUS_MENU = new String[]{}; + return; + } + + nomStatusTypesList.addAll(statusVocab.getTerms()); // Populate nom status type menu labels List nomStatusTypesMenuList = new ArrayList(); @@ -202,10 +189,14 @@ public class NonViralNamePropertySource implements IPropertySource { * @param id */ protected void addDescriptor(String id) { + + // Parsed: reports whether parsing was successful if (id.equals(P_ID_PARSED)) { descriptors.addElement( new PropertyDescriptor(P_ID_PARSED, P_PARSED)); } + + // Rank menu if (id.equals(P_ID_RANK)) { if (ranks == null) { populateRanks(); @@ -213,42 +204,23 @@ public class NonViralNamePropertySource implements IPropertySource { descriptors.addElement( new ComboBoxPropertyDescriptor(P_ID_RANK, P_RANK, P_RANK_MENU)); } + + // Title cache if (id.equals(P_ID_TITLECACHE)) { descriptors.addElement( new PropertyDescriptor(P_ID_TITLECACHE, P_TITLECACHE)); } - if (id.equals(P_ID_UNINOMIAL)) { - descriptors.addElement( - new TextPropertyDescriptor(P_ID_UNINOMIAL, P_UNINOMIAL)); - } - if (id.equals(P_ID_INFRAGENERICEP)) { - descriptors.addElement( - new TextPropertyDescriptor(P_ID_INFRAGENERICEP, P_INFRAGENERICEP)); - } - if (id.equals(P_ID_SPECIESEP)) { - descriptors.addElement( - new TextPropertyDescriptor(P_ID_SPECIESEP, P_SPECIESEP)); - } - if (id.equals(P_ID_INFRASPECIFICEP)) { - descriptors.addElement( - new TextPropertyDescriptor(P_ID_INFRASPECIFICEP, P_INFRASPECIFICEP)); - } - if (id.equals(P_ID_APPENDEDPHRASE)) { - descriptors.addElement( - new TextPropertyDescriptor(P_ID_APPENDEDPHRASE, P_APPENDEDPHRASE)); - } - if (id.equals(P_ID_AUTHORSHIPCACHE)) { - descriptors.addElement( - new TextPropertyDescriptor(P_ID_AUTHORSHIPCACHE, P_AUTHORSHIPCACHE)); - } + + // Homotypical group if (id.equals(P_ID_HOMOTYPICALGROUP)) { descriptors.addElement( new PropertyDescriptor(P_ID_HOMOTYPICALGROUP, P_HOMOTYPICALGROUP)); } + + // Name relations, listed in custom property descriptor if (id.equals(P_ID_NAMERELATIONS)) { descriptors.addElement( new NameRelationsPropertyDescriptor(P_ID_NAMERELATIONS, P_NAMERELATIONS, name) { - @Override protected void saveNameRelations(Set set) { setPropertyValue(P_ID_NAMERELATIONS, set); } @@ -256,20 +228,24 @@ public class NonViralNamePropertySource implements IPropertySource { ); }; + // Type if (id.equals(P_ID_TYPE)) { descriptors.addElement( new PropertyDescriptor(P_ID_TYPE, P_TYPE)); } + + // Annotations, listed in custom property descriptor if (id.equals(P_ID_ANNOTATIONS)) { descriptors.addElement( new AnnotationsPropertyDescriptor(P_ID_ANNOTATIONS, P_ANNOTATIONS, name) { - @Override protected void saveAnnotations(Set set) { setPropertyValue(P_ID_ANNOTATIONS, set); } } ); }; + + // Nomenclatural status if (id.equals(P_ID_NOMSTATUS)) { if (nomStatusTypes == null) { populateNomStatusTypes(); @@ -277,54 +253,54 @@ public class NonViralNamePropertySource implements IPropertySource { descriptors.addElement( new ComboBoxPropertyDescriptor(P_ID_NOMSTATUS, P_NOMSTATUS, P_NOMSTATUS_MENU)); } + + // UUID if (id.equals(P_ID_UUID)) { descriptors.addElement( new PropertyDescriptor(P_ID_UUID, P_UUID)); } + + // Markers if (id.equals(P_ID_MARKERS)) { descriptors.addElement( new PropertyDescriptor(P_ID_MARKERS, P_MARKERS)); } + + // Taxon bases referring to this name if (id.equals(P_ID_NUM_OF_BASES)) { descriptors.addElement( new PropertyDescriptor(P_ID_NUM_OF_BASES, P_NUM_OF_BASES)); } + + // Object created when if (id.equals(P_ID_CREATED)) { descriptors.addElement( new PropertyDescriptor(P_ID_CREATED, P_CREATED)); } + + // Object created by if (id.equals(P_ID_CREATEDBY)) { descriptors.addElement( new PropertyDescriptor(P_ID_CREATEDBY, P_CREATEDBY)); } + + // Nomenclatural code used by parser if (id.equals(P_ID_NOMENCLATURAL_CODE)) { descriptors.addElement( new PropertyDescriptor(P_ID_NOMENCLATURAL_CODE, P_NOMENCLATURAL_CODE)); - // Assuming the ability to change a name's code is not a burning priority ... -// new ComboBoxPropertyDescriptor(P_ID_NOMENCLATURAL_CODE, P_NOMENCLATURAL_CODE, P_NOMENCLATURALCODE_MENU)); } + + // Nomenclatural reference if (id.equals(P_ID_NOMENCLATURAL_REF)) { descriptors.addElement( -// new TextPropertyDescriptor(P_ID_NOMENCLATURAL_REF, P_NOMENCLATURAL_REF)); - new PropertyDescriptor(P_ID_NOMENCLATURAL_REF, P_NOMENCLATURAL_REF)); + new PropertyDescriptor(P_ID_NOMENCLATURAL_REF,P_NOMENCLATURAL_REF)); } + + // Microreference if (id.equals(P_ID_NOMENCLATURAL_MICROREF)) { descriptors.addElement( new TextPropertyDescriptor(P_ID_NOMENCLATURAL_MICROREF,P_NOMENCLATURAL_MICROREF)); - } - if (id.equals(P_ID_NOMREF_TYPE)) { - descriptors.addElement( - new PropertyDescriptor(P_ID_NOMREF_TYPE, P_NOMREF_TYPE)); -// new ComboBoxPropertyDescriptor(P_ID_NOMREF_TYPE, P_NOMREF_TYPE, P_NOMREF_TYPE_MENU)); - } - if (id.equals(P_ID_NOMREF_YEAR)) { - descriptors.addElement( - new TextPropertyDescriptor(P_ID_NOMREF_YEAR, P_NOMREF_YEAR)); - } - if (id.equals(P_ID_NOMREF_TITLE)) { - descriptors.addElement( - new TextPropertyDescriptor(P_ID_NOMREF_TITLE, P_NOMREF_TITLE)); - } + } } /** @@ -345,22 +321,23 @@ public class NonViralNamePropertySource implements IPropertySource { } } - @Override public Object getEditableValue() { - return this; + return CdmUtils.Nz(name.getTitleCache()); } - @Override public IPropertyDescriptor[] getPropertyDescriptors() { return (IPropertyDescriptor[]) descriptors.toArray( new IPropertyDescriptor[descriptors.size()]); } - @Override public Object getPropertyValue(Object id) { + + // Parsed: reports whether parsing was successful if (id.equals(P_ID_PARSED)) { return name.getHasProblem() == true ? "problem" : "parsed" ; } + + // Rank menu if (id.equals(P_ID_RANK)) { if (this.name.getRank() == null) { return 0; @@ -373,40 +350,41 @@ public class NonViralNamePropertySource implements IPropertySource { } return 0; } + + // Title cache if (id.equals(P_ID_TITLECACHE)) { // If the name has not been parsed, only show the title cache -// if (name.getHasProblem()) { if (name.getRank() == null) { return CdmUtils.Nz(name.getTitleCache()); } else { - return new NonViralNamePropertySource(name, P_ID_TITLECACHE, getNameFields()); + + // Create property source for submenu + ScientificNamePropertySource nameFieldsPropertySource = new ScientificNamePropertySource(name); + + // Add listener to notify name of all changes to nom. reference + nameFieldsPropertySource.addPropertyChangeListener(new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent evt) { +// if (evt.getNewValue() instanceof INomenclaturalReference) { +// name.setNomenclaturalReference((INomenclaturalReference) evt.getNewValue()); +// } + } + }); + return nameFieldsPropertySource; } } - if (id.equals(P_ID_UNINOMIAL)) { - return CdmUtils.Nz(name.getGenusOrUninomial()); - } - if (id.equals(P_ID_INFRAGENERICEP)) { - return CdmUtils.Nz(name.getInfraGenericEpithet()); - } - if (id.equals(P_ID_SPECIESEP)) { - return CdmUtils.Nz(name.getSpecificEpithet()); - } - if (id.equals(P_ID_INFRASPECIFICEP)) { - return CdmUtils.Nz(name.getInfraSpecificEpithet()); - } - if (id.equals(P_ID_APPENDEDPHRASE)) { - return CdmUtils.Nz(name.getAppendedPhrase()); - } - if (id.equals(P_ID_AUTHORSHIPCACHE)) { - return CdmUtils.Nz(name.getAuthorshipCache()); - } + + // Homotypical group if (id.equals(P_ID_HOMOTYPICALGROUP)) { return CdmUtils.Nz(name.getHomotypicalGroup().getUuid().toString()); } - if (id.equals(P_ID_ANNOTATIONS)) { - return new AnnotationPropertySource(name.getAnnotations()); - } + + // Annotations, listed in custom property descriptor +// if (id.equals(P_ID_ANNOTATIONS)) { +// return new AnnotationPropertySource(name.getAnnotations()); +// } + + // Nomenclatural status if (id.equals(P_ID_NOMSTATUS)) { // return new NomStatusPropertySource(name.getStatus()); // if (this.name.getRank() == null) return 0; @@ -424,22 +402,33 @@ public class NonViralNamePropertySource implements IPropertySource { } return 0; } + + // Name relations, popup to edit list if (id.equals(P_ID_NAMERELATIONS)) { return new NameRelationsPropertySource(name, name.getNameRelations()); } - // TODO Button to link to type module + + // Type if (id.equals(P_ID_TYPE)) { return ""; } + + // UUID if (id.equals(P_ID_UUID)) { return CdmUtils.Nz(name.getUuid().toString()); } + + // Markers if (id.equals(P_ID_MARKERS)) { return new MarkersPropertySource(name.getMarkers()); } + + // Taxon bases referring to this name if (id.equals(P_ID_NUM_OF_BASES)) { return name.getTaxonBases().size(); } + + // Object created by if (id.equals(P_ID_CREATED)) { if (name.getCreated() == null) { return ""; @@ -447,153 +436,63 @@ public class NonViralNamePropertySource implements IPropertySource { return formatDate(name.getCreated().toDate()); } } + + // Object created when if (id.equals(P_ID_CREATEDBY)) { if (name.getCreatedBy() == null) { return ""; } else { - return CdmUtils.Nz(name.getCreatedBy().generateTitle()); + return CdmUtils.Nz(((IIdentifiableEntity) name.getCreatedBy()).generateTitle()); } } + + // Nomenclatural code used by parser if (id.equals(P_ID_NOMENCLATURAL_CODE)) { // Only shown if extending classes don't handle P_ID_NOMENCLATURAL_CODE return "none (nonviral name)"; } + + // Nomenclatural reference if (id.equals(P_ID_NOMENCLATURAL_REF)) { -// INomenclaturalReference nomenclaturalReference = (INomenclaturalReference) name.getNomenclaturalReference(); -// if (nomenclaturalReference == null) { -// return ""; -// } -// String microReference = name.getNomenclaturalMicroReference(); -// return CdmUtils.Nz(nomenclaturalReference.getNomenclaturalCitation(microReference)); + + ReferenceBase nomRef = (ReferenceBase) name.getNomenclaturalReference(); - INomenclaturalReference nomenclaturalReference = (INomenclaturalReference) name.getNomenclaturalReference(); - if (name.getNomenclaturalReference() == null) { - return ""; - } else { - return new NonViralNamePropertySource(name, P_ID_NOMENCLATURAL_REF, getReferenceFields()); - } + // Create nom. reference as necessary + if (nomRef == null) { + nomRef = Generic.NewInstance(); + } + + // Create property source for submenu + ReferencePropertySource nomRefPropertySource = new NomenclaturalReferencePropertySource(nomRef); + + // Add listener to notify name of all changes to nom. reference + nomRefPropertySource.addPropertyChangeListener(new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getNewValue() instanceof INomenclaturalReference) { + name.setNomenclaturalReference((ReferenceBase) evt.getNewValue()); + } + } + }); + return nomRefPropertySource; + } + + // Microreference if (id.equals(P_ID_NOMENCLATURAL_MICROREF)) { return CdmUtils.Nz(name.getNomenclaturalMicroReference()); } - INomenclaturalReference nomenclaturalReference = (INomenclaturalReference) name.getNomenclaturalReference(); - if (id.equals(P_ID_NOMREF_TYPE)) { - if (nomenclaturalReference instanceof Article) { - return "Article"; - } - if (nomenclaturalReference instanceof BibtexReference) { - return "Bibtex"; - } - if (nomenclaturalReference instanceof Book) { - return "Book"; - } - if (nomenclaturalReference instanceof BookSection) { - return "Book Section"; - } - if (nomenclaturalReference instanceof Generic) { - return "Generic"; - } - return "none"; - } - if (id.equals(P_ID_NOMREF_YEAR)) { - return CdmUtils.Nz(nomenclaturalReference.getYear()); - } - if (id.equals(P_ID_NOMREF_TITLE)) { - if (nomenclaturalReference instanceof Article) { - return CdmUtils.Nz(((Article) nomenclaturalReference).getTitle()); - } - if (nomenclaturalReference instanceof BibtexReference) { - return CdmUtils.Nz(((BibtexReference) nomenclaturalReference).getTitle()); - } - if (nomenclaturalReference instanceof Book) { - return CdmUtils.Nz(((Book) nomenclaturalReference).getTitle()); - } - if (nomenclaturalReference instanceof BookSection) { - return CdmUtils.Nz(((BookSection) nomenclaturalReference).getTitle()); - } - if (nomenclaturalReference instanceof Generic) { - return CdmUtils.Nz(((Generic) nomenclaturalReference).getTitle()); - } - } return null; } - /** - * The fields displayed under the title cache are dependent on rank. - * - * @return - */ - private String[] getNameFields() { - - // An unparsed name has no name fields, only a cache. - // Therefore, if rank is null, the name is unparsed. - if (name.getRank() == null) { - return null; - } - - List nameFields = new ArrayList(); - nameFields.add(P_ID_UNINOMIAL); - if (name.isSupraGeneric() || name.isGenus()) { // Rank is higher than GENUS or equals GENUS - } - else if (name.isInfraGeneric()) { // lower than GENUS and higher than SPECIES - nameFields.add(P_ID_INFRAGENERICEP); - } - else if (name.isSpecies()) { // Rank equals SPECIES - nameFields.add(P_ID_SPECIESEP); - } - else if (name.isInfraSpecific()) { // Rank is lower than SPECIES - nameFields.add(P_ID_SPECIESEP); - nameFields.add(P_ID_INFRASPECIFICEP); - } else { - nameFields.add(P_ID_SPECIESEP); - } - nameFields.add(P_ID_AUTHORSHIPCACHE); - nameFields.add(P_ID_APPENDEDPHRASE); - return nameFields.toArray(new String[nameFields.size()]); - } - - private String[] getReferenceFields() { - List referenceFields = new ArrayList(); - - INomenclaturalReference reference = (INomenclaturalReference) name.getNomenclaturalReference(); - if (reference == null) { - return null; - } - - referenceFields.add(P_ID_NOMREF_TYPE); - referenceFields.add(P_ID_NOMREF_YEAR); - referenceFields.add(P_ID_NOMENCLATURAL_MICROREF); - referenceFields.add(P_ID_NOMREF_TITLE); - - if (reference instanceof Article) { - - } - if (reference instanceof BibtexReference) { - - } - if (reference instanceof Book) { - - } - if (reference instanceof BookSection) { - - } - if (reference instanceof Generic) { - - } - - return referenceFields.toArray(new String[referenceFields.size()]); - } private Object formatDate(Date date) { return String.format("%1$tm-%1$td-%1$tY %1$tH:%1$tM:%1$tS", date); } - @Override public boolean isPropertySet(Object id) { return false; } - @Override public void resetPropertyValue(Object id) {} /** @@ -601,7 +500,6 @@ public class NonViralNamePropertySource implements IPropertySource { * * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object) */ - @Override public void setPropertyValue(Object id, Object value) { // Since this is only called when the property value changes, @@ -609,41 +507,13 @@ public class NonViralNamePropertySource implements IPropertySource { // listener. name.firePropertyChange(ITaxEditorConstants.PROPERTY_SHEET_CHANGE, null, null); + // Rank menu if (id.equals(P_ID_RANK)) { int index = ((Integer) value).intValue(); name.setRank(ranks[index]); } - if (id.equals(P_ID_UNINOMIAL)) { - name.setGenusOrUninomial((String) value); - } - if (id.equals(P_ID_INFRAGENERICEP)) { - name.setInfraGenericEpithet((String) value); - } - if (id.equals(P_ID_SPECIESEP)) { - name.setSpecificEpithet((String) value); - } - if (id.equals(P_ID_INFRASPECIFICEP)) { - name.setInfraSpecificEpithet((String) value); - } - if (id.equals(P_ID_APPENDEDPHRASE)) { - name.setAppendedPhrase((String) value); - } - if (id.equals(P_ID_AUTHORSHIPCACHE)) { - name.setAuthorshipCache((String) value); - } - if (id.equals(P_ID_ANNOTATIONS)) { - Set annotations = name.getAnnotations(); - if (value instanceof Set) { - for (Object object: (Set) value) { - if (object instanceof Annotation && !annotations.contains(object)) { - name.addAnnotation((Annotation) object); - } - } - } - } - if (id.equals(P_ID_NAMERELATIONS)) { - // TODO set name relations - } + + // Nomenclatural status if (id.equals(P_ID_NOMSTATUS)) { NomenclaturalStatus nomStatus; int index = ((Integer) value).intValue(); @@ -663,102 +533,35 @@ public class NonViralNamePropertySource implements IPropertySource { name.addStatus(nomStatus); } } + + // Markers if (id.equals(P_ID_MARKERS)) { // TODO set markers } + + // Nomenclatural reference if (id.equals(P_ID_NOMENCLATURAL_REF)) { - // TODO ask Andreas M. how best to set nom. ref + if (value instanceof INomenclaturalReference) { + name.setNomenclaturalReference((ReferenceBase) value); + } } + + // Microreference if (id.equals(P_ID_NOMENCLATURAL_MICROREF)) { name.setNomenclaturalMicroReference((String) value); } - if (id.equals(P_ID_NOMREF_YEAR)) { - INomenclaturalReference reference = name.getNomenclaturalReference(); - - if (reference instanceof BibtexReference) { - ((BibtexReference) reference).setYear((String) value); - } - TimePeriod datePublished = getDatePublished((String) value); - if (reference instanceof Article) { - ((Article) reference).setDatePublished(datePublished); - } - if (reference instanceof Book) { - ((Book) reference).setDatePublished(datePublished); - } - if (reference instanceof BookSection) { - ((BookSection) reference).setDatePublished(datePublished); - } - if (reference instanceof Generic) { - ((Generic) reference).setDatePublished(datePublished); - } - } - if (id.equals(P_ID_NOMREF_TITLE)) { - INomenclaturalReference reference = name.getNomenclaturalReference(); + + // If there is no rank, generated caches will be blank, wiping out the freetext area + if (name.getRank() != null) { - if (reference instanceof BibtexReference) { - ((BibtexReference) reference).setTitle((String) value); - } - if (reference instanceof Article) { - ((Article) reference).setTitle((String) value); - } - if (reference instanceof Book) { - ((Book) reference).setTitle((String) value); - } - if (reference instanceof BookSection) { - ((BookSection) reference).setTitle((String) value); - } - if (reference instanceof Generic) { - ((Generic) reference).setTitle((String) value); - } + // Reset both caches to reflect property sheet changes + name.setTitleCache(name.generateTitle(), false); + name.setFullTitleCache(name.generateFullTitle(), false); } - - // Reset both caches to reflect property sheet changes - name.setTitleCache(name.generateTitle(), false); - name.setFullTitleCache(name.generateFullTitle(), false); - name.firePropertyChange(ITaxEditorConstants.REFRESH_NAMEVIEWER, null, null); - } - - private TimePeriod getDatePublished(String refYear) { - if (refYear == null){ - return null; - } +// name.firePropertyChange(ITaxEditorConstants.REFRESH_NAMEVIEWER, null, null); - String[] years = refYear.split("-"); - Calendar calStart = null; - Calendar calEnd = null; - if (years.length > 2 || years.length <= 0){ - logger.warn("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX getDatePublished"); - }else { - calStart = getCalendar(years[0]); - if (years.length >= 2){ - calEnd = getCalendar(years[1]); - } - } - TimePeriod result = TimePeriod.NewInstance(calStart, calEnd); - return result; } - - private static Calendar getCalendar(String strYear){ - - //FIXME until now only quick and dirty and wrong - Calendar cal = Calendar.getInstance(); - cal.set(9999, Calendar.DECEMBER, 30, 0, 0, 0); - if (CdmUtils.isNumeric(strYear)){ - try { - Integer year = Integer.valueOf(strYear.trim()); - if (year > 1750 && year < 2030){ - cal.set(year, Calendar.JANUARY, 1, 0, 0, 0); - } - } catch (NumberFormatException e) { - logger.debug("Not a Integer format in getCalendar()"); - } - } - - return cal; - - } - /** * Any node with children must override {@link java.lang.Object#toString()} @@ -766,13 +569,15 @@ public class NonViralNamePropertySource implements IPropertySource { * * @see java.lang.Object#toString() */ - @Override public String toString() { + if (parentid == null || parentid.equals("")) { + return ""; + } if (parentid.equals(P_ID_TITLECACHE)) { return name.getTitleCache(); } if (parentid.equals(P_ID_NOMENCLATURAL_REF)) { - INomenclaturalReference nomenclaturalReference = name.getNomenclaturalReference(); + INomenclaturalReference nomenclaturalReference = (INomenclaturalReference) name.getNomenclaturalReference(); if (nomenclaturalReference == null) { return ""; }