Project

General

Profile

« Previous | Next » 

Revision 91d72a14

Added by Katja Luther over 2 years ago

ref #9816: disable field for more than one description element

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CellEditorDataConversionConfiguration.java
11 11

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

  
15 16
import org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration;
16 17
import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;
18
import org.eclipse.nebula.widgets.nattable.config.EditableRule;
17 19
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
18 20
import org.eclipse.nebula.widgets.nattable.config.IEditableRule;
21
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
19 22
import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes;
20 23
import org.eclipse.nebula.widgets.nattable.edit.gui.ICellEditDialog;
21 24
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
......
76 79
        //make cell editable
77 80
        configRegistry.registerConfigAttribute(
78 81
                EditConfigAttributes.CELL_EDITABLE_RULE,
79
                IEditableRule.ALWAYS_EDITABLE,
82
                getEditRule(matrix.getBodyDataProvider()),
83
//                IEditableRule.ALWAYS_EDITABLE,
80 84
                DisplayMode.EDIT,
81 85
                CharacterMatrixConfigLabelAccumulator.CATEGORICAL_EDITABLE
82 86
                );
......
101 105
        //make cell editable
102 106
        configRegistry.registerConfigAttribute(
103 107
                EditConfigAttributes.CELL_EDITABLE_RULE,
104
                IEditableRule.ALWAYS_EDITABLE,
108
                getEditRule(matrix.getBodyDataProvider()),
109
//                IEditableRule.ALWAYS_EDITABLE,
105 110
                DisplayMode.EDIT,
106 111
                CharacterMatrixConfigLabelAccumulator.QUANTITATIVE_EDITABLE
107 112
                );
......
117 122
                DisplayMode.NORMAL,
118 123
                CharacterMatrixConfigLabelAccumulator.QUANTITATIVE);
119 124

  
125
        
126
        
120 127
        //Open cell editor in dialog
121 128
        configRegistry.registerConfigAttribute(
122 129
                EditConfigAttributes.OPEN_IN_DIALOG,
......
148 155
                DisplayMode.EDIT,
149 156
                CharacterMatrixConfigLabelAccumulator.QUANTITATIVE_EDITABLE);
150 157
    }
158
   
159
    
160
    private static IEditableRule getEditRule(final IDataProvider dataProvider) {
161
    			return new EditableRule(){
162
    			public boolean isEditable(int columnIndex, int rowIndex) {
163
    				Object dataValue = dataProvider.getDataValue(columnIndex, rowIndex);
164
    				if (dataValue instanceof Set && ((Set)dataValue).size()>1){
165
    					return false;
166
    				}else return true;
167
    				}
168
    			};
169
    		}
151 170

  
152 171
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java
673 673
    }
674 674

  
675 675
    public void loadDescriptions(boolean isInitialExpandToDeepestTaxonLevel, boolean initialLoading) {
676
    	
676 677
        UUID monitorUuid =  CdmApplicationState.getLongRunningTasksService().monitGetRowWrapper(this.getDescriptiveDataSet().getUuid());
677 678

  
678 679
        final Collection<RowWrapperDTO<?>> wrappers = new ArrayList<>();
......
723 724
                                );
724 725
                    }
725 726
                    descriptions.clear();
727
//                    part.setDescriptiveDataSet(CdmStore.getService(IDescriptiveDataSetService.class).getDescriptiveDataSetDtoByUuid(part.getDescriptiveDataSet().getUuid()));
726 728
                    wrappers.stream().filter(row->row.getTaxonNode()!=null).forEach(wrapper->CharacterMatrix.this.descriptions.add(wrapper));
727 729
                    if(initialLoading){
728 730
                        loadingDone(isInitialExpandToDeepestTaxonLevel);
......
1007 1009
    @Override
1008 1010
    public void dispose () {
1009 1011
        super.dispose();
1010
        descriptions.dispose();
1012
        if (descriptions != null){
1013
        	descriptions.dispose();
1014
        }
1011 1015
        descriptions = null;
1012 1016
        this.natTable.dispose();
1013 1017
        this.natTable = null;
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrixConfigLabelAccumulator.java
37 37
    public static final String CATEGORICAL = "CATEGORICAL";
38 38
    public static final String CATEGORICAL_EDITABLE = CATEGORICAL+"_EDITABLE";
39 39
    public static final String QUANTITATIVE_EDITABLE = QUANTITATIVE+"_EDITABLE";
40
    public static final String NOT_EDITABLE = "NOT_EDITABLE";
40 41

  
41 42
    private CharacterMatrix matrix;
42 43

  
......
117 118
                        configLabels.addLabel(DEFAULT_OVERRIDDEN);
118 119
                    }
119 120
                }
121
                if (hasMoreThanOneValue(feature, specimenRowWrapper)){
122
                	isEditable = false;
123
                }
120 124
            }
121 125

  
122 126
            if(feature.isSupportsCategoricalData()){
123 127
                configLabels.addLabel(CATEGORICAL);
124 128
                if(isEditable){
125 129
                    configLabels.addLabel(CATEGORICAL_EDITABLE);
130
                }else{
131
                	configLabels.addLabel(NOT_EDITABLE);
126 132
                }
127 133
            }
128 134
            else if(feature.isSupportsQuantitativeData()){
129 135
                configLabels.addLabel(QUANTITATIVE);
130 136
                if(isEditable){
131 137
                    configLabels.addLabel(QUANTITATIVE_EDITABLE);
138
                }else{
139
                	configLabels.addLabel(NOT_EDITABLE);
132 140
                }
133 141
            }
134 142
        }
135 143
    }
136 144

  
137 145
    private boolean hasDefaultOverriddenValue(FeatureDto feature, RowWrapperDTO<?> rowWrapper) {
138
        DescriptionElementDto dataValueForFeature = rowWrapper.getDataValueForFeature(feature.getUuid());
146
        Set<DescriptionElementDto> dataValueForFeature = rowWrapper.getDataValueForFeature(feature.getUuid());
139 147
        if(dataValueForFeature!=null){
140
            if(dataValueForFeature instanceof CategoricalDataDto){
141
                return !((CategoricalDataDto) dataValueForFeature).getStates().isEmpty();
142
            }
143
            else if(dataValueForFeature instanceof QuantitativeDataDto){
144
                return !((QuantitativeDataDto) dataValueForFeature).getValues().isEmpty();
145
            }
148
        	for (DescriptionElementDto dto:dataValueForFeature){
149
	            if(dto instanceof CategoricalDataDto && !((CategoricalDataDto) dto).getStates().isEmpty()){
150
	                return true;
151
	            }
152
	            else if(dto instanceof QuantitativeDataDto && !((QuantitativeDataDto) dto).getValues().isEmpty()){
153
	                return true;
154
	            }
155
        	}
146 156
        }
147 157
        return false;
148 158
    }
......
167 177
        }
168 178
        return false;
169 179
    }
180
    private boolean hasMoreThanOneValue(FeatureDto feature, RowWrapperDTO<?> rowWrapperDTO) {
181
        if(rowWrapperDTO instanceof SpecimenRowWrapperDTO){
182
            Set<DescriptionElementDto> elements = ((SpecimenRowWrapperDTO)rowWrapperDTO).getDataValueForFeature(feature.getUuid());
183
            return elements != null && elements.size()>1;
184
        }
185
        
186
        return false;
187
    }
188

  
170 189

  
171 190
    private boolean hasDefaultValue(FeatureDto feature, DescriptionBaseDto defaultDescription) {
172 191
        if(defaultDescription!=null){
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrixLabelStyleConfiguration.java
69 69
                hasDefaultValueStyle,
70 70
                DisplayMode.NORMAL,
71 71
                CharacterMatrixConfigLabelAccumulator.HAS_DEFAULT);
72
        
73
        Style notEditableValueStyle = new Style();
74
        notEditableValueStyle.setAttributeValue(
75
                CellStyleAttributes.BACKGROUND_COLOR,
76
                GUIHelper.COLOR_GRAY);
77
        configRegistry.registerConfigAttribute(
78
                CellConfigAttributes.CELL_STYLE,
79
                notEditableValueStyle,
80
                DisplayMode.NORMAL,
81
                CharacterMatrixConfigLabelAccumulator.NOT_EDITABLE);
72 82

  
73 83
        Style defaultOverriddenStyle = new Style();
74 84
        defaultOverriddenStyle.setAttributeValue(
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrixPart.java
14 14
import java.util.HashMap;
15 15
import java.util.List;
16 16
import java.util.Map;
17
import java.util.Properties;
17 18
import java.util.Set;
18 19
import java.util.UUID;
19 20
import java.util.stream.Collectors;
......
167 168
            matrix.createTable(treeView, true, true);
168 169
            thisPart.setLabel(descriptiveDataSet.getTitleCache());
169 170
            matrix.loadDescriptions( true, true);
171
           
170 172
        }
171 173
    }
