Search in sources :

Example 1 with Tab

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

the class TemplateGenerator method createTabPanelHTML.

// private static void createTabHTML(Tab meta, StringBuffer html, TextualCSS css)
// {
// }
private static void createTabPanelHTML(TabPanel tabPanel, Form form, StringBuffer html, TextualCSS css, int startY, int endY, boolean enableAnchoring, IServiceProvider sp) {
    TextualStyle styleObj = css.addStyle('#' + ComponentFactory.getWebID(form, tabPanel));
    BorderAndPadding borderAndPadding = applyBaseComponentProperties(tabPanel, form, styleObj, null, null, sp);
    applyLocationAndSize(tabPanel, styleObj, borderAndPadding, startY, endY, form.getSize().width, enableAnchoring, tabPanel.getAnchors(), sp);
    boolean isSplitPane = tabPanel.getTabOrientation() == TabPanel.SPLIT_HORIZONTAL || tabPanel.getTabOrientation() == TabPanel.SPLIT_VERTICAL;
    // do not apply foreground to the whole tab panel
    styleObj.remove("color");
    // html.append("<table cellpadding=0 cellspacing=0 ");
    html.append("<div ");
    html.append(getWicketIDParameter(form, tabPanel));
    String tabPanelCssClass = "tabpanel";
    if (!tabPanel.getTransparent())
        tabPanelCssClass = "opaquecontainer " + tabPanelCssClass;
    boolean[] userCssClassAdded = new boolean[] { false };
    html.append(getCssClassForElement(tabPanel, userCssClassAdded, tabPanelCssClass));
    if (isSplitPane)
        html.append(" style='overflow: hidden;' ");
    html.append(">\n");
    boolean isTabbedTabPanel = false;
    // int yoffset = 0;
    if (tabPanel.getTabOrientation() != TabPanel.HIDE && tabPanel.getTabOrientation() != TabPanel.ACCORDION_PANEL && !isSplitPane && !(tabPanel.getTabOrientation() == TabPanel.DEFAULT_ORIENTATION && tabPanel.hasOneTab())) {
        // yoffset = 20;
        // html.append("\t<thead><tr valign='bottom'><th height=20>\n");
        isTabbedTabPanel = true;
        html.append("\t<div tabholder='true' class='tabs'>\n");
        html.append("\t<servoy:remove>\n");
        html.append("\t\t<div class='selected_tab'><a href='tab1'>Tab1</a></div>\n");
        html.append("\t\t<div><a href='tab1'>Tab2</a></div>\n");
        html.append("\t</servoy:remove>\n");
        Iterator<IPersist> it = tabPanel.getAllObjects();
        if (it.hasNext()) {
            Tab tab = (Tab) it.next();
            // applyTextProperties(tab, styleObj);
            html.append("\t\t<div servoy:id='tablinks'");
            html.append("><a servoy:id='tablink' href='tab1' class='tablink'><div servoy:id='icon'></div><span style=\"white-space: nowrap;\" servoy:id='linktext'>");
            html.append(getSafeText(tab.getText()));
            html.append("</span></a></div>\n");
        } else {
            html.append("\t\t<div servoy:id='tablinks'");
            html.append("><a servoy:id='tablink' href='tab1' class='tablink'><div servoy:id='icon'></div><span style=\"white-space: nowrap;\" servoy:id='linktext'>");
            html.append("No tabs");
            html.append("</span></a></div>\n");
        }
        html.append("\t</div>\n");
    // html.append("\t</th></tr></thead>\n");
    }
    // html.append("\t<tbody><tr><td>\n");
    // Insets ins = borderAndPadding != null ? borderAndPadding.getSum() : new Insets(0, 0, 0, 0);
    // int t_width = tabPanel.getSize().width - (ins.left + ins.right + 2); //not sure why to add 2
    // int t_height = (tabPanel.getSize().height - yoffset) - (ins.top + ins.bottom + 4); //not sure why to add 4
    TextualStyle style = new TextualStyle();
    style.setProperty("overflow", "auto");
    style.setProperty("position", "relative");
    // style.setProperty("height",t_height+"px");
    if (tabPanel.getBorderType() != null) {
        ComponentFactoryHelper.createBorderCSSProperties(tabPanel.getBorderType(), styleObj);
    }
    if (tabPanel.getTabOrientation() == TabPanel.ACCORDION_PANEL) {
        for (Attribute att : ServoyStyleSheet.fontAttributes) {
            styleObj.remove(att.toString());
        }
        int alignment = ISupportTextSetup.LEFT;
        String styleAlignment = null;
        if (tabPanel.getHorizontalAlignment() >= 0) {
            alignment = tabPanel.getHorizontalAlignment();
        } else if (styleObj.containsKey(CSS.Attribute.TEXT_ALIGN.toString())) {
            styleAlignment = (String) styleObj.get(CSS.Attribute.TEXT_ALIGN.toString());
        }
        if (styleAlignment == null) {
            styleAlignment = getHorizontalAlignValue(alignment);
        }
        styleObj.remove(CSS.Attribute.TEXT_ALIGN.toString());
        String tabPanelMarkupId = ComponentFactory.getWebID(form, tabPanel);
        Iterator<IPersist> it = tabPanel.getAllObjects();
        String text = "";
        if (it.hasNext()) {
            Tab tab = (Tab) it.next();
            text = tab.getText();
        }
        html.append("\t\t<div id='accordion_").append(tabPanelMarkupId).append("'servoy:id='accordion_").append(tabPanelMarkupId).append("'><div servoy:id='tabs'");
        html.append("><h3 style='text-align:");
        html.append(styleAlignment);
        html.append(";' onclick='this.getElementsByTagName(\"a\")[0].click()'><a servoy:id='tablink' href='#'><div servoy:id='icon'></div><span style=\"white-space: nowrap;\" servoy:id='linktext'>");
        html.append(getSafeText(text));
        html.append("</span></a></h3><div servoy:id='webform' ");
        // html.append(getCSSClassParameter("webform"));
        html.append("></div></div></div>\n");
    } else if (isSplitPane) {
        String tabPanelMarkupId = ComponentFactory.getWebID(form, tabPanel);
        StringBuffer leftPanelStyle = new StringBuffer("position: absolute; ");
        StringBuffer rightPanelStyle = new StringBuffer("position: absolute; ");
        if (tabPanel.getTabOrientation() == TabPanel.SPLIT_HORIZONTAL) {
            leftPanelStyle.append("top: 0px; left: 0px; bottom: 0px;");
            rightPanelStyle.append("top: 0px; bottom: 0px; right: 0px");
        } else {
            leftPanelStyle.append("top: 0px; left: 0px; right: 0px;");
            rightPanelStyle.append("left: 0px; bottom: 0px; right: 0px;");
        }
        // $NON-NLS-1$  //$NON-NLS-2$
        html.append("\t<div id='splitter_").append(tabPanelMarkupId).append("' servoy:id='splitter' style='").append(leftPanelStyle).append("'><div id='websplit_left_").append(tabPanelMarkupId).append("' servoy:id='websplit_left' style='").append(leftPanelStyle).append(// $NON-NLS-1$  //$NON-NLS-2$ //$NON-NLS-3$
        "' ").append("><div servoy:id='webform'").append(getCSSClassParameter("webform")).append(// $NON-NLS-1$
        "></div></div></div>");
        // $NON-NLS-1$//$NON-NLS-2$
        html.append("<div id='websplit_right_").append(tabPanelMarkupId).append("' servoy:id='websplit_right' style='").append(rightPanelStyle).append(// $NON-NLS-1$
        "' ").append("><div servoy:id='webform'").append(getCSSClassParameter("webform")).append(// $NON-NLS-1$
        "></div></div>");
    } else {
        html.append("\t<div servoy:id='webform' ").append(style.toString());
        String cssClass = "webform";
        boolean tabPanelHasBorder = tabPanel.getBorderType() != null || styleObj.containsKey(CSS.Attribute.BORDER_STYLE.toString());
        if (isTabbedTabPanel && !tabPanelHasBorder) {
            // apply default border
            cssClass = "tabcontainer " + cssClass;
        }
        html.append(getCSSClassParameter(cssClass));
        html.append("></div>");
    }
    html.append("</div>");
// html.append("</td></tr></tbody></table>");
}
Also used : Tab(com.servoy.j2db.persistence.Tab) IPersist(com.servoy.j2db.persistence.IPersist) Attribute(javax.swing.text.html.CSS.Attribute) Point(java.awt.Point)

