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);
menu.addAnalyze(getWikipedia(), popup, templatePage);
menu.addView(getWikipedia(), popup, page, true);
menu.addView(getWikipedia(), popup, templatePage, true);
menu.addDisambiguation(getWikipedia(), popup, page);
menu.addItemReloadLinks(getWikipedia(), popup, page, getWindow());
return popup;
}
if ((!(attrPage instanceof Page)) || (!(attrText instanceof String))) {
return null;
}
// Menu name
String text = (String) attrText;
JPopupMenu popup = menu.createPopupMenu(null);
// Create sub menus
Configuration config = Configuration.getConfiguration();
AbstractButton addNote = null;
if (config.getBoolean(null, ConfigurationValueBoolean.ADD_NOTE_FOR_HELP)) {
addNote = textPane.getCheckBoxAddNote();
}
menu.addReplaceLink(getWikipedia(), popup, page, text, element, textPane);
menu.addItemRemoveLink(popup, text, textPane, startOffset, endOffset);
menu.addMarkAsNormal(getWikipedia(), popup, page, text, element, textPane);
menu.addMarkAsNeedingHelp(getWikipedia(), popup, page, text, element, textPane, addNote);
menu.addLinkText(getWikipedia(), popup, page, text, element, textPane);
menu.addSeparator(popup);
if (page != null) {
menu.addDisabledText(popup, page.getTitle());
}
menu.addCurrentChapter(popup, position, pageAnalysis);
menu.addSeparator(popup);
menu.addAnalyze(getWikipedia(), popup, page);
menu.addView(getWikipedia(), popup, page, true);
menu.addDisambiguation(getWikipedia(), popup, page);
menu.addItemReloadLinks(getWikipedia(), popup, page, getWindow());
return popup;
}