Search in sources :

Example 61 with IPersist

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

the class FormLayoutGenerator method generateFormElement.

// private static boolean canContainComponents(WebComponentSpecification spec)
// {
// Map<String, PropertyDescription> properties = spec.getProperties();
// for (PropertyDescription propertyDescription : properties.values())
// {
// String simpleTypeName = propertyDescription.getType().getName().replaceFirst(spec.getName() + ".", "");
// if (simpleTypeName.equals(ComponentPropertyType.TYPE_NAME)) return true;
// Object configObject = propertyDescription.getConfig();
// if (configObject != null)
// {
// try
// {
// if (configObject instanceof JSONObject && ((JSONObject)configObject).has(DesignerFilter.DROPPABLE))
// {
// Object droppable = ((JSONObject)configObject).get(DesignerFilter.DROPPABLE);
// if (droppable instanceof Boolean && (Boolean)droppable)
// {
// if (simpleTypeName.equals("tab")) return true;
// }
// }
// }
// catch (JSONException e)
// {
// Debug.log(e);
// }
// }
// }
// return false;
// }
public static void generateFormElement(PrintWriter writer, FormElement fe, Form form) {
    IPersist fePersist = fe.getPersistIfAvailable();
    String name = fe.getName();
    boolean selectable = fe.isFormComponentChild() ? name.indexOf('$' + FormElement.SVY_NAME_PREFIX) == -1 : true;
    writer.print("<");
    writer.print(fe.getTagname());
    writer.print(" name='");
    writer.print(name);
    writer.print("'");
    if (Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.ngclient.testingMode", "false"))) {
        String elementName = name;
        if (elementName.startsWith("svy_") && fePersist != null) {
            elementName = "svy_" + fePersist.getUUID().toString();
        }
        writer.print(" data-svy-name='");
        writer.print(form.getName() + "." + elementName);
        writer.print("'");
    }
    String designId = getDesignId(fe);
    if (designId != null) {
        if (form.isResponsiveLayout()) {
            writer.print(" svy-id='");
            writer.print(designId);
            writer.print("'");
            if (fePersist instanceof ISupportBounds) {
                writer.print(" svy-location='");
                writer.print(((ISupportBounds) fePersist).getLocation().x);
                writer.print("'");
            }
            if (!selectable) {
                writer.print(" svy-non-selectable='noname'");
            }
            writer.print(" svy-formelement-type='");
            writer.print(fe.getTypeName());
            writer.print("'");
            JSONObject ngClass = new JSONObject();
            List<String>[] typeAndPropertyNames = fe.getSvyTypesAndPropertiesNames();
            if (typeAndPropertyNames[0].size() > 0) {
                writer.print(" svy-types='");
                writer.print("[" + String.join(",", typeAndPropertyNames[0]) + "]");
                writer.print("'");
                writer.print(" svy-types-properties='");
                writer.print("[" + String.join(",", typeAndPropertyNames[1]) + "]");
                writer.print("'");
                ngClass.put("drop_highlight", "<canContainDraggedElement('" + fe.getTypeName() + "',['" + String.join("','", typeAndPropertyNames[0]) + "'])<");
            }
            List<String> forbiddenComponentNames = fe.getForbiddenComponentNames();
            if (forbiddenComponentNames.size() > 0) {
                writer.print(" svy-forbidden-components='");
                writer.print("[" + String.join(",", forbiddenComponentNames) + "]");
                writer.print("'");
            }
            String directEditPropertyName = getDirectEditProperty(fe);
            if (directEditPropertyName != null) {
                writer.print(" directEditPropertyName='");
                writer.print(directEditPropertyName);
                writer.print("'");
            }
            if (// is this inherited or override element?
            !fe.getForm().equals(form) || fePersist instanceof ISupportExtendsID && PersistHelper.getSuperPersist((ISupportExtendsID) fePersist) != null) {
                ngClass.put("inheritedElement", true);
            }
            if (fe.isFormComponentChild()) {
                ngClass.put("formComponentChild", true);
            }
            ngClass.put("invisible_element", "<getDesignFormControllerScope().model('" + designId + "').svyVisible == false<".toString());
            // added <> tokens so that we can remove quotes around the values so that angular will evaluate at runtime
            ngClass.put("highlight_child_element", "<design_highlight=='highlight_element'<".toString());
            writer.print(" ng-class='" + ngClass.toString().replaceAll("\"<", "").replaceAll("<\"", "").replaceAll("'", "\"") + "'");
        }
        writer.print(" svy-model=\"model('");
        writer.print(designId);
        writer.print("')\"");
        writer.print(" svy-api=\"api('");
        writer.print(designId);
        writer.print("')\"");
        writer.print(" svy-handlers=\"handlers('");
        writer.print(designId);
        writer.print("')\"");
        writer.print(" svy-servoyApi=\"servoyApi('");
        writer.print(designId);
        writer.print("')\"");
        if (fePersist instanceof IFormElement) {
            writer.print(" form-index=" + ((IFormElement) fePersist).getFormIndex() + "");
        }
    } else {
        writer.print(" svy-model='model.");
        writer.print(name);
        writer.print("'");
        writer.print(" svy-api='api.");
        writer.print(name);
        writer.print("'");
        writer.print(" svy-handlers='handlers.");
        writer.print(name);
        writer.print("'");
        writer.print(" svy-servoyApi='handlers.");
        writer.print(name);
        writer.print(".svy_servoyApi'");
    }
    writer.print(">");
    writer.print("</");
    writer.print(fe.getTagname());
    writer.print(">");
}
Also used : IFormElement(com.servoy.j2db.persistence.IFormElement) JSONObject(org.json.JSONObject) IPersist(com.servoy.j2db.persistence.IPersist) ISupportExtendsID(com.servoy.j2db.persistence.ISupportExtendsID) ISupportBounds(com.servoy.j2db.persistence.ISupportBounds) ArrayList(java.util.ArrayList) List(java.util.List)

Example 62 with IPersist

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

the class FormLayoutGenerator method generateRecordViewForm.

public static void generateRecordViewForm(PrintWriter writer, Form form, String realFormName, IServoyDataConverterContext context, boolean design) {
    generateFormStartTag(writer, form, realFormName, false, design);
    Iterator<Part> it = form.getParts();
    if (design) {
        while (it.hasNext()) {
            Part part = it.next();
            if (!Part.rendersOnlyInPrint(part.getPartType())) {
                writer.print("<div ng-style=\"");
                writer.print(PartWrapper.getName(part));
                writer.print("Style\"");
                String partClass = "svy-" + PartWrapper.getName(part);
                if (part.getStyleClass() != null) {
                    partClass += " " + part.getStyleClass();
                }
                writer.print(" class=\"");
                writer.print(partClass);
                writer.print("\">");
                generateEndDiv(writer);
            }
        }
    }
    Map<IPersist, FormElement> cachedElementsMap = new HashMap<IPersist, FormElement>();
    if (context != null && context.getApplication() != null) {
        IFormController controller = ((BasicFormManager) context.getApplication().getFormManager()).getCachedFormController(realFormName);
        if (controller != null && controller.getFormUI() instanceof WebFormUI) {
            List<FormElement> cachedFormElements = ((WebFormUI) controller.getFormUI()).getFormElements();
            for (FormElement fe : cachedFormElements) {
                if (fe.getPersistIfAvailable() != null) {
                    cachedElementsMap.put(fe.getPersistIfAvailable(), fe);
                }
            }
        }
    }
    it = form.getParts();
    while (it.hasNext()) {
        Part part = it.next();
        if (!Part.rendersOnlyInPrint(part.getPartType())) {
            if (!design) {
                writer.print("<div svy-ng-style=\"");
                writer.print(PartWrapper.getName(part));
                writer.print("Style\"");
                String partClass = "svy-" + PartWrapper.getName(part);
                if (part.getStyleClass() != null) {
                    partClass += " " + part.getStyleClass();
                }
                writer.print(" class=\"");
                writer.print(partClass);
                writer.print("\">");
            }
            for (IFormElement bc : PartWrapper.getBaseComponents(part, form, context, design, false)) {
                FormElement fe = null;
                if (cachedElementsMap.containsKey(bc)) {
                    fe = cachedElementsMap.get(bc);
                }
                if (fe == null) {
                    fe = FormElementHelper.INSTANCE.getFormElement(bc, context.getSolution(), null, design);
                }
                generateFormElementWrapper(writer, fe, form, form.isResponsiveLayout());
                generateFormElement(writer, fe, form);
                generateEndDiv(writer);
            }
            if (!design)
                generateEndDiv(writer);
        }
    }
    generateFormEndTag(writer, design);
}
Also used : IFormElement(com.servoy.j2db.persistence.IFormElement) WebFormUI(com.servoy.j2db.server.ngclient.WebFormUI) IPersist(com.servoy.j2db.persistence.IPersist) HashMap(java.util.HashMap) Part(com.servoy.j2db.persistence.Part) BasicFormManager(com.servoy.j2db.BasicFormManager) IFormController(com.servoy.j2db.IFormController) FormElement(com.servoy.j2db.server.ngclient.FormElement) IFormElement(com.servoy.j2db.persistence.IFormElement)

Example 63 with IPersist

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

the class FormLayoutStructureGenerator method generateLayout.

public static void generateLayout(Form form, String realFormName, FlattenedSolution fs, PrintWriter writer, DesignProperties design) {
    try {
        FormLayoutGenerator.generateFormStartTag(writer, form, realFormName, false, design != null);
        Iterator<IPersist> components = form.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
        while (components.hasNext()) {
            IPersist component = components.next();
            if (component instanceof LayoutContainer) {
                generateLayoutContainer((LayoutContainer) component, form, fs, writer, design, FormElementHelper.INSTANCE);
            } else if (component instanceof IFormElement) {
                FormLayoutGenerator.generateFormElement(writer, FormElementHelper.INSTANCE.getFormElement((IFormElement) component, fs, null, false), form);
            }
        }
        FormLayoutGenerator.generateFormEndTag(writer, design != null);
    } catch (Exception e) {
        Debug.error(e);
    }
}
Also used : IFormElement(com.servoy.j2db.persistence.IFormElement) IPersist(com.servoy.j2db.persistence.IPersist) LayoutContainer(com.servoy.j2db.persistence.LayoutContainer) IOException(java.io.IOException)

