Search in sources :

Example 51 with Label

use of org.apache.wicket.markup.html.basic.Label in project wicket by apache.

the class BookDetails method link.

/**
 * Creates an external page link
 *
 * @param name
 *            The name of the link component to create
 * @param book
 *            The book to link to
 * @param noBookTitle
 *            The title to show if book is null
 * @return The external page link
 */
public static BookmarkablePageLink<Void> link(final String name, final Book book, final String noBookTitle) {
    final BookmarkablePageLink<Void> link = new BookmarkablePageLink<>(name, BookDetails.class);
    if (book != null) {
        link.getPageParameters().add("id", book.getId());
        link.add(new Label("title", new Model<>(book)));
    } else {
        link.add(new Label("title", noBookTitle));
        link.setEnabled(false);
    }
    return link;
}
Also used : BookmarkablePageLink(org.apache.wicket.markup.html.link.BookmarkablePageLink) Label(org.apache.wicket.markup.html.basic.Label) Model(org.apache.wicket.model.Model)

Example 52 with Label

use of org.apache.wicket.markup.html.basic.Label in project wicket by apache.

the class ExportToolbar method onInitialize.

/**
 * {@inheritDoc }
 */
@Override
protected void onInitialize() {
    super.onInitialize();
    WebMarkupContainer td = new WebMarkupContainer("td");
    add(td);
    td.add(AttributeModifier.replace("colspan", new IModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            return String.valueOf(getTable().getColumns().size()).intern();
        }
    }));
    td.add(new Label("exportTo", messageModel));
    RepeatingView linkContainers = new RepeatingView("linkContainer");
    td.add(linkContainers);
    for (IDataExporter exporter : dataExporters) {
        WebMarkupContainer span = new WebMarkupContainer(linkContainers.newChildId());
        linkContainers.add(span);
        span.add(createExportLink("exportLink", exporter));
    }
}
Also used : IModel(org.apache.wicket.model.IModel) Label(org.apache.wicket.markup.html.basic.Label) RepeatingView(org.apache.wicket.markup.repeater.RepeatingView) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer)

Example 53 with Label

use of org.apache.wicket.markup.html.basic.Label in project wicket by apache.

the class AjaxTimerBehaviorTest method restartResultsInAddTimeout.

/**
 * Validates the response, then makes sure the timer injects itself again when called. Tests
 * {@link AbstractAjaxTimerBehavior#restart(AjaxRequestTarget)} method
 *
 * WICKET-1525, WICKET-2152
 */
@Test
public void restartResultsInAddTimeout() {
    final Integer labelInitialValue = Integer.valueOf(0);
    final Label label = new Label(MockPageWithLinkAndComponent.COMPONENT_ID, new Model<Integer>(labelInitialValue));
    // the duration doesn't matter because we manually trigger the behavior
    final AbstractAjaxTimerBehavior timerBehavior = new AbstractAjaxTimerBehavior(Duration.seconds(2)) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onTimer(AjaxRequestTarget target) {
            // increment the label's model object
            label.setDefaultModelObject(((Integer) label.getDefaultModelObject()) + 1);
            target.add(label);
        }
    };
    final MockPageWithLinkAndComponent page = new MockPageWithLinkAndComponent();
    page.add(label);
    page.add(new AjaxLink<Void>(MockPageWithLinkAndComponent.LINK_ID) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            if (timerBehavior.isStopped()) {
                timerBehavior.restart(target);
            } else {
                timerBehavior.stop(target);
            }
        }
    });
    label.setOutputMarkupId(true);
    label.add(timerBehavior);
    tester.startPage(page);
    final String labelPath = MockPageWithLinkAndComponent.COMPONENT_ID;
    // assert label == initial value (i.e. 0)
    tester.assertLabel(labelPath, String.valueOf(labelInitialValue));
    // increment to 1
    tester.executeBehavior(timerBehavior);
    // assert label == 1
    tester.assertLabel(labelPath, String.valueOf(labelInitialValue + 1));
    // stop the timer
    tester.clickLink(MockPageWithLinkAndComponent.LINK_ID);
    // trigger it, but it is stopped
    tester.executeBehavior(timerBehavior);
    // assert label is still 1
    tester.assertLabel(labelPath, String.valueOf(labelInitialValue + 1));
    // restart the timer
    tester.clickLink(MockPageWithLinkAndComponent.LINK_ID);
    assertMatches("Wicket.Timer.set", 1);
    // WICKET-5439 label is not updated automatically
    assertMatches("wicket:id=\"component\"", 0);
    // increment to 2
    tester.executeBehavior(timerBehavior);
    // assert label is now 2
    tester.assertLabel(labelPath, String.valueOf(labelInitialValue + 2));
}
Also used : MockPageWithLinkAndComponent(org.apache.wicket.MockPageWithLinkAndComponent) Label(org.apache.wicket.markup.html.basic.Label) Test(org.junit.Test)

