/*******************************************************************************
* Copyright (c) 2006-2007 Nicolas Richeton.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* 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;
/**
* <p>
* 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.
* </p>
*
* @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();
}
}