|
| 1 | +package de.vogella.plugin.adapter.views; |
| 2 | + |
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.List; |
| 5 | + |
| 6 | +import javax.annotation.PostConstruct; |
| 7 | + |
| 8 | +import org.eclipse.e4.ui.workbench.modeling.ESelectionService; |
| 9 | +import org.eclipse.jface.viewers.ArrayContentProvider; |
| 10 | +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider; |
| 11 | +import org.eclipse.jface.viewers.ISelectionChangedListener; |
| 12 | +import org.eclipse.jface.viewers.SelectionChangedEvent; |
| 13 | +import org.eclipse.jface.viewers.TableViewer; |
| 14 | +import org.eclipse.swt.SWT; |
| 15 | +import org.eclipse.swt.widgets.Composite; |
| 16 | +import org.eclipse.ui.model.WorkbenchLabelProvider; |
| 17 | + |
| 18 | +import de.vogella.plugin.adapter.model.Todo; |
| 19 | + |
| 20 | +public class SampleWorkbenchAdapterView { |
| 21 | + |
| 22 | + private TableViewer viewer; |
| 23 | + |
| 24 | + /** |
| 25 | + * This is a callback that will allow us to create the viewer and initialize |
| 26 | + * it. |
| 27 | + */ |
| 28 | + @PostConstruct |
| 29 | + public void createPartControl(Composite parent, ESelectionService selectionService) { |
| 30 | + viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); |
| 31 | + viewer.setContentProvider(new ArrayContentProvider()); |
| 32 | + |
| 33 | + // make use of the DelegatingStyledCellLabelProvider with the WorkbenchLabelProvider as IStyledLabelProvider implementation |
| 34 | + viewer.setLabelProvider(new DelegatingStyledCellLabelProvider(new WorkbenchLabelProvider())); |
| 35 | + viewer.addSelectionChangedListener(new ISelectionChangedListener() { |
| 36 | + |
| 37 | + @Override |
| 38 | + public void selectionChanged(SelectionChangedEvent event) { |
| 39 | + selectionService.setSelection(event.getSelection()); |
| 40 | + } |
| 41 | + }); |
| 42 | + |
| 43 | + viewer.setInput(getElements()); |
| 44 | + } |
| 45 | + |
| 46 | + // Build up a simple data model |
| 47 | + private List<Todo> getElements() { |
| 48 | + List<Todo> todos = new ArrayList<>(); |
| 49 | + Todo todo = new Todo(); |
| 50 | + todo.setSummary("First Todo"); |
| 51 | + todo.setDescription("A very good description"); |
| 52 | + todo.setDone(true); |
| 53 | + todos.add(todo); |
| 54 | + todo = new Todo(); |
| 55 | + todo.setSummary("Second Todo"); |
| 56 | + todo.setDescription("Second super description"); |
| 57 | + todos.add(todo); |
| 58 | + |
| 59 | + return todos; |
| 60 | + } |
| 61 | +} |
0 commit comments