Project

General

Profile

Revision 6ff2e71e

ID6ff2e71ed74be927ea56a60ad47fab30f19f8e55
Parent 09d274c7
Child 5c025bd1

Added by Patrick Plitzner almost 4 years ago

ref #7095 Cache specimens for specimen selection dialog

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/CharacterMatrix.java
185 185

  
186 186
    private EventList<RowWrapper> descriptions;
187 187

  
188
    private Collection<SpecimenOrObservationBase> specimenCache = null;
189

  
188 190
    @PostConstruct
189 191
    public void create(Composite parent) {
190 192
        if(CdmStore.isActive() && conversation==null){
......
560 562
        btnAddDescription.addSelectionListener(new SelectionAdapter() {
561 563
            @Override
562 564
            public void widgetSelected(SelectionEvent e) {
563
                SpecimenSelectionDialog dialog = new SpecimenSelectionDialog(natTable.getShell(), workingSet);
565
                SpecimenSelectionDialog dialog = new SpecimenSelectionDialog(natTable.getShell(), CharacterMatrix.this);
564 566
                if(dialog.open()==Window.OK){
565 567
                    Collection<SpecimenOrObservationBase> specimens = dialog.getSpecimen();
566 568
                    boolean hasAdded = false;
......
744 746
        return natTable;
745 747
    }
746 748

  
749
    public WorkingSet getWorkingSet() {
750
        return workingSet;
751
    }
752

  
753
    public Collection<SpecimenOrObservationBase> getSpecimenCache() {
754
        return specimenCache;
755
    }
756

  
757
    public void setSpecimenCache(Collection<SpecimenOrObservationBase> specimenCache) {
758
        this.specimenCache = specimenCache;
759
    }
760

  
747 761
    @Persist
748 762
    @Override
749 763
    public void save(IProgressMonitor monitor) {
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/SpecimenSelectionDialog.java
20 20
import org.eclipse.jface.viewers.IStructuredSelection;
21 21
import org.eclipse.jface.viewers.LabelProvider;
22 22
import org.eclipse.jface.viewers.TableViewer;
23
import org.eclipse.swt.layout.FillLayout;
23
import org.eclipse.swt.SWT;
24
import org.eclipse.swt.events.SelectionAdapter;
25
import org.eclipse.swt.events.SelectionEvent;
26
import org.eclipse.swt.layout.GridData;
27
import org.eclipse.swt.layout.GridLayout;
28
import org.eclipse.swt.widgets.Button;
24 29
import org.eclipse.swt.widgets.Composite;
25 30
import org.eclipse.swt.widgets.Control;
26 31
import org.eclipse.swt.widgets.Shell;
32
import org.eclipse.swt.widgets.Table;
27 33

  
28 34
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
29 35
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
30 36
import eu.etaxonomy.cdm.api.service.config.FindOccurrencesConfigurator;
31 37
import eu.etaxonomy.cdm.filter.TaxonNodeFilter;
32
import eu.etaxonomy.cdm.model.description.WorkingSet;
33 38
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
34 39
import eu.etaxonomy.cdm.model.taxon.Taxon;
40
import eu.etaxonomy.taxeditor.model.ImageResources;
35 41
import eu.etaxonomy.taxeditor.store.CdmStore;
36 42

  
37 43
/**
......
43 49

  
44 50
    private TableViewer list;
45 51

  
46
    private WorkingSet workingSet;
52
    private Collection<SpecimenOrObservationBase> selectedSpecimens = new ArrayList<>();
53
    private CharacterMatrix matrix;
47 54

  
48
    Collection<SpecimenOrObservationBase> selectedSpecimens = new ArrayList<>();
49

  
50
    protected SpecimenSelectionDialog(Shell parentShell, WorkingSet workingSet) {
55
    protected SpecimenSelectionDialog(Shell parentShell, CharacterMatrix matrix) {
51 56
        super(parentShell);
52
        this.workingSet = workingSet;
57
        this.matrix = matrix;
53 58
    }
54 59

  
55 60
    @Override
56 61
    protected Control createDialogArea(Composite parent) {
57 62
        Composite composite = (Composite) super.createDialogArea(parent);
58
        composite.setLayout(new FillLayout());
63
        composite.setLayout(new GridLayout());
64

  
65
        Button btnRefreshButton = new Button(composite, SWT.NONE);
66
        btnRefreshButton.setToolTipText("Refresh");
67
        btnRefreshButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
68
        btnRefreshButton.setImage(ImageResources.getImage(ImageResources.REFRESH));
69
        btnRefreshButton.addSelectionListener(new SelectionAdapter() {
70
            @Override
71
            public void widgetSelected(SelectionEvent e) {
72
                loadSpecimens();
73
                list.setInput(matrix.getSpecimenCache());
74
            }
75
        });
59 76
        list = new TableViewer(composite);
77
        Table table = list.getTable();
78
        table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
60 79
        list.setContentProvider(new DescriptionContentProvider());
61 80
        list.setLabelProvider(new LabelProvider());
62 81

  
63 82
        //gather descriptions
64
        Set<SpecimenOrObservationBase> specimens = new HashSet<>();
83
        if(matrix.getSpecimenCache()==null){
84
            loadSpecimens();
85
        }
86
        list.setInput(matrix.getSpecimenCache());
87
        return composite;
88
    }
65 89

  
90
    private void loadSpecimens(){
91
        Set<SpecimenOrObservationBase> specimens = new HashSet<>();
66 92
        //set filter parameters
67
        TaxonNodeFilter filter = TaxonNodeFilter.NewRankInstance(workingSet.getMinRank(), workingSet.getMaxRank());
68
        workingSet.getGeoFilter().forEach(area -> filter.orArea(area.getUuid()));
69
        workingSet.getTaxonSubtreeFilter().forEach(node -> filter.orSubtree(node));
93
        TaxonNodeFilter filter = TaxonNodeFilter.NewRankInstance(matrix.getWorkingSet().getMinRank(), matrix.getWorkingSet().getMaxRank());
94
        matrix.getWorkingSet().getGeoFilter().forEach(area -> filter.orArea(area.getUuid()));
95
        matrix.getWorkingSet().getTaxonSubtreeFilter().forEach(node -> filter.orSubtree(node));
70 96

  
71 97
        ITaxonNodeService taxonNodeService = CdmStore.getService(ITaxonNodeService.class);
72 98
        List<UUID> filteredNodes = taxonNodeService.uuidList(filter);
......
80 106
                specimens.addAll(CdmStore.getService(IOccurrenceService.class).findByTitle(config).getRecords());
81 107
            }
82 108
        }
83
        list.setInput(specimens);
84
        return composite;
109
        matrix.setSpecimenCache(specimens);
85 110
    }
86 111

  
87 112
    @Override
......
113 138
        public Object[] getElements(Object inputElement) {
114 139
            return ((Collection<SpecimenOrObservationBase>) inputElement).stream().filter(specimen ->
115 140
                specimen.getDescriptions().stream().noneMatch(description ->
116
                workingSet.getDescriptions().contains(description))).toArray();
141
                matrix.getWorkingSet().getDescriptions().contains(description))).toArray();
117 142
        }
118 143
    }
119 144
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/ImageResources.java
120 120
	public static final String LOCK_ICON = "lock";
121 121

  
122 122
	public static final String SYNCED = "synced";
123
	public static final String REFRESH = "refresh";
123 124

  
124 125
	/** Constant <code>LOCK_OPEN_ICON="lock_open"</code> */
125 126
	public static final String LOCK_OPEN_ICON = "lock_open";
......
347 348
		        "lock.png");
348 349
		registerImage(registry, SYNCED,
349 350
		        "synced.gif");
351
		registerImage(registry, REFRESH,
352
		        "refresh.gif");
350 353
		registerImage(registry, LOCK_OPEN_ICON,
351 354
		        "lock_open.png");
352 355
		registerImage(registry, SWITCH_VIEW_TYPE,

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)