use of com.servoy.j2db.persistence.TabPanel in project servoy-client by Servoy.
the class RelatedFormsTest method testRelatedFormsInTabPanels.
@Test
public void testRelatedFormsInTabPanels() throws RepositoryException {
// f1 is the main
//
// 3 forms on that main
//
// f2 "relation2"
// f3 "relation2.relation3"
// f4 "relation2.relation3.relation4"
Form f1 = solution.createNewForm(validator, null, "f1", null, false, new Dimension(600, 400));
IWebFormController f1Controller = new TestFormController(f1, client);
IDataAdapterList dataAdapterListF1 = f1Controller.getFormUI().getDataAdapterList();
Form f2 = solution.createNewForm(validator, null, "f2", null, false, new Dimension(600, 400));
IWebFormController f2Controller = new TestFormController(f2, client);
IDataAdapterList dataAdapterListF2 = f2Controller.getFormUI().getDataAdapterList();
Form f3 = solution.createNewForm(validator, null, "f3", null, false, new Dimension(600, 400));
IWebFormController f3Controller = new TestFormController(f3, client);
IDataAdapterList dataAdapterListF3 = f3Controller.getFormUI().getDataAdapterList();
Form f4 = solution.createNewForm(validator, null, "f4", null, false, new Dimension(600, 400));
IWebFormController f4Controller = new TestFormController(f4, client);
IDataAdapterList dataAdapterListF4 = f4Controller.getFormUI().getDataAdapterList();
TabPanel tabpanelF2 = f1.createNewTabPanel("tabpanelF2");
tabpanelF2.createNewTab("tab1", "relation2", f2);
TabPanel tabpanelF3 = f1.createNewTabPanel("tabpanelF3");
tabpanelF3.createNewTab("tab1", "relation2.relation3", f3);
TabPanel tabpanelF4 = f1.createNewTabPanel("tabpanelF4");
tabpanelF4.createNewTab("tab1", "relation2.relation3.relation4", f4);
dataAdapterListF1.addVisibleChildForm(f2Controller, "relation2", true);
// relatedForms of f1 has now f2
Assert.assertEquals(1, dataAdapterListF1.getRelatedForms().size());
Assert.assertEquals("relation2", dataAdapterListF1.getRelatedForms().get(f2Controller));
dataAdapterListF1.addVisibleChildForm(f3Controller, "relation2.relation3", true);
// relatedForms of f1 has now f2 and f3
Assert.assertEquals(2, dataAdapterListF1.getRelatedForms().size());
Assert.assertEquals("relation2.relation3", dataAdapterListF1.getRelatedForms().get(f3Controller));
// also f2 relatedForms has f3
Assert.assertEquals(1, dataAdapterListF2.getRelatedForms().size());
Assert.assertEquals("relation3", dataAdapterListF2.getRelatedForms().get(f3Controller));
// and f3 relatedParentsForms has f2
Assert.assertEquals(1, dataAdapterListF3.getParentRelatedForms().size());
Assert.assertEquals(dataAdapterListF3.getParentRelatedForms().toString() + " should have:" + f2Controller, 0, dataAdapterListF3.getParentRelatedForms().indexOf(f2Controller));
Assert.assertNotEquals(dataAdapterListF3.getParentRelatedForms().toString() + " should have:" + f2Controller, -1, dataAdapterListF3.getParentRelatedForms().indexOf(f2Controller));
dataAdapterListF1.addVisibleChildForm(f4Controller, "relation2.relation3.relation4", true);
// relatedForms of f1 has now f2 and f3 and f4
Assert.assertEquals(3, dataAdapterListF1.getRelatedForms().size());
Assert.assertEquals("relation2.relation3.relation4", dataAdapterListF1.getRelatedForms().get(f4Controller));
// relatedForms of f2 has now f3 and f4
Assert.assertEquals(2, dataAdapterListF2.getRelatedForms().size());
Assert.assertEquals("relation3", dataAdapterListF2.getRelatedForms().get(f3Controller));
Assert.assertEquals("relation3.relation4", dataAdapterListF2.getRelatedForms().get(f4Controller));
// and f4 relatedParentsForms has f2 and f3
Assert.assertEquals(2, dataAdapterListF4.getParentRelatedForms().size());
Assert.assertTrue(dataAdapterListF4.getParentRelatedForms() + " should have " + f2Controller, dataAdapterListF4.getParentRelatedForms().indexOf(f2Controller) >= 0);
Assert.assertTrue(dataAdapterListF4.getParentRelatedForms() + " should have " + f3Controller, dataAdapterListF4.getParentRelatedForms().indexOf(f3Controller) >= 0);
dataAdapterListF1.removeVisibleChildForm(f4Controller, true);
// relatedForms of f1 has now f2 and f3
Assert.assertEquals(2, dataAdapterListF1.getRelatedForms().size());
Assert.assertEquals("relation2", dataAdapterListF1.getRelatedForms().get(f2Controller));
Assert.assertEquals("relation2.relation3", dataAdapterListF1.getRelatedForms().get(f3Controller));
// relatedForms of f2 has now f3
Assert.assertEquals(1, dataAdapterListF2.getRelatedForms().size());
Assert.assertEquals("relation3", dataAdapterListF2.getRelatedForms().get(f3Controller));
dataAdapterListF2.removeVisibleChildForm(f3Controller, true);
// relatedForms of f1 has now f2 and f3
Assert.assertEquals(2, dataAdapterListF1.getRelatedForms().size());
Assert.assertEquals("relation2", dataAdapterListF1.getRelatedForms().get(f2Controller));
Assert.assertEquals("relation2.relation3", dataAdapterListF1.getRelatedForms().get(f3Controller));
// relatedForms of f2 has no related forms
Assert.assertEquals(0, dataAdapterListF2.getRelatedForms().size());
}
use of com.servoy.j2db.persistence.TabPanel in project servoy-client by Servoy.
the class ChildrenJSONGenerator method writeFormElement.
public static void writeFormElement(JSONWriter writer, IPersist o, Form form, FormElement fe, WebFormUI formUI, ServoyDataConverterContext context, boolean designer) {
writer.key("name");
String name = designer ? fe.getDesignId() : fe.getName();
writer.value(name);
writer.key("type");
if (o instanceof TabPanel) {
// special support for TabPanel so that we have a specific tabpanel,tablesspanel,accordion and splitpane
String type = "servoydefault-tabpanel";
int orient = ((TabPanel) o).getTabOrientation();
if (orient == TabPanel.SPLIT_HORIZONTAL || orient == TabPanel.SPLIT_VERTICAL)
type = "servoydefault-splitpane";
else if (orient == TabPanel.ACCORDION_PANEL)
type = "servoydefault-accordion";
else if (orient == TabPanel.HIDE || (orient == TabPanel.DEFAULT_ORIENTATION && ((TabPanel) o).hasOneTab()))
type = "servoydefault-tablesspanel";
writer.value(ClientService.convertToJSName(type));
} else {
// hack for now to map it to the types that we know are there, so that we can test responsive without really already having to have bootstrap components.
writer.value(ClientService.convertToJSName(FormTemplateGenerator.getComponentTypeName((IFormElement) o)));
}
WebFormComponent webComponent = (formUI != null) ? formUI.getWebComponent(fe.getName()) : null;
AngularFormGenerator.writePosition(writer, o, form, webComponent, designer);
writer.key("model");
writer.object();
if (formUI != null) {
// there is a existing form, take the current properties from that.
if (webComponent != null) {
TypedData<Map<String, Object>> properties = webComponent.getProperties();
TypedData<Map<String, Object>> templateProperties = fe.propertiesForTemplateJSON();
// remove from the templates properties all the properties that are current "live" in the component
templateProperties.content.keySet().removeAll(properties.content.keySet());
DataConversion dataConversion = new DataConversion();
// write the template properties that are left
JSONUtils.writeData(FormElementToJSON.INSTANCE, writer, templateProperties.content, templateProperties.contentType, dataConversion, new FormElementContext(fe));
// write the actual values
webComponent.writeProperties(FullValueToJSONConverter.INSTANCE, null, writer, properties, dataConversion);
JSONUtils.writeClientConversions(writer, dataConversion);
} else {
System.err.println("null");
}
} else {
fe.propertiesAsTemplateJSON(writer, new FormElementContext(fe, context, null), false);
if (designer && Utils.isInheritedFormElement(o, form)) {
writer.key("svyInheritedElement");
writer.value(true);
}
}
if (designer) {
DataConversion dataConversion = new DataConversion();
fe.getWebComponentSpec().getProperties().values().forEach(pd -> {
if (pd.getType() instanceof IDesignerDefaultWriter)
((IDesignerDefaultWriter) pd.getType()).toDesignerDefaultJSONValue(writer, pd.getName(), dataConversion);
});
if (!dataConversion.getConversions().isEmpty()) {
JSONUtils.writeClientConversions(writer, dataConversion);
}
}
if (o instanceof BaseComponent) {
writer.key("servoyAttributes");
writer.object();
Map<String, String> attributes = new HashMap<String, String>(((BaseComponent) fe.getPersistIfAvailable()).getMergedAttributes());
if (designer) {
attributes.put("svy-id", fe.getDesignId());
attributes.put("svy-formelement-type", fe.getTypeName());
attributes.put("svy-name", fe.getName());
attributes.put("svy-anchors", Integer.toString(((BaseComponent) o).getAnchors()));
List<String>[] typeAndPropertyNames = fe.getSvyTypesAndPropertiesNames();
if (typeAndPropertyNames[0].size() > 0) {
attributes.put("svy-types", String.join(",", typeAndPropertyNames[0]));
attributes.put("svy-types-properties", String.join(",", typeAndPropertyNames[1]));
}
attributes.put("svy-priority", form.isResponsiveLayout() ? String.valueOf(((ISupportBounds) o).getLocation().x) : String.valueOf(((BaseComponent) o).getFormIndex()));
}
if (Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.ngclient.testingMode", "false"))) {
String elementName = name;
if (elementName.startsWith("svy_") && o.getUUID() != null) {
elementName = "svy_" + o.getUUID().toString();
}
attributes.put("data-cy", form.getName() + "." + elementName);
}
String directEditPropertyName = getDirectEditProperty(fe);
if (directEditPropertyName != null) {
attributes.put("directEditPropertyName", directEditPropertyName);
}
attributes.forEach((key, value) -> {
writer.key(StringEscapeUtils.escapeEcmaScript(key));
writer.value(value);
});
writer.endObject();
}
writer.endObject();
WebObjectSpecification spec = fe.getWebComponentSpec();
if (spec != null) {
Collection<PropertyDescription> properties = spec.getProperties(FormComponentPropertyType.INSTANCE);
if (properties.size() > 0) {
boolean isResponsive = false;
for (PropertyDescription pd : properties) {
Object propertyValue = fe.getPropertyValue(pd.getName());
Form frm = FormComponentPropertyType.INSTANCE.getForm(propertyValue, context.getSolution());
if (frm == null)
continue;
isResponsive = frm.isResponsiveLayout();
}
// responsive state can change, so send it with updates
writer.key("responsive");
writer.value(isResponsive);
}
}
Collection<String> handlers = fe.getHandlers();
if (handlers.size() > 0) {
writer.key("handlers");
writer.array();
for (String handler : handlers) {
writer.value(handler);
}
writer.endArray();
}
}
use of com.servoy.j2db.persistence.TabPanel in project servoy-client by Servoy.
the class PersistBasedFormElementImpl method getFormElementPropertyValues.
public Map<String, Object> getFormElementPropertyValues(FlattenedSolution fs, Map<String, PropertyDescription> specProperties, PropertyPath propertyPath) {
Map<String, String> parsedAttributes = new HashMap<String, String>();
if (persist instanceof BaseComponent) {
Map<String, String> attributes = new HashMap<String, String>(((BaseComponent) persist).getMergedAttributes());
if (attributes != null && attributes.size() > 0) {
attributes.forEach((key, value) -> {
if (value != null && key != null)
parsedAttributes.put(StringEscapeUtils.escapeEcmaScript(key), value);
});
}
}
if (persist instanceof IBasicWebComponent) {
if (FormTemplateGenerator.isWebcomponentBean(persist)) {
JSONObject jsonProperties = ((IBasicWebComponent) persist).getFlattenedJson();
if (jsonProperties == null)
jsonProperties = new ServoyJSONObject();
// convert from persist design-time value (which might be non-json) to the expected value
Map<String, Object> jsonMap = processPersistProperties(fs, specProperties, propertyPath);
// this is handled separately as NG component definition
jsonMap.remove(IContentSpecConstantsBase.PROPERTY_BEANXML);
// this is handled separately as NG component definition
jsonMap.remove(IContentSpecConstants.PROPERTY_JSON);
try {
// add beanXML (which is actually a JSON string here) defined properties to the map
formElement.convertFromJSONToFormElementValues(fs, specProperties, jsonMap, formElement.getWebComponentSpec().getHandlers(), jsonProperties, propertyPath);
} catch (Exception ex) {
Debug.error("Error while parsing bean design json", ex);
jsonMap.put("error", "Error while parsing bean design json(bean not supported in NGClient?): " + persist);
}
if (parsedAttributes.size() > 0) {
jsonMap.put(IContentSpecConstants.PROPERTY_ATTRIBUTES, parsedAttributes);
}
return jsonMap;
} else {
Map<String, Object> defaultProperties = new HashMap<String, Object>();
defaultProperties.put(StaticContentSpecLoader.PROPERTY_SIZE.getPropertyName(), ((IBasicWebComponent) persist).getSize());
defaultProperties.put(StaticContentSpecLoader.PROPERTY_NAME.getPropertyName(), ((IBasicWebComponent) persist).getName());
defaultProperties.put("error", "Bean not supported in NGClient: " + persist);
return defaultProperties;
}
} else if (persist instanceof AbstractBase) {
Map<String, Object> map = processPersistProperties(fs, specProperties, propertyPath);
if (persist instanceof Field && ((Field) persist).getDisplayType() == Field.MULTISELECT_LISTBOX) {
map.put("multiselectListbox", Boolean.TRUE);
} else if (persist instanceof TabPanel) {
convertFromTabPanelToNGProperties((IFormElement) persist, fs, map, specProperties, propertyPath);
} else if (persist instanceof Portal) {
convertFromPortalToNGProperties((Portal) persist, fs, map, specProperties, propertyPath);
}
if (parsedAttributes.size() > 0) {
map.put(IContentSpecConstants.PROPERTY_ATTRIBUTES, parsedAttributes);
}
return map;
} else {
return Collections.emptyMap();
}
}
use of com.servoy.j2db.persistence.TabPanel in project servoy-client by Servoy.
the class PersistBasedFormElementImpl method convertFromTabPanelToNGProperties.
private void convertFromTabPanelToNGProperties(IFormElement persist, FlattenedSolution fs, Map<String, Object> map, Map<String, PropertyDescription> specProperties, PropertyPath propertyPath) {
ArrayList<Map<String, Object>> tabList = new ArrayList<>();
// add the tabs.
Iterator<IPersist> tabs = ((TabPanel) persist).getTabs();
putAndConvertProperty("tabIndex", 1, map, fs, specProperties.get("tabIndex"), propertyPath);
PropertyDescription tabSpecProperties = specProperties.get("tabs").getProperty("[0]");
boolean active = true;
while (tabs.hasNext()) {
Map<String, Object> tabMap = new HashMap<>();
Tab tab = (Tab) tabs.next();
putAndConvertProperty("text", tab.getText(), tabMap, fs, tabSpecProperties.getProperty("text"), propertyPath);
putAndConvertProperty("relationName", tab.getRelationName(), tabMap, fs, tabSpecProperties.getProperty("relationName"), propertyPath);
putAndConvertProperty("active", Boolean.valueOf(active), tabMap, fs, tabSpecProperties.getProperty("active"), propertyPath);
tabMap.put("foreground", tab.getForeground());
putAndConvertProperty("name", tab.getName(), tabMap, fs, tabSpecProperties.getProperty("name"), propertyPath);
putAndConvertProperty("mnemonic", tab.getMnemonic(), tabMap, fs, tabSpecProperties.getProperty("mnemonic"), propertyPath);
int containsFormID = tab.getContainsFormID();
// TODO should this be resolved way later on?
// if solution model then this form can change..
Form form = fs.getForm(containsFormID);
if (form != null) {
putAndConvertProperty("containsFormId", form.getName(), tabMap, fs, tabSpecProperties.getProperty("containsFormId"), propertyPath);
}
putAndConvertProperty("disabled", false, tabMap, fs, tabSpecProperties.getProperty("disabled"), propertyPath);
int orient = ((TabPanel) persist).getTabOrientation();
if (orient != TabPanel.SPLIT_HORIZONTAL && orient != TabPanel.SPLIT_VERTICAL) {
int tabMediaID = tab.getImageMediaID();
if (tabMediaID > 0) {
putAndConvertProperty("imageMediaID", Integer.valueOf(tabMediaID), tabMap, fs, tabSpecProperties.getProperty("imageMediaID"), propertyPath);
}
}
tabList.add(tabMap);
active = false;
}
map.put("tabs", tabList.toArray());
}
use of com.servoy.j2db.persistence.TabPanel in project servoy-client by Servoy.
the class ComponentFactory method createComponent.
/**
* Create a component
*
* @param meta the definition
* @param el the event listener such as action,mouse event listeners, can be null (Example:makes possible for button to call script)
*/
public static IComponent createComponent(IApplication application, Form form, IPersist meta, IDataProviderLookup dataProviderLookup, IScriptExecuter el, boolean printing) {
IComponent c = createComponentEx(application, form, meta, dataProviderLookup, el, printing);
// set groupID property
if (meta instanceof IFormElement && ((IFormElement) meta).getGroupID() != null) {
String groupId = ((IFormElement) meta).getGroupID();
if (groupId != null) {
setComponentProperty(application, c, GROUPID_COMPONENT_PROPERTY, groupId);
}
}
// Extra call so that focusable is user set...
if (c instanceof Component) {
Component comp = (Component) c;
if (comp.isFocusable())
comp.setFocusable(true);
OrientationApplier.setOrientationToAWTComponent(comp, application.getLocale(), application.getSolution().getTextOrientation());
}
int access = application.getFlattenedSolution().getSecurityAccess(meta.getUUID(), form.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
if (access != -1) {
boolean b_visible = ((access & IRepository.VIEWABLE) != 0);
if (!b_visible) {
if (c instanceof ISupportSecuritySettings) {
((ISupportSecuritySettings) c).setViewable(false);
} else {
c.setComponentVisible(false);
}
}
if (c instanceof ISupportSecuritySettings) {
boolean b_accessible = ((access & IRepository.ACCESSIBLE) != 0);
if (!b_accessible)
((ISupportSecuritySettings) c).setAccessible(false);
}
}
// special case requested by ayton (have own security interface)
if (c instanceof ITabPanel && meta instanceof TabPanel) {
try {
int i = 0;
Iterator<IPersist> it = ((TabPanel) meta).getTabs();
while (it.hasNext()) {
Tab t = (Tab) it.next();
int access1 = application.getFlattenedSolution().getSecurityAccess(t.getUUID(), form.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
if (access1 != -1) {
boolean b_accessible = ((access1 & IRepository.ACCESSIBLE) != 0);
boolean b_visible = ((access & IRepository.VIEWABLE) != 0);
if (!b_accessible || !b_visible)
((ITabPanel) c).setTabEnabledAt(i, false);
}
i++;
}
} catch (Exception e) {
Debug.error(e);
}
}
return c;
}
Aggregations