[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.technology.nebula] Re: select item in the gallery widget
|
Nicolas Richeton escribió:
Vicente Rico Guillén a écrit :
Nicolas Richeton escribió:
Vicente Rico Guillén a écrit :
Well. I'll explain better... and thanks for answer :-D
My app has 3 view modes: 2 tables and 1 gallery.
I have a button that rotates between these 3 views.
When the user push a button, the program rotates between these
views, as i said before. The program fill the view perfectly, but
when the selected view is populated, i want to show the first
elements (if not empty). The order is "selectItem(int itemNumber);"
Then, the code for tables is this:
public void selectItemNumber(int item) {
if (GlobalSettings.moviesList.size() > 0) {
moviesTable.setFocus();
moviesTable.setSelection(item);
moviesTable.notifyListeners(SWT.Selection, new Event());
return;
} else {
return;
}
}
This works for the tables, but with the gallery don't.
I've tried the same for gallery but it's impossible.
setSelection( int index) does not exist in the gallery yet, please
open a bug if you need it.
But you'll get the same result using :
Keep in mind that Gallery is a Tree and groups are root items. So you
need to call getItem() on the parent group of your item.
Excuse me, but it doesn't work. You said that with:
setSelection( galleryGroup.getItem( index ) )
i'll get the same result but:
In javadoc, says that the method setSelection needs a GalleryItem[]. I
mean, it needs an array of items. With your code, "getItem" returns
only an item, and Eclipse show error because this method expect an
array of GalleryItems and not only an item.
What i want to do is that, select ONLY an item: the first item.
In short:
I want select, programmatically the first item of a gallery after this
gallery is populated. I want this item selected, and painted in the
gallery as selected. In the other hand, setSelection only accept as
argument an array of galleryItems and not only a galleryItem.
How can this be done?? Have you any idea? Thanks!!!
What about creating an array ? ;-)
setSelection( new GalleryItem[]{ galleryGroup.getItem( index ) } );
It doesn't work. I get a nullpointerexception..
-------------------------------------------------------------------------------
java.lang.NullPointerException
at
org.eclipse.nebula.widgets.gallery.AbstractGridGroupRenderer.getVisibleItems(AbstractGridGroupRenderer.java:280)
at
org.eclipse.nebula.widgets.gallery.NoGroupRenderer.draw(NoGroupRenderer.java:43)
at org.eclipse.nebula.widgets.gallery.Gallery._drawGroup(Gallery.java:1339)
at org.eclipse.nebula.widgets.gallery.Gallery.onPaint(Gallery.java:1183)
at
org.eclipse.nebula.widgets.gallery.Gallery$2.paintControl(Gallery.java:586)
at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
--------------------------------------------------------------------------------
I show you the main code related to this:
------------------------------------------------
public void selectItemNumber(int number) {
if (GlobalSettings.moviesList.size() > 0) {
moviesGallery.setFocus();
moviesGallery.setSelection( new GalleryItem[]{ moviesGallery.getItem(
0 ) } );
moviesGallery.notifyListeners(SWT.Selection, new Event());
return;
} else {
return;
}
}
-------------------------------------------------
moviesGallery.addListener(SWT.SetData, new Listener() {
public void handleEvent(Event event) {
if (GlobalSettings.moviesList.size()==0) return;
GalleryItem item = (GalleryItem) event.item;
int index;
index = moviesGallery.indexOf(item);
Long movieID= GlobalSettings.moviesList.get(index);
String caratula = getCover(index);
if (StringUtils.isBlank(caratula)) {
caratula = "noCover.jpg";
}
item.setImage(new Image(GUI.display,baseDirForImages+caratula));
listaImagenes.add(item.getImage());
item.setData(movieID);
item.setItemCount(GlobalSettings.moviesList.size());
}
});
--------------------------------------------------------------------------
Globalsettings.movieslist is a LinkedList with movies Objects. And yes,
i'm developing a movie manager: www.visualdivx.org :-D
-------------------------------------------------------------------------------
moviesGallery.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
if (getSelectedMovies().size() == 0)
return;
Long alfa = (Long) getSelectedMovies().get(0);
long number = alfa.longValue();
gui.getDataBase().loadMovieObjectIntoMemory(number);
if (secundaryControl!=null) {
secundaryControl.fillData();
// IN SECUNDARYCONTROL.FILLDATA i fill a Browser control.
}else{
}
}
});