use of org.mozilla.javascript.NativeJavaObject in project servoy-client by Servoy.
the class FormManager method showFormInMainPanel.
// show a form in the main panel
public FormController showFormInMainPanel(final String formName, final IMainContainer container, final String title, final boolean closeAll, final 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"));
FormController currentMainShowingForm = null;
if (currentContainer != null) {
currentMainShowingForm = container.getController();
}
boolean containerSwitch = container != currentContainer;
if (currentMainShowingForm != null && formName.equals(currentMainShowingForm.getName()) && !containerSwitch && !design)
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) {
application.invokeLater(new Runnable() {
public void run() {
// $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 (!containerSwitch && application.getModeManager().getMode() != IModeManager.EDIT_MODE) {
application.getModeManager().setMode(IModeManager.EDIT_MODE);
}
FormController fp = leaseFormPanel(currentMainShowingForm.getName());
if (fp != null && !containerSwitch) {
List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>();
boolean ok = fp.notifyVisible(false, invokeLaterRunnables);
Utils.invokeLater(application, invokeLaterRunnables);
// solution closed in onhide method of previous form?
if (application.getSolution() == null)
return null;
if (!ok) {
selectFormMenuItem(currentMainShowingForm.getForm());
return fp;
}
}
}
// set main
FormController tmpForm = currentMainShowingForm;
final FormController fp = leaseFormPanel(formName);
currentMainShowingForm = fp;
currentContainer = container;
if (fp != null) {
if (application.getCmdManager() instanceof ICmdManagerInternal) {
((ICmdManagerInternal) application.getCmdManager()).setCurrentUndoManager(fp.getUndoManager());
}
boolean isNewUser = checkAndUpdateFormUser(fp, container);
IFormUIInternal formUI = fp.getFormUI();
if (isNewUser) {
container.add(fp.getFormUI(), formName);
}
if (formUI != null && !formUI.isVisible())
formUI.setComponentVisible(true);
// this code must be below the checkAndUpdateUser because setFormController can already set the formui
currentContainer.setController(fp);
SolutionScope ss = application.getScriptEngine().getSolutionScope();
Context.enter();
try {
// $NON-NLS-1$
ss.put("currentcontroller", ss, new NativeJavaObject(ss, fp.initForJSUsage(), new InstanceJavaMembers(ss, JSForm.class)));
} finally {
Context.exit();
}
fp.setView(fp.getView());
fp.executeOnLoadMethod();
// test if solution is closed in the onload method.
if (application.getSolution() == null)
return null;
// correct script menu for this form
fillScriptMenu();
// if this is first show and we have to mimic the legacy 3.1 behavior of dialogs (show all in 1 window), allow 100 forms
if (!container.isVisible() && !closeAll) {
((FormManager) application.getFormManager()).getHistory(currentContainer).clear(100);
}
// add to history
getHistory(currentContainer).add(fp.getName());
// check for programatic change
selectFormMenuItem(f);
// show panel as main
List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>();
fp.notifyVisible(true, invokeLaterRunnables);
// only enable command when it is the default container
// if (getMainContainer(null) == currentContainer)
// Command should rightly enabled for the forms
enableCmds(true);
final IMainContainer cachedContainer = currentContainer;
Runnable title_focus = new Runnable() {
public void run() {
FormController fc = cachedContainer.getController();
if (fc != null && fc == fp && application.getSolution() != null) {
// correct title
String titleText = title;
if (titleText == null)
titleText = f.getTitleText();
// $NON-NLS-1$
if (NO_TITLE_TEXT.equals(titleText))
titleText = "";
cachedContainer.setTitle(titleText);
cachedContainer.requestFocus();
}
}
};
if (isNewUser) {
final IMainContainer showContainer = currentContainer;
// to overcome paint problem in swing...
currentContainer.showBlankPanel();
invokeLaterRunnables.add(new Runnable() {
public void run() {
// only call show if it is still the right form.
FormController currentController = showContainer.getController();
if (currentController != null && fp.getName().equals(currentController.getName())) {
showContainer.show(fp.getName());
application.getRuntimeWindowManager().setCurrentWindowName(dialogName);
}
}
});
} else {
currentContainer.show(fp.getName());
application.getRuntimeWindowManager().setCurrentWindowName(dialogName);
}
invokeLaterRunnables.add(title_focus);
Utils.invokeLater(application, invokeLaterRunnables);
} else {
currentContainer.setController(null);
}
// $NON-NLS-1$
J2DBGlobals.firePropertyChange(this, "form", tmpForm, currentMainShowingForm);
return fp;
} catch (Exception e) {
Debug.error(e);
}
return null;
}
use of org.mozilla.javascript.NativeJavaObject in project servoy-client by Servoy.
the class SwingForm method registerComponentsToScope.
private int registerComponentsToScope(Scriptable fs, ElementScope es, int counter, Object[] comps, Object[] compsRenderer, Component controller, Map<String, Object[]> hmChildrenJavaMembers) {
if (comps != null) {
for (int j = 0; j < comps.length; j++) {
Object comp = comps[j];
if (comp instanceof PortalComponent) {
PortalComponent portal = (PortalComponent) comp;
counter = registerComponentsToScope(fs, es, counter, portal.getEditorComponents(), portal.getRendererComponents(), portal, hmChildrenJavaMembers);
}
String name = null;
if (comp instanceof IComponent) {
name = ((IComponent) comp).getName();
} else if (comp instanceof Component) {
name = ((Component) comp).getName();
}
Object obj = comp;
if (comp instanceof InvisibleBean) {
obj = ((InvisibleBean) comp).getDelegate();
} else if (comp instanceof VisibleBean) {
obj = ((VisibleBean) comp).getDelegate();
}
String groupName = FormElementGroup.getName((String) formController.getComponentProperty(comp, ComponentFactory.GROUPID_COMPONENT_PROPERTY));
if (obj instanceof IScriptableProvider)
obj = ((IScriptableProvider) obj).getScriptObject();
IRuntimeComponent baseMethodsObj = null;
if (obj instanceof IRuntimeComponent) {
baseMethodsObj = (IRuntimeComponent) obj;
}
JavaMembers jm = ScriptObjectRegistry.getJavaMembers(obj.getClass(), ScriptableObject.getTopLevelScope(fs));
// $NON-NLS-1$
boolean named = name != null && !name.equals("") && !name.startsWith(ComponentFactory.WEB_ID_PREFIX);
if (groupName != null || named) {
Object obj2 = null;
if (compsRenderer != null) {
obj2 = compsRenderer[j];
if (obj2 instanceof InvisibleBean) {
obj2 = ((InvisibleBean) obj2).getDelegate();
}
}
try {
Scriptable s = null;
if (obj2 != null) {
if (obj2 instanceof IScriptableProvider)
obj2 = ((IScriptableProvider) obj2).getScriptObject();
NativeJavaObject s2 = new NativeJavaObject(fs, obj2, jm);
s = new TwoNativeJavaObject(fs, obj, s2, jm, controller);
// group properties have to be set to both
if (groupName != null && obj2 instanceof IRuntimeComponent) {
if (baseMethodsObj == null) {
baseMethodsObj = (IRuntimeComponent) obj2;
} else {
RuntimeGroup runtimeGroup = new RuntimeGroup(baseMethodsObj.getName());
runtimeGroup.addScriptBaseMethodsObj(baseMethodsObj);
runtimeGroup.addScriptBaseMethodsObj((IRuntimeComponent) obj2);
baseMethodsObj = runtimeGroup;
}
}
} else {
s = new NativeJavaObject(fs, obj, jm);
}
if (named) {
es.put(name, fs, s);
es.put(counter++, fs, s);
hmChildrenJavaMembers.put(name, new Object[] { jm, obj });
}
if (groupName != null) {
Object group = es.get(groupName, fs);
if (group == Scriptable.NOT_FOUND) {
group = new NativeJavaObject(fs, new RuntimeGroup(groupName), ScriptObjectRegistry.getJavaMembers(RuntimeGroup.class, ScriptableObject.getTopLevelScope(fs)));
es.put(groupName, fs, group);
es.put(counter++, fs, group);
}
if (baseMethodsObj != null && group instanceof NativeJavaObject && ((NativeJavaObject) group).unwrap() instanceof RuntimeGroup) {
((RuntimeGroup) (((NativeJavaObject) group).unwrap())).addScriptBaseMethodsObj(baseMethodsObj);
}
}
} catch (Throwable ex) {
// incase classdefnot founds are thrown for beans,applets/plugins
Debug.error(ex);
}
}
}
}
return counter;
}
use of org.mozilla.javascript.NativeJavaObject in project servoy-client by Servoy.
the class NGFormManager method setCurrentControllerJS.
public void setCurrentControllerJS(IWebFormController currentController) {
if (currentController != null) {
SolutionScope ss = application.getScriptEngine().getSolutionScope();
Context.enter();
try {
// $NON-NLS-1$
ss.put(// $NON-NLS-1$
"currentcontroller", // $NON-NLS-1$
ss, new NativeJavaObject(ss, currentController.initForJSUsage(), ScriptObjectRegistry.getJavaMembers(com.servoy.j2db.BasicFormController.JSForm.class, ss)));
} finally {
Context.exit();
}
} else {
Debug.warn("A null current controller is tried to be set in the solution, very likely this is a problem with visibility of a form in a window");
}
}
use of org.mozilla.javascript.NativeJavaObject in project convertigo by convertigo.
the class DefaultInternalTranslator method addParameterObject.
private void addParameterObject(Document doc, Node parentItem, String parameterName, Object parameterObject) {
if (parameterObject instanceof NativeJavaObject) {
parameterObject = ((NativeJavaObject) parameterObject).unwrap();
}
if (parameterObject.getClass().isArray()) {
int len = Array.getLength(parameterObject);
for (int i = 0; i < len; i++) {
Object o = Array.get(parameterObject, i);
if (o != null) {
addParameterObject(doc, parentItem, parameterName, o);
}
}
} else if (parameterObject instanceof Node) {
Node node = (Node) parameterObject;
Element item = doc.createElement("variable");
item.setAttribute("name", parameterName);
if (bStrictMode) {
// append full structured node
if (node.getNodeType() == Node.ELEMENT_NODE) {
item.appendChild(doc.importNode(node, true));
} else {
item.setAttribute("value", node.getNodeValue());
}
} else {
// append only child nodes for a structured node
if (node.getNodeType() == Node.TEXT_NODE) {
item.setAttribute("value", node.getNodeValue());
} else {
NodeList nl = node.getChildNodes();
if (nl.getLength() == 1 && nl.item(0).getNodeType() == Node.TEXT_NODE) {
item.setAttribute("value", nl.item(0).getNodeValue());
} else {
node = doc.importNode(node, true);
nl = node.getChildNodes();
while (nl.getLength() > 0) {
item.appendChild(node.removeChild(nl.item(0)));
}
}
}
}
parentItem.appendChild(item);
} else if (parameterObject instanceof NodeList) {
NodeList nl = (NodeList) parameterObject;
int len = nl.getLength();
if (bStrictMode) {
Element item = doc.createElement("variable");
item.setAttribute("name", parameterName);
for (int i = 0; i < len; i++) {
Node node = nl.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
item.appendChild(doc.importNode(node, true));
} else {
item.setAttribute("value", node.getNodeValue());
}
}
parentItem.appendChild(item);
} else {
for (int i = 0; i < len; i++) {
addParameterObject(doc, parentItem, parameterName, nl.item(i));
}
}
} else if (parameterObject instanceof XMLVector) {
XMLVector<Object> values = GenericUtils.cast(parameterObject);
for (Object object : values) {
addParameterObject(doc, parentItem, parameterName, object);
}
} else if (parameterObject instanceof List) {
List<Object> list = GenericUtils.cast(parameterObject);
for (Object object : list) {
addParameterObject(doc, parentItem, parameterName, object);
}
} else {
Element item = doc.createElement("variable");
item.setAttribute("name", parameterName);
item.setAttribute("value", parameterObject.toString());
parentItem.appendChild(item);
}
}
use of org.mozilla.javascript.NativeJavaObject in project convertigo by convertigo.
the class Step method evaluate.
protected void evaluate(Context javascriptContext, Scriptable scope, String source, String sourceName, boolean bDialog) throws EngineException {
org.mozilla.javascript.Context jsContext = null;
if (javascriptContext == null) {
// evalution of step's property at design time
jsContext = org.mozilla.javascript.Context.enter();
scope = jsContext.initStandardObjects(null);
javascriptContext = jsContext;
}
String message = null;
evaluated = null;
try {
evaluated = RhinoUtils.evalCachedJavascript(javascriptContext, scope, source, sourceName, 1, null);
if (evaluated != null && evaluated instanceof NativeJavaObject) {
evaluated = ((NativeJavaObject) evaluated).unwrap();
}
} catch (EcmaError e) {
message = "Unable to evaluate step expression code for '" + sourceName + "' property or variable.\n" + "Step: \"" + getName() + "\"\n" + "A Javascript runtime error has occured at line " + e.lineNumber() + ", column " + e.columnNumber() + ": " + e.getMessage() + " \n" + e.lineSource();
logException(e, message, bDialog);
} catch (EvaluatorException e) {
message = "Unable to evaluate step expression code for '" + sourceName + "' property or variable.\n" + "Step: \"" + getName() + "\"\n" + "A Javascript evaluation error has occured: " + e.getMessage();
logException(e, message, bDialog);
} catch (JavaScriptException e) {
message = "Unable to evaluate step expression code for '" + sourceName + "' property or variable.\n" + "Step: \"" + getName() + "\"\n" + "A Javascript error has occured: " + e.getMessage();
logException(e, message, bDialog);
} finally {
if (jsContext != null) {
org.mozilla.javascript.Context.exit();
}
if (message != null) {
EngineException ee = new EngineException(message);
throw ee;
}
}
}
Aggregations