import java.util.Collection;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.UUID;
import org.eclipse.core.runtime.ICoreRunnable;
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
import eu.etaxonomy.cdm.api.service.IDescriptiveDataSetService;
+import eu.etaxonomy.cdm.api.service.IOccurrenceService;
import eu.etaxonomy.cdm.api.service.IPolytomousKeyService;
+import eu.etaxonomy.cdm.api.service.ITaxonService;
import eu.etaxonomy.cdm.api.service.UpdateResult;
import eu.etaxonomy.cdm.api.service.config.DescriptionAggregationConfiguration;
import eu.etaxonomy.cdm.api.service.config.IdentifiableServiceConfiguratorImpl;
import eu.etaxonomy.cdm.common.CdmUtils;
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
import eu.etaxonomy.cdm.model.description.CategoricalData;
+import eu.etaxonomy.cdm.model.description.DescriptionType;
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
import eu.etaxonomy.cdm.model.description.Feature;
+import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
import eu.etaxonomy.cdm.model.description.PolytomousKey;
import eu.etaxonomy.cdm.model.description.QuantitativeData;
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
+import eu.etaxonomy.cdm.model.description.TaxonDescription;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
import eu.etaxonomy.cdm.persistence.dto.SpecimenNodeWrapper;
import eu.etaxonomy.cdm.strategy.generate.PolytomousKeyGenerator;
import eu.etaxonomy.cdm.strategy.generate.PolytomousKeyGeneratorConfigurator;
SpecimenSelectionDialog dialog = new SpecimenSelectionDialog(matrix.getShell(), matrix);
if(dialog.open()==Window.OK){
Collection<SpecimenNodeWrapper> wrappers = dialog.getSpecimen();
+ if(wrappers.stream().anyMatch(wrapper->!wrapper.isIndividualsAssociation())
+ && !MessagingUtils.confirmDialog(
+ "Create Taxon Association",
+ "Some specimens are not linked with taxon via IndividualsAssociation yet.\n"
+ + "Do you want to create this association?")){
+ return;
+ }
for (SpecimenNodeWrapper wrapper : wrappers) {
+ if(!wrapper.isIndividualsAssociation()){
+ Optional<TaxonDescription> associationDescriptionOptional = wrapper.getTaxonNode().getTaxon().getDescriptions().stream()
+ .filter(desc->desc.getTypes().contains(DescriptionType.INDIVIDUALS_ASSOCIATION))
+ .findFirst();
+ Taxon taxon = wrapper.getTaxonNode().getTaxon();
+ TaxonDescription associationDescription;
+ if(!associationDescriptionOptional.isPresent()){
+ associationDescription = TaxonDescription.NewInstance(taxon);
+ }
+ else{
+ associationDescription = associationDescriptionOptional.get();
+ }
+
+ SpecimenOrObservationBase specimen = CdmStore.getService(IOccurrenceService.class).load(wrapper.getUuidAndTitleCache().getUuid());
+ IndividualsAssociation association = IndividualsAssociation.NewInstance(specimen);
+ associationDescription.addElement(association);
+ CdmStore.getService(ITaxonService.class).saveOrUpdate(wrapper.getTaxonNode().getTaxon());
+ }
SpecimenDescription specimenDescription = CdmStore.getService(IDescriptiveDataSetService.class)
.findSpecimenDescription(matrix.getDescriptiveDataSet().getUuid(),
wrapper.getUuidAndTitleCache().getUuid(), true);
/**
-* 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.
-*/
+ * 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.descriptiveDataSet.matrix;
import java.util.ArrayList;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
GridLayout gl_composite = new GridLayout();
+ gl_composite.numColumns = 2;
composite.setLayout(gl_composite);
Composite composite_1 = new Composite(composite, SWT.NONE);
- composite_1.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
+ composite_1.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
composite_1.setLayout(new GridLayout(4, false));
txtTextFilter = new Text(composite_1, SWT.BORDER);
@Override
public void widgetSelected(SelectionEvent e) {
loadSpecimens();
- list.setInput(matrix.getSpecimenCache());
+ refreshInput(matrix.getSpecimenCache());
}
});
+ Label lblNewLabel = new Label(composite, SWT.NONE);
+ lblNewLabel.setImage(ImageResources.getImage(ImageResources.WARNING_ICON));
+
+ Label lblNewLabel_1 = new Label(composite, SWT.NONE);
+ lblNewLabel_1.setText(": Specimen not associated with taxon");
+
ScrolledComposite scrolledComposite = new ScrolledComposite(composite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
- scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+ scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
//table
loadSpecimens();
}
- list.setInput(matrix.getSpecimenCache());
+ refreshInput(matrix.getSpecimenCache());
columnSpecimen.getColumn().pack();
- // enable tooltips
- columnSpecimen.setLabelProvider(new SpecimenListLabelProvider());
- ColumnViewerToolTipSupport.enableFor(columnSpecimen.getViewer());
-
return composite;
}
+ private void refreshInput(Object input){
+ list.setInput(input);
+ }
+
private void applyFilter(){
List<SpecimenNodeWrapper> result = new ArrayList<>();
Collection<SpecimenNodeWrapper> specimenCache = matrix.getSpecimenCache();
.collect(Collectors.toList()));
}
}
- list.setInput(result);
+ refreshInput(result);
}
private void loadSpecimens(){