Skip to content

Commit

Permalink
jdave-wicket-1.5 now compiles against wicket 1.5. A bunch of deprecat…
Browse files Browse the repository at this point in the history
…ed functionality is still used.
  • Loading branch information
jsyrjala committed Nov 23, 2011
1 parent 57efde9 commit a8a4373
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
21 changes: 18 additions & 3 deletions jdave-wicket-1.5/src/java/jdave/wicket/ComponentSpecification.java
Expand Up @@ -38,9 +38,9 @@
import org.apache.wicket.util.resource.IResourceStream;
import org.apache.wicket.util.resource.StringResourceStream;
import org.apache.wicket.util.tester.BaseWicketTester;
import org.apache.wicket.util.tester.DummyHomePage;
import org.apache.wicket.util.tester.ITestPageSource;
import org.apache.wicket.util.tester.ITestPanelSource;
import org.apache.wicket.util.tester.BaseWicketTester.DummyWebApplication;

/**
* A base class for Wicket's <code>Component</code> specifications.
Expand Down Expand Up @@ -270,11 +270,11 @@ public <T> Item<T> itemAt(final RepeatingView view, final int index) {
* Select an item from a <code>ListView</code>.
*/
public <T> ListItem<T> itemAt(final ListView<T> view, final int index) {
final Iterator<? extends ListItem<T>> items = view.iterator();
final Iterator<Component> items = view.iterator();
for (int i = 0; i < index; i++) {
items.next();
}
return items.next();
return (ListItem<T>)items.next();
}

/**
Expand Down Expand Up @@ -383,4 +383,19 @@ public <S extends Component> MultiSelection<S> selectAll(final Class<S> type,
* @see #startComponent(IModel)
*/
protected abstract C newComponent(String id, IModel<M> model);

private static class DummyWebApplication extends WebApplication
{
@Override
public Class<? extends Page> getHomePage()
{
return DummyHomePage.class;
}

@Override
protected void outputDevelopmentModeWarning()
{
// Do nothing.
}
}
}
41 changes: 21 additions & 20 deletions jdave-wicket-1.5/src/java/jdave/wicket/Selector.java
Expand Up @@ -19,7 +19,8 @@
import java.util.List;
import org.apache.wicket.Component;
import org.apache.wicket.MarkupContainer;
import org.apache.wicket.Component.IVisitor;
import org.apache.wicket.util.visit.IVisit;
import org.apache.wicket.util.visit.IVisitor;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;

Expand Down Expand Up @@ -58,14 +59,14 @@ public <T extends Component, X extends Component> List<X> all(final MarkupContai
private <T extends Component, X extends Component> List<X> selectAll(
final MarkupContainer root, final Class<T> componentType,
final Matcher<T> componentMatcher) {
final CollectingVisitor<T, X> visitor = new CollectingVisitor<T, X>(componentMatcher);
return visitor.selectFrom(root, componentType, IVisitor.CONTINUE_TRAVERSAL);
final CollectingVisitor<T, X> visitor = new CollectingVisitor<T, X>(componentMatcher, false);
return visitor.selectFrom(root, componentType);
}

private <T extends Component, X extends Component> X selectFirst(final MarkupContainer root,
final Class<T> componentType, final Matcher<T> componentMatcher) {
final CollectingVisitor<T, X> visitor = new CollectingVisitor<T, X>(componentMatcher);
final List<X> firstMatch = visitor.selectFrom(root, componentType, IVisitor.STOP_TRAVERSAL);
final CollectingVisitor<T, X> visitor = new CollectingVisitor<T, X>(componentMatcher, true);
final List<X> firstMatch = visitor.selectFrom(root, componentType);
if (firstMatch.isEmpty()) {
return null;
}
Expand All @@ -79,33 +80,33 @@ private <T extends Component> Matcher<T> combine(final Matcher<?> modelMatcher,
new WicketIdEqualsTo<T>(wicketId));
}


/**
* Not thread safe.
*/
private class CollectingVisitor<T extends Component, X extends Component> implements
IVisitor<T> {
IVisitor<T, X> {
private final Matcher<T> componentMatcher;
private final List<X> matches = new ArrayList<X>();
private Object actionOnMatch;

public CollectingVisitor(final Matcher<T> componentMatcher) {
private final boolean stopAfterFirstMatch;
public CollectingVisitor(final Matcher<T> componentMatcher, boolean stopAfterFirstMatch) {
this.componentMatcher = componentMatcher;
this.stopAfterFirstMatch = stopAfterFirstMatch;
}

public List<X> selectFrom(final MarkupContainer root, final Class<T> componentType) {
root.visitChildren(componentType, this);
return matches;
}

@SuppressWarnings( { "unchecked" })
public Object component(final Component component) {
@SuppressWarnings("unchecked")
public void component(T component, IVisit<X> visit) {
if (componentMatcher.matches(component)) {
matches.add((X) component);
return actionOnMatch;
if(stopAfterFirstMatch) {
visit.stop((X) component);
}
}
return CONTINUE_TRAVERSAL;
}

public List<X> selectFrom(final MarkupContainer root, final Class<T> componentType,
final Object actionOnMatch) {
this.actionOnMatch = actionOnMatch;
root.visitChildren(componentType, this);
return matches;
}
}
}
3 changes: 2 additions & 1 deletion jdave-wicket-1.5/src/test/jdave/wicket/PageWithItems.java
Expand Up @@ -33,6 +33,7 @@
* @author Joni Freeman
*/
public class PageWithItems extends WebPage {
@SuppressWarnings({ "unchecked", "rawtypes" })
public PageWithItems(final IModel<List<Integer>> items) {
add(new ListView<Integer>("listView", items) {
@Override
Expand All @@ -56,7 +57,7 @@ protected void populateItem(Item<Integer> item) {
item.add(new Label("item", item.getModelObject().toString()));
}
});
add(new WebMarkupContainer("container", new CompoundPropertyModel<List<Integer>>(this))
add(new WebMarkupContainer("container", new CompoundPropertyModel(this))
.add(new WebMarkupContainer("innerContainer")));
}
}

0 comments on commit a8a4373

Please sign in to comment.