Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Nebula » Gallery not receiving events
Gallery not receiving events [message #53203] Sat, 17 May 2008 09:39 Go to next message
Eclipse UserFriend
Originally posted by: zacusca.16.gmail.com

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

}

}
Re: Gallery not receiving events [message #53228 is a reply to message #53203] Sat, 17 May 2008 13:19 Go to previous messageGo to next message
Nicolas Richeton is currently offline Nicolas RichetonFriend
Messages: 179
Registered: July 2009
Senior Member
Hi,

You should implements setFocus() with gallery.setFocus(); The other part
of you code seems ok.
This may solve your issue, but if it doesn't let me know.
BTW, you should dispose images you created, the Gallery widget does not
dispose item images when it is disposed itself.

--
Nicolas




Radu a écrit :
> 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
>
> }
>
> }
>
>
Re: Gallery not receiving events [message #53254 is a reply to message #53228] Sun, 18 May 2008 10:45 Go to previous message
Eclipse UserFriend
Originally posted by: zacusca.16.gmail.com

Hello!

I tried :
public void setFocus() {
gallery.setFocus();

}
but the result is the same :| . The gallery still does not receive events.
I saw that there is a thread here, where you posted some examples about
how to use ISelectionListener and SelectionProvider, but that still does
not work (I mean i registered the view as selection provider, and created
a listener to receive selection events, but with no success).


BUT!!! When writing this post, i tried once more to make it work. I closed
the view, opened it again....moved it around, and somehow i "extracted"
the view from the application (dragged it outside the main window), and i
got a nice scrollable view, and i could even select the items!!! :D:D:D:D
Dunno what was the problem...Hope not to bump into this problem again in
the future.

Thanks for all your help!

Radu
Re: Gallery not receiving events [message #589931 is a reply to message #53203] Sat, 17 May 2008 13:19 Go to previous message
Nicolas Richeton is currently offline Nicolas RichetonFriend
Messages: 179
Registered: July 2009
Senior Member
Hi,

You should implements setFocus() with gallery.setFocus(); The other part
of you code seems ok.
This may solve your issue, but if it doesn't let me know.
BTW, you should dispose images you created, the Gallery widget does not
dispose item images when it is disposed itself.

--
Nicolas




Radu a écrit :
> 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
>
> }
>
> }
>
>
Re: Gallery not receiving events [message #589939 is a reply to message #53228] Sun, 18 May 2008 10:45 Go to previous message
Radu is currently offline RaduFriend
Messages: 44
Registered: July 2009
Member
Hello!

I tried :
public void setFocus() {
gallery.setFocus();

}
but the result is the same :| . The gallery still does not receive events.
I saw that there is a thread here, where you posted some examples about
how to use ISelectionListener and SelectionProvider, but that still does
not work (I mean i registered the view as selection provider, and created
a listener to receive selection events, but with no success).


BUT!!! When writing this post, i tried once more to make it work. I closed
the view, opened it again....moved it around, and somehow i "extracted"
the view from the application (dragged it outside the main window), and i
got a nice scrollable view, and i could even select the items!!! :D:D:D:D
Dunno what was the problem...Hope not to bump into this problem again in
the future.

Thanks for all your help!

Radu
Previous Topic:Gallery not receiving events
Next Topic:Does GridViewer support fixed columns?
Goto Forum:
  


Current Time: Thu Mar 28 14:47:00 GMT 2024

Powered by FUDForum. Page generated in 0.03310 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top