Project

General

Profile

« Previous | Next » 

Revision 278a5e0a

Added by Katja Luther over 5 years ago

ref #7854 Implement NatTable for distribution editor

View differences:

eu.etaxonomy.taxeditor.editor/fragment.e4xmi
310 310
        <children xsi:type="menu:HandledToolItem" xmi:id="_hnZYUPycEeeOqKfc2I-67A" elementId="eu.etaxonomy.taxeditor.editor.handledtoolitem.0" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.store/icons/refresh.gif" tooltip="%handledtoolitem.tooltip.1" command="_4k-uYPycEeeOqKfc2I-67A"/>
311 311
      </toolbar>
312 312
    </elements>
313
    <elements xsi:type="basic:PartDescriptor" xmi:id="_KnkUEPemEeiZEKOlcMbiPw" elementId="eu.etaxonomy.taxeditor.editor.view.checklist.e4.DistributionEditorPart" label="Distribution Editor" allowMultiple="true" closeable="true" dirtyable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.checklist.e4.DistributionEditorPart"/>
313 314
  </fragments>
314 315
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="__mwtMDVpEee_b7RlBzTDRw" featurename="commands" parentElementId="xpath:/">
315 316
    <elements xsi:type="commands:Command" xmi:id="_BjF3ADVqEee_b7RlBzTDRw" elementId="eu.etaxonomy.taxeditor.editor.command.specimeneditor.create_field_unit" commandName="%command.commandname.1"/>
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/AppModelId.java
278 278
	public static final String PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_KEY_POLYTOMOUS_E4_POLYTOMOUSKEYLISTEDITORE4 = "eu.etaxonomy.taxeditor.editor.key.polytomous.e4.PolytomousKeyListEditorE4";
279 279
	public static final String PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_NAME_E4_TAXONNAMEEDITORE4 = "eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4";
280 280
	public static final String PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_CHECKLIST_E4_CHECKLISTEDITORE4 = "eu.etaxonomy.taxeditor.editor.view.checklist.e4.ChecklistEditorE4";
281
	public static final String PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_CHECKLIST_E4_DISTRIBUTIONEDITORPART = "eu.etaxonomy.taxeditor.editor.view.checklist.e4.DistributionEditorPart";
281 282
	public static final String PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_CONCEPT_E4_CONCEPTVIEWPARTE4 = "eu.etaxonomy.taxeditor.editor.view.concept.e4.ConceptViewPartE4";
282 283
	public static final String PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_CONCEPT_GRAPH_E4_CONCEPTGRAPHVIEWE4 = "eu.etaxonomy.taxeditor.editor.view.concept.graph.e4.ConceptGraphViewE4";
283 284
	public static final String PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DERIVATE_DERIVATEVIEW = "eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView";
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java
45 45
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
46 46
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
47 47
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
48
import eu.etaxonomy.taxeditor.editor.view.checklist.e4.DistributionEditorPart;
48 49
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
49 50
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewEditorInput;
50 51
import eu.etaxonomy.taxeditor.model.AbstractUtility;
......
84 85
        editor.init(descriptiveDataSetUuid, true);
85 86
    }
86 87

  
88
    public static void openDistributionEditor(UUID parentTaxonUuid, EModelService modelService, EPartService partService, MApplication application){
89
        Collection<MPart> parts = partService.getParts();
90
        String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_CHECKLIST_E4_DISTRIBUTIONEDITORPART;
91
        MPart part = showPart(partId, modelService, partService, application);
92
        DistributionEditorPart editor = (DistributionEditorPart) part.getObject();
93
        editor.init(parentTaxonUuid);
94
    }
