use of com.servoy.j2db.persistence.TabPanel 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"));
}
use of com.servoy.j2db.persistence.TabPanel 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);
}
use of com.servoy.j2db.persistence.TabPanel in project servoy-client by Servoy.
the class ComponentFactory method createComponentEx.
protected static IComponent createComponentEx(IApplication application, Form form, IPersist meta, IDataProviderLookup dataProviderLookup, IScriptExecuter el, boolean printing) {
IComponent comp = null;
switch(meta.getTypeID()) {
case IRepository.FIELDS:
comp = createField(application, form, (Field) meta, dataProviderLookup, el, printing);
break;
case IRepository.GRAPHICALCOMPONENTS:
comp = createGraphicalComponent(application, form, (GraphicalComponent) meta, el, dataProviderLookup);
break;
case IRepository.RECTSHAPES:
comp = createRectangle(application, form, (RectShape) meta);
break;
case IRepository.PORTALS:
comp = createPortal(application, form, (Portal) meta, dataProviderLookup, el, printing);
break;
case IRepository.PARTS:
comp = createPart(application, (Part) meta);
break;
case IRepository.TABPANELS:
TabPanel tabPanelMeta = (TabPanel) meta;
int orient = tabPanelMeta.getTabOrientation();
if (orient == TabPanel.SPLIT_HORIZONTAL || orient == TabPanel.SPLIT_VERTICAL)
comp = createSplitPane(application, form, tabPanelMeta, el);
else
comp = createTabPanel(application, form, tabPanelMeta, el);
break;
case IRepository.BEANS:
comp = createBean(application, form, (Bean) meta, null);
break;
case IRepository.WEBCOMPONENTS:
comp = createWebComponentPlaceholder(application, form, (WebComponent) meta);
break;
default:
Debug.error("ComponentFactory:unkown type " + meta.getTypeID() + ", uuid: " + meta.getUUID() + ", parent:" + meta.getParent());
IStandardLabel label = application.getItemFactory().createLabel(getWebID(form, meta), "ComponentFactory:unkown type " + meta.getTypeID());
label.setSize(new Dimension(200, 20));
comp = label;
}
if (comp instanceof JComponent) {
((JComponent) comp).putClientProperty("Id", ComponentFactory.getWebID(form, meta));
}
return comp;
}
use of com.servoy.j2db.persistence.TabPanel in project servoy-client by Servoy.
the class RuntimeWebComponent method getVisibleForms.
private List<Pair<String, String>> getVisibleForms() {
List<Pair<String, String>> visibleContainedForms = new ArrayList<Pair<String, String>>();
// legacy for now, should we do it more general, from the spec
if (component.getFormElement() != null && component.getFormElement().getPersistIfAvailable() instanceof TabPanel) {
Object visibleTabPanel = component.getProperty("visible");
if (visibleTabPanel instanceof Boolean && !((Boolean) visibleTabPanel).booleanValue())
return visibleContainedForms;
Object tabIndex = component.getProperty("tabIndex");
Object tabs = component.getProperty("tabs");
if (tabs instanceof List && ((List<?>) tabs).size() > 0) {
@SuppressWarnings("unchecked") List<Map<String, Object>> tabsList = (List<Map<String, Object>>) tabs;
TabPanel tabpanel = (TabPanel) component.getFormElement().getPersistIfAvailable();
if (tabpanel.getTabOrientation() == TabPanel.SPLIT_HORIZONTAL || tabpanel.getTabOrientation() == TabPanel.SPLIT_VERTICAL) {
for (Map<String, Object> element : tabsList) {
Map<String, Object> tab = element;
if (tab != null) {
String relationName = tab.get("relationName") != null ? tab.get("relationName").toString() : null;
Object form = tab.get("containsFormId");
if (form != null) {
visibleContainedForms.add(new Pair<String, String>(form.toString(), relationName));
}
}
}
} else {
Map<String, Object> visibleTab = null;
if (tabIndex instanceof Number && tabsList.size() > 0 && ((Number) tabIndex).intValue() <= tabsList.size()) {
int index = ((Number) tabIndex).intValue() - 1;
if (index < 0) {
index = 0;
}
visibleTab = (tabsList.get(index));
} else if (tabIndex instanceof String || tabIndex instanceof CharSequence) {
for (Map<String, Object> element : tabsList) {
Map<String, Object> tab = element;
if (Utils.equalObjects(tabIndex, tab.get("name"))) {
visibleTab = tab;
break;
}
}
}
if (visibleTab != null) {
String relationName = visibleTab.get("relationName") != null ? visibleTab.get("relationName").toString() : null;
Object form = visibleTab.get("containsFormId");
if (form != null) {
visibleContainedForms.add(new Pair<String, String>(form.toString(), relationName));
}
}
}
}
}
return visibleContainedForms;
}
use of com.servoy.j2db.persistence.TabPanel in project servoy-client by Servoy.
the class TabPanelTest method fillTestSolution.
/*
* @see com.servoy.j2db.server.ngclient.property.AbstractSolutionTest#fillTestSolution()
*/
@Override
protected void fillTestSolution() throws ServoyException {
Form f1 = solution.createNewForm(validator, null, "f1", null, false, new Dimension(600, 400));
f1.setNavigatorID(-1);
Form f2 = solution.createNewForm(validator, null, "f2", null, false, new Dimension(600, 400));
Form f3 = solution.createNewForm(validator, null, "f3", null, false, new Dimension(600, 400));
Form f4 = solution.createNewForm(validator, null, "f4", null, false, new Dimension(600, 400));
TabPanel tabpanelF2 = f1.createNewTabPanel("tabpanel");
tabpanelF2.createNewTab("tab1", "relation2", f2);
tabpanelF2.createNewTab("tab2", "relation3", f3);
tabpanelF2.createNewTab("tab3", "relation4", f4);
}
Aggregations