use of com.codename1.ui.util.EmbeddedContainer in project CodenameOne by codenameone.
the class LazyValueC method getFormNavigationStackForComponent.
private Vector getFormNavigationStackForComponent(Component c) {
if (baseFormNavigationStack == null) {
return null;
}
if (c == null) {
return baseFormNavigationStack;
}
Component root = getRootAncestor(c);
if (root.getParent() instanceof EmbeddedContainer) {
Vector nav = (Vector) root.getParent().getClientProperty("$baseNav");
if (nav == null) {
nav = new Vector();
root.getParent().putClientProperty("$baseNav", nav);
}
return nav;
}
return baseFormNavigationStack;
}
use of com.codename1.ui.util.EmbeddedContainer in project CodenameOne by codenameone.
the class LazyValueC method showContainerImpl.
private Container showContainerImpl(String resourceName, Command sourceCommand, Component sourceComponent, boolean forceBack) {
if (sourceComponent != null) {
Form currentForm = sourceComponent.getComponentForm();
// avoid the overhead of searching if no embedding is used
if (currentForm.getClientProperty(EMBEDDED_FORM_FLAG) != null) {
Container destContainer = sourceComponent.getParent();
while (!(destContainer instanceof EmbeddedContainer || destContainer instanceof Form)) {
// race condition, container was already removed by someone else
if (destContainer == null) {
return null;
}
destContainer = destContainer.getParent();
}
if (destContainer instanceof EmbeddedContainer) {
Container cnt = createContainer(fetchResourceFile(), resourceName, (EmbeddedContainer) destContainer);
if (cnt instanceof Form) {
// Form f = (Form)cnt;
// cnt = formToContainer(f);
showForm((Form) cnt, sourceCommand, sourceComponent);
return cnt;
}
Component fromCmp = destContainer.getComponentAt(0);
// This seems to be no longer necessary now that we have the replaceAndWait version that drops events
// block the user from the ability to press the button twice by mistake
// fromCmp.setEnabled(false);
boolean isBack = forceBack;
Transition t = fromCmp.getUIManager().getLookAndFeel().getDefaultFormTransitionOut();
if (forceBack) {
initBackContainer(cnt, destContainer.getComponentForm(), getFormNavigationStackForComponent(sourceComponent));
t = t.copy(true);
} else {
if (sourceCommand != null) {
if (t != null && backCommands != null && backCommands.contains(sourceCommand) || Display.getInstance().getCurrent().getBackCommand() == sourceCommand) {
isBack = true;
t = t.copy(true);
}
}
}
// create a back command if supported
String commandAction = cnt.getName();
Vector formNavigationStack = getFormNavigationStackForComponent(fromCmp);
if (formNavigationStack != null && !isBack && allowBackTo(commandAction) && !isSameBackDestination((Container) fromCmp, cnt)) {
// trigger listener creation if this is the only command in the form
getFormListenerInstance(destContainer.getComponentForm(), null);
formNavigationStack.addElement(getContainerState((com.codename1.ui.Container) fromCmp));
}
beforeShowContainer(cnt);
destContainer.replaceAndWait(fromCmp, cnt, t, true);
postShowContainer(cnt);
return cnt;
} else {
Container cnt = createContainer(fetchResourceFile(), resourceName);
showForm((Form) cnt, sourceCommand, sourceComponent);
return cnt;
}
}
}
Container cnt = createContainer(fetchResourceFile(), resourceName);
if (cnt instanceof Form) {
showForm((Form) cnt, sourceCommand, sourceComponent);
} else {
Form f = new Form();
f.setLayout(new BorderLayout());
f.addComponent(BorderLayout.CENTER, cnt);
f.setName("Form" + cnt.getName());
showForm(f, sourceCommand, sourceComponent);
}
return cnt;
}
use of com.codename1.ui.util.EmbeddedContainer in project CodenameOne by codenameone.
the class LazyValueC method createContainer.
Container createContainer(Resources res, String resourceName, EmbeddedContainer parentContainer) {
onCreateRoot(resourceName);
InputStream source = res.getUi(resourceName);
if (source == null) {
throw new RuntimeException("Resource doesn't exist within the current resource object: " + resourceName);
}
DataInputStream in = new DataInputStream(source);
try {
Hashtable h = null;
if (localComponentListeners != null) {
h = (Hashtable) localComponentListeners.get(resourceName);
}
Container c = (Container) createComponent(in, null, null, res, h, parentContainer);
c.setName(resourceName);
postCreateComponents(in, c, res);
// try to be smart about initializing the home form
if (homeForm == null) {
if (c instanceof Form) {
String nextForm = (String) c.getClientProperty("%next_form%");
if (nextForm != null) {
homeForm = nextForm;
} else {
homeForm = resourceName;
}
}
}
return c;
} catch (Exception ex) {
// If this happens its probably a serious bug
ex.printStackTrace();
return null;
}
}
use of com.codename1.ui.util.EmbeddedContainer in project CodenameOne by codenameone.
the class LazyValueC method back.
/**
* This method effectively pops the form navigation stack and goes back
* to the previous form if back navigation is enabled and there is
* a previous form.
*
* @param sourceComponent the component that triggered the back command which effectively
* allows us to find the EmbeddedContainer for a case of container navigation. Null
* can be used if not applicable.
*/
public void back(Component sourceComponent) {
Vector formNavigationStack = getFormNavigationStackForComponent(sourceComponent);
if (formNavigationStack != null && formNavigationStack.size() > 0) {
Hashtable h = (Hashtable) formNavigationStack.elementAt(formNavigationStack.size() - 1);
if (h.containsKey(FORM_STATE_KEY_CONTAINER)) {
Form currentForm = Display.getInstance().getCurrent();
if (currentForm != null) {
exitForm(currentForm);
}
}
String formName = (String) h.get(FORM_STATE_KEY_NAME);
if (!h.containsKey(FORM_STATE_KEY_CONTAINER)) {
Form f = (Form) createContainer(fetchResourceFile(), formName);
initBackForm(f);
onBackNavigation();
beforeShow(f);
f.showBack();
postShowImpl(f);
} else {
showContainerImpl(formName, null, sourceComponent, true);
}
}
}
use of com.codename1.ui.util.EmbeddedContainer in project CodenameOne by codenameone.
the class LazyValueC method getFormListenerInstance.
private FormListener getFormListenerInstance(Component cmp, EmbeddedContainer embedded) {
if (embedded != null) {
FormListener fc = (FormListener) embedded.getClientProperty("!FormListener!");
if (fc != null) {
return fc;
}
fc = new FormListener();
embedded.putClientProperty("!FormListener!", fc);
return fc;
}
Form f = cmp.getComponentForm();
if (f == null) {
return null;
}
FormListener fc = (FormListener) f.getClientProperty("!FormListener!");
if (fc != null) {
return fc;
}
fc = new FormListener();
f.putClientProperty("!FormListener!", fc);
f.addCommandListener(fc);
return fc;
}
Aggregations