Search in sources :

Example 1 with SolutionScope

use of com.servoy.j2db.scripting.SolutionScope in project servoy-client by Servoy.

the class DebugClientHandler method setDesignerCallback.

/**
 * @param designerCallback the designerCallback to set
 */
public void setDesignerCallback(IDesignerCallback designerCallback) {
    this.designerCallback = designerCallback;
    if (debugJ2DBClient != null && debugJ2DBClient.getSolution() != null) {
        SolutionScope solutionScope = debugJ2DBClient.getScriptEngine().getSolutionScope();
        designerCallback.addScriptObjects(debugJ2DBClient, solutionScope);
    }
    if (debugWebClient != null && debugWebClient.getSolution() != null) {
        SolutionScope solutionScope = debugWebClient.getScriptEngine().getSolutionScope();
        designerCallback.addScriptObjects(debugWebClient, solutionScope);
    }
    if (debugNGClient != null && debugNGClient.getSolution() != null) {
        SolutionScope solutionScope = debugNGClient.getScriptEngine().getSolutionScope();
        designerCallback.addScriptObjects(debugNGClient, solutionScope);
    }
    if (debugHeadlessClient != null && debugHeadlessClient.getSolution() != null) {
        SolutionScope solutionScope = debugHeadlessClient.getScriptEngine().getSolutionScope();
        designerCallback.addScriptObjects(debugHeadlessClient, solutionScope);
    }
    for (IDebugClient c : customDebugClients.values()) {
        if (c.getSolution() != null) {
            SolutionScope solutionScope = c.getScriptEngine().getSolutionScope();
            designerCallback.addScriptObjects(c, solutionScope);
        }
    }
}
Also used : IDebugClient(com.servoy.j2db.IDebugClient) SolutionScope(com.servoy.j2db.scripting.SolutionScope)

Example 2 with SolutionScope

use of com.servoy.j2db.scripting.SolutionScope 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");
    }
}
Also used : NativeJavaObject(org.mozilla.javascript.NativeJavaObject) SolutionScope(com.servoy.j2db.scripting.SolutionScope) BasicFormController(com.servoy.j2db.BasicFormController)

Example 3 with SolutionScope

use of com.servoy.j2db.scripting.SolutionScope 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;
}
Also used : JSForm(com.servoy.j2db.BasicFormController.JSForm) Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) ArrayList(java.util.ArrayList) SolutionScope(com.servoy.j2db.scripting.SolutionScope) InstanceJavaMembers(com.servoy.j2db.scripting.InstanceJavaMembers) ICmdManagerInternal(com.servoy.j2db.cmd.ICmdManagerInternal) NativeJavaObject(org.mozilla.javascript.NativeJavaObject)

Example 4 with SolutionScope

use of com.servoy.j2db.scripting.SolutionScope in project servoy-client by Servoy.

the class BasicFormController method initForJSUsage.

// if the js init is not done , do!
public synchronized JSForm initForJSUsage() {
    if (formScope == null) {
        if (destroyed) {
            Debug.error("Calling initForJSUsage on a destroyed form: " + this, new RuntimeException("Calling initForJSUsage on a destroyed form: " + this));
            return null;
        }
        Context.enter();
        try {
            IExecutingEnviroment se = application.getScriptEngine();
            if (se != null) {
                SolutionScope solScope = application.getScriptEngine().getSolutionScope();
                // $NON-NLS-1$
                initForJSUsage((CreationalPrototype) solScope.get("forms", solScope));
            } else {
                // saw this happen on MAC debug smart client - edit the value in a combobox (change it) then directly click on the close window button;
                // shutDown executed first (windowClosing) - setting solution to null, then the combo item state change (generated by focus lost) event was triggered
                // $NON-NLS-1$
                Debug.log("Trying to initForJSUsage with null script engine - probably a method was about to be invoked post-shutdown", null);
            }
        } catch (Exception ex) {
            // $NON-NLS-1$
            application.reportError(application.getI18NMessage("servoy.formPanel.error.initScriptEngine"), ex);
        } finally {
            Context.exit();
        }
    }
    return scriptableForm;
}
Also used : IExecutingEnviroment(com.servoy.j2db.scripting.IExecutingEnviroment) ServoyException(com.servoy.j2db.util.ServoyException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) SolutionScope(com.servoy.j2db.scripting.SolutionScope)

Example 5 with SolutionScope

use of com.servoy.j2db.scripting.SolutionScope in project servoy-client by Servoy.

the class BasicFormManager method canBeDeleted.

protected boolean canBeDeleted(IFormController fp) {
    if (fp.isFormVisible()) {
        if (Debug.tracing())
            Debug.trace("Couldn't destroy form " + fp.getName() + "  instance because it is still visible");
        return false;
    }
    // cannot be deleted if a global var has a ref
    ScopesScope scopesScope = application.getScriptEngine().getScopesScope();
    if (hasReferenceInScriptable(scopesScope, fp, new HashSet<Scriptable>())) {
        if (Debug.tracing())
            Debug.trace("Couldn't destroy form " + fp.getName() + "  instance because it has references in scripting");
        return false;
    }
    if (fp.isFormExecutingFunction()) {
        if (Debug.tracing())
            Debug.trace("Couldn't destroy form " + fp.getName() + "  instance because it is executing a function");
        return false;
    }
    // if this controller uses a separate foundset
    if (fp.getForm().getUseSeparateFoundSet()) {
        // test if that foundset has edited records that can't be saved
        EditRecordList editRecordList = application.getFoundSetManager().getEditRecordList();
        if (editRecordList.stopIfEditing(fp.getFoundSet()) != ISaveConstants.STOPPED) {
            if (Debug.tracing())
                Debug.trace("Couldn't destroy form " + fp.getName() + "  instance because it has a seperate foundset that has editing records");
            return false;
        }
    }
    // the cached currentcontroller may not be destroyed
    SolutionScope ss = application.getScriptEngine().getSolutionScope();
    // $NON-NLS-1$
    return ss == null || fp.initForJSUsage() != ss.get("currentcontroller", ss);
}
Also used : EditRecordList(com.servoy.j2db.dataprocessing.EditRecordList) ScopesScope(com.servoy.j2db.scripting.ScopesScope) Scriptable(org.mozilla.javascript.Scriptable) SolutionScope(com.servoy.j2db.scripting.SolutionScope)

Aggregations

SolutionScope (com.servoy.j2db.scripting.SolutionScope)8 IExecutingEnviroment (com.servoy.j2db.scripting.IExecutingEnviroment)3 NativeJavaObject (org.mozilla.javascript.NativeJavaObject)3 InstanceJavaMembers (com.servoy.j2db.scripting.InstanceJavaMembers)2 ScopesScope (com.servoy.j2db.scripting.ScopesScope)2 BasicFormController (com.servoy.j2db.BasicFormController)1 JSForm (com.servoy.j2db.BasicFormController.JSForm)1 IDebugClient (com.servoy.j2db.IDebugClient)1 ICmdManagerInternal (com.servoy.j2db.cmd.ICmdManagerInternal)1 EditRecordList (com.servoy.j2db.dataprocessing.EditRecordList)1 IServoyAwareBean (com.servoy.j2db.dataui.IServoyAwareBean)1 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)1 Form (com.servoy.j2db.persistence.Form)1 RepositoryException (com.servoy.j2db.persistence.RepositoryException)1 CreationalPrototype (com.servoy.j2db.scripting.CreationalPrototype)1 IDestroyable (com.servoy.j2db.util.IDestroyable)1 ServoyException (com.servoy.j2db.util.ServoyException)1 ArrayList (java.util.ArrayList)1 Scriptable (org.mozilla.javascript.Scriptable)1