172 174

  
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/ElementEditableRule.java
1
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix;
2

  
3
import java.util.Set;
4

  
5
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
6
import org.eclipse.nebula.widgets.nattable.config.IEditableRule;
7
import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
8

  
9
public class ElementEditableRule implements IEditableRule {
10

  
11
	@Override
12
	public boolean isEditable(ILayerCell cell, IConfigRegistry configRegistry) {
13
		if (cell.getDataValue() instanceof Set){
14
			if(((Set)cell.getDataValue()).size() > 1)
15
				return false;
16
		}
17
		return true;
18
	}
19

  
20
	@Override
21
	public boolean isEditable(int columnIndex, int rowIndex) {
22
		
23
		// TODO Auto-generated method stub
24
		return false;
25
	}
26

  
27
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/categorical/CategoricalDataCellEditor.java
8 8
*/
9 9
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.categorical;
10 10

  
11
import java.util.Set;
12

  
11 13
import org.eclipse.nebula.widgets.nattable.edit.editor.ComboBoxCellEditor;
12 14
import org.eclipse.nebula.widgets.nattable.widget.NatCombo;
13 15
import org.eclipse.swt.events.SelectionEvent;
......
15 17
import org.eclipse.swt.widgets.Composite;
16 18
import org.eclipse.swt.widgets.Control;
17 19

  
20
import eu.etaxonomy.cdm.api.service.dto.DescriptionElementDto;
18 21
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
19 22
import eu.etaxonomy.cdm.persistence.dto.FeatureDto;
20 23
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrix;
......
35 38
        setUseCheckbox(true);
36 39
        setMultiselect(true);
37 40
        setShowDropdownFilter(true);
41
//        Object rowWrapper = matrix.getBodyDataProvider().getRowObject(this.getRowIndex());
42
//        if(rowWrapper instanceof RowWrapperDTO){
43
//        	FeatureDto feature = matrix.getIndexToFeatureMap().get(getColumnIndex());
44
//        	Set<DescriptionElementDto> elements = ((RowWrapperDTO)rowWrapper).getDataValueForFeature(feature.getUuid());
45
//        	if (elements != null && elements.size() >1){
46
//        		this.getEditorControl().setEnabled(false);
47
//        	}
48
//        }
38 49
    }
39 50

  
40 51
    @Override
......
45 56
                FeatureDto feature = matrix.getIndexToFeatureMap().get(getColumnIndex());
46 57
                // FIXME avoid creating empty CategoricalData
47 58
//                ((RowWrapperDTO) rowWrapper).addCategoricalData(feature);
59
                
48 60
            }
61
            
49 62
        }
63
        
50 64
        super.setCanonicalValue(canonicalValue);
51 65
    }
52 66

  
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialogEditor.java
9 9
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative;
10 10

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

  
13 14
import org.eclipse.jface.window.Window;
14 15
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
......
96 97
        QuantitativeDataDto quantitativeData = null;
97 98
        if(rowObject instanceof RowWrapperDTO){
98 99
            rowWrapperDTO = (RowWrapperDTO<?>) rowObject;
99
            DescriptionElementDto dataValueForFeature = rowWrapperDTO.getDataValueForFeature(feature.getUuid());
100
            Set<DescriptionElementDto> dataValueForFeature = rowWrapperDTO.getDataValueForFeature(feature.getUuid());
101
            if (dataValueForFeature.size() > 1){
102
            	return null;
103
            }
100 104
            if(dataValueForFeature instanceof QuantitativeDataDto){
101 105
                quantitativeData = (QuantitativeDataDto) dataValueForFeature;
102 106
            }

Also available in: Unified diff