@Override
protected void onClick(AjaxRequestTarget target) {
List<ParameterFilter> list;
list = new ArrayList<ParameterFilter>(filters.getModelObject());
final ParameterFilter filter = (ParameterFilter) getDefaultModelObject();
list.remove(filter);
filters.setModelObject(list);
item.remove();
target.addComponent(container);
}
};
removeLink.setDefaultModel(item.getModel());
removeLink.add(new AttributeModifier("title", true, new ResourceModel(
"ParameterFilterEditor.removeLink")));
item.add(removeLink);
}
};
filters.setOutputMarkupId(true);
// this is necessary to avoid loosing item contents on edit/validation checks
filters.setReuseItems(true);
table.add(filters);
List<String> parameterKeys = new ArrayList<String>(GWC.get().getGridSetBroker().getNames());
for (ParameterFilter filter : model.getObject()) {
parameterKeys.remove(filter.getKey());
}
Collections.sort(parameterKeys);
GeoServerAjaxFormLink addStyleFilterLink = new GeoServerAjaxFormLink("addStyleFilter") {
private static final long serialVersionUID = 1L;
@Override
protected void onClick(AjaxRequestTarget target, Form form) {
StyleParameterFilter newFilter = new StyleParameterFilter();
newFilter.setLayer((LayerInfo)layerModel.getObject());
addFilter(newFilter);
target.addComponent(container);
}
};
addStyleFilterLink.add(new Icon("addIcon", GWCIconFactory.ADD_ICON));
add(addStyleFilterLink);
// FIXME: make this extensible so new kinds of filter can be supported by
ArrayList<Class<? extends ParameterFilter>> filterTypes =
new ArrayList<Class<? extends ParameterFilter>>();
filterTypes.add(StringParameterFilter.class);
filterTypes.add(FloatParameterFilter.class);
filterTypes.add(RegexParameterFilter.class);
availableFilterTypes = new DropDownChoice<Class<? extends ParameterFilter>>
( "availableFilterTypes",
new Model<Class<? extends ParameterFilter>>(),
new Model<ArrayList<Class<? extends ParameterFilter>>>(filterTypes),
new IChoiceRenderer<Class<? extends ParameterFilter>>() {
/** serialVersionUID */
private static final long serialVersionUID = 1L;
@Override
public Object getDisplayValue(
Class<? extends ParameterFilter> object) {
String resource = "ParameterFilterEditor.filtername."
+object.getCanonicalName();
try {
// Try to look up a localized name for the class
return getLocalizer().getString(resource,
ParameterFilterEditor.this);
} catch (MissingResourceException ex) {
// Use the simple name as a backup
if(LOGGER.isLoggable(Level.CONFIG))
LOGGER.log(Level.CONFIG, "Could not find localization resource"+
" for ParameterFilter subclass "+object.getCanonicalName());
return object.getSimpleName();
}
}
@Override
public String getIdValue(
Class<? extends ParameterFilter> object,
int index) {
return Integer.toString(index);
}
});
availableFilterTypes.setOutputMarkupId(true);
add(availableFilterTypes);
newFilterKey = new TextField<String>("newFilterKey", Model.of(""));
add(newFilterKey);
// TODO update this to eliminate keys that are in use
final RepeatingView commonKeys = new RepeatingView("commonKeys");
for(String key: COMMON_KEYS) {
commonKeys.add(new Label(commonKeys.newChildId(), key));
}
add(commonKeys);
GeoServerAjaxFormLink addFilterLink = new GeoServerAjaxFormLink("addFilter") {
private static final long serialVersionUID = 1L;
@Override
protected void onClick(AjaxRequestTarget target, Form form) {
availableFilterTypes.processInput();
newFilterKey.processInput();
String key = newFilterKey.getModelObject();
if(key == null || key.isEmpty()){
ParamResourceModel rm = new ParamResourceModel("ParameterFilterEditor.nonEmptyFilter", null, "");
error(rm.getString());
}else{
Class<? extends ParameterFilter> type = availableFilterTypes.getModelObject();
try {
ParameterFilter newFilter = type.getConstructor().newInstance();
newFilter.setKey(key);
addFilter(newFilter);
newFilterKey.setModel(Model.of("")); // Reset the key field
} catch (NoSuchMethodException ex) {
LOGGER.log(Level.WARNING, "No Default Constructor for "+type ,ex);
} catch (InvocationTargetException ex) {