Revision 8309769f
Added by Patrick Plitzner almost 6 years ago
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java | ||
---|---|---|
10 | 10 |
package eu.etaxonomy.taxeditor.bulkeditor.e4; |
11 | 11 |
|
12 | 12 |
import java.io.Serializable; |
13 |
import java.util.ArrayList; |
|
13 | 14 |
import java.util.HashMap; |
14 | 15 |
import java.util.List; |
15 | 16 |
import java.util.Map; |
... | ... | |
32 | 33 |
import org.eclipse.jface.viewers.ISelection; |
33 | 34 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
34 | 35 |
import org.eclipse.jface.viewers.IStructuredSelection; |
36 |
import org.eclipse.jface.viewers.StructuredSelection; |
|
35 | 37 |
import org.eclipse.jface.viewers.TableViewer; |
36 | 38 |
import org.eclipse.nebula.widgets.nattable.NatTable; |
37 | 39 |
import org.eclipse.nebula.widgets.nattable.config.AbstractUiBindingConfiguration; |
... | ... | |
50 | 52 |
import org.eclipse.nebula.widgets.nattable.layer.DataLayer; |
51 | 53 |
import org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack; |
52 | 54 |
import org.eclipse.nebula.widgets.nattable.selection.RowSelectionModel; |
55 |
import org.eclipse.nebula.widgets.nattable.selection.RowSelectionProvider; |
|
56 |
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer; |
|
53 | 57 |
import org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry; |
54 | 58 |
import org.eclipse.nebula.widgets.nattable.ui.matcher.MouseEventMatcher; |
55 | 59 |
import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuAction; |
... | ... | |
105 | 109 |
|
106 | 110 |
private TableViewer viewer; |
107 | 111 |
|
108 |
private NatTable natTable; |
|
109 |
|
|
110 | 112 |
private ConversationHolder conversation; |
111 | 113 |
|
112 | 114 |
@Inject |
... | ... | |
129 | 131 |
@Inject |
130 | 132 |
private EMenuService menuService; |
131 | 133 |
|
134 |
private NatTable natTable; |
|
135 |
|
|
136 |
private SelectionLayer selectionLayer; |
|
137 |
|
|
138 |
private ListDataProvider<CdmBase> bodyDataProvider; |
|
139 |
|
|
132 | 140 |
@Inject |
133 | 141 |
public BulkEditorE4() { |
134 | 142 |
} |
... | ... | |
233 | 241 |
propertyToLabels.put(getEditorInput().getName(), getEditorInput().getName()); |
234 | 242 |
propertyToLabels.put(TYPE_PROPERTY, TYPE_PROPERTY); |
235 | 243 |
String[] propertyNames = new String[] { getEditorInput().getName(), TYPE_PROPERTY }; |
236 |
ListDataProvider bodyDataProvider = new ListDataProvider<CdmBase>(list,
|
|
244 |
bodyDataProvider = new ListDataProvider<CdmBase>(list, |
|
237 | 245 |
new BulkEditorPropertyAccessor(getEditorInput())); |
238 | 246 |
|
239 | 247 |
|
... | ... | |
245 | 253 |
DataLayer dataLayer = new DataLayer(bodyDataProvider); |
246 | 254 |
GlazedListsEventLayer<CdmBase> eventLayer = new GlazedListsEventLayer<>(dataLayer, list); |
247 | 255 |
DefaultBodyLayerStack bodyLayer = new DefaultBodyLayerStack(eventLayer); |
256 |
selectionLayer = bodyLayer.getSelectionLayer(); |
|
248 | 257 |
|
249 | 258 |
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer( |
250 | 259 |
new DataLayer(colHeaderDataProvider), |
... | ... | |
307 | 316 |
} |
308 | 317 |
|
309 | 318 |
})); |
319 |
|
|
320 |
//propagate selection |
|
321 |
selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event))); |
|
322 |
RowSelectionProvider<CdmBase> selectionProvider = new RowSelectionProvider<CdmBase>(selectionLayer, bodyDataProvider, true); |
|
323 |
selectionProvider.addSelectionChangedListener(selectionChangedListener); |
|
310 | 324 |
} |
311 | 325 |
|
312 | 326 |
/** {@inheritDoc} */ |
... | ... | |
366 | 380 |
input.saveModel(resetMerge); |
367 | 381 |
|
368 | 382 |
List<CdmBase> saveCandidates = getEditorInput().getSaveCandidates(); |
369 |
ISelection selection = getViewer().getSelection();
|
|
383 |
IStructuredSelection selection = getSelection();
|
|
370 | 384 |
|
371 | 385 |
dirty.setDirty(false); |
372 | 386 |
getEditorInput().resetSaveCandidates(); |
... | ... | |
376 | 390 |
|
377 | 391 |
if (lastQuery != null){ |
378 | 392 |
performSearch(lastQuery); |
379 |
getViewer().setSelection(selection, true);
|
|
393 |
setSelection(selection);
|
|
380 | 394 |
} |
381 | 395 |
// viewer.refresh(); |
382 | 396 |
|
... | ... | |
423 | 437 |
// viewer.refresh(); |
424 | 438 |
} |
425 | 439 |
|
426 |
public TableViewer getViewer() { |
|
427 |
return viewer; |
|
440 |
// public TableViewer getViewer() { |
|
441 |
// return viewer; |
|
442 |
// } |
|
443 |
|
|
444 |
public IStructuredSelection getSelection(){ |
|
445 |
List<CdmBase> selection = new ArrayList<>(); |
|
446 |
int[] fullySelectedRowPositions = selectionLayer.getFullySelectedRowPositions(); |
|
447 |
for (int i : fullySelectedRowPositions) { |
|
448 |
Object rowObject = bodyDataProvider.getRowObject(i); |
|
449 |
if(rowObject instanceof CdmBase){ |
|
450 |
selection.add((CdmBase) rowObject); |
|
451 |
} |
|
452 |
} |
|
453 |
return new StructuredSelection(selection); |
|
454 |
} |
|
455 |
|
|
456 |
public void setSelection(IStructuredSelection selection){ |
|
457 |
Object[] objects = selection.toArray(); |
|
458 |
for (Object object : objects) { |
|
459 |
if(object instanceof CdmBase){ |
|
460 |
selectionLayer.selectRow(0, bodyDataProvider.indexOfRowObject((CdmBase) object), false, false); |
|
461 |
} |
|
462 |
} |
|
428 | 463 |
} |
429 | 464 |
|
430 | 465 |
public void setDirty(){ |
Also available in: Unified diff
ref #7439 Propagate row selection of nattable