Revision b2128023
Added by Patrick Plitzner about 6 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/CharacterMatrix.java | ||
---|---|---|
43 | 43 |
import org.eclipse.jface.window.Window; |
44 | 44 |
import org.eclipse.nebula.widgets.nattable.NatTable; |
45 | 45 |
import org.eclipse.nebula.widgets.nattable.command.StructuralRefreshCommand; |
46 |
import org.eclipse.nebula.widgets.nattable.command.VisualRefreshCommand; |
|
46 | 47 |
import org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration; |
47 | 48 |
import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes; |
48 | 49 |
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry; |
... | ... | |
387 | 388 |
btnCollapseAll.setEnabled(isTree); |
388 | 389 |
btnExpandAll.setEnabled(isTree); |
389 | 390 |
natTable.doCommand(new StructuralRefreshCommand()); |
391 |
natTable.doCommand(new VisualRefreshCommand()); |
|
390 | 392 |
} |
391 | 393 |
|
392 | 394 |
public void init(UUID workingSetUuid, boolean treeView) { |
... | ... | |
407 | 409 |
} |
408 | 410 |
// use the SortedList constructor with 'null' for the Comparator |
409 | 411 |
// because the Comparator will be set by configuration |
410 |
SortedList<Object> sortedList = new SortedList<>(descriptions, null);
|
|
412 |
SortedList<Object> sortedList = new SortedList<>(descriptions, new MatrixRowComparator());
|
|
411 | 413 |
// wrap the SortedList with the TreeList |
412 | 414 |
TreeList<Object> treeList = new TreeList(sortedList, new DescriptionTreeFormat(workingSet.getMaxRank()), TreeList.NODES_START_EXPANDED); |
413 | 415 |
/** |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/DescriptionTreeFormat.java | ||
---|---|---|
16 | 16 |
import ca.odell.glazedlists.TreeList; |
17 | 17 |
import eu.etaxonomy.cdm.model.name.Rank; |
18 | 18 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
19 |
import eu.etaxonomy.cdm.model.taxon.TaxonNaturalComparator; |
|
20 | 19 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
21 |
import eu.etaxonomy.cdm.model.taxon.TaxonNodeByNameComparator; |
|
22 |
import eu.etaxonomy.cdm.model.taxon.TaxonNodeByRankAndNameComparator; |
|
23 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
|
24 | 20 |
|
25 | 21 |
/** |
26 | 22 |
* @author pplitzner |
... | ... | |
29 | 25 |
*/ |
30 | 26 |
public class DescriptionTreeFormat implements TreeList.Format<Object> { |
31 | 27 |
|
32 |
private Comparator<TaxonNode> comparator; |
|
33 |
private Rank minRank; |
|
34 | 28 |
private Rank maxRank; |
35 | 29 |
|
36 | 30 |
public DescriptionTreeFormat(Rank maxRank) { |
37 | 31 |
this.maxRank = maxRank; |
38 |
if (PreferencesUtil.getSortNodesNaturally()){ |
|
39 |
comparator = new TaxonNaturalComparator(); |
|
40 |
} else if (PreferencesUtil.getSortNodesStrictlyAlphabetically()){ |
|
41 |
comparator = new TaxonNodeByNameComparator(); |
|
42 |
}else { |
|
43 |
comparator = new TaxonNodeByRankAndNameComparator(); |
|
44 |
} |
|
45 | 32 |
} |
46 | 33 |
|
47 | 34 |
@Override |
48 | 35 |
public void getPath(List path, Object element) { |
49 | 36 |
if(element instanceof RowWrapper){ |
50 | 37 |
//TODO: check for multiple taxon nodes in multiple classifications |
51 |
Taxon taxon = (Taxon) ((RowWrapper) element).getAssociatedTaxa().iterator().next();
|
|
38 |
Taxon taxon = ((RowWrapper) element).getAssociatedTaxon();
|
|
52 | 39 |
Set<TaxonNode> taxonNodes = taxon.getTaxonNodes(); |
53 | 40 |
if(taxonNodes!=null){ |
54 | 41 |
TaxonNode node = taxonNodes.iterator().next(); |
... | ... | |
83 | 70 |
|
84 | 71 |
@Override |
85 | 72 |
public Comparator<Object> getComparator(int depth) { |
86 |
return new Comparator<Object>() { |
|
87 |
|
|
88 |
@Override |
|
89 |
public int compare(Object o1, Object o2) { |
|
90 |
if(o1 instanceof TaxonNode && o2 instanceof TaxonNode){ |
|
91 |
return comparator.compare((TaxonNode)o1, (TaxonNode)o2); |
|
92 |
} |
|
93 |
return o1.hashCode()-o2.hashCode(); |
|
94 |
} |
|
95 |
|
|
96 |
}; |
|
73 |
return new MatrixRowComparator(); |
|
97 | 74 |
} |
75 |
|
|
98 | 76 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/MatrixRowComparator.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2018 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.workingSet.matrix; |
|
10 |
|
|
11 |
import java.util.Comparator; |
|
12 |
|
|
13 |
import eu.etaxonomy.cdm.model.taxon.TaxonNaturalComparator; |
|
14 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
|
15 |
import eu.etaxonomy.cdm.model.taxon.TaxonNodeByNameComparator; |
|
16 |
import eu.etaxonomy.cdm.model.taxon.TaxonNodeByRankAndNameComparator; |
|
17 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
|
18 |
|
|
19 |
/** |
|
20 |
* @author pplitzner |
|
21 |
* @since Jan 25, 2018 |
|
22 |
* |
|
23 |
*/ |
|
24 |
public class MatrixRowComparator implements Comparator<Object>{ |
|
25 |
|
|
26 |
private Comparator<TaxonNode> comparator; |
|
27 |
|
|
28 |
public MatrixRowComparator() { |
|
29 |
if (PreferencesUtil.getSortNodesNaturally()){ |
|
30 |
comparator = new TaxonNaturalComparator(); |
|
31 |
} else if (PreferencesUtil.getSortNodesStrictlyAlphabetically()){ |
|
32 |
comparator = new TaxonNodeByNameComparator(); |
|
33 |
}else { |
|
34 |
comparator = new TaxonNodeByRankAndNameComparator(); |
|
35 |
} |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
public int compare(Object o1, Object o2) { |
|
40 |
if(o1 instanceof TaxonNode && o2 instanceof TaxonNode){ |
|
41 |
return comparator.compare((TaxonNode)o1, (TaxonNode)o2); |
|
42 |
} |
|
43 |
if(o1 instanceof RowWrapper && o2 instanceof RowWrapper){ |
|
44 |
RowWrapper rowWrapper1 = (RowWrapper)o1; |
|
45 |
RowWrapper rowWrapper2 = (RowWrapper)o2; |
|
46 |
TaxonNode node1 = rowWrapper1.getAssociatedTaxon().getTaxonNodes().iterator().next().getParent(); |
|
47 |
TaxonNode node2 = rowWrapper2.getAssociatedTaxon().getTaxonNodes().iterator().next().getParent(); |
|
48 |
if(node1!=null && node2!=null){ |
|
49 |
return comparator.compare(node1, node2); |
|
50 |
} |
|
51 |
} |
|
52 |
return o1.hashCode()-o2.hashCode(); |
|
53 |
} |
|
54 |
|
|
55 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/RowWrapper.java | ||
---|---|---|
17 | 17 |
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit; |
18 | 18 |
import eu.etaxonomy.cdm.model.occurrence.FieldUnit; |
19 | 19 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
20 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
20 | 21 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
21 | 22 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
22 | 23 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
... | ... | |
30 | 31 |
|
31 | 32 |
private SpecimenDescription description; |
32 | 33 |
|
33 |
private Collection<TaxonBase<?>> associatedTaxa;
|
|
34 |
private Taxon associatedTaxon;
|
|
34 | 35 |
private FieldUnit fieldUnit; |
35 | 36 |
private String identifier; |
36 | 37 |
private NamedArea country; |
... | ... | |
41 | 42 |
IOccurrenceService occurrenceService = CdmStore.getService(IOccurrenceService.class); |
42 | 43 |
SpecimenOrObservationBase<?> specimen = HibernateProxyHelper.deproxy(description.getDescribedSpecimenOrObservation(), SpecimenOrObservationBase.class); |
43 | 44 |
if(specimen!=null){ |
44 |
associatedTaxa = occurrenceService.listAssociatedTaxa(specimen, null, null, null, null); |
|
45 |
Collection<TaxonBase<?>> associatedTaxa = occurrenceService.listAssociatedTaxa(specimen, null, null, null, null); |
|
46 |
if(associatedTaxa!=null){ |
|
47 |
associatedTaxon = (Taxon) associatedTaxa.iterator().next(); |
|
48 |
} |
|
45 | 49 |
Collection<FieldUnit> fieldUnits = occurrenceService.getFieldUnits(specimen.getUuid()); |
46 | 50 |
if(fieldUnits.size()!=1){ |
47 | 51 |
MessagingUtils.error(RowWrapper.class, "More than one or no field unit found for specimen", null); |
... | ... | |
62 | 66 |
return description; |
63 | 67 |
} |
64 | 68 |
|
65 |
public Collection<TaxonBase<?>> getAssociatedTaxa() {
|
|
66 |
return associatedTaxa;
|
|
69 |
public Taxon getAssociatedTaxon() {
|
|
70 |
return associatedTaxon;
|
|
67 | 71 |
} |
68 | 72 |
|
69 | 73 |
public FieldUnit getFieldUnit() { |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/SpecimenColumnPropertyAccessor.java | ||
---|---|---|
44 | 44 |
RowWrapper rowWrapper = (RowWrapper)rowObject; |
45 | 45 |
switch (columnIndex) { |
46 | 46 |
case 0: |
47 |
return rowWrapper.getAssociatedTaxa();
|
|
47 |
return rowWrapper.getAssociatedTaxon();
|
|
48 | 48 |
case 1: |
49 | 49 |
return rowWrapper.getFieldUnit(); |
50 | 50 |
case 2: |
Also available in: Unified diff
ref #7095 Extract row comparator to own class file