Search in sources :

Example 1 with ITabPanel

use of com.servoy.j2db.ui.ITabPanel in project servoy-client by Servoy.

the class DesignModeBehavior method renderHead.

/**
 * @see org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#renderHead(org.apache.wicket.markup.html.IHeaderResponse)
 */
@Override
public void renderHead(IHeaderResponse response) {
    super.renderHead(response);
    YUILoader.renderResize(response);
    final ArrayList<Component> markupIds = new ArrayList<Component>();
    final ArrayList<Component> dropMarkupIds = new ArrayList<Component>();
    ((MarkupContainer) getComponent()).visitChildren(IComponent.class, new IVisitor<Component>() {

        public Object component(Component component) {
            if (!(component instanceof WebDataRenderer)) {
                markupIds.add(component);
                if (component instanceof ITabPanel || component instanceof WebDataCalendar) {
                    return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
                }
            } else if (component instanceof WebDataRenderer) {
                dropMarkupIds.add(component);
            }
            return IVisitor.CONTINUE_TRAVERSAL;
        }
    });
    if (markupIds.size() > 0) {
        boolean webAnchorsEnabled = Utils.getAsBoolean(((WebClientSession) Session.get()).getWebClient().getRuntimeProperties().get("enableAnchors"));
        // WebClientSession webClientSession = (WebClientSession)getSession();
        // WebClient webClient = webClientSession.getWebClient();
        ArrayList<String> selectedComponentsId = new ArrayList<String>();
        StringBuilder sb = new StringBuilder(markupIds.size() * 10);
        sb.append("Servoy.ClientDesign.attach({");
        for (int i = 0; i < markupIds.size(); i++) {
            Component component = markupIds.get(i);
            Object clientdesign_handles = null;
            if (component instanceof IScriptableProvider && ((IScriptableProvider) component).getScriptObject() instanceof IRuntimeComponent) {
                IRuntimeComponent sbmc = (IRuntimeComponent) ((IScriptableProvider) component).getScriptObject();
                // skip, elements with no name are not usable in CD
                if (sbmc.getName() == null)
                    continue;
                clientdesign_handles = sbmc.getClientProperty(CLIENTDESIGN.HANDLES);
                Object clientdesign_selectable = sbmc.getClientProperty(CLIENTDESIGN.SELECTABLE);
                // skip
                if (clientdesign_selectable != null && !Utils.getAsBoolean(clientdesign_selectable))
                    continue;
            }
            // $NON-NLS-1$
            String padding = "0px 0px 0px 0px";
            if (component instanceof ISupportWebBounds) {
                Insets p = ((ISupportWebBounds) component).getPaddingAndBorder();
                if (p != null)
                    padding = "0px " + (p.left + p.right) + "px " + (p.bottom + p.top) + "px 0px";
            }
            boolean editable = false;
            if (component instanceof IScriptableProvider && ((IScriptableProvider) component).getScriptObject() instanceof IRuntimeInputComponent) {
                editable = ((IRuntimeInputComponent) ((IScriptableProvider) component).getScriptObject()).isEditable();
            }
            String compId;
            if (webAnchorsEnabled && component instanceof IScriptableProvider && ((IScriptableProvider) component).getScriptObject() instanceof IRuntimeComponent && needsWrapperDivForAnchoring(((IRuntimeComponent) ((IScriptableProvider) component).getScriptObject()).getElementType(), editable)) {
                compId = component.getMarkupId() + TemplateGenerator.WRAPPER_SUFFIX;
            } else {
                compId = component.getMarkupId();
            }
            sb.append(compId);
            if (component instanceof IComponent) {
                Iterator<IComponent> selectedComponentsIte = onSelectComponents.keySet().iterator();
                IComponent c;
                while (selectedComponentsIte.hasNext()) {
                    c = selectedComponentsIte.next();
                    if (c.getName().equals(((IComponent) component).getName())) {
                        onSelectComponents.put(c, compId);
                        selectedComponentsId.add(compId);
                        break;
                    }
                }
            }
            sb.append(":['");
            sb.append(padding);
            sb.append("'");
            if (clientdesign_handles instanceof Object[]) {
                sb.append(",[");
                Object[] array = (Object[]) clientdesign_handles;
                for (Object element : array) {
                    sb.append('\'');
                    sb.append(ScriptRuntime.escapeString(element.toString()));
                    sb.append("',");
                }
                // rollback last comma
                sb.setLength(sb.length() - 1);
                sb.append("]");
            }
            sb.append("],");
        }
        // rollback last comma
        sb.setLength(sb.length() - 1);
        sb.append("},'" + getCallbackUrl() + "')");
        if (selectedComponentsId.size() > 0) {
            for (int i = 0; i < selectedComponentsId.size(); i++) {
                sb.append(";Servoy.ClientDesign.selectedElementId[").append(i).append("]='").append(selectedComponentsId.get(i)).append("';");
            }
            sb.append("Servoy.ClientDesign.reattach();");
        }
        response.renderOnDomReadyJavascript(sb.toString());
    // if (dropMarkupIds.size() > 0)
    // {
    // StringBuilder attachDrop = new StringBuilder();
    // attachDrop.append("attachDrop([");
    // for (int i = 0; i < dropMarkupIds.size(); i++)
    // {
    // Component component = dropMarkupIds.get(i);
    // attachDrop.append("'");
    // attachDrop.append(component.getMarkupId());
    // attachDrop.append("',");
    // }
    // attachDrop.setLength(attachDrop.length() - 1);
    // attachDrop.append("])");
    // response.renderOnDomReadyJavascript(attachDrop.toString());
    // }
    }
}
Also used : MarkupContainer(org.apache.wicket.MarkupContainer) WebDataRenderer(com.servoy.j2db.server.headlessclient.dataui.WebDataRenderer) Insets(java.awt.Insets) IComponent(com.servoy.j2db.ui.IComponent) ArrayList(java.util.ArrayList) ITabPanel(com.servoy.j2db.ui.ITabPanel) Point(java.awt.Point) IRuntimeInputComponent(com.servoy.j2db.ui.runtime.IRuntimeInputComponent) ISupportWebBounds(com.servoy.j2db.ui.ISupportWebBounds) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) IComponent(com.servoy.j2db.ui.IComponent) Component(org.apache.wicket.Component) IRuntimeInputComponent(com.servoy.j2db.ui.runtime.IRuntimeInputComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) WebDataCalendar(com.servoy.j2db.server.headlessclient.dataui.WebDataCalendar) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider)

