/******************************************************************************* * Copyright (c) 2006, 2015 Tom Schindl and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * * Contributors: * Tom Schindl - initial API and implementation * Lars Vogel - Bug 413427, 475361 * Jeanderson Candido (http://jeandersonbc.github.io) - Bug 414565 *******************************************************************************/ package org.eclipse.jface.snippets.viewers; import java.util.ArrayList; import java.util.List; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.ListViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; /** * Demonstrate a simple ListViewer */ public class Snippet039ListViewer { public static class MyModel { public int counter; public MyModel(int counter) { this.counter = counter; } @Override public String toString() { return "Item " + this.counter; } } public Snippet039ListViewer(Shell shell) { final ListViewer v = new ListViewer(shell, SWT.H_SCROLL | SWT.V_SCROLL); v.setLabelProvider(new LabelProvider()); v.setContentProvider(ArrayContentProvider.getInstance()); v.setInput(createModel()); } private List createModel() { List elements = new ArrayList<>(); for (int i = 0; i < 10; i++) { elements.add(new MyModel(i)); } return elements; } public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); new Snippet039ListViewer(shell); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }