Object attrPage = attributes.getAttribute(MWPaneFormatter.ATTRIBUTE_PAGE);
Object attrPageElement = attributes.getAttribute(MWPaneFormatter.ATTRIBUTE_PAGE_ELEMENT);
Object attrTemplateMatcher = attributes.getAttribute(MWPaneFormatter.ATTRIBUTE_TEMPLATE_MATCHER);
Object attrText = attributes.getAttribute(MWPaneFormatter.ATTRIBUTE_TEXT);
Page page = (attrPage instanceof Page) ? (Page) attrPage : null;
TemplateMatcher matcher = (attrTemplateMatcher instanceof TemplateMatcher) ?
(TemplateMatcher) attrTemplateMatcher : null;
MWPaneDisambiguationMenuCreator menu = new MWPaneDisambiguationMenuCreator();
// Manage TemplateMatcher
if (attrPageElement instanceof PageElementTemplate) {
PageElementTemplate template = (PageElementTemplate) attrPageElement;
String templateTitle = getWikipedia().getWikiConfiguration().getPageTitle(
Namespace.TEMPLATE,
template.getTemplateName());
JPopupMenu popup = menu.createPopupMenu(templateTitle);
if ((matcher != null) &&
(matcher.getExplanation() != null) &&
(matcher.getExplanation().length() > 0)) {
menu.addDisabledText(popup, "→ " + matcher.getExplanation() + " ←");
}
menu.addCurrentChapter(popup, position, pageAnalysis);
menu.addSeparator(popup);
Page templatePage = DataManager.getPage(getWikipedia(), templateTitle, null, null, null);
menu.addReplaceTemplate(
getWikipedia(), popup, template, matcher,
page, pageAnalysis.getPage(), element, textPane);
menu.addAnalyze(getWikipedia(), popup, page);