Project

General

Profile

« Previous | Next » 

Revision 04f83f13

Added by Katja Luther about 4 years ago

ref #7063:fix that the last selection always appears in next field in distribution editor

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/ChecklistEditorE4.java
427 427
     */
428 428
    private TableViewerColumn addTableViewerColumn(String title, int bound, final int colNumber, DefinedTermBase term) {
429 429

  
430
        final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE);
430
        final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.FULL_SELECTION);
431 431
        final TableColumn column = viewerColumn.getColumn();
432 432
        column.setText(title);
433 433
        String[] UuidAndLable = new String[2];
......
435 435
        UuidAndLable[1] = title;
436 436
        column.setData(UuidAndLable);
437 437
        column.setWidth(200);
438

  
438 439
        viewerColumn.setEditingSupport(new DistributionEditingSupportE4(viewer, this, colNumber));
439 440
        column.setResizable(true);
440 441
        column.setMoveable(true);
......
744 745

  
745 746
        //propagate selection
746 747
        selectionChangedListener = (event -> selService.setSelection(
747
               DistributionEditorHelper.getDistributionForColumn(event)));
748
               DistributionEditorHelper.getDistributionForColumn(event, areaPosition)));
748 749

  
749 750
        viewer.addSelectionChangedListener(selectionChangedListener);
750 751

  
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionEditingSupportE4.java
32 32
import eu.etaxonomy.cdm.model.description.TaxonDescription;
33 33
import eu.etaxonomy.cdm.model.location.NamedArea;
34 34
import eu.etaxonomy.cdm.model.taxon.Taxon;
35
import eu.etaxonomy.taxeditor.event.EventUtility;
36
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
35 37
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
36 38
import eu.etaxonomy.taxeditor.store.CdmStore;
37 39

  
38 40
public final class DistributionEditingSupportE4 extends EditingSupport {
39 41

  
40 42
    private ComboBoxViewerCellEditor cellEditor = null;
41
    private final TableViewer viewer;
43
    //private final TableViewer viewer;
42 44
    private final ChecklistEditorE4 editor;
43 45
//    private final IDescriptionService descriptionService;
44 46
    private final int columnIndex;
......
51 53

  
52 54
    public DistributionEditingSupportE4(TableViewer viewer, ChecklistEditorE4 checklistEditor, int columnIndex) {
53 55
        super(viewer);
54
        this.viewer = viewer;
56
       // this.viewer = viewer;
55 57
        this.columnIndex = columnIndex;
56 58

  
57 59
//        descriptionService = CdmStore.getService(IDescriptionService.class);
58 60
        editor = checklistEditor;
59
        cellEditor = new ComboBoxViewerCellEditor((Composite) viewer.getControl(), SWT.READ_ONLY);
61
        cellEditor = new DistributionStatusComboBoxViewerCellEditor((Composite) this.getViewer().getControl(), SWT.READ_ONLY);
60 62
        cellEditor.setLabelProvider(new LabelProvider(){
61 63
        	 @Override
62 64
        	   public String getText(Object element) {
......
91 93
        inputAll.addAll(1, input);
92 94
        cellEditor.setInput(inputAll);
93 95

  
96

  
94 97
    }
95 98

  
96 99
    @Override
......
112 115

  
113 116
            if (distributionForColumn != null) {
114 117
                PresenceAbsenceTerm status = distributionForColumn.getStatus();
118

  
115 119
                if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
116 120
                    if (status.getIdInVocabulary() != null){
117 121
                        result =  status.getIdInVocabulary();
......
126 130
                }
127 131
            }
128 132

  
129
           fireStateChanged(distributionForColumn);
133
           //fireStateChanged(distributionForColumn);
130 134
            return result;
131 135
        }
132 136
        return null;
......
142 146
    @Override
143 147
    protected void setValue(Object element, Object value) {
144 148
    	if (element instanceof Taxon && value instanceof PresenceAbsenceTerm) {
149

  
145 150
            Taxon taxon = (Taxon) element;
146 151
            PresenceAbsenceTerm occurenceStatus = (PresenceAbsenceTerm) value;
147 152
            Distribution distribution = getDistributionForColumn(taxon);
......
163 168
//            viewer.update(element, null);
164 169
//            viewer.refresh();
165 170
//            editor.setDirty(true);
171

  
166 172
            editor.changed(element);
167
            viewer.refresh();
173
            getViewer().refresh();
174

  
175
            EventUtility.postEvent(WorkbenchEventConstants.REFRESH_TAXON_DETAILS, true);
168 176
        }
169 177
    }
170 178

  
......
180 188
//        List<TaxonDescription> listTaxonDescriptions = descriptionService.listTaxonDescriptions(taxon, null, null,
181 189
//                null, null, null, DESC_INIT_STRATEGY);
182 190
        Set<TaxonDescription> listTaxonDescriptions = taxon.getDescriptions();
183
        TableColumn column = viewer.getTable().getColumn(columnIndex);
191
        TableColumn column = ((TableViewer)getViewer()).getTable().getColumn(columnIndex);
184 192
        for (TaxonDescription td : listTaxonDescriptions) {
185 193
            for (DescriptionElementBase deb : td.getElements()) {
186 194
                if (deb instanceof Distribution) {
......
203 211
    }
204 212

  
205 213
    private void createDistributionForColumn(Taxon taxon, PresenceAbsenceTerm occurenceStatus) {
206
        TableColumn column = viewer.getTable().getColumn(columnIndex);
214
        TableColumn column = ((TableViewer)this.getViewer()).getTable().getColumn(columnIndex);
207 215

  
208 216
        SortedSet<DefinedTermBase> namedAreas = this.editor.getLabelProvider().getNamedAreas(false);
209 217

  
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionEditorHelper.java
9 9
*/
10 10
package eu.etaxonomy.taxeditor.editor.view.checklist.e4;
11 11

  
12
import java.util.Map;
12 13
import java.util.Set;
14
import java.util.UUID;
13 15

  
14 16
import org.eclipse.jface.viewers.SelectionChangedEvent;
15 17
import org.eclipse.jface.viewers.TableViewer;
16 18
import org.eclipse.jface.viewers.TableViewerEditor;
17 19
import org.eclipse.jface.viewers.ViewerCell;
18
import org.eclipse.swt.widgets.TableColumn;
19 20

  
20 21
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
21 22
import eu.etaxonomy.cdm.model.description.Distribution;
22 23
import eu.etaxonomy.cdm.model.description.TaxonDescription;
23 24
import eu.etaxonomy.cdm.model.taxon.Taxon;
24
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
25 25

  
26 26
/**
27 27
 * @author k.luther
......
30 30
 */
31 31
public class DistributionEditorHelper {
32 32

  
33
    public static Distribution getDistributionForColumn(SelectionChangedEvent event) {
33
    public static Distribution getDistributionForColumn(SelectionChangedEvent event, Map<UUID, Integer> areaPosition) {
34 34
        //      List<TaxonDescription> listTaxonDescriptions = descriptionService.listTaxonDescriptions(taxon, null, null,
35 35
        //      null, null, null, DESC_INIT_STRATEGY);
36 36
        TableViewer viewer = null;
......
57 57
            return null;
58 58
        }
59 59
        columnIndex = cell.getColumnIndex();
60
        UUID areaUuid = null;
61
        for (Map.Entry<UUID,Integer> entry: areaPosition.entrySet()){
62
            if (entry.getValue().intValue()== columnIndex){
63
                areaUuid = entry.getKey();
64
                break;
65
            }
66
        }
67
        if (areaUuid == null){
68
            return null;
69
        }
60 70
        Set<TaxonDescription> listTaxonDescriptions = taxon.getDescriptions();
61
        TableColumn column = viewer.getTable().getColumn(columnIndex);
71

  
62 72
        for (TaxonDescription td : listTaxonDescriptions) {
63 73
          for (DescriptionElementBase deb : td.getElements()) {
64 74
              if (deb instanceof Distribution) {
65 75
                  Distribution distribution = (Distribution) deb;
66
                  if (distribution.getArea() != null){
67
                      if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
68
                          if (column.getText().equalsIgnoreCase(distribution.getArea().getIdInVocabulary())) {
69
                              return distribution;
70
                          }
71
                      }else{
72
                          if (column.getText().equalsIgnoreCase(distribution.getArea().getTitleCache())) {
73
                              return distribution;
74
                          }
75
                      }
76
                  if (distribution.getArea().getUuid() == areaUuid){
77
                      return distribution;
76 78
                  }
77 79
              }
78 80
          }
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionStatusComboBoxViewerCellEditor.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.jface.viewers.ComboBoxViewerCellEditor;
12
import org.eclipse.swt.widgets.Composite;
13

  
14
/**
15
 * @author k.luther
16
 * @since 28.09.2018
17
 *
18
 */
19
public class DistributionStatusComboBoxViewerCellEditor extends ComboBoxViewerCellEditor {
20

  
21
    /**
22
     * @param parent
23
     */
24
    public DistributionStatusComboBoxViewerCellEditor(Composite parent, int style) {
25
        super(parent, style);
26
    }
27

  
28
    @Override
29
    protected void focusLost() {
30
        this.getViewer().setSelection(null, true);
31
        if (this.getViewer().getCCombo() != null){
32
            this.getViewer().getCCombo().deselectAll();
33
        }
34
    }
35

  
36
    @Override
37
    protected boolean dependsOnExternalFocusListener() {
38
        return false;
39
    }
40

  
41

  
42

  
43

  
44

  
45
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/details/DetailsViewerE4.java
223 223
        // of the corresponding detail viewer.
224 224

  
225 225
        Object input = getInput();
226

  
226
        if (input == null){
227
            return;
228
        }
227 229
        destroySections();
228 230
        if (input instanceof TaxonBase) {
229 231
            if(((TaxonBase) input).getName()==null){

Also available in: Unified diff