Example 64 with IPersist

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

the class PartWrapper method getBaseComponents.

public static Collection<BaseComponent> getBaseComponents(Part part, Form context, IServoyDataConverterContext converterContext, boolean isDesign, boolean flatten) {
    if (!isDesign && part.getPartType() == Part.BODY) {
        switch(context.getView()) {
            case FormController.TABLE_VIEW:
            case FormController.LOCKED_TABLE_VIEW:
            case IForm.LIST_VIEW:
            case FormController.LOCKED_LIST_VIEW:
                return Arrays.asList(new BaseComponent[] { new BodyPortal(context) });
        }
    }
    List<BaseComponent> baseComponents = new ArrayList<>();
    int startPos = context.getPartStartYPos(part.getID());
    int endPos = part.getHeight();
    Comparator<? super IFormElement> comparator = null;
    if (context.isResponsiveLayout()) {
        comparator = PositionComparator.XY_PERSIST_COMPARATOR;
    } else {
        comparator = FlattenedForm.FORM_INDEX_WITH_HIERARCHY_COMPARATOR;
    }
    List<IFormElement> persists = null;
    if (flatten) {
        persists = context.getFlattenedObjects(comparator);
    } else {
        persists = new ArrayList(context.getAllObjectsAsList());
        Iterator<IFormElement> it = persists.iterator();
        while (it.hasNext()) {
            IPersist persist = it.next();
            if (!(persist instanceof BaseComponent)) {
                it.remove();
            }
        }
        Collections.sort(persists, comparator);
    }
    for (IFormElement persist : persists) {
        Point location = CSSPositionUtils.getLocation(persist);
        if (startPos <= location.y && endPos > location.y && persist instanceof BaseComponent) {
            if (isSecurityVisible(persist, converterContext.getSolution(), context))
                baseComponents.add((BaseComponent) persist);
        }
    }
    return baseComponents;
}
Also used : IFormElement(com.servoy.j2db.persistence.IFormElement) BaseComponent(com.servoy.j2db.persistence.BaseComponent) IPersist(com.servoy.j2db.persistence.IPersist) BodyPortal(com.servoy.j2db.server.ngclient.BodyPortal) ArrayList(java.util.ArrayList) Point(java.awt.Point) Point(java.awt.Point)

Example 65 with IPersist

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

the class FlattenedSolution method updatePersistInSolutionCopy.

public void updatePersistInSolutionCopy(final IPersist persist) {
    if (mainSolution == null && loginFlattenedSolution != null) {
        loginFlattenedSolution.updatePersistInSolutionCopy(persist);
        return;
    }
    if (copySolution == null)
        return;
    IPersist copyPersist = (IPersist) copySolution.acceptVisitor(new IPersistVisitor() {

        public Object visit(IPersist o) {
            if (o.getUUID().equals(persist.getUUID())) {
                return o;
            }
            return IPersistVisitor.CONTINUE_TRAVERSAL;
        }
    });
    if (copyPersist != null) {
        ((AbstractBase) copyPersist).copyPropertiesMap(((AbstractBase) persist).getPropertiesMap(), false);
        ISupportChilds parent = copyPersist.getParent();
        flush(persist);
        if (parent instanceof Form) {
            ((Form) parent).setLastModified(System.currentTimeMillis());
        } else if (copyPersist instanceof Form) {
            ((Form) copyPersist).setLastModified(System.currentTimeMillis());
        }
    } else if (persist.getParent() != null && !(persist.getParent() instanceof Solution)) {
        ISupportChilds copyParent = (ISupportChilds) copySolution.acceptVisitor(new IPersistVisitor() {

            public Object visit(IPersist o) {
                if (o.getUUID().equals(persist.getParent().getUUID())) {
                    return o;
                }
                return IPersistVisitor.CONTINUE_TRAVERSAL;
            }
        });
        if (copyParent != null) {
            if (persist instanceof ICloneable) {
                ((ICloneable) persist).clonePersist((AbstractBase) copyParent);
            } else {
                copyParent.addChild(persist);
            }
            flush(persist);
            if (copyParent instanceof Form) {
                ((Form) copyParent).setLastModified(System.currentTimeMillis());
            }
        }
    }
}
Also used : ICloneable(com.servoy.j2db.persistence.ICloneable) ISupportChilds(com.servoy.j2db.persistence.ISupportChilds) IPersist(com.servoy.j2db.persistence.IPersist) Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) AbstractBase(com.servoy.j2db.persistence.AbstractBase) IPersistVisitor(com.servoy.j2db.persistence.IPersistVisitor) JSONObject(org.json.JSONObject) IRootObject(com.servoy.j2db.persistence.IRootObject) Solution(com.servoy.j2db.persistence.Solution)

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