Example 2 with ITabPanel

use of com.servoy.j2db.ui.ITabPanel 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 3 with ITabPanel

use of com.servoy.j2db.ui.ITabPanel in project servoy-client by Servoy.

the class SwingItemFactory method createTabPanel.

public ITabPanel createTabPanel(RuntimeTabPanel scriptable, String name, int orient, boolean oneTab) {
    ITabPanel tabPanel = new SpecialTabPanel(application, scriptable, orient, oneTab);
    tabPanel.setName(name);
    return tabPanel;
}
Also used : ITabPanel(com.servoy.j2db.ui.ITabPanel)

Example 4 with ITabPanel

use of com.servoy.j2db.ui.ITabPanel in project servoy-client by Servoy.

the class SwingItemFactory method createAccordionPanel.

public ITabPanel createAccordionPanel(RuntimeAccordionPanel scriptable, String name) {
    ITabPanel tabPanel = new SpecialTabPanel(application, scriptable, TabPanel.ACCORDION_PANEL, false);
    tabPanel.setName(name);
    return tabPanel;
}
Also used : ITabPanel(com.servoy.j2db.ui.ITabPanel)

Example 5 with ITabPanel

use of com.servoy.j2db.ui.ITabPanel in project servoy-client by Servoy.

the class WebForm method getFormContext.

