@SuppressWarnings("serial")
public OrganizeImportsPage() {
TreeModel treeModel = createTreeModel();
final LinkTree tree = new LinkTree("tree", treeModel)
{
@Override
protected void onNodeLinkClicked(Object node, BaseTree tree, AjaxRequestTarget target) {
DefaultMutableTreeNode mnode = (DefaultMutableTreeNode) node;
if (!mnode.isLeaf()) {
return;
}
String imp = (String) mnode.getUserObject();
importName = imp;
info("");
target.add(importField);
target.add(feedbackPanel);
}
};
tree.getTreeState().expandAll();
add(tree);
Form<Object> form = new Form<Object>("editForm", new CompoundPropertyModel<Object>(this));
submitButton = new AjaxButton("submitButton", form) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
if (importName == null || importName.equals("")) {
String message = new StringResourceModel("emptyError", this, null).getString();
error(message);
target.add(feedbackPanel);
return;
}
try {
ruleManager.addImport(importName);
String message = new StringResourceModel("insertedImport", this, null).getString();
LOGGER.info("successfully inserted import " + importName);
info(importName + " " + message);
} catch (RuleBaseException e) {
ruleManager.removeImport(importName);
LOGGER.debug("error while saving import " + importName, e);
String message = new StringResourceModel("savingError", this, null).getString();
error(importName + " " + message + "\n" + e.getLocalizedMessage());
}
tree.setModelObject(createTreeModel());
importName = "";
target.add(importField);
target.add(tree);
target.add(feedbackPanel);
}
@Override
protected void onError(AjaxRequestTarget target, Form<?> form) {
LOGGER.warn("Error during submitButton submit action.");
}
};
submitButton.setOutputMarkupId(true);
form.add(submitButton);
deleteButton = new AjaxButton("deleteButton", form) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
try {
ruleManager.removeImport(importName);
String message = new StringResourceModel("deletedImport", this, null).getString();
info(importName + " " + message);
LOGGER.info("successfully deleted import " + importName);
} catch (RuleBaseException e) {
LOGGER.debug("error while deleting import " + importName, e);
if (e.getMessage().startsWith("Rule Compilation error")) {
ruleManager.addImport(importName);
String message = new StringResourceModel("deletingError", this, null).getString();
error(importName + " " + message + "\n" + e.getLocalizedMessage());
} else {
String message = new StringResourceModel("notExistingError", this, null).getString();
error(importName + " " + message);
}
target.add(feedbackPanel);
return;
}
tree.setModelObject(createTreeModel());
importName = "";
target.add(feedbackPanel);
target.add(importField);