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);
}
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();
}
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();
}
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;
}
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;
}
Aggregations