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) {
LOGGER.log(Level.WARNING, "Could not execute default Constructor for "+type ,ex);
} catch (SecurityException ex) {
LOGGER.log(Level.WARNING, "Could not execute default Constructor for "+type ,ex);
} catch (InstantiationException ex) {
LOGGER.log(Level.WARNING, "Could not execute default Constructor for "+type ,ex);
} catch (IllegalAccessException ex) {
LOGGER.log(Level.WARNING, "Could not execute default Constructor for "+type ,ex);
}
}
target.addComponent(container);
}
};
addFilterLink.add(new Icon("addIcon", GWCIconFactory.ADD_ICON));
add(addFilterLink);
}