com.databasesandlife.util.wicket.MapKeyModel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-common Show documentation
Show all versions of java-common Show documentation
Utility classes developed at Adrian Smith Software (A.S.S.)
package com.databasesandlife.util.wicket;
import org.apache.wicket.model.AbstractWrapModel;
import org.apache.wicket.model.IModel;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import java.util.SortedMap;
/**
* Takes an underlying model which returns a map, and returns that map's keys.
*
* Performance note:
* Do not use this in a ListView if there are a large number of entries (e.g. more than 1,000).
* Unfortunately the model's getObject method gets called a great number of times if it's used as a ListView's model,
* and the populateItem method calls getModelObject, which does a listView.getModel().get(i).
*
*
* @author This source is copyright Adrian Smith and licensed under the LGPL 3.
* @see Project on GitHub
*/
public class MapKeyModel> extends AbstractWrapModel> {
final @Nonnull IModel> wrappedModel;
public MapKeyModel(@Nonnull IModel> wrappedModel) {
this.wrappedModel = wrappedModel;
}
@Override public IModel> getWrappedModel() {
return wrappedModel;
}
@Override public List getObject() {
return new ArrayList<>(getWrappedModel().getObject().keySet());
}
}