Search in sources :

Example 6 with Part

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

the class ComponentFactory method createComponentEx.

protected static IComponent createComponentEx(IApplication application, Form form, IPersist meta, IDataProviderLookup dataProviderLookup, IScriptExecuter el, boolean printing) {
    IComponent comp = null;
    switch(meta.getTypeID()) {
        case IRepository.FIELDS:
            comp = createField(application, form, (Field) meta, dataProviderLookup, el, printing);
            break;
        case IRepository.GRAPHICALCOMPONENTS:
            comp = createGraphicalComponent(application, form, (GraphicalComponent) meta, el, dataProviderLookup);
            break;
        case IRepository.RECTSHAPES:
            comp = createRectangle(application, form, (RectShape) meta);
            break;
        case IRepository.PORTALS:
            comp = createPortal(application, form, (Portal) meta, dataProviderLookup, el, printing);
            break;
        case IRepository.PARTS:
            comp = createPart(application, (Part) meta);
            break;
        case IRepository.TABPANELS:
            TabPanel tabPanelMeta = (TabPanel) meta;
            int orient = tabPanelMeta.getTabOrientation();
            if (orient == TabPanel.SPLIT_HORIZONTAL || orient == TabPanel.SPLIT_VERTICAL)
                comp = createSplitPane(application, form, tabPanelMeta, el);
            else
                comp = createTabPanel(application, form, tabPanelMeta, el);
            break;
        case IRepository.BEANS:
            comp = createBean(application, form, (Bean) meta, null);
            break;
        case IRepository.WEBCOMPONENTS:
            comp = createWebComponentPlaceholder(application, form, (WebComponent) meta);
            break;
        default:
            Debug.error("ComponentFactory:unkown type " + meta.getTypeID() + ", uuid: " + meta.getUUID() + ", parent:" + meta.getParent());
            IStandardLabel label = application.getItemFactory().createLabel(getWebID(form, meta), "ComponentFactory:unkown type " + meta.getTypeID());
            label.setSize(new Dimension(200, 20));
            comp = label;
    }
    if (comp instanceof JComponent) {
        ((JComponent) comp).putClientProperty("Id", ComponentFactory.getWebID(form, meta));
    }
    return comp;
}
Also used : ITabPanel(com.servoy.j2db.ui.ITabPanel) TabPanel(com.servoy.j2db.persistence.TabPanel) RuntimeTabPanel(com.servoy.j2db.ui.scripting.RuntimeTabPanel) RectShape(com.servoy.j2db.persistence.RectShape) IComponent(com.servoy.j2db.ui.IComponent) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) JComponent(javax.swing.JComponent) Dimension(java.awt.Dimension) IStandardLabel(com.servoy.j2db.ui.IStandardLabel) IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean) Bean(com.servoy.j2db.persistence.Bean) RuntimeMediaField(com.servoy.j2db.ui.scripting.RuntimeMediaField) RuntimeDataLookupField(com.servoy.j2db.ui.scripting.RuntimeDataLookupField) Field(com.servoy.j2db.persistence.Field) RuntimeDataField(com.servoy.j2db.ui.scripting.RuntimeDataField) AbstractRuntimeField(com.servoy.j2db.ui.scripting.AbstractRuntimeField) WebComponent(com.servoy.j2db.persistence.WebComponent) Part(com.servoy.j2db.persistence.Part) Portal(com.servoy.j2db.persistence.Portal) RuntimePortal(com.servoy.j2db.ui.scripting.RuntimePortal)

Example 7 with Part

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

the class FormController method createDataRenderers.

