Search in sources :

Example 1 with FormElement

use of com.servoy.j2db.server.ngclient.FormElement in project servoy-client by Servoy.

the class PersistFieldInstanceTest method testFieldWithValueList.

@Test
public void testFieldWithValueList() throws RepositoryException {
    Form form = solution.getForm("test");
    Assert.assertNotNull(form);
    ValueList vl = solution.getValueList("test");
    Assert.assertNotNull(vl);
    Field field = form.createNewField(new Point(0, 0));
    field.setDataProviderID("mycolumn");
    field.setFormat("#,###.00");
    field.setDisplayType(Field.TYPE_AHEAD);
    field.setValuelistID(vl.getID());
    // needed for a valuelist property type that searches it's form's table via the webform ui
    WebFormUI formUI = new WebFormUI(client.getFormManager().getForm(form.getName()));
    IDataAdapterList dataAdapterList = formUI.getDataAdapterList();
    List<FormElement> formElements = FormElementHelper.INSTANCE.getFormElements(form.getAllObjects(), new ServoyDataConverterContext(client));
    Assert.assertEquals(1, formElements.size());
    WebFormComponent wc = ComponentFactory.createComponent(client, dataAdapterList, formElements.get(0), formUI, form);
    Object property = wc.getProperty("valuelistID");
    Assert.assertTrue(property != null ? property.getClass().getName() : "null", property instanceof ValueListTypeSabloValue && ((ValueListTypeSabloValue) property).getValueList() instanceof CustomValueList);
    Assert.assertEquals("#,###.00", ((CustomValueList) ((ValueListTypeSabloValue) property).getValueList()).getFormat().getDisplayFormat());
}
Also used : CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) Form(com.servoy.j2db.persistence.Form) ValueList(com.servoy.j2db.persistence.ValueList) CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) ValueListTypeSabloValue(com.servoy.j2db.server.ngclient.property.types.ValueListTypeSabloValue) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) Point(java.awt.Point) FormElement(com.servoy.j2db.server.ngclient.FormElement) Field(com.servoy.j2db.persistence.Field) WebFormUI(com.servoy.j2db.server.ngclient.WebFormUI) ServoyDataConverterContext(com.servoy.j2db.server.ngclient.ServoyDataConverterContext) IDataAdapterList(com.servoy.j2db.server.ngclient.IDataAdapterList) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) Test(org.junit.Test)

Example 2 with FormElement

use of com.servoy.j2db.server.ngclient.FormElement in project servoy-client by Servoy.

the class PersistFieldInstanceTest method testTabPanelWithTabs.

@Test
public void testTabPanelWithTabs() throws RepositoryException {
    Form form = solution.getForm("test");
    Assert.assertNotNull(form);
    Form tabForm = solution.createNewForm(validator, null, "tabform", null, false, new Dimension(600, 400));
    tabForm.setNavigatorID(-1);
    DataAdapterList dataAdapterList = new DataAdapterList(new TestFormController(tabForm, client));
    TabPanel tabpanel = form.createNewTabPanel("tabpanel");
    tabpanel.createNewTab("tab1", null, tabForm);
    tabpanel.createNewTab("tab2", null, tabForm);
    List<FormElement> formElements = FormElementHelper.INSTANCE.getFormElements(form.getAllObjects(), new ServoyDataConverterContext(client));
    Assert.assertEquals(1, formElements.size());
    WebFormComponent wc = ComponentFactory.createComponent(client, dataAdapterList, formElements.get(0), null, form);
    List<Map<String, Object>> tabs = (List) wc.getProperty("tabs");
    Assert.assertEquals(2, tabs.size());
    Map<String, Object> map = tabs.get(1);
    Assert.assertSame(tabForm.getName(), map.get("containsFormId"));
}
Also used : TabPanel(com.servoy.j2db.persistence.TabPanel) Form(com.servoy.j2db.persistence.Form) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) IDataAdapterList(com.servoy.j2db.server.ngclient.IDataAdapterList) DataAdapterList(com.servoy.j2db.server.ngclient.DataAdapterList) Dimension(java.awt.Dimension) FormElement(com.servoy.j2db.server.ngclient.FormElement) ServoyDataConverterContext(com.servoy.j2db.server.ngclient.ServoyDataConverterContext) ValueList(com.servoy.j2db.persistence.ValueList) IDataAdapterList(com.servoy.j2db.server.ngclient.IDataAdapterList) CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) List(java.util.List) DataAdapterList(com.servoy.j2db.server.ngclient.DataAdapterList) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 3 with FormElement

