Home » Eclipse Projects » Nebula » Gallery not receiving events
Gallery not receiving events [message #53203] |
Sat, 17 May 2008 05:39  |
Eclipse User |
|
|
|
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 09:19   |
Eclipse User |
|
|
|
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 06:45  |
Eclipse User |
|
|
|
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 09:19  |
Eclipse User |
|
|
|
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 06:45  |
Eclipse User |
|
|
|
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
|
|
|
Goto Forum:
Current Time: Sat May 10 08:59:58 EDT 2025
Powered by FUDForum. Page generated in 0.02672 seconds
|