Example usage for org.apache.wicket MarkupContainer findParent

List of usage examples for org.apache.wicket MarkupContainer findParent

Introduction

In this page you can find the example usage for org.apache.wicket MarkupContainer findParent.

Prototype

public final <Z> Z findParent(final Class<Z> c) 

Source Link

Document

Finds the first container parent of this component of the given class.

Usage

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

License:Open Source License

/**
 * Renders the next element of markup in the given markup stream.
 * /*from ww w .j  a va  2 s  .c  o m*/
 * @param markupStream The markup stream
 */
private final void _renderNext(final MarkupStream markupStream) {
    // Get the current markup element
    final MarkupElement element = markupStream.get();

    // If it a tag like <wicket..> or <span wicket:id="..." >
    if ((element instanceof ComponentTag) && !markupStream.atCloseTag()) {
        // Get element as tag
        final ComponentTag tag = (ComponentTag) element;

        // Get component id
        final String id = tag.getId();

        // Get the component for the id from the given container
        final Component component = get(id);

        // Failed to find it?
        if (component != null && orderedHeaders.get(renderColumnIdx) != null) {
            if (component instanceof SortableCellViewHeader) {
                int currentIdx = markupStream.getCurrentIndex();
                renderHeader(renderColumnIdx, markupStream);
                renderColumnIdx++;
                markupStream.setCurrentIndex(currentIdx);
                markupStream.skipComponent();
            }
        } else {
            // 2rd try: Components like Border and Panel might implement
            // the ComponentResolver interface as well.
            MarkupContainer container = this;
            while (container != null) {
                if (container instanceof SortableCellViewHeaders) {
                    // we should created the corect header, use the id from the orderedHeaders
                    String headerId = orderedHeaderIds.get(renderColumnIdx);
                    renderColumnIdx++;
                    if (resolve(markupStream, tag, headerId)) {
                        return;
                    }

                }

                if (container instanceof IComponentResolver) {
                    if (((IComponentResolver) container).resolve(this, markupStream, tag)) {
                        return;
                    }
                }

                container = container.findParent(MarkupContainer.class);
            }

            // 3rd try: Try application's component resolvers
            final List<IComponentResolver> componentResolvers = getApplication().getPageSettings()
                    .getComponentResolvers();
            final Iterator<IComponentResolver> iterator = componentResolvers.iterator();
            while (iterator.hasNext()) {
                final IComponentResolver resolver = iterator.next();
                if (resolver.resolve(this, markupStream, tag)) {
                    return;
                }
            }

            if (tag instanceof WicketTag) {
                if (((WicketTag) tag).isChildTag()) {
                    markupStream.throwMarkupException("Found " + tag.toString() + " but no <wicket:extend>"); //$NON-NLS-1$ //$NON-NLS-2$
                } else {
                    markupStream.throwMarkupException("Failed to handle: " + tag.toString()); //$NON-NLS-1$
                }
            }

            // No one was able to handle the component id
            markupStream.throwMarkupException("Unable to find component with id '" + id + "' in " + this //$NON-NLS-1$//$NON-NLS-2$
                    + ". This means that you declared wicket:id=" + //$NON-NLS-1$
                    id + " in your markup, but that you either did not add the " //$NON-NLS-1$
                    + "component to your page at all, or that the hierarchy does not match."); //$NON-NLS-1$
        }
    } else {
        getResponse().write(element.toCharSequence());
        markupStream.next();
    }
}

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

License:Open Source License

