Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Nebula » Gallery not receiving events
Gallery not receiving events [message #589918] Sat, 17 May 2008 05:39
Radu is currently offline Radu
Messages: 44
Registered: July 2009
Member
Hello!

I'm currently developing an RCP application that has to display some
pictures. I have created a view that deals with that (at least
theoretical). I added a Gallery in that view, and wrote the instructions
that i could drag'n'drop items on the Gallery. The thing is that the
drag'n'drop works, the pictures are displayed on the Gallery, but the
Gallery does not receive any events, like mouse scroll, select item etc.

All the examples i found with Gallery and GalleryTreeViewer were taking
events quite nicely actually. Could anyone point me in the right direction
with this?

Many thanks in advance!

My code is :

package edu.dustman.thesis.ui.views;

import java.io.InputStream;
import java.util.StringTokenizer;

import org.eclipse.nebula.widgets.gallery.DefaultGalleryGroupRender er;
import org.eclipse.nebula.widgets.gallery.DefaultGalleryItemRendere r;
import org.eclipse.nebula.widgets.gallery.Gallery;
import org.eclipse.nebula.widgets.gallery.GalleryItem;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DropTarget;
import org.eclipse.swt.dnd.DropTargetAdapter;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.part.ViewPart;

import edu.dustman.thesis.service.Service;
import edu.dustman.thesis.util.registry.ServiceRegistry;

public class PictureDisplayView extends ViewPart{

public static final String ID =
"edu.dustman.thesis.ui.views.PictureDisplayView";
private Service service;
private Gallery gallery;
private GalleryItem group;


@Override
public void createPartControl(Composite parent) {
service = ServiceRegistry.INSTANCE.getService(Service.class);

gallery = new Gallery(parent, SWT.V_SCROLL | SWT.MULTI);
DefaultGalleryGroupRenderer gr = new DefaultGalleryGroupRenderer();
gr.setMinMargin(2);
gr.setItemHeight(200);
gr.setItemWidth(100);
gr.setAutoMargin(true);
gallery.setGroupRenderer(gr);

DefaultGalleryItemRenderer ir = new DefaultGalleryItemRenderer();
gallery.setItemRenderer(ir);

Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
DropTarget target = new DropTarget(gallery, DND.DROP_MOVE |
DND.DROP_COPY | DND.DROP_DEFAULT);
target.setTransfer(types);

target.addDropListener(new DropTargetAdapter() {
public void dragEnter(DropTargetEvent event) {
if (event.detail == DND.DROP_DEFAULT) {
event.detail = (event.operations & DND.DROP_COPY) != 0 ?
DND.DROP_COPY : DND.DROP_NONE;
}

// Allow dropping text only
for (int i = 0, n = event.dataTypes.length; i < n; i++) {
if (TextTransfer.getInstance().isSupportedType(event.dataTypes[ i])) {
event.currentDataType = event.dataTypes[i];
}
}
}

public void dragOver(DropTargetEvent event) {
event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;
}
public void drop(DropTargetEvent event) {
if (TextTransfer.getInstance().isSupportedType(event.currentDat aType))
{
String data = (String) event.data;
System.out.println("dropped:"+data);
loadImage(data);
}
}
});

group = new GalleryItem(gallery, SWT.NONE);
group.setText("no image loaded");

}

protected void loadImage(final String data) {
StringTokenizer tok = new StringTokenizer(data, "|");
int id = Integer.parseInt(tok.nextToken());
String name = tok.nextToken();
String tags = tok.nextToken();
InputStream fileInputStream = service.loadImage(id);
Image image = new Image(Display.getCurrent(), fileInputStream);
group.setText("Pictures with tags:"+tags);
group.setExpanded(true);
GalleryItem galleryItem = new GalleryItem(group, SWT.NONE);
galleryItem.setImage(image);
galleryItem.setText(name);
}

@Override
public void setFocus() {
// TODO Auto-generated method stub

}

}
Previous Topic:Gantt Widget 2.0 - Any Requests?
Next Topic:Gallery not receiving events
Goto Forum:
  


Current Time: Thu Aug 21 12:06:08 EDT 2014

Powered by FUDForum. Page generated in 0.01595 seconds