Example usage for org.apache.wicket MarkupContainer addOrReplace

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

Introduction

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

Prototype

public MarkupContainer addOrReplace(final Component... children) 

Source Link

Document

Replaces a child component of this container with another or just adds it in case no child with the same id existed yet.

Usage

From source file:au.com.scds.isis.viewer.wicket.ui.components.entity.properties.MyEntityPropertiesForm.java

License:Apache License

private void addFeedbackGui(final MarkupContainer markupContainer) {
    feedback = new NotificationPanel(ID_FEEDBACK, this, new ComponentFeedbackMessageFilter(this));
    feedback.setOutputMarkupPlaceholderTag(true);
    markupContainer.addOrReplace(feedback);

    // to avoid potential XSS attacks, no longer escape model strings
    // (risk is low but could just happen: error message being rendered
    // might accidentally or deliberately contain rogue Javascript)
    // feedback.setEscapeModelStrings(false);

    final ObjectAdapter adapter = getEntityModel().getObject();
    if (adapter == null) {
        feedback.error("cannot locate object:" + getEntityModel().getObjectAdapterMemento().toString());
    }/*w ww . jav a2s  .  c  om*/
}

From source file:com.premiumminds.webapp.wicket.drawer.DrawerManager.java

License:Open Source License

private void removeDrawer(MarkupContainer previous, AjaxRequestTarget target) {
    Panel panel = new EmptyPanel("next");
    panel.setOutputMarkupId(true);/*  w ww .ja  va2s  .  c  om*/
    previous.addOrReplace(panel);
    target.add(panel);
}

From source file:net.rrm.ehour.ui.report.panel.TreeReportDataPanel.java

License:Open Source License

private void createReportTableContainer(TreeReportModel reportModel, MarkupContainer parent) {
    Border reportFrame = new GreyBlueRoundedBorder("reportFrame") {
        @Override//from   ww w.  jav  a  2s.c om
        protected WebMarkupContainer createComponent() {
            WebMarkupContainer frame = super.createComponent();
            frame.add(AttributeModifier.append("style", "margin: 0 5px 0 5px;"));

            return frame;
        }
    };

    reportFrameContainer = new Container("reportFrameContainer");
    reportFrame.add(reportFrameContainer);

    reportFrameContainer.add(addHeaderColumns("columnHeaders"));

    DataView<TreeReportElement> dataView = createDataView(reportModel);
    reportFrameContainer.add(dataView);
    reportFrameContainer.add(addGrandTotal("cell", reportModel));

    pagingNavigator = createNav(dataView);
    parent.addOrReplace(pagingNavigator);
    parent.addOrReplace(reportFrame);
}

From source file:nl.knaw.dans.common.wicket.WicketUtil.java

License:Apache License

/**
 * Hides an element with a certain wicketId in a certain parent component.
 * @param parentComponent the parent component, may be a page, panel, etc.
 * @param wicketId the id of the wicket element that needs to be hidden
 *///from   ww  w.  j  a  v a  2 s  .  c o m
public static void hide(MarkupContainer parentComponent, String wicketId) {
    HiddenComponent hiddenComponent = new HiddenComponent(wicketId);
    parentComponent.addOrReplace(hiddenComponent);
}

From source file:org.apache.isis.viewer.wicket.ui.components.actionmenu.entityactions.AdditionalLinksPanel.java

License:Apache License

public static AdditionalLinksPanel addAdditionalLinks(final MarkupContainer markupContainer, final String id,
        final List<LinkAndLabel> links, final Style style) {
    if (links.isEmpty()) {
        Components.permanentlyHide(markupContainer, id);
        return null;
    }// ww  w .  ja va  2 s .c o m

    final AdditionalLinksPanel additionalLinksPanel = style.newPanel(id, links);
    markupContainer.addOrReplace(additionalLinksPanel);
    return additionalLinksPanel;
}

From source file:org.apache.isis.viewer.wicket.ui.components.entity.properties.EntityPropertiesForm.java

License:Apache License

private void addFeedbackGui(final MarkupContainer markupContainer) {
    feedback = new NotificationPanel(ID_FEEDBACK, this, new ComponentFeedbackMessageFilter(this));
    feedback.setOutputMarkupPlaceholderTag(true);
    markupContainer.addOrReplace(feedback);

    // to avoid potential XSS attacks, no longer escape model strings
    // (risk is low but could just happen: error message being rendered might accidentally or deliberately contain rogue Javascript)
    // feedback.setEscapeModelStrings(false);

    final ObjectAdapter adapter = getEntityModel().getObject();
    if (adapter == null) {
        feedback.error("cannot locate object:" + getEntityModel().getObjectAdapterMemento().toString());
    }/*w w w  .jav  a2s  .  c om*/
}

From source file:org.apache.isis.viewer.wicket.ui.components.scalars.isisapplib.IsisBlobOrClobPanelAbstract.java

License:Apache License

private Label updateFileNameLabel(String idFileName, MarkupContainer formComponent) {
    class FileNameModel extends Model<String> {
        private static final long serialVersionUID = 1L;

        @Override/*from www .  j  ava2s.c  om*/
        public String getObject() {
            T blobOrClob = getBlobOrClobFromModel();
            String fileName = blobOrClob != null ? blobOrClob.getName() : "";
            return fileName;
        }
    }
    Label fileNameLabel = new Label(idFileName, new FileNameModel());
    formComponent.addOrReplace(fileNameLabel);
    fileNameLabel.setOutputMarkupId(true);
    return fileNameLabel;
}

From source file:org.apache.isis.viewer.wicket.ui.components.scalars.isisapplib.IsisBlobOrClobPanelAbstract.java

License:Apache License

