use of de.knowwe.tools.DefaultTool in project d3web-KnowWE by denkbares.
the class AdministrationToolProvider method getTools.
@Override
public Tool[] getTools(Section<?> section, UserContext user) {
if (user.userIsAdmin()) {
boolean readonly = ReadOnlyManager.isReadOnly();
String js = "javascript:KNOWWE.plugin.jspwikiConnector.setReadOnly(" + readonly + ")";
Tool readOnlyTool;
if (readonly) {
readOnlyTool = new DefaultTool(Icon.TOGGLE_ON, "Deactivate ReadOnly Mode", "Disclaimer: This is a purely administrative feature and should not be used for security purposes, because it is not secure.", js, Tool.CATEGORY_LAST);
} else {
readOnlyTool = new DefaultTool(Icon.TOGGLE_OFF, "Activate ReadOnly Mode", "Disclaimer: This is a purely administrative feature and should not be used for security purposes, because it is not secure.", js, Tool.CATEGORY_LAST);
}
DefaultTool threadDumpTool = new DefaultTool(Icon.COPY_TO_CLIPBOARD, "Copy thread dump to clipboard", "Create thread dump and copy it to the clipboard", AsynchronousActionTool.buildJsAction(getClass(), section, "jq$('#" + section.getID() + "').copyToClipboard(response);" + "KNOWWE.editCommons.hideAjaxLoader();" + "KNOWWE.notification.success(null, 'Copied thread dump to clipboard', 'thread-dump.copy', 3000);", Map.of("type", THREAD_DUMP)), Tool.ActionType.ONCLICK, Tool.CATEGORY_EDIT);
return new Tool[] { readOnlyTool, threadDumpTool };
} else {
return null;
}
}
use of de.knowwe.tools.DefaultTool in project d3web-KnowWE by denkbares.
the class TermInfoToolProvider method getTools.
@Override
public Tool[] getTools(Section<?> section, UserContext userContext) {
List<TermCompiler> compilers = new ArrayList<>(Compilers.getCompilersWithCompileScript(section, TermCompiler.class));
Optional<Identifier> identifierOpt = compilers.stream().map(c -> getIdentifier(c, section)).filter(Objects::nonNull).findFirst();
if (identifierOpt.isEmpty())
return ToolUtils.emptyToolArray();
Identifier identifier = identifierOpt.get();
// get sorted list of all defining articles
Map<String, Section<?>> articles = new HashMap<>();
if (compilers.isEmpty())
compilers = new ArrayList<>(Compilers.getCompilers(section, TermCompiler.class));
compilers.sort((o1, o2) -> {
if (o1 instanceof PackageCompiler && o2 instanceof PackageCompiler)
return 0;
if (o1 instanceof PackageCompiler)
return -1;
return 1;
});
for (TermCompiler termCompiler : compilers) {
Collection<Section<?>> definitions = getTermDefiningSections(termCompiler, section);
for (Section<?> definition : definitions) {
Section<?> previewAncestor = PreviewManager.getInstance().getPreviewAncestor(definition);
articles.put(definition.getTitle(), previewAncestor == null ? definition : previewAncestor);
}
}
List<String> sorted = new ArrayList<>(articles.keySet());
Collections.sort(sorted);
// check if we have a home page for that term (article that has the same title)
final ArticleManager articleManager = section.getArticleManager();
if (articleManager == null) {
return ToolUtils.emptyToolArray();
}
Article home = getHomeArticle(articleManager, identifier);
if (home != null) {
sorted.remove(home.getTitle());
sorted.add(0, home.getTitle());
}
// restrict to max number of items
if (sorted.size() > 5)
sorted = sorted.subList(0, 5);
// remove or sort current page to bottom of list
if (sorted.remove(userContext.getTitle()) && "termbrowser".equals(userContext.getParameter("location"))) {
sorted.add(userContext.getTitle());
}
// create tools for edit, rename and definitions
Tool[] tools = new Tool[sorted.size()];
int index = 0;
// tools[index++] = getRenamingTool(term);
for (String title : sorted) {
Section<?> definition = articles.get(title);
String link;
if (definition == null) {
link = KnowWEUtils.getURLLink(title);
} else {
link = KnowWEUtils.getURLLink(definition);
}
String description;
String titleText;
if (title.equals(userContext.getTitle())) {
titleText = "Highlight on this page";
description = "Highlights the occurrence of the term on this page";
} else {
titleText = getTitle(title);
description = getDescription(home, title);
}
tools[index++] = new DefaultTool(Icon.ARTICLE, titleText, description, link, Tool.ActionType.HREF, Tool.CATEGORY_NAVIGATE);
}
return tools;
}
use of de.knowwe.tools.DefaultTool in project d3web-KnowWE by denkbares.
the class OntologyDownloadProvider method getDownloadTool.
protected Tool getDownloadTool(Section<?> section, RDFFormat syntax) {
OntologyCompiler compiler = OntologyUtils.getOntologyCompiler(section);
if (compiler == null) {
return null;
}
Rdf2GoCore ontology = Rdf2GoCore.getInstance(compiler);
if (ontology == null || ontology.isEmpty()) {
return null;
}
// get name of ontology
String ontologyName = DefaultMarkupType.getContent(section).trim();
if (ontologyName.isEmpty()) {
ontologyName = "ontology";
}
String extension = syntax.getDefaultFileExtension();
List<Section<OntologyType>> ontologySections = Sections.successors(section.getArticle(), OntologyType.class);
String jsAction;
// if there is only one ontology section on this article provide static URL access per article name
String identifierForThisOntology;
if (ontologySections.size() == 1) {
identifierForThisOntology = TITLE + "=" + section.getTitle();
} else {
identifierForThisOntology = Attributes.SECTION_ID + "=" + section.getID();
}
jsAction = "action/OntologyDownloadAction" + "?" + identifierForThisOntology + "&" + OntologyDownloadAction.PARAM_SYNTAX + "=" + Strings.encodeURL(syntax.getDefaultMIMEType()) + "&" + OntologyDownloadAction.PARAM_FILENAME + "=" + ontologyName + "." + extension + "";
// assemble download tool
return new DefaultTool(Icon.DOWNLOAD, "Download " + syntax.getName().toUpperCase(), "Download the entire ontology in " + syntax.getName() + " format for deployment.", jsAction, Tool.ActionType.HREF, Tool.CATEGORY_DOWNLOAD);
}
use of de.knowwe.tools.DefaultTool in project d3web-KnowWE by denkbares.
the class AbstractCorrectionToolProvider method getTools.
@Override
public final Tool[] getTools(Section<?> section, UserContext userContext) {
List<Suggestion> suggestions = getSuggestions(userContext, section);
if (suggestions.isEmpty()) {
return ToolUtils.emptyToolArray();
}
List<Tool> tools = new ArrayList<>();
if (showHeader) {
tools.add(new DefaultTool(Icon.LIGHTBULB, Messages.getMessageBundle().getString("KnowWE.Correction.do"), "", null, Tool.CATEGORY_CORRECT));
}
for (int i = 0; i < suggestions.size(); i++) {
Suggestion suggestion = suggestions.get(i);
tools.add(new DefaultTool(Icon.SHARE, suggestions.get(i).getSuggestionLabel(), "", "KNOWWE.plugin.correction.doCorrection('" + section.getID() + "', " + (!suggestion.isScript() ? "'" : "") + suggestions.get(i).getSuggestionText() + (!suggestion.isScript() ? "'" : "") + ", '" + actionClass.getSimpleName() + "');", Tool.CATEGORY_CORRECT + "/item"));
}
return tools.toArray(new Tool[0]);
}
use of de.knowwe.tools.DefaultTool in project d3web-KnowWE by denkbares.
the class SparqlVisTemplateToolProvider method getTools.
@Override
public Tool[] getTools(Section<?> section, UserContext userContext) {
List<Section<SparqlVisualizationType>> templateSections = findApplicableTemplate(section);
if (templateSections == null || templateSections.isEmpty())
return new Tool[] {};
List<Tool> tools = new ArrayList<>();
for (Section<SparqlVisualizationType> templateSection : templateSections) {
String templateClass = DefaultMarkupType.getAnnotation(templateSection, SparqlVisualizationType.VIS_TEMPLATE_CLASS);
if (templateClass == null)
return new Tool[] {};
IRI uri = getIRI(section);
OntologyCompiler compiler = OntologyUtils.getOntologyCompiler(section);
if (compiler == null || uri == null)
return new Tool[] {};
String reducedConceptIRI = Rdf2GoUtils.reduceNamespace(compiler.getRdf2GoCore(), uri.toString());
String link = KnowWEUtils.getURLLink(templateSection.getTitle());
try {
String conceptParameterAppendix = "&concept=" + URLEncoder.encode(reducedConceptIRI, "UTF-8");
link += conceptParameterAppendix;
} catch (UnsupportedEncodingException e) {
LOGGER.error("problem encoding vis template link", e);
}
tools.add(new DefaultTool(Icon.SHOWTRACE, "Visualize with SparqlVis template '" + templateClass + "'", "Open SparqlVis template for class " + templateClass, link, Tool.ActionType.HREF, Tool.CATEGORY_UTIL));
}
return tools.toArray(new Tool[tools.size()]);
}
Aggregations