use of com.servoy.j2db.persistence.Form in project servoy-client by Servoy.
the class NGFormManager method showFormInContainer.
@Override
public IFormController showFormInContainer(String formName, IBasicMainContainer container, String title, boolean closeAll, String dialogName) {
if (loginForm != null && loginForm.getName() != formName) {
// not allowed to leave here...or show anything else than login form
return null;
}
// $NON-NLS-1$
if (formName == null)
throw new IllegalArgumentException(application.getI18NMessage("servoy.formManager.error.SettingVoidForm"));
IFormController currentMainShowingForm = container.getController();
boolean sameForm = (currentMainShowingForm != null && formName.equals(currentMainShowingForm.getName()));
if (sameForm && currentMainShowingForm.isFormVisible())
return leaseFormPanel(currentMainShowingForm.getName());
final Form f = possibleForms.get(formName);
if (f == null) {
return null;
}
try {
int access = application.getFlattenedSolution().getSecurityAccess(f.getUUID(), f.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
if (access != -1) {
boolean b_visible = ((access & IRepository.VIEWABLE) != 0);
if (!b_visible) {
// $NON-NLS-1$
application.reportWarningInStatus(application.getI18NMessage("servoy.formManager.warningAccessForm"));
return null;
}
}
// handle old panel
if (currentMainShowingForm != null) {
// leave forms in browse mode // TODO can this be set if notifyVisible returns false (current form is being kept)
if (application.getModeManager().getMode() != IModeManager.EDIT_MODE) {
application.getModeManager().setMode(IModeManager.EDIT_MODE);
}
IWebFormController fp = leaseFormPanel(currentMainShowingForm.getName());
if (fp != null && !sameForm) {
List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>();
boolean ok = fp.notifyVisible(false, invokeLaterRunnables);
if (invokeLaterRunnables.size() > 0)
wrapInShowLoadingIndicator(invokeLaterRunnables);
Utils.invokeLater(application, invokeLaterRunnables);
// solution closed in onhide method of previous form?
if (application.getSolution() == null)
return null;
if (!ok) {
return fp;
}
}
}
// set main
IFormController tmpForm = currentMainShowingForm;
final IWebFormController fp = leaseFormPanel(formName);
currentMainShowingForm = fp;
if (fp != null) {
// test if solution is closed in the onload method.
if (application.getSolution() == null)
return null;
setCurrentControllerJS(fp);
// add to history
getHistory(container).add(fp.getName());
container.setController(fp);
// show panel as main
List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>();
fp.notifyVisible(true, invokeLaterRunnables);
String titleText = title;
if (titleText == null)
titleText = f.getTitleText();
// $NON-NLS-1$
if (titleText == null || titleText.equals(""))
titleText = fp.getName();
// $NON-NLS-1$
if (NO_TITLE_TEXT.equals(titleText))
titleText = "";
container.setTitle(titleText);
fp.getFormUI().setParentWindowName(container.getContainerName());
if (invokeLaterRunnables.size() > 0)
wrapInShowLoadingIndicator(invokeLaterRunnables);
Utils.invokeLater(application, invokeLaterRunnables);
} else {
container.setController(null);
}
// $NON-NLS-1$
J2DBGlobals.firePropertyChange(this, "form", tmpForm, currentMainShowingForm);
return fp;
} catch (Exception e) {
Debug.error(e);
}
return null;
}
use of com.servoy.j2db.persistence.Form in project servoy-client by Servoy.
the class NGFormManager method makeSolutionSettings.
public void makeSolutionSettings(Solution s) {
Solution solution = s;
Iterator<Form> e = application.getFlattenedSolution().getForms(true);
// add all forms first, they may be referred to in the login form
Form first = application.getFlattenedSolution().getForm(solution.getFirstFormID());
boolean firstFormCanBeInstantiated = application.getFlattenedSolution().formCanBeInstantiated(first);
if (!firstFormCanBeInstantiated) {
Solution[] modules = application.getFlattenedSolution().getModules();
if (modules != null) {
for (Solution module : modules) {
if (module.getFirstFormID() > 0) {
first = application.getFlattenedSolution().getForm(module.getFirstFormID());
firstFormCanBeInstantiated = application.getFlattenedSolution().formCanBeInstantiated(first);
if (firstFormCanBeInstantiated)
break;
}
}
}
}
while (e.hasNext()) {
Form form = e.next();
if (application.getFlattenedSolution().formCanBeInstantiated(form)) {
if (!firstFormCanBeInstantiated)
first = form;
firstFormCanBeInstantiated = true;
}
// add anyway, the form may be used in scripting
addForm(form, form.equals(first));
}
if (firstFormCanBeInstantiated) {
// start in browse mode
application.getModeManager().setMode(IModeManager.EDIT_MODE);
}
boolean showLoginForm = (solution.getLoginFormID() > 0 && solution.getMustAuthenticate() && application.getUserUID() == null);
if (application.getUserUID() == null) {
ScriptMethod onBeforeLogin = application.getFlattenedSolution().getScriptMethod(solution.getOnBeforeLoginMethodID());
if (onBeforeLogin != null) {
try {
Object[] paramArray = null;
Object[] clientArray = ((ClientState) application).getPreferedSolutionMethodArguments();
if (clientArray != null && clientArray.length > 1) {
paramArray = new Object[] { clientArray[1] };
}
application.getScriptEngine().getScopesScope().executeGlobalFunction(onBeforeLogin.getScopeName(), onBeforeLogin.getName(), Utils.arrayMerge(paramArray, Utils.parseJSExpressions(solution.getFlattenedMethodArguments("onBeforeLoginMethodID"))), false, false);
} catch (Exception e1) {
application.reportError(// $NON-NLS-1$
Messages.getString("servoy.formManager.error.ExecutingOpenSolutionMethod", new Object[] { onBeforeLogin.getName() }), e1);
}
}
}
if (solution.getLoginFormID() > 0 && solution.getMustAuthenticate() && application.getUserUID() == null) {
Form login = application.getFlattenedSolution().getForm(solution.getLoginFormID());
if (application.getFlattenedSolution().formCanBeInstantiated(login) && loginForm == null) {
// must set the login form early so its even correct if onload of login form is called
loginForm = login;
showFormInMainPanel(login.getName());
// stop and recall this method from security.login(...)!
return;
}
} else if (showLoginForm) {
// there was a login in onBeforeLogin, so only second call to makeSolutionSettings should go further
return;
}
IBasicMainContainer currentContainer = getCurrentContainer();
if (solution.getLoginFormID() > 0 && solution.getMustAuthenticate() && application.getUserUID() != null && loginForm != null) {
if (currentContainer.getController() != null && loginForm.getName().equals(currentContainer.getController().getForm().getName())) {
hideFormIfVisible(currentContainer.getController());
currentContainer.setController(null);
}
// clear and continue
loginForm = null;
}
ScriptMethod sm = application.getFlattenedSolution().getScriptMethod(solution.getOnOpenMethodID());
Object[] solutionOpenMethodArgs = null;
String preferedSolutionMethodName = ((ClientState) application).getPreferedSolutionMethodNameToCall();
if (preferedSolutionMethodName == null && ((ClientState) application).getPreferedSolutionMethodArguments() != null) {
solutionOpenMethodArgs = ((ClientState) application).getPreferedSolutionMethodArguments();
}
if (sm != null) {
try {
application.getScriptEngine().getScopesScope().executeGlobalFunction(sm.getScopeName(), sm.getName(), Utils.arrayMerge(solutionOpenMethodArgs, Utils.parseJSExpressions(solution.getFlattenedMethodArguments("onOpenMethodID"))), false, false);
if (application.getSolution() == null)
return;
} catch (Exception e1) {
// $NON-NLS-1$
application.reportError(Messages.getString("servoy.formManager.error.ExecutingOpenSolutionMethod", new Object[] { sm.getName() }), e1);
}
}
if (first != null && getCurrentForm() == null) {
// we only set if the solution startup did not yet show a form already
showFormInMainPanel(first.getName());
}
if (preferedSolutionMethodName != null && (application.getFlattenedSolution().isMainSolutionLoaded() || solution.getSolutionType() == SolutionMetaData.LOGIN_SOLUTION)) {
try {
Object[] args = ((ClientState) application).getPreferedSolutionMethodArguments();
Pair<String, String> scope = ScopesUtils.getVariableScope(preferedSolutionMethodName);
GlobalScope gs = application.getScriptEngine().getScopesScope().getGlobalScope(scope.getLeft());
if (// make sure the function is found before resetting preferedSolutionMethodName
gs != null && gs.get(scope.getRight()) instanceof Function) {
// avoid stack overflows when an execute method URL is used to open the solution, and that method does call JSSecurity login
((ClientState) application).resetPreferedSolutionMethodNameToCall();
Object result = application.getScriptEngine().getScopesScope().executeGlobalFunction(scope.getLeft(), scope.getRight(), args, false, false);
if (application.getSolution().getSolutionType() == SolutionMetaData.AUTHENTICATOR) {
application.getRuntimeProperties().put(IServiceProvider.RT_OPEN_METHOD_RESULT, result);
}
} else if (application.getFlattenedSolution().isMainSolutionLoaded()) {
Debug.error("Preferred method '" + preferedSolutionMethodName + "' not found in " + application.getFlattenedSolution() + ".");
((ClientState) application).resetPreferedSolutionMethodNameToCall();
}
} catch (Exception e1) {
// $NON-NLS-1$
application.reportError(// $NON-NLS-1$
Messages.getString("servoy.formManager.error.ExecutingOpenSolutionMethod", new Object[] { preferedSolutionMethodName }), e1);
}
}
}
use of com.servoy.j2db.persistence.Form in project servoy-client by Servoy.
the class NGFormManager method leaseFormPanel.
@Override
public IWebFormController leaseFormPanel(String formName) {
if (formName == null)
return null;
String name = formName;
IWebFormController fp = createdFormControllers.get(name);
if (fp == null) {
Form f = possibleForms.get(formName);
if (f == null)
return null;
try {
// $NON-NLS-1$
application.blockGUII18NMessage("servoy.formManager.loadingForm", formName);
f = application.getFlattenedSolution().getFlattenedForm(f, false);
fp = new WebFormController((INGApplication) application, f, name);
createdFormControllers.put(fp.getName(), fp);
fp.init();
updateLeaseHistory(fp);
fp.setView(fp.getView());
fp.executeOnLoadMethod();
} finally {
application.releaseGUI();
}
} else {
addAsLastInLeaseHistory(fp);
}
return fp;
}
use of com.servoy.j2db.persistence.Form in project servoy-client by Servoy.
the class ContainersScope method findFormComponentContainers.
private static void findFormComponentContainers(Iterator<WebComponent> components, Map<String, List<String>> namesToLayout, FlattenedSolution fs) {
while (components.hasNext()) {
WebComponent component = components.next();
String typeName = (String) component.getProperty(IContentSpecConstants.PROPERTY_TYPENAME);
WebComponentSpecProvider.getInstance();
WebObjectSpecification spec = WebComponentSpecProvider.getSpecProviderState().getWebComponentSpecification(typeName);
if (spec != null) {
Collection<PropertyDescription> pd = spec.getProperties(FormComponentPropertyType.INSTANCE);
if (pd != null && !pd.isEmpty()) {
PropertyDescription prop = pd.iterator().next();
Object val = component.getProperty(prop.getName());
Form fcomp = FormComponentPropertyType.INSTANCE.getForm(val, fs);
if (fcomp != null && fcomp.isResponsiveLayout()) {
fillNames(fcomp.getLayoutContainers(), namesToLayout, fs);
}
}
}
}
}
use of com.servoy.j2db.persistence.Form in project servoy-client by Servoy.
the class ServoyFunctionPropertyType method toJSON.
public JSONWriter toJSON(JSONWriter writer, String key, Object object, PropertyDescription pd, DataConversion clientConversion, FlattenedSolution fs, FormElement fe, WebFormComponent formComponent) throws JSONException {
Map<String, Object> map = new HashMap<>();
if (object != null && fs != null) {
// $NON-NLS-1$
String[] components = object.toString().split("-");
if (components.length == 5) {
String scriptString = null;
// this is a uuid
ScriptMethod sm = fs.getScriptMethod(object.toString());
if (sm != null) {
ISupportChilds parent = sm.getParent();
if (parent instanceof Solution) {
scriptString = "scopes." + sm.getScopeName() + "." + sm.getName();
} else if (parent instanceof Form) {
if (formComponent != null) {
// use the real, runtime form
scriptString = formComponent.getDataAdapterList().getForm().getForm().getName() + "." + sm.getName();
} else {
scriptString = ((Form) parent).getName() + "." + sm.getName();
}
} else if (parent instanceof TableNode && fe != null) {
scriptString = "entity." + fe.getForm().getName() + "." + sm.getName();
}
object = scriptString;
} else
Debug.log("can't find a scriptmethod for: " + object);
}
}
try {
if (object instanceof String) {
addScriptToMap((String) object, map);
} else if (object instanceof NativeFunction) {
nativeFunctionToJSON((NativeFunction) object, map);
} else if (object instanceof FunctionWrapper && ((FunctionWrapper) object).getWrappedFunction() instanceof NativeFunction) {
nativeFunctionToJSON((NativeFunction) ((FunctionWrapper) object).getWrappedFunction(), map);
} else if (object instanceof Map) {
map = new HashMap<String, Object>((Map<String, Object>) object);
if (map.get("script") instanceof String)
addScriptToMap((String) map.get("script"), map);
}
} catch (Exception ex) {
Debug.error(ex);
}
return JSONUtils.toBrowserJSONFullValue(writer, key, map.size() == 0 ? null : map, null, clientConversion, null);
}
Aggregations