Revision 952ef0ec
Added by Katja Luther over 5 years ago
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 |
|
|
32 |
public DistributionColumnAccessor(DistributionEditor editor) { |
|
33 |
this.editor = editor; |
|
34 |
} |
|
35 |
|
|
36 |
|
|
37 |
/** |
|
38 |
* {@inheritDoc} |
|
39 |
*/ |
|
40 |
@Override |
|
41 |
public Object getDataValue(TaxonDistributionDTO rowObject, int columnIndex) { |
|
42 |
switch (columnIndex) { |
|
43 |
case 0: |
|
44 |
return rowObject.getNameCache(); |
|
45 |
case 1: |
|
46 |
if (editor.isShowRank()){ |
|
47 |
return rowObject.getRankString(); |
|
48 |
}else{ |
|
49 |
break; |
|
50 |
} |
|
51 |
default: |
|
52 |
break; |
|
53 |
} |
|
54 |
NamedArea area = editor.getAreaToColumnIndexMap().get(columnIndex); |
|
55 |
return rowObject.getDistributionMap().get(area); |
|
56 |
|
|
57 |
|
|
58 |
} |
|
59 |
|
|
60 |
|
|
61 |
/** |
|
62 |
* {@inheritDoc} |
|
63 |
*/ |
|
64 |
@Override |
|
65 |
public int getColumnCount() { |
|
66 |
return editor.getPropertyToLabelMap().size(); |
|
67 |
} |
|
68 |
|
|
69 |
/** |
|
70 |
* {@inheritDoc} |
|
71 |
*/ |
|
72 |
@Override |
|
73 |
public String getColumnProperty(int columnIndex) { |
|
74 |
return editor.getPropertyToLabelMap().get(columnIndex); |
|
75 |
} |
|
76 |
|
|
77 |
/** |
|
78 |
* {@inheritDoc} |
|
79 |
*/ |
|
80 |
@Override |
|
81 |
public int getColumnIndex(String propertyName){ |
|
82 |
return editor.getPropertyToLabelMap().indexOf(propertyName); |
|
83 |
} |
|
84 |
|
|
85 |
|
|
86 |
/** |
|
87 |
* {@inheritDoc} |
|
88 |
*/ |
|
89 |
@Override |
|
90 |
public void setDataValue(TaxonDistributionDTO taxonWrapper, int columnIndex, Object newValue) { |
|
91 |
if (newValue instanceof PresenceAbsenceTerm){ |
|
92 |
NamedArea area =editor.getAreaToColumnIndexMap().get(columnIndex); |
|
93 |
Set<DescriptionElementBase> distributions = taxonWrapper.getDistributionMap().get(area); |
|
94 |
if (distributions != null && !distributions.isEmpty()){ |
|
95 |
DescriptionElementBase desc = distributions.iterator().next(); |
|
96 |
if (desc instanceof Distribution){ |
|
97 |
((Distribution)desc).setStatus((PresenceAbsenceTerm)newValue); |
|
98 |
} |
|
99 |
}else{ |
|
100 |
if (distributions == null){ |
|
101 |
distributions = new HashSet(); |
|
102 |
} |
|
103 |
Distribution dist = Distribution.NewInstance(area, (PresenceAbsenceTerm)newValue); |
|
104 |
Set<TaxonDescription> descs = taxonWrapper.getDescriptionsWrapper().getDescriptions(); |
|
105 |
TaxonDescription desc; |
|
106 |
if (descs.size() >= 1){ |
|
107 |
desc = descs.iterator().next(); |
|
108 |
}else { |
|
109 |
desc = TaxonDescription.NewInstance(); |
|
110 |
} |
|
111 |
desc.addElement(dist); |
|
112 |
distributions.add(dist); |
|
113 |
} |
|
114 |
|
|
115 |
} |
|
116 |
|
|
117 |
} |
|
118 |
|
|
119 |
} |
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.Collection; |
|
13 |
import java.util.HashMap; |
|
14 |
import java.util.HashSet; |
|
15 |
import java.util.List; |
|
16 |
import java.util.Map; |
|
17 |
|
|
18 |
import javax.inject.Inject; |
|
19 |
|
|
20 |
import org.apache.commons.collections4.map.LinkedMap; |
|
21 |
import org.apache.log4j.Logger; |
|
22 |
import org.eclipse.e4.ui.services.EMenuService; |
|
23 |
import org.eclipse.jface.layout.GridDataFactory; |
|
24 |
import org.eclipse.jface.wizard.WizardDialog; |
|
25 |
import org.eclipse.nebula.widgets.nattable.NatTable; |
|
26 |
import org.eclipse.nebula.widgets.nattable.config.AbstractUiBindingConfiguration; |
|
27 |
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry; |
|
28 |
import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration; |
|
29 |
import org.eclipse.nebula.widgets.nattable.data.IDataProvider; |
|
30 |
import org.eclipse.nebula.widgets.nattable.data.IRowDataProvider; |
|
31 |
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider; |
|
32 |
import org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler; |
|
33 |
import org.eclipse.nebula.widgets.nattable.extension.e4.selection.E4SelectionListener; |
|
34 |
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer; |
|
35 |
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsSortModel; |
|
36 |
import org.eclipse.nebula.widgets.nattable.freeze.CompositeFreezeLayer; |
|
37 |
import org.eclipse.nebula.widgets.nattable.freeze.FreezeLayer; |
|
38 |
import org.eclipse.nebula.widgets.nattable.grid.GridRegion; |
|
39 |
import org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand; |
|
40 |
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider; |
|
41 |
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider; |
|
42 |
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider; |
|
43 |
import org.eclipse.nebula.widgets.nattable.grid.data.FixedSummaryRowHeaderLayer; |
|
44 |
import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer; |
|
45 |
import org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer; |
|
46 |
import org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer; |
|
47 |
import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer; |
|
48 |
import org.eclipse.nebula.widgets.nattable.layer.AbstractLayer; |
|
49 |
import org.eclipse.nebula.widgets.nattable.layer.CompositeLayer; |
|
50 |
import org.eclipse.nebula.widgets.nattable.layer.DataLayer; |
|
51 |
import org.eclipse.nebula.widgets.nattable.layer.ILayer; |
|
52 |
import org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator; |
|
53 |
import org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack; |
|
54 |
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer; |
|
55 |
import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer; |
|
56 |
import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration; |
|
57 |
import org.eclipse.nebula.widgets.nattable.style.HorizontalAlignmentEnum; |
|
58 |
import org.eclipse.nebula.widgets.nattable.style.theme.ModernNatTableThemeConfiguration; |
|
59 |
import org.eclipse.nebula.widgets.nattable.summaryrow.FixedSummaryRowLayer; |
|
60 |
import org.eclipse.nebula.widgets.nattable.summaryrow.SummaryRowLayer; |
|
61 |
import org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry; |
|
62 |
import org.eclipse.nebula.widgets.nattable.ui.matcher.MouseEventMatcher; |
|
63 |
import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuAction; |
|
64 |
import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder; |
|
65 |
import org.eclipse.nebula.widgets.nattable.util.GUIHelper; |
|
66 |
import org.eclipse.swt.SWT; |
|
67 |
import org.eclipse.swt.events.SelectionAdapter; |
|
68 |
import org.eclipse.swt.events.SelectionEvent; |
|
69 |
import org.eclipse.swt.layout.GridData; |
|
70 |
import org.eclipse.swt.layout.GridLayout; |
|
71 |
import org.eclipse.swt.widgets.Button; |
|
72 |
import org.eclipse.swt.widgets.Composite; |
|
73 |
import org.eclipse.swt.widgets.Label; |
|
74 |
import org.eclipse.swt.widgets.Menu; |
|
75 |
import org.eclipse.swt.widgets.Text; |
|
76 |
|
|
77 |
import ca.odell.glazedlists.EventList; |
|
78 |
import ca.odell.glazedlists.SortedList; |
|
79 |
import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO; |
|
80 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
|
81 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
|
82 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
83 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
|
84 |
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrixLabelStyleConfiguration; |
|
85 |
import eu.etaxonomy.taxeditor.editor.l10n.Messages; |
|
86 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
|
87 |
import eu.etaxonomy.taxeditor.preference.Resources; |
|
88 |
import eu.etaxonomy.taxeditor.preference.wizard.AvailableDistributionWizard; |
|
89 |
import eu.etaxonomy.taxeditor.store.StoreUtil; |
|
90 |
import eu.etaxonomy.taxeditor.ui.dialog.selection.ReferenceSelectionDialog; |
|
91 |
|
|
92 |
/** |
|
93 |
* @author k.luther |
|
94 |
* @since 27.11.2018 |
|
95 |
* |
|
96 |
*/ |
|
97 |
public class DistributionEditor extends Composite { |
|
98 |
|
|
99 |
|
|
100 |
private static final String DISTRIBUTION_EDITOR = "Distribution Editor"; |
|
101 |
private static final String LOADING_TAXA = Messages.ChecklistEditor_LOAD_TAXA; |
|
102 |
private static final String UNKNOWN = Messages.ChecklistEditor_UNKNOWN; |
|
103 |
private static final String ELEMENT_COUNT = Messages.ChecklistEditor_ELEMENT_COUNT; |
|
104 |
public static final String TYPE_FILTER_TEXT = "type filter text"; //$NON-NLS-1$ |
|
105 |
|
|
106 |
static final String TAXON_COLUMN = "taxon_column"; //$NON-NLS-1$ |
|
107 |
static final String RANK_COLUMN = "collector_column"; //$NON-NLS-1$ |
|
108 |
|
|
109 |
private static final Logger logger = Logger.getLogger(DistributionEditor.class); |
|
110 |
@Inject |
|
111 |
private EMenuService menuService; |
|
112 |
private NatTable natTable; |
|
113 |
private Label statusLabel; |
|
114 |
private Label statusLabelSourceReference; |
|
115 |
private Reference defaultSource; |
|
116 |
|
|
117 |
private Map<Integer, NamedArea> areaToColumnIndexMap= new HashMap(); |
|
118 |
private int firstDataColumnIndex; |
|
119 |
|
|
120 |
private ListDataProvider<TaxonDistributionDTO> bodyDataProvider; |
|
121 |
private LinkedMap<String, String> propertyToLabelMap = new LinkedMap<>(); |
|
122 |
|
|
123 |
private boolean isShowRank; |
|
124 |
private Integer countNodes; |
|
125 |
private Text searchText; |
|
126 |
|
|
127 |
EventList<TaxonDistributionDTO> taxonList; |
|
128 |
List<NamedArea> areas = new ArrayList(); |
|
129 |
DistributionEditorPart part; |
|
130 |
private DefaultBodyLayerStack bodyLayer; |
|
131 |
private FreezeLayer freezeLayer; |
|
132 |
private ConfigRegistry configRegistry; |
|
133 |
private AbstractLayer topMostLayer; |
|
134 |
|
|
135 |
private FixedSummaryRowLayer summaryRowLayer; |
|
136 |
|
|
137 |
|
|
138 |
/** |
|
139 |
* @param parent |
|
140 |
* @param style |
|
141 |
*/ |
|
142 |
public DistributionEditor(Composite parent, DistributionEditorPart part) { |
|
143 |
super(parent, SWT.NULL); |
|
144 |
this.setLayout(new GridLayout()); |
|
145 |
this.part = part; |
|
146 |
createTopComposite(parent); |
|
147 |
|
|
148 |
natTable = new NatTable(this, false); |
|
149 |
|
|
150 |
createStatusBar(parent); |
|
151 |
} |
|
152 |
|
|
153 |
public boolean isShowRank() { |
|
154 |
return isShowRank; |
|
155 |
} |
|
156 |
|
|
157 |
public void setShowRank(boolean isShowRank) { |
|
158 |
this.isShowRank = isShowRank; |
|
159 |
} |
|
160 |
|
|
161 |
public int getFirstDataColumnIndex() { |
|
162 |
return firstDataColumnIndex; |
|
163 |
} |
|
164 |
|
|
165 |
public void setFirstDataColumnIndex(int firstDataColumnIndex) { |
|
166 |
this.firstDataColumnIndex = firstDataColumnIndex; |
|
167 |
} |
|
168 |
|
|
169 |
public LinkedMap<String, String> getPropertyToLabelMap() { |
|
170 |
return propertyToLabelMap; |
|
171 |
} |
|
172 |
|
|
173 |
public void setPropertyToLabelMap(LinkedMap<String, String> propertyToLabelMap) { |
|
174 |
this.propertyToLabelMap = propertyToLabelMap; |
|
175 |
} |
|
176 |
|
|
177 |
public Map<Integer, NamedArea> getAreaToColumnIndexMap() { |
|
178 |
return areaToColumnIndexMap; |
|
179 |
} |
|
180 |
|
|
181 |
|
|
182 |
public void setAreaToColumnIndexMap(Map<Integer, NamedArea> areaToColumnIndexMap) { |
|
183 |
this.areaToColumnIndexMap = areaToColumnIndexMap; |
|
184 |
} |
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
private void createStatusBar(Composite composite) { |
|
189 |
GridData gridData = new GridData(); |
|
190 |
gridData.horizontalSpan = 1; |
|
191 |
gridData.grabExcessHorizontalSpace = true; |
|
192 |
gridData.horizontalAlignment = GridData.FILL; |
|
193 |
|
|
194 |
statusLabel = new Label(composite, SWT.LEFT); |
|
195 |
statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN)); |
|
196 |
statusLabel.setLayoutData(gridData); |
|
197 |
|
|
198 |
statusLabelSourceReference = new Label(composite, SWT.RIGHT); |
|
199 |
// GridData sourceGrid = new GridData(); |
|
200 |
// sourceGrid.horizontalAlignment = GridData.HORIZONTAL_ALIGN_END; |
|
201 |
// //sourceGrid.grabExcessHorizontalSpace = false; |
|
202 |
// sourceGrid.horizontalSpan = 1; |
|
203 |
statusLabelSourceReference.setLayoutData(gridData); |
|
204 |
|
|
205 |
if (defaultSource != null){ |
|
206 |
statusLabelSourceReference.setText("Default Source Reference: " + defaultSource.getAbbrevTitle() != null? defaultSource.getAbbrevTitle() : defaultSource.getAbbrevTitleCache()); |
|
207 |
|
|
208 |
} |
|
209 |
} |
|
210 |
|
|
211 |
private void applyStyles(){ |
|
212 |
ModernNatTableThemeConfiguration configuration = new ModernNatTableThemeConfiguration(); |
|
213 |
configuration.summaryRowHAlign = HorizontalAlignmentEnum.CENTER; |
|
214 |
// NOTE: Getting the colors and fonts from the GUIHelper ensures that |
|
215 |
// they are disposed properly (required by SWT) |
|
216 |
configuration.cHeaderBgColor = GUIHelper.getColor(211, 211, 211); |
|
217 |
configuration.rHeaderBgColor = GUIHelper.getColor(211, 211, 211); |
|
218 |
natTable.addConfiguration(configuration); |
|
219 |
|
|
220 |
} |
|
221 |
|
|
222 |
private void configureNatTable(ConfigRegistry configRegistry, |
|
223 |
AbstractLayer topMostLayer) { |
|
224 |
/** |
|
225 |
* CONFIGURATION |
|
226 |
*/ |
|
227 |
natTable.setConfigRegistry(configRegistry); |
|
228 |
|
|
229 |
applyStyles(); |
|
230 |
|
|
231 |
//add default configuration because autoconfigure is set to false in constructor |
|
232 |
natTable.addConfiguration(new DefaultNatTableStyleConfiguration()); |
|
233 |
|
|
234 |
//FIXME: this is for DEBUG ONLY |
|
235 |
// natTable.addConfiguration(new DebugMenuConfiguration(natTable)); |
|
236 |
|
|
237 |
// override the default sort configuration and change the mouse bindings |
|
238 |
// to sort on a single click |
|
239 |
|
|
240 |
natTable.addConfiguration(new SingleClickSortConfiguration()); |
|
241 |
natTable.addConfiguration(new CharacterMatrixLabelStyleConfiguration()); |
|
242 |
|
|
243 |
// add the header menu configuration for adding the column header menu |
|
244 |
// with hide/show actions |
|
245 |
natTable.addConfiguration(new DistributionEditorHeaderMenuConfiguration(natTable)); |
|
246 |
|
|
247 |
// add custom configuration for data conversion and add column labels to viewport layer |
|
248 |
// topMostLayer.addConfiguration(new CellEditorDataConversionConfiguration(this)); |
|
249 |
|
|
250 |
// //register aggregation configuration |
|
251 |
// summaryRowLayer.addConfiguration(new AggregationConfiguration(this)); |
|
252 |
|
|
253 |
//+++CONTEXT MENU+++ |
|
254 |
menuService.registerContextMenu(natTable, "eu.etaxonomy.taxeditor.editor.popupmenu.charactermatrix"); //$NON-NLS-1$ |
|
255 |
// get the menu registered by EMenuService |
|
256 |
final Menu e4Menu = natTable.getMenu(); |
|
257 |
// remove the menu reference from NatTable instance |
|
258 |
natTable.setMenu(null); |
|
259 |
natTable.addConfiguration( |
|
260 |
new AbstractUiBindingConfiguration() { |
|
261 |
@Override |
|
262 |
public void configureUiBindings( |
|
263 |
UiBindingRegistry uiBindingRegistry) { |
|
264 |
// add e4 menu to NatTable |
|
265 |
new PopupMenuBuilder(natTable, e4Menu) |
|
266 |
.build(); |
|
267 |
|
|
268 |
// register the UI binding for header, corner and body region |
|
269 |
uiBindingRegistry.registerMouseDownBinding( |
|
270 |
new MouseEventMatcher( |
|
271 |
SWT.NONE, |
|
272 |
null, |
|
273 |
MouseEventMatcher.RIGHT_BUTTON), |
|
274 |
new PopupMenuAction(e4Menu)); |
|
275 |
} |
|
276 |
}); |
|
277 |
|
|
278 |
natTable.configure(); |
|
279 |
} |
|
280 |
|
|
281 |
public void createTable(boolean freezeSupplementalColumns){ |
|
282 |
/** |
|
283 |
* layers |
|
284 |
*/ |
|
285 |
createLayers(); |
|
286 |
|
|
287 |
/** |
|
288 |
* configuration |
|
289 |
*/ |
|
290 |
configureNatTable( configRegistry, topMostLayer); |
|
291 |
|
|
292 |
/** |
|
293 |
* handlers and listeners |
|
294 |
*/ |
|
295 |
registerHandlersAndListeners(topMostLayer); |
|
296 |
|
|
297 |
//grab all space |
|
298 |
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable); |
|
299 |
|
|
300 |
//update label to current data set |
|
301 |
// toolbar.getWsLabel().setText(descriptiveDataSet.getLabel()); |
|
302 |
// toolbar.getWsLabel().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
|
303 |
// toolbar.getWsLabel().getParent().layout(); |
|
304 |
|
|
305 |
//initial freeze of supplemental columns |
|
306 |
// freezeSupplementalColumns(freezeSupplementalColumns); |
|
307 |
|
|
308 |
|
|
309 |
this.layout(); |
|
310 |
natTable.doCommand(new ClientAreaResizeCommand(natTable)); |
|
311 |
} |
|
312 |
|
|
313 |
|
|
314 |
private void createLayers() { |
|
315 |
|
|
316 |
SortedList sortedList = new SortedList(taxonList, new TaxonDistributionDtoComparator()); |
|
317 |
|
|
318 |
|
|
319 |
/** |
|
320 |
* data provider |
|
321 |
*/ |
|
322 |
DistributionColumnAccessor columnPropertyAccessor = new DistributionColumnAccessor(this); |
|
323 |
bodyDataProvider = new ListDataProvider(sortedList, columnPropertyAccessor); |
|
324 |
|
|
325 |
propertyToLabelMap.put(TAXON_COLUMN, Messages.CharacterMatrix_TAXON); |
|
326 |
if (isShowRank){ |
|
327 |
propertyToLabelMap.put(RANK_COLUMN, Messages.CharacterMatrix_COLLECTOR_NO); |
|
328 |
} |
|
329 |
configRegistry = new ConfigRegistry(); |
|
330 |
|
|
331 |
|
|
332 |
/** |
|
333 |
* BODY layer |
|
334 |
* |
|
335 |
* |
|
336 |
|
|
337 |
CompositeLayer |
|
338 |
- (top) SummaryRowLayer |
|
339 |
- (bottom) ViewportLayer |
|
340 |
|
|
341 |
^ |
|
342 |
ViewportLayer |
|
343 |
|
|
344 |
^ |
|
345 |
TreeLayer (default visible) |
|
346 |
|
|
347 |
^ |
|
348 |
CompositeFreezeLayer |
|
349 |
- viewportLayer |
|
350 |
- selectionLayer |
|
351 |
- freezeLayer |
|
352 |
|
|
353 |
^ |
|
354 |
FreezeLayer |
|
355 |
|
|
356 |
^ |
|
357 |
SelectionLayer |
|
358 |
|
|
359 |
^ |
|
360 |
ColumnHideShowLayer |
|
361 |
|
|
362 |
^ |
|
363 |
ColumnReorderLayer |
|
364 |
|
|
365 |
^ |
|
366 |
DataLayer |
|
367 |
|
|
368 |
* |
|
369 |
|
|
370 |
*/ |
|
371 |
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider); |
|
372 |
|
|
373 |
//register labels |
|
374 |
// CharacterMatrixConfigLabelAccumulator labelAccumulator = new CharacterMatrixConfigLabelAccumulator(this); |
|
375 |
// bodyDataLayer.setConfigLabelAccumulator(labelAccumulator); |
|
376 |
|
|
377 |
|
|
378 |
propertyToLabelMap.put(TAXON_COLUMN, Messages.CharacterMatrix_TAXON); |
|
379 |
initLabels(); |
|
380 |
|
|
381 |
|
|
382 |
// layer for event handling of GlazedLists and PropertyChanges |
|
383 |
GlazedListsEventLayer eventLayer = new GlazedListsEventLayer<>(bodyDataLayer, taxonList); |
|
384 |
|
|
385 |
|
|
386 |
|
|
387 |
bodyLayer = new DefaultBodyLayerStack(eventLayer); |
|
388 |
final SelectionLayer selectionLayer = bodyLayer.getSelectionLayer(); |
|
389 |
freezeLayer = new FreezeLayer(selectionLayer); |
|
390 |
final CompositeFreezeLayer compositeFreezeLayer = new CompositeFreezeLayer( |
|
391 |
freezeLayer, bodyLayer.getViewportLayer(), selectionLayer); |
|
392 |
|
|
393 |
|
|
394 |
topMostLayer = compositeFreezeLayer; |
|
395 |
|
|
396 |
summaryRowLayer = new FixedSummaryRowLayer(bodyDataLayer, topMostLayer, configRegistry, false); |
|
397 |
//register labels with summary prefix for summary layer |
|
398 |
ColumnOverrideLabelAccumulator summaryColumnLabelAccumulator =new ColumnOverrideLabelAccumulator(bodyDataLayer); |
|
399 |
summaryRowLayer.setConfigLabelAccumulator(summaryColumnLabelAccumulator); |
|
400 |
int n = 1; |
|
401 |
if (isShowRank){ |
|
402 |
n++; |
|
403 |
} |
|
404 |
for(int i=0;i<areas.size();i++){ |
|
405 |
NamedArea namedArea = areas.get(i); |
|
406 |
summaryColumnLabelAccumulator.registerColumnOverrides( |
|
407 |
i+n, |
|
408 |
SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX+namedArea.getLabel()); |
|
409 |
} |
|
410 |
// because the horizontal dependency is the ViewportLayer |
|
411 |
// we need to set the composite dependency to false |
|
412 |
summaryRowLayer.setHorizontalCompositeDependency(false); |
|
413 |
|
|
414 |
CompositeLayer composite = new CompositeLayer(1, 2); |
|
415 |
composite.setChildLayer("SUMMARY", summaryRowLayer, 0, 0); //$NON-NLS-1$ |
|
416 |
composite.setChildLayer(GridRegion.BODY, topMostLayer, 0, 1); |
|
417 |
|
|
418 |
|
|
419 |
/** |
|
420 |
* column header layer |
|
421 |
*/ |
|
422 |
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider( |
|
423 |
propertyToLabelMap.values().toArray(new String[] {}), propertyToLabelMap); |
|
424 |
DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider); |
|
425 |
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, topMostLayer, selectionLayer); |
|
426 |
|
|
427 |
// add the SortHeaderLayer to the column header layer stack |
|
428 |
// as we use GlazedLists, we use the GlazedListsSortModel which |
|
429 |
// delegates the sorting to the SortedList |
|
430 |
final SortHeaderLayer<TaxonDistributionDTO> sortHeaderLayer = new SortHeaderLayer<>( |
|
431 |
columnHeaderLayer, |
|
432 |
new GlazedListsSortModel<>(sortedList, |
|
433 |
columnPropertyAccessor, |
|
434 |
configRegistry, |
|
435 |
columnHeaderDataLayer)); |
|
436 |
|
|
437 |
|
|
438 |
/** |
|
439 |
* row header layer |
|
440 |
*/ |
|
441 |
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider); |
|
442 |
DefaultRowHeaderDataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider); |
|
443 |
FixedSummaryRowHeaderLayer fixedSummaryRowHeaderLayer = new FixedSummaryRowHeaderLayer(rowHeaderDataLayer, |
|
444 |
composite, selectionLayer); |
|
445 |
fixedSummaryRowHeaderLayer.setSummaryRowLabel("\u2211"); //$NON-NLS-1$ |
|
446 |
|
|
447 |
|
|
448 |
/** |
|
449 |
* corner layer |
|
450 |
*/ |
|
451 |
ILayer cornerLayer = new CornerLayer( |
|
452 |
new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)), |
|
453 |
fixedSummaryRowHeaderLayer, sortHeaderLayer); |
|
454 |
|
|
455 |
|
|
456 |
/** |
|
457 |
* GRID layer (composition of all other layers) |
|
458 |
*/ |
|
459 |
GridLayer gridLayer = new GridLayer(composite, sortHeaderLayer, null, cornerLayer); |
|
460 |
|
|
461 |
natTable.setLayer(gridLayer); |
|
462 |
|
|
463 |
} |
|
464 |
|
|
465 |
/** |
|
466 |
* @param parent |
|
467 |
* @return |
|
468 |
*/ |
|
469 |
private Text createSearchBar(Composite parent) { |
|
470 |
|
|
471 |
final Text searchText = new Text(parent, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH | SWT.CANCEL); |
|
472 |
GridData gridData = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL); |
|
473 |
|
|
474 |
searchText.setLayoutData(gridData); |
|
475 |
searchText.setForeground(EditorUtil.getColor(Resources.SEARCH_VIEW_FOREGROUND)); |
|
476 |
searchText.setText(TYPE_FILTER_TEXT); |
|
477 |
searchText.setToolTipText(Messages.ChecklistEditor_SEARCH_TOOLTIP); |
|
478 |
|
|
479 |
Button button1 = new Button(parent, SWT.PUSH ); |
|
480 |
GridData gridData2 = new GridData(); |
|
481 |
gridData2.horizontalSpan = 1; |
|
482 |
gridData2.horizontalAlignment = SWT.RIGHT; |
|
483 |
button1.setLayoutData(gridData2); |
|
484 |
|
|
485 |
|
|
486 |
button1.setText(Messages.ChecklistEditor_DIST_STATUS); |
|
487 |
button1.setToolTipText(Messages.ChecklistEditor_DIST_STATUS_TOOLTIP); |
|
488 |
button1.addSelectionListener(new SelectionAdapter() { |
|
489 |
@Override |
|
490 |
public void widgetSelected(SelectionEvent event) { |
|
491 |
AvailableDistributionWizard availableDistributionWizard = new AvailableDistributionWizard(); |
|
492 |
WizardDialog dialog = new WizardDialog(StoreUtil.getShell(), |
|
493 |
availableDistributionWizard); |
|
494 |
|
|
495 |
int open = dialog.open(); |
|
496 |
if(open == 0){ |
|
497 |
//TODO!!!! |
|
498 |
// reload(); |
|
499 |
} |
|
500 |
} |
|
501 |
}); |
|
502 |
|
|
503 |
Button button2 = new Button(parent, SWT.PUSH ); |
|
504 |
GridData gridData3 = new GridData(); |
|
505 |
gridData2.horizontalSpan = 1; |
|
506 |
button2.setLayoutData(gridData3); |
|
507 |
|
|
508 |
|
|
509 |
button2.setText(Messages.ChecklistEditor_DEFAULT_SOURCE); |
|
510 |
button2.setToolTipText(Messages.ChecklistEditor_DEFAULT_SOURCE_TOOLTIP); |
|
511 |
button2.addSelectionListener(new SelectionAdapter() { |
|
512 |
|
|
513 |
@Override |
|
514 |
public void widgetSelected(SelectionEvent event) { |
|
515 |
defaultSource = ReferenceSelectionDialog.select(AbstractUtility.getShell(), null); |
|
516 |
|
|
517 |
String defaultSourceStr = (defaultSource == null) ? "" : "Default Source Reference: " + defaultSource.getTitleCache(); |
|
518 |
if (defaultSourceStr.length()> 100){ |
|
519 |
defaultSourceStr = defaultSourceStr.substring(0, 98) + "..."; |
|
520 |
} |
|
521 |
statusLabelSourceReference.setText(defaultSourceStr); |
|
522 |
|
|
523 |
button2.setBackground(EditorUtil.getColor(Resources.COLOR_CONTROL_SELECTED)); |
|
524 |
} |
|
525 |
|
|
526 |
}); |
|
527 |
|
|
528 |
parent.pack(); |
|
529 |
return searchText; |
|
530 |
} |
|
531 |
|
|
532 |
/** |
|
533 |
* @param parent |
|
534 |
*/ |
|
535 |
private void createTopComposite(Composite parent) { |
|
536 |
GridLayout gridLayout = new GridLayout(3, false); |
|
537 |
gridLayout.marginWidth = 0; |
|
538 |
gridLayout.marginHeight = 0; |
|
539 |
parent.setLayout(gridLayout); |
|
540 |
|
|
541 |
searchText = createSearchBar(parent); |
|
542 |
|
|
543 |
|
|
544 |
} |
|
545 |
public void loadDistributions(List<TaxonDistributionDTO> taxonList) { |
|
546 |
this.taxonList.addAll(taxonList); |
|
547 |
|
|
548 |
} |
|
549 |
|
|
550 |
public Collection<DescriptionElementBase> getDistributions() { |
|
551 |
Collection<DescriptionElementBase> descElements = new HashSet(); |
|
552 |
//TODO: only for edited taxa |
|
553 |
taxonList.forEach(taxonDto->taxonDto.getDistributionMap() |
|
554 |
.forEach((area, descriptionElements)->descElements.addAll(descriptionElements))); |
|
555 |
|
|
556 |
|
|
557 |
return descElements; |
|
558 |
|
|
559 |
} |
|
560 |
|
|
561 |
private void initLabels() { |
|
562 |
|
|
563 |
int index = 1; |
|
564 |
if (isShowRank){ |
|
565 |
index++; |
|
566 |
} |
|
567 |
for (NamedArea area: areas) { |
|
568 |
this.areaToColumnIndexMap.put(index++, area); |
|
569 |
|
|
570 |
//TODO: adapt to preference |
|
571 |
String areaLabel = area.getLabel(); |
|
572 |
String property = areaLabel; |
|
573 |
propertyToLabelMap.put(property, areaLabel); |
|
574 |
} |
|
575 |
} |
|
576 |
|
|
577 |
|
|
578 |
private void registerHandlersAndListeners(AbstractLayer topMostLayer) { |
|
579 |
// add the ExportCommandHandler to the ViewportLayer in order to make |
|
580 |
// exporting work |
|
581 |
topMostLayer.registerCommandHandler(new ExportCommandHandler(topMostLayer)); |
|
582 |
|
|
583 |
//selection listener |
|
584 |
E4SelectionListener selectionListener = new DistributionCellSelectionListener(part.getSelectionService(), |
|
585 |
bodyLayer.getSelectionLayer(), bodyDataProvider, part); |
|
586 |
bodyLayer.getSelectionLayer().addLayerListener(selectionListener); |
|
587 |
selectionListener.setFullySelectedRowsOnly(false); |
|
588 |
|
|
589 |
//register handler for view configuration menu |
|
590 |
// natTable.registerCommandHandler(toolbar.getDisplayPersistenceDialogCommandHandler()); |
|
591 |
} |
|
592 |
|
|
593 |
/** |
|
594 |
* @return |
|
595 |
*/ |
|
596 |
public IRowDataProvider<TaxonDistributionDTO> getBodyDataProvider() { |
|
597 |
return bodyDataProvider; |
|
598 |
} |
|
599 |
|
|
600 |
|
|
601 |
} |
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.inject.Inject; |
|
19 |
|
|
20 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
21 |
import org.eclipse.e4.core.contexts.ContextInjectionFactory; |
|
22 |
import org.eclipse.e4.core.contexts.IEclipseContext; |
|
23 |
import org.eclipse.e4.ui.di.Persist; |
|
24 |
import org.eclipse.e4.ui.model.application.ui.MDirtyable; |
|
25 |
import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
|
26 |
import org.eclipse.e4.ui.workbench.modeling.ESelectionService; |
|
27 |
import org.eclipse.swt.SWT; |
|
28 |
import org.eclipse.swt.custom.StackLayout; |
|
29 |
import org.eclipse.swt.widgets.Composite; |
|
30 |
import org.eclipse.swt.widgets.Label; |
|
31 |
|
|
32 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
|
33 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; |
|
34 |
import eu.etaxonomy.cdm.api.service.IDescriptionService; |
|
35 |
import eu.etaxonomy.cdm.api.service.ITaxonNodeService; |
|
36 |
import eu.etaxonomy.cdm.api.service.UpdateResult; |
|
37 |
import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO; |
|
38 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
39 |
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; |
|
40 |
import eu.etaxonomy.taxeditor.editor.l10n.Messages; |
|
41 |
import eu.etaxonomy.taxeditor.model.IDirtyMarkable; |
|
42 |
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails; |
|
43 |
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData; |
|
44 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySession; |
|
45 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled; |
|
46 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
47 |
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart; |
|
48 |
|
|
49 |
/** |
|
50 |
* @author k.luther |
|
51 |
* @since 28.11.2018 |
|
52 |
* |
|
53 |
*/ |
|
54 |
public class DistributionEditorPart implements IE4SavablePart, IConversationEnabled, IDirtyMarkable, |
|
55 |
ICdmEntitySessionEnabled, IPartContentHasSupplementalData, IPartContentHasDetails{ |
|
56 |
|
|
57 |
private static final List<String> TAXONNODE_PROPERTY_PATH = Arrays.asList(new String[] { |
|
58 |
"taxon", //$NON-NLS-1$ |
|
59 |
"taxon.name", //$NON-NLS-1$ |
|
60 |
"taxon.name.rank",//$NON-NLS-1$ |
|
61 |
"taxon.descriptions", //$NON-NLS-1$ |
|
62 |
"taxon.descriptions.descriptionElements", //$NON-NLS-1$ |
|
63 |
"taxon.descriptions.descriptionElements.feature", //$NON-NLS-1$ |
|
64 |
"taxon.descriptions.descriptionElements.sources", //$NON-NLS-1$ |
|
65 |
"taxon.descriptions.descriptionElements.media" //$NON-NLS-1$ |
|
66 |
}); |
|
67 |
|
|
68 |
private List<TaxonDistributionDTO> taxonList; |
|
69 |
private Collection<UpdateResult> updateResults; |
|
70 |
|
|
71 |
private ConversationHolder conversation; |
|
72 |
|
|
73 |
private ICdmEntitySession cdmEntitySession; |
|
74 |
|
|
75 |
@Inject |
|
76 |
private ESelectionService selService; |
|
77 |
|
|
78 |
@Inject |
|
79 |
private MDirtyable dirty; |
|
80 |
|
|
81 |
@Inject |
|
82 |
private MPart thisPart; |
|
83 |
|
|
84 |
private DistributionEditor editor; |
|
85 |
|
|
86 |
private StackLayout stackLayout; |
|
87 |
|
|
88 |
@PostConstruct |
|
89 |
public void create(Composite parent, IEclipseContext context) { |
|
90 |
if(CdmStore.isActive() && conversation==null){ |
|
91 |
conversation = CdmStore.createConversation(); |
|
92 |
} |
|
93 |
if(cdmEntitySession == null){ |
|
94 |
cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true); |
|
95 |
} |
|
96 |
else{ |
|
97 |
return; |
|
98 |
} |
|
99 |
stackLayout = new StackLayout(); |
|
100 |
parent.setLayout(stackLayout); |
|
101 |
editor = new DistributionEditor(parent, this); |
|
102 |
Label label = new Label(parent, SWT.NONE); |
|
103 |
label.setText(Messages.CharacterMatrixPart_LOADING_MATRIX); |
|
104 |
stackLayout.topControl = label; |
|
105 |
ContextInjectionFactory.inject(editor, context); |
|
106 |
} |
|
107 |
|
|
108 |
public void init(UUID parentTaxonUuid) { |
|
109 |
this.taxonList = CdmStore.getService(ITaxonNodeService.class).getTaxonDistributionDTOForSubtree(parentTaxonUuid, TAXONNODE_PROPERTY_PATH); |
|
110 |
if(taxonList!=null){ |
|
111 |
editor.createTable( true); |
|
112 |
editor.loadDistributions(taxonList); |
|
113 |
} |
|
114 |
} |
|
115 |
public ESelectionService getSelectionService() { |
|
116 |
return selService; |
|
117 |
} |
|
118 |
|
|
119 |
|
|
120 |
public DistributionEditor getEditor() { |
|
121 |
return editor; |
|
122 |
} |
|
123 |
|
|
124 |
/** |
|
125 |
* {@inheritDoc} |
|
126 |
*/ |
|
127 |
@Override |
|
128 |
public void update(CdmDataChangeMap changeEvents) { |
|
129 |
// TODO Auto-generated method stub |
|
130 |
|
|
131 |
} |
|
132 |
|
|
133 |
/** |
|
134 |
* {@inheritDoc} |
|
135 |
*/ |
|
136 |
@Override |
|
137 |
public ICdmEntitySession getCdmEntitySession() { |
|
138 |
// TODO Auto-generated method stub |
|
139 |
return null; |
|
140 |
} |
|
141 |
|
|
142 |
/** |
|
143 |
* {@inheritDoc} |
|
144 |
*/ |
|
145 |
@Override |
|
146 |
public <T extends CdmBase> Collection<T> getRootEntities() { |
|
147 |
// TODO Auto-generated method stub |
|
148 |
return null; |
|
149 |
} |
|
150 |
|
|
151 |
/** |
|
152 |
* {@inheritDoc} |
|
153 |
*/ |
|
154 |
@Override |
|
155 |
public Map<Object, List<String>> getPropertyPathsMap() { |
|
156 |
// TODO Auto-generated method stub |
|
157 |
return null; |
|
158 |
} |
|
159 |
|
|
160 |
/** |
|
161 |
* {@inheritDoc} |
|
162 |
*/ |
|
163 |
@Override |
|
164 |
public void changed(Object element) { |
|
165 |
// TODO Auto-generated method stub |
|
166 |
|
|
167 |
} |
|
168 |
|
|
169 |
/** |
|
170 |
* {@inheritDoc} |
|
171 |
*/ |
|
172 |
@Override |
|
173 |
public void forceDirty() { |
|
174 |
// TODO Auto-generated method stub |
|
175 |
|
|
176 |
} |
|
177 |
|
|
178 |
/** |
|
179 |
* {@inheritDoc} |
|
180 |
*/ |
|
181 |
@Override |
|
182 |
public ConversationHolder getConversationHolder() { |
|
183 |
// TODO Auto-generated method stub |
|
184 |
return null; |
|
185 |
} |
|
186 |
|
|
187 |
@Persist |
|
188 |
@Override |
|
189 |
public void save(IProgressMonitor monitor) { |
|
190 |
//save distributions |
|
191 |
CdmStore.getService(IDescriptionService.class).saveDescriptionElement(editor.getDistributions()); |
|
192 |
|
|
193 |
conversation.commit(); |
|
194 |
updateResults = null; |
|
195 |
dirty.setDirty(false); |
|
196 |
} |
|
197 |
|
|
198 |
/** |
|
199 |
* {@inheritDoc} |
|
200 |
*/ |
|
201 |
@Override |
|
202 |
public boolean isDirty() { |
|
203 |
// TODO Auto-generated method stub |
|
204 |
return false; |
|
205 |
} |
|
206 |
|
|
207 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/TaxonDistributionDtoComparator.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 |
|
|
13 |
import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO; |
|
14 |
import eu.etaxonomy.cdm.model.name.Rank; |
|
15 |
|
|
16 |
/** |
|
17 |
* @author k.luther |
|
18 |
* @since 28.11.2018 |
|
19 |
* |
|
20 |
*/ |
|
21 |
public class TaxonDistributionDtoComparator implements Comparator<TaxonDistributionDTO> { |
|
22 |
|
|
23 |
/** |
|
24 |
* {@inheritDoc} |
|
25 |
*/ |
|
26 |
@Override |
|
27 |
public int compare(TaxonDistributionDTO arg0, TaxonDistributionDTO arg1) { |
|
28 |
if (arg0 == arg1){ |
|
29 |
return 0; |
|
30 |
} |
|
31 |
|
|
32 |
if (arg0.getTaxonUuid().equals(arg1.getTaxonUuid())){ |
|
33 |
return 0; |
|
34 |
} |
|
35 |
|
|
36 |
String name1 = arg0.getNameCache(); |
|
37 |
String name2 = arg1.getNameCache(); |
|
38 |
Rank rankTax1 = arg0.getRank(); |
|
39 |
Rank rankTax2 = arg1.getRank(); |
|
40 |
|
|
41 |
if (rankTax1 == null && rankTax2 != null){ |
|
42 |
return 1; |
|
43 |
}else if(rankTax2 == null && rankTax1 != null){ |
|
44 |
return -1; |
|
45 |
}else if (rankTax1 != null && rankTax1.isHigher(rankTax2)){ |
|
46 |
return -1; |
|
47 |
}else if (rankTax1 == null && rankTax2 == null || rankTax1.equals(rankTax2)) { |
|
48 |
//same rank, order by name |
|
49 |
return name1.compareTo(name2); |
|
50 |
} |
|
51 |
|
|
52 |
return 0; |
|
53 |
} |
|
54 |
|
|
55 |
} |
Also available in: Unified diff
first steps for using nat tables for distribution editor