Example 2 with Tab

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

the class ComponentFactory method createSplitPane.

private static IComponent createSplitPane(IApplication application, Form form, TabPanel meta, IScriptExecuter el) {
    RuntimeSplitPane scriptable = new RuntimeSplitPane(application.getItemFactory().createChangesRecorder(), application);
    ISplitPane splitPane = application.getItemFactory().createSplitPane(scriptable, getWebID(form, meta), meta.getTabOrientation());
    scriptable.setComponent(splitPane, meta);
    applyBasicComponentProperties(application, splitPane, meta, getStyleForBasicComponent(application, meta, form));
    try {
        int index = 0;
        Iterator<IPersist> it = meta.getTabs();
        while (it.hasNext() && index < 2) {
            Tab tab = (Tab) it.next();
            Form f = application.getFlattenedSolution().getForm(tab.getContainsFormID());
            if (f != null) {
                IFormLookupPanel flp = splitPane.createFormLookupPanel(tab.getName(), tab.getRelationName(), f.getName());
                if (index < 1)
                    splitPane.setLeftForm(flp);
                else
                    splitPane.setRightForm(flp);
                index++;
            }
        }
    } catch (Exception ex) {
        Debug.error(ex);
    }
    splitPane.setDividerLocation(meta.getTabOrientation() == TabPanel.SPLIT_HORIZONTAL ? splitPane.getSize().width / 2 : splitPane.getSize().height / 2);
    if (el != null && meta.getOnChangeMethodID() > 0) {
        splitPane.setOnDividerChangeMethodCmd((Integer.toString(meta.getOnChangeMethodID())));
        splitPane.addScriptExecuter(el);
    }
    return splitPane;
}
Also used : ISplitPane(com.servoy.j2db.ui.ISplitPane) Tab(com.servoy.j2db.persistence.Tab) IPersist(com.servoy.j2db.persistence.IPersist) IForm(com.servoy.j2db.IForm) Form(com.servoy.j2db.persistence.Form) RuntimeSplitPane(com.servoy.j2db.ui.scripting.RuntimeSplitPane) JSONException(org.json.JSONException) IOException(java.io.IOException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IFormLookupPanel(com.servoy.j2db.ui.IFormLookupPanel)

Example 3 with Tab

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

the class ComponentFactory method createTabPanel.

private static IComponent createTabPanel(IApplication application, Form form, TabPanel meta, IScriptExecuter el) {
    // HACK:To set the selected color on a tabpanel
    Color oldColor = null;
    if (meta.getSelectedTabColor() != null) {
        oldColor = UIManager.getColor("TabbedPane.selected");
        UIManager.put("TabbedPane.selected", meta.getSelectedTabColor());
    }
    int orient = meta.getTabOrientation();
    AbstractRuntimeTabPaneAlike scriptable = null;
    ITabPanel tabs;
    if (meta.getTabOrientation() == TabPanel.ACCORDION_PANEL) {
        scriptable = new RuntimeAccordionPanel(application.getItemFactory().createChangesRecorder(), application);
        tabs = application.getItemFactory().createAccordionPanel((RuntimeAccordionPanel) scriptable, getWebID(form, meta));
    } else {
        scriptable = new RuntimeTabPanel(application.getItemFactory().createChangesRecorder(), application);
        tabs = application.getItemFactory().createTabPanel((RuntimeTabPanel) scriptable, getWebID(form, meta), orient, meta.hasOneTab());
    }
    scriptable.setComponent(tabs, meta);
    if (meta.getScrollTabs()) {
        tabs.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    } else {
        tabs.setTabLayoutPolicy(JTabbedPane.WRAP_TAB_LAYOUT);
    }
    if (el != null && meta.getOnTabChangeMethodID() > 0) {
        tabs.setOnTabChangeMethodCmd(Integer.toString(meta.getOnTabChangeMethodID()), Utils.parseJSExpressions(meta.getFlattenedMethodArguments("onTabChangeMethodID")));
        tabs.addScriptExecuter(el);
    }
    applyBasicComponentProperties(application, tabs, meta, getStyleForBasicComponent(application, meta, form));
    if (meta.getHorizontalAlignment() >= 0) {
        tabs.setHorizontalAlignment(meta.getHorizontalAlignment());
    }
    // HACK:restore so not all tabpanel get that color!
    if (meta.getSelectedTabColor() != null)
        UIManager.put("TabbedPane.selected", oldColor);
    try {
        int index = 0;
        Iterator<IPersist> it = meta.getTabs();
        while (it.hasNext()) {
            Tab tab = (Tab) it.next();
            Form f = application.getFlattenedSolution().getForm(tab.getContainsFormID());
            if (f != null) {
                IFormLookupPanel flp = tabs.createFormLookupPanel(tab.getName(), tab.getRelationName(), f.getName());
                tabs.addTab(application.getI18NMessageIfPrefixed(tab.getText()), tab.getImageMediaID(), flp, application.getI18NMessageIfPrefixed(tab.getToolTipText()));
                Color fg = tab.getForeground();
                Color bg = tab.getBackground();
                if (fg != null)
                    tabs.setTabForegroundAt(index, fg);
                if (bg != null)
                    tabs.setTabBackgroundAt(index, bg);
                String mnemonic = application.getI18NMessageIfPrefixed(tab.getMnemonic());
                if (mnemonic != null && mnemonic.length() > 0) {
                    tabs.setMnemonicAt(index, mnemonic.charAt(0));
                }
                index++;
            }
        }
    } catch (Exception ex) {
        Debug.error(ex);
    }
    return tabs;
}
Also used : AbstractRuntimeTabPaneAlike(com.servoy.j2db.ui.scripting.AbstractRuntimeTabPaneAlike) IForm(com.servoy.j2db.IForm) Form(com.servoy.j2db.persistence.Form) Color(java.awt.Color) ITabPanel(com.servoy.j2db.ui.ITabPanel) RuntimeAccordionPanel(com.servoy.j2db.ui.scripting.RuntimeAccordionPanel) JSONException(org.json.JSONException) IOException(java.io.IOException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IFormLookupPanel(com.servoy.j2db.ui.IFormLookupPanel) Tab(com.servoy.j2db.persistence.Tab) RuntimeTabPanel(com.servoy.j2db.ui.scripting.RuntimeTabPanel) IPersist(com.servoy.j2db.persistence.IPersist)

Example 4 with Tab

use of com.servoy.j2db.persistence.Tab 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 5 with Tab

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

the class JSTabPanel method getTabs.

/**
 * Returns an array of JSTab instances holding the tabs of the tab panel.
 *
 * @sample
 * var tabPanel = form.newTabPanel('tabs', 10, 10, 620, 460);
 * tabPanel.newTab('tab1', 'Child Two', childOne);
 * tabPanel.newTab('tab2', 'Child Two', childTwo);
 * var tabs = tabPanel.getTabs();
 * for (var i=0; i<tabs.length; i++)
 * 	application.output("Tab " + i + " has text " + tabs[i].text);
 *
 * @return An array of JSTab instances representing all tabs of this tabpanel.
 */
@JSFunction
public JSTab[] getTabs() {
    ArrayList<JSTab> labels = new ArrayList<JSTab>();
    Iterator<IPersist> tabs = getBaseComponent(false).getTabs();
    while (tabs.hasNext()) {
        Tab tab = (Tab) tabs.next();
        labels.add(new JSTab(this, tab, application, false));
    }
    return labels.toArray(new JSTab[labels.size()]);
}
Also used : Tab(com.servoy.j2db.persistence.Tab) IPersist(com.servoy.j2db.persistence.IPersist) ArrayList(java.util.ArrayList) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Aggregations

Tab (com.servoy.j2db.persistence.Tab)9 IPersist (com.servoy.j2db.persistence.IPersist)8 Form (com.servoy.j2db.persistence.Form)4 RepositoryException (com.servoy.j2db.persistence.RepositoryException)4 TabPanel (com.servoy.j2db.persistence.TabPanel)3 ArrayList (java.util.ArrayList)3 JSFunction (org.mozilla.javascript.annotations.JSFunction)3 IForm (com.servoy.j2db.IForm)2 WebComponent (com.servoy.j2db.persistence.WebComponent)2 IFormLookupPanel (com.servoy.j2db.ui.IFormLookupPanel)2 ITabPanel (com.servoy.j2db.ui.ITabPanel)2 RuntimeTabPanel (com.servoy.j2db.ui.scripting.RuntimeTabPanel)2 IOException (java.io.IOException)2 JSONException (org.json.JSONException)2 PropertyDescription (org.sablo.specification.PropertyDescription)2 IFormController (com.servoy.j2db.IFormController)1 FoundSetManager (com.servoy.j2db.dataprocessing.FoundSetManager)1 RelatedFoundSet (com.servoy.j2db.dataprocessing.RelatedFoundSet)1 DebugSwingFormMananger (com.servoy.j2db.debug.DebugJ2DBClient.DebugSwingFormMananger)1 BaseComponent (com.servoy.j2db.persistence.BaseComponent)1