95

  
96

  
87 97
    public static void openSpecimenEditor(DerivateViewEditorInput input, EModelService modelService, EPartService partService, MApplication application){
88 98
        String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DERIVATE_DERIVATEVIEW;
89 99
        MPart part = showPart(partId, modelService, partService, application);
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/character/CharacterEditor.java
142 142
        composite.setLayout(gl_composite);
143 143

  
144 144
        structuresTreeEditorComposite = addFeatureTreeEditor(composite);
145

  
145 146
        initFeatureTreeComposite(structuresTreeEditorComposite,
146 147
                new FeatureNodeDragListener(structuresTreeEditorComposite.getViewer()), null, null, null, null);
148

  
147 149
        structuresTreeEditorComposite.getLabel_title().setText(Messages.CharacterEditor_STRUCTURES);
148 150

  
149 151
        Composite composite_1 = new Composite(sashForm, SWT.NONE);
......
155 157

  
156 158
        propertiesTreeEditorComposite = addFeatureTreeEditor(composite_1);
157 159
        initFeatureTreeComposite(propertiesTreeEditorComposite,
160

  
158 161
                new CharacterDragListener(structuresTreeEditorComposite.getViewer(), propertiesTreeEditorComposite.getViewer()),
159 162
                null,
160 163
                new Transfer[] {CharacterTransfer.getInstance()},
161 164
                null,
162 165
                null
166

  
163 167
        );
164 168
        propertiesTreeEditorComposite.getLabel_title().setText(Messages.CharacterEditor_PROPERTIES);
165 169

  
......
177 181
        characterTreeEditorComposite = addFeatureTreeEditor(composite_3);
178 182
        initFeatureTreeComposite(characterTreeEditorComposite, new FeatureNodeDragListener(characterTreeEditorComposite.getViewer()),
179 183
                new CharacterDropAdapter(this, characterTreeEditorComposite.getViewer(), sync),
184

  
180 185
                new Transfer[] {FeatureNodeTransfer.getInstance(), CharacterTransfer.getInstance()},
181 186
                this,
182 187
                this);
188

  
183 189
        characterTreeEditorComposite.getLabel_title().setText(Messages.CharacterEditor_CHARACTERS);
184 190

  
185 191
        //add context menu to character viewer//create context menu
......
202 208
            Transfer[] transfers,
203 209
            ISelectionChangedListener viewerSelectionChangedListener,
204 210
            ModifyListener modifyListener) {
211

  
205 212
        featureTreeEditorComposite.init(
206 213
                featureNodeDragListener,
207 214
                featureNodeDropAdapter,
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java
178 178

  
179 179
    private DefaultBodyLayerStack bodyLayer;
180 180

  
181
    private boolean isTreeView = true;
181
    private boolean isTreeView = false;
182 182

  
183 183
    private CharacterMatrixToolbar toolbar;
184 184

  
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/BodyLayerStack.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.view.checklist.e4;
10

  
11
import java.util.Comparator;
12
import java.util.List;
13

  
14
import org.eclipse.nebula.widgets.nattable.data.IColumnPropertyAccessor;
15
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
16
import org.eclipse.nebula.widgets.nattable.layer.AbstractLayerTransform;
17
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
18
import org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator;
19
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
20
import org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer;
21

  
22
import ca.odell.glazedlists.EventList;
23
import ca.odell.glazedlists.FilterList;
24
import ca.odell.glazedlists.GlazedLists;
25
import ca.odell.glazedlists.SortedList;
26
import ca.odell.glazedlists.TransformedList;
27

  
28
/**
29
 * @author k.luther
30
 * @since 13.12.2018
31
 *
32
 */
33
public class BodyLayerStack<T> extends AbstractLayerTransform {
34
    private final FilterList<T> filterList;
35

  
36
    private final ListDataProvider<T> bodyDataProvider;
37

  
38
    private final SelectionLayer selectionLayer;
39
    private final ViewportLayer viewportLayer ;
40

  
41
    public BodyLayerStack(List<T> values, IColumnPropertyAccessor<T> columnPropertyAccessor, Comparator<T> comparator, IConfigLabelAccumulator labelAccumulator) {
42
        // wrapping of the list to show into GlazedLists
43
        // see http://publicobject.com/glazedlists/ for further information
44
        EventList<T> eventList = GlazedLists.eventList(values);
45
        TransformedList<T, T> rowObjectsGlazedList = GlazedLists.threadSafeList(eventList);
46
        SortedList<T> sortedList = new SortedList<>(rowObjectsGlazedList, comparator);
47
        // wrap the SortedList with the FilterList
48
        this.filterList = new FilterList<>(sortedList);
49

  
50
        this.bodyDataProvider =
51
                new ListDataProvider<>(this.filterList, columnPropertyAccessor);
52

  
53
        DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
54
        bodyDataLayer.setConfigLabelAccumulator(labelAccumulator);
55

  
56
//        // layer for event handling of GlazedLists and PropertyChanges
57
//        GlazedListsEventLayer<T> glazedListsEventLayer =
58
//                new GlazedListsEventLayer<>(bodyDataLayer, this.filterList);
59

  
60
        this.selectionLayer = new SelectionLayer(bodyDataLayer);
61
        viewportLayer = new ViewportLayer(getSelectionLayer());
62

  
63
        setUnderlyingLayer(viewportLayer);
64
    }
65

  
66
    public SelectionLayer getSelectionLayer() {
67
        return this.selectionLayer;
68
    }
69

  
70
    public ViewportLayer getViewPortLayer() {
71
        return this.viewportLayer;
72
    }
73

  
74
    public FilterList<T> getFilterList() {
75
        return this.filterList;
76
    }
77

  
78
    public ListDataProvider<T> getBodyDataProvider() {
79
        return this.bodyDataProvider;
80
}
81
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/ChecklistEditorE4.java
12 12

  
13 13
import java.util.ArrayList;
14 14
import java.util.Arrays;
15
import java.util.Collection;
16 15
import java.util.Collections;
17 16
import java.util.HashMap;
18 17
import java.util.List;
......
638 637
      //create new Items for Dropdown menue
639 638
        Table table = viewer.getTable();
640 639
        table.setRedraw(false);
641
        Collection<DefinedTermBase> oldTerms = labelProvider.getNamedAreas(false);
642

  
643 640
        SortedSet<DefinedTermBase> newTerms = labelProvider.getNamedAreas(true);
644 641

  
645 642

  
......
679 676
              }
680 677
          }
681 678
          TableViewerColumn column= addTableViewerColumn(termLable, 200, areaPosition.get(term.getUuid()), term);
682
          System.err.println(column.getColumn().getText() + " index: " +areaPosition.get(term.getUuid()) );
679

  
683 680

  
684 681
      }
685 682

  
......
813 810
     *
814 811
     * @see org.eclipse.ui.forms.editor.FormEditor#isDirty()
815 812
     */
813
    @Override
816 814
    public boolean isDirty() {
817 815
        return dirty.isDirty();
818 816
    }
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionCellEditorDataConversionConfiguration.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.view.checklist.e4;
10

  
11
import org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration;
12
import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;
13
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
14
import org.eclipse.nebula.widgets.nattable.config.IEditableRule;
15
import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes;
16
import org.eclipse.nebula.widgets.nattable.filterrow.FilterRowTextCellEditor;
17
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
18

  
19
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.supplementalInfo.SupplementalInfoDisplayConverter;
20

  
21
/**
22
 * @author k.luther
23
 * @since 05.12.2018
24
 *
25
 */
26
public class DistributionCellEditorDataConversionConfiguration extends AbstractRegistryConfiguration {
27
    private DistributionEditor editor;
28

  
29
    public DistributionCellEditorDataConversionConfiguration(DistributionEditor editor) {
30
        super();
31
        this.editor = editor;
32
    }
33

  
34
    @Override
35
    public void configureRegistry(IConfigRegistry configRegistry) {
36

  
37
        //add display converter for string representation
38
        configRegistry.registerConfigAttribute(
39
                CellConfigAttributes.DISPLAY_CONVERTER,
40
                new SupplementalInfoDisplayConverter(),
41
                DisplayMode.NORMAL,
42
                DistributionEditor.TAXON_COLUMN);
43

  
44
        configRegistry.registerConfigAttribute(
45
                CellConfigAttributes.DISPLAY_CONVERTER,
46
                new SupplementalInfoDisplayConverter(),
47
                DisplayMode.NORMAL,
48
                DistributionEditor.RANK_COLUMN);
49

  
50
        configRegistry.registerConfigAttribute(
51
                CellConfigAttributes.DISPLAY_CONVERTER,
52
                new StatusDataDisplayConverter(),
53
                DisplayMode.NORMAL,
54
                DistributionEditorConfigLabelAccumulator.STATUS
55
                );
56

  
57
        //---register cell editors---
58

  
59

  
60
        //make cell editable
61
        configRegistry.registerConfigAttribute(
62
                EditConfigAttributes.CELL_EDITABLE_RULE,
63
                IEditableRule.ALWAYS_EDITABLE,
64
                DisplayMode.EDIT,
65
                DistributionEditorConfigLabelAccumulator.STATUS_EDITABLE
66
                );
67
        //add display converter for string representation
68
        configRegistry.registerConfigAttribute(
69
                CellConfigAttributes.DISPLAY_CONVERTER,
70
                new StatusDisplayConverter(),
71
                DisplayMode.NORMAL,
72
                DistributionEditorConfigLabelAccumulator.STATUS
73
                );
74
        //register status editor
75

  
76
        StatusDataCellEditor cellEditor = new StatusDataCellEditor(editor, new StatusComboBoxDataProvider(editor));
77
        configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR,
78
                cellEditor,
79
                DisplayMode.EDIT,
80
                DistributionEditorConfigLabelAccumulator.STATUS_EDITABLE
81
                );
82

  
83
        FilterRowTextCellEditor filterCellEditor = new FilterRowTextCellEditor();
84
        configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR,
85
                filterCellEditor,
86
                DisplayMode.EDIT,
87
                DistributionEditorConfigLabelAccumulator.FILTER_EDITABLE
88
                );
