Friday, June 22, 2012

LWUIT reloadForm()

In my app, I wanted to refresh the contents of the form (list). After looking into the UIBuilder source code, I found a method named reloadForm(). It worked as expected i.e. before method and list model init methods were called, however, it didn't put Back button in the refreshed form. To get around the issue, i implemented a method called refreshForm in StateMachine.java and added the back command explicitly. Back command addition code I got from showForm() method in UIBuilder.java. The method is as below-


private void refreshForm() {
        //reloadForm();
        Form currentForm = Display.getInstance().getCurrent();
        Form newForm = (Form) createContainer(fetchResourceFile(), currentForm.getName());
        Command backCommand = currentForm.getBackCommand();
        newForm.addCommand(backCommand, newForm.getCommandCount());
        newForm.setBackCommand(backCommand);
        beforeShow(newForm);
        Transition tin = newForm.getTransitionInAnimator();
        Transition tout = newForm.getTransitionOutAnimator();
        currentForm.setTransitionInAnimator(CommonTransitions.createEmpty());
        currentForm.setTransitionOutAnimator(CommonTransitions.createEmpty());
        newForm.setTransitionInAnimator(CommonTransitions.createEmpty());
        newForm.setTransitionOutAnimator(CommonTransitions.createEmpty());
        newForm.show();
        postShow(newForm);
        newForm.setTransitionInAnimator(tin);
        newForm.setTransitionOutAnimator(tout);
    }

I am not sure if the reloadForm() implementation has bug. I would soon put the issue in the LWUIT issue tracker.

Wednesday, May 30, 2012


Disable back command selectively in form

protected void beforeLandingPage(Form f) {
        // If the resource file changes the names of components this call will break notifying you that you should fix the code
        super.beforeLandingPage(f);
   
        /*
         * Disable back command in Landing Page - we don't want to go to login
         * screen
         */
        Command backCommand = f.getBackCommand();
        f.removeCommand(backCommand);
    }
prevent auto insertion of back command, put following in StateMachine.java --setBackCommandEnabled(false);