Example usage for org.apache.wicket Component isVisibleInHierarchy

List of usage examples for org.apache.wicket Component isVisibleInHierarchy

Introduction

In this page you can find the example usage for org.apache.wicket Component isVisibleInHierarchy.

Prototype

public final boolean isVisibleInHierarchy() 

Source Link

Document

Checks if the component itself and all its parents are visible.

Usage

From source file:com.googlecode.londonwicket.ComponentExpression.java

License:Apache License

private static final boolean evaluateConditions(Collection<Condition> conditions, Component component) {
    boolean result = true;
    for (Condition condition : conditions) {
        switch (condition.getAttr()) {
        case ENABLED: {
            result = result && (component.isEnabledInHierarchy() == condition.getCondition());
            break;
        }/*from  w  w  w  . j a va  2  s .  c  o  m*/
        case VISIBLE: {
            result = result && (component.isVisibleInHierarchy() == condition.getCondition());
        }
        }
        if (!result) {
            break;
        }
    }
    return result;
}

From source file:com.lyndir.lhunath.opal.wayward.behavior.FocusOnReady.java

License:Open Source License

@Override
public void bind(final Component component) {

    component.setOutputMarkupId(true);/*from w w  w  .j  a  v a  2s.co m*/
    headerContributor = new IHeaderContributor() {

        @Override
        public void renderHead(final IHeaderResponse response) {

            if (component.isVisibleInHierarchy()) {
                String id = component.getMarkupId(true);
                response.renderOnDomReadyJavascript(
                        String.format("document.getElementById(%s).focus()", JSUtils.toString(id)));
            }
        }
    };
}

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

License:Open Source License

private void respondHeaderContribution(final StringBuilder headerJS, final Component component) {
    if (header == null) {
        header = new ScrollResponseHeaderContainer();
    }/*from   ww w.  j a  v a2 s. c om*/
    header.setOutput(headerJS);
    component.renderHead(header);

    if (component instanceof MarkupContainer) {
        ((MarkupContainer) component).visitChildren(new Component.IVisitor<Component>() {
            public Object component(Component c) {
                if (c.isVisibleInHierarchy()) {
                    c.renderHead(header);
                    return CONTINUE_TRAVERSAL;
                } else {
                    return CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
                }
            }
        });
    }
}

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

License:Open Source License

public PageContributor(final IApplication application, String id) {
    super(id, new Model());
    this.application = application;
    setOutputMarkupPlaceholderTag(true);

    add(new AbstractServoyDefaultAjaxBehavior() {
        private static final long serialVersionUID = 1L;

        @Override//from   w w  w.j  a  va2s .com
        protected void respond(AjaxRequestTarget target) {
            String update = getRequestCycle().getRequest().getParameter("update"); //$NON-NLS-1$
            // get the update parameter and check if that is still the same, else wait for the next.
            if (Long.parseLong(update) == lastTableUpdate) {
                for (int i = 0; i < tablesToRender.size(); i++) {
                    Component comp = tablesToRender.get(i);
                    if (comp.isVisibleInHierarchy()) {
                        target.addComponent(comp);
                    }
                }
                tablesToRender.clear();
                WebEventExecutor.generateResponse(target, findPage());
            } else {
                Debug.log("IGNORED TABLE REQUEST");
            }
        }

        @Override
        public void renderHead(IHeaderResponse response) {
            super.renderHead(response);
            response.renderOnDomReadyJavascript(getCallbackScript().toString());
        }

        @Override
        public CharSequence getCallbackUrl(boolean onlyTargetActivePage) {
            CharSequence url = super.getCallbackUrl(true);
            url = url + "&update=" + lastTableUpdate; //$NON-NLS-1$
            return url;
        }

        @Override
        public boolean isEnabled(Component component) {
            return tablesToRender.size() > 0 && super.isEnabled(component);
        }
    });
    add(eventCallbackBehavior = new EventCallbackBehavior());
    add(new AbstractServoyDefaultAjaxBehavior() {
        @Override
        public void renderHead(IHeaderResponse response) {
            if (isFormWidthZero()) {
                response.renderOnLoadJavascript("Servoy.Resize.onWindowResize();"); //$NON-NLS-1$
            }
        }

        @Override
        protected void respond(AjaxRequestTarget target) {
            // not used
        }

        private boolean isFormWidthZero() {
            final boolean[] returnValue = { false };
            Page page = findPage();
            if (page != null) {
                page.visitChildren(WebForm.class, new Component.IVisitor<WebForm>() {
                    public Object component(WebForm form) {
                        if (form.getFormWidth() == 0 && form.isVisibleInHierarchy()) {
                            IWebFormContainer formContainer = form.findParent(IWebFormContainer.class);
                            if (!(formContainer instanceof WebSplitPane)) {
                                returnValue[0] = true;
                                return IVisitor.STOP_TRAVERSAL;
                            }
                        }
                        return IVisitor.CONTINUE_TRAVERSAL;
                    }
                });
            }
            return returnValue[0];
        }
    });
}

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

License:Open Source License

public static List<Component> getVisibleChildren(Component component, final boolean onlyChanged) {
    final List<Component> visibleChildren = new ArrayList<Component>();
    if (component.isVisibleInHierarchy() && (!onlyChanged || (component instanceof IProviderStylePropertyChanges
            && ((IProviderStylePropertyChanges) component).getStylePropertyChanges().isChanged()))) {
        visibleChildren.add(component);//from  w  w w . j  a  v a 2  s  .c o m
    }
    if (component instanceof MarkupContainer) {
        ((MarkupContainer) component).visitChildren(IProviderStylePropertyChanges.class,
                new IVisitor<Component>() {
                    public Object component(Component stylePropertyChange) {
                        if (!stylePropertyChange.isVisibleInHierarchy()) {
                            return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
                        }
                        if (onlyChanged && !((IProviderStylePropertyChanges) stylePropertyChange)
                                .getStylePropertyChanges().isChanged()) {
                            return IVisitor.CONTINUE_TRAVERSAL;
                        }
                        visibleChildren.add(stylePropertyChange);
                        // add all children from here
                        if (stylePropertyChange instanceof MarkupContainer) {
                            ((MarkupContainer) stylePropertyChange).visitChildren(IComponent.class,
                                    new IVisitor<Component>() {
                                        public Object component(Component fieldComponent) {
                                            if (!fieldComponent.isVisibleInHierarchy()) {
                                                return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
                                            }
                                            visibleChildren.add(fieldComponent);
                                            return IVisitor.CONTINUE_TRAVERSAL;
                                        }
                                    });
                        }
                        return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
                    }
                });
    }
    return visibleChildren;
}

From source file:com.wiquery.plugins.jqgrid.component.XMLDataRequestTarget.java

License:Apache License

/**
 * //  ww w  . ja  va2s .  co  m
 * @param response
 * @param component
 */
private void respondHeaderContribution(final Response response, final Component component,
        StringBuffer writer) {
    headerRendering = true;

    // create the htmlheadercontainer if needed
    if (header == null) {
        header = new AjaxHtmlHeaderContainer(HtmlHeaderSectionHandler.HEADER_ID, this);
        final Page page = component.getPage();
        page.addOrReplace(header);
    }

    // save old response, set new
    Response oldResponse = RequestCycle.get().setResponse(encodingHeaderResponse);

    encodingHeaderResponse.reset();

    // render the head of component and all it's children

    component.renderHead(header);

    if (component instanceof MarkupContainer) {
        ((MarkupContainer) component).visitChildren(new Component.IVisitor<Component>() {
            public Object component(Component component) {
                if (component.isVisibleInHierarchy()) {
                    component.renderHead(header);
                    return CONTINUE_TRAVERSAL;
                } else {
                    return CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
                }
            }
        });
    }

    // revert to old response

    RequestCycle.get().setResponse(oldResponse);

    if (encodingHeaderResponse.getContents().length() != 0) {
        writer.append("<header-contribution");

        if (encodingHeaderResponse.isContentsEncoded()) {
            writer.append(" encoding=\"");
            writer.append(getEncodingName());
            writer.append("\" ");
        }

        // we need to write response as CDATA and parse it on client,
        // because
        // konqueror crashes when there is a <script> element
        writer.append("><![CDATA[<head xmlns:wicket=\"http://wicket.apache.org\">");

        writer.append(encodingHeaderResponse.getContents());

        writer.append("</head>]]>");

        writer.append("</header-contribution>");
    }

    headerRendering = false;
}

From source file:de.alpharogroup.wicket.component.search.ComponentExpression.java

License:Apache License

/**
 * Evaluates the given {@link org.apache.wicket.Component} with the given collection of
 * {@link Condition}s.// w  ww.j  ava 2s  .  c o m
 * 
 * @param conditions
 *            a collection of {@link Condition}s to evaluate.
 * @param component
 *            the {@link org.apache.wicket.Component} that the evaluation will be executed.
 * @return true if the evaluation is successful otherwise false.
 */