private void updateClearLink(InputFieldVisibility visibility) {
    final MarkupContainer formComponent = (MarkupContainer) getComponentForRegular();
    formComponent.setOutputMarkupId(true); // enable ajax link

    final AjaxLink<Void> ajaxLink = new AjaxLink<Void>(ID_SCALAR_IF_REGULAR_CLEAR) {
        private static final long serialVersionUID = 1L;

        @Override/*from  w  ww . ja v  a 2  s  .c  om*/
        public void onClick(AjaxRequestTarget target) {
            setEnabled(false);
            ScalarModel model = IsisBlobOrClobPanelAbstract.this.getModel();
            model.setObject(null);
            target.add(formComponent);
            target.add(fileNameLabel);
        }
    };
    ajaxLink.setOutputMarkupId(true);
    formComponent.addOrReplace(ajaxLink);

    final T blobOrClob = getBlobOrClobFromModel();
    formComponent.get(ID_SCALAR_IF_REGULAR_CLEAR)
            .setVisible(blobOrClob != null && visibility == InputFieldVisibility.VISIBLE);
}

From source file:org.apache.isis.viewer.wicket.ui.components.scalars.isisapplib.IsisBlobOrClobPanelAbstract.java

License:Apache License

private MarkupContainer updateDownloadLink(String downloadId, MarkupContainer container) {
    final ResourceLink<?> resourceLink = createResourceLink(downloadId);
    if (resourceLink != null) {
        container.addOrReplace(resourceLink);
    } else {/*w  w  w  .j a  v  a2  s.c om*/
        Components.permanentlyHide(container, downloadId);
    }
    return resourceLink;
}

From source file:org.apache.isis.viewer.wicket.ui.components.scalars.reference.ReferencePanel.java

License:Apache License

private void syncWithInput() {
    final ObjectAdapter adapter = getModel().getPendingElseCurrentAdapter();

    // syncLinkWithInput
    final MarkupContainer componentForRegular = (MarkupContainer) getComponentForRegular();
    if (adapter != null) {
        if (componentForRegular != null) {
            final EntityModel entityModelForLink = new EntityModel(adapter);

            entityModelForLink.setContextAdapterIfAny(getModel().getContextAdapterIfAny());
            entityModelForLink.setRenderingHint(getModel().getRenderingHint());

            final ComponentFactory componentFactory = getComponentFactoryRegistry()
                    .findComponentFactory(ComponentType.ENTITY_ICON_AND_TITLE, entityModelForLink);
            final Component component = componentFactory.createComponent(entityModelForLink);

            componentForRegular.addOrReplace(component);

            Components.permanentlyHide(componentForRegular, "entityTitleIfNull");

        }// w w  w .  ja v  a  2  s  . c o  m

    } else {

        if (componentForRegular != null) {
            componentForRegular.addOrReplace(new Label("entityTitleIfNull", "(none)"));
            //Components.permanentlyHide(componentForRegular, "entityTitleIfNull");
            Components.permanentlyHide(componentForRegular, ID_ENTITY_ICON_TITLE);
        }
    }

    // syncLinkWithInputIfAutoCompleteOrChoices
    if (isEditableWithEitherAutoCompleteOrChoices()) {
        final IModel<ObjectAdapterMemento> model = Util.createModel(getModel().asScalarModelWithPending());

        if (select2Field == null) {
            entityLink.setRequired(getModel().isRequired());
            select2Field = Select2ChoiceUtil.newSelect2Choice(ID_AUTO_COMPLETE, model, getModel());
            setProviderAndCurrAndPending(select2Field, getModel().getActionArgsHint());
            if (!getModel().hasChoices()) {
                final Settings settings = select2Field.getSettings();
                final int minLength = getModel().getAutoCompleteMinLength();
                settings.setMinimumInputLength(minLength);
                settings.setPlaceholder(getModel().getName());
            }
            if (hasObjectAutoComplete()) {
                final ObjectSpecification typeOfSpecification = getModel().getTypeOfSpecification();
                final AutoCompleteFacet autoCompleteFacet = typeOfSpecification
                        .getFacet(AutoCompleteFacet.class);
                final Settings settings = select2Field.getSettings();
                final int minLength = autoCompleteFacet.getMinLength();
                settings.setMinimumInputLength(minLength);
            }
            entityLink.addOrReplace(select2Field);
        } else {
            //
            // the select2Field already exists, so the widget has been rendered before.  If it is
            // being re-rendered now, it may be because some other property/parameter was invalid.
            // when the form was submitted, the selected object (its oid as a string) would have
            // been saved as rawInput.  If the property/parameter had been valid, then this rawInput
            // would be correctly converted and processed by the select2Field's choiceProvider.  However,
            // an invalid property/parameter means that the webpage is re-rendered in another request,
            // and the rawInput can no longer be interpreted.  The net result is that the field appears
            // with no input.
            //
            // The fix is therefore (I think) simply to clear any rawInput, so that the select2Field
            // renders its state from its model.
            //
            // see: FormComponent#getInputAsArray()
            // see: Select2Choice#renderInitializationScript()
            //
            select2Field.clearInput();
        }

        if (getComponentForRegular() != null) {
            Components.permanentlyHide((MarkupContainer) getComponentForRegular(), ID_ENTITY_ICON_TITLE);
            Components.permanentlyHide(componentForRegular, "entityTitleIfNull");
        }

        // syncUsability
        if (select2Field != null) {
            final boolean mutability = entityLink.isEnableAllowed() && !getModel().isViewMode();
            select2Field.setEnabled(mutability);
        }

        Components.permanentlyHide(entityLink, "entityLinkIfNull");
    } else {
        // this is horrid; adds a label to the id
        // should instead be a 'temporary hide'
        Components.permanentlyHide(entityLink, ID_AUTO_COMPLETE);
        select2Field = null; // this forces recreation next time around
    }

}