/******************************************************************************* * Copyright (c) 2006-2007 Nicolas Richeton. * * 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 : * Nicolas Richeton (nicolas.richeton@gmail.com) - initial implementation *******************************************************************************/ package org.eclipse.nebula.snippets.gallery; import org.eclipse.nebula.widgets.gallery.DefaultGalleryGroupRenderer; import org.eclipse.nebula.widgets.gallery.DefaultGalleryItemRenderer; import org.eclipse.nebula.widgets.gallery.Gallery; import org.eclipse.nebula.widgets.gallery.GalleryItem; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; /** *

* NOTE: THIS WIDGET AND ITS API ARE STILL UNDER DEVELOPMENT. THIS IS A * PRE-RELEASE ALPHA VERSION. USERS SHOULD EXPECT API CHANGES IN FUTURE * VERSIONS. *

* * @author Nicolas Richeton (nicolas.richeton@gmail.com) */ public class SnippetVirtual { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final Gallery gallery = new Gallery(shell, SWT.V_SCROLL | SWT.VIRTUAL); // Renderers DefaultGalleryGroupRenderer gr = new DefaultGalleryGroupRenderer(); gr.setItemSize(64, 64); gr.setMinMargin(3); DefaultGalleryItemRenderer ir = new DefaultGalleryItemRenderer(); gallery.setGroupRenderer(gr); gallery.setItemRenderer(ir); gallery.setVirtualGroups(true); gallery.addListener(SWT.SetData, new Listener() { public void handleEvent(Event event) { GalleryItem item = (GalleryItem) event.item; int index; if (item.getParentItem() != null) { index = item.getParentItem().indexOf(item); item.setItemCount(0); } else { index = gallery.indexOf(item); item.setItemCount(100); } System.out.println( "setData index " + index); //$NON-NLS-1$ // Your image here // item.setImage(eclipseImage); item.setText("Item " + index); //$NON-NLS-1$ } }); gallery.setItemCount(100); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }