Package at.reppeitsolutions.formbuilder.components.formbuilderitem

Examples of at.reppeitsolutions.formbuilder.components.formbuilderitem.FormBuilderItemBase


        boolean firstFormData = true;
        Map<String, FormDataResult> formDatasResults = new HashMap<>();
        for (FormData formData : formDatas) {
           
            for (FormBuilderItemData formBuilderItemData : formData.getData()) {
                FormBuilderItemBase item = formBuilderItemData.getFormBuilderItem();
                if (item instanceof FormBuilderItemInput
                        || item instanceof FormBuilderItemTextarea
                        || item instanceof FormBuilderItemDate
                        || item instanceof FormBuilderItemTime) {
                    if(firstFormData) {
                        FormDataStringResult stringFormDataResult = new FormDataStringResult(item);
                        formDatasResults.put(item.getId(), stringFormDataResult);
                    }
                    ((FormDataStringResult)formDatasResults.get(item.getId())).addStringFormDataResult(formBuilderItemData.getValue());
                } else if (item instanceof FormBuilderItemSelect
                        || item instanceof FormBuilderItemRadio
                        || item instanceof FormBuilderItemListbox
                        || item instanceof FormBuilderItemCheckbox) {
                    FormDataPieChartResult pieChartFormDataResult;
                    if(firstFormData) {
                        pieChartFormDataResult = new FormDataPieChartResult(item);
                        for(String value : item.getProperties().getValues().split(";")) {
                            pieChartFormDataResult.addNewValue(value, 0);
                        }
                        formDatasResults.put(item.getId(), pieChartFormDataResult);
                    }
                    pieChartFormDataResult = ((FormDataPieChartResult)formDatasResults.get(item.getId()));
                    pieChartFormDataResult.incrementValue(formBuilderItemData.getValue());
                } else if (item instanceof FormBuilderItemNumber) {
                    FormDataFloatResult floatFormDataResult;
                    if(firstFormData) {
                        floatFormDataResult = new FormDataFloatResult(item);
                        formDatasResults.put(item.getId(), floatFormDataResult);
                    }
                    ((FormDataFloatResult)formDatasResults.get(item.getId())).addFloatFormDataResult(formBuilderItemData.getNumberValue());
                }
            }
            firstFormData = false;
        }
        return formDatasResults.values();
