Search in sources :

Example 6 with TabPanel

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

the class WebFormController method notifyVisible.

@Override
public boolean notifyVisible(boolean visible, List<Runnable> invokeLaterRunnables) {
    if (isFormVisible == visible)
        return true;
    if (!visible && destroyOnHide) {
        Runnable run = new Runnable() {

            public void run() {
                destroy();
            }
        };
        invokeLaterRunnables.add(run);
    }
    boolean notifyVisibleSuccess = super.notifyVisible(visible, invokeLaterRunnables);
    if (notifyVisibleSuccess) {
        for (WebComponent comp : getFormUI().getComponents()) {
            RuntimeWebComponent runtimeComponent = getFormUI().getRuntimeWebComponent(comp.getName());
            if (runtimeComponent != null) {
                WebObjectFunctionDefinition function = null;
                if (visible)
                    function = comp.getSpecification().getInternalApiFunction("onShow");
                else
                    function = comp.getSpecification().getInternalApiFunction("onHide");
                if (function != null) {
                    runtimeComponent.executeScopeFunction(function, new Object[0]);
                }
            }
        }
    }
    if (visible && !isFormVisible) {
        // note: the show operation (visible = true in if above) of a form cannot be denied, so we can update things before the call to super.notifyVisible below
        for (WebComponent comp : getFormUI().getComponents()) {
            if ((comp instanceof WebFormComponent) && ((WebFormComponent) comp).getFormElement().getPersistIfAvailable() instanceof TabPanel) {
                Object visibleTabPanel = comp.getProperty("visible");
                if (visibleTabPanel instanceof Boolean && !((Boolean) visibleTabPanel).booleanValue())
                    continue;
                Object tabIndex = comp.getProperty("tabIndex");
                Object tabs = comp.getProperty("tabs");
                if (tabs instanceof List && ((List) tabs).size() > 0) {
                    List tabsList = (List) tabs;
                    TabPanel tabpanel = (TabPanel) ((WebFormComponent) comp).getFormElement().getPersistIfAvailable();
                    if (tabpanel.getTabOrientation() == TabPanel.SPLIT_HORIZONTAL || tabpanel.getTabOrientation() == TabPanel.SPLIT_VERTICAL) {
                        for (Object element : tabsList) {
                            Map<String, Object> tab = (Map<String, Object>) element;
                            if (tab != null) {
                                String relationName = tab.get("relationName") != null ? tab.get("relationName").toString() : null;
                                Object tabForm = tab.get("containsFormId");
                                if (tabForm != null) {
                                    getFormUI().getDataAdapterList().addVisibleChildForm(getApplication().getFormManager().getForm(tabForm.toString()), relationName, true);
                                }
                            }
                        }
                    } 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 = (Map<String, Object>) (tabsList.get(index));
                        } else if (tabIndex instanceof String || tabIndex instanceof CharSequence) {
                            for (Object element : tabsList) {
                                Map<String, Object> tab = (Map<String, Object>) 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 tabForm = visibleTab.get("containsFormId");
                            if (tabForm != null) {
                                getFormUI().getDataAdapterList().addVisibleChildForm(getApplication().getFormManager().getForm(tabForm.toString()), relationName, true);
                            }
                        }
                    }
                }
            }
        }
    }
    // TODO should notifyVisibleSuccess be altered here? See WebFormUI/WebFormComponent notifyVisible calls.
    if (notifyVisibleSuccess)
        notifyVisibleOnChildren(visible, invokeLaterRunnables);
    return notifyVisibleSuccess;
}
Also used : TabPanel(com.servoy.j2db.persistence.TabPanel) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) WebObjectFunctionDefinition(org.sablo.specification.WebObjectFunctionDefinition) Point(java.awt.Point) WebComponent(org.sablo.WebComponent) IDataAdapterList(com.servoy.j2db.server.ngclient.IDataAdapterList) List(java.util.List) ArrayList(java.util.ArrayList) SortedList(com.servoy.j2db.util.SortedList) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 7 with TabPanel

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

the class JSForm method newTabPanel.

/**
 * Creates a new JSTabPanel object on the form - including the name of the JSTabPanel object, the "x" and "y" position of the JSTabPanel object in pixels, as well as the width and height of the JSTabPanel object in pixels.
 *
 * @sample
 * var form = solutionModel.newForm('parentForm','db:/server1/parent_table',null,false,640,480);
 * var childOne = solutionModel.newForm('childOne','db:/server1/child_table',null,false,400,300);
 * childOne.newField('child_table_text', JSField.TEXT_FIELD,10,10,100,20);
 * var parentToChild = solutionModel.newRelation('parentToChild','db:/server1/parent_table','db:/server1/child_table',JSRelation.INNER_JOIN);
 * parentToChild.newRelationItem('parent_table_id','=','child_table_parent_id');
 * var childTwo = solutionModel.newForm('childTwo','db:/server1/my_table',null,false,400,300);
 * childTwo.newField('my_table_image', JSField.IMAGE_MEDIA,10,10,100,100);
 * var tabPanel = form.newTabPanel('tabs',10,10,620,460);
 * tabPanel.newTab('tab1','Child One',childOne,parentToChild);
 * tabPanel.newTab('tab2','Child Two',childTwo);
 * forms['parentForm'].controller.show();
 *
 * @param name the specified name of the JSTabPanel object
 * @param x the horizontal "x" position of the JSTabPanel object in pixels
 * @param y the vertical "y" position of the JSTabPanel object in pixels
 * @param width the width of the JSTabPanel object in pixels
 * @param height the height of the JSTabPanel object in pixels
 *
 * @return a JSTabPanel object
 */
