Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Nebula » Gallery with SWT.VIRTUAL
Gallery with SWT.VIRTUAL [message #522998] Wed, 24 March 2010 17:37 Go to next message
Aurelien Pupier is currently offline Aurelien PupierFriend
Messages: 574
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

Hi,

I'm trying to use SWT.VIRTUAL on the gallery widget. I look at the official snippet.

Unfortunately,
if I let
gallery.setItemCount(100);

I've got a NPE:
java.lang.NullPointerException
	at org.eclipse.nebula.widgets.gallery.Gallery.calculateSize(Gallery.java:1516)
	at org.eclipse.nebula.widgets.gallery.Gallery.updateStructuralValues(Gallery.java:1455)
	at org.eclipse.nebula.widgets.gallery.Gallery.setItemCount(Gallery.java:233)


If I remove it, none of my Image is displayed. And in fact the listener on SWT.SetData is never called.

Any hints are welcome.

regards,



Aurélien Pupier - Bonitasoft S.A.
My company Eclipse-related blog
Re: Gallery with SWT.VIRTUAL [message #523208 is a reply to message #522998] Thu, 25 March 2010 14:32 Go to previous messageGo to next message
Nicolas Richeton is currently offline Nicolas RichetonFriend
Messages: 179
Registered: July 2009
Senior Member
Strange.
Are you using the released version or the latest nightly ?
Could you try to remove virtual groups and see if it works ?

--
Nicolas

Le 24/03/10 18:37, Aurelien Pupier a écrit :
> Hi,
>
> I'm trying to use SWT.VIRTUAL on the gallery widget. I look at the
> official
> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.neb ula/org.eclipse.swt.nebula.snippets/src/org/eclipse/swt/nebu la/snippets/gallery/SnippetVirtual.java?root=Technology_Proj ect&view=co
>
>
> Unfortunately,
> if I let gallery.setItemCount(100);
> I've got a NPE:
> java.lang.NullPointerException
> at
> org.eclipse.nebula.widgets.gallery.Gallery.calculateSize(Gal lery.java:1516)
> at
> org.eclipse.nebula.widgets.gallery.Gallery.updateStructuralV alues(Gallery.java:1455)
>
> at
> org.eclipse.nebula.widgets.gallery.Gallery.setItemCount(Gall ery.java:233)
>
> If I remove it, none of my Image is displayed. And in fact the listener
> on SWT.SetData is never called.
>
> Any hints are welcome.
>
> regards,
>
>
Re: Gallery with SWT.VIRTUAL [message #523218 is a reply to message #523208] Thu, 25 March 2010 15:03 Go to previous messageGo to next message
Aurelien Pupier is currently offline Aurelien PupierFriend
Messages: 574
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

I tried with release and nightly version.
I also already tried wihtout setting virtual groups.

Here you can see what I've done, th ecommentary code is code that I tried. Notice that none of my listener is called.
		final Gallery gallery = new Gallery(bottomComposite, SWT.V_SCROLL | SWT.BORDER | SWT.VIRTUAL);
		gallery.setLayoutData(new GridData(330, 250));
		// Renderers
		DefaultGalleryGroupRenderer gr = new DefaultGalleryGroupRenderer();
		gr.setItemSize(150, 100);
		gr.setAlwaysExpanded(false);
		gr.setMinMargin(3);
		DefaultGalleryItemRenderer ir = new DefaultGalleryItemRenderer();
		ir.setShowLabels(true);

		gallery.setGroupRenderer(gr);
		gallery.setItemRenderer(ir);
		
		//gallery.setVirtualGroups(true);
		
		gallery.addListener(SWT.SetData, new Listener() {

			public void handleEvent(Event event) {
//never go here
				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
				if(item.getData("object") != null){
					if(item.getData("object") instanceof FormRepositoryArtifact){
						item.setImage(((FormRepositoryArtifact)item.getData("object")).getImage(getShell().getDisplay()/*Display.getCurrent()*/));
					} else if(item.getData("object") instanceof Form){
						item.setImage(createImage((Form) item.getData("object")));
					}
				}
				// item.setImage(eclipseImage);
				item.setText("Item " + index); //$NON-NLS-1$
			}

		});
		//gallery.setItemCount(100);
		
		GalleryItem groupTemplates = new GalleryItem(gallery, SWT.NONE);
		groupTemplates.setText("Templates");
		groupTemplates.addListener(SWT.SetData, new Listener(){
			public void handleEvent(Event event) {
//never go here
				// TODO Auto-generated method stub
				System.out.println("test moi");
			}
		});
		groupTemplates.addListener(SWT.Expand, new Listener(){
			public void handleEvent(Event event) {
//never go here
				// TODO Auto-generated method stub
				System.out.println("enfin un event qui marche?");
			}
		});
		gallery.setData(groupTemplates);
		for(FormRepositoryArtifact artifact : FormRepository.getInstance().getAllArtifacts()){
			GalleryItem g = new GalleryItem(groupTemplates, SWT.NONE);
			g.setText(0, artifact.getName());
			g.setText(1, ((Form)artifact.getContent()).getName());
			g.setData("object", artifact);
			//g.setImage(artifact.getImage(getShell().getDisplay()));
			g.setItemCount(2);
			gallery.setData(g);
		}
		
		for(AbstractProcess proc : ProcessRepository.getInstance().getAllProcesses()){
			GalleryItem groupProc = new GalleryItem(gallery, SWT.NONE);
			groupProc.setText(proc.getName());
			for(Form form : ModelHelper.getAllFormsContainedIn(proc)){
				GalleryItem g = new GalleryItem(groupProc, SWT.NONE);
				g.setData("object", form);
				g.setItemCount(2);
				g.setText(0, form.getName());
				//g.setImage(createImage(form));
			}
		}
		//gallery.setItemCount(100);


Aurélien Pupier - Bonitasoft S.A.
My company Eclipse-related blog

[Updated on: Thu, 25 March 2010 16:49]

Report message to a moderator

Re: Gallery with SWT.VIRTUAL [message #523359 is a reply to message #523218] Fri, 26 March 2010 07:05 Go to previous messageGo to next message
Nicolas Richeton is currently offline Nicolas RichetonFriend
Messages: 179
Registered: July 2009
Senior Member
Aurelien,

The virtual snippet works for me and SetData is tested in gallery unit
tests : you should be able to get events. Could you try to run the
snippet as-is and run the tests in
org.eclipse.nebula.widgets.gallery.tests to ensure there really is an issue.

Looking at your code, I have the following comments :
- Avoid mixing virtual and non virtual code : don't use new GalleryItem
() if you are using SWT.VIRTUAL and SWT.SetData at the same time. This
is because SetData will only be called if a visible item is
uninitialized (null) on paint.
-> mixing is supported by is likely to produce unexpected results.

- With SWT, ASAIK SetData, or Expand listeners are never attached to
items but to the container. With Gallery, listener added on items will
never be used.
Try to replace Gallery by Tree and compare the behavior. If they are
different, please open a bug.

- setData is used for linking some object to a widget. This is only for
your code and never used by swt nor Gallery.

--
Nicolas


Le 25/03/10 16:03, Aurelien Pupier a écrit :
> I tried with release and nightly version.
> I also already tried wihtout setting virtual groups.
>
> Here you can see what I've done, th ecommentary code is code that I
> tried. Notice that none of my listener is called.
> final Gallery gallery = new Gallery(bottomComposite, SWT.V_SCROLL |
> SWT.BORDER | SWT.VIRTUAL);
> gallery.setLayoutData(new GridData(330, 250));
> // Renderers
> DefaultGalleryGroupRenderer gr = new DefaultGalleryGroupRenderer();
> gr.setItemSize(150, 100);
> gr.setAlwaysExpanded(false);
> gr.setMinMargin(3);
> DefaultGalleryItemRenderer ir = new DefaultGalleryItemRenderer();
> ir.setShowLabels(true);
>
> gallery.setGroupRenderer(gr);
> gallery.setItemRenderer(ir);
>
> //gallery.setVirtualGroups(true);
>
> gallery.addListener(SWT.SetData, new Listener() {
>
> public void handleEvent(Event event) {
> //never going into
> 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
> if(item.getData("object") != null){
> if(item.getData("object") instanceof FormRepositoryArtifact){
> item.setImage(((FormRepositoryArtifact)item.getData("object " )).getImage(getShell().getDisplay()/*Display.getCurrent()*/) );
>
> } else if(item.getData("object") instanceof Form){
> item.setImage(createImage((Form) item.getData("object")));
> }
> }
> // item.setImage(eclipseImage);
> item.setText("Item " + index); //$NON-NLS-1$
> }
>
> });
> //gallery.setItemCount(100);
>
> GalleryItem groupTemplates = new GalleryItem(gallery, SWT.NONE);
> groupTemplates.setText("Templates");
> groupTemplates.addListener(SWT.SetData, new Listener(){
> public void handleEvent(Event event) {
> // TODO Auto-generated method stub
> System.out.println("test moi");
> }
> });
> groupTemplates.addListener(SWT.Expand, new Listener(){
> public void handleEvent(Event event) {
> // TODO Auto-generated method stub
> System.out.println("enfin un event qui marche?");
> }
> });
> gallery.setData(groupTemplates);
> for(FormRepositoryArtifact artifact :
> FormRepository.getInstance().getAllArtifacts()){
> GalleryItem g = new GalleryItem(groupTemplates, SWT.NONE);
> g.setText(0, artifact.getName());
> g.setText(1, ((Form)artifact.getContent()).getName());
> g.setData("object", artifact);
> //g.setImage(artifact.getImage(getShell().getDisplay()));
> g.setItemCount(2);
> gallery.setData(g);
> }
>
> for(AbstractProcess proc :
> ProcessRepository.getInstance().getAllProcesses()){
> GalleryItem groupProc = new GalleryItem(gallery, SWT.NONE);
> groupProc.setText(proc.getName());
> for(Form form : ModelHelper.getAllFormsContainedIn(proc)){
> GalleryItem g = new GalleryItem(groupProc, SWT.NONE);
> g.setData("object", form);
> g.setItemCount(2);
> g.setText(0, form.getName());
> final Gallery gallery = new Gallery(bottomComposite, SWT.V_SCROLL |
> SWT.BORDER | SWT.VIRTUAL);
> gallery.setLayoutData(new GridData(330, 250));
> // Renderers
> DefaultGalleryGroupRenderer gr = new DefaultGalleryGroupRenderer();
> gr.setItemSize(150, 100);
> gr.setAlwaysExpanded(false);
> gr.setMinMargin(3);
> DefaultGalleryItemRenderer ir = new DefaultGalleryItemRenderer();
> ir.setShowLabels(true);
>
> gallery.setGroupRenderer(gr);
> gallery.setItemRenderer(ir);
>
> //gallery.setVirtualGroups(true);
>
> gallery.addListener(SWT.SetData, new Listener() {
>
> public void handleEvent(Event event) {
> //never going into
> 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
> if(item.getData("object") != null){
> if(item.getData("object") instanceof FormRepositoryArtifact){
> item.setImage(((FormRepositoryArtifact)item.getData("object " )).getImage(getShell().getDisplay()/*Display.getCurrent()*/) );
>
> } else if(item.getData("object") instanceof Form){
> item.setImage(createImage((Form) item.getData("object")));
> }
> }
> // item.setImage(eclipseImage);
> item.setText("Item " + index); //$NON-NLS-1$
> }
>
> });
> //gallery.setItemCount(100);
>
> GalleryItem groupTemplates = new GalleryItem(gallery, SWT.NONE);
> groupTemplates.setText("Templates");
> groupTemplates.addListener(SWT.SetData, new Listener(){
> public void handleEvent(Event event) {
> //never going into
> System.out.println("test moi");
> }
> });
> groupTemplates.addListener(SWT.Expand, new Listener(){
> public void handleEvent(Event event) {
> //never going into
> }
> });
> gallery.setData(groupTemplates);
> for(FormRepositoryArtifact artifact :
> FormRepository.getInstance().getAllArtifacts()){
> GalleryItem g = new GalleryItem(groupTemplates, SWT.NONE);
> g.setText(0, artifact.getName());
> g.setText(1, ((Form)artifact.getContent()).getName());
> g.setData("object", artifact);
> //g.setImage(artifact.getImage(getShell().getDisplay()));
> g.setItemCount(2);
> gallery.setData(g);
> }
>
> for(AbstractProcess proc :
> ProcessRepository.getInstance().getAllProcesses()){
> GalleryItem groupProc = new GalleryItem(gallery, SWT.NONE);
> groupProc.setText(proc.getName());
> for(Form form : ModelHelper.getAllFormsContainedIn(proc)){
> GalleryItem g = new GalleryItem(groupProc, SWT.NONE);
> g.setData("object", form);
> g.setItemCount(2);
> g.setText(0, form.getName());
> //g.setImage(createImage(form));
> }
> }
> //gallery.setItemCount(100);
> }
> }
> //gallery.setItemCount(100);
>
>
>
Re: Gallery with SWT.VIRTUAL [message #523373 is a reply to message #523359] Fri, 26 March 2010 08:45 Go to previous messageGo to next message
Aurelien Pupier is currently offline Aurelien PupierFriend
Messages: 574
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

I run the tests and all is ok Smile

I will take a look deeper asap to see what I misdone.

Thanks for your quick replies.


Aurélien Pupier - Bonitasoft S.A.
My company Eclipse-related blog
Re: Gallery with SWT.VIRTUAL [message #523633 is a reply to message #522998] Sat, 27 March 2010 18:04 Go to previous message
Aurelien Pupier is currently offline Aurelien PupierFriend
Messages: 574
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

hum I understand better how it works and... it works with a Gallery Smile

By now, I don't understand how it works with the viewer but not look deeper into that.

Thanks for your help.


Aurélien Pupier - Bonitasoft S.A.
My company Eclipse-related blog
Re: Gallery with SWT.VIRTUAL [message #599334 is a reply to message #523208] Thu, 25 March 2010 15:03 Go to previous message
Aurelien Pupier is currently offline Aurelien PupierFriend
Messages: 574
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

I tried with release and nightly version.
I also already tried wihtout setting virtual groups.

Here you can see what I've done, th ecommentary code is code that I tried. Notice that none of my listener is called.
final Gallery gallery = new Gallery(bottomComposite, SWT.V_SCROLL | SWT.BORDER | SWT.VIRTUAL);
gallery.setLayoutData(new GridData(330, 250));
// Renderers
DefaultGalleryGroupRenderer gr = new DefaultGalleryGroupRenderer();
gr.setItemSize(150, 100);
gr.setAlwaysExpanded(false);
gr.setMinMargin(3);
DefaultGalleryItemRenderer ir = new DefaultGalleryItemRenderer();
ir.setShowLabels(true);

gallery.setGroupRenderer(gr);
gallery.setItemRenderer(ir);

//gallery.setVirtualGroups(true);

gallery.addListener(SWT.SetData, new Listener() {

public void handleEvent(Event event) {
//never going into
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
if(item.getData("object") != null){
if(item.getData("object") instanceof FormRepositoryArtifact){
item.setImage(((FormRepositoryArtifact)item.getData("object " )).getImage(getShell().getDisplay()/*Display.getCurrent()*/) );
} else if(item.getData("object") instanceof Form){
item.setImage(createImage((Form) item.getData("object")));
}
}
// item.setImage(eclipseImage);
item.setText("Item " + index); //$NON-NLS-1$
}

});
//gallery.setItemCount(100);

GalleryItem groupTemplates = new GalleryItem(gallery, SWT.NONE);
groupTemplates.setText("Templates");
groupTemplates.addListener(SWT.SetData, new Listener(){
public void handleEvent(Event event) {
// TODO Auto-generated method stub
System.out.println("test moi");
}
});
groupTemplates.addListener(SWT.Expand, new Listener(){
public void handleEvent(Event event) {
// TODO Auto-generated method stub
System.out.println("enfin un event qui marche?");
}
});
gallery.setData(groupTemplates);
for(FormRepositoryArtifact artifact : FormRepository.getInstance().getAllArtifacts()){
GalleryItem g = new GalleryItem(groupTemplates, SWT.NONE);
g.setText(0, artifact.getName());
g.setText(1, ((Form)artifact.getContent()).getName());
g.setData("object", artifact);
//g.setImage(artifact.getImage(getShell().getDisplay()));
g.setItemCount(2);
gallery.setData(g);
}

for(AbstractProcess proc : ProcessRepository.getInstance().getAllProcesses()){
GalleryItem groupProc = new GalleryItem(gallery, SWT.NONE);
groupProc.setText(proc.getName());
for(Form form : ModelHelper.getAllFormsContainedIn(proc)){
GalleryItem g = new GalleryItem(groupProc, SWT.NONE);
g.setData("object", form);
g.setItemCount(2);
g.setText(0, form.getName());
final Gallery gallery = new Gallery(bottomComposite, SWT.V_SCROLL | SWT.BORDER | SWT.VIRTUAL);
gallery.setLayoutData(new GridData(330, 250));
// Renderers
DefaultGalleryGroupRenderer gr = new DefaultGalleryGroupRenderer();
gr.setItemSize(150, 100);
gr.setAlwaysExpanded(false);
gr.setMinMargin(3);
DefaultGalleryItemRenderer ir = new DefaultGalleryItemRenderer();
ir.setShowLabels(true);

gallery.setGroupRenderer(gr);
gallery.setItemRenderer(ir);

//gallery.setVirtualGroups(true);

gallery.addListener(SWT.SetData, new Listener() {

public void handleEvent(Event event) {
//never going into
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
if(item.getData("object") != null){
if(item.getData("object") instanceof FormRepositoryArtifact){
item.setImage(((FormRepositoryArtifact)item.getData("object " )).getImage(getShell().getDisplay()/*Display.getCurrent()*/) );
} else if(item.getData("object") instanceof Form){
item.setImage(createImage((Form) item.getData("object")));
}
}
// item.setImage(eclipseImage);
item.setText("Item " + index); //$NON-NLS-1$
}

});
//gallery.setItemCount(100);

GalleryItem groupTemplates = new GalleryItem(gallery, SWT.NONE);
groupTemplates.setText("Templates");
groupTemplates.addListener(SWT.SetData, new Listener(){
public void handleEvent(Event event) {
//never going into
System.out.println("test moi");
}
});
groupTemplates.addListener(SWT.Expand, new Listener(){
public void handleEvent(Event event) {
//never going into
}
});
gallery.setData(groupTemplates);
for(FormRepositoryArtifact artifact : FormRepository.getInstance().getAllArtifacts()){
GalleryItem g = new GalleryItem(groupTemplates, SWT.NONE);
g.setText(0, artifact.getName());
g.setText(1, ((Form)artifact.getContent()).getName());
g.setData("object", artifact);
//g.setImage(artifact.getImage(getShell().getDisplay()));
g.setItemCount(2);
gallery.setData(g);
}

for(AbstractProcess proc : ProcessRepository.getInstance().getAllProcesses()){
GalleryItem groupProc = new GalleryItem(gallery, SWT.NONE);
groupProc.setText(proc.getName());
for(Form form : ModelHelper.getAllFormsContainedIn(proc)){
GalleryItem g = new GalleryItem(groupProc, SWT.NONE);
g.setData("object", form);
g.setItemCount(2);
g.setText(0, form.getName());
//g.setImage(createImage(form));
}
}
//gallery.setItemCount(100);
}
}
//gallery.setItemCount(100);



--
Aurelien Pupier - BonitaSoft S.A.
"http://scratsh.wordpress.com/"


Aurélien Pupier - Bonitasoft S.A.
My company Eclipse-related blog
Re: Gallery with SWT.VIRTUAL [message #599359 is a reply to message #599334] Fri, 26 March 2010 07:05 Go to previous message
Nicolas Richeton is currently offline Nicolas RichetonFriend
Messages: 179
Registered: July 2009
Senior Member
Aurelien,

The virtual snippet works for me and SetData is tested in gallery unit
tests : you should be able to get events. Could you try to run the
snippet as-is and run the tests in
org.eclipse.nebula.widgets.gallery.tests to ensure there really is an issue.

Looking at your code, I have the following comments :
- Avoid mixing virtual and non virtual code : don't use new GalleryItem
() if you are using SWT.VIRTUAL and SWT.SetData at the same time. This
is because SetData will only be called if a visible item is
uninitialized (null) on paint.
-> mixing is supported by is likely to produce unexpected results.

- With SWT, ASAIK SetData, or Expand listeners are never attached to
items but to the container. With Gallery, listener added on items will
never be used.
Try to replace Gallery by Tree and compare the behavior. If they are
different, please open a bug.

- setData is used for linking some object to a widget. This is only for
your code and never used by swt nor Gallery.

--
Nicolas


Le 25/03/10 16:03, Aurelien Pupier a écrit :
> I tried with release and nightly version.
> I also already tried wihtout setting virtual groups.
>
> Here you can see what I've done, th ecommentary code is code that I
> tried. Notice that none of my listener is called.
> final Gallery gallery = new Gallery(bottomComposite, SWT.V_SCROLL |
> SWT.BORDER | SWT.VIRTUAL);
> gallery.setLayoutData(new GridData(330, 250));
> // Renderers
> DefaultGalleryGroupRenderer gr = new DefaultGalleryGroupRenderer();
> gr.setItemSize(150, 100);
> gr.setAlwaysExpanded(false);
> gr.setMinMargin(3);
> DefaultGalleryItemRenderer ir = new DefaultGalleryItemRenderer();
> ir.setShowLabels(true);
>
> gallery.setGroupRenderer(gr);
> gallery.setItemRenderer(ir);
>
> //gallery.setVirtualGroups(true);
>
> gallery.addListener(SWT.SetData, new Listener() {
>
> public void handleEvent(Event event) {
> //never going into
> 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
> if(item.getData("object") != null){
> if(item.getData("object") instanceof FormRepositoryArtifact){
> item.setImage(((FormRepositoryArtifact)item.getData("object " )).getImage(getShell().getDisplay()/*Display.getCurrent()*/) );
>
> } else if(item.getData("object") instanceof Form){
> item.setImage(createImage((Form) item.getData("object")));
> }
> }
> // item.setImage(eclipseImage);
> item.setText("Item " + index); //$NON-NLS-1$
> }
>
> });
> //gallery.setItemCount(100);
>
> GalleryItem groupTemplates = new GalleryItem(gallery, SWT.NONE);
> groupTemplates.setText("Templates");
> groupTemplates.addListener(SWT.SetData, new Listener(){
> public void handleEvent(Event event) {
> // TODO Auto-generated method stub
> System.out.println("test moi");
> }
> });
> groupTemplates.addListener(SWT.Expand, new Listener(){
> public void handleEvent(Event event) {
> // TODO Auto-generated method stub
> System.out.println("enfin un event qui marche?");
> }
> });
> gallery.setData(groupTemplates);
> for(FormRepositoryArtifact artifact :
> FormRepository.getInstance().getAllArtifacts()){
> GalleryItem g = new GalleryItem(groupTemplates, SWT.NONE);
> g.setText(0, artifact.getName());
> g.setText(1, ((Form)artifact.getContent()).getName());
> g.setData("object", artifact);
> //g.setImage(artifact.getImage(getShell().getDisplay()));
> g.setItemCount(2);
> gallery.setData(g);
> }
>
> for(AbstractProcess proc :
> ProcessRepository.getInstance().getAllProcesses()){
> GalleryItem groupProc = new GalleryItem(gallery, SWT.NONE);
> groupProc.setText(proc.getName());
> for(Form form : ModelHelper.getAllFormsContainedIn(proc)){
> GalleryItem g = new GalleryItem(groupProc, SWT.NONE);
> g.setData("object", form);
> g.setItemCount(2);
> g.setText(0, form.getName());
> final Gallery gallery = new Gallery(bottomComposite, SWT.V_SCROLL |
> SWT.BORDER | SWT.VIRTUAL);
> gallery.setLayoutData(new GridData(330, 250));
> // Renderers
> DefaultGalleryGroupRenderer gr = new DefaultGalleryGroupRenderer();
> gr.setItemSize(150, 100);
> gr.setAlwaysExpanded(false);
> gr.setMinMargin(3);
> DefaultGalleryItemRenderer ir = new DefaultGalleryItemRenderer();
> ir.setShowLabels(true);
>
> gallery.setGroupRenderer(gr);
> gallery.setItemRenderer(ir);
>
> //gallery.setVirtualGroups(true);
>
> gallery.addListener(SWT.SetData, new Listener() {
>
> public void handleEvent(Event event) {
> //never going into
> 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
> if(item.getData("object") != null){
> if(item.getData("object") instanceof FormRepositoryArtifact){
> item.setImage(((FormRepositoryArtifact)item.getData("object " )).getImage(getShell().getDisplay()/*Display.getCurrent()*/) );
>
> } else if(item.getData("object") instanceof Form){
> item.setImage(createImage((Form) item.getData("object")));
> }
> }
> // item.setImage(eclipseImage);
> item.setText("Item " + index); //$NON-NLS-1$
> }
>
> });
> //gallery.setItemCount(100);
>
> GalleryItem groupTemplates = new GalleryItem(gallery, SWT.NONE);
> groupTemplates.setText("Templates");
> groupTemplates.addListener(SWT.SetData, new Listener(){
> public void handleEvent(Event event) {
> //never going into
> System.out.println("test moi");
> }
> });
> groupTemplates.addListener(SWT.Expand, new Listener(){
> public void handleEvent(Event event) {
> //never going into
> }
> });
> gallery.setData(groupTemplates);
> for(FormRepositoryArtifact artifact :
> FormRepository.getInstance().getAllArtifacts()){
> GalleryItem g = new GalleryItem(groupTemplates, SWT.NONE);
> g.setText(0, artifact.getName());
> g.setText(1, ((Form)artifact.getContent()).getName());
> g.setData("object", artifact);
> //g.setImage(artifact.getImage(getShell().getDisplay()));
> g.setItemCount(2);
> gallery.setData(g);
> }
>
> for(AbstractProcess proc :
> ProcessRepository.getInstance().getAllProcesses()){
> GalleryItem groupProc = new GalleryItem(gallery, SWT.NONE);
> groupProc.setText(proc.getName());
> for(Form form : ModelHelper.getAllFormsContainedIn(proc)){
> GalleryItem g = new GalleryItem(groupProc, SWT.NONE);
> g.setData("object", form);
> g.setItemCount(2);
> g.setText(0, form.getName());
> //g.setImage(createImage(form));
> }
> }
> //gallery.setItemCount(100);
> }
> }
> //gallery.setItemCount(100);
>
>
>
Re: Gallery with SWT.VIRTUAL [message #599365 is a reply to message #523359] Fri, 26 March 2010 08:45 Go to previous message
Aurelien Pupier is currently offline Aurelien PupierFriend
Messages: 574
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

I run the tests and all is ok :)

I will take a look deeper asap to see what I misdone.

Thanks for your quick replies.
--
Aurelien Pupier - BonitaSoft S.A.
"http://scratsh.wordpress.com/"


Aurélien Pupier - Bonitasoft S.A.
My company Eclipse-related blog
Previous Topic:Using CalendarCombo as a table cell editor
Next Topic:Gallery with SWT.VIRTUAL
Goto Forum:
  


Current Time: Wed Nov 26 18:06:34 GMT 2014

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

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