private static final boolean evaluateConditions(Collection<Condition> conditions, Component component) {
    boolean result = true;
    for (Condition condition : conditions) {
        switch (condition.getAttr()) {
        case ENABLED: {
            result = result && (component.isEnabledInHierarchy() == condition.getCondition());
            break;
        }
        case VISIBLE: {
            result = result && (component.isVisibleInHierarchy() == condition.getCondition());
        }
        }
        if (!result) {
            break;
        }
    }
    return result;
}

From source file:org.hippoecm.frontend.dialog.AbstractDialogTest.java

License:Apache License

@Test
public void okButtonIsPresentAfterFailure() {
    tester.runInAjax(home, new Runnable() {

        @Override//from  w w  w .  ja  v a 2s . c  o m
        public void run() {
            IDialogService dialogService = context.getService(IDialogService.class.getName(),
                    IDialogService.class);
            dialogService.show(new FailureDialog());
        }
    });

    tester.executeAjaxEvent(home.get("dialog:content:form:buttons:0:button"), "onclick");
    Component button = home.get("dialog:content:form:buttons:0:button");
    assertTrue("OK Button was hidden after failed submit", button.isVisibleInHierarchy());
}

From source file:org.opensingular.lib.wicket.util.util.IBehaviorsMixin.java

License:Apache License

default Behavior visibleIfAlso(Component otherComponent) {
    return new Behavior() {
        @Override//  ww  w.j  av a 2 s.c o m
        public void onConfigure(Component component) {
            component.setVisible(otherComponent.isVisibleInHierarchy());
        }
    };
}

From source file:org.patientview.radar.web.panels.DiagnosisGeneMutationPanel.java

License:Open Source License

public DiagnosisGeneMutationPanel(final String id, int i, CompoundPropertyModel model,
        final IModel<Boolean> otherDetailsVisibilityModel, final IModel<Boolean> moreDetailsVisibilityModel,
        final List<Component> componentsToUpdateList) {
    super(id);/*from  w ww  .j a v  a2s  .  c o m*/

    // Add the field for mutationYorN
    RadioGroup<Diagnosis.MutationYorN> mutationYorN = new RadioGroup<Diagnosis.MutationYorN>("mutationYorN",
            model.bind("mutationYorN" + i));

    Radio<Diagnosis.MutationYorN> y = new Radio<Diagnosis.MutationYorN>("y",
            new Model<Diagnosis.MutationYorN>(Diagnosis.MutationYorN.Y));
    mutationYorN.add(y);
    y.add(new AjaxEventBehavior("onClick") {
        @Override
        protected void onEvent(AjaxRequestTarget target) {
            if (id.equals(DiagnosisPanel.OTHER_CONTAINER_ID)) {
                otherDetailsVisibilityModel.setObject(true);
            } else {
                moreDetailsVisibilityModel.setObject(true);

            }
            for (Component component : componentsToUpdateList) {
                if (component.isVisibleInHierarchy()) {
                    target.add(component);
                }
            }
        }
    });

    Radio<Diagnosis.MutationYorN> n = new Radio<Diagnosis.MutationYorN>("n",
            new Model<Diagnosis.MutationYorN>(Diagnosis.MutationYorN.N));
    mutationYorN.add(n);
    n.add(new AjaxEventBehavior("onClick") {
        @Override
        protected void onEvent(AjaxRequestTarget target) {
            if (id.equals(DiagnosisPanel.OTHER_CONTAINER_ID)) {
                otherDetailsVisibilityModel.setObject(false);
                for (Component component : componentsToUpdateList) {
                    if (component.isVisibleInHierarchy()) {
                        target.add(component);
                    }
                }
            }
        }
    });
    add(mutationYorN);

    // Add the field for mutationSorSN
    RadioGroup<Diagnosis.MutationSorSN> mutationSorSN = new RadioGroup<Diagnosis.MutationSorSN>("mutationSorSN",
            model.bind("mutationSorSN" + i));

    mutationSorSN.add(new Radio<Diagnosis.MutationSorSN>("s",
            new Model<Diagnosis.MutationSorSN>(Diagnosis.MutationSorSN.S)));

    mutationSorSN.add(new Radio<Diagnosis.MutationSorSN>("sn",
            new Model<Diagnosis.MutationSorSN>(Diagnosis.MutationSorSN.SN)));
    add(mutationSorSN);
}