/**
-* 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 java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITableLabelProvider;
-import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT;
import eu.etaxonomy.taxeditor.model.ImageResources;
import eu.etaxonomy.taxeditor.preference.Resources;
import eu.etaxonomy.taxeditor.store.CdmStore;
-import eu.etaxonomy.taxeditor.ui.combo.taxon.TaxonNodeCombo;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
/**
* Dialog to choose specimens for the character matrix.<br>
private CharacterMatrix matrix;
private Text txtTextFilter;
- private TaxonNodeCombo comboTaxon;
-
protected SpecimenSelectionDialog(Shell parentShell, CharacterMatrix matrix) {
super(parentShell);
this.matrix = matrix;
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));
- Label lblNewLabel = new Label(composite_1, SWT.NONE);
- lblNewLabel.setText("Taxon");
+ Label l_textFilter = new Label(composite_1, SWT.NULL);
+ GridData data_label = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
- comboTaxon = new TaxonNodeCombo(composite_1, SWT.NONE);
- comboTaxon.setInput(matrix.getDescriptiveDataSet().getTaxonSubtreeFilter());
- comboTaxon.addSelectionChangedListener(e->applyFilter());
+ l_textFilter.setLayoutData(data_label);
+ l_textFilter.setText("Specimen Filter");
+ l_textFilter.setAlignment(SWT.RIGHT);
txtTextFilter = new Text(composite_1, SWT.BORDER);
- txtTextFilter.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ txtTextFilter.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
txtTextFilter.setText(TEXT_FILTER_DEFAULT);
txtTextFilter.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
txtTextFilter.setForeground(AbstractUtility.getColor(Resources.SEARCH_VIEW_FOCUS));
if (TEXT_FILTER_DEFAULT.equals(txtTextFilter.getText())) {
- txtTextFilter.setText("");
+ StoreUtil.setTextWithoutModifyListeners(txtTextFilter, "");
}
}
public void focusLost(FocusEvent e) {
if (CdmUtils.isBlank(txtTextFilter.getText())){
txtTextFilter.setForeground(AbstractUtility.getColor(Resources.SEARCH_VIEW_FOREGROUND));
- txtTextFilter.setText(TEXT_FILTER_DEFAULT);
+ StoreUtil.setTextWithoutModifyListeners(txtTextFilter, TEXT_FILTER_DEFAULT);
}
}
});
@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
columnTaxon.getColumn().setWidth(200);
columnTaxon.getColumn().setResizable(true);
columnTaxon.getColumn().setMoveable(true);
+ TableViewerColumn columnType = new TableViewerColumn(list, SWT.NONE);
+ columnType.getColumn().setText("Type");
+ columnType.getColumn().setWidth(150);
+ columnType.getColumn().setResizable(true);
+ columnType.getColumn().setMoveable(true);
TableViewerColumn columnSpecimen = new TableViewerColumn(list, SWT.NONE);
columnSpecimen.getColumn().setText("Specimen");
columnSpecimen.getColumn().setResizable(true);
columnSpecimen.getColumn().setMoveable(true);
columnSpecimen.getColumn().setWidth(400);
+
table.setHeaderVisible(true);
table.setLinesVisible(true);
scrolledComposite.setContent(table);
loadSpecimens();
}
- list.setInput(matrix.getSpecimenCache());
+ refreshInput(matrix.getSpecimenCache());
columnSpecimen.getColumn().pack();
return composite;
}
+ private void refreshInput(Object input){
+ list.setInput(input);
+ }
+
private void applyFilter(){
- Collection<SpecimenNodeWrapper> specimenCache = matrix.getSpecimenCache();
List<SpecimenNodeWrapper> result = new ArrayList<>();
- if(comboTaxon.getSelection()!=null){
- result.addAll(specimenCache.stream()
- .filter(wrapper->wrapper.getTaxonNode().equals(comboTaxon.getSelection()))
- .collect(Collectors.toList()));
+ Collection<SpecimenNodeWrapper> specimenCache = matrix.getSpecimenCache();
+ String text = txtTextFilter.getText();
+ if(CdmUtils.isBlank(text)){
+ result = new ArrayList<>(specimenCache);
}
- if(!txtTextFilter.getForeground().equals(AbstractUtility.getColor(Resources.SEARCH_VIEW_FOREGROUND))
- &&!CdmUtils.isBlank(txtTextFilter.getText())){
- result.addAll(specimenCache.stream()
- .filter(wrapper->wrapper.getUuidAndTitleCache().getTitleCache().toLowerCase().contains(txtTextFilter.getText().toLowerCase()))
- .collect(Collectors.toList()));
+ else{
+ if(!txtTextFilter.getForeground().equals(AbstractUtility.getColor(Resources.SEARCH_VIEW_FOREGROUND))
+ &&!CdmUtils.isBlank(text)){
+ result.addAll(specimenCache.stream()
+ .filter(wrapper->wrapper.getUuidAndTitleCache().getTitleCache().toLowerCase().contains(text.toLowerCase()))
+ .collect(Collectors.toList()));
+ result.addAll(specimenCache.stream()
+ .filter(wrapper->wrapper.getTaxonNode().getTaxon().getTitleCache().toLowerCase().contains(text.toLowerCase()))
+ .collect(Collectors.toList()));
+ }
}
- list.setInput(result);
+ refreshInput(result);
}
private void loadSpecimens(){
- Collection<SpecimenNodeWrapper> specimenCache = CdmStore.getService(IDescriptiveDataSetService.class).loadSpecimens(matrix.getDescriptiveDataSet());
- matrix.setSpecimenCache(specimenCache);
+ ArrayList<SpecimenNodeWrapper> specimenList = new ArrayList<>(CdmStore.getService(IDescriptiveDataSetService.class).loadSpecimens(matrix.getDescriptiveDataSet().getUuid()));
+ Collections.sort(specimenList, new Comparator<SpecimenNodeWrapper>() {
+
+ @Override
+ public int compare(SpecimenNodeWrapper o1, SpecimenNodeWrapper o2) {
+ if(o1 == null){
+ if(o2 == null){
+ return 0;
+ }
+ return -1;
+ }
+ if(o2==null){
+ return 1;
+ }
+ try{
+ return o1.getTaxonNode().getTaxon().getTitleCache().compareTo(o2.getTaxonNode().getTaxon().getTitleCache());
+ }
+ catch(NullPointerException e){
+ return 0;
+ }
+ }
+ });
+ matrix.setSpecimenCache(specimenList);
}
@Override
return selectedSpecimens;
}
- private class SpecimenListLabelProvider extends LabelProvider implements ITableLabelProvider{
+ private class SpecimenListLabelProvider extends ColumnLabelProvider implements ITableLabelProvider {
+
+ @Override
+ public String getToolTipText(Object element) {
+ if(element instanceof SpecimenNodeWrapper
+ && ((SpecimenNodeWrapper) element).getTaxonDescriptionUuid()==null){
+ return "Does not have and IndividualsAssociation with the taxon";
+ }
+ return null;
+ }
@Override
public Image getColumnImage(Object element, int columnIndex) {
+ if(element instanceof SpecimenNodeWrapper && columnIndex == 2
+ && ((SpecimenNodeWrapper) element).getTaxonDescriptionUuid()==null){
+ return ImageResources.getImage(ImageResources.WARNING_ICON);
+ }
return null;
}
case 0:
return wrapper.getTaxonNode().getTaxon().getName().getTitleCache();
case 1:
+ return wrapper.getType().getMessage();
+ case 2:
return wrapper.getUuidAndTitleCache().getTitleCache();
default:
break;