use of com.servoy.j2db.server.ngclient.FormElement in project servoy-client by Servoy.

the class PersistFieldInstanceTest method testSettingTextOfTabInTabpanel.

@Test
public void testSettingTextOfTabInTabpanel() throws RepositoryException, JSONException {
    Form form = solution.getForm("test");
    Assert.assertNotNull(form);
    DataAdapterList dataAdapterList = new DataAdapterList(new TestFormController(form, client));
    Form tabForm = solution.createNewForm(validator, null, "tabform", null, false, new Dimension(600, 400));
    tabForm.setNavigatorID(-1);
    TabPanel tabpanel = form.createNewTabPanel("tabpanel");
    tabpanel.createNewTab("tab1", null, tabForm);
    tabpanel.createNewTab("tab2", null, tabForm);
    List<FormElement> formElements = FormElementHelper.INSTANCE.getFormElements(form.getAllObjects(), new ServoyDataConverterContext(client));
    Assert.assertEquals(1, formElements.size());
    WebFormComponent wc = ComponentFactory.createComponent(client, dataAdapterList, formElements.get(0), null, form);
    TypedData<Map<String, Object>> changes = wc.getAndClearChanges();
    Assert.assertEquals(0, changes.content.size());
    List<Map<String, Object>> tabs = (List) wc.getProperty("tabs");
    Assert.assertEquals(2, tabs.size());
    Map<String, Object> map = tabs.get(0);
    map.put("text", new BasicTagStringTypeSabloValue("a test", null));
    changes = wc.getAndClearChanges();
    Assert.assertEquals(1, changes.content.size());
    String json = JSONUtils.writeChangesWithConversions(changes.content, changes.contentType, null);
    JSONAssert.assertEquals("{\"tabs\":{\"vEr\":1,\"g\":[{\"op\":[0,0,0],\"d\":[{\"rt\":\"servoydefault-tabpanel.tab\",\"vEr\":1,\"u\":[{\"k\":\"text\",\"v\":\"a test\"}]}],\"svy_types\":{\"0\":\"JSON_obj\"}}]},\"svy_types\":{\"tabs\":\"JSON_arr\"}}", json, true);
}
Also used : TabPanel(com.servoy.j2db.persistence.TabPanel) BasicTagStringTypeSabloValue(com.servoy.j2db.server.ngclient.property.types.BasicTagStringTypeSabloValue) Form(com.servoy.j2db.persistence.Form) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) IDataAdapterList(com.servoy.j2db.server.ngclient.IDataAdapterList) DataAdapterList(com.servoy.j2db.server.ngclient.DataAdapterList) Dimension(java.awt.Dimension) FormElement(com.servoy.j2db.server.ngclient.FormElement) ServoyDataConverterContext(com.servoy.j2db.server.ngclient.ServoyDataConverterContext) ValueList(com.servoy.j2db.persistence.ValueList) IDataAdapterList(com.servoy.j2db.server.ngclient.IDataAdapterList) CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) List(java.util.List) DataAdapterList(com.servoy.j2db.server.ngclient.DataAdapterList) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 4 with FormElement

use of com.servoy.j2db.server.ngclient.FormElement 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 5 with FormElement

use of com.servoy.j2db.server.ngclient.FormElement 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)

Aggregations

FormElement (com.servoy.j2db.server.ngclient.FormElement)22 IFormElement (com.servoy.j2db.persistence.IFormElement)12 Form (com.servoy.j2db.persistence.Form)11 WebFormComponent (com.servoy.j2db.server.ngclient.WebFormComponent)10 HashMap (java.util.HashMap)10 JSONObject (org.json.JSONObject)9 ServoyDataConverterContext (com.servoy.j2db.server.ngclient.ServoyDataConverterContext)6 IDataAdapterList (com.servoy.j2db.server.ngclient.IDataAdapterList)5 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)5 Dimension (java.awt.Dimension)5 Map (java.util.Map)5 Test (org.junit.Test)5 DataAdapterList (com.servoy.j2db.server.ngclient.DataAdapterList)4 FormComponentCache (com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache)4 INGFormElement (com.servoy.j2db.server.ngclient.INGFormElement)4 IWebFormUI (com.servoy.j2db.server.ngclient.IWebFormUI)4 WebFormUI (com.servoy.j2db.server.ngclient.WebFormUI)4 CustomValueList (com.servoy.j2db.dataprocessing.CustomValueList)3 IValueList (com.servoy.j2db.dataprocessing.IValueList)3 IPersist (com.servoy.j2db.persistence.IPersist)3