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());
}
}
}
}
}
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;
}
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();
}
}
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());
}
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());
}
Aggregations