89

  
90

  
91

  
92

  
93

  
94

  
95

  
96
    }
97

  
98
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionCellSelectionListener.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.view.checklist.e4;
10

  
11
import java.util.Collection;
12

  
13
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
14
import org.eclipse.jface.viewers.StructuredSelection;
15
import org.eclipse.nebula.widgets.nattable.data.IRowDataProvider;
16
import org.eclipse.nebula.widgets.nattable.extension.e4.selection.E4SelectionListener;
17
import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
18
import org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent;
19
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
20
import org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent;
21
import org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent;
22

  
23
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
24
import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO;
25

  
26
/**
27
 * @author k.luther
28
 * @since 28.11.2018
29
 *
30
 */
31
public class DistributionCellSelectionListener extends E4SelectionListener<TaxonDistributionDTO>{
32
    private DistributionEditorPart part;
33

  
34
    public DistributionCellSelectionListener(
35
            ESelectionService service,
36
            SelectionLayer selectionLayer,
37
            IRowDataProvider<TaxonDistributionDTO> rowDataProvider,
38
            DistributionEditorPart part) {
39
        super(service, selectionLayer, rowDataProvider);
40
        this.part = part;
41
    }
42

  
43
    @Override
44
    public void handleLayerEvent(ILayerEvent event) {
45
        if(event instanceof CellSelectionEvent){
46
            CellSelectionEvent cellSelectionEvent = (CellSelectionEvent)event;
47
            int columnPosition = cellSelectionEvent.getColumnPosition();
48
            if(columnPosition>=part.getEditor().getFirstDataColumnIndex()){
49
                Collection<ILayerCell> selectedCells = cellSelectionEvent.getSelectionLayer().getSelectedCells();
50
                if(selectedCells.size()==1){
51
                    ILayerCell cell = selectedCells.iterator().next();
52
                    Object dataValue = cell.getDataValue();
53
                    if(dataValue!=null){
54
                        part.getSelectionService().setSelection(new StructuredSelection(dataValue));
55
                        return;
56
                    }
57
                }
58
            }
59
        }
60
        else if(event instanceof RowSelectionEvent){
61
            RowSelectionEvent rowSelectionEvent = (RowSelectionEvent) event;
62
            int[] fullySelectedRowPositions = rowSelectionEvent.getSelectionLayer().getFullySelectedRowPositions();
63
            if(fullySelectedRowPositions.length==1){
64
                Object rowObject = part.getEditor().getBodyDataProvider().getRowObject(fullySelectedRowPositions[0]);
65
                if(rowObject instanceof RowWrapperDTO){
66
                    part.getSelectionService().setSelection(new StructuredSelection(((RowWrapperDTO) rowObject).getDescription()));
67
                    return;
68
                }
69
            }
70
        }
71
        part.getSelectionService().setSelection(new StructuredSelection());
72
    }
73
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionColumnAccessor.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.view.checklist.e4;
10

  
11
import java.util.HashSet;
12
import java.util.Set;
13

  
14
import org.eclipse.nebula.widgets.nattable.data.IColumnPropertyAccessor;
15

  
16
import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO;
17
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
18
import eu.etaxonomy.cdm.model.description.Distribution;
19
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
20
import eu.etaxonomy.cdm.model.description.TaxonDescription;
21
import eu.etaxonomy.cdm.model.location.NamedArea;
22

  
23

  
24
/**
25
 * @author k.luther
26
 * @since 28.11.2018
27
 *
28
 */
29
public class DistributionColumnAccessor implements IColumnPropertyAccessor<TaxonDistributionDTO> {
30
    private DistributionEditor editor;
31
    public static final String DEFAULT_ENTRY = "";
32

  
33
    public DistributionColumnAccessor(DistributionEditor editor) {
34
        this.editor = editor;
35
    }
36

  
37

  
38
    /**
39
     * {@inheritDoc}
40
     */
41
    @Override
42
    public Object getDataValue(TaxonDistributionDTO rowObject, int columnIndex) {
43
     switch (columnIndex) {
44
            case 0:
45
                return rowObject.getNameCache();
46
            case 1:
47
                if (editor.isShowRank()){
48
                    return rowObject.getRankString();
49
                }else{
50
                    break;
51
                }
52
            default:
53
                break;
54
            }
55
        NamedArea area = editor.getAreaToColumnIndexMap().get(columnIndex);
56

  
57
        //TODO: do not get the distribution objcts, but the label of the status.
58
        Set<DescriptionElementBase> distributionsForArea = rowObject.getDistributionMap().get(area);
59
        if (distributionsForArea == null){
60
            return null;
61
        }
62
        if (distributionsForArea.size() == 1){
63
            return distributionsForArea.iterator().next();
64
        }
65
        if (distributionsForArea.size() > 1){
66
            return distributionsForArea;
67
        }
68
        return null;
69

  
70
    }
71

  
72

  
73
    /**
74
     * {@inheritDoc}
75
     */
76
    @Override
77
    public int getColumnCount() {
78
        return editor.getPropertyToLabelMap().size();
79
    }
80

  
81
    /**
82
     * {@inheritDoc}
83
     */
84
    @Override
85
    public String getColumnProperty(int columnIndex) {
86
        return editor.getPropertyToLabelMap().get(columnIndex);
87
    }
88

  
89
    /**
90
     * {@inheritDoc}
91
     */
92
    @Override
93
    public int getColumnIndex(String propertyName){
94
        return editor.getPropertyToLabelMap().indexOf(propertyName);
95
    }
96

  
97

  
98
    /**
99
     * {@inheritDoc}
100
     */
101
    @Override
102
    public void setDataValue(TaxonDistributionDTO taxonWrapper, int columnIndex, Object newValue) {
103
            if (newValue instanceof PresenceAbsenceTerm){
104
                NamedArea area =editor.getAreaToColumnIndexMap().get(columnIndex);
105
                Set<DescriptionElementBase> distributions = taxonWrapper.getDistributionMap().get(area);
106
                if (distributions != null && !distributions.isEmpty()){
107
                    DescriptionElementBase desc = distributions.iterator().next();
108
                    if (desc instanceof Distribution){
109
                        if (((PresenceAbsenceTerm)newValue).getId() == 0){
110
                            desc.getInDescription().removeElement(desc);
111
                            distributions.remove(desc);
112
                        }else {
113
                            ((Distribution)desc).setStatus((PresenceAbsenceTerm)newValue);
114
                        }
115
                    }
116
                }else{
117
                    if (distributions == null){
118
                        distributions = new HashSet();
119
                    }
120
                    Distribution dist = Distribution.NewInstance(area, (PresenceAbsenceTerm)newValue);
121
                    Set<TaxonDescription> descs = taxonWrapper.getDescriptionsWrapper().getDescriptions();
122
                    TaxonDescription desc;
123
                    if (descs.size() >= 1){
124
                        desc = descs.iterator().next();
125
                    }else {
126
                        desc = TaxonDescription.NewInstance();
127
                    }
128
                    desc.addElement(dist);
129
                    distributions.add(dist);
130
                }
131

  
132
            }
133

  
134
    }
135

  
136
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionEditor.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.view.checklist.e4;
10

  
11
import java.util.ArrayList;
12
import java.util.Arrays;
13
import java.util.HashMap;
14
import java.util.HashSet;
15
import java.util.List;
16
import java.util.Map;
17
import java.util.Set;
18
import java.util.SortedSet;
19
import java.util.TreeSet;
20
import java.util.UUID;
21

  
22
import javax.inject.Inject;
23

  
24
import org.apache.commons.collections4.map.LinkedMap;
25
import org.apache.log4j.Logger;
26
import org.eclipse.e4.ui.services.EMenuService;
27
import org.eclipse.jface.layout.GridDataFactory;
28
import org.eclipse.jface.layout.GridLayoutFactory;
29
import org.eclipse.jface.wizard.WizardDialog;
30
import org.eclipse.nebula.widgets.nattable.NatTable;
31
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
32
import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration;
33
import org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate;
34
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
35
import org.eclipse.nebula.widgets.nattable.data.IRowDataProvider;
36
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
37
import org.eclipse.nebula.widgets.nattable.extension.e4.selection.E4SelectionListener;
38
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.filterrow.DefaultGlazedListsFilterStrategy;
39
import org.eclipse.nebula.widgets.nattable.filterrow.FilterRowHeaderComposite;
40
import org.eclipse.nebula.widgets.nattable.freeze.CompositeFreezeLayer;
41
import org.eclipse.nebula.widgets.nattable.freeze.FreezeHelper;
42
import org.eclipse.nebula.widgets.nattable.freeze.FreezeLayer;
43
import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
44
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider;
45
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider;
46
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider;
47
import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer;
48
import org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer;
49
import org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer;
50
import org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer;
51
import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer;
52
import org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer;
53
import org.eclipse.nebula.widgets.nattable.layer.AbstractLayer;
54
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
55
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
56
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
57
import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration;
58
import org.eclipse.nebula.widgets.nattable.style.HorizontalAlignmentEnum;
59
import org.eclipse.nebula.widgets.nattable.style.theme.ModernNatTableThemeConfiguration;
60
import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
61
import org.eclipse.swt.SWT;
62
import org.eclipse.swt.events.SelectionAdapter;
63
import org.eclipse.swt.events.SelectionEvent;
64
import org.eclipse.swt.layout.GridData;
65
import org.eclipse.swt.layout.GridLayout;
66
import org.eclipse.swt.widgets.Button;
67
import org.eclipse.swt.widgets.Composite;
68
import org.eclipse.swt.widgets.Label;
69
import org.eclipse.swt.widgets.Text;
70

  
71
import ca.odell.glazedlists.BasicEventList;
72
import ca.odell.glazedlists.EventList;
73
import eu.etaxonomy.cdm.api.service.IVocabularyService;
74
import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO;
75
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
76
import eu.etaxonomy.cdm.model.common.Language;
77
import eu.etaxonomy.cdm.model.common.OrderedTermBase;
78
import eu.etaxonomy.cdm.model.common.OrderedTermComparator;
79
import eu.etaxonomy.cdm.model.common.TermIdInVocabularyComparator;
80
import eu.etaxonomy.cdm.model.common.TermLanguageComparator;
81
import eu.etaxonomy.cdm.model.common.TermVocabulary;
82
import eu.etaxonomy.cdm.model.description.DescriptionBase;
83
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
84
import eu.etaxonomy.cdm.model.description.Distribution;
85
import eu.etaxonomy.cdm.model.location.NamedArea;
86
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
87
import eu.etaxonomy.cdm.model.reference.Reference;
88
import eu.etaxonomy.taxeditor.editor.EditorUtil;
89
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
90
import eu.etaxonomy.taxeditor.model.AbstractUtility;
91
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
92
import eu.etaxonomy.taxeditor.preference.Resources;
93
import eu.etaxonomy.taxeditor.preference.wizard.AvailableDistributionWizard;
94
import eu.etaxonomy.taxeditor.store.CdmStore;
95
import eu.etaxonomy.taxeditor.store.StoreUtil;
96
import eu.etaxonomy.taxeditor.ui.dialog.selection.ReferenceSelectionDialog;
97

  
98
/**
99
 * @author k.luther
100
 * @since 27.11.2018
101
 *
102
 */
103
public class DistributionEditor extends Composite {
104

  
105

  
106
    private static final String DISTRIBUTION_EDITOR = "Distribution Editor";
107
    private static final String LOADING_TAXA = Messages.ChecklistEditor_LOAD_TAXA;
108
    private static final String UNKNOWN = Messages.ChecklistEditor_UNKNOWN;
109
    private static final String ELEMENT_COUNT = Messages.ChecklistEditor_ELEMENT_COUNT;
110
    public static final String TYPE_FILTER_TEXT = "type filter text"; //$NON-NLS-1$
111

  
112
    static final String TAXON_COLUMN = "taxon_column"; //$NON-NLS-1$
113
    static final String RANK_COLUMN = "collector_column"; //$NON-NLS-1$
114

  
115
    private static final Logger logger = Logger.getLogger(DistributionEditor.class);
116
    @Inject
117
    private EMenuService menuService;
118
    private NatTable natTable;
119
    private Label statusLabel;
120
    private Label statusLabelSourceReference;
121
    private Reference defaultSource;
122

  
123
    private Map<Integer, NamedArea> areaToColumnIndexMap= new HashMap();
124
    private int firstDataColumnIndex;
125

  
126
    private ListDataProvider<TaxonDistributionDTO> bodyDataProvider;
127
    private LinkedMap<String, String> propertyToLabelMap = new LinkedMap<>();
128

  
129
    private boolean isShowRank;
130
    private Integer countNodes;
131
    private Text searchText;
132

  
133
    EventList<TaxonDistributionDTO> taxonList;
134

  
135
    SortedSet<DefinedTermBase> areas;
136
    DistributionEditorPart part;
137
    BodyLayerStack<TaxonDistributionDTO> bodyLayerStack;
138
    private FreezeLayer freezeLayer;
139
    private ConfigRegistry configRegistry;
140
    private AbstractLayer topMostLayer;
141

  
142
    private SelectionLayer selectionLayer;
143

  
144

  
145

  
146
 //  private FixedSummaryRowLayer summaryRowLayer;
147

  
148

  
149
    /**
150
     * @param parent
151
     * @param style
152
     */
153
    public DistributionEditor(Composite parent, DistributionEditorPart part) {
154
        super(parent, SWT.NULL);
155
        this.part = part;
156
        this.setLayout(new GridLayout());
157
        GridLayoutFactory.fillDefaults().applyTo(parent);
158

  
159
        Composite topComposite = new Composite(parent, SWT.NONE);
160
        createTopComposite(topComposite);
161

  
162
        Composite bottomComposite = new Composite(parent, SWT.NONE);
163
        GridLayoutFactory.fillDefaults().applyTo(bottomComposite);
164

  
165
        natTable = new NatTable(parent, false);
166
        parent.pack();
167

  
168

  
169
//       // natTable = new NatTable(parent, viewportLayer);
170
//        natTable = new NatTable(parent, false);
171

  
172
        createStatusBar(parent);
173
    }
174

  
175
    public boolean isShowRank() {
176
        return isShowRank;
177
    }
178

  
179
    public void setShowRank(boolean isShowRank) {
180
        this.isShowRank = isShowRank;
181
    }
182

  
183
    public int getFirstDataColumnIndex() {
184
        return firstDataColumnIndex;
185
    }
186

  
187
    public void setFirstDataColumnIndex(int firstDataColumnIndex) {
188
        this.firstDataColumnIndex = firstDataColumnIndex;
189
    }
190

  
191
    public LinkedMap<String, String> getPropertyToLabelMap() {
192
        return propertyToLabelMap;
193
    }
194

  
195
    public void setPropertyToLabelMap(LinkedMap<String, String> propertyToLabelMap) {
196
        this.propertyToLabelMap = propertyToLabelMap;
197
    }
198

  
199
    public Map<Integer, NamedArea> getAreaToColumnIndexMap() {
200
        return areaToColumnIndexMap;
201
    }
202

  
203

  
204
    public void setAreaToColumnIndexMap(Map<Integer, NamedArea> areaToColumnIndexMap) {
205
        this.areaToColumnIndexMap = areaToColumnIndexMap;
206
    }
207

  
208

  
209

  
210
    private void createStatusBar(Composite composite) {
211
        GridData gridData = new GridData();
212
        gridData.horizontalSpan = 1;
213
        gridData.grabExcessHorizontalSpace = true;
214
        gridData.horizontalAlignment = GridData.FILL;
215

  
216
        statusLabel = new Label(composite, SWT.LEFT);
217
        statusLabel.setText(ELEMENT_COUNT + (taxonList != null ? taxonList.size() : UNKNOWN));
218
        statusLabel.setLayoutData(gridData);
219

  
220
        statusLabelSourceReference = new Label(composite, SWT.RIGHT);
221

  
222
        statusLabelSourceReference.setLayoutData(gridData);
223

  
224
        if (defaultSource != null){
225
            statusLabelSourceReference.setText("Default Source Reference: " + defaultSource.getAbbrevTitle() != null? defaultSource.getAbbrevTitle() : defaultSource.getAbbrevTitleCache());
226

  
227
        }
228
    }
229

  
230
    private void applyStyles(){
231
        ModernNatTableThemeConfiguration configuration = new ModernNatTableThemeConfiguration();
232
        configuration.summaryRowHAlign = HorizontalAlignmentEnum.CENTER;
233
        // NOTE: Getting the colors and fonts from the GUIHelper ensures that
234
        // they are disposed properly (required by SWT)
235
        configuration.cHeaderBgColor = GUIHelper.getColor(211, 211, 211);
236
        configuration.rHeaderBgColor = GUIHelper.getColor(211, 211, 211);
237
        natTable.addConfiguration(configuration);
238

  
239
    }
240

  
241
    private void configureNatTable(ConfigRegistry configRegistry,
242
            AbstractLayer topMostLayer) {
243
        /**
244
         * CONFIGURATION
245
         */
246
        natTable.setConfigRegistry(configRegistry);
247

  
248
        applyStyles();
249

  
250
        //add default configuration because autoconfigure is set to false in constructor
251
        natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
252

  
253
        // override the default sort configuration and change the mouse bindings
254
        // to sort on a single click
255

  
256
        natTable.addConfiguration(new SingleClickSortConfiguration());
257
        natTable.addConfiguration(new FilterRowConfiguration(this));
258

  
259
        // add the header menu configuration for adding the column header menu
260
        // with hide/show actions
261
        natTable.addConfiguration(new DistributionEditorHeaderMenuConfiguration(natTable));
262

  
263
        // add custom configuration for data conversion and add column labels to viewport layer
264
        topMostLayer.addConfiguration(new DistributionCellEditorDataConversionConfiguration(this));
265

  
266
        natTable.configure();
267
    }
268

  
269
    public void createTable(){
270
        /**
271
         * layers
272
         */
273

  
274
        createLayers();
275

  
276
        /**
277
         * configuration
278
         */
279
        configureNatTable( configRegistry, topMostLayer);
280

  
281
        /**
282
         * handlers and listeners
283
         */
284
        registerHandlersAndListeners(topMostLayer);
285
        FreezeHelper.freeze(freezeLayer, bodyLayerStack.getViewPortLayer(),
286
                new PositionCoordinate(bodyLayerStack.getViewPortLayer(), 0, 0),
287
                new PositionCoordinate(bodyLayerStack.getViewPortLayer(), 0, -1));
288
        //grab all space
289
        GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
290

  
291
        this.layout();
292
      //  boolean ok = natTable.doCommand(new ClientAreaResizeCommand(natTable));
293
      //  System.out.println(ok);
294
    }
295

  
296

  
297
    private void createLayers() {
298

  
299
        DistributionColumnAccessor columnPropertyAccessor = new DistributionColumnAccessor(this);
300

  
301
        DistributionEditorConfigLabelAccumulator labelAccumulator = new DistributionEditorConfigLabelAccumulator(this);
302
        bodyLayerStack = new BodyLayerStack<>(taxonList, columnPropertyAccessor, new TaxonDistributionDtoComparator(), labelAccumulator);
303

  
304
        bodyDataProvider = bodyLayerStack.getBodyDataProvider();
305

  
306

  
307

  
308
        propertyToLabelMap.put(TAXON_COLUMN, Messages.ChecklistEditor_TAXON);
309
        if (isShowRank){
310
            propertyToLabelMap.put(RANK_COLUMN, Messages.ChecklistEditor_RANK);
311
        }
312
        configRegistry = new ConfigRegistry();
313

  
314
        initLabels();
315
        this.selectionLayer = bodyLayerStack.getSelectionLayer();
316

  
317

  
318

  
319
        freezeLayer = new FreezeLayer(selectionLayer);
320
        final CompositeFreezeLayer compositeFreezeLayer = new CompositeFreezeLayer(
321
                freezeLayer,  bodyLayerStack.getViewPortLayer(), selectionLayer);
322

  
323
        // as the selection mouse bindings are registered for the region label
324
        // GridRegion.BODY
325
        // we need to set that region label to the viewport so the selection via mouse
326
        // is working correctly
327
        compositeFreezeLayer.setRegionName(GridRegion.BODY);
328

  
329

  
330
        IDataProvider columnHeaderDataProvider =
331
                new DefaultColumnHeaderDataProvider(propertyToLabelMap.values().toArray(new String[] {}), propertyToLabelMap);
332
        DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
333
        ILayer columnHeaderLayer = new ColumnHeaderLayer(
334
            columnHeaderDataLayer,
335
            compositeFreezeLayer,
336
            selectionLayer);
337

  
338
        FilterRowHeaderComposite<TaxonDistributionDTO> filterRowHeaderLayer =
339
                new FilterRowHeaderComposite<>(
340
                        new DefaultGlazedListsFilterStrategy<>(
341
                                bodyLayerStack.getFilterList(),
342
                                columnPropertyAccessor,
343
                                configRegistry),
344
                        columnHeaderLayer,
345
                        columnHeaderDataLayer.getDataProvider(),
346
                        configRegistry);
347

  
348

  
349

  
350
     // build the row header layer stack
351
        IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
352
        DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
353
        ILayer rowHeaderLayer = new RowHeaderLayer(
354
            rowHeaderDataLayer,
355
            compositeFreezeLayer,
356
            selectionLayer);
357

  
358

  
359

  
360
        IDataProvider cornerDataProvider =
361
                new DefaultCornerDataProvider(
362
                    columnHeaderDataProvider,
363
                    rowHeaderDataProvider);
364
        DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
365
        ILayer cornerLayer = new CornerLayer(
366
            cornerDataLayer,
367
            rowHeaderLayer,
368
            filterRowHeaderLayer);
369

  
370
        GridLayer gridLayer = new GridLayer(
371
                compositeFreezeLayer,
372
                filterRowHeaderLayer,
373
                rowHeaderLayer,
374
                cornerLayer);
375

  
376
        natTable.setLayer(gridLayer);
377

  
378
        topMostLayer = compositeFreezeLayer;
379

  
380

  
381
    }
382

  
383
    /**
384
     * @param parent
385
     * @return
386
     */
387
    private Text createSearchBar(Composite parent) {
388

  
389
        Button button1 = new Button(parent, SWT.PUSH );
390
        GridData gridData2 = new GridData();
391
        gridData2.horizontalSpan = 1;
392
        gridData2.horizontalAlignment = SWT.RIGHT;
393
        button1.setLayoutData(gridData2);
394

  
395

  
396
        button1.setText(Messages.ChecklistEditor_DIST_STATUS);
397
        button1.setToolTipText(Messages.ChecklistEditor_DIST_STATUS_TOOLTIP);
398
        button1.addSelectionListener(new SelectionAdapter() {
399
            @Override
400
            public void widgetSelected(SelectionEvent event) {
401
                AvailableDistributionWizard availableDistributionWizard = new AvailableDistributionWizard();
402
                WizardDialog dialog = new WizardDialog(StoreUtil.getShell(),
403
                        availableDistributionWizard);
404

  
405
                int open = dialog.open();
406
                if(open == 0){
407
                    reload();
408
                }
409
            }
410
        });
411

  
412
        Button button2 = new Button(parent, SWT.PUSH );
413
        GridData gridData3 = new GridData();
414
        gridData2.horizontalSpan = 1;
415
        button2.setLayoutData(gridData3);
416

  
417

  
418
        button2.setText(Messages.ChecklistEditor_DEFAULT_SOURCE);
419
        button2.setToolTipText(Messages.ChecklistEditor_DEFAULT_SOURCE_TOOLTIP);
420
        button2.addSelectionListener(new SelectionAdapter() {
421

  
422
            @Override
423
            public void widgetSelected(SelectionEvent event) {
424
                defaultSource = ReferenceSelectionDialog.select(AbstractUtility.getShell(), null);
425

  
426
                String defaultSourceStr = (defaultSource == null) ? "" : "Default Source Reference: " + defaultSource.getTitleCache();
427
                if (defaultSourceStr.length()> 100){
428
                    defaultSourceStr = defaultSourceStr.substring(0, 98) + "...";
429
                }
430
                statusLabelSourceReference.setText(defaultSourceStr);
431

  
432
                button2.setBackground(EditorUtil.getColor(Resources.COLOR_CONTROL_SELECTED));
433
            }
434

  
435
        });
436

  
437
        parent.pack();
438
        return searchText;
439
    }
440
    /**
441
    * This method should only be called for adding new Distribution columns and reloading the table.<br>
442
    * It will hide the old distribution column and load the newly added columns.<br>
443
    * <p>
444
    * <b>Notice:</b> for data update please use <b>refresh()</b>
445
    *
446
    */
447
   @SuppressWarnings({ "unchecked", "rawtypes" })
448
   public void reload(){
449
       this.areaToColumnIndexMap.clear();
450
       this.areas.clear();
451
       this.propertyToLabelMap.clear();
452
       createTable();
453
       natTable.redraw();
454
    }
455

  
456
    /**
457
     * @param parent
458
     */
459
    private void createTopComposite(Composite parent) {
460
        GridLayout gridLayout = new GridLayout(3, false);
461
        gridLayout.marginWidth = 0;
462
        gridLayout.marginHeight = 0;
463
        parent.setLayout(gridLayout);
464
        searchText = createSearchBar(parent);
465

  
466

  
467
    }
468
    public void loadDistributions(List<TaxonDistributionDTO> taxonList) {
469
        if (this.taxonList == null){
470
            this.taxonList = new BasicEventList<>();
471
        }
472
       taxonList.stream().forEach(wrapper->DistributionEditor.this.taxonList.add(wrapper));
473
       statusLabel.setText(ELEMENT_COUNT + (taxonList != null ? taxonList.size() : UNKNOWN));
474
    }
475

  
476

  
477

  
478
    public List<DescriptionBase> getDistributions() {
479
        List<DescriptionBase> descriptions = new ArrayList();
480

  
481
//        taxonList.forEach(taxonDto->taxonDto.getDistributionMap()
482
//                .forEach((area, descriptionElements)->descElements.addAll(descriptionElements)));
483

  
484
        taxonList.forEach(taxonDto -> taxonDto.getDescriptionsWrapper().getDescriptions().forEach(taxDesc -> descriptions.add(taxDesc)));
485

  
486
        for (DescriptionBase description: descriptions){
487
            List<DescriptionElementBase> toDelete = new ArrayList();
488
           for (Object desc: description.getElements()){
489
               if (desc instanceof Distribution){
490
                   Distribution distribution = (Distribution) desc;
491
                   if (distribution.getStatus() == null || !distribution.getStatus().isPersited()){
492
                       toDelete.add(distribution);
493
                   }
494
               }
495
           }
496
           for (DescriptionElementBase element: toDelete){
497
               description.removeElement(element);
498
           }
499

  
500
        }
501

  
502

  
503
        return descriptions;
504

  
505
    }
506

  
507
    private void initLabels() {
508

  
509
        int index = 1;
510
        if (isShowRank){
511
            index++;
512
        }
513

  
514
        loadNamedAreas();
515
        for (DefinedTermBase area: areas) {
516
            this.areaToColumnIndexMap.put(index++, (NamedArea)area);
517

  
518
            //TODO: adapt to preference
519
            String areaLabel = area.getLabel();
520
            String property = areaLabel;
521
            propertyToLabelMap.put(property, areaLabel);
522
        }
523
    }
524

  
525
    private SortedSet<DefinedTermBase> loadNamedAreas() {
526
        //IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
527

  
528
        String valuesAreas = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey());
529
        String values = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey());
530
        if (values != null && values != "") { //$NON-NLS-1$
531
            String[] split = values.split(";"); //$NON-NLS-1$
532
            List<String> listValue = Arrays.asList(split);
533
            List<DefinedTermBase> termlist = new ArrayList<DefinedTermBase>();
534
            Set<UUID> uuidList = new HashSet<UUID>();
535
            UUID uuid;
536
            for(String s : listValue){
537
                uuid = UUID.fromString(s);
538
                uuidList.add(uuid);
539

  
540
            }
541
            IVocabularyService service =  CdmStore.getService(IVocabularyService.class);
542
            List<TermVocabulary> vocs = service.find(uuidList);
543
            split = valuesAreas.split(";");
544
            listValue = Arrays.asList(split);
545
            for (TermVocabulary voc: vocs){
546
                termlist.addAll(service.getTerms(voc, null, null, null, null).getRecords());
547
            }
548
            List<DefinedTermBase> filteredList = new ArrayList();
549
            for (DefinedTermBase area: termlist){
550
                if (listValue.contains(area.getUuid().toString())) {
551
                    filteredList.add(area);
552
                }
553

  
554
            }
555

  
556
            if (PreferencesUtil.isSortNamedAreaByOrderInVocabulary()){
557
                areas =  getTermsOrderedByVocabularyOrder(filteredList);
558
            } else if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
559
                areas = getTermsOrderedByIdInVocabulary(filteredList);
560
            }else{
561
                areas =  getTermsOrderedByLabels(filteredList, CdmStore.getDefaultLanguage());
562
            }
563
        }
564
        return null;
565
    }
