private void configureTab(final IImageStore store, CTabFolder fld) {
final CTabItem item = new CTabItem(fld, SWT.NONE);
item.setText(store.getName());
final Composite cm = new Composite(fld, SWT.NONE);
cm.setLayout(new FillLayout());
final Gallery gallery = new Gallery(cm, SWT.VIRTUAL | SWT.V_SCROLL | SWT.BORDER);
item.setControl(cm);
gallery.setVertical(false);
final DefaultGalleryGroupRenderer gr = new DefaultGalleryGroupRenderer();
gallery.setGroupRenderer(gr);
gallery.setItemRenderer(new DefaultGalleryItemRenderer() {
protected Image getImage(GalleryItem item) {
final IImageEntry entry = (IImageEntry) item.getData();
try {
return ImageCache.getImage(entry);
} catch (final Exception e) {
e.printStackTrace();
}
return null;
}
});
final DragSource dragSource = new DragSource(gallery, DND.DROP_COPY);
dragSource.setTransfer(new Transfer[] { FileTransfer.getInstance() });
dragSource.addDragListener(new DragSourceListener() {
private String[] dataX;
public void dragFinished(DragSourceEvent event) {
this.dataX = null;
}
public void dragSetData(DragSourceEvent event) {
event.data = this.dataX;
}
public void dragStart(DragSourceEvent event) {
event.detail = DND.DROP_COPY;
final GalleryItem item2 = gallery.getItem(new Point(event.x, event.y));
if (item2 != null) {
final Object data = item2.getData();
if (data instanceof IImageEntry) {
final IImageEntry e = (IImageEntry) data;
final String file = e.getFile();
this.dataX = new String[] { file };
try {
event.image = e.getImage();
} catch (final IOException e1) {
e1.printStackTrace();
}
}
}
}
});
final IImageEntryCallback cb = new IImageEntryCallback() {
public void imageLoaded() {
gallery.redraw();
}
};
ImageCache.addCallback(cb);
gallery.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
ImageCache.removeCallback(cb);
}
});
item.setData("g", gr);
gr.setItemHeight(56);
gr.setItemWidth(72);
this.fillContextMenu(gallery, gr);
this.tooltip = new ImagesViewTooltip(gallery, gallery);
final ArrayList<Object> images = new ArrayList<Object>(store.getContents());
this.prepareImages(images);
gallery.addListener(SWT.SetData, new Listener() {
public void handleEvent(Event event) {
final GalleryItem item = (GalleryItem) event.item;
final GalleryItem parentItem = item.getParentItem();
if (parentItem == null) {
final int index = gallery.indexOf(item);
final ItemGroup itemGroup = (ItemGroup) images.get(index);
item.setText(itemGroup.getName());
item.setData(itemGroup);
item.setItemCount(itemGroup.getChildCount());
} else {
final int indexOf = parentItem.indexOf(item);
final ItemGroup ga = (ItemGroup) parentItem.getData();
item.setItemCount(0);
final IImageEntry image = ga.getImage(indexOf);
try {
item.setImage(image.getImage());
} catch (IOException e) {
e.printStackTrace();
}
item.setText(image.getName());
item.setData(image);
}
}
});
final HashSet<Object> expanded = new HashSet<Object>();
item.setData("ga", new Collapser() {
void collapse() {
for (int a = 0; a < gallery.getItemCount(); a++) {
final GalleryItem item2 = gallery.getItem(a);
item2.setExpanded(false);
}
expanded.clear();
}
void expand() {
for (int a = 0; a < gallery.getItemCount(); a++) {
final GalleryItem item2 = gallery.getItem(a);
item2.setExpanded(true);
expanded.add(item2.getData());
}
}
});
gallery.addTreeListener(new TreeListener() {
public void treeCollapsed(TreeEvent e) {
expanded.remove(e.data);
}
public void treeExpanded(TreeEvent e) {
expanded.add(e.data);
}
});
final IStoreImageListener storeImageListener = new IStoreImageListener() {
public void platformChanged() {
final ArrayList<?> contents = new ArrayList<Object>(store.getContents());
Display.getDefault().asyncExec(new Runnable() {
public void run() {
ImagesView.this.refresh(gallery, images, expanded, contents);
}
});
}
};
item.setData("r", new Refresher() {
public void refresh() {
final ArrayList<?> contents = new ArrayList<Object>(store.getContents());
ImagesView.this.refresh(gallery, images, expanded, new ArrayList<Object>(contents));
}
});
store.addListener(storeImageListener);
gallery.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
store.removeListener(storeImageListener);
}
});
gallery.setItemCount(images.size());
gallery.setVertical(true);
}