Search in sources :

Example 16 with IPersist

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

the class FormLayoutGenerator method generateFormComponent.

public static String generateFormComponent(Form form, FlattenedSolution fs, IFormElementCache cache) {
    StringWriter out = new StringWriter();
    PrintWriter writer = new PrintWriter(out);
    Iterator<? extends IPersist> componentsIterator = null;
    if (!form.isResponsiveLayout()) {
        List<IPersist> components = fs.getFlattenedForm(form).getAllObjectsAsList();
        List<IFormElement> formElements = new ArrayList<>();
        for (IPersist persist : components) {
            if (persist instanceof IFormElement) {
                formElements.add((IFormElement) persist);
            }
        }
        Collections.sort(formElements, new Comparator<IFormElement>() {

            public int compare(IFormElement o1, IFormElement o2) {
                int result = FlattenedForm.FORM_INDEX_WITH_HIERARCHY_COMPARATOR.compare(o1, o2);
                if (result == 0) {
                    result = TabSeqComparator.compareTabSeq(getTabSeq(o1), o1, getTabSeq(o2), o2);
                }
                return result;
            }
        });
        componentsIterator = formElements.iterator();
    } else {
        componentsIterator = fs.getFlattenedForm(form).getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
    }
    while (componentsIterator.hasNext()) {
        IPersist component = componentsIterator.next();
        // if (PartWrapper.isSecurityVisible(component, fs, form))
        if (component instanceof LayoutContainer) {
            FormLayoutStructureGenerator.generateLayoutContainer((LayoutContainer) component, form, fs, writer, null, cache);
        } else if (component instanceof IFormElement) {
            FormElement fe = cache.getFormElement((IFormElement) component, fs, null, false);
            if (form != null && !form.isResponsiveLayout()) {
                FormLayoutGenerator.generateFormElementWrapper(writer, fe, form, form.isResponsiveLayout());
            }
            FormLayoutGenerator.generateFormElement(writer, fe, form);
            if (form != null && !form.isResponsiveLayout()) {
                FormLayoutGenerator.generateEndDiv(writer);
            }
        }
    }
    return out.getBuffer().toString();
}
Also used : IFormElement(com.servoy.j2db.persistence.IFormElement) StringWriter(java.io.StringWriter) IPersist(com.servoy.j2db.persistence.IPersist) LayoutContainer(com.servoy.j2db.persistence.LayoutContainer) ArrayList(java.util.ArrayList) FormElement(com.servoy.j2db.server.ngclient.FormElement) IFormElement(com.servoy.j2db.persistence.IFormElement) PrintWriter(java.io.PrintWriter)

Example 17 with IPersist

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

the class FormLayoutStructureGenerator method generateLayoutContainer.

public static void generateLayoutContainer(LayoutContainer container, Form form, FlattenedSolution fs, PrintWriter writer, DesignProperties design, IFormElementCache cache) {
    WebLayoutSpecification spec = null;
    if (container.getPackageName() != null) {
        PackageSpecification<WebLayoutSpecification> pkg = WebComponentSpecProvider.getSpecProviderState().getLayoutSpecifications().get(container.getPackageName());
        if (pkg != null) {
            spec = pkg.getSpecification(container.getSpecName());
        }
    }
    boolean isCSSPositionContainer = CSSPositionUtils.isCSSPositionContainer(spec);
    writer.print("<");
    writer.print(container.getTagType());
    Set<String> writtenAttributes = new HashSet<>();
    if (design != null) {
        writer.print(" svy-id='");
        writer.print(container.getUUID().toString());
        writer.print("'");
        writer.print(" svy-location='");
        writer.print(container.getLocation().x);
        writer.print("'");
        boolean highSet = false;
        JSONObject ngClass = new JSONObject();
        String layoutStyleClasses = "";
        String solutionStyleClasses = "";
        if (spec != null) {
            writer.print(" svy-layoutname='");
            writer.print(spec.getPackageName() + "." + spec.getName());
            writer.print("'");
            ngClass.put("svy-layoutcontainer", true);
            if (// is this inherited?
            !(container.getAncestor(IRepository.FORMS).getID() == form.getID())) {
                ngClass.put("inheritedElement", true);
            }
            String designClass = spec.getDesignStyleClass() != null && spec.getDesignStyleClass().length() > 0 ? spec.getDesignStyleClass() : "customDivDesign";
            if ("customDivDesign".equals(designClass) && hasSameDesignClassAsParent(container, spec)) {
                designClass = isEvenLayoutContainer(container) ? "customDivDesignOdd" : "customDivDesignEven";
            }
            highSet = true;
            if (design.mainContainer != container.getID()) {
                // added <> tokens so that we can remove quotes around the values so that angular will evaluate at runtime
                ngClass.put(designClass, "<showWireframe<");
            } else {
                writer.print(" data-maincontainer='true'");
                ngClass.put(designClass, "<false<");
            }
            // added <> tokens so that we can remove quotes around the values so that angular will evaluate at runtime
            ngClass.put("highlight_element", "<design_highlight=='highlight_element'<");
            List<String> containerStyleClasses = getStyleClassValues(spec, container.getCssClasses());
            solutionStyleClasses = getSolutionSpecificClasses(spec, container);
            if (!containerStyleClasses.isEmpty()) {
                layoutStyleClasses = containerStyleClasses.stream().collect(Collectors.joining(" "));
                writer.print(" class='" + layoutStyleClasses + "'");
            }
            if (container.getCssClasses() != null && container.getCssClasses().trim().length() > 0) {
                writtenAttributes.add("class");
            }
            if (spec.getAllowedChildren().size() > 0 || spec.getExcludedChildren() != null) {
                // added <> tokens so that we can remove quotes around the values so that angular will evaluate at runtime
                ngClass.put("drop_highlight", "<canContainDraggedElement('" + spec.getPackageName() + "." + spec.getName() + "')<");
            }
        }
        if (!highSet)
            ngClass.put("highlight_element", "<design_highlight=='highlight_element'<");
        if (ngClass.length() > 0) {
            writer.print(" ng-class='" + ngClass.toString().replaceAll("\"<", "").replaceAll("<\"", "").replaceAll("'", "\"") + "'");
        }
        if (writtenAttributes.contains("class")) {
            writer.print(" svy-layout-class='" + layoutStyleClasses + "'");
            writer.print(" svy-solution-layout-class='" + solutionStyleClasses + "'");
        }
        writer.print(" svy-title='" + getLayouContainerTitle(container) + "'");
    }
    if (container.getName() != null) {
        writer.print(" svy-name='");
        writer.print(container.getName());
        writer.print("' ");
    }
    if (container.getElementId() != null) {
        writer.print(" id='");
        writer.print(container.getElementId());
        writer.print("' ");
    }
    writer.print(" svy-autosave ");
    if (isCSSPositionContainer) {
        // we need to specify the height
        writer.print(" style='height:");
        writer.print(container.getSize().height);
        writer.print("px;position: relative;' ");
    }
    Map<String, String> attributes = new HashMap<String, String>(container.getMergedAttributes());
    if (spec != null) {
        for (String propertyName : spec.getAllPropertiesNames()) {
            PropertyDescription pd = spec.getProperty(propertyName);
            if (pd.getDefaultValue() != null && !attributes.containsKey(propertyName)) {
                attributes.put(propertyName, pd.getDefaultValue().toString());
            }
        }
    }
    String classes = attributes.get("class");
    if (classes == null)
        classes = "svy-layoutcontainer";
    else
        classes += " svy-layoutcontainer";
    attributes.put("class", classes);
    for (Entry<String, String> entry : attributes.entrySet()) {
        if (design != null && writtenAttributes.contains(entry.getKey()))
            continue;
        writer.print(" ");
        try {
            StringEscapeUtils.ESCAPE_ECMASCRIPT.translate(entry.getKey(), writer);
            if (entry.getValue() != null && entry.getValue().length() > 0) {
                writer.print("=\"");
                StringEscapeUtils.ESCAPE_ECMASCRIPT.translate(entry.getValue(), writer);
                writer.print("\"");
            }
        } catch (IOException e) {
            Debug.error(e);
        }
    }
    writer.print(">");
    Iterator<IPersist> components = container.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
    while (components.hasNext()) {
        IPersist component = components.next();
        if (component instanceof LayoutContainer) {
            generateLayoutContainer((LayoutContainer) component, form, fs, writer, design, cache);
        } else if (component instanceof IFormElement) {
            FormElement fe = cache.getFormElement((IFormElement) component, fs, null, design != null);
            if (!isSecurityVisible(fs, fe.getPersistIfAvailable(), form)) {
                continue;
            }
            if (isCSSPositionContainer) {
                FormLayoutGenerator.generateFormElementWrapper(writer, fe, form, false);
            }
            FormLayoutGenerator.generateFormElement(writer, fe, form);
            if (isCSSPositionContainer) {
                FormLayoutGenerator.generateEndDiv(writer);
            }
        }
    }
    writer.print("</");
    writer.print(container.getTagType());
    writer.print(">");
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) FormElement(com.servoy.j2db.server.ngclient.FormElement) IFormElement(com.servoy.j2db.persistence.IFormElement) PropertyDescription(org.sablo.specification.PropertyDescription) WebLayoutSpecification(org.sablo.specification.WebLayoutSpecification) IFormElement(com.servoy.j2db.persistence.IFormElement) JSONObject(org.json.JSONObject) IPersist(com.servoy.j2db.persistence.IPersist) LayoutContainer(com.servoy.j2db.persistence.LayoutContainer) HashSet(java.util.HashSet)