public JSDataSet getFormContext() {
    WebForm current = this;
    ITabPanel currentTabPanel = null;
    String currentBeanName = null;
    WebSplitPane currentSplitPane = null;
    IDataSet set = new BufferedDataSet(// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$//$NON-NLS-6$
    new String[] { "containername", "formname", "tabpanel/splitpane/accordion/beanname", "tabname", "tabindex", "tabindex1based" }, new ArrayList<Object[]>());
    set.addRow(new Object[] { null, current.formController.getName(), null, null, null, null });
    MarkupContainer parent = getParent();
    while (parent != null) {
        if (parent instanceof WebSplitPane) {
            currentSplitPane = (WebSplitPane) parent;
        } else if (parent instanceof ITabPanel) {
            currentTabPanel = (ITabPanel) parent;
        } else if (parent instanceof IServoyAwareBean && parent instanceof IComponent) {
            currentBeanName = ((IComponent) parent).getName();
        } else if (parent instanceof WebForm) {
            if (currentTabPanel != null) {
                int index = -1;
                String tabName = null;
                if (currentTabPanel instanceof WebTabPanel) {
                    index = ((WebTabPanel) currentTabPanel).getTabIndex(current);
                } else if (currentTabPanel instanceof WebAccordionPanel) {
                    index = ((WebAccordionPanel) currentTabPanel).getTabIndex(current);
                }
                if (index != -1) {
                    // js method so +1
                    tabName = currentTabPanel.getTabNameAt(index);
                }
                current = (WebForm) parent;
                set.addRow(0, new Object[] { null, current.formController.getName(), currentTabPanel.getName(), tabName, new Integer(index), new Integer(index + 1) });
            } else if (currentBeanName != null) {
                current = (WebForm) parent;
                set.addRow(0, new Object[] { null, current.formController.getName(), currentBeanName, null, null, null });
            } else if (currentSplitPane != null) {
                int idx = currentSplitPane.getLeftForm() != null && current.equals(((WebTabFormLookup) currentSplitPane.getLeftForm()).getWebForm()) ? 0 : 1;
                current = (WebForm) parent;
                set.addRow(0, new Object[] { null, current.formController.getName(), currentSplitPane.getName(), currentSplitPane.getTabNameAt(idx), new Integer(idx + 1), new Integer(idx + 1) });
            }
            current = (WebForm) parent;
            currentTabPanel = null;
            currentBeanName = null;
            currentSplitPane = null;
        } else if (parent instanceof MainPage) {
            String containerName = ((MainPage) parent).getContainerName();
            if (containerName != null) {
                for (int i = 0; i < set.getRowCount(); i++) {
                    set.getRow(i)[0] = containerName;
                }
            }
            return new JSDataSet(formController.getApplication(), set);
        }
        parent = parent.getParent();
    }
    return new JSDataSet(formController.getApplication(), set);
}
Also used : MarkupContainer(org.apache.wicket.MarkupContainer) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) IComponent(com.servoy.j2db.ui.IComponent) JSDataSet(com.servoy.j2db.dataprocessing.JSDataSet) ITabPanel(com.servoy.j2db.ui.ITabPanel) WebTabFormLookup(com.servoy.j2db.server.headlessclient.dataui.WebTabFormLookup) WebSplitPane(com.servoy.j2db.server.headlessclient.dataui.WebSplitPane) Point(java.awt.Point) IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean) BufferedDataSet(com.servoy.j2db.dataprocessing.BufferedDataSet) WebAccordionPanel(com.servoy.j2db.server.headlessclient.dataui.WebAccordionPanel) WebTabPanel(com.servoy.j2db.server.headlessclient.dataui.WebTabPanel) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ScriptableObject(org.mozilla.javascript.ScriptableObject) IDataSet(com.servoy.j2db.dataprocessing.IDataSet)

Aggregations

ITabPanel (com.servoy.j2db.ui.ITabPanel)6 IComponent (com.servoy.j2db.ui.IComponent)3 IPersist (com.servoy.j2db.persistence.IPersist)2 RepositoryException (com.servoy.j2db.persistence.RepositoryException)2 Tab (com.servoy.j2db.persistence.Tab)2 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)2 RuntimeTabPanel (com.servoy.j2db.ui.scripting.RuntimeTabPanel)2 Point (java.awt.Point)2 IOException (java.io.IOException)2 MarkupContainer (org.apache.wicket.MarkupContainer)2 JSONException (org.json.JSONException)2 IForm (com.servoy.j2db.IForm)1 BufferedDataSet (com.servoy.j2db.dataprocessing.BufferedDataSet)1 IDataSet (com.servoy.j2db.dataprocessing.IDataSet)1 JSDataSet (com.servoy.j2db.dataprocessing.JSDataSet)1 IServoyAwareBean (com.servoy.j2db.dataui.IServoyAwareBean)1 BaseComponent (com.servoy.j2db.persistence.BaseComponent)1 Form (com.servoy.j2db.persistence.Form)1 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)1 IFormElement (com.servoy.j2db.persistence.IFormElement)1