Project

General

Profile

Revision 94d71120

ID94d711202ab51ff4fdf999d0f287fae48db0fadd
Parent 378fbb8a
Child bf128d5f

Added by Patrick Plitzner about 1 year ago

ref #7439 Extract column property accessor to class

View differences:

eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java
33 33
import org.eclipse.jface.viewers.IStructuredSelection;
34 34
import org.eclipse.jface.viewers.TableViewer;
35 35
import org.eclipse.nebula.widgets.nattable.NatTable;
36
import org.eclipse.nebula.widgets.nattable.data.IColumnPropertyAccessor;
37 36
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
38 37
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
39 38
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer;
......
85 84
        IDirtyMarkable, IDerivedUnitFacadePart, IPartContentHasFactualData,
86 85
        IPartContentHasSupplementalData, IPartContentHasMedia, IE4SavablePart, ITaxonEditor {
87 86

  
88
    private static final String TYPE = "Type";
87
    public static final String TYPE_PROPERTY = "Type";
89 88

  
90 89
    @Inject
91 90
	private MDirtyable dirty;
......
219 218
        list = new BasicEventList<>();
220 219
        Map<String, String> propertyToLabels = new HashMap<>();
221 220
        propertyToLabels.put(getEditorInput().getName(), getEditorInput().getName());
222
        propertyToLabels.put(TYPE, TYPE);
223
        String[] propertyNames = new String[] { getEditorInput().getName(), TYPE };
221
        propertyToLabels.put(TYPE_PROPERTY, TYPE_PROPERTY);
222
        String[] propertyNames = new String[] { getEditorInput().getName(), TYPE_PROPERTY };
224 223
        IDataProvider bodyDataProvider = new ListDataProvider<CdmBase>(list,
225
                new IColumnPropertyAccessor<CdmBase>() {
226

  
227
                    @Override
228
                    public Object getDataValue(CdmBase rowObject, int columnIndex) {
229
                        if(columnIndex==0){
230
                            return getEditorInput().getText(rowObject);
231
                        }else if(columnIndex==1){
232
                            return getEditorInput().getTypeText(rowObject);
233
                        }
234
                        return null;
235
                    }
236

  
237
                    @Override
238
                    public void setDataValue(CdmBase rowObject, int columnIndex, Object newValue) {
239
                        //no editing allowed
240
                    }
241

  
242
                    @Override
243
                    public int getColumnCount() {
244
                        return 2;
245
                    }
246

  
247
                    @Override
248
                    public String getColumnProperty(int columnIndex) {
249
                        if(columnIndex==0){
250
                            return getEditorInput().getName();
251
                        }else if(columnIndex==1){
252
                            return TYPE;
253
                        }
254
                        return null;
255
                    }
256

  
257
                    @Override
258
                    public int getColumnIndex(String propertyName) {
259
                        if(propertyName.equals(getEditorInput().getName())){
260
                            return 0;
261
                        }
262
                        else if(propertyName.equals(TYPE)){
263
                            return 1;
264
                        }
265
                        return 0;
266
                    }
267
                });
224
                new BulkEditorPropertyAccessor(getEditorInput()));
268 225

  
269 226

  
270 227
        DefaultColumnHeaderDataProvider colHeaderDataProvider = new DefaultColumnHeaderDataProvider(
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorPropertyAccessor.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.bulkeditor.e4;
10

  
11
import org.eclipse.nebula.widgets.nattable.data.IColumnPropertyAccessor;
12

  
13
import eu.etaxonomy.cdm.model.common.CdmBase;
14
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
15

  
16
/**
17
 * @author pplitzner
18
 * @since May 29, 2018
19
 *
20
 */
21
public class BulkEditorPropertyAccessor implements IColumnPropertyAccessor<CdmBase> {
22

  
23
        private AbstractBulkEditorInput input;
24

  
25

  
26
        public BulkEditorPropertyAccessor(AbstractBulkEditorInput<CdmBase> input) {
27
            super();
28
            this.input = input;
29
        }
30

  
31
        @Override
32
        public Object getDataValue(CdmBase rowObject, int columnIndex) {
33
            if(columnIndex==0){
34
                return input.getText(rowObject);
35
            }else if(columnIndex==1){
36
                return input.getTypeText(rowObject);
37
            }
38
            return null;
39
        }
40

  
41
        @Override
42
        public void setDataValue(CdmBase rowObject, int columnIndex, Object newValue) {
43
            //no editing allowed
44
        }
45

  
46
        @Override
47
        public int getColumnCount() {
48
            return 2;
49
        }
50

  
51
        @Override
52
        public String getColumnProperty(int columnIndex) {
53
            if(columnIndex==0){
54
                return input.getName();
55
            }else if(columnIndex==1){
56
                return BulkEditorE4.TYPE_PROPERTY;
57
            }
58
            return null;
59
        }
60

  
61
        @Override
62
        public int getColumnIndex(String propertyName) {
63
            if(propertyName.equals(input.getName())){
64
                return 0;
65
            }
66
            else if(propertyName.equals(BulkEditorE4.TYPE_PROPERTY)){
67
                return 1;
68
            }
69
            return 0;
70
        }
71
    }

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)