Search in sources :

Example 1 with IFormUIInternal

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

the class WebTabFormLookup method notifyVisible.

public boolean notifyVisible(boolean b, List invokeLaterRunnables) {
    if (isReady()) {
        IFormUIInternal ui = webForm;
        FormController child = ui.getController();
        return child.notifyVisible(b, invokeLaterRunnables);
    }
    return true;
}
Also used : FormController(com.servoy.j2db.FormController) IFormUIInternal(com.servoy.j2db.IFormUIInternal)

Example 2 with IFormUIInternal

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

the class TemplateGenerator method getFormHTMLAndCSS.

public static Pair<String, String> getFormHTMLAndCSS(Solution solution, Form form, IServiceProvider sp, String formInstanceName) throws RepositoryException, RemoteException {
    if (form == null)
        return null;
    final IRepository repository = ApplicationServerRegistry.get().getLocalRepository();
    boolean enableAnchoring = sp != null ? Utils.getAsBoolean(sp.getRuntimeProperties().get("enableAnchors")) : Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.webclient.enableAnchors", Boolean.TRUE.toString()));
    String overriddenStyleName = null;
    Pair<String, ArrayList<Pair<String, String>>> retval = formCache.getFormAndCssPair(form, formInstanceName, overriddenStyleName, repository);
    Form f = form;
    FlattenedSolution fsToClose = null;
    try {
        if (retval == null) {
            if (f.getExtendsID() > 0) {
                FlattenedSolution fs = sp == null ? null : sp.getFlattenedSolution();
                if (fs == null) {
                    try {
                        IApplicationServer as = ApplicationServerRegistry.getService(IApplicationServer.class);
                        fsToClose = fs = new FlattenedSolution(solution.getSolutionMetaData(), new AbstractActiveSolutionHandler(as) {

                            @Override
                            public IRepository getRepository() {
                                return repository;
                            }
                        });
                    } catch (RepositoryException e) {
                        Debug.error("Couldn't create flattened form for the template generator", e);
                    }
                }
                f = fs.getFlattenedForm(f);
                if (f == null) {
                    Debug.log("TemplateGenerator couldn't get a FlattenedForm for " + form + ", solution closed?");
                    f = form;
                }
            }
            StringBuffer html = new StringBuffer();
            TextualCSS css = new TextualCSS();
            IFormLayoutProvider layoutProvider = FormLayoutProviderFactory.getFormLayoutProvider(sp, solution, f, formInstanceName);
            int viewType = layoutProvider.getViewType();
            layoutProvider.renderOpenFormHTML(html, css);
            int startY = 0;
            Iterator<Part> parts = f.getParts();
            while (parts.hasNext()) {
                Part part = parts.next();
                int endY = part.getHeight();
                if (Part.rendersOnlyInPrint(part.getPartType())) {
                    startY = part.getHeight();
                    // is never shown (=printing only)
                    continue;
                }
                Color bgColor = ComponentFactory.getPartBackground(sp, part, f);
                if (part.getPartType() == Part.BODY && (viewType == FormController.TABLE_VIEW || viewType == FormController.LOCKED_TABLE_VIEW || viewType == IForm.LIST_VIEW || viewType == FormController.LOCKED_LIST_VIEW)) {
                    layoutProvider.renderOpenTableViewHTML(html, css, part);
                    // tableview == bodypart
                    createCellBasedView(f, f, html, css, layoutProvider.needsHeaders(), startY, endY, bgColor, sp, viewType, enableAnchoring, startY, endY);
                    layoutProvider.renderCloseTableViewHTML(html);
                } else {
                    layoutProvider.renderOpenPartHTML(html, css, part);
                    placePartElements(f, startY, endY, html, css, bgColor, enableAnchoring, sp);
                    layoutProvider.renderClosePartHTML(html, part);
                }
                startY = part.getHeight();
            }
            layoutProvider.renderCloseFormHTML(html);
            retval = new Pair<String, ArrayList<Pair<String, String>>>(html.toString(), css.getAsSelectorValuePairs());
            formCache.putFormAndCssPair(form, formInstanceName, overriddenStyleName, repository, retval);
        }
        Map<String, String> formIDToMarkupIDMap = null;
        if (sp instanceof IApplication) {
            Map runtimeProps = sp.getRuntimeProperties();
            Map<WebForm, Map<String, String>> clientFormsIDToMarkupIDMap = (Map<WebForm, Map<String, String>>) runtimeProps.get("WebFormIDToMarkupIDCache");
            if (clientFormsIDToMarkupIDMap == null) {
                clientFormsIDToMarkupIDMap = new WeakHashMap<WebForm, Map<String, String>>();
                runtimeProps.put("WebFormIDToMarkupIDCache", clientFormsIDToMarkupIDMap);
            }
            IForm wfc = ((IApplication) sp).getFormManager().getForm(formInstanceName);
            if (wfc instanceof FormController) {
                IFormUIInternal wf = ((FormController) wfc).getFormUI();
                if (wf instanceof WebForm) {
                    if (!((WebForm) wf).isUIRecreated())
                        formIDToMarkupIDMap = clientFormsIDToMarkupIDMap.get(wf);
                    if (formIDToMarkupIDMap == null) {
                        ArrayList<Pair<String, String>> formCSS = retval.getRight();
                        ArrayList<String> selectors = new ArrayList<String>(formCSS.size());
                        for (Pair<String, String> formCSSEntry : formCSS) selectors.add(formCSSEntry.getLeft());
                        formIDToMarkupIDMap = getWebFormIDToMarkupIDMap((WebForm) wf, selectors);
                        clientFormsIDToMarkupIDMap.put((WebForm) wf, formIDToMarkupIDMap);
                    }
                }
            }
        }
        String webFormCSS = getWebFormCSS(retval.getRight(), formIDToMarkupIDMap);
        // string the formcss/solutionname/ out of the url.
        webFormCSS = StripHTMLTagsConverter.convertMediaReferences(webFormCSS, solution.getName(), new ResourceReference("media"), "", false).toString();
        return new Pair<String, String>(retval.getLeft(), webFormCSS);
    } finally {
        if (fsToClose != null) {
            fsToClose.close(null);
        }
    }
}
Also used : IForm(com.servoy.j2db.IForm) Form(com.servoy.j2db.persistence.Form) WebForm(com.servoy.j2db.server.headlessclient.WebForm) WebForm(com.servoy.j2db.server.headlessclient.WebForm) ArrayList(java.util.ArrayList) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IForm(com.servoy.j2db.IForm) AbstractActiveSolutionHandler(com.servoy.j2db.AbstractActiveSolutionHandler) ResourceReference(org.apache.wicket.ResourceReference) IFormUIInternal(com.servoy.j2db.IFormUIInternal) Pair(com.servoy.j2db.util.Pair) FormController(com.servoy.j2db.FormController) Color(java.awt.Color) IApplicationServer(com.servoy.j2db.server.shared.IApplicationServer) RepositoryException(com.servoy.j2db.persistence.RepositoryException) Point(java.awt.Point) IApplication(com.servoy.j2db.IApplication) Part(com.servoy.j2db.persistence.Part) IRepository(com.servoy.j2db.persistence.IRepository) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) TreeMap(java.util.TreeMap)

Example 3 with IFormUIInternal

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

the class SwingFormManager method showPreview.

@Override
public void showPreview(final FormController afp, final IFoundSetInternal foundset, int zoomFactor, final PrinterJob printJob) {
    removePreview();
    final FormController fc = currentContainer.getController();
    if (fc != null) {
        List invokeLaterRunnables = new ArrayList();
        boolean ok = fc.notifyVisible(false, invokeLaterRunnables);
        Utils.invokeLater(getApplication(), invokeLaterRunnables);
        if (!ok) {
            // cannot hide...so skip preview
            return;
        }
    }
    showFormInMainPanel(afp.getName(), currentContainer, null, true, null);
    getApplication().getModeManager().setMode(IModeManager.PREVIEW_MODE);
    boolean isNewUser = checkAndUpdateFormUser(afp, currentContainer);
    if (isNewUser) {
        IFormUIInternal ui = afp.getFormUI();
        currentContainer.add(ui, afp.getName());
    }
    try {
        final PrintPreview printPreview = new PrintPreview((ISmartClientApplication) getApplication(), afp, foundset, zoomFactor, printJob);
        Runnable r = new Runnable() {

            public void run() {
                printPreviews.put(currentContainer, new PrintPreviewHolder(printPreview, fc));
                // $NON-NLS-1$
                currentContainer.add(printPreview, "@preview");
                // $NON-NLS-1$
                currentContainer.show("@preview");
                // handle navigator propertly
                List invokeLaterRunnables = new ArrayList();
                afp.showNavigator(invokeLaterRunnables);
                Utils.invokeLater(getApplication(), invokeLaterRunnables);
                printPreview.showPages();
            }
        };
        getApplication().invokeLater(r);
    } catch (Exception ex) {
        // $NON-NLS-1$
        getApplication().reportError(Messages.getString("servoy.formManager.error.PrintPreview"), ex);
    }
}
Also used : FormController(com.servoy.j2db.FormController) BasicFormController(com.servoy.j2db.BasicFormController) PrintPreview(com.servoy.j2db.printing.PrintPreview) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IFormUIInternal(com.servoy.j2db.IFormUIInternal)

Example 4 with IFormUIInternal

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

the class FormLookupPanel method createFormPanel.

private FormController createFormPanel() {
    FormManager fm = (FormManager) application.getFormManager();
    FormController fp = fm.getFormController(formName, this);
    if (fp != null) {
        IFormUIInternal ui = fp.getFormUI();
        if (ui instanceof Component) {
            add((Component) ui, BorderLayout.CENTER);
            // just to be sure the cardlayout of main panel does return them as not visible
            ui.setComponentVisible(true);
            // delegate readOnly, really set it once from the form manager state
            fp.setReadOnly(fm.isFormReadOnly(formName));
            Container con = getParent();
            if (con != null && (con instanceof ITabPaneAlike) && !con.isEnabled()) {
                // reaply the isEnabled state of the tabpanel to its child tabs (tabs are added after enabled state is set); only if the tabpanel is disabled
                this.setEnabled(con.isEnabled());
            }
            while (con != null) {
                if (con instanceof IFormUIInternal) {
                    fp.getUndoManager().setFormUndoManager(((IFormUIInternal) con).getUndoManager());
                    break;
                }
                con = con.getParent();
            }
            // invalidate later so that everything is first visible (like the datamodel of a tableview)
            application.invokeLater(new Runnable() {

                public void run() {
                    validate();
                }
            });
        }
    }
    return fp;
}
Also used : FormController(com.servoy.j2db.FormController) Container(java.awt.Container) FormManager(com.servoy.j2db.FormManager) ITabPaneAlike(com.servoy.j2db.util.ITabPaneAlike) IFormUIInternal(com.servoy.j2db.IFormUIInternal) Component(java.awt.Component)

Example 5 with IFormUIInternal

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

the class FormLookupPanel method notifyVisible.

/**
 * This method must be called on the event thread
 */
public boolean notifyVisible(boolean visible, List invokeLaterRunnables) {
    Component[] childs = getComponents();
    if (childs.length == 1) {
        IFormUIInternal ui = (IFormUIInternal) childs[0];
        FormController child = ui.getController();
        return child.notifyVisible(visible, invokeLaterRunnables);
    }
    return true;
}
Also used : FormController(com.servoy.j2db.FormController) Component(java.awt.Component) IFormUIInternal(com.servoy.j2db.IFormUIInternal)

Aggregations

IFormUIInternal (com.servoy.j2db.IFormUIInternal)7 FormController (com.servoy.j2db.FormController)5 Component (java.awt.Component)3 ArrayList (java.util.ArrayList)3 IComponent (com.servoy.j2db.ui.IComponent)2 Point (java.awt.Point)2 List (java.util.List)2 AbstractActiveSolutionHandler (com.servoy.j2db.AbstractActiveSolutionHandler)1 BasicFormController (com.servoy.j2db.BasicFormController)1 FlattenedSolution (com.servoy.j2db.FlattenedSolution)1 FormManager (com.servoy.j2db.FormManager)1 IApplication (com.servoy.j2db.IApplication)1 IForm (com.servoy.j2db.IForm)1 Form (com.servoy.j2db.persistence.Form)1 IRepository (com.servoy.j2db.persistence.IRepository)1 Part (com.servoy.j2db.persistence.Part)1 RepositoryException (com.servoy.j2db.persistence.RepositoryException)1 Solution (com.servoy.j2db.persistence.Solution)1 PrintPreview (com.servoy.j2db.printing.PrintPreview)1 WebForm (com.servoy.j2db.server.headlessclient.WebForm)1