Search in sources :

Example 1 with AccordionSelectionListener

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();
}
Also used : Vote(org.apache.pivot.util.Vote) Accordion(org.apache.pivot.wtk.Accordion) AccordionSelectionListener(org.apache.pivot.wtk.AccordionSelectionListener) Component(org.apache.pivot.wtk.Component)

Aggregations

Vote (org.apache.pivot.util.Vote)1 Accordion (org.apache.pivot.wtk.Accordion)1 AccordionSelectionListener (org.apache.pivot.wtk.AccordionSelectionListener)1 Component (org.apache.pivot.wtk.Component)1