Hello,
I’m trying to use Nifty 1.3 and I have some issues.
I add a screenController that managed Dropdown controls.
Until now, I had to specify that my ScreenController implements DropdownNotify.
[java]
public class CharacterJobsController implements ScreenController, DropDownControlNotify
[…]
DropDownControl = jobListing = screen.findControl( “jobListing”, DropDownControl.class );
[…]
jobListing.addNotify( this );
[…]
@Override
public void dropDownSelectionChanged( DropDownControl control )
{
if( control == jobListing )
loadDataForSelectedJob();
else […]
}
[/java]
For what I have understood, now I don’t need to specify the interface
[java]
public class CharacterJobsController implements ScreenController
[…]
@SuppressWarnings(“unchecked”)
DropDown<String> jobListing = screen.findNiftyControl(“jobListing”, DropDown.class);
[…]
@NiftyEventSubscriber(id=“dropDown”)
public void onDropDownSelectionChanged(final String id, final DropDownSelectionChangedEvent<String> event)
{
if( event == jobListing )
loadDataForSelectedJob();
else […]
}
[/java]
This new methods is really easier to read. Thanks
I just have one orr two question about the new Dropdown API :
- I didn’t find a getSelectedIndex() method. Is this a wanted miss ?
I suppose this works ( I still havn’t been able to compile my project so I didn’t verify ) :
[java]
int jobIndex = jobListing.getItems().indexOf( jobListing.getSelection() );
[/java]
- The method onDropDownSelectionChanged takes a DropDownSelectionChangedEvent. The previous method took the DropdownControl directly.
Is there a way to retrieve the dropdown control that triggered the event from the DropDownSelectionChangedEvent class ?
For now, I simply assumed that the DropDownSelectionChangedEvent is an interface of the same object .
( But like for the previous one. It compiles, but I still can’t check if my hypothesis is correct )
[java]
@NiftyEventSubscriber(id=“dropDown”)
public void onDropDownSelectionChanged(final String id, final DropDownSelectionChangedEvent<String> event)
{
if( event == jobListing )
loadDataForSelectedJob();
else […]
}
[/java]
Thanks in advance ! This version 1.3 is really promising.
Edit :
I just read the post : “ActionListener” for a nitfy checkbox?
It seems my solution won’t work for the second question.
In fact, I have two dropdown in my screen : “jobListing” and “jobPageListing”
This line is wrong then :
[java]
@NiftyEventSubscriber(id=“dropDown”)
[/java]
It should be something like
[java]
@SuppressWarnings(“unchecked”)
@NiftyEventSubscriber(id=“jobListing”)
@NiftyEventSubscriber(id=“jobPageListing”)
public void onDropDownSelectionChanged(final String id, final DropDownSelectionChangedEvent<String> event)
{
DropDown<String> control = screen.findNiftyControl( id, DropDown.class );
if( control == jobListing )
loadDataForSelectedJob();
else if( control == jobPageListing )
{
loadSkills();
updateJobDescription();
}
}
[/java]
I don’t really know how this annotation system works. Can you give me a tip?