566

  
567
    public SortedSet<DefinedTermBase> getTermsOrderedByLabels(List<DefinedTermBase> listTerm,Language language){
568
        TermLanguageComparator<?> comp = new TermLanguageComparator<>();
569
        comp.setCompareLanguage(language);
570
        SortedSet<DefinedTermBase> result = new TreeSet(comp);
571
        if(listTerm != null){
572
            result.addAll(listTerm);
573
        }
574
        return result;
575
    }
576

  
577
    public SortedSet<DefinedTermBase> getTermsOrderedByIdInVocabulary(List<DefinedTermBase> namedAreas) {
578
        TermIdInVocabularyComparator<?> comp = new TermIdInVocabularyComparator<>();
579

  
580
        SortedSet<DefinedTermBase> result = new TreeSet(comp);
581
        if(namedAreas != null){
582
            result.addAll(namedAreas);
583
        }
584
        return result;
585
    }
586

  
587
    public SortedSet<DefinedTermBase> getTermsOrderedByVocabularyOrder(List<DefinedTermBase> listAreas){
588
        HashMap<TermVocabulary<DefinedTermBase>, List<DefinedTermBase>> vocs = new HashMap<>();
589
        OrderedTermComparator<?> comp = new OrderedTermComparator<>();
590
        boolean allOrderedTerms = true;
591
        List<TermVocabulary> alreadyOrderIndexNull = new ArrayList<>();
592
        for (DefinedTermBase term: listAreas){
593
            if (!(term instanceof OrderedTermBase)){
594
                allOrderedTerms = false;
595
                break;
596
            }else if (((OrderedTermBase)term).getOrderIndex() == 0){
597
                if(alreadyOrderIndexNull.contains(term.getVocabulary())) {
598
                    allOrderedTerms = false;
599
                    break;
600
                }else{
601
                    alreadyOrderIndexNull.add(term.getVocabulary());
602
                }
603

  
604

  
605
            }
606
        }
607
        if (allOrderedTerms){
608
            SortedSet<DefinedTermBase> result = new TreeSet(comp.reversed());
609
            result.addAll(listAreas);
610
            return result;
611
        }else{
612
            return getTermsOrderedByLabels(listAreas, PreferencesUtil.getGlobalLanguage());
613
        }
614

  
615

  
616
    }