Example 54 with Label

use of org.apache.wicket.markup.html.basic.Label in project wicket by apache.

the class AjaxTimerBehaviorTest method setVisibleSetsTimeout.

/**
 */
@Test
public void setVisibleSetsTimeout() {
    Duration dur = Duration.seconds(20);
    final AjaxSelfUpdatingTimerBehavior timer = new AjaxSelfUpdatingTimerBehavior(dur);
    final MockPageWithLinkAndComponent page = new MockPageWithLinkAndComponent();
    final Label label = new Label(MockPageWithLinkAndComponent.COMPONENT_ID, "Hello");
    page.add(label);
    page.add(new AjaxLink<Void>(MockPageWithLinkAndComponent.LINK_ID) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
        }
    });
    label.setOutputMarkupId(true);
    label.setVisible(false);
    label.add(timer);
    tester.startPage(page);
    assertMatches("Wicket.Timer.set", 0);
    tester.clickLink(MockPageWithLinkAndComponent.LINK_ID);
    assertMatches("Wicket.Timer.set", 0);
    label.setVisible(true);
    tester.startPage(page);
    // no visible, so timeout is set
    assertMatches("Wicket.Timer.set", 1);
}
Also used : MockPageWithLinkAndComponent(org.apache.wicket.MockPageWithLinkAndComponent) Label(org.apache.wicket.markup.html.basic.Label) Duration(org.apache.wicket.util.time.Duration) Test(org.junit.Test)

Example 55 with Label

use of org.apache.wicket.markup.html.basic.Label in project wicket by apache.

the class AjaxTimerBehaviorTest method setDisabledClearsTimeout.

/**
 */
@Test
public void setDisabledClearsTimeout() {
    final AbstractAjaxTimerBehavior timer = new AbstractAjaxTimerBehavior(Duration.seconds(20)) {

        private boolean enabled = true;

        @Override
        protected void onTimer(AjaxRequestTarget target) {
            enabled = false;
        }

        @Override
        public boolean isEnabled(Component component) {
            return enabled;
        }
    };
    final MockPageWithLinkAndComponent page = new MockPageWithLinkAndComponent();
    final Label label = new Label(MockPageWithLinkAndComponent.COMPONENT_ID, "Hello");
    page.add(label);
    page.add(new Link<Void>(MockPageWithLinkAndComponent.LINK_ID) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
        }
    });
    label.setOutputMarkupId(true);
    label.add(timer);
    tester.startPage(page);
    assertMatches("Wicket.Timer.set", 1);
    tester.executeBehavior(timer);
    assertMatches("Wicket.Timer.clear", 0);
    assertMatches("Wicket.Timer.set", 0);
}
Also used : MockPageWithLinkAndComponent(org.apache.wicket.MockPageWithLinkAndComponent) Label(org.apache.wicket.markup.html.basic.Label) WebComponent(org.apache.wicket.markup.html.WebComponent) Component(org.apache.wicket.Component) MockPageWithLinkAndComponent(org.apache.wicket.MockPageWithLinkAndComponent) Test(org.junit.Test)

Aggregations

Label (org.apache.wicket.markup.html.basic.Label)519 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)189 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)181 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)121 IModel (org.apache.wicket.model.IModel)116 ListItem (org.apache.wicket.markup.html.list.ListItem)84 ListView (org.apache.wicket.markup.html.list.ListView)70 ArrayList (java.util.ArrayList)68 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)65 PropertyModel (org.apache.wicket.model.PropertyModel)61 Test (org.junit.Test)56 List (java.util.List)51 InfoTooltipBehavior (com.evolveum.midpoint.web.util.InfoTooltipBehavior)47 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)46 IColumn (org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn)41 Model (org.apache.wicket.model.Model)36 Item (org.apache.wicket.markup.repeater.Item)35 AttributeAppender (org.apache.wicket.behavior.AttributeAppender)34 AttributeModifier (org.apache.wicket.AttributeModifier)32 Component (org.apache.wicket.Component)30