Search in sources :

Example 1 with TabPanel

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"));
}
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 2 with TabPanel

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);
}
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 3 with TabPanel

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;
}
Also used : ITabPanel(com.servoy.j2db.ui.ITabPanel) TabPanel(com.servoy.j2db.persistence.TabPanel) RuntimeTabPanel(com.servoy.j2db.ui.scripting.RuntimeTabPanel) RectShape(com.servoy.j2db.persistence.RectShape) IComponent(com.servoy.j2db.ui.IComponent) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) JComponent(javax.swing.JComponent) Dimension(java.awt.Dimension) IStandardLabel(com.servoy.j2db.ui.IStandardLabel) IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean) Bean(com.servoy.j2db.persistence.Bean) RuntimeMediaField(com.servoy.j2db.ui.scripting.RuntimeMediaField) RuntimeDataLookupField(com.servoy.j2db.ui.scripting.RuntimeDataLookupField) Field(com.servoy.j2db.persistence.Field) RuntimeDataField(com.servoy.j2db.ui.scripting.RuntimeDataField) AbstractRuntimeField(com.servoy.j2db.ui.scripting.AbstractRuntimeField) WebComponent(com.servoy.j2db.persistence.WebComponent) Part(com.servoy.j2db.persistence.Part) Portal(com.servoy.j2db.persistence.Portal) RuntimePortal(com.servoy.j2db.ui.scripting.RuntimePortal)

Example 4 with TabPanel

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;
}
Also used : TabPanel(com.servoy.j2db.persistence.TabPanel) ArrayList(java.util.ArrayList) IRefreshValueList(com.servoy.j2db.IRefreshValueList) List(java.util.List) DataAdapterList(com.servoy.j2db.server.ngclient.DataAdapterList) ArrayList(java.util.ArrayList) GlobalMethodValueList(com.servoy.j2db.dataprocessing.GlobalMethodValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) Map(java.util.Map) HashMap(java.util.HashMap) Pair(com.servoy.j2db.util.Pair)

Example 5 with TabPanel

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);
}
Also used : TabPanel(com.servoy.j2db.persistence.TabPanel) Form(com.servoy.j2db.persistence.Form) Dimension(java.awt.Dimension)

Aggregations

TabPanel (com.servoy.j2db.persistence.TabPanel)15 Map (java.util.Map)7 Form (com.servoy.j2db.persistence.Form)6 HashMap (java.util.HashMap)6 Dimension (java.awt.Dimension)5 ArrayList (java.util.ArrayList)5 IDataAdapterList (com.servoy.j2db.server.ngclient.IDataAdapterList)4 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)4 List (java.util.List)4 JSFunction (org.mozilla.javascript.annotations.JSFunction)4 IValueList (com.servoy.j2db.dataprocessing.IValueList)3 BaseComponent (com.servoy.j2db.persistence.BaseComponent)3 IPersist (com.servoy.j2db.persistence.IPersist)3 Tab (com.servoy.j2db.persistence.Tab)3 DataAdapterList (com.servoy.j2db.server.ngclient.DataAdapterList)3 WebFormComponent (com.servoy.j2db.server.ngclient.WebFormComponent)3 JSONObject (org.json.JSONObject)3 CustomValueList (com.servoy.j2db.dataprocessing.CustomValueList)2 Field (com.servoy.j2db.persistence.Field)2 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)2