617

  
618
    private void registerHandlersAndListeners(AbstractLayer topMostLayer) {
619
        //selection listener
620
        E4SelectionListener selectionListener = new DistributionCellSelectionListener(part.getSelectionService(),
621
                selectionLayer, bodyDataProvider, part);
622
        selectionLayer.addLayerListener(selectionListener);
623
        selectionListener.setFullySelectedRowsOnly(false);
624

  
625
        //register handler for view configuration menu
626
      //  natTable.registerCommandHandler(toolbar.getDisplayPersistenceDialogCommandHandler());
627
    }
628

  
629
    /**
630
     * @return
631
     */
632
    public IRowDataProvider<TaxonDistributionDTO> getBodyDataProvider() {
633
        return bodyDataProvider;
634
    }
635

  
636
    public void setDirty() {
637
        part.setDirty();
638
    }
639

  
640
    public Reference getDefaultSource(){
641
        return defaultSource;
642
    }
643

  
644

  
645

  
646
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionEditorConfigLabelAccumulator.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.view.checklist.e4;
10

  
11
import org.eclipse.nebula.widgets.nattable.layer.LabelStack;
12
import org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator;
13

  
14
import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO;
15

  
16
/**
17
 * @author k.luther
18
 * @since 05.12.2018
19
 *
20
 */
