Example usage for org.apache.wicket.ajax AjaxRequestTarget appendJavaScript

List of usage examples for org.apache.wicket.ajax AjaxRequestTarget appendJavaScript

Introduction

In this page you can find the example usage for org.apache.wicket.ajax AjaxRequestTarget appendJavaScript.

Prototype

void appendJavaScript(CharSequence javascript);

Source Link

Document

Adds javascript that will be evaluated on the client side after components are replaced

If the javascript needs to do something asynchronously (i.e.

Usage

From source file:com.servoy.j2db.server.headlessclient.dataui.WebEventExecutor.java

License:Open Source License

/**
 * @param component//from  ww w. jav a  2 s . com
 */
@SuppressWarnings("nls")
public static boolean setSelectedIndex(Component component, AjaxRequestTarget target, int modifiers,
        boolean bHandleMultiselect) {
    WebForm parentForm = component.findParent(WebForm.class);
    WebCellBasedView tableView = null;
    if (parentForm != null) {
        int parentFormViewType = parentForm.getController().getForm().getView();
        if (parentFormViewType == FormController.TABLE_VIEW
                || parentFormViewType == FormController.LOCKED_TABLE_VIEW
                || parentFormViewType == IForm.LIST_VIEW
                || parentFormViewType == FormController.LOCKED_LIST_VIEW) {
            tableView = component.findParent(WebCellBasedView.class);
            if (tableView == null) {
                // the component is not part of the table view (it is on other form part), so ignore selection change
                return true;
            } else
                tableView.setSelectionMadeByCellAction();

            if (parentFormViewType == IForm.LIST_VIEW
                    || parentFormViewType == FormController.LOCKED_LIST_VIEW) {
                if (component instanceof WebCellBasedViewListViewItem) {
                    ((WebCellBasedViewListViewItem) component).markSelected(target);
                } else {
                    WebCellBasedViewListViewItem listViewItem = component
                            .findParent(WebCellBasedView.WebCellBasedViewListViewItem.class);
                    if (listViewItem != null) {
                        listViewItem.markSelected(target);
                    }
                }
            }
        }
    }

    //search for recordItem model
    Component recordItemModelComponent = component;
    IModel<?> someModel = recordItemModelComponent.getDefaultModel();
    while (!(someModel instanceof RecordItemModel)) {
        recordItemModelComponent = recordItemModelComponent.getParent();
        if (recordItemModelComponent == null)
            break;
        someModel = recordItemModelComponent.getDefaultModel();
    }

    if (someModel instanceof RecordItemModel) {
        if (!(component instanceof WebCellBasedViewListViewItem)) {
            // update the last rendered value for the events component (if updated)
            ((RecordItemModel) someModel).updateRenderedValue(component);
        }

        IRecordInternal rec = (IRecordInternal) someModel.getObject();
        if (rec != null) {
            int index;
            IFoundSetInternal fs = rec.getParentFoundSet();
            if (someModel instanceof FoundsetRecordItemModel) {
                index = ((FoundsetRecordItemModel) someModel).getRowIndex();
            } else {
                index = fs.getRecordIndex(rec); // this is used only on "else", because a "plugins.rawSQL.flushAllClientsCache" could result in index = -1 although the record has not changed (but record & underlying row instances changed)
            }

            if (fs instanceof FoundSet && ((FoundSet) fs).isMultiSelect()) {
                //set the selected record
                ClientProperties clp = ((WebClientInfo) Session.get().getClientInfo()).getProperties();
                String navPlatform = clp.getNavigatorPlatform();
                int controlMask = (navPlatform != null && navPlatform.toLowerCase().indexOf("mac") != -1)
                        ? Event.META_MASK
                        : Event.CTRL_MASK;

                boolean toggle = (modifiers != MODIFIERS_UNSPECIFIED) && ((modifiers & controlMask) != 0);
                boolean extend = (modifiers != MODIFIERS_UNSPECIFIED) && ((modifiers & Event.SHIFT_MASK) != 0);
                boolean isRightClick = (modifiers != MODIFIERS_UNSPECIFIED)
                        && ((modifiers & Event.ALT_MASK) != 0);

                if (!isRightClick) {
                    if (!toggle && !extend && tableView != null && tableView.getDragNDropController() != null
                            && Arrays.binarySearch(((FoundSet) fs).getSelectedIndexes(), index) > -1) {
                        return true;
                    }

                    if (toggle || extend) {
                        if (bHandleMultiselect) {
                            if (toggle) {
                                int[] selectedIndexes = ((FoundSet) fs).getSelectedIndexes();
                                ArrayList<Integer> selectedIndexesA = new ArrayList<Integer>();
                                Integer selectedIndex = new Integer(index);

                                for (int selected : selectedIndexes)
                                    selectedIndexesA.add(new Integer(selected));
                                if (selectedIndexesA.indexOf(selectedIndex) != -1) {
                                    if (selectedIndexesA.size() > 1)
                                        selectedIndexesA.remove(selectedIndex);
                                } else
                                    selectedIndexesA.add(selectedIndex);
                                selectedIndexes = new int[selectedIndexesA.size()];
                                for (int i = 0; i < selectedIndexesA.size(); i++)
                                    selectedIndexes[i] = selectedIndexesA.get(i).intValue();
                                ((FoundSet) fs).setSelectedIndexes(selectedIndexes);
                            } else if (extend) {
                                int anchor = ((FoundSet) fs).getSelectedIndex();
                                int min = Math.min(anchor, index);
                                int max = Math.max(anchor, index);

                                int[] newSelectedIndexes = new int[max - min + 1];
                                for (int i = min; i <= max; i++)
                                    newSelectedIndexes[i - min] = i;
                                ((FoundSet) fs).setSelectedIndexes(newSelectedIndexes);
                            }
                        }
                    } else if (index != -1 || fs.getSize() == 0) {
                        fs.setSelectedIndex(index);
                    }
                }
            } else if (!isIndexSelected(fs, index))
                fs.setSelectedIndex(index);
            if (!isIndexSelected(fs, index) && !(fs instanceof FoundSet && ((FoundSet) fs).isMultiSelect())) {
                // setSelectedIndex failed, probably due to validation failed, do a blur()
                if (target != null)
                    target.appendJavascript("var toBlur = document.getElementById(\"" + component.getMarkupId()
                            + "\");if (toBlur) toBlur.blur();");
                return false;
            }
        }
    }
    return true;
}

From source file:com.servoy.j2db.server.headlessclient.dataui.WebEventExecutor.java

License:Open Source License

@SuppressWarnings("nls")
public static void generateResponse(final AjaxRequestTarget target, Page page) {
    WebClientSession webClientSession = WebClientSession.get();
    if (target != null && page instanceof MainPage && webClientSession != null
            && webClientSession.getWebClient() != null
            && webClientSession.getWebClient().getSolution() != null) {
        if (target instanceof CloseableAjaxRequestTarget && ((CloseableAjaxRequestTarget) target).isClosed()) {
            return;
        }/* w w w  . j a  va2s.  c o  m*/
        // do executed the events for before generating the response.
        webClientSession.getWebClient().executeEvents();

        if (webClientSession.getWebClient() == null || webClientSession.getWebClient().getSolution() == null) {
            // how can web client be null here ?
            return;
        }
        final MainPage mainPage = ((MainPage) page);

        if (mainPage.getPageMap() instanceof ModifiedAccessStackPageMap) {
            // at every request mark the pagemap as dirty so lru eviction really works
            ((ModifiedAccessStackPageMap) mainPage.getPageMap()).flagDirty();
        }

        // If the main form is switched then do a normal redirect.
        if (mainPage.isMainFormSwitched()) {
            mainPage.versionPush();
            RequestCycle.get().setResponsePage(page);
        }

        else {
            page.visitChildren(WebTabPanel.class, new Component.IVisitor<WebTabPanel>() {
                public Object component(WebTabPanel component) {
                    component.initalizeFirstTab();
                    return IVisitor.CONTINUE_TRAVERSAL;
                }
            });

            mainPage.addWebAnchoringInfoIfNeeded();

            final Set<WebCellBasedView> tableViewsToRender = new HashSet<WebCellBasedView>();
            final List<String> valueChangedIds = new ArrayList<String>();
            final List<String> invalidValueIds = new ArrayList<String>();
            final Map<WebCellBasedView, List<Integer>> tableViewsWithChangedRowIds = new HashMap<WebCellBasedView, List<Integer>>();

            // first, get all invalidValue & valueChanged components
            page.visitChildren(IProviderStylePropertyChanges.class, new Component.IVisitor<Component>() {
                public Object component(Component component) {
                    if (component instanceof IDisplayData && !((IDisplayData) component).isValueValid()) {
                        invalidValueIds.add(component.getMarkupId());
                    }
                    if (((IProviderStylePropertyChanges) component).getStylePropertyChanges()
                            .isValueChanged()) {
                        if (component.getParent().isVisibleInHierarchy()) {
                            // the component will get added to the target & rendered only if it's parent is visible in hierarchy because changed flag is also set (see the visitor below)
                            // so we will only list these components if they are visible otherwise ajax timer could end up sending hundreds of id's that don't actually render every 5 seconds
                            // because the valueChanged flag is cleared only by onRender
                            valueChangedIds.add(component.getMarkupId());
                            if (component instanceof MarkupContainer) {
                                ((MarkupContainer) component).visitChildren(IDisplayData.class,
                                        new IVisitor<Component>() {
                                            public Object component(Component comp) {
                                                // labels/buttons that don't display data are not changed
                                                if (!(comp instanceof ILabel)) {
                                                    valueChangedIds.add(comp.getMarkupId());
                                                }
                                                return CONTINUE_TRAVERSAL;
                                            }
                                        });
                            }
                        }
                    }
                    return CONTINUE_TRAVERSAL;
                }
            });

            // add changed components to target; if a component is changed, the change check won't go deeper in hierarchy
            page.visitChildren(IProviderStylePropertyChanges.class, new Component.IVisitor<Component>() {
                public Object component(Component component) {
                    if (((IProviderStylePropertyChanges) component).getStylePropertyChanges().isChanged()) {
                        if (component.getParent().isVisibleInHierarchy()) {
                            target.addComponent(component);
                            generateDragAttach(component, target.getHeaderResponse());

                            WebForm parentForm = component.findParent(WebForm.class);
                            boolean isDesignMode = parentForm != null && parentForm.isDesignMode();

                            if (!component.isVisible() || (component instanceof WrapperContainer
                                    && !((WrapperContainer) component).getDelegate().isVisible())) {
                                ((IProviderStylePropertyChanges) component).getStylePropertyChanges()
                                        .setRendered();
                                if (isDesignMode) {
                                    target.appendJavascript("Servoy.ClientDesign.hideSelected('"
                                            + component.getMarkupId() + "')");
                                }
                            } else {
                                if (isDesignMode) {
                                    target.appendJavascript("Servoy.ClientDesign.refreshSelected('"
                                            + component.getMarkupId() + "')");
                                }
                                // some components need to perform js layout tasks when their markup is replaced when using anchored layout
                                mainPage.getPageContributor().markComponentForAnchorLayoutIfNeeded(component);
                            }

                            ListItem<IRecordInternal> row = component.findParent(ListItem.class);
                            if (row != null) {
                                WebCellBasedView wcbv = row.findParent(WebCellBasedView.class);
                                if (wcbv != null) {
                                    if (tableViewsWithChangedRowIds.get(wcbv) == null) {
                                        tableViewsWithChangedRowIds.put(wcbv, new ArrayList<Integer>());
                                    }
                                    List<Integer> ids = tableViewsWithChangedRowIds.get(wcbv);
                                    int changedRowIdx = wcbv.indexOf(row);
                                    if (changedRowIdx >= 0 && !ids.contains(changedRowIdx)) {
                                        ids.add(changedRowIdx);
                                    }
                                }
                            }
                        }
                        return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
                    } else if (component instanceof WebCellBasedView)
                        tableViewsToRender.add((WebCellBasedView) component);
                    return component.isVisible() ? IVisitor.CONTINUE_TRAVERSAL
                            : IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
                }
            });

            page.visitChildren(IComponentToRequestAttacher.class, new Component.IVisitor<Component>() {
                public Object component(Component component) {
                    ((IComponentToRequestAttacher) component).attachComponents(target);
                    return IVisitor.CONTINUE_TRAVERSAL;
                }
            });

            final List<String> visibleEditors = new ArrayList<String>();
            page.visitChildren(WebDataHtmlArea.class, new Component.IVisitor<Component>() {
                public Object component(Component component) {
                    visibleEditors.add(((WebDataHtmlArea) component).getEditorID());
                    return IVisitor.CONTINUE_TRAVERSAL;
                }
            });
            StringBuffer argument = new StringBuffer();
            for (String id : visibleEditors) {
                argument.append("\"");
                argument.append(id);
                argument.append("\"");
                if (visibleEditors.indexOf(id) != visibleEditors.size() - 1) {
                    argument.append(",");
                }
            }
            target.prependJavascript("Servoy.HTMLEdit.removeInvalidEditors(" + argument + ");");

            String rowSelectionScript, columnResizeScript;
            for (final WebCellBasedView wcbv : tableViewsToRender) {
                if (wcbv.isScrollMode())
                    wcbv.scrollViewPort(target, true);
                wcbv.updateRowSelection(target);
                List<Integer> changedIds = tableViewsWithChangedRowIds.get(wcbv);
                List<Integer> selectedIndexesChanged = wcbv.getIndexToUpdate(false);
                List<Integer> mergedIds = selectedIndexesChanged != null ? selectedIndexesChanged
                        : new ArrayList<Integer>();
                if (changedIds != null) {
                    for (Integer id : changedIds) {
                        if (!mergedIds.contains(id)) {
                            mergedIds.add(id);
                        }
                    }
                }
                rowSelectionScript = wcbv.getRowSelectionScript(mergedIds);
                wcbv.clearSelectionByCellActionFlag();
                if (rowSelectionScript != null)
                    target.appendJavascript(rowSelectionScript);
                columnResizeScript = wcbv.getColumnResizeScript();
                if (columnResizeScript != null)
                    target.appendJavascript(columnResizeScript);
            }

            // double check if the page contributor is changed, because the above IStylePropertyChanges ischanged could have altered it.
            if (mainPage.getPageContributor().getStylePropertyChanges().isChanged()) {
                target.addComponent((Component) mainPage.getPageContributor());
            }
            if (invalidValueIds.size() == 0) {
                target.appendJavascript("setValidationFailed(null);"); //$NON-NLS-1$
            } else {
                target.appendJavascript("setValidationFailed('" + invalidValueIds.get(0) + "');"); //$NON-NLS-1$
            }
            Component comp = mainPage.getAndResetToFocusComponent();
            if (comp != null) {
                if (comp instanceof WebDataHtmlArea) {
                    target.appendJavascript("tinyMCE.activeEditor.focus()");
                } else {
                    target.focusComponent(comp);
                }
            } else if (mainPage.getAndResetMustFocusNull()) {
                // This is needed for example when showing a non-modal dialog in IE7 (or otherwise
                // the new window would be displayed in the background).
                target.focusComponent(null);
            }
            if (valueChangedIds.size() > 0) {
                argument = new StringBuffer();
                for (String id : valueChangedIds) {
                    argument.append("\"");
                    argument.append(id);
                    argument.append("\"");
                    if (valueChangedIds.indexOf(id) != valueChangedIds.size() - 1) {
                        argument.append(",");
                    }
                }
                target.prependJavascript("storeValueAndCursorBeforeUpdate(" + argument + ");");
                target.appendJavascript("restoreValueAndCursorAfterUpdate();");
            }

            //if we have admin info, show it
            String adminInfo = mainPage.getAdminInfo();
            if (adminInfo != null) {
                adminInfo = Utils.stringReplace(adminInfo, "\r", "");
                adminInfo = Utils.stringReplace(adminInfo, "\n", "\\n");
                target.appendJavascript("alert('Servoy admin info : " + adminInfo + "');");
            }

            // If we have a status text, set it.
            String statusText = mainPage.getStatusText();
            if (statusText != null) {
                target.appendJavascript("setStatusText('" + statusText + "');");
            }

            String show = mainPage.getShowUrlScript();
            if (show != null) {
                target.appendJavascript(show);
            }

            mainPage.renderJavascriptChanges(target);

            if (((WebClientInfo) webClientSession.getClientInfo()).getProperties().isBrowserInternetExplorer()
                    && ((WebClientInfo) webClientSession.getClientInfo()).getProperties()
                            .getBrowserVersionMajor() < 9) {
                target.appendJavascript("Servoy.Utils.checkWebFormHeights();");
            }
            try {
                if (isStyleSheetLimitForIE(page.getSession())) {
                    target.appendJavascript("testStyleSheets();");
                }
            } catch (Exception e) {
                Debug.error(e);//cannot retrieve session/clientinfo/properties?
                target.appendJavascript("testStyleSheets();");
            }
        }
    }
}

From source file:com.servoy.j2db.server.headlessclient.dataui.WebSplitPane.java

License:Open Source License

public void attachComponents(AjaxRequestTarget target) {
    if (!((ChangesRecorder) scriptable.getChangesRecorder()).isChanged()) {
        if (!isParentContainerChanged() && (paneChanged[0] || paneChanged[1])) {
            if (paneChanged[0] && paneChanged[1]) {
                target.addComponent(WebSplitPane.this);
            } else if (paneChanged[0]) {
                target.addComponent(splitComponents[0]);
            } else {
                target.addComponent(splitComponents[1]);
            }/*from  www  .  j  ava 2s  . co  m*/
            target.appendJavascript(getSplitScripting());
        }
    }
    paneChanged[0] = false;
    paneChanged[1] = false;
}

From source file:com.servoy.j2db.server.headlessclient.DesignModeBehavior.java

License:Open Source License

/**
 * @see org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#respond(org.apache.wicket.ajax.AjaxRequestTarget)
 *//*from  www.  j a v  a 2s  .c om*/
@Override
protected void respond(AjaxRequestTarget target) {
    Request request = RequestCycle.get().getRequest();
    String action = request.getParameter(DraggableBehavior.PARAM_ACTION);
    String id = extractId(request.getParameter(DraggableBehavior.PARAM_DRAGGABLE_ID));
    if (id != null) {
        final String finalId = id.endsWith(TemplateGenerator.WRAPPER_SUFFIX) ? id.substring(0, id.length() - 8)
                : id;
        MarkupContainer comp = (MarkupContainer) getComponent();
        Component child = (Component) comp.visitChildren(Component.class, new IVisitor<Component>() {
            public Object component(Component component) {
                String markupId = component.getMarkupId();
                if (finalId.equals(markupId))
                    return component;
                return IVisitor.CONTINUE_TRAVERSAL;
            }
        });
        if (action != null) {
            int height = stripUnitPart(request.getParameter(PARAM_RESIZE_HEIGHT));
            int width = stripUnitPart(request.getParameter(PARAM_RESIZE_WIDTH));
            int x = stripUnitPart(request.getParameter(DraggableBehavior.PARAM_X));
            int y = stripUnitPart(request.getParameter(DraggableBehavior.PARAM_Y));

            if (action.equals(ACTION_SELECT)) {
                if (!(child instanceof IComponent))
                    onSelectComponents.clear();
                else {
                    boolean isSelectionRemove = false;
                    if (!Boolean.parseBoolean(request.getParameter(PARAM_IS_CTRL_KEY)))
                        onSelectComponents.clear();
                    else {
                        isSelectionRemove = onSelectComponents.remove(child) != null;
                    }

                    IComponent[] param = onSelectComponents.keySet()
                            .toArray(new IComponent[isSelectionRemove ? onSelectComponents.size()
                                    : onSelectComponents.size() + 1]);
                    if (!isSelectionRemove)
                        param[onSelectComponents.size()] = (IComponent) child;

                    Object ret = callback
                            .executeOnSelect(getJSEvent(EventType.action, 0, new Point(x, y), param));
                    if (ret instanceof Boolean && !((Boolean) ret).booleanValue()) {
                        onSelectComponents.clear();
                    } else {
                        if (!isSelectionRemove)
                            onSelectComponents.put((IComponent) child, id);
                        StringBuilder idsArray = new StringBuilder("new Array(");
                        Iterator<String> idsIte = onSelectComponents.values().iterator();
                        while (idsIte.hasNext()) {
                            idsArray.append('\'').append(idsIte.next()).append('\'');
                            if (idsIte.hasNext())
                                idsArray.append(',');
                        }
                        idsArray.append(')');
                        target.appendJavascript(
                                "Servoy.ClientDesign.attachElements(" + idsArray.toString() + ");");

                    }
                    if (Boolean.parseBoolean(request.getParameter(PARAM_IS_RIGHTCLICK))) {
                        callback.executeOnRightClick(
                                getJSEvent(EventType.rightClick, 0, new Point(x, y), param));
                    } else if (Boolean.parseBoolean(request.getParameter(PARAM_IS_DBLCLICK))) {
                        callback.executeOnDblClick(
                                getJSEvent(EventType.doubleClick, 0, new Point(x, y), param));
                    }
                }

                WebEventExecutor.generateResponse(target, getComponent().getPage());
                target.appendJavascript("Servoy.ClientDesign.clearClickTimer();");
                return;
            }

            if (child instanceof IComponent) {
                if (!onSelectComponents.containsKey(child)) {
                    onSelectComponents.put((IComponent) child, id);
                }
                if (action.equals(ACTION_RESIZE)) {
                    if (width != -1 && height != -1) {
                        if (child instanceof ISupportWebBounds) {
                            Insets paddingAndBorder = ((ISupportWebBounds) child).getPaddingAndBorder();
                            if (paddingAndBorder != null) {
                                height += paddingAndBorder.bottom + paddingAndBorder.top;
                                width += paddingAndBorder.left + paddingAndBorder.right;
                            }
                        }
                        if (child instanceof IScriptableProvider) {
                            ((IRuntimeComponent) ((IScriptableProvider) child).getScriptObject()).setSize(width,
                                    height);
                            ((IRuntimeComponent) ((IScriptableProvider) child).getScriptObject()).setLocation(x,
                                    y);
                        }
                        if (child instanceof IProviderStylePropertyChanges)
                            ((IProviderStylePropertyChanges) child).getStylePropertyChanges().setRendered();
                    }
                    callback.executeOnResize(getJSEvent(EventType.onDrop, 0, new Point(x, y),
                            new IComponent[] { (IComponent) child }));
                } else if (action.equals(DraggableBehavior.ACTION_DRAG_START)) {
                    Object onDragAllowed = callback.executeOnDrag(getJSEvent(EventType.onDrag, 0,
                            new Point(x, y),
                            onSelectComponents.keySet().toArray(new IComponent[onSelectComponents.size()])));
                    if ((onDragAllowed instanceof Boolean && !((Boolean) onDragAllowed).booleanValue())
                            || (onDragAllowed instanceof Number
                                    && ((Number) onDragAllowed).intValue() == DRAGNDROP.NONE)) {
                        onDragComponent = null;
                    } else {
                        onDragComponent = (IComponent) child;
                    }
                    WebEventExecutor.generateResponse(target, getComponent().getPage());
                    return;
                } else {
                    if (child == onDragComponent) {
                        if (x != -1 && y != -1) {
                            ((IRuntimeComponent) ((IScriptableProvider) child).getScriptObject()).setLocation(x,
                                    y);
                            if (child instanceof IProviderStylePropertyChanges) {
                                // test if it is wrapped
                                if ((child).getParent() instanceof WrapperContainer) {
                                    // call for the changes on the wrapper container so that it will copy the right values over
                                    WrapperContainer wrapper = (WrapperContainer) (child).getParent();
                                    wrapper.getStylePropertyChanges().getChanges();
                                    wrapper.getStylePropertyChanges().setRendered();

                                }
                                ((IProviderStylePropertyChanges) child).getStylePropertyChanges().setRendered();
                            }
                        }
                        callback.executeOnDrop(
                                getJSEvent(EventType.onDrop, 0, new Point(x, y), onSelectComponents.keySet()
                                        .toArray(new IComponent[onSelectComponents.size()])));
                    }

                    if (Boolean.parseBoolean(request.getParameter(PARAM_IS_DBLCLICK))) {
                        callback.executeOnDblClick(getJSEvent(EventType.doubleClick, 0, new Point(x, y),
                                new IComponent[] { (IComponent) child }));
                    }
                }
            }
        }
    }
    WebEventExecutor.generateResponse(target, getComponent().getPage());
    target.appendJavascript("Servoy.ClientDesign.reattach();");
}

From source file:com.servoy.j2db.server.headlessclient.DivWindow.java

License:Open Source License

/**
 * When show was initially called from a child iframe request (thus callback scripts were generated using that
 * page's target), you need to call this method subsequently on a request from the root main frame, to make
 * behaviors work with the main page as you would expect (otherwise problems occur when you try to close it).
 * @param mainFrameTarget/*  w ww . jav a  2s  .c  o m*/
 * @param childFrameBatchId should never be null; it is the child frame batchId that will execute/has executed the show. 
 */
public void reAttachBehaviorsAfterShow(AjaxRequestTarget mainFrameTarget, String childFrameBatchId) {
    if (childFrameBatchId == null)
        throw new IllegalArgumentException(
                "'reAttachBehaviors' is only to be called if a show happened on child frame.");
    AppendingStringBuffer settingsToUpdate = new AppendingStringBuffer(500);

    // if show was already called (as a result of a child frame request), just re-register; otherwise wait for show to be called and that will do the re-register directly
    settingsToUpdate.append("function (settings) {\n");
    attachOnMove(settingsToUpdate);
    attachOnResize(settingsToUpdate);
    reattachOnClose(settingsToUpdate);
    reattachOnCloseButton(settingsToUpdate);
    settingsToUpdate.append("}");

    mainFrameTarget.appendJavascript("Wicket.DivWindow.reAttachBehaviorsAfterShow("
            + settingsToUpdate.toString() + ", \"" + getJSId() + "\", \"" + childFrameBatchId + "\");");
}

From source file:com.servoy.j2db.server.headlessclient.DivWindow.java

License:Open Source License

/**
 * @param childFrameBatchId null if this target is of the main window (that contains all dialog iframes), an unique ID if it's of an iframe. Must always be wrapped by {@link #beginActionBatch(AjaxRequestTarget, String)} and {@link #actionBatchComplete(AjaxRequestTarget, String)} with the same batchID if it is not null.
 *///from   w  w w  .j  av a2 s.  com
public void setBounds(AjaxRequestTarget target, int x, int y, int width, int height, String childFrameBatchId) {
    target.appendJavascript(getActionJavascript(".setPosition",
            ((x >= 0) ? ("'" + x + "px'") : "winObj.window.style.left") + ","
                    + ((y >= 0) ? ("'" + y + "px'") : "winObj.window.style.top") + ","
                    + ((width >= 0) ? ("'" + width + "px'") : "winObj.window.style.width") + ","
                    + ((height >= 0) ? ("'" + height + "px'") : "winObj.content.style.height"),
            childFrameBatchId));
    if (x >= 0)
        bounds.x = x;
    if (y >= 0)
        bounds.y = y;
    if (width >= 0)
        bounds.width = width;
    if (height >= 0)
        bounds.height = height;
}

From source file:com.servoy.j2db.server.headlessclient.DivWindow.java

License:Open Source License

/**
 * @param childFrameBatchId null if this target is of the main window (that contains all dialog iframes), an unique ID if it's of an iframe. Must always be wrapped by {@link #beginActionBatch(AjaxRequestTarget, String)} and {@link #actionBatchComplete(AjaxRequestTarget, String)} with the same batchID if it is not null.
 *//*  w w  w . java 2s . c o m*/
public void saveBounds(AjaxRequestTarget target, String childFrameBatchId) {
    target.appendJavascript(getActionJavascript(".savePosition", "", childFrameBatchId));
}

From source file:com.servoy.j2db.server.headlessclient.DivWindow.java

License:Open Source License

/**
 * @param childFrameBatchId null if this target is of the main window (that contains all dialog iframes), an unique ID if it's of an iframe. Must always be wrapped by {@link #beginActionBatch(AjaxRequestTarget, String)} and {@link #actionBatchComplete(AjaxRequestTarget, String)} with the same batchID if it is not null.
 *//*from   w  w w  . j  av a  2 s .  c  o  m*/
public void toFront(AjaxRequestTarget target, String childFrameBatchId) {
    target.appendJavascript(getActionJavascript(".toFront", "", childFrameBatchId));
}

From source file:com.servoy.j2db.server.headlessclient.DivWindow.java

License:Open Source License

/**
 * @param childFrameBatchId null if this target is of the main window (that contains all dialog iframes), an unique ID if it's of an iframe. Must always be wrapped by {@link #beginActionBatch(AjaxRequestTarget, String)} and {@link #actionBatchComplete(AjaxRequestTarget, String)} with the same batchID if it is not null.
 *//*from   ww w. j a  v a  2 s. c om*/
public void toBack(AjaxRequestTarget target, String childFrameBatchId) {
    target.appendJavascript(getActionJavascript(".toBack", "", childFrameBatchId));
}

From source file:com.servoy.j2db.server.headlessclient.DivWindow.java

License:Open Source License

public static void deleteStoredBounds(AjaxRequestTarget target, String dialogName) {
    target.getHeaderResponse().renderJavascriptReference(JAVA_SCRIPT);
    target.appendJavascript("Wicket.DivWindow.deletePosition(\"" + dialogName + "\");");
}