use of org.apache.pivot.wtk.AccordionSelectionListener in project pivot by apache.
the class Accordions method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
accordion = (Accordion) namespace.get("accordion");
accordion.getAccordionSelectionListeners().add(new AccordionSelectionListener() {
private int selectedIndex = -1;
@Override
public Vote previewSelectedIndexChange(Accordion accordionArgument, int selectedIndexArgument) {
this.selectedIndex = selectedIndexArgument;
// transition looks smoother
if (selectedIndexArgument != -1) {
int previousSelectedIndex = accordionArgument.getSelectedIndex();
if (selectedIndexArgument > previousSelectedIndex) {
accordionArgument.getPanels().get(selectedIndexArgument).setEnabled(true);
} else {
accordionArgument.getPanels().get(previousSelectedIndex).setEnabled(false);
}
}
return Vote.APPROVE;
}
@Override
public void selectedIndexChangeVetoed(Accordion accordionArgument, Vote reason) {
if (reason == Vote.DENY && selectedIndex != -1) {
Component panel = accordionArgument.getPanels().get(selectedIndex);
panel.setEnabled(!panel.isEnabled());
}
}
@Override
public void selectedIndexChanged(Accordion accordionArgument, int previousSelection) {
updateAccordion();
}
});
updateAccordion();
}
Aggregations