21
public class DistributionEditorConfigLabelAccumulator  implements IConfigLabelAccumulator{
22

  
23
    public static final String STATUS = "STATUS";
24
    public static final String STATUS_EDITABLE = STATUS+"_EDITABLE";
25
    public static final String FILTER_EDITABLE = "FILTER_EDITABLE";
26

  
27

  
28
    private DistributionEditor editor;
29

  
30
    public DistributionEditorConfigLabelAccumulator(DistributionEditor editor) {
31
        super();
32
        this.editor = editor;
33
    }
34

  
35
    @Override
36
    public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
37
        boolean isEditable = true;
38

  
39
        Object rowObject = editor.getBodyDataProvider().getRowObject(rowPosition);
40
        TaxonDistributionDTO taxonRowWrapper = null;
41
        if(rowObject instanceof TaxonDistributionDTO){
42
            taxonRowWrapper = (TaxonDistributionDTO) rowObject;
43
        }
44

  
45
        if(columnPosition==0){
46
            configLabels.addLabel(DistributionEditor.TAXON_COLUMN);
47
            configLabels.addLabel(FILTER_EDITABLE);
48
        } else if(columnPosition==1 && editor.isShowRank()){
49
            configLabels.addLabel(DistributionEditor.RANK_COLUMN);
50
        } else{
51

  
52
            configLabels.addLabel(STATUS);
53
            if(isEditable){
54
                configLabels.addLabel(STATUS_EDITABLE);
55
            }
56

  
57

  
58

  
59
        }
60
    }
