import org.eclipse.jface.window.Window;
import org.eclipse.nebula.widgets.nattable.NatTable;
import org.eclipse.nebula.widgets.nattable.command.StructuralRefreshCommand;
+import org.eclipse.nebula.widgets.nattable.command.VisualRefreshCommand;
import org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration;
import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
btnCollapseAll.setEnabled(isTree);
btnExpandAll.setEnabled(isTree);
natTable.doCommand(new StructuralRefreshCommand());
+ natTable.doCommand(new VisualRefreshCommand());
}
public void init(UUID workingSetUuid, boolean treeView) {
}
// use the SortedList constructor with 'null' for the Comparator
// because the Comparator will be set by configuration
- SortedList<Object> sortedList = new SortedList<>(descriptions, null);
+ SortedList<Object> sortedList = new SortedList<>(descriptions, new MatrixRowComparator());
// wrap the SortedList with the TreeList
TreeList<Object> treeList = new TreeList(sortedList, new DescriptionTreeFormat(workingSet.getMaxRank()), TreeList.NODES_START_EXPANDED);
/**
import ca.odell.glazedlists.TreeList;
import eu.etaxonomy.cdm.model.name.Rank;
import eu.etaxonomy.cdm.model.taxon.Taxon;
-import eu.etaxonomy.cdm.model.taxon.TaxonNaturalComparator;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
-import eu.etaxonomy.cdm.model.taxon.TaxonNodeByNameComparator;
-import eu.etaxonomy.cdm.model.taxon.TaxonNodeByRankAndNameComparator;
-import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
/**
* @author pplitzner
*/
public class DescriptionTreeFormat implements TreeList.Format<Object> {
- private Comparator<TaxonNode> comparator;
- private Rank minRank;
private Rank maxRank;
public DescriptionTreeFormat(Rank maxRank) {
this.maxRank = maxRank;
- if (PreferencesUtil.getSortNodesNaturally()){
- comparator = new TaxonNaturalComparator();
- } else if (PreferencesUtil.getSortNodesStrictlyAlphabetically()){
- comparator = new TaxonNodeByNameComparator();
- }else {
- comparator = new TaxonNodeByRankAndNameComparator();
- }
}
@Override
public void getPath(List path, Object element) {
if(element instanceof RowWrapper){
//TODO: check for multiple taxon nodes in multiple classifications
- Taxon taxon = (Taxon) ((RowWrapper) element).getAssociatedTaxa().iterator().next();
+ Taxon taxon = ((RowWrapper) element).getAssociatedTaxon();
Set<TaxonNode> taxonNodes = taxon.getTaxonNodes();
if(taxonNodes!=null){
TaxonNode node = taxonNodes.iterator().next();
@Override
public Comparator<Object> getComparator(int depth) {
- return new Comparator<Object>() {
-
- @Override
- public int compare(Object o1, Object o2) {
- if(o1 instanceof TaxonNode && o2 instanceof TaxonNode){
- return comparator.compare((TaxonNode)o1, (TaxonNode)o2);
- }
- return o1.hashCode()-o2.hashCode();
- }
-
- };
+ return new MatrixRowComparator();
}
+
}
--- /dev/null
+/**
+* Copyright (C) 2018 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.editor.workingSet.matrix;
+
+import java.util.Comparator;
+
+import eu.etaxonomy.cdm.model.taxon.TaxonNaturalComparator;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.cdm.model.taxon.TaxonNodeByNameComparator;
+import eu.etaxonomy.cdm.model.taxon.TaxonNodeByRankAndNameComparator;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+
+/**
+ * @author pplitzner
+ * @since Jan 25, 2018
+ *
+ */
+public class MatrixRowComparator implements Comparator<Object>{
+
+ private Comparator<TaxonNode> comparator;
+
+ public MatrixRowComparator() {
+ if (PreferencesUtil.getSortNodesNaturally()){
+ comparator = new TaxonNaturalComparator();
+ } else if (PreferencesUtil.getSortNodesStrictlyAlphabetically()){
+ comparator = new TaxonNodeByNameComparator();
+ }else {
+ comparator = new TaxonNodeByRankAndNameComparator();
+ }
+ }
+
+ @Override
+ public int compare(Object o1, Object o2) {
+ if(o1 instanceof TaxonNode && o2 instanceof TaxonNode){
+ return comparator.compare((TaxonNode)o1, (TaxonNode)o2);
+ }
+ if(o1 instanceof RowWrapper && o2 instanceof RowWrapper){
+ RowWrapper rowWrapper1 = (RowWrapper)o1;
+ RowWrapper rowWrapper2 = (RowWrapper)o2;
+ TaxonNode node1 = rowWrapper1.getAssociatedTaxon().getTaxonNodes().iterator().next().getParent();
+ TaxonNode node2 = rowWrapper2.getAssociatedTaxon().getTaxonNodes().iterator().next().getParent();
+ if(node1!=null && node2!=null){
+ return comparator.compare(node1, node2);
+ }
+ }
+ return o1.hashCode()-o2.hashCode();
+ }
+
+}
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.store.CdmStore;
private SpecimenDescription description;
- private Collection<TaxonBase<?>> associatedTaxa;
+ private Taxon associatedTaxon;
private FieldUnit fieldUnit;
private String identifier;
private NamedArea country;
IOccurrenceService occurrenceService = CdmStore.getService(IOccurrenceService.class);
SpecimenOrObservationBase<?> specimen = HibernateProxyHelper.deproxy(description.getDescribedSpecimenOrObservation(), SpecimenOrObservationBase.class);
if(specimen!=null){
- associatedTaxa = occurrenceService.listAssociatedTaxa(specimen, null, null, null, null);
+ Collection<TaxonBase<?>> associatedTaxa = occurrenceService.listAssociatedTaxa(specimen, null, null, null, null);
+ if(associatedTaxa!=null){
+ associatedTaxon = (Taxon) associatedTaxa.iterator().next();
+ }
Collection<FieldUnit> fieldUnits = occurrenceService.getFieldUnits(specimen.getUuid());
if(fieldUnits.size()!=1){
MessagingUtils.error(RowWrapper.class, "More than one or no field unit found for specimen", null);
return description;
}
- public Collection<TaxonBase<?>> getAssociatedTaxa() {
- return associatedTaxa;
+ public Taxon getAssociatedTaxon() {
+ return associatedTaxon;
}
public FieldUnit getFieldUnit() {
RowWrapper rowWrapper = (RowWrapper)rowObject;
switch (columnIndex) {
case 0:
- return rowWrapper.getAssociatedTaxa();
+ return rowWrapper.getAssociatedTaxon();
case 1:
return rowWrapper.getFieldUnit();
case 2: