Search in sources :

Example 6 with FormController

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

the class FormCssResource method getResourceStream.

/**
 * @see org.apache.wicket.Resource#getResourceStream()
 */
@Override
public IResourceStream getResourceStream() {
    String css = "";
    ValueMap params = getParameters();
    Long time = null;
    if (params.size() == 1) {
        Iterator iterator = params.entrySet().iterator();
        if (iterator.hasNext()) {
            Map.Entry entry = (Entry) iterator.next();
            String solutionName = (String) entry.getKey();
            Pair<String, Long> filterTime = filterTime((String) entry.getValue());
            String formInstanceName = filterTime.getLeft();
            time = filterTime.getRight();
            // $NON-NLS-1$
            String solutionAndForm = solutionName + "/" + formInstanceName;
            // $NON-NLS-1$
            String templateDir = "default";
            IServiceProvider sp = null;
            Solution solution = null;
            Form form = null;
            if (Session.exists()) {
                sp = WebClientSession.get().getWebClient();
                if (sp != null) {
                    IForm fc = ((WebClient) sp).getFormManager().getForm(formInstanceName);
                    if (fc instanceof FormController) {
                        FlattenedSolution clientSolution = sp.getFlattenedSolution();
                        form = clientSolution.getForm(((FormController) fc).getForm().getName());
                    }
                }
                templateDir = WebClientSession.get().getTemplateDirectoryName();
            }
            final String fullpath = "/servoy-webclient/templates/" + templateDir + "/" + solutionAndForm + ".css";
            try {
                URL url = context.getResource(fullpath);
                if (url != null) {
                    return new NullUrlResourceStream(url);
                }
            } catch (Exception e) {
                Debug.error(e);
            }
            try {
                IApplicationServerSingleton as = ApplicationServerRegistry.get();
                RootObjectMetaData sd = as.getLocalRepository().getRootObjectMetaData(solutionName, IRepository.SOLUTIONS);
                if (sd != null) {
                    solution = (Solution) as.getLocalRepository().getActiveRootObject(sd.getRootObjectId());
                    if (form == null) {
                        form = solution.getForm(formInstanceName);
                    }
                }
                if (form != null) {
                    Pair<String, String> formHTMLAndCSS = TemplateGenerator.getFormHTMLAndCSS(solution, form, sp, formInstanceName);
                    css = formHTMLAndCSS.getRight();
                }
            } catch (Exception e) {
                Debug.error(e);
            }
        }
    }
    // $NON-NLS-1$
    StringResourceStream stream = new StringResourceStream(css, "text/css");
    stream.setLastModified(time != null ? Time.valueOf(time.longValue()) : null);
    return stream;
}
Also used : Entry(java.util.Map.Entry) FormController(com.servoy.j2db.FormController) RootObjectMetaData(com.servoy.j2db.persistence.RootObjectMetaData) IApplicationServerSingleton(com.servoy.j2db.server.shared.IApplicationServerSingleton) IForm(com.servoy.j2db.IForm) Form(com.servoy.j2db.persistence.Form) ValueMap(org.apache.wicket.util.value.ValueMap) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IForm(com.servoy.j2db.IForm) URL(java.net.URL) Entry(java.util.Map.Entry) IServiceProvider(com.servoy.j2db.IServiceProvider) Iterator(java.util.Iterator) StringResourceStream(org.apache.wicket.util.resource.StringResourceStream) Map(java.util.Map) ValueMap(org.apache.wicket.util.value.ValueMap) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution)

Example 7 with FormController

use of com.servoy.j2db.FormController 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 8 with FormController

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

the class WebAccordionPanel method notifyResized.

public void notifyResized() {
    if (currentForm != null && currentForm.isReady()) {
        WebForm webForm = currentForm.getWebForm();
        FormController controller = webForm.getController();
        if (controller != null && webForm.isFormWidthHeightChanged()) {
            controller.notifyResized();
            webForm.clearFormWidthHeightChangedFlag();
            if (// $NON-NLS-1$
            Utils.getAsBoolean(application.getRuntimeProperties().get("enableAnchors"))) {
                scriptable.getChangesRecorder().setChanged();
            }
        }
    }
}
Also used : FormController(com.servoy.j2db.FormController) WebForm(com.servoy.j2db.server.headlessclient.WebForm)

Example 9 with FormController

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

the class WebAccordionPanel method showFoundSet.

protected void showFoundSet(WebTabFormLookup flp, IRecordInternal parentState, List<SortColumn> sort) {
    deregisterSelectionListeners();
    if (!flp.isReady())
        return;
    FormController fp = flp.getWebForm().getController();
    if (fp != null && flp.getRelationName() != null) {
        IFoundSetInternal relatedFoundset = parentState == null ? null : parentState.getRelatedFoundSet(flp.getRelationName(), sort);
        registerSelectionListeners(parentState, flp.getRelationName());
        fp.loadData(relatedFoundset, null);
    }
    ITagResolver resolver = getTagResolver(parentState);
    // refresh tab text
    for (int i = 0; i < allTabs.size(); i++) {
        WebTabHolder element = allTabs.get(i);
        if (element.getPanel() == flp) {
            element.refreshTagStrings(resolver);
            break;
        }
    }
}
Also used : FormController(com.servoy.j2db.FormController) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) ITagResolver(com.servoy.base.util.ITagResolver) Point(java.awt.Point)

Example 10 with FormController

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

the class WebAccordionPanel method notifyVisible.

public void notifyVisible(boolean visible, List<Runnable> invokeLaterRunnables) {
    if (currentForm == null && allTabs.size() > 0) {
        WebTabHolder holder = allTabs.get(0);
        setCurrentForm(holder.getPanel(), -1, invokeLaterRunnables);
    }
    if (currentForm != null) {
        FormController controller = currentForm.getWebForm().getController();
        // this is not needed when closing
        if (visible && parentData != null) {
            showFoundSet(currentForm, parentData, controller.getDefaultSortColumns());
            // Test if current one is there
            if (currentForm.isReady()) {
                addCurrentFormComponent();
                recomputeTabSequence();
            }
        }
        controller.notifyVisible(visible, invokeLaterRunnables);
    }
}
Also used : FormController(com.servoy.j2db.FormController)

Aggregations

FormController (com.servoy.j2db.FormController)70 FormManager (com.servoy.j2db.FormManager)15 Form (com.servoy.j2db.persistence.Form)13 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)12 RepositoryException (com.servoy.j2db.persistence.RepositoryException)10 Point (java.awt.Point)10 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)9 ArrayList (java.util.ArrayList)9 IFormController (com.servoy.j2db.IFormController)8 BasicFormController (com.servoy.j2db.BasicFormController)7 IForm (com.servoy.j2db.IForm)7 WebForm (com.servoy.j2db.server.headlessclient.WebForm)7 FlattenedSolution (com.servoy.j2db.FlattenedSolution)6 IFormUIInternal (com.servoy.j2db.IFormUIInternal)5 IDataProvider (com.servoy.j2db.persistence.IDataProvider)5 List (java.util.List)5 ApplicationException (com.servoy.j2db.ApplicationException)4 IMainContainer (com.servoy.j2db.IMainContainer)4 PrototypeState (com.servoy.j2db.dataprocessing.PrototypeState)4 IDataRenderer (com.servoy.j2db.ui.IDataRenderer)4