private void createDataRenderers(int viewType) throws Exception {
    int v = viewType;
    if (getDataSource() == null) {
        // form not based on any datasource
        v = LOCKED_RECORD_VIEW;
    }
    application.getDataRenderFactory().prepareRenderers(application, form);
    Part bodyPart = null;
    Map<Part, IDataRenderer> part_panels = new LinkedHashMap<Part, IDataRenderer>();
    Iterator<Part> e2 = form.getParts();
    while (e2.hasNext()) {
        Part part = e2.next();
        Color partColor = ComponentFactory.getPartBackground(application, part, form);
        // extract the body (bgcolor)
        if (part.getPartType() == Part.BODY) {
            bodyPart = part;
            bgColor = partColor;
            Pair<IStyleSheet, IStyleRule> partStyle = ComponentFactory.getStyleForBasicComponent(application, part, form);
            bodyRule = partStyle != null ? partStyle.getRight() : null;
        }
        if (part.getPartType() == Part.BODY && v == FormController.LOCKED_TABLE_VIEW) {
            // don't create part, view == part
            continue;
        }
        IDataRenderer dr = application.getDataRenderFactory().getEmptyDataRenderer(ComponentFactory.getWebID(form, part), part.toString(), application, (part.getPartType() == Part.BODY));
        dr.initDragNDrop(this, form.getPartStartYPos(part.getID()));
        dataRenderers[part.getPartType()] = dr;
        dr.setName(part.toString());
        part_panels.put(part, dr);
        if (part.getPartType() == Part.BODY) {
            int onRenderMethodID = form.getOnRenderMethodID();
            if (onRenderMethodID > 0) {
                dr.getOnRenderComponent().getRenderEventExecutor().setRenderCallback(Integer.toString(onRenderMethodID), Utils.parseJSExpressions(form.getFlattenedMethodArguments("onRenderMethodID")));
                dr.getOnRenderComponent().getRenderEventExecutor().setRenderScriptExecuter(getScriptExecuter());
            }
        }
        dr.setBackground(partColor);
    }
    tabSequence.clear();
    application.getDataRenderFactory().completeRenderers(application, form, scriptExecuter, part_panels, form.getSize().width, false, containerImpl.getUndoManager(), tabSequence);
    if (bodyPart != null && (v == FormController.LOCKED_LIST_VIEW || v == IForm.LIST_VIEW)) {
        IDataRenderer dr = application.getDataRenderFactory().getEmptyDataRenderer(ComponentFactory.getWebID(form, bodyPart), bodyPart.toString(), application, true);
        int onRenderMethodID = form.getOnRenderMethodID();
        if (onRenderMethodID > 0) {
            dr.getOnRenderComponent().getRenderEventExecutor().setRenderCallback(Integer.toString(onRenderMethodID), Utils.parseJSExpressions(form.getFlattenedMethodArguments("onRenderMethodID")));
            dr.getOnRenderComponent().getRenderEventExecutor().setRenderScriptExecuter(getScriptExecuter());
        }
        // apply bgcolor to renderer
        if (bgColor != null) {
            dr.setBackground(bgColor);
        }
        dataRenderers[FORM_RENDERER] = dr;
        dr.setName(bodyPart.toString());
        part_panels = new LinkedHashMap<Part, IDataRenderer>();
        part_panels.put(bodyPart, dr);
        application.getDataRenderFactory().completeRenderers(application, form, scriptExecuter, part_panels, form.getSize().width, false, containerImpl.getUndoManager(), null);
    }
    // apply security
    int access = application.getFlattenedSolution().getSecurityAccess(form.getUUID(), form.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
    if (access != -1) {
        boolean b_accessible = ((access & IRepository.ACCESSIBLE) != 0);
        if (!b_accessible) {
            for (IDataRenderer dataRenderer : dataRenderers) {
                if (dataRenderer != null) {
                    Iterator<? extends IComponent> componentIterator = dataRenderer.getComponentIterator();
                    while (componentIterator.hasNext()) {
                        IComponent c = componentIterator.next();
                        if (c instanceof ISupportSecuritySettings) {
                            if (!b_accessible)
                                ((ISupportSecuritySettings) c).setAccessible(b_accessible);
                        }
                    }
                }
            }
        }
    }
}
Also used : IStyleSheet(com.servoy.j2db.util.IStyleSheet) IComponent(com.servoy.j2db.ui.IComponent) Color(java.awt.Color) LinkedHashMap(java.util.LinkedHashMap) IDataRenderer(com.servoy.j2db.ui.IDataRenderer) Part(com.servoy.j2db.persistence.Part) IStyleRule(com.servoy.j2db.util.IStyleRule) ISupportSecuritySettings(com.servoy.j2db.ui.ISupportSecuritySettings)

Example 8 with Part

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

the class PageDefinition method handleSink.

void handleSink() {
    heightLeft -= skipOnY;
    if (heightLeft > 0) {
        for (int i = panels.size() - 1; i >= 0; i--) {
            DataRendererDefinition drd = panels.get(i);
            Part part = drd.getPart();
            if (part != null) {
                if (part.getPartType() == Part.FOOTER || part.getPartType() == Part.TITLE_FOOTER) {
                    continue;
                }
                if (part.getSinkWhenLast()) {
                    // sink
                    drd.setYlocation(drd.getYlocation() + heightLeft);
                    heightLeft = 0;
                }
            }
            break;
        }
    }
}
Also used : Part(com.servoy.j2db.persistence.Part)

Example 9 with Part

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

the class FormPreviewPanel method process.

// build the chain and fill the renderers,returns number of pages
public int process() throws Exception {
    // clear
    root = null;
    // set size of this panel
    orgWidth = new Dimension((int) (currentPageFormat.getWidth() * (1 / factor)), (int) (currentPageFormat.getHeight() * (1 / factor)));
    applySize();
    part_panels = createPartPanels();
    Form form = controllerBeingPreviewed.getForm();
    // otherwise you cannot print multiple columns   (int) (application.getPageFormat().getImageableWidth()*(1/factor));
    int w = form.getWidth();
    try {
        // $NON-NLS-1$
        application.getRuntimeProperties().put("isPrinting", Boolean.TRUE);
        Map componentsUsingSliding = application.getDataRenderFactory().completeRenderers(application, form, controllerBeingPreviewed.getScriptExecuter(), part_panels, w, true, null, null);
        PropertyCopy.copyExistingPrintableProperties(application, controllerBeingPreviewed, part_panels);
        Iterator<DataRenderer> panels = part_panels.values().iterator();
        while (panels.hasNext()) {
            DataRenderer panel = panels.next();
            panel.setComponentsUsingSliding(componentsUsingSliding);
            DataRendererFactory.addSpringsBetweenComponents(application, panel);
        }
        // $NON-NLS-1$
        Debug.trace("usesSliding " + (componentsUsingSliding.size() != 0));
    } finally {
        // $NON-NLS-1$
        application.getRuntimeProperties().put("isPrinting", null);
    }
    // create list
    renderParent = application.getPrintingRendererParent();
    plist = new PageList(application, this, renderParent);
    PartNode node = null;
    // create the chain based on the sort,LAST node must be the body part (is virtal added if not present)
    Part body = null;
    FormController fp = ((FormManager) application.getFormManager()).leaseFormPanel(controllerBeingPreviewed.getName());
    if (fp != null && !fp.isShowingData()) {
        // List lst = fp.getFormModel().getLastSearchColumns();
        if (fp.wantEmptyFoundSet()) {
            if (fp.getFormModel() != null)
                fp.getFormModel().clear();
        } else {
            fp.loadAllRecords();
        }
    // fp.getFormModel().sort(lst);
    }
    List<SortColumn> sortColumns = ((FoundSet) formData).getLastSortColumns();
    if (formData.getSize() != 0) {
        if (sortColumns != null) {
            Set<String> consumed = new HashSet<String>();
            for (int i = 0; i < sortColumns.size(); i++) {
                SortColumn sc = sortColumns.get(i);
                Iterator<Part> it = part_panels.keySet().iterator();
                while (it.hasNext()) {
                    Part part = it.next();
                    DataRenderer dr = part_panels.get(part);
                    if (part.getPartType() == Part.BODY) {
                        body = part;
                        continue;
                    }
                    if (part.getPartType() != Part.LEADING_SUBSUMMARY && part.getPartType() != Part.TRAILING_SUBSUMMARY) {
                        IRecordInternal state = new PageNumberState(formData, plist);
                        plist.setNonRepeatingPart(part.getPartType(), new DataRendererDefinition(this, renderParent, part, dr, state));
                        continue;
                    }
                    boolean match = false;
                    int inlineCount = 0;
                    List<SortColumn> partSortColumns = new ArrayList<SortColumn>();
                    SortColumn lastMatch = sc;
                    String groupByDataproviders = part.getGroupbyDataProviderIDs() != null ? part.getGroupbyDataProviderIDs() : "";
                    // $NON-NLS-1$ //$NON-NLS-2$
                    StringTokenizer tk = new StringTokenizer("" + groupByDataproviders.toLowerCase(), ", ");
                    int tokenCount = tk.countTokens();
                    String[] ids = new String[tokenCount];
                    for (; inlineCount < tokenCount; inlineCount++) {
                        String id = tk.nextToken();
                        ids[inlineCount] = id;
                        if (lastMatch.getDataProviderID().equals(id)) {
                            partSortColumns.add(lastMatch);
                            if ((i + inlineCount + 1) < sortColumns.size()) {
                                lastMatch = sortColumns.get(i + inlineCount + 1);
                                if (part.getPartType() == Part.LEADING_SUBSUMMARY && consumed.contains(lastMatch)) {
                                    break;
                                }
                            } else {
                                break;
                            }
                        } else {
                            break;
                        }
                    }
                    if (// did all match?
                    tokenCount > 0 && partSortColumns.size() == tokenCount) {
                        match = true;
                        if (part.getPartType() == Part.LEADING_SUBSUMMARY) {
                            for (String element : ids) {
                                consumed.add(element);
                            }
                        }
                    }
                    if (match) {
                        SortColumn[] array = new SortColumn[partSortColumns.size()];
                        partSortColumns.toArray(array);
                        if (// create root
                        root == null) {
                            root = new PartNode(this, part, dr, renderParent, array);
                            node = root;
                        } else {
                            if (!tryToPlaceInExistingNodes(part, dr, array)) {
                                PartNode newNode = new PartNode(this, part, dr, renderParent, array);
                                node.setChild(newNode);
                                node = newNode;
                            }
                        }
                    }
                }
            }
            PartNode newNode = null;
            if (body == null) {
                // a virtual body (when no body is placed in the parts)
                newNode = new PartNode(this, null, null, renderParent, null);
            } else {
                // the body
                newNode = new PartNode(this, body, part_panels.get(body), renderParent, null);
            }
            if (node != null) {
                node.setChild(newNode);
            } else {
                root = newNode;
            }
        } else // no sort...
        {
            if (// search for body
            body == null) {
                Iterator<Part> it = part_panels.keySet().iterator();
                while (it.hasNext()) {
                    Part part = it.next();
                    DataRenderer dr = part_panels.get(part);
                    IRecordInternal state = new PageNumberState(formData, plist);
                    if (part.getPartType() == Part.BODY) {
                        body = part;
                        continue;
                    }
                    if (part.getPartType() != Part.LEADING_SUBSUMMARY && part.getPartType() != Part.TRAILING_SUBSUMMARY) {
                        plist.setNonRepeatingPart(part.getPartType(), new DataRendererDefinition(this, renderParent, part, dr, state));
                        continue;
                    }
                }
            }
            if (body == null) {
                // a virtual body (when no body is placed in the parts)
                root = new PartNode(this, null, null, renderParent, null);
            } else // if (body != null)
            {
                // the body
                root = new PartNode(this, body, part_panels.get(body), renderParent, null);
            }
        }
    }
    try {
        // $NON-NLS-1$
        application.getRuntimeProperties().put("isPrinting", Boolean.TRUE);
        long t1 = System.currentTimeMillis();
        // fill the renderers with data
        if (root != null) {
            // dump chain
            // $NON-NLS-1$
            Debug.trace("Root " + root);
            QuerySelect sqlString = ((FoundSet) formData).getQuerySelectForReading();
            Table table = formData.getSQLSheet().getTable();
            FoundSet fs = (FoundSet) ((FoundSetManager) application.getFoundSetManager()).getNewFoundSet(table, null, sortColumns);
            fs.browseAll(sqlString);
            long t3 = System.currentTimeMillis();
            List<DataRendererDefinition> childRetval = root.process(this, fs, table, sqlString);
            long t4 = System.currentTimeMillis();
            if (Debug.tracing()) {
                // $NON-NLS-1$ //$NON-NLS-2$
                Debug.trace("Database queries took " + ((t4 - t3) / 1000f) + " second");
            }
            if (childRetval != null) {
                for (int i = 0; i < childRetval.size(); i++) {
                    plist.addPanel(childRetval.get(i));
                }
            }
        }
        plist.finish();
        long t2 = System.currentTimeMillis();
        int pageCount = plist.getNumberOfPages();
        // dump
        if (Debug.tracing()) {
            Debug.trace(plist);
            // $NON-NLS-1$ //$NON-NLS-2$
            Debug.trace("Generated " + pageCount / ((t2 - t1) / 1000f) + " printable pages per second");
        }
    } finally {
        // $NON-NLS-1$
        application.getRuntimeProperties().put("isPrinting", null);
    }
    renderParent.removeAll();
    return plist.getNumberOfPages();
}
Also used : Form(com.servoy.j2db.persistence.Form) DataRenderer(com.servoy.j2db.smart.dataui.DataRenderer) ArrayList(java.util.ArrayList) SortColumn(com.servoy.j2db.dataprocessing.SortColumn) FormManager(com.servoy.j2db.FormManager) HashSet(java.util.HashSet) FormController(com.servoy.j2db.FormController) Table(com.servoy.j2db.persistence.Table) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) FoundSet(com.servoy.j2db.dataprocessing.FoundSet) Dimension(java.awt.Dimension) QuerySelect(com.servoy.j2db.query.QuerySelect) StringTokenizer(java.util.StringTokenizer) Part(com.servoy.j2db.persistence.Part) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 10 with Part

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

