Revision 8e4eddeb
Added by Katja Luther over 5 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionEditor.java | ||
---|---|---|
9 | 9 |
package eu.etaxonomy.taxeditor.editor.view.checklist.e4; |
10 | 10 |
|
11 | 11 |
import java.util.ArrayList; |
12 |
import java.util.Arrays; |
|
12 | 13 |
import java.util.Collection; |
13 | 14 |
import java.util.HashMap; |
14 | 15 |
import java.util.HashSet; |
15 | 16 |
import java.util.List; |
16 | 17 |
import java.util.Map; |
18 |
import java.util.Set; |
|
19 |
import java.util.SortedSet; |
|
20 |
import java.util.TreeSet; |
|
21 |
import java.util.UUID; |
|
17 | 22 |
|
18 | 23 |
import javax.inject.Inject; |
19 | 24 |
|
... | ... | |
23 | 28 |
import org.eclipse.jface.layout.GridDataFactory; |
24 | 29 |
import org.eclipse.jface.wizard.WizardDialog; |
25 | 30 |
import org.eclipse.nebula.widgets.nattable.NatTable; |
26 |
import org.eclipse.nebula.widgets.nattable.config.AbstractUiBindingConfiguration; |
|
27 | 31 |
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry; |
28 | 32 |
import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration; |
29 | 33 |
import org.eclipse.nebula.widgets.nattable.data.IDataProvider; |
30 | 34 |
import org.eclipse.nebula.widgets.nattable.data.IRowDataProvider; |
31 | 35 |
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider; |
32 |
import org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler; |
|
33 | 36 |
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 | 37 |
import org.eclipse.nebula.widgets.nattable.freeze.FreezeLayer; |
38 | 38 |
import org.eclipse.nebula.widgets.nattable.grid.GridRegion; |
39 |
import org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand; |
|
40 | 39 |
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider; |
41 | 40 |
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider; |
42 | 41 |
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider; |
43 |
import org.eclipse.nebula.widgets.nattable.grid.data.FixedSummaryRowHeaderLayer; |
|
44 | 42 |
import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer; |
45 | 43 |
import org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer; |
46 |
import org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer; |
|
47 | 44 |
import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer; |
45 |
import org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer; |
|
48 | 46 |
import org.eclipse.nebula.widgets.nattable.layer.AbstractLayer; |
49 |
import org.eclipse.nebula.widgets.nattable.layer.CompositeLayer; |
|
50 | 47 |
import org.eclipse.nebula.widgets.nattable.layer.DataLayer; |
51 | 48 |
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 | 49 |
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer; |
55 |
import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer; |
|
56 | 50 |
import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration; |
57 | 51 |
import org.eclipse.nebula.widgets.nattable.style.HorizontalAlignmentEnum; |
58 | 52 |
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 | 53 |
import org.eclipse.nebula.widgets.nattable.util.GUIHelper; |
54 |
import org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer; |
|
66 | 55 |
import org.eclipse.swt.SWT; |
67 | 56 |
import org.eclipse.swt.events.SelectionAdapter; |
68 | 57 |
import org.eclipse.swt.events.SelectionEvent; |
... | ... | |
71 | 60 |
import org.eclipse.swt.widgets.Button; |
72 | 61 |
import org.eclipse.swt.widgets.Composite; |
73 | 62 |
import org.eclipse.swt.widgets.Label; |
74 |
import org.eclipse.swt.widgets.Menu; |
|
75 | 63 |
import org.eclipse.swt.widgets.Text; |
76 | 64 |
|
65 |
import ca.odell.glazedlists.BasicEventList; |
|
77 | 66 |
import ca.odell.glazedlists.EventList; |
78 | 67 |
import ca.odell.glazedlists.SortedList; |
68 |
import eu.etaxonomy.cdm.api.service.IVocabularyService; |
|
79 | 69 |
import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO; |
70 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
|
71 |
import eu.etaxonomy.cdm.model.common.Language; |
|
72 |
import eu.etaxonomy.cdm.model.common.OrderedTermBase; |
|
73 |
import eu.etaxonomy.cdm.model.common.OrderedTermComparator; |
|
74 |
import eu.etaxonomy.cdm.model.common.TermIdInVocabularyComparator; |
|
75 |
import eu.etaxonomy.cdm.model.common.TermLanguageComparator; |
|
76 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
|
80 | 77 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
81 | 78 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
79 |
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate; |
|
82 | 80 |
import eu.etaxonomy.cdm.model.reference.Reference; |
83 | 81 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
84 |
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrixLabelStyleConfiguration; |
|
85 | 82 |
import eu.etaxonomy.taxeditor.editor.l10n.Messages; |
86 | 83 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
84 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
|
87 | 85 |
import eu.etaxonomy.taxeditor.preference.Resources; |
88 | 86 |
import eu.etaxonomy.taxeditor.preference.wizard.AvailableDistributionWizard; |
87 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
89 | 88 |
import eu.etaxonomy.taxeditor.store.StoreUtil; |
90 | 89 |
import eu.etaxonomy.taxeditor.ui.dialog.selection.ReferenceSelectionDialog; |
91 | 90 |
|
... | ... | |
125 | 124 |
private Text searchText; |
126 | 125 |
|
127 | 126 |
EventList<TaxonDistributionDTO> taxonList; |
128 |
List<NamedArea> areas = new ArrayList();
|
|
127 |
SortedSet<DefinedTermBase> areas;
|
|
129 | 128 |
DistributionEditorPart part; |
130 |
private DefaultBodyLayerStack bodyLayer;
|
|
129 |
private ViewportLayer bodyLayer;
|
|
131 | 130 |
private FreezeLayer freezeLayer; |
132 | 131 |
private ConfigRegistry configRegistry; |
133 | 132 |
private AbstractLayer topMostLayer; |
134 | 133 |
|
135 |
private FixedSummaryRowLayer summaryRowLayer; |
|
134 |
private SelectionLayer selectionLayer; |
|
135 |
|
|
136 |
// private FixedSummaryRowLayer summaryRowLayer; |
|
136 | 137 |
|
137 | 138 |
|
138 | 139 |
/** |
... | ... | |
145 | 146 |
this.part = part; |
146 | 147 |
createTopComposite(parent); |
147 | 148 |
|
149 |
|
|
150 |
// natTable = new NatTable(parent, viewportLayer); |
|
148 | 151 |
natTable = new NatTable(this, false); |
149 | 152 |
|
150 |
createStatusBar(parent); |
|
153 |
// createStatusBar(parent);
|
|
151 | 154 |
} |
152 | 155 |
|
153 | 156 |
public boolean isShowRank() { |
... | ... | |
196 | 199 |
statusLabel.setLayoutData(gridData); |
197 | 200 |
|
198 | 201 |
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); |
|
202 |
|
|
203 |
statusLabelSourceReference.setLayoutData(gridData); |
|
204 | 204 |
|
205 | 205 |
if (defaultSource != null){ |
206 | 206 |
statusLabelSourceReference.setText("Default Source Reference: " + defaultSource.getAbbrevTitle() != null? defaultSource.getAbbrevTitle() : defaultSource.getAbbrevTitleCache()); |
... | ... | |
238 | 238 |
// to sort on a single click |
239 | 239 |
|
240 | 240 |
natTable.addConfiguration(new SingleClickSortConfiguration()); |
241 |
natTable.addConfiguration(new CharacterMatrixLabelStyleConfiguration()); |
|
241 |
// natTable.addConfiguration(new CharacterMatrixLabelStyleConfiguration());
|
|
242 | 242 |
|
243 | 243 |
// add the header menu configuration for adding the column header menu |
244 | 244 |
// with hide/show actions |
... | ... | |
251 | 251 |
// summaryRowLayer.addConfiguration(new AggregationConfiguration(this)); |
252 | 252 |
|
253 | 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 |
}); |
|
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 | 277 |
|
278 | 278 |
natTable.configure(); |
279 | 279 |
} |
280 | 280 |
|
281 |
public void createTable(boolean freezeSupplementalColumns){
|
|
281 |
public void createTable(){ |
|
282 | 282 |
/** |
283 | 283 |
* layers |
284 | 284 |
*/ |
285 |
|
|
285 | 286 |
createLayers(); |
286 | 287 |
|
287 | 288 |
/** |
... | ... | |
307 | 308 |
|
308 | 309 |
|
309 | 310 |
this.layout(); |
310 |
natTable.doCommand(new ClientAreaResizeCommand(natTable)); |
|
311 |
// boolean ok = natTable.doCommand(new ClientAreaResizeCommand(natTable)); |
|
312 |
// System.out.println(ok); |
|
311 | 313 |
} |
312 | 314 |
|
313 | 315 |
|
314 | 316 |
private void createLayers() { |
315 | 317 |
|
316 | 318 |
SortedList sortedList = new SortedList(taxonList, new TaxonDistributionDtoComparator()); |
319 |
DistributionColumnAccessor columnPropertyAccessor = new DistributionColumnAccessor(this); |
|
317 | 320 |
|
318 | 321 |
|
319 |
/** |
|
320 |
* data provider |
|
321 |
*/ |
|
322 |
DistributionColumnAccessor columnPropertyAccessor = new DistributionColumnAccessor(this); |
|
323 | 322 |
bodyDataProvider = new ListDataProvider(sortedList, columnPropertyAccessor); |
324 | 323 |
|
325 |
propertyToLabelMap.put(TAXON_COLUMN, Messages.CharacterMatrix_TAXON);
|
|
324 |
propertyToLabelMap.put(TAXON_COLUMN, Messages.ChecklistEditor_TAXON);
|
|
326 | 325 |
if (isShowRank){ |
327 |
propertyToLabelMap.put(RANK_COLUMN, Messages.CharacterMatrix_COLLECTOR_NO);
|
|
326 |
propertyToLabelMap.put(RANK_COLUMN, Messages.ChecklistEditor_RANK);
|
|
328 | 327 |
} |
329 | 328 |
configRegistry = new ConfigRegistry(); |
330 | 329 |
|
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 | 330 |
initLabels(); |
331 |
// build up a layer stack consisting of DataLayer, SelectionLayer and |
|
332 |
// ViewportLayer |
|
333 |
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider); |
|
334 |
selectionLayer = new SelectionLayer(bodyDataLayer); |
|
335 |
bodyLayer = new ViewportLayer(selectionLayer); |
|
380 | 336 |
|
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); |
|
337 |
// as the selection mouse bindings are registered for the region label |
|
338 |
// GridRegion.BODY |
|
339 |
// we need to set that region label to the viewport so the selection via mouse |
|
340 |
// is working correctly |
|
341 |
bodyLayer.setRegionName(GridRegion.BODY); |
|
417 | 342 |
|
418 | 343 |
|
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)); |
|
344 |
IDataProvider columnHeaderDataProvider = |
|
345 |
new DefaultColumnHeaderDataProvider(propertyToLabelMap.values().toArray(new String[] {}), propertyToLabelMap); |
|
346 |
DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider); |
|
347 |
ILayer columnHeaderLayer = new ColumnHeaderLayer( |
|
348 |
columnHeaderDataLayer, |
|
349 |
bodyLayer, |
|
350 |
selectionLayer); |
|
436 | 351 |
|
437 | 352 |
|
438 |
/** |
|
439 |
* row header layer |
|
440 |
*/ |
|
353 |
// build the row header layer stack |
|
441 | 354 |
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); |
|
355 |
DataLayer rowHeaderDataLayer = new DataLayer(rowHeaderDataProvider, 40, 20); |
|
356 |
ILayer rowHeaderLayer = new RowHeaderLayer( |
|
357 |
rowHeaderDataLayer, |
|
358 |
bodyLayer, |
|
359 |
selectionLayer); |
|
360 |
|
|
361 |
|
|
362 |
|
|
363 |
IDataProvider cornerDataProvider = |
|
364 |
new DefaultCornerDataProvider( |
|
365 |
columnHeaderDataProvider, |
|
366 |
rowHeaderDataProvider); |
|
367 |
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider); |
|
368 |
ILayer cornerLayer = new CornerLayer( |
|
369 |
cornerDataLayer, |
|
370 |
rowHeaderLayer, |
|
371 |
columnHeaderLayer); |
|
372 |
|
|
373 |
GridLayer gridLayer = new GridLayer( |
|
374 |
bodyLayer, |
|
375 |
columnHeaderLayer, |
|
376 |
rowHeaderLayer, |
|
377 |
cornerLayer); |
|
454 | 378 |
|
379 |
natTable.setLayer(gridLayer); |
|
455 | 380 |
|
456 |
/** |
|
457 |
* GRID layer (composition of all other layers) |
|
458 |
*/ |
|
459 |
GridLayer gridLayer = new GridLayer(composite, sortHeaderLayer, null, cornerLayer); |
|
381 |
topMostLayer = bodyLayer; |
|
460 | 382 |
|
461 |
natTable.setLayer(gridLayer); |
|
462 | 383 |
|
463 | 384 |
} |
464 | 385 |
|
... | ... | |
543 | 464 |
|
544 | 465 |
} |
545 | 466 |
public void loadDistributions(List<TaxonDistributionDTO> taxonList) { |
546 |
this.taxonList.addAll(taxonList); |
|
547 |
|
|
467 |
if (this.taxonList == null){ |
|
468 |
this.taxonList = new BasicEventList<>(); |
|
469 |
} |
|
470 |
taxonList.stream().forEach(wrapper->DistributionEditor.this.taxonList.add(wrapper)); |
|
548 | 471 |
} |
549 | 472 |
|
473 |
|
|
474 |
|
|
550 | 475 |
public Collection<DescriptionElementBase> getDistributions() { |
551 | 476 |
Collection<DescriptionElementBase> descElements = new HashSet(); |
552 | 477 |
//TODO: only for edited taxa |
... | ... | |
564 | 489 |
if (isShowRank){ |
565 | 490 |
index++; |
566 | 491 |
} |
567 |
for (NamedArea area: areas) { |
|
568 |
this.areaToColumnIndexMap.put(index++, area); |
|
492 |
|
|
493 |
loadNamedAreas(); |
|
494 |
for (DefinedTermBase area: areas) { |
|
495 |
this.areaToColumnIndexMap.put(index++, (NamedArea)area); |
|
569 | 496 |
|
570 | 497 |
//TODO: adapt to preference |
571 | 498 |
String areaLabel = area.getLabel(); |
... | ... | |
574 | 501 |
} |
575 | 502 |
} |
576 | 503 |
|
504 |
private SortedSet<DefinedTermBase> loadNamedAreas() { |
|
505 |
//IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore(); |
|
506 |
|
|
507 |
String valuesAreas = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey()); |
|
508 |
String values = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey()); |
|
509 |
if (values != null && values != "") { //$NON-NLS-1$ |
|
510 |
String[] split = values.split(";"); //$NON-NLS-1$ |
|
511 |
List<String> listValue = Arrays.asList(split); |
|
512 |
List<DefinedTermBase> termlist = new ArrayList<DefinedTermBase>(); |
|
513 |
Set<UUID> uuidList = new HashSet<UUID>(); |
|
514 |
UUID uuid; |
|
515 |
for(String s : listValue){ |
|
516 |
uuid = UUID.fromString(s); |
|
517 |
uuidList.add(uuid); |
|
577 | 518 |
|
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)); |
|
519 |
} |
|
520 |
IVocabularyService service = CdmStore.getService(IVocabularyService.class); |
|
521 |
List<TermVocabulary> vocs = service.find(uuidList); |
|
522 |
split = valuesAreas.split(";"); |
|
523 |
listValue = Arrays.asList(split); |
|
524 |
for (TermVocabulary voc: vocs){ |
|
525 |
termlist.addAll(service.getTerms(voc, null, null, null, null).getRecords()); |
|
526 |
} |
|
527 |
List<DefinedTermBase> filteredList = new ArrayList(); |
|
528 |
for (DefinedTermBase area: termlist){ |
|
529 |
if (listValue.contains(area.getUuid().toString())) { |
|
530 |
filteredList.add(area); |
|
531 |
} |
|
582 | 532 |
|
533 |
} |
|
534 |
|
|
535 |
if (PreferencesUtil.isSortNamedAreaByOrderInVocabulary()){ |
|
536 |
areas = getTermsOrderedByVocabularyOrder(filteredList); |
|
537 |
} else if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){ |
|
538 |
areas = getTermsOrderedByIdInVocabulary(filteredList); |
|
539 |
}else{ |
|
540 |
areas = getTermsOrderedByLabels(filteredList, CdmStore.getDefaultLanguage()); |
|
541 |
} |
|
542 |
} |
|
543 |
return null; |
|
544 |
} |
|
545 |
|
|
546 |
public SortedSet<DefinedTermBase> getTermsOrderedByLabels(List<DefinedTermBase> listTerm,Language language){ |
|
547 |
TermLanguageComparator<?> comp = new TermLanguageComparator<>(); |
|
548 |
comp.setCompareLanguage(language); |
|
549 |
SortedSet<DefinedTermBase> result = new TreeSet(comp); |
|
550 |
if(listTerm != null){ |
|
551 |
result.addAll(listTerm); |
|
552 |
} |
|
553 |
return result; |
|
554 |
} |
|
555 |
|
|
556 |
public SortedSet<DefinedTermBase> getTermsOrderedByIdInVocabulary(List<DefinedTermBase> namedAreas) { |
|
557 |
TermIdInVocabularyComparator<?> comp = new TermIdInVocabularyComparator<>(); |
|
558 |
|
|
559 |
SortedSet<DefinedTermBase> result = new TreeSet(comp); |
|
560 |
if(namedAreas != null){ |
|
561 |
result.addAll(namedAreas); |
|
562 |
} |
|
563 |
return result; |
|
564 |
} |
|
565 |
|
|
566 |
public SortedSet<DefinedTermBase> getTermsOrderedByVocabularyOrder(List<DefinedTermBase> listAreas){ |
|
567 |
HashMap<TermVocabulary<DefinedTermBase>, List<DefinedTermBase>> vocs = new HashMap<>(); |
|
568 |
OrderedTermComparator<?> comp = new OrderedTermComparator<>(); |
|
569 |
boolean allOrderedTerms = true; |
|
570 |
List<TermVocabulary> alreadyOrderIndexNull = new ArrayList<>(); |
|
571 |
for (DefinedTermBase term: listAreas){ |
|
572 |
if (!(term instanceof OrderedTermBase)){ |
|
573 |
allOrderedTerms = false; |
|
574 |
break; |
|
575 |
}else if (((OrderedTermBase)term).getOrderIndex() == 0){ |
|
576 |
if(alreadyOrderIndexNull.contains(term.getVocabulary())) { |
|
577 |
allOrderedTerms = false; |
|
578 |
break; |
|
579 |
}else{ |
|
580 |
alreadyOrderIndexNull.add(term.getVocabulary()); |
|
581 |
} |
|
582 |
|
|
583 |
|
|
584 |
} |
|
585 |
} |
|
586 |
if (allOrderedTerms){ |
|
587 |
SortedSet<DefinedTermBase> result = new TreeSet(comp.reversed()); |
|
588 |
result.addAll(listAreas); |
|
589 |
return result; |
|
590 |
}else{ |
|
591 |
return getTermsOrderedByLabels(listAreas, PreferencesUtil.getGlobalLanguage()); |
|
592 |
} |
|
593 |
|
|
594 |
|
|
595 |
} |
|
596 |
|
|
597 |
private void registerHandlersAndListeners(AbstractLayer topMostLayer) { |
|
583 | 598 |
//selection listener |
584 | 599 |
E4SelectionListener selectionListener = new DistributionCellSelectionListener(part.getSelectionService(), |
585 |
bodyLayer.getSelectionLayer(), bodyDataProvider, part);
|
|
586 |
bodyLayer.getSelectionLayer().addLayerListener(selectionListener);
|
|
600 |
selectionLayer, bodyDataProvider, part);
|
|
601 |
selectionLayer.addLayerListener(selectionListener);
|
|
587 | 602 |
selectionListener.setFullySelectedRowsOnly(false); |
588 | 603 |
|
589 | 604 |
//register handler for view configuration menu |
Also available in: Unified diff
build layers for distribution editor