61
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionEditorHeaderMenuConfiguration.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.view.checklist.e4;
10

  
11
import org.eclipse.nebula.widgets.nattable.NatTable;
12
import org.eclipse.nebula.widgets.nattable.ui.menu.AbstractHeaderMenuConfiguration;
13
import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder;
14

  
15
/**
16
 * @author kluther
17
 * @date 28.11.2018
18
 *
19
 */
20
final class DistributionEditorHeaderMenuConfiguration extends AbstractHeaderMenuConfiguration {
21

  
22
    /**
23
     * @param natTable
24
     */
25
    public DistributionEditorHeaderMenuConfiguration(NatTable natTable) {
26
        super(natTable);
27

  
28
    }
29

  
30

  
31
    @Override
32
    protected PopupMenuBuilder createColumnHeaderMenu(NatTable natTable) {
33
        return super.createColumnHeaderMenu(natTable)
34
                .withHideColumnMenuItem()
35
                .withShowAllColumnsMenuItem();
36
    }
37
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionEditorPart.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.view.checklist.e4;
10

  
11
import java.util.Arrays;
12
import java.util.Collection;
13
import java.util.List;
14
import java.util.Map;
15
import java.util.UUID;
16

  
17
import javax.annotation.PostConstruct;
18
import javax.annotation.PreDestroy;
19
import javax.inject.Inject;
20

  
21
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
23
import org.eclipse.e4.core.contexts.IEclipseContext;
24
import org.eclipse.e4.ui.di.Persist;
25
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
26
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
27
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
28
import org.eclipse.swt.custom.StackLayout;
29
import org.eclipse.swt.widgets.Composite;
30

  
31
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
32
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
33
import eu.etaxonomy.cdm.api.service.IDescriptionService;
34
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
35
import eu.etaxonomy.cdm.api.service.UpdateResult;
36
import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO;
37
import eu.etaxonomy.cdm.model.common.CdmBase;
38
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
39
import eu.etaxonomy.taxeditor.editor.IDistributionEditor;
40
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
41
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
42
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
43
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
44
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
45
import eu.etaxonomy.taxeditor.store.CdmStore;
46
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
47

  
48
/**
49
 * @author k.luther
50
 * @since 28.11.2018
51
 *
52
 */
53
public class DistributionEditorPart implements IE4SavablePart, IConversationEnabled, IDirtyMarkable,
54
ICdmEntitySessionEnabled, IPartContentHasSupplementalData, IPartContentHasDetails, IDistributionEditor{
55

  
56
    private static final List<String> TAXONNODE_PROPERTY_PATH = Arrays.asList(new String[] {
57
            "taxon", //$NON-NLS-1$
58
            "taxon.name", //$NON-NLS-1$
59
            "taxon.name.rank",//$NON-NLS-1$
60
            "taxon.descriptions", //$NON-NLS-1$
61
            "taxon.descriptions.descriptionElements", //$NON-NLS-1$
62
            "taxon.descriptions.descriptionElements.feature", //$NON-NLS-1$
63
            "taxon.descriptions.descriptionElements.sources", //$NON-NLS-1$
64
            "taxon.descriptions.descriptionElements.media" //$NON-NLS-1$
65
    });
66

  
67
    private List<TaxonDistributionDTO> taxonList;
68
    private Collection<UpdateResult> updateResults;
69

  
70
    private ConversationHolder conversation;
71

  
72
    private ICdmEntitySession cdmEntitySession;
73

  
74
    @Inject
75
    private ESelectionService selService;
76

  
77
    @Inject
78
    private MDirtyable dirty;
79

  
80
    @Inject
81
    private MPart thisPart;
82

  
83
    private DistributionEditor editor;
84

  
85
    private StackLayout stackLayout;
86

  
87
    @PostConstruct
88
    public void create(Composite parent, IEclipseContext context) {
89
        if(CdmStore.isActive() && conversation==null){
90
            conversation = CdmStore.createConversation();
91
        }
92
        if(cdmEntitySession == null){
93
            cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
94
        }
95
        else{
96
            return;
97
        }
98
        stackLayout = new StackLayout();
99
        parent.setLayout(stackLayout);
100
        editor = new DistributionEditor(parent, this);
101

  
102
        ContextInjectionFactory.inject(editor, context);
103
    }
104

  
105
    public void init(UUID parentTaxonUuid) {
106
        this.taxonList = CdmStore.getService(ITaxonNodeService.class).getTaxonDistributionDTOForSubtree(parentTaxonUuid, TAXONNODE_PROPERTY_PATH);
107

  
108
        if(taxonList!=null){
109
            editor.loadDistributions(taxonList);
110
            editor.createTable();
111
            editor.pack();
112
            stackLayout.topControl = editor;
113
            editor.getParent().layout();
114
        }
115
    }
116
    public ESelectionService getSelectionService() {
117
        return selService;
118
    }
119

  
120

  
121
    public DistributionEditor getEditor() {
122
        return editor;
123
    }
124

  
125
    /**
126
     * {@inheritDoc}
127
     */
128
    @Override
129
    public void update(CdmDataChangeMap changeEvents) {
130
        // TODO Auto-generated method stub
131

  
132
    }
133
    @PreDestroy
134
    public void dispose(){
135
        if (conversation != null) {
136
            conversation.close();
137
            conversation = null;
138
        }
139
        if(cdmEntitySession != null) {
140
            cdmEntitySession.dispose();
141
            cdmEntitySession = null;
142
        }
143
        dirty.setDirty(false);
144

  
145
    }
146

  
147

  
148
    /**
149
     * {@inheritDoc}
150
     */
151
    @Override
152
    public ICdmEntitySession getCdmEntitySession() {
153
        // TODO Auto-generated method stub
154
        return null;
155
    }
156

  
157
    /**
158
     * {@inheritDoc}
159
     */
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff