Search in sources :

Example 1 with DefaultTool

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;
    }
}
Also used : DefaultTool(de.knowwe.tools.DefaultTool) DefaultTool(de.knowwe.tools.DefaultTool) AsynchronousActionTool(de.knowwe.tools.AsynchronousActionTool) Tool(de.knowwe.tools.Tool)

Example 2 with DefaultTool

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;
}
Also used : ArticleManager(de.knowwe.core.ArticleManager) HashMap(java.util.HashMap) Article(de.knowwe.core.kdom.Article) DefaultTool(de.knowwe.tools.DefaultTool) ArrayList(java.util.ArrayList) Section(de.knowwe.core.kdom.parsing.Section) TermCompiler(de.knowwe.core.compile.terminology.TermCompiler) Identifier(com.denkbares.strings.Identifier) PackageCompiler(de.knowwe.core.compile.PackageCompiler) DefaultTool(de.knowwe.tools.DefaultTool) Tool(de.knowwe.tools.Tool)

Example 3 with DefaultTool

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 + "&amp;" + OntologyDownloadAction.PARAM_SYNTAX + "=" + Strings.encodeURL(syntax.getDefaultMIMEType()) + "&amp;" + 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);
}
Also used : Rdf2GoCore(de.knowwe.rdf2go.Rdf2GoCore) OntologyCompiler(de.knowwe.ontology.compile.OntologyCompiler) DefaultTool(de.knowwe.tools.DefaultTool) Section(de.knowwe.core.kdom.parsing.Section)

Example 4 with DefaultTool

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]);
}
Also used : DefaultTool(de.knowwe.tools.DefaultTool) ArrayList(java.util.ArrayList) DefaultTool(de.knowwe.tools.DefaultTool) Tool(de.knowwe.tools.Tool)

Example 5 with DefaultTool

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()]);
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) OntologyCompiler(de.knowwe.ontology.compile.OntologyCompiler) DefaultTool(de.knowwe.tools.DefaultTool) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Section(de.knowwe.core.kdom.parsing.Section) DefaultTool(de.knowwe.tools.DefaultTool) Tool(de.knowwe.tools.Tool)

Aggregations

DefaultTool (de.knowwe.tools.DefaultTool)19 Tool (de.knowwe.tools.Tool)14 Article (de.knowwe.core.kdom.Article)3 Section (de.knowwe.core.kdom.parsing.Section)3 OntologyCompiler (de.knowwe.ontology.compile.OntologyCompiler)3 ArrayList (java.util.ArrayList)3 PackageCompileType (de.knowwe.core.compile.packaging.PackageCompileType)2 IRI (org.eclipse.rdf4j.model.IRI)2 Identifier (com.denkbares.strings.Identifier)1 KnowledgeBase (de.d3web.core.knowledge.KnowledgeBase)1 ArticleManager (de.knowwe.core.ArticleManager)1 PackageCompiler (de.knowwe.core.compile.PackageCompiler)1 TermCompiler (de.knowwe.core.compile.terminology.TermCompiler)1 HeaderType (de.knowwe.jspwiki.types.HeaderType)1 Rdf2GoCore (de.knowwe.rdf2go.Rdf2GoCore)1 AsynchronousActionTool (de.knowwe.tools.AsynchronousActionTool)1 DefaultToolSet (de.knowwe.tools.DefaultToolSet)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1