View Full Code Here


                                    }
                                }
                                if (o != null) {
                                    //Start image specific code
                                    if (o instanceof FormBuilderItemImage || o instanceof FormBuilderItemDownload) {
                                        FormBuilderItemBase object = (FormBuilderItemBase) o;
                                        for (FormBuilderItemBase tmpItem : formBuilder.getForm().getItems()) {
                                            if (tmpItem.getId().equals(object.getId())) {
                                                cachedObjects.put(tmpItem.getId(), tmpItem);
                                            }
                                        }
                                    }
                                    //End image specific code
                                    FormBuilderItemBase itemBase = (FormBuilderItemBase) o;
                                    itemBase.setPosition(itemBase.getPosition() + positionOffset);
                                    itemBase.initConstraintsFromConstraintsString(formBuilder.getWorkflowStates(), formBuilder.getConstraintClients());
                                    list.add((FormBuilderItemBase) o);
                                    //Start format area specific code
                                    if (o instanceof FormBuilderItemFormatArea || o instanceof FormBuilderItemConstraint) {
                                        FormBuilderItemBase area = (FormBuilderItemBase) o;
                                        if (area.getProperties().getBrother() == null) {
                                            HashMap<String, String> areasMap = new HashMap<>();
                                            HashMap<String, String> constraintsMap = new HashMap<>();
                                            for (FormBuilderItemBase tmpItem : formBuilder.getForm().getItems()) {
                                                if (tmpItem instanceof FormBuilderItemFormatArea
                                                        && !areasMap.containsKey(tmpItem.getProperties().getFormatareauuid())) {
                                                    areasMap.put(tmpItem.getProperties().getFormatareauuid(), null);
                                                }
                                                if (tmpItem instanceof FormBuilderItemConstraint
                                                        && !areasMap.containsKey(tmpItem.getProperties().getFormatareauuid())) {
                                                    constraintsMap.put(tmpItem.getProperties().getFormatareauuid(), null);
                                                }
                                            }
                                            int areas = 1 + areasMap.size();
                                            int constrains = 1 + constraintsMap.size();
                                            FormBuilderItemBase brother = null;
                                            if (o instanceof FormBuilderItemFormatArea) {
                                                brother = new FormBuilderItemFormatArea();
                                            } else {
                                                brother = new FormBuilderItemConstraint();
                                            }
                                            brother.getProperties().setBrother(area.getId());
                                            brother.setBrother(area);
                                            brother.setPosition(area.getPosition() + 1);
                                            area.getProperties().setBrother(brother.getId());
                                            area.setBrother(brother);
                                            list.add(brother);
                                            String formatAreaUuid = UUID.randomUUID().toString();
                                            area.getProperties().setFormatareauuid(formatAreaUuid);
                                            brother.getProperties().setFormatareauuid(formatAreaUuid);
                                            if (o instanceof FormBuilderItemFormatArea) {
                                                area.getProperties().setValues(area.getProperties().getValues() + " " + areas);
                                                brother.getProperties().setValues(brother.getProperties().getValues() + " " + areas);
                                            } else {
                                                area.getProperties().setValues(area.getProperties().getValues() + " " + constrains);
                                                brother.getProperties().setValues(brother.getProperties().getValues() + " " + constrains);
                                            }
                                            positionOffset++;
                                        }
                                        if (o instanceof FormBuilderItemFormatArea) {
                                            if (activeFormatArea == null) {
                                                activeFormatArea = area.getProperties().getFormatareauuid();
                                            } else if (activeFormatArea.equals(area.getProperties().getFormatareauuid())) {
                                                activeFormatArea = null;
                                            } else {
                                                throw new RuntimeException(Messages.getStringJSF("formatarea.error"));
                                            }
                                        } else {
                                            if (activeConstraint == null) {
                                                activeConstraint = area.getProperties().getFormatareauuid();
                                            } else if (activeConstraint.equals(area.getProperties().getFormatareauuid())) {
                                                activeConstraint = null;
                                            } else {
                                                throw new RuntimeException(Messages.getStringJSF("constraint.error"));
                                            }
                                        }
                                    }
                                    //End format area specific code
                                }
                            }
                        }
                    }
                    if (!list.isEmpty()) {
                        formBuilder.getForm().getItems().clear();
                        formBuilder.getForm().addItems(list);
                    }
                    //Start image specific code
                    if (!cachedObjects.isEmpty()) {
                        for (FormBuilderItemBase tmpItem : formBuilder.getForm().getItems()) {
                            if ((tmpItem instanceof FormBuilderItemImage || tmpItem instanceof FormBuilderItemDownload)
                                    && cachedObjects.containsKey(tmpItem.getId())) {
                                tmpItem.getProperties().setFile(cachedObjects.get(tmpItem.getId()).getProperties().getFile());
                            }
                        }
                    }
                    HttpServletRequest request = (HttpServletRequest) ctx.getExternalContext().getRequest();
                    MultipartRequest multiRequest = new MultipartRequest(request);
                    for (String key : multiRequest.getFiles().keySet()) {
                        for (FormBuilderItemBase item : formBuilder.getForm().getItems()) {
                            if (key.contains(item.getId())) {
                                item.getProperties().setFile(multiRequest.getFiles().get(key));
                            }
                        }
                    }
                    //End image specific code                   
                    break;



                case "edit":
                    try {
                        FormBuilderItemUpdateHolder updateHolder = mapper.readValue(formContentString, FormBuilderItemUpdateHolder.class);
                        List<FormBuilderItemBase> items = formBuilder.getForm().getItems();
                        for (FormBuilderItemBase item : items) {
                            if (item.getId().equals(updateHolder.getItemId())) {
                                FormBuilderItemFactory.updateFormBuilderItem(item, updateHolder.getUpdates());
                                if (item instanceof FormBuilderItemFormatArea || item instanceof FormBuilderItemConstraint) {
                                    for (FormBuilderItemBase item2 : items) {
                                        if (item2.getProperties().getBrother() != null
                                                && (item2 instanceof FormBuilderItemFormatArea || item2 instanceof FormBuilderItemConstraint)
                                                && item2.getProperties().getBrother().equals(item.getId())) {
                                            Iterator<FormBuilderItemUpdate> updateIter = updateHolder.getUpdates().iterator();
                                            while (updateIter.hasNext()) {
                                                FormBuilderItemUpdate update = updateIter.next();
                                                if (update.getMethod().equals("brother")) {
                                                    updateIter.remove();
                                                }
                                            }
                                            FormBuilderItemFactory.updateFormBuilderItem(item2, updateHolder.getUpdates());
                                        }
                                    }
                                }
                            }
                        }
                    } catch (IOException ex) {
                        Logger.getLogger(FormBuilderInternalRenderer.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    break;
                case "delete":
                    List<FormBuilderItemBase> items = formBuilder.getForm().getItems();
                    Iterator<FormBuilderItemBase> itemIter = items.iterator();
                    String brotherToDelete = null;
                    while (itemIter.hasNext()) {
                        FormBuilderItemBase item = itemIter.next();
                        if (item.getId().equals(formContentString)) {
                            if (item instanceof FormBuilderItemFormatArea || item instanceof FormBuilderItemConstraint) {
                                brotherToDelete = item.getProperties().getBrother();
                            }
                            itemIter.remove();
                            break;
                        }
                    }
                    if (brotherToDelete != null) {
                        itemIter = items.iterator();
                        while (itemIter.hasNext()) {
                            FormBuilderItemBase item = itemIter.next();
                            if (item.getId().equals(brotherToDelete)) {
                                itemIter.remove();
                                break;
                            }
                        }
                    }
View Full Code Here

        ITextOuterTableCell outputCell;
        ITextOuterTableCell dummyCell = null;
        FormBuilderItemConstraint activeConstraint = null;
        int halfwidthcount = 0;
        for (int i = 0; i < items.size(); ++i) {
            FormBuilderItemBase item = items.get(i).getFormBuilderItem();
            FormBuilderItemData itemData = items.get(i).getFormBuilderItemData();
            if(itemData != null) {
                ConstraintVariablesContainer constraintVariablesContainer = new ConstraintVariablesContainer();
                activeConstraint = FormFillerInternalRenderer.checkConstraints(
                        itemData,
                        activeConstraint,
                        constraintVariablesContainer,
                        workflowState,
                        constraintClient);
            }
            if (!item.getSkipRendering() &&
                 item.getProperties().getVisible()) {
                switch (item.getWidth()) {
                    case FormBuilderItemBase.FULLWIDTH:
                        outputCell = new ITextOuterTableCell(2);
                        halfwidthcount = 0;
                        break;
                    case FormBuilderItemBase.HALFWIDTH:
                        outputCell = new ITextOuterTableCell(1);
                        halfwidthcount++;
                        if (((i + 1 < items.size()
                                && items.get(i + 1).getFormBuilderItem().getWidth().equals(FormBuilderItemBase.FULLWIDTH)) || (i + 1 == items.size()
                                && items.get(i).getFormBuilderItem().getWidth().equals(FormBuilderItemBase.HALFWIDTH)))
                                && halfwidthcount % 2 == 1) {
                            dummyCell = new ITextOuterTableCell(1);
                            dummyCell.addElement(new ITextParagraph(""));
                        }
                        break;
                    default:
                        outputCell = new ITextOuterTableCell(2);
                }
                if(itemData != null) {
                    outputCell.addElement(FormBuilderItemPdfFactory.getUIPdfComponent(itemData, mode));
                } else {
                    outputCell.addElement(FormBuilderItemPdfFactory.getUIPdfComponent(item));
                }
                outerTable.addCell(outputCell);
                if (dummyCell != null) {
                    outerTable.addCell(dummyCell);
                    dummyCell = null;
                }
            } else if (item instanceof FormBuilderItemPagebreak) {
                document.add(outerTable);
                document.newPage();
                outerTable = new ITextOuterTable();
            }
            item.getProperties().resetConstraintVariables();
        }
        return outerTable;
    }
View Full Code Here

TOP

Related Classes of at.reppeitsolutions.formbuilder.components.formbuilderitem.FormBuilderItemBase

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.