Search in sources :

Example 6 with Form

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

the class FormElement method adjustLocationRelativeToPart.

private void adjustLocationRelativeToPart(FlattenedSolution fs, Map<String, Object> map) {
    if (map != null && form != null) {
        Form flatForm = fs.getFlattenedForm(form);
        Point location = getDesignLocation();
        if (location != null) {
            // if it is design client, it has no parts
            boolean isInDesginer = getDesignId() != null;
            if (isInDesginer) {
                map.put(StaticContentSpecLoader.PROPERTY_LOCATION.getPropertyName(), location);
                map.put("offsetY", 0);
            } else {
                Point newLocation = new Point(location);
                Part part = flatForm.getPartAt(location.y);
                if (part != null) {
                    int top = flatForm.getPartStartYPos(part.getID());
                    newLocation.y = newLocation.y - top;
                    map.put(StaticContentSpecLoader.PROPERTY_LOCATION.getPropertyName(), newLocation);
                    map.put("offsetY", top);
                    map.put("partHeight", part.getHeight());
                }
            }
        }
    }
}
Also used : Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) Part(com.servoy.j2db.persistence.Part) Point(java.awt.Point) Point(java.awt.Point)

Example 7 with Form

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

the class FormElement method getHandlers.

public <T> Collection<T> getHandlers(boolean skipPrivate, Class<T> clazz) {
    List<T> handlers = new ArrayList<>();
    Form mainForm = getForm();
    if (isFormComponentChild()) {
        String mainFormName = ((AbstractBase) getPersistIfAvailable()).getRuntimeProperty(FormElementHelper.FORM_COMPONENT_FORM_NAME);
        if (fs != null && mainFormName != null) {
            mainForm = fs.getForm(mainFormName);
            mainForm = fs.getFlattenedForm(mainForm);
        }
    }
    if (mainForm == null) {
        mainForm = getForm();
    }
    WebObjectSpecification componentSpec = getWebComponentSpec();
    Set<Entry<String, WebObjectFunctionDefinition>> entries = componentSpec.getHandlers().entrySet();
    for (Entry<String, WebObjectFunctionDefinition> entry : entries) {
        if (skipPrivate && entry.getValue().isPrivate())
            continue;
        String eventName = entry.getKey();
        @SuppressWarnings("unchecked") T item = clazz == WebObjectFunctionDefinitionWrapper.class ? (T) new WebObjectFunctionDefinitionWrapper(entry.getValue()) : (T) eventName;
        Object eventValue = getPropertyValue(eventName);
        if (eventValue != null && !(eventValue instanceof Integer && (((Integer) eventValue).intValue() == -1 || ((Integer) eventValue).intValue() == 0))) {
            handlers.add(item);
        } else if (Utils.equalObjects(eventName, StaticContentSpecLoader.PROPERTY_ONFOCUSGAINEDMETHODID.getPropertyName()) && (mainForm.getOnElementFocusGainedMethodID() > 0)) {
            handlers.add(item);
        } else if (Utils.equalObjects(eventName, StaticContentSpecLoader.PROPERTY_ONFOCUSLOSTMETHODID.getPropertyName()) && (mainForm.getOnElementFocusLostMethodID() > 0)) {
            handlers.add(item);
        }
    }
    return handlers;
}
Also used : WebObjectSpecification(org.sablo.specification.WebObjectSpecification) Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) ArrayList(java.util.ArrayList) AbstractBase(com.servoy.j2db.persistence.AbstractBase) WebObjectFunctionDefinition(org.sablo.specification.WebObjectFunctionDefinition) Entry(java.util.Map.Entry) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject)

Example 8 with Form

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

the class ValuelistPropTest method fillTestSolution.

@Override
protected void fillTestSolution() throws ServoyException {
    try {
        ValueList vl = solution.createNewValueList(validator, "myVl1");
        vl.setCustomValues("1\n2\n3");
        vl = solution.createNewValueList(validator, "myVl2");
        vl.setCustomValues("11\n22\n33");
        Form form = solution.createNewForm(validator, null, "test", "mem:test", false, new Dimension(600, 400));
        form.setNavigatorID(-1);
        form.createNewPart(IBaseSMPart.BODY, 5);
        form.createNewWebComponent("myCustomComponent", "my-component");
    } catch (JSONException e) {
        e.printStackTrace();
        throw new ServoyException();
    }
}
Also used : ValueList(com.servoy.j2db.persistence.ValueList) Form(com.servoy.j2db.persistence.Form) JSONException(org.json.JSONException) Dimension(java.awt.Dimension) ServoyException(com.servoy.j2db.util.ServoyException)

Example 9 with Form

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

the class EventCallTest method fillTestSolution.

@Override
protected void fillTestSolution() throws ServoyException {
    Form form = solution.createNewForm(validator, null, "test", null, false, new Dimension(600, 400));
    form.setNavigatorID(-1);
    form.createNewScriptVariable(DummyValidator.INSTANCE, "testVar", IColumnTypes.INTEGER);
    GraphicalComponent button = form.createNewGraphicalComponent(new Point(10, 10));
    button.setShowClick(true);
    button.setShowFocus(true);
    ScriptMethod sm = form.createNewScriptMethod(DummyValidator.INSTANCE, "test");
    sm.setDeclaration("function test() {testVar = 10}");
    button.setOnActionMethodID(sm.getID());
    form.createNewScriptVariable(DummyValidator.INSTANCE, "testVar2", IColumnTypes.TEXT);
    GraphicalComponent button2 = form.createNewGraphicalComponent(new Point(10, 10));
    button2.setName(uuid);
    button2.setShowClick(true);
    button2.setShowFocus(true);
    ScriptMethod sm2 = form.createNewScriptMethod(DummyValidator.INSTANCE, "test2");
    sm2.setDeclaration("function test2() {testVar2 = elements['" + uuid + "'].getName()}");
    button2.setOnActionMethodID(sm2.getID());
}
Also used : Form(com.servoy.j2db.persistence.Form) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) Dimension(java.awt.Dimension) Point(java.awt.Point) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod)

Example 10 with Form

use of com.servoy.j2db.persistence.Form 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)

Aggregations

Form (com.servoy.j2db.persistence.Form)146 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)35 ArrayList (java.util.ArrayList)32 Point (java.awt.Point)26 FlattenedSolution (com.servoy.j2db.FlattenedSolution)24 IPersist (com.servoy.j2db.persistence.IPersist)22 ISMForm (com.servoy.j2db.solutionmodel.ISMForm)20 JSONObject (org.json.JSONObject)20 Solution (com.servoy.j2db.persistence.Solution)16 Dimension (java.awt.Dimension)15 Part (com.servoy.j2db.persistence.Part)14 RepositoryException (com.servoy.j2db.persistence.RepositoryException)14 FormController (com.servoy.j2db.FormController)13 WebFormComponent (com.servoy.j2db.server.ngclient.WebFormComponent)12 IMobileSMForm (com.servoy.base.solutionmodel.mobile.IMobileSMForm)11 IForm (com.servoy.j2db.IForm)11 ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)11 FormElement (com.servoy.j2db.server.ngclient.FormElement)11 HashMap (java.util.HashMap)11 JSFunction (org.mozilla.javascript.annotations.JSFunction)11