the class WebListFormUI method getFormElements.

@Override
public List<FormElement> getFormElements() {
    if (cachedElements.size() == 0) {
        Form form = getController().getForm();
        List<IFormElement> elements = form.getFlattenedObjects(PositionComparator.XY_PERSIST_COMPARATOR);
        Iterator<IFormElement> it = elements.iterator();
        Part body = FormElementHelper.INSTANCE.getBodyPart(form);
        int bodyStartY = form.getPartStartYPos(body.getID());
        int bodyEndY = body.getHeight();
        // only the elements from other form parts then body still need to be added to cached elements
        while (it.hasNext()) {
            IFormElement element = it.next();
            if (bodyStartY <= element.getLocation().y && bodyEndY > element.getLocation().y) {
                it.remove();
            }
        }
        elements.add(getPortal());
        cachedElements = FormElementHelper.INSTANCE.getFormElements(new ArrayList<IPersist>(elements).iterator(), getDataConverterContext());
    }
    return cachedElements;
}
Also used : IFormElement(com.servoy.j2db.persistence.IFormElement) Form(com.servoy.j2db.persistence.Form) IPersist(com.servoy.j2db.persistence.IPersist) Part(com.servoy.j2db.persistence.Part)

Aggregations

Part (com.servoy.j2db.persistence.Part)36 Point (java.awt.Point)17 Form (com.servoy.j2db.persistence.Form)14 IPersist (com.servoy.j2db.persistence.IPersist)9 IFormElement (com.servoy.j2db.persistence.IFormElement)8 Dimension (java.awt.Dimension)8 ArrayList (java.util.ArrayList)8 BaseComponent (com.servoy.j2db.persistence.BaseComponent)7 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)6 IDataRenderer (com.servoy.j2db.ui.IDataRenderer)6 IStyleRule (com.servoy.j2db.util.IStyleRule)5 IStyleSheet (com.servoy.j2db.util.IStyleSheet)5 FormController (com.servoy.j2db.FormController)4 IForm (com.servoy.j2db.IForm)4 Color (java.awt.Color)4 Portal (com.servoy.j2db.persistence.Portal)3 IComponent (com.servoy.j2db.ui.IComponent)3 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 Map (java.util.Map)3