Search in sources :

Example 6 with ViewController

use of com.codename1.rad.controllers.ViewController in project CodeRAD by shannah.

the class ControllerEvent method getViewController.

public ViewController getViewController() {
    Object source = getSource();
    if (source instanceof Controller) {
        return ((Controller) source).getViewController();
    }
    Component cmp = getComponent();
    if (cmp == null) {
        return null;
    }
    return ViewController.getViewController(cmp);
}
Also used : Component(com.codename1.ui.Component)

Example 7 with ViewController

use of com.codename1.rad.controllers.ViewController in project CodeRAD by shannah.

the class ControllerEvent method getApplicationController.

public ApplicationController getApplicationController() {
    ViewController ctl = getViewController();
    if (ctl == null) {
        Form f = CN.getCurrentForm();
        if (f == null) {
            return null;
        }
        ctl = ViewController.getViewController(f);
    }
    if (ctl == null)
        return null;
    return ctl.getApplicationController();
}
Also used : Form(com.codename1.ui.Form)

Example 8 with ViewController

use of com.codename1.rad.controllers.ViewController in project CodeRAD by shannah.

the class FormController method showBack.

/**
 * Shows this controller's form using the "back" animation.  If the current controller is an instance of {@link AutoCloseable},
 * then this will first attempt to call {@link AutoCloseable#close() } on the current form first.  If it throws an exception,
 * then that exception will be swallowed, but the showBack() action will be cancelled.
 */
public void showBack() {
    Form currForm = CN.getCurrentForm();
    if (currForm != null) {
        ViewController currentController = getViewController(currForm);
        if (currentController instanceof AutoCloseable) {
            AutoCloseable ac = (AutoCloseable) currentController;
            try {
                ac.close();
            } catch (Exception ex) {
                return;
            }
        }
    }
    getView().showBack();
}
Also used : Form(com.codename1.ui.Form)

Example 9 with ViewController

use of com.codename1.rad.controllers.ViewController in project CodeRAD by shannah.

the class ViewController method getViewController.

/**
 * Gets the ViewController associated with this component.  This will
 * return the "nearest" view controller found in the view hierarchy.  I.e.
 * If the {@literal cmp} has no view controller, then it will look in the
 * parent container, and it's parent, if necessary, all the way up to
 *  the Form.
 *
 * @param cmp Component whose ViewController we wish to retrieve.
 * @return The ViewController for the component.
 */
public static ViewController getViewController(Component cmp) {
    Component orig = cmp;
    ViewController ctrl = (ViewController) cmp.getClientProperty(KEY);
    if (ctrl != null) {
        ctrl.startControllerInternal();
        return ctrl;
    }
    cmp = orig.getOwner();
    if (cmp != null) {
        ctrl = getViewController(cmp);
        if (ctrl != null) {
            ctrl.startControllerInternal();
            return ctrl;
        }
    }
    cmp = orig.getParent();
    if (cmp != null) {
        ctrl = getViewController(cmp);
        if (ctrl != null) {
            ctrl.startControllerInternal();
            return ctrl;
        }
    }
    return null;
}
Also used : Component(com.codename1.ui.Component)

Example 10 with ViewController

use of com.codename1.rad.controllers.ViewController in project CodeRAD by shannah.

the class ViewController method getNearestViewModel.

/**
 * Crawls up controller hierarchy until it finds a controller with an attached view model.
 * @return The nearest view model or null.
 */
public Entity getNearestViewModel() {
    Entity vm = getViewModel();
    Controller parent = getParent();
    while (parent != null) {
        if (parent instanceof ViewController) {
            ViewController parentVC = (ViewController) parent;
            vm = parentVC.getViewModel();
            if (vm != null) {
                return vm;
            }
        }
        parent = parent.getParent();
    }
    return null;
}
Also used : Entity(com.codename1.rad.models.Entity)

Aggregations

Form (com.codename1.ui.Form)5 Component (com.codename1.ui.Component)4 Entity (com.codename1.rad.models.Entity)3 Log (com.codename1.io.Log)2 NetworkEvent (com.codename1.io.NetworkEvent)2 ViewController (com.codename1.rad.controllers.ViewController)2 EntityList (com.codename1.rad.models.EntityList)2 EntityTypeBuilder.entityTypeBuilder (com.codename1.rad.models.EntityTypeBuilder.entityTypeBuilder)2 ActionNode (com.codename1.rad.nodes.ActionNode)2 ListNode (com.codename1.rad.nodes.ListNode)2 Thing (com.codename1.rad.schemas.Thing)2 UI (com.codename1.rad.ui.UI)2 ProfileListView (com.codename1.rad.ui.entityviews.ProfileListView)2 CN (com.codename1.ui.CN)2 Dialog (com.codename1.ui.Dialog)2 Display (com.codename1.ui.Display)2 FontImage (com.codename1.ui.FontImage)2 Label (com.codename1.ui.Label)2 Toolbar (com.codename1.ui.Toolbar)2 BorderLayout (com.codename1.ui.layouts.BorderLayout)2