public void reload(FormController[] fcontrollers) {
    HashSet<MainPage> mainPages = new HashSet<MainPage>();
    for (FormController fc : fcontrollers) {
        WebForm formUI = (WebForm) fc.getFormUI();
        MainPage mp = formUI.findParent(MainPage.class);
        if (mp != null && mainPages.add(mp)) {
            mp.setVersioned(false);//from w ww. j  a  v a 2s  .  c  o m
            mp.setMainPageSwitched();
        }
    }

    String navigatorName = null;
    Set<MainPage> parents = new HashSet<MainPage>();
    for (FormController fp : fcontrollers) {
        if (fp != null) {
            boolean formVisible = fp.isFormVisible();
            FoundSet foundset = fp.getFormModel();
            WebForm wf = (WebForm) fp.getFormUI();
            MarkupContainer wfParent = wf.getParent();

            boolean refresh = false;
            //datasource has changed, but foundset has not
            if (foundset != null && !Utils.equalObjects(foundset.getDataSource(), fp.getDataSource())) {
                try {
                    foundset = (FoundSet) (getApplication()).getFoundSetManager()
                            .getSharedFoundSet(fp.getDataSource());
                    foundset.loadAllRecords();
                    refresh = true;
                } catch (ServoyException e) {
                    Debug.error("Failed to reload foundset.", e); //$NON-NLS-1$
                }
            }

            MainPage page = wf.findParent(MainPage.class);
            try {
                if (page != null) {
                    page.setTempRemoveMainForm(true);
                }

                fp.destroy();
            } finally {
                if (page != null) {
                    page.setTempRemoveMainForm(false);
                }
            }

            while (wfParent != null && !(wfParent instanceof IWebFormContainer)
                    && !(wfParent.getParent() instanceof MainPage)
                    && !(wfParent.getParent() instanceof WebForm)) {
                wfParent = wfParent.getParent();
            }

            if (wfParent instanceof IWebFormContainer) {
                if (formVisible) {
                    FormController fc = leaseFormPanel(fp.getName());
                    if (fc != null) {
                        // form was deleted in developer?
                        fc.loadData(foundset, null);
                        if (refresh)
                            fc.recreateUI();
                        List<Runnable> runnables = new ArrayList<Runnable>();
                        ((IWebFormContainer) wfParent).notifyVisible(true, runnables);
                        Utils.invokeLater(getApplication(), runnables);
                    }
                }
            } else if (wfParent != null) {
                WebForm parentWF = wfParent.findParent(WebForm.class);
                if (parentWF != null) {
                    if (!Arrays.asList(fcontrollers).contains(parentWF.getController()))
                        parentWF.getController().destroy();
                } else {
                    MainPage parent = wfParent.findParent(MainPage.class);
                    if (parent != null && !parents.contains(parent)) {
                        parents.add(parent);

                        if (parent.getNavigator() == fp) {
                            navigatorName = fp.getName();
                            FormController navigator = getFormController(navigatorName, parent);
                            if (navigator != null) {
                                List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>();
                                navigator.notifyVisible(true, invokeLaterRunnables);
                                Utils.invokeLater(getApplication(), invokeLaterRunnables);
                                parent.setNavigator(navigator);
                                //parent.triggerBrowserRequestIfNeeded(); // FIXME: this is needed here but currently does nothing because the request target is not yet set
                            }
                        }

                        FormController previousMainShowingForm = (parent != null ? parent.getController()
                                : null);
                        if (previousMainShowingForm != null) {
                            FormController previousNavigator = parent.getNavigator();
                            parent.setController(null);
                            // navigator is not re-applied so apply it manually
                            int navigatorID = previousMainShowingForm.getForm().getNavigatorID();
                            if (navigatorID == Form.NAVIGATOR_IGNORE || (previousNavigator != null
                                    && previousNavigator.getForm().getID() == navigatorID)) {
                                parent.setNavigator(previousNavigator);
                            } else if (navigatorID > 0) {
                                Form newNavigator = application.getFlattenedSolution().getForm(navigatorID);
                                if (newNavigator != null) {
                                    parent.setNavigator(leaseFormPanel(newNavigator.getName()));
                                }
                            }
                            showFormInMainPanel(previousMainShowingForm.getName(), parent, null, true, null);
                            //                        parent.triggerBrowserRequestIfNeeded(); // FIXME: this is needed here but currently does nothing because the request target is not yet set
                        }
                    }
                }
            }
        }
    }

    for (MainPage mainPage : mainPages) {
        mainPage.setVersioned(true);
    }
}