Search in sources :

Example 1 with ICmdManagerInternal

use of com.servoy.j2db.cmd.ICmdManagerInternal in project servoy-client by Servoy.

the class FormController method showNavigator.

@Override
public void showNavigator(List<Runnable> invokeLaterRunnables) {
    if (// safety for tabpanels (those cannot have a custom controller)
    fm != null && fm.getCurrentMainShowingFormController() == this) {
        ISupportNavigator navigatorSupport = fm.getCurrentContainer();
        if (navigatorSupport != null) {
            int form_id = form.getNavigatorID();
            if (form_id > 0) {
                FormController currentFC = navigatorSupport.getNavigator();
                if (// is already there
                currentFC == null || currentFC.getForm().getID() != form_id) {
                    try {
                        Form sliderDef = application.getFlattenedSolution().getForm(form_id);
                        if (sliderDef != null) {
                            // safety a slider Form CANNOT HAVE A SLIDER
                            if (sliderDef.getID() != form_id && sliderDef.getNavigatorID() >= 0)
                                return;
                            FormController nav = fm.getFormController(sliderDef.getName(), navigatorSupport);
                            ControllerUndoManager cum = null;
                            if (nav != null) {
                                nav.notifyVisible(true, invokeLaterRunnables);
                                cum = nav.getUndoManager();
                            }
                            if (application.getCmdManager() instanceof ICmdManagerInternal) {
                                ((ICmdManagerInternal) application.getCmdManager()).setControllerUndoManager(cum);
                            }
                            FormController old_nav = navigatorSupport.setNavigator(nav);
                            if (old_nav != null)
                                old_nav.notifyVisible(false, invokeLaterRunnables);
                        } else {
                            // Form deleted??
                            FormController old_nav = navigatorSupport.setNavigator(null);
                            if (old_nav != null)
                                old_nav.notifyVisible(false, invokeLaterRunnables);
                        }
                    } catch (Exception ex) {
                        Debug.error(ex);
                    }
                } else {
                    // Try to lease it extra so it will be added to last used screens.
                    Form sliderDef = application.getFlattenedSolution().getForm(form_id);
                    if (sliderDef != null) {
                        fm.leaseFormPanel(sliderDef.getName());
                        currentFC.notifyVisible(true, invokeLaterRunnables);
                    }
                }
            } else if (// if is ignore leave previous,if not remove
            form_id != Form.NAVIGATOR_IGNORE) {
                FormController old_nav = navigatorSupport.setNavigator(null);
                if (old_nav != null)
                    old_nav.notifyVisible(false, invokeLaterRunnables);
            }
        }
    }
}
Also used : ICmdManagerInternal(com.servoy.j2db.cmd.ICmdManagerInternal) Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) ServoyException(com.servoy.j2db.util.ServoyException)

Example 2 with ICmdManagerInternal

use of com.servoy.j2db.cmd.ICmdManagerInternal 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)

Aggregations

ICmdManagerInternal (com.servoy.j2db.cmd.ICmdManagerInternal)2 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)2 Form (com.servoy.j2db.persistence.Form)2 JSForm (com.servoy.j2db.BasicFormController.JSForm)1 InstanceJavaMembers (com.servoy.j2db.scripting.InstanceJavaMembers)1 SolutionScope (com.servoy.j2db.scripting.SolutionScope)1 ServoyException (com.servoy.j2db.util.ServoyException)1 ArrayList (java.util.ArrayList)1 NativeJavaObject (org.mozilla.javascript.NativeJavaObject)1