Example 18 with IPersist

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

the class FlattenedSolution method getAllObjectsAsList.

public List<IPersist> getAllObjectsAsList() {
    if (mainSolution == null) {
        if (loginFlattenedSolution != null) {
            return loginFlattenedSolution.getAllObjectsAsList();
        }
        return Collections.emptyList();
    }
    if (allObjectscache == null) {
        List<IPersist> retval = new ArrayList<IPersist>(allObjectsSize);
        if (copySolution != null) {
            fillList(retval, copySolution);
        }
        getAllModuleObjects(retval);
        fillList(retval, mainSolution);
        if (loginFlattenedSolution != null) {
            List<IPersist> elements = loginFlattenedSolution.getAllObjectsAsList();
            for (IPersist persist : elements) {
                if (!retval.contains(persist))
                    retval.add(persist);
            }
        }
        allObjectsSize = retval.size();
        retval.removeAll(getIndex().getRemoved());
        allObjectscache = retval;
    }
    return allObjectscache;
}
Also used : IPersist(com.servoy.j2db.persistence.IPersist) ArrayList(java.util.ArrayList)

Example 19 with IPersist

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

the class FlattenedSolution method getMaxID.

protected int getMaxID() {
    final int[] maxId = new int[1];
    IPersistVisitor visitor = new IPersistVisitor() {

        public Object visit(IPersist o) {
            if (maxId[0] < o.getID()) {
                maxId[0] = o.getID();
            }
            return IPersistVisitor.CONTINUE_TRAVERSAL;
        }
    };
    mainSolution.acceptVisitor(visitor);
    if (modules != null) {
        for (Solution module : modules) {
            module.acceptVisitor(visitor);
        }
    }
    int max = maxId[0];
    if (loginFlattenedSolution != null) {
        int loginMax = loginFlattenedSolution.getMaxID();
        if (loginMax > max) {
            max = loginMax;
        }
    }
    return max;
}
Also used : IPersist(com.servoy.j2db.persistence.IPersist) IPersistVisitor(com.servoy.j2db.persistence.IPersistVisitor) Solution(com.servoy.j2db.persistence.Solution)

Example 20 with IPersist

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

the class FlattenedSolution method getSolutionCopy.

public Solution getSolutionCopy(boolean create) {
    if (mainSolution == null) {
        if (loginFlattenedSolution != null) {
            return loginFlattenedSolution.getSolutionCopy(create);
        }
        return null;
    }
    if (copySolution != null || !create)
        return copySolution;
    try {
        SimplePersistFactory factory = getPersistFactory();
        copySolution = SimplePersistFactory.createDummyCopy(mainSolution);
        copySolution.setChangeHandler(new ChangeHandler(factory) {

            // overwrite this new Object to skip the call to rootObject.registerNewObject(object); which shouldn't be needed for solution model solutions.
            @Override
            public IPersist createNewObject(ISupportChilds parent, int object_type_id, int element_id, UUID uuid) throws RepositoryException {
                return factory.createObject(parent, object_type_id, element_id, uuid);
            }
        });
        copySolution.getChangeHandler().addIPersistListener(this);
        getIndex().setSolutionModelSolution(copySolution);
    } catch (Exception e) {
        Debug.error(e);
    }
    return copySolution;
}
Also used : ISupportChilds(com.servoy.j2db.persistence.ISupportChilds) ChangeHandler(com.servoy.j2db.persistence.ChangeHandler) IPersist(com.servoy.j2db.persistence.IPersist) RepositoryException(com.servoy.j2db.persistence.RepositoryException) UUID(com.servoy.j2db.util.UUID) SimplePersistFactory(com.servoy.j2db.persistence.SimplePersistFactory) RemoteException(java.rmi.RemoteException) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Aggregations

IPersist (com.servoy.j2db.persistence.IPersist)84 Point (java.awt.Point)26 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)23 Form (com.servoy.j2db.persistence.Form)22 ArrayList (java.util.ArrayList)22 IFormElement (com.servoy.j2db.persistence.IFormElement)20 BaseComponent (com.servoy.j2db.persistence.BaseComponent)19 HashMap (java.util.HashMap)16 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)14 IComponent (com.servoy.j2db.ui.IComponent)13 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)13 Component (org.apache.wicket.Component)13 AbstractBase (com.servoy.j2db.persistence.AbstractBase)12 JSONObject (org.json.JSONObject)10 PropertyDescription (org.sablo.specification.PropertyDescription)10 RepositoryException (com.servoy.j2db.persistence.RepositoryException)8 Tab (com.servoy.j2db.persistence.Tab)8 IPortalComponent (com.servoy.j2db.ui.IPortalComponent)8 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)7 ISupportAnchors (com.servoy.j2db.persistence.ISupportAnchors)7