Sample Code
The following code is extracted from the CarambolaBreadCrumbDelegate which generates the breadcrumbs for multiple carambola examples or components.
public class CarambolaBreadCrumbDelegate implements BreadCrumbDelegate {
private static final Logger log = LogR.getLoggerInternal(CarambolaBreadCrumbDelegate.class.getName());
@Override
public boolean canHandle(Persistable contextObject, WTContainer container, String url) throws WTException {
return (url.contains("componentCatalog") || url.contains("carambola") || url.contains("apiDocs")
|| url.contains("jsapi") || url.contains("tools") || url.contains("testClients"));
}
@Override
public AbstractBreadCrumbGenerator getGenerator(Persistable p, WTContainer container, String url)
throws WTException {
return new CarambolaCrumbGenerator(p, container, url);
}
public class CarambolaCrumbGenerator extends AbstractBreadCrumbGenerator {
BreadCrumbArray breadCrumbs;
String carambolaURL = "";
public CarambolaCrumbGenerator(Persistable p, WTContainer container, String url) throws WTException {
this.carambolaURL = url;
}
/**
* NOTE: all "main" component pages (treeComponent.jsp, splitPaneComponent.jsp, etc) are covered by the second
* if statement so it never falls through below to also add a breadcrumb to the page itself.
*/
@Override
public BreadCrumbArray getBreadCrumbs() {
breadCrumbs = new BreadCrumbArray();
try {
if (carambolaURL.contains("componentCatalog/componentCatalog")) {
return breadCrumbs;
} else if (carambolaURL.contains("componentCatalog") && carambolaURL.contains("Component.jsp")) {
breadCrumbs.add(CustomizationPage.Page.CATALOG.getFullLink(), CustomizationPage.Page.CATALOG.getDisplayName());
} else if (carambolaURL.contains("jsapi")) {
//two requests come through here on the jsapi page, both having "jsapi" in the url
breadCrumbs.add(CustomizationPage.Page.API_DOCS.getLink(),
CustomizationPage.Page.API_DOCS.getDisplayName());
}
else if (carambolaURL.contains("testClients") &&
!carambolaURL.contains("testClients/testClients")) { // "testClients" is the main test clients
// page
breadCrumbs.add(CustomizationPage.Page.TEST_CLIENTS.getLink(),
CustomizationPage.Page.TEST_CLIENTS.getDisplayName());
} else if (carambolaURL.contains("testClients/tags")) {
breadCrumbs.add(CustomizationPage.Page.TEST_CLIENTS.getLink(),
CustomizationPage.Page.TEST_CLIENTS.getDisplayName());
breadCrumbs.add(CustomizationPage.Page.JCA_TAGS.getLink(),
CustomizationPage.Page.JCA_TAGS.getDisplayName());
} else if ((carambolaURL.contains("/tools/") || carambolaURL.contains("tools"))
&& !carambolaURL.contains("/tools/list")) { // do not show crumb on main Tools page
breadCrumbs.add(CustomizationPage.Page.TOOLS.getLink(),
CustomizationPage.Page.TOOLS.getDisplayName());
} else if (carambolaURL.contains("carambola.mvc.table")) {
addComponentCatalogBreadCrumbs(CustomizationPage.Page.TABLE);
} else if (carambolaURL.contains("carambola.mvc.tree")) {
addComponentCatalogBreadCrumbs(CustomizationPage.Page.TREE);
} else if (carambolaURL.contains("infoPage")) {
addComponentCatalogBreadCrumbs(CustomizationPage.Page.INFO_PAGE);
} else if (carambolaURL.contains("attributePanel")) {
addComponentCatalogBreadCrumbs(CustomizationPage.Page.ATT_PANEL);
} else if (carambolaURL.contains("twoPanePanels")) {
addComponentCatalogBreadCrumbs(CustomizationPage.Page.SPLIT_PANE);
} else if (carambolaURL.contains("menu")) {
addComponentCatalogBreadCrumbs(CustomizationPage.Page.MENU);
} else if (carambolaURL.contains("breadCrumb")) {
addComponentCatalogBreadCrumbs(CustomizationPage.Page.BREAD_CRUMB);
} else if (carambolaURL.contains("miniInfoNavigator")) {
addComponentCatalogBreadCrumbs(CustomizationPage.Page.MINI_NAV);
} else if (carambolaURL.contains("picker")) {
addComponentCatalogBreadCrumbs(CustomizationPage.Page.PICKER);
} else if (carambolaURL.contains("customization/examples/paste")) {
//link to a wizard example on a jsp. One-off case
addComponentCatalogBreadCrumbs(CustomizationPage.Page.WIZARD);
} else if (carambolaURL.contains("apiDocs") && carambolaURL.contains("javadocInternal")) {
breadCrumbs.add(CustomizationPage.Page.API_DOCS.getLink(),
CustomizationPage.Page.API_DOCS.getDisplayName());
}
else if (carambolaURL.contains("graphicalAttrs")) {
addComponentCatalogBreadCrumbs(CustomizationPage.Page.GRAPHICAL_ATTRIBUTES);
}
} catch (WTException e) {
log.warn("Couldn't create carambola crumb.", e);
}
return breadCrumbs;
}
private void addComponentCatalogBreadCrumbs(CustomizationPage.Page component) throws WTException {
breadCrumbs.add(CustomizationPage.Page.CATALOG.getFullLink(), CustomizationPage.Page.CATALOG.getDisplayName());
breadCrumbs.add(component.getFullLink(), component.getDisplayName());
}
}
}
Parent topic