}
public List<TaxonNode> getAllNodes(){
- TaxonNode taxonNode = getChosenTaxonNode();
- List<TaxonNode> nodes = new ArrayList<TaxonNode>();
- if(taxonNode!=null){
+ List<TaxonNode> allNodes = new ArrayList<TaxonNode>();
+
+ List<TaxonNode> taxonNodes = getChosenTaxonNodes();
+ for (TaxonNode taxonNode : taxonNodes) {
if(taxonNode.getTaxon()!=null){
- nodes.add(taxonNode);
+ allNodes.add(taxonNode);
}
- nodes.addAll(taxonNodeService.loadChildNodesOfTaxonNode(taxonNode, null, true, null));
+ allNodes.addAll(taxonNodeService.loadChildNodesOfTaxonNode(taxonNode, null, true, null));
}
- return nodes;
+ return allNodes;
}
- public TaxonNode getChosenTaxonNode() {
+ public List<TaxonNode> getChosenTaxonNodes() {
VaadinSession session = VaadinSession.getCurrent();
- UUID taxonNodeUUID = (UUID) session.getAttribute(DistributionEditorUtil.SATTR_TAXON_NODE_UUID);
- TaxonNode classificationNode = taxonNodeService.load(taxonNodeUUID);
- return classificationNode;
- }
-
- public int getSizeOfTaxonNode(){
- TaxonNode taxonNode = getChosenTaxonNode();
- return taxonNodeService.loadChildNodesOfTaxonNode(taxonNode, null, true, null).size();
+ List<UUID> taxonNodeUUIDs = (List<UUID>) session.getAttribute(DistributionEditorUtil.SATTR_TAXON_NODES_UUID);
+ UUID classificationUuid = (UUID)session.getAttribute(DistributionEditorUtil.SATTR_CLASSIFICATION);
+ if(taxonNodeUUIDs==null && classificationUuid!=null){
+ taxonNodeUUIDs = Collections.singletonList(classificationUuid);
+ }
+ List<TaxonNode> loadedNodes = taxonNodeService.load(taxonNodeUUIDs, null);
+ if(loadedNodes!=null){
+ return loadedNodes;
+ }
+ return Collections.emptyList();
}
-
public CdmSQLContainer getSQLContainer() throws SQLException{
List<Integer> nodeIds = new ArrayList<Integer>();
for (TaxonNode taxonNode : getAllNodes()) {
package eu.etaxonomy.cdm.vaadin.presenter.dbstatus.settings;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import java.util.UUID;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.server.VaadinSession;
+import eu.etaxonomy.cdm.api.service.IClassificationService;
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
import eu.etaxonomy.cdm.api.service.ITermService;
import eu.etaxonomy.cdm.api.service.IVocabularyService;
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
import eu.etaxonomy.cdm.model.common.TermType;
import eu.etaxonomy.cdm.model.common.TermVocabulary;
+import eu.etaxonomy.cdm.model.taxon.Classification;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
private IVocabularyService vocabularyService;
private ITermService termService;
private ITaxonNodeService taxonNodeService;
- private UUID taxonNodeUuid;
+ private IClassificationService classificationService;
private UUID termUUID;
public SettingsPresenter(){
taxonNodeService = CdmSpringContextHelper.getTaxonNodeService();
- Object taxonNodeUuidString = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_TAXON_NODE_UUID);
+ classificationService = CdmSpringContextHelper.getClassificationService();
Object selectedVocabularyUuidString = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_SELECTED_VOCABULARY_UUID);
- if(taxonNodeUuidString!=null){
- taxonNodeUuid = UUID.fromString(taxonNodeUuidString.toString());
- }
if(selectedVocabularyUuidString!=null){
termUUID = UUID.fromString(selectedVocabularyUuidString.toString());
}
distributionStatusContainer = new IndexedContainer(getPresenceAbsenceVocabulary());
}
- public TaxonNode getChosenTaxonNode(){
- return taxonNodeService.load(taxonNodeUuid);
+ public List<TaxonNode> getChosenTaxonNodes(){
+ List<UUID> nodeUuids = (List<UUID>) VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_TAXON_NODES_UUID);
+ if(nodeUuids!=null){
+ return taxonNodeService.load(nodeUuids, null);
+ }
+ return Collections.emptyList();
+ }
+
+ public Classification getChosenClassification(){
+ UUID uuid = (UUID) VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_CLASSIFICATION);
+ if(uuid!=null){
+ return classificationService.load(uuid);
+ }
+ return null;
}
public TermVocabulary getChosenArea(){
package eu.etaxonomy.cdm.vaadin.util;
import java.sql.SQLException;
+import java.util.List;
import java.util.Set;
+import java.util.UUID;
import com.vaadin.server.VaadinSession;
import com.vaadin.ui.Notification;
import eu.etaxonomy.cdm.model.common.TermVocabulary;
import eu.etaxonomy.cdm.model.location.NamedArea;
-import eu.etaxonomy.cdm.model.taxon.TaxonNode;
public class DistributionEditorUtil {
public static final String SATTR_SELECTED_VOCABULARY_UUID = "selectedVocabularyUuid";
- public static final String SATTR_TAXON_NODE_UUID = "taxonNodeUUID";
+ public static final String SATTR_TAXON_NODES_UUID = "taxonNodesUUID";
+
+ public static final String SATTR_CLASSIFICATION = "classificationUUID";
public static final String SATTR_ABBREVIATED_LABELS = "abbreviatedLabels";
public static final String SEPARATOR = ";;";
- public static void openDistributionView(TaxonNode taxonNode, TermVocabulary<NamedArea> term, Set<NamedArea> selectedAreas) {
- VaadinSession.getCurrent().setAttribute(SATTR_TAXON_NODE_UUID, taxonNode.getUuid());
+ public static void openDistributionView(List<UUID> taxonNodes, TermVocabulary<NamedArea> term, Set<NamedArea> selectedAreas, UUID classificationUuid) {
+ VaadinSession.getCurrent().setAttribute(SATTR_TAXON_NODES_UUID, taxonNodes);
VaadinSession.getCurrent().setAttribute(SATTR_SELECTED_VOCABULARY_UUID, term.getUuid());
VaadinSession.getCurrent().setAttribute(SATTR_SELECTED_AREAS, selectedAreas);
+ VaadinSession.getCurrent().setAttribute(SATTR_CLASSIFICATION, classificationUuid);
//navigate to table view
UI.getCurrent().getNavigator().navigateTo(VIEW_TABLE);
package eu.etaxonomy.cdm.vaadin.view.dbstatus;
import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import com.vaadin.ui.VerticalLayout;
import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.model.common.ICdmBase;
import eu.etaxonomy.cdm.model.common.TermVocabulary;
import eu.etaxonomy.cdm.model.location.NamedArea;
+import eu.etaxonomy.cdm.model.taxon.Classification;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer;
@Override
protected void init() {
- //init classification and taxon selection
- TaxonNode chosenTaxonNode = presenter.getChosenTaxonNode();
-
+ //init classification
+ Classification classification = presenter.getChosenClassification();
try {
classificationBox.setContainerDataSource(new CdmSQLContainer(CdmQueryFactory.generateTableQuery("Classification")));
} catch (SQLException e) {
DistributionEditorUtil.showSqlError(e);
}
- Object classificationSelection = null;
- if(classificationBox.getItemIds().size()==1){
+ RowId parent = null;
+ if(classification!=null){
+ parent = new RowId(classification.getRootNode().getId());
+ }
+ else if(classificationBox.getItemIds().size()==1){
//only one classification exists
- classificationSelection = classificationBox.getItemIds().iterator().next();
+ parent = (RowId) classificationBox.getItemIds().iterator().next();
}
- else if(chosenTaxonNode!=null){
- //get the classification from the selected taxon node
- classificationSelection = chosenTaxonNode.getClassification().getRootNode();
- }
- if(classificationSelection!=null){
- classificationBox.setValue(classificationSelection);
- taxonTree.addExpandListener(this);
-
- UuidAndTitleCache<TaxonNode> parent = getUuidAndTitleCacheFromRowId(classificationSelection);
- showClassificationTaxa(parent);
- if(chosenTaxonNode!=null){
- taxonTree.select(new RowId(chosenTaxonNode.getId()));
- }
+ if(parent!=null){
+ classificationBox.setValue(new RowId(parent.getId()));
+ showClassificationTaxa(getUuidAndTitleCacheFromRowId(parent));
}
+ //init taxon selection
+ List<TaxonNode> chosenTaxonNodes = presenter.getChosenTaxonNodes();
+ if(chosenTaxonNodes!=null){
+ for (TaxonNode taxonNode : chosenTaxonNodes) {
+ UuidAndTitleCache<ICdmBase> uuidAndTitleCache = new UuidAndTitleCache<>(taxonNode.getUuid(), taxonNode.getId(), null);
+ taxonTree.select(uuidAndTitleCache);
+ Object parentNode = taxonTree.getParent(uuidAndTitleCache);
+ while(parentNode!=null){
+ taxonTree.setCollapsed(parentNode, false);
+ parentNode = taxonTree.getParent(parentNode);
+ }
+ }
+ }
+
classificationBox.addValueChangeListener(this);
taxonFilter.addValueChangeListener(this);
+ taxonTree.addExpandListener(this);
TermVocabulary<NamedArea> chosenArea = presenter.getChosenArea();
distAreaBox.setContainerDataSource(presenter.getDistributionContainer());
taxonTree.setImmediate(true);
taxonTree.setCacheRate(20);
taxonTree.setColumnHeaderMode(ColumnHeaderMode.HIDDEN);
+ taxonTree.setMultiSelect(true);
leftContainer.addComponent(distAreaBox);
leftContainer.addComponent(namedAreaList);
public void valueChange(ValueChangeEvent event) {
Property property = event.getProperty();
if(property==classificationBox){
- TaxonNode parentNode = (TaxonNode) event.getProperty().getValue();
- UUID uuid = parentNode.getUuid();
- int id = parentNode.getId();
- String titleCache = parentNode.getClassification().getTitleCache();
- UuidAndTitleCache<TaxonNode> parent = new UuidAndTitleCache<>(uuid, id, titleCache);
+ UuidAndTitleCache<TaxonNode> parent = getUuidAndTitleCacheFromRowId(classificationBox.getValue());
showClassificationTaxa(parent);
}
else if(property==taxonFilter){
public void buttonClick(ClickEvent event) {
Object source = event.getSource();
if(source==okButton){
- TaxonNode taxonNode = null;
+ List<UUID> taxonNodes = new ArrayList<>();
TermVocabulary<NamedArea> term = null;
- //TODO use field converter
- if(taxonTree.getValue()!=null){
- taxonNode = CdmSpringContextHelper.getTaxonNodeService().load(((UuidAndTitleCache<TaxonNode>)taxonTree.getValue()).getUuid());
- }
- if(taxonNode==null){
- String uuidString = (String) classificationBox.getContainerProperty(classificationBox.getValue(),"uuid").getValue();
- UUID uuid = UUID.fromString(uuidString);
- taxonNode = CdmSpringContextHelper.getClassificationService().load(uuid).getRootNode();
+ String uuidString = (String) classificationBox.getContainerProperty(classificationBox.getValue(),"uuid").getValue();
+ UUID classificationUuid = UUID.fromString(uuidString);
+ Set<UuidAndTitleCache<TaxonNode>> treeSelection = (Set<UuidAndTitleCache<TaxonNode>>) taxonTree.getValue();
+ if(!treeSelection.isEmpty()){
+ for (UuidAndTitleCache<TaxonNode> uuidAndTitleCache : treeSelection) {
+ taxonNodes.add(uuidAndTitleCache.getUuid());
+ }
}
term = (TermVocabulary<NamedArea>) distAreaBox.getValue();
Set<NamedArea> selectedAreas = (Set<NamedArea>) namedAreaList.getValue();
- DistributionEditorUtil.openDistributionView(taxonNode, term, selectedAreas);
+ DistributionEditorUtil.openDistributionView(taxonNodes, term, selectedAreas, classificationUuid);
window.close();
}
else if(source==cancelButton){