Project

General

Profile

« Previous | Next » 

Revision 456b89bd

Added by Patrick Plitzner over 4 years ago

ref #7095 Add descriptions via button to matrix

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/CharacterMatrix.java
35 35
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
36 36
import org.eclipse.jface.layout.GridDataFactory;
37 37
import org.eclipse.jface.viewers.StructuredSelection;
38
import org.eclipse.jface.window.Window;
38 39
import org.eclipse.nebula.widgets.nattable.NatTable;
39 40
import org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration;
40 41
import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;
......
155 156

  
156 157
    private Properties natTableState;
157 158

  
159
    private EventList<RowWrapper> descriptions;
160

  
158 161
    @PostConstruct
159 162
    public void create(Composite parent) {
160 163
        if(CdmStore.isActive() && conversation==null){
......
182 185
        Collections.sort(features);
183 186

  
184 187

  
185
        EventList<RowWrapper> descriptions = GlazedLists.eventList(getDescriptions(workingSet));
188
        descriptions = GlazedLists.eventList(getDescriptions(workingSet));
186 189
        SortedList<RowWrapper> sortedList = new SortedList<>(descriptions, null);
187 190

  
188 191
        /**
......
433 436
            }
434 437
        });
435 438

  
439
        /**
440
         * Add description button
441
         */
442
        Button btnAddDescription = new Button(parent, SWT.PUSH);
443
        btnAddDescription.setImage(ImageResources.getImage(ImageResources.ADD_ICON));
444
        btnAddDescription.addSelectionListener(new SelectionAdapter() {
445
            @Override
446
            public void widgetSelected(SelectionEvent e) {
447
                DescriptionSelectionDialog dialog = new DescriptionSelectionDialog(natTable.getShell(), workingSet);
448
                if(dialog.open()==Window.OK){
449
                    Collection<DescriptionBase> selectedDescriptions = dialog.getDescriptions();
450
                    boolean hasAdded = false;
451
                    for (DescriptionBase description : selectedDescriptions) {
452
                        if(!workingSet.getDescriptions().contains(description)){
453
                            CharacterMatrix.this.descriptions.add(new RowWrapper((SpecimenDescription) description));
454
                            workingSet.addDescription(description);
455
                            hasAdded = true;
456
                        }
457
                    }
458
                    if(hasAdded){
459
                        setDirty();
460
                    }
461
                }
462
            }
463
        });
464

  
436 465
        parent.layout();
437 466
    }
438 467

  
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/DescriptionSelectionDialog.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.ArrayList;
12
import java.util.Collection;
13
import java.util.Set;
14

  
15
import org.eclipse.jface.dialogs.Dialog;
16
import org.eclipse.jface.viewers.ArrayContentProvider;
17
import org.eclipse.jface.viewers.IStructuredSelection;
18
import org.eclipse.jface.viewers.LabelProvider;
19
import org.eclipse.jface.viewers.TableViewer;
20
import org.eclipse.swt.graphics.Image;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Control;
23
import org.eclipse.swt.widgets.Shell;
24

  
25
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
26
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
27
import eu.etaxonomy.cdm.model.description.DescriptionBase;
28
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
29
import eu.etaxonomy.cdm.model.description.WorkingSet;
30
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
31
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
32
import eu.etaxonomy.cdm.model.taxon.Taxon;
33
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
34
import eu.etaxonomy.taxeditor.model.ImageResources;
35
import eu.etaxonomy.taxeditor.store.CdmStore;
36

  
37
/**
38
 * @author pplitzner
39
 * @since Jan 3, 2018
40
 *
41
 */
42
public class DescriptionSelectionDialog extends Dialog {
43

  
44
    private TableViewer list;
45

  
46
    private WorkingSet workingSet;
47

  
48
    Collection<DescriptionBase> selectedDescriptions = new ArrayList<>();
49

  
50
    protected DescriptionSelectionDialog(Shell parentShell, WorkingSet workingSet) {
51
        super(parentShell);
52
        this.workingSet = workingSet;
53
    }
54

  
55
    @Override
56
    protected Control createDialogArea(Composite parent) {
57
        Composite composite = (Composite) super.createDialogArea(parent);
58
        list = new TableViewer(composite);
59
        list.setContentProvider(new ArrayContentProvider());
60
        list.setLabelProvider(new DescriptionLabelProvider());
61

  
62
        //gather descriptions
63
        Collection<DescriptionBase> descriptions = new ArrayList<>();
64
        Set<TaxonNode> taxonNodes = workingSet.getTaxonSubtreeFilter();
65
        for (ITaxonTreeNode taxonTreeNode : taxonNodes) {
66
            if(taxonTreeNode instanceof TaxonNode){
67
                TaxonNode taxonNode = (TaxonNode)taxonTreeNode;
68
                workingSet.addTaxonSubtree(taxonNode);
69
                if(taxonNode.getTaxon()!=null){
70
                    Taxon taxon = HibernateProxyHelper.deproxy(taxonNode.getTaxon(), Taxon.class);
71
                    Collection<SpecimenOrObservationBase> specimens = CdmStore.getService(IOccurrenceService.class).listByAssociatedTaxon(SpecimenOrObservationBase.class, null, taxon, null, null, null, null, null);
72
                    for (SpecimenOrObservationBase specimen : specimens) {
73
                        Set<SpecimenDescription> specimenDescriptions = specimen.getSpecimenDescriptions();
74
                        for (SpecimenDescription specimenDescription : specimenDescriptions) {
75
                            descriptions.add(specimenDescription);
76
                        }
77
                    }
78
                }
79
            }
80
        }
81
        list.setInput(descriptions);
82

  
83
        return composite;
84
    }
85

  
86
    /**
87
     * {@inheritDoc}
88
     */
89
    @Override
90
    protected void okPressed() {
91
        selectedDescriptions = ((IStructuredSelection)list.getSelection()).toList();
92
        super.okPressed();
93
    }
94
    public Collection<DescriptionBase> getDescriptions(){
95
        return selectedDescriptions;
96
    }
97

  
98
    private class DescriptionLabelProvider extends LabelProvider{
99
        /**
100
         * {@inheritDoc}
101
         */
102
        @Override
103
        public Image getImage(Object element) {
104
            if(workingSet.getDescriptions().contains(element)){
105
                return ImageResources.getImage(ImageResources.SYNCED);
106
            }
107
            return null;
108
        }
109
    }
110
}

Also available in: Unified diff