Bread Crumbs Based on the Context Object
This example shows how bread crumbs can be created based on the context object of the page. The bread crumbs for this example were created by the FolderedBreadCrumbDelegate. This is the default delegate that will be called to create bread crumbs, if it can, when no other delegate claims the ability to handle the page. This is accomplished with the following code:
@Override
public boolean canHandle(Persistable p, WTContainer container, String url)
throws WTException {
return true;
}
The FolderedBreadCrumbDelegate first tries to use a passed in WTContainer (“container” in this case), if any. If no container is passed in, the delegate uses the Persistable context object (“p” in this case) to determine where the object lives in the system. If the Persistable is itself a container, use that as the crumb. If the Persistable is not a container, attempt to get the Persistable’s container as the crumb. If all of the previous options fail, simply return an empty crumb.
public class FolderedBreadCrumbDelegate implements BreadCrumbDelegate {



@Override
public AbstractBreadCrumbGenerator getGenerator(Persistable p,
WTContainer container, String url) throws WTException {
return new FolderedCrumbGenerator(p, container);
}

public class FolderedCrumbGenerator extends AbstractBreadCrumbGenerator {

protected Persistable p;

protected WTContainer container;

public FolderedCrumbGenerator(Persistable p, WTContainer container) throws WTException {
init();

// If a container is present, use it. Else if p is itself a
// container, use that. Otherwise get p's
// container.
if (container != null) {
this.container = container;
} else if (p instanceof WTContainer) {
this.container = (WTContainer) p;
} else if (p instanceof WTContained) {
this.container = ((WTContained) p).getContainer();
}

this.p = p;
}

@Override
public JSONArray getCrumbs() {
// Try to add the container crumbs.
try {
addContainerCrumbs(container);
} catch (Exception e) {
addCrumb(getSecuredInfoCrumb());
}

// Try to add the trail of parent folder crumbs.
try {
addFoldersIfNeeded(container, p);
} catch (Exception e) {
addCrumb(getSecuredInfoCrumb());
}

return crumbs;
}


When visiting the info page link for our example haiku, you can see the bread crumb shows that this particular object resides under Site > Folders. Note: only users with adequate permissions will be able to view this object’s info page.
Location of Example
To navigate to this example in the product go to Customization > Component Catalog > Bread Crumb > Bread Crumb Component based on the Context Object.
* 
The Component Catalog is not enabled in the Windchill UI by default. For instructions on enabling the Component Catalog, see Enable Customization Utilities.
Actions for this Example
None
Action Models for this Example
None
Files Used in This Example
com/ptc/windchill/enterprise/navigation/breadcrumb/FolderedBreadCrumbDelegate.java
com/ptc/core/components/components.wt.properties.xconf
도움이 되셨나요?