Example usage for org.apache.wicket Component setVisible

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

Introduction

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

Prototype

public final Component setVisible(final boolean visible) 

Source Link

Document

Sets whether this component and any children are visible.

Usage

From source file:org.opensingular.form.wicket.mapper.TableListMapper.java

License:Apache License

private void builContent(BSContainer<?> content, Form<?> form, IModel<SIList<SInstance>> list,
        WicketBuildContext ctx, SViewListByTable view, boolean isEdition) {

    final String markup = ""
            + " <div class='list-table-empty' wicket:id='empty-content'>                                             "
            + "     <p class='list-table-empty-message'>Nenhum item foi adicionado. </p>                             "
            + " </div>                                                                                               "
            + " <div wicket:id='not-empty-content'>                                                                  "
            + "     <table class='table table-condensed table-unstyled' style='margin-bottom:0px'>                   "
            + "          <thead wicket:id='_h'></thead>                                                              "
            + "          <tbody><wicket:container wicket:id='_e'><tr wicket:id='_r'></tr></wicket:container></tbody> "
            + "          <tfoot wicket:id='_ft'>                                                                     "
            + "              <tr><td colspan='99' wicket:id='_fb'></td></tr>                                         "
            + "          </tfoot>                                                                                    "
            + "     </table>                                                                                         "
            + " </div>                                                                                               ";

    final TemplatePanel template = content.newTemplateTag(tp -> markup);

    final WebMarkupContainer emptyContent = new WebMarkupContainer("empty-content");
    emptyContent.add(new Behavior() {
        @Override//from   w  ww. ja  v a  2  s .co  m
        public void onConfigure(Component component) {
            super.onConfigure(component);
            component.setVisible(list.getObject().isEmpty());
        }
    });
    template.add(emptyContent);

    final WebMarkupContainer notEmptyContent = new WebMarkupContainer("not-empty-content");

    final BSTSection tableHeader = new BSTSection("_h").setTagName("thead");
    final ElementsView tableRows = new TableElementsView("_e", list, ctx, form);
    final WebMarkupContainer tableFooter = new WebMarkupContainer("_ft");
    final BSContainer<?> footerBody = new BSContainer<>("_fb");
    final SType<SInstance> elementsType = list.getObject().getElementsType();

    notEmptyContent.add($b.onConfigure(c -> c.setVisible(!list.getObject().isEmpty())));

    //        content.add($b.attrAppender("style", "padding: 15px 15px 10px 15px", ";"));

    if (elementsType.isComposite()) {

        final STypeComposite<?> compositeElementsType = (STypeComposite<?>) elementsType;
        final BSTRow row = tableHeader.newRow();

        if (view.isInsertEnabled()) {
            row.newTHeaderCell($m.ofValue(""));
        }

        Collection<SType<?>> fields = compositeElementsType.getFields();
        int sumWidthPref = fields.stream().mapToInt((x) -> x.asAtrBootstrap().getColPreference(1)).sum();

        for (SType<?> tCampo : fields) {

            final Integer preferentialWidth = tCampo.asAtrBootstrap().getColPreference(1);
            final IModel<String> headerModel = $m.ofValue(tCampo.asAtr().getLabel());
            final BSTDataCell cell = row.newTHeaderCell(headerModel);
            final String width = String.format("width:%.0f%%;", (100.0 * preferentialWidth) / sumWidthPref);
            final boolean isCampoObrigatorio = tCampo.asAtr().isRequired();

            ctx.configureContainer(headerModel);

            cell.setInnerStyle(width);
            cell.add(new ClassAttributeModifier() {
                @Override
                protected Set<String> update(Set<String> oldClasses) {
                    if (isCampoObrigatorio && isEdition) {
                        oldClasses.add("singular-form-required");
                    } else {
                        oldClasses.remove("singular-form-required");
                    }
                    return oldClasses;
                }
            });
        }
    }

    tableFooter.setVisible(!(view.isNewEnabled() && isEdition));

    template.add(notEmptyContent.add(tableHeader).add(tableRows).add(tableFooter.add(footerBody)));

    content.getParent().add(dependsOnModifier(list));
}

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

License:Apache License

default Behavior notVisibleIf(ISupplier<Boolean> model) {
    return new Behavior() {
        @Override// w w  w.ja  va 2s  .c  o  m
        public void onConfigure(Component component) {
            component.setVisible(!model.get());
        }
    };
}

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

License:Apache License

default Behavior visibleIf(ISupplier<Boolean> model) {
    return new Behavior() {
        @Override/*from  ww  w  .  j  a  v a  2  s. c  om*/
        public void onConfigure(Component component) {
            component.setVisible(model.get());
        }
    };
}

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

License:Apache License

default <T> Behavior visibleIfModelObject(IPredicate<T> predicate) {
    return new Behavior() {
        @Override/*from  w ww .  jav  a 2s.  com*/
        @SuppressWarnings("unchecked")
        public void onConfigure(Component component) {
            component.setVisible(predicate.test((T) component.getDefaultModelObject()));
        }
    };
}

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

License:Apache License

default Behavior visibleIf(IModel<Boolean> model) {
    return new Behavior() {
        @Override//w  ww  .  ja  v  a  2s  . c  om
        public void onConfigure(Component component) {
            component.setVisible(model.getObject());
        }
    };
}

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

License:Apache License

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

From source file:org.patientview.radar.web.pages.patient.srns.SrnsPatientPageReadOnly.java

License:Open Source License

public SrnsPatientPageReadOnly(PageParameters parameters) {
    super(parameters);

    //a patient cannot edit so hide and disable stuff so only a read only view is available
    visitChildren(new IVisitor<Component, Object>() {
        public void component(Component component, IVisit<Object> objectIVisit) {
            RadarSecuredSession session = RadarSecuredSession.get();
            if (session.get().isSignedIn()) {
                if (session.getRoles().hasRole(User.ROLE_PATIENT)) {
                    if (component instanceof FormComponent) {
                        component.setEnabled(false);
                    }//from   www.  ja  v a 2 s  . c o m

                    if (component instanceof AjaxSubmitLink) {
                        component.setVisible(false);
                    }

                    for (String regexToHide : Arrays.asList("\\w*edit\\w*(container|form)",
                            "\\w*delete\\w*(container|form)", "\\w*add\\w*(container|form)",
                            "\\w*addnew\\w*")) {
                        Matcher matcher = Pattern.compile(regexToHide, Pattern.CASE_INSENSITIVE)
                                .matcher(component.getId().toLowerCase());
                        if (matcher.matches()) {
                            component.setVisible(false);
                        }
                    }

                    for (String regexToEnable : Arrays.asList("\\w*switcher\\w*")) {
                        Matcher matcher = Pattern.compile(regexToEnable, Pattern.CASE_INSENSITIVE)
                                .matcher(component.getId().toLowerCase());
                        if (matcher.matches()) {
                            component.setEnabled(true);
                        }
                    }
                }
            }

        }
    });
}

From source file:org.projectforge.web.fibu.InvoicePositionsPanel.java

License:Open Source License

@SuppressWarnings("serial")
public void init(final Set<RechnungsPositionVO> invoicePositions) {
    final RepeatingView positionsRepeater = new RepeatingView("pos");
    add(positionsRepeater);/*from  w w w. j  a  v a  2s .c om*/
    if (invoicePositions != null) {
        final Iterator<RechnungsPositionVO> it = invoicePositions.iterator();
        int orderNumber = -1;
        Link<String> link = null;
        RechnungsPositionVO previousOrderPosition = null;
        BigDecimal netSum = BigDecimal.ZERO;
        while (it.hasNext() == true) {
            final RechnungsPositionVO invoicePosition = it.next();
            netSum = netSum.add(invoicePosition.getNettoSumme());
            if (orderNumber != invoicePosition.getRechnungNummer().intValue()) {
                orderNumber = invoicePosition.getRechnungNummer();
                final WebMarkupContainer item = new WebMarkupContainer(positionsRepeater.newChildId());
                positionsRepeater.add(item);
                final Label separatorLabel = new Label("separator", ", ");
                if (previousOrderPosition == null) {
                    separatorLabel.setVisible(false); // Invisible for first entry.
                }
                previousOrderPosition = invoicePosition;
                item.add(separatorLabel);
                link = new Link<String>("link") {
                    @Override
                    public void onClick() {
                        final PageParameters params = new PageParameters();
                        params.add(AbstractEditPage.PARAMETER_KEY_ID,
                                String.valueOf(invoicePosition.getRechnungId()));
                        final RechnungEditPage page = new RechnungEditPage(params);
                        page.setReturnToPage((AbstractSecuredPage) getPage());
                        setResponsePage(page);
                    };
                };
                item.add(link);
                final String invoiceNumber = String.valueOf(invoicePosition.getRechnungNummer());
                final Component label = new Label("label", invoiceNumber).setRenderBodyOnly(true);
                item.add(label);
                if (rechnungDao.hasLoggedInUserSelectAccess(false) == true) {
                    link.add(new Label("label", invoiceNumber));
                    label.setVisible(false);
                } else {
                    link.setVisible(false);
                }
                WicketUtils.addTooltip(link, CurrencyFormatter.format(netSum));
                netSum = BigDecimal.ZERO;
            }
        }
    }
}

From source file:org.sakaiproject.gradebookng.tool.actions.ViewGradeSummaryAction.java

License:Educational Community License

@Override
public ActionResponse handleEvent(final JsonNode params, final AjaxRequestTarget target) {
    final String studentUuid = params.get("studentId").asText();

    final GradebookUiSettings settings = ((GradebookPage) target.getPage()).getUiSettings();

    final GbUser student = businessService.getUser(studentUuid);

    final Map<String, Object> model = new HashMap<>();
    model.put("studentUuid", studentUuid);
    model.put("groupedByCategoryByDefault", settings.isCategoriesEnabled());

    final GradebookPage gradebookPage = (GradebookPage) target.getPage();
    final GbModalWindow window = gradebookPage.getStudentGradeSummaryWindow();

    final Component content = new StudentGradeSummaryPanel(window.getContentId(), Model.ofMap(model), window);

    if (window.isShown() && window.isVisible()) {
        window.replace(content);//w ww  .  ja v a2s.  c om
        content.setVisible(true);
        target.add(content);
    } else {
        window.setContent(content);
        window.show(target);
    }

    window.setStudentToReturnFocusTo(studentUuid);
    content.setOutputMarkupId(true);

    final String modalTitle = (new StringResourceModel("heading.studentsummary", null,
            new Object[] { student.getDisplayName(), student.getDisplayId() })).getString();

    window.setTitle(modalTitle);
    window.show(target);

    target.appendJavaScript(String.format("new GradebookGradeSummary($(\"#%s\"), false, \"%s\");",
            content.getMarkupId(), modalTitle));

    return new EmptyOkResponse();
}

From source file:org.sakaiproject.sitestats.tool.wicket.pages.ServerWidePage.java

License:Educational Community License

@SuppressWarnings("serial")
private void makeSelectorLink(final String id, final String view) {
    IndicatingAjaxLink link = new IndicatingAjaxLink(id) {
        @Override/*w  w w.  ja v a2s .co  m*/
        public void onClick(AjaxRequestTarget target) {
            // select view
            report.setSelectedView(view);
            // make title, description & notes visible
            reportTitle.add(new AttributeModifier("style", new Model("display: block")));
            reportDescription.add(new AttributeModifier("style", new Model("display: block")));
            reportNotes.add(new AttributeModifier("style", new Model("display: block")));
            reportChart.renderImage(target, true);
            // toggle selectors link state
            for (Component lbl : labels.values()) {
                lbl.setVisible(false);
            }
            for (Component lnk : links) {
                lnk.setVisible(true);
            }
            this.setVisible(false);
            labels.get(this).setVisible(true);
            // mark component for rendering
            target.add(selectors);
            target.add(reportTitle);
            target.add(reportDescription);
            target.add(reportNotes);
            target.appendJavaScript("setMainFrameHeightNoScroll( window.name, 650 )");
        }
    };
    link.setVisible(true);
    links.add(link);
    selectors.add(link);
    makeSelectorLabel(link, id + "Lbl");
}