@JSFunction
public JSTabPanel newTabPanel(String name, int x, int y, int width, int height) {
    checkModification();
    try {
        TabPanel tabPanel = getContainer().createNewTabPanel(IdentDocumentValidator.checkName(name));
        CSSPositionUtils.setSize(tabPanel, width, height);
        CSSPositionUtils.setLocation(tabPanel, x, y);
        return new JSTabPanel(this, tabPanel, application, true);
    } catch (RepositoryException e) {
        throw new RuntimeException(e);
    }
}
Also used : TabPanel(com.servoy.j2db.persistence.TabPanel) RepositoryException(com.servoy.j2db.persistence.RepositoryException) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 8 with TabPanel

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

the class JSTabPanel method removeTab.

/**
 * Removes the tab with the specified name from the tab panel.
 *
 * @param name the name of the tab to be removed
 *
 * @sample
 * var tabPanel = form.newTabPanel('tabs', 10, 10, 620, 460);
 * tabPanel.newTab('tab1', 'Child Two', childOne);
 * tabPanel.newTab('tab2', 'Child Two', childTwo);
 * tabPanel.removeTab('tab1');
 */
@JSFunction
public void removeTab(String name) {
    if (name == null)
        return;
    TabPanel tp = getBaseComponent(true);
    Iterator<IPersist> tabs = tp.getTabs();
    while (tabs.hasNext()) {
        Tab tab = (Tab) tabs.next();
        if (name.equals(tab.getName())) {
            // removing the child tab from the tabpanel
            tp.removeChild(tab);
            break;
        }
    }
}
Also used : TabPanel(com.servoy.j2db.persistence.TabPanel) ISMTabPanel(com.servoy.j2db.solutionmodel.ISMTabPanel) Tab(com.servoy.j2db.persistence.Tab) IPersist(com.servoy.j2db.persistence.IPersist) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 9 with TabPanel

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

the class JSForm method removeTabPanel.

/**
 * Removes a JSTabPanel that has the given name. Returns true if removal was successful, false otherwise.
 *
 * @sample
 * var form = solutionModel.newForm('newFormX','db:/server1/parent_table',null,false,800,600);
 * var childOne = solutionModel.newForm('childOne','db:/server1/child_table',null,false,400,300);
 * childOne.newField('child_table_text', JSField.TEXT_FIELD,10,10,100,20);
 * var parentToChild = solutionModel.newRelation('parentToChild','db:/server1/parent_table','db:/server1/child_table',JSRelation.INNER_JOIN);
 * parentToChild.newRelationItem('parent_table_id','=','child_table_id');
 * var childTwo = solutionModel.newForm('childTwo','db:/server1/another_table',null,false,400,300);
 * childTwo.newField('columnDataProvider', JSField.TEXT_FIELD,10,10,100,100);
 * var tabPanel = form.newTabPanel('jst',10,10,620,460);
 * tabPanel.newTab('tab1','Child One',childOne,parentToChild);
 * tabPanel.newTab('tab2','Child Two',childTwo);
 * var jsmethod = form.newMethod("function removeMe(event) { var form = solutionModel.getForm('newFormX');\n if (form.removeComponent('jst') == true)\n application.output('TabPanel has been removed ok');\n else\n application.output('TabPanel could not be deleted');\n forms['newFormX'].controller.recreateUI();\n}");
 * var removerButton = form.newButton('Click here to remove the tab panel',450,500,250,50,jsmethod);
 * removerButton.name = 'remover';
 * forms['newFormX'].controller.show();
 *
 * @param name the specified name of the JSTabPanel to be removed
 *
 * @return true is the JSTabPanel has been successfully removed, false otherwise
 */
@JSFunction
public boolean removeTabPanel(String name) {
    if (name == null)
        return false;
    checkModification();
    Iterator<TabPanel> tabPanels = getContainer().getTabPanels();
    while (tabPanels.hasNext()) {
        TabPanel tabPanel = tabPanels.next();
        if (name.equals(tabPanel.getName())) {
            getContainer().removeChild(tabPanel);
            return true;
        }
    }
    return false;
}
Also used : TabPanel(com.servoy.j2db.persistence.TabPanel) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 10 with TabPanel

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

the class JSForm method getTabPanels.

/**
 * Returns all JSTabPanels of this form (optionally the ones from the parent form), including the ones without a name.
 *
 * @sample
 * var frm = solutionModel.getForm("myForm");
 * var tabPanels = frm.getTabPanels();
 * for (var i in tabPanels)
 * {
 *	var tp = tabPanels[i];
 *	if (tp.name != null)
 *		application.output("Tab " + tp.name + " has text " + tp.text);
 *	else
 *		application.output("Tab with text " + tp.text + " has no name");
 * }
 *
 * @param returnInheritedElements boolean true to also return the elements from parent form
 * @return an array of all JSTabPanel objects on this form
 */
@JSFunction
public JSTabPanel[] getTabPanels(boolean returnInheritedElements) {
    List<JSTabPanel> tabPanels = new ArrayList<JSTabPanel>();
    AbstractContainer form2use = returnInheritedElements ? getFlattenedContainer() : getContainer();
    Iterator<TabPanel> iterator = form2use.getTabPanels();
    while (iterator.hasNext()) {
        tabPanels.add(new JSTabPanel(this, iterator.next(), application, false));
    }
    return tabPanels.toArray(new JSTabPanel[tabPanels.size()]);
}
Also used : TabPanel(com.servoy.j2db.persistence.TabPanel) AbstractContainer(com.servoy.j2db.persistence.AbstractContainer) ArrayList(java.util.ArrayList) JSFunction(org.mozilla.javascript.annotations.JSFunction)

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