protected void populateItem(final ListItem<XMLGridSubset> item) {
// odd/even style
final int index = item.getIndex();
item.add(new SimpleAttributeModifier("class", index % 2 == 0 ? "even" : "odd"));
final XMLGridSubset gridSubset = item.getModelObject();
GridSetBroker gridSetBroker = GWC.get().getGridSetBroker();
String gridsetDescription = null;
int gridsetLevels;
boolean gridsetExists;
{
final GridSet gridSet = gridSetBroker.get(gridSubset.getGridSetName());
gridsetExists = gridSet != null;
if (gridsetExists) {
gridsetLevels = gridSet.getNumLevels();
gridsetDescription = gridSet.getDescription();
} else {
gridsetLevels = gridSubset.getZoomStop() == null ? 1 : gridSubset
.getZoomStop().intValue();
}
}
final Label gridSetLabel;
final Component gridSetBounds;
gridSetLabel = new Label("gridSet", new PropertyModel<String>(item.getModel(),
"gridSetName"));
if(!gridsetExists){
gridSetLabel.add(new AttributeModifier("style", true, new Model<String>("color:red;text-decoration:line-through;")));
getPage().warn("GridSet " + gridSubset.getGridSetName() + " does not exist");
}
item.add(gridSetLabel);
if (null != gridsetDescription) {
gridSetLabel.add(new AttributeModifier("title", true, new Model<String>(
gridsetDescription)));
}
final Component removeLink;
final int maxZoomLevel = gridsetLevels - 1;
final ArrayList<Integer> zoomLevels = new ArrayList<Integer>(maxZoomLevel + 1);
for (int z = 0; z <= maxZoomLevel; z++) {
zoomLevels.add(Integer.valueOf(z));
}
// zoomStart has all zoom levels as choices
// zoomStop choices start at zoomStart's selection
// minCachedLevel start at zoomStart's selection and ends at zoomStop's selection
// maxCachedLevel start at minCachedLevels' and ends at zoomStop's selection
final IModel<Integer> zoomStartModel;
final IModel<Integer> zoomStopModel;
final IModel<Integer> minCachedLevelModel;
final IModel<Integer> maxCachedLevelModel;
final ZoomLevelDropDownChoice zoomStart;
final ZoomLevelDropDownChoice zoomStop;
final ZoomLevelDropDownChoice minCachedLevel;
final ZoomLevelDropDownChoice maxCachedLevel;
zoomStartModel = new PropertyModel<Integer>(item.getModel(), "zoomStart");
zoomStopModel = new PropertyModel<Integer>(item.getModel(), "zoomStop");
minCachedLevelModel = new PropertyModel<Integer>(item.getModel(), "minCachedLevel");
maxCachedLevelModel = new PropertyModel<Integer>(item.getModel(), "maxCachedLevel");
@SuppressWarnings({ "rawtypes", "unchecked" })
final IModel<List<Integer>> allLevels = new Model(zoomLevels);
zoomStart = new ZoomLevelDropDownChoice("zoomStart", zoomStartModel, allLevels);
zoomStart.setEnabled(gridsetExists);
item.add(zoomStart);
zoomStop = new ZoomLevelDropDownChoice("zoomStop", zoomStopModel, allLevels);
zoomStop.setEnabled(gridsetExists);
item.add(zoomStop);
minCachedLevel = new ZoomLevelDropDownChoice("minCachedLevel", minCachedLevelModel,
allLevels);
minCachedLevel.setEnabled(gridsetExists);
item.add(minCachedLevel);
maxCachedLevel = new ZoomLevelDropDownChoice("maxCachedLevel", maxCachedLevelModel,
allLevels);
maxCachedLevel.setEnabled(gridsetExists);
item.add(maxCachedLevel);
for (ZoomLevelDropDownChoice dropDown : Arrays.asList(zoomStart, zoomStop,
minCachedLevel, maxCachedLevel)) {
dropDown.add(new OnChangeAjaxBehavior() {
private static final long serialVersionUID = 1L;
// cascades to zoomStop, min and max cached levels
@Override
protected void onUpdate(AjaxRequestTarget target) {
updateValidZoomRanges(zoomStart, zoomStop, minCachedLevel,
maxCachedLevel, target);
}
});
}
updateValidZoomRanges(zoomStart, zoomStop, minCachedLevel, maxCachedLevel, null);
// gridSetBounds = new EnvelopePanel("bounds");
// gridSetBounds.setCRSFieldVisible(false);
// gridSetBounds.setCrsRequired(false);
// gridSetBounds.setLabelsVisibility(false);
// gridSetBounds.setModel(new Model<ReferencedEnvelope>(new ReferencedEnvelope()));
gridSetBounds = new Label("bounds", new ResourceModel(
"GridSubsetsEditor.bounds.dynamic"));
item.add(gridSetBounds);
removeLink = new ImageAjaxLink("removeLink", GWCIconFactory.DELETE_ICON) {
private static final long serialVersionUID = 1L;
@Override
protected void onClick(AjaxRequestTarget target) {
List<XMLGridSubset> list;
list = new ArrayList<XMLGridSubset>(grids.getModelObject());
final XMLGridSubset subset = (XMLGridSubset) getDefaultModelObject();
list.remove(subset);
grids.setModelObject(list);
List<String> choices = new ArrayList<String>(availableGridSets.getChoices());
choices.add(subset.getGridSetName());
Collections.sort(choices);
availableGridSets.setChoices(choices);
target.addComponent(container);
target.addComponent(availableGridSets);
}
};
removeLink.setDefaultModel(item.getModel());
removeLink.add(new AttributeModifier("title", true, new ResourceModel(
"GridSubsetsEditor.removeLink")));
item.add(removeLink);
}
};
grids.setOutputMarkupId(true);
// this is necessary to avoid loosing item contents on edit/validation checks
grids.setReuseItems(true);
table.add(grids);
List<String> gridSetNames = new ArrayList<String>(GWC.get().getGridSetBroker().getNames());
for (XMLGridSubset gs : model.getObject()) {
gridSetNames.remove(gs.getGridSetName());
}
Collections.sort(gridSetNames);
GeoServerAjaxFormLink addGridsubsetLink = new GeoServerAjaxFormLink("addGridSubset") {
private static final long serialVersionUID = 1L;
@Override
protected void onClick(AjaxRequestTarget target, Form form) {
availableGridSets.processInput();
final String selectedGridset = availableGridSets.getModelObject();
if (null == selectedGridset) {
return;
}
List<String> choices = new ArrayList<String>(availableGridSets.getChoices());
choices.remove(selectedGridset);
availableGridSets.setChoices(choices);
availableGridSets.setEnabled(!choices.isEmpty());
XMLGridSubset newSubset = new XMLGridSubset();
newSubset.setGridSetName(selectedGridset);
grids.getModelObject().add(newSubset);
target.addComponent(table);
target.addComponent(availableGridSets);
}