Button ruleSaveButton = new Button("ruleSaveButton", new ResourceModel("profiler.rule.save")) {
@Override
public void onSubmit() {
Profiler profiler = getServiceLocator().getProfiler();
try {
profiler.storeProfilingRule(profilingRule);
if (!getRules().contains(profilingRule)) {
getRules().add(profilingRule);
}
ruleIdFieldReadOnly(true);
} catch (ProfilerException e) {
logger.error("Failed to update rule: " + profilingRule, e);
}
}
};
Button ruleRemoveButton = new Button("ruleRemoveButton", new ResourceModel("profiler.rule.remove")) {
@Override
public void onSubmit() {
Profiler profiler = getServiceLocator().getProfiler();
try {
if (getRules().contains(profilingRule)) {
getRules().remove(profilingRule);
}
profiler.deleteProfilingRule(profilingRule);
profilingRule = null;
RuleEditPanel.this.setVisible(false);
} catch (ProfilerException e) {
logger.error("Failed to REMOVE: " + profilingRule, e);
}
}
};
ruleEditForm.add(ruleIdField);
ruleEditForm.add(ruleTitleField);
ruleEditForm.add(ruleClassField);
ruleEditForm.add(ruleSaveButton);
ruleEditForm.add(ruleRemoveButton);
// the list of criteria for the selected rule
ruleEditForm.add(new Label("ruleCriteriaLabel",new ResourceModel("criteria.title")));
SortableDataProvider dataProvider = new SortableDataProvider()
{
public int size()
{
return profilingRule.getRuleCriteria().size();
}
public IModel model(Object object)
{
RuleCriterion ruleCriterion = (RuleCriterion) object;
return new Model(ruleCriterion);
}
public Iterator iterator(int first, int count)
{
return new ArrayList(profilingRule.getRuleCriteria()).subList(first, first + count).iterator();
}
};
IColumn[] columns = { new AbstractColumn(new Model("Name")) {
public void populateItem(Item cellItem, String componentId, IModel rowModel) {
//cellItem.add(new CriterionLink(componentId, rowModel));
cellItem.add(new ActionPanel(componentId, rowModel, new Link("link", rowModel) {
public void onClick()
{
setCriterion((RuleCriterion) getModelObject());
criterionEditPanel.setVisible(true);
}
}, "name"));
}
},
new PropertyColumn(new Model("Value"), "value"),
new PropertyColumn(new Model("Resolver Type"), "type"),
new PropertyColumn(new Model("Fallback Type"), "fallbackType"),
new PropertyColumn(new Model("Order"), "fallbackOrder") };
DataTable ruleCriteriaTable = new DataTable("ruleCriteriaTable", columns, dataProvider, 10);
ruleCriteriaTable.addTopToolbar(new HeadersToolbar(ruleCriteriaTable, dataProvider));
ruleCriteriaTable.addBottomToolbar(new NavigationToolbar(ruleCriteriaTable));
ruleEditForm.add(ruleCriteriaTable);
Button newCriterionButton = new Button("newCriterionButton",new ResourceModel("criteria.new")) {
@Override
public void onSubmit() {
if(StringUtils.isEmpty(getProfilingRule().getId()))
{
error(getLocalizer().getString("ruleIdField.Required",this));
return;
}
Profiler profiler = getServiceLocator().getProfiler();
try {
criterion = profiler.createRuleCriterion();
criterionEditPanel.setVisible(true);
} catch (ClassNotFoundException e) {
logger.error("Could not create new rule criterion.", e);
}