Search in sources :

Example 1 with Program

use of com.github.lindenb.jvarkit.util.jcommander.Program in project jvarkit by lindenb.

the class JvarkitCentral method start.

@Override
public void start(Stage primaryStage) throws Exception {
    primaryStage.setTitle("Jvarkit-Central");
    StackPane root = new StackPane();
    root.setPadding(new Insets(2));
    final TableView<Class<?>> tableView = new TableView<>();
    final TableColumn<Class<?>, String> nameCol = new TableColumn<>("Name");
    nameCol.setCellValueFactory(CB -> {
        final String value;
        Class<?> clazz = CB.getValue();
        final Program program = clazz.getAnnotation(Program.class);
        if (!Launcher.class.isAssignableFrom(clazz) || program == null) {
            value = null;
        } else {
            value = program.name();
        }
        return new SimpleStringProperty(value);
    });
    final TableColumn<Class<?>, String> descCol = new TableColumn<>("Description");
    descCol.setCellValueFactory(CB -> {
        final String value;
        Class<?> clazz = CB.getValue();
        final Program program = clazz.getAnnotation(Program.class);
        if (!Launcher.class.isAssignableFrom(clazz) || program == null) {
            value = null;
        } else {
            value = program.description();
        }
        return new SimpleStringProperty(value);
    });
    tableView.getColumns().addAll(nameCol, descCol);
    final BorderPane borderPane1 = new BorderPane(tableView);
    borderPane1.setPadding(new Insets(10));
    final Button but = new Button("New Instance...");
    but.setOnAction(AE -> {
        final Class<?> clazz = tableView.getSelectionModel().getSelectedItem();
        if (clazz == null)
            return;
        final Program program = clazz.getAnnotation(Program.class);
        if (!Launcher.class.isAssignableFrom(clazz) || program == null)
            return;
        createNewInstanceOf(clazz);
    });
    FlowPane bottom = new FlowPane(but);
    borderPane1.setBottom(bottom);
    tableView.getItems().addAll(String.class, Integer.class, VCFFilterJS.class, BioAlcidae.class);
    root.getChildren().add(borderPane1);
    // root.getChildren().add(btn);
    primaryStage.setScene(new Scene(root, 300, 250));
    primaryStage.show();
}
Also used : BorderPane(javafx.scene.layout.BorderPane) Insets(javafx.geometry.Insets) Program(com.github.lindenb.jvarkit.util.jcommander.Program) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Scene(javafx.scene.Scene) TableColumn(javafx.scene.control.TableColumn) Button(javafx.scene.control.Button) FlowPane(javafx.scene.layout.FlowPane) StackPane(javafx.scene.layout.StackPane) TableView(javafx.scene.control.TableView)

Example 2 with Program

use of com.github.lindenb.jvarkit.util.jcommander.Program in project jvarkit by lindenb.

the class JVarkitAnnotationProcessor method process.

@Override
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) {
    final String mainClass = System.getProperty("jvarkit.main.class");
    final String thisDir = System.getProperty("jvarkit.this.dir");
    roundEnv.getElementsAnnotatedWith(IncludeSourceInJar.class).stream().filter(E -> E.getKind() == ElementKind.CLASS).filter(E -> E.getAnnotation(IncludeSourceInJar.class) != null).forEach(E -> {
        if (thisDir == null || thisDir.isEmpty())
            return;
        copySource(E);
    });
    /* find if roundEnv contains main class annotated with 'Program' annotation
		 * if true: generate a file that will tell Make to compile the markdown
		 * documentation
		 */
    roundEnv.getElementsAnnotatedWith(Program.class).stream().filter(E -> E.getKind() == ElementKind.CLASS).filter(E -> {
        final Program prog = E.getAnnotation(Program.class);
        return prog != null && prog.generate_doc();
    }).forEach(E -> {
        copySource(E);
        final String className = E.toString();
        if (mainClass == null)
            return;
        if (!mainClass.equals(className))
            return;
        final Program prog = E.getAnnotation(Program.class);
        if (prog == null || !prog.generate_doc())
            return;
        try {
            final Filer filer = super.processingEnv.getFiler();
            FileObject fo = filer.createResource(StandardLocation.CLASS_OUTPUT, "", "markdown.flag");
            fo.openWriter().append(String.valueOf(mainClass)).close();
        } catch (final Exception err) {
            LOG.warn(err);
        }
        if (thisDir != null) {
            final File index_html = new File(thisDir, "docs/index.html");
            if (index_html.exists()) {
                try {
                    final Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(index_html);
                    Element tr = dom.createElement("tr");
                    tr.setAttribute("id", prog.name());
                    // name
                    Element td = dom.createElement("th");
                    tr.appendChild(td);
                    Element a = dom.createElement("a");
                    a.setAttribute("href", E.getSimpleName() + ".html");
                    a.setAttribute("title", E.getSimpleName().toString());
                    td.appendChild(a);
                    a.appendChild(dom.createTextNode(prog.name()));
                    // desc
                    td = dom.createElement("td");
                    tr.appendChild(td);
                    td.appendChild(dom.createTextNode(prog.description()));
                    // keywords
                    td = dom.createElement("td");
                    tr.appendChild(td);
                    td.appendChild(dom.createTextNode(Arrays.asList(prog.keywords()).stream().collect(Collectors.joining(" "))));
                    // terms
                    td = dom.createElement("td");
                    tr.appendChild(td);
                    td.appendChild(dom.createTextNode(Arrays.asList(prog.terms()).stream().map(T -> "[" + T.getAccession() + "]" + T.getLabel()).collect(Collectors.joining(" "))));
                    // misc
                    td = dom.createElement("td");
                    tr.appendChild(td);
                    final DocumentFragment misc = dom.createDocumentFragment();
                    if (prog.deprecatedMsg() != null && !prog.deprecatedMsg().isEmpty()) {
                        Element span = dom.createElement("span");
                        span.setAttribute("style", "color:orange;");
                        span.setAttribute("title", "deprecated");
                        span.appendChild(dom.createTextNode(prog.deprecatedMsg()));
                        misc.appendChild(span);
                        misc.appendChild(dom.createTextNode(". "));
                    }
                    td.appendChild(misc);
                    final XPath xpath = XPathFactory.newInstance().newXPath();
                    final NodeList nodeList = (NodeList) xpath.evaluate("//table[1]/tbody/tr[@id='" + prog.name() + "']", dom, XPathConstants.NODESET);
                    for (int i = 0; i < nodeList.getLength(); ++i) {
                        Node oldTr = nodeList.item(i);
                        if (tr != null) {
                            oldTr.getParentNode().replaceChild(tr, oldTr);
                            tr = null;
                        } else {
                            oldTr.getParentNode().removeChild(oldTr);
                        }
                    }
                    if (tr != null) {
                        Node tbody = (Node) xpath.evaluate("//table[1]/tbody", dom, XPathConstants.NODE);
                        if (tbody != null) {
                            tbody.appendChild(tr);
                            tbody.appendChild(dom.createTextNode("\n"));
                            tr = null;
                        }
                    }
                    if (tr != null) {
                        LOG.warn("Cannot insert new doc in " + index_html);
                    } else {
                        final Transformer transformer = TransformerFactory.newInstance().newTransformer();
                        transformer.setOutputProperty(OutputKeys.INDENT, "no");
                        transformer.setOutputProperty(OutputKeys.METHOD, "xml");
                        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
                        transformer.transform(new DOMSource(dom), new StreamResult(index_html));
                    }
                } catch (final Exception err) {
                    LOG.warn(err);
                }
            } else {
                LOG.warn("Cannot get " + index_html);
            }
        }
    });
    return true;
}
Also used : Transformer(javax.xml.transform.Transformer) DOMSource(javax.xml.transform.dom.DOMSource) Arrays(java.util.Arrays) XPath(javax.xml.xpath.XPath) Program(com.github.lindenb.jvarkit.util.jcommander.Program) AbstractProcessor(javax.annotation.processing.AbstractProcessor) XPathConstants(javax.xml.xpath.XPathConstants) StreamResult(javax.xml.transform.stream.StreamResult) TypeElement(javax.lang.model.element.TypeElement) FileObject(javax.tools.FileObject) SupportedSourceVersion(javax.annotation.processing.SupportedSourceVersion) Document(org.w3c.dom.Document) DeclaredType(javax.lang.model.type.DeclaredType) Node(org.w3c.dom.Node) StandardLocation(javax.tools.StandardLocation) NodeList(org.w3c.dom.NodeList) ElementKind(javax.lang.model.element.ElementKind) Logger(com.github.lindenb.jvarkit.util.log.Logger) Set(java.util.Set) Reader(java.io.Reader) OutputKeys(javax.xml.transform.OutputKeys) Collectors(java.util.stream.Collectors) File(java.io.File) TypeKind(javax.lang.model.type.TypeKind) DocumentFragment(org.w3c.dom.DocumentFragment) SourceVersion(javax.lang.model.SourceVersion) XPathFactory(javax.xml.xpath.XPathFactory) TypeMirror(javax.lang.model.type.TypeMirror) Element(org.w3c.dom.Element) RoundEnvironment(javax.annotation.processing.RoundEnvironment) Filer(javax.annotation.processing.Filer) Writer(java.io.Writer) ProcessingEnvironment(javax.annotation.processing.ProcessingEnvironment) FileReader(java.io.FileReader) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TransformerFactory(javax.xml.transform.TransformerFactory) XPath(javax.xml.xpath.XPath) DOMSource(javax.xml.transform.dom.DOMSource) Program(com.github.lindenb.jvarkit.util.jcommander.Program) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) TypeElement(javax.lang.model.element.TypeElement) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) FileObject(javax.tools.FileObject) Filer(javax.annotation.processing.Filer) File(java.io.File) DocumentFragment(org.w3c.dom.DocumentFragment)

Aggregations

Program (com.github.lindenb.jvarkit.util.jcommander.Program)2 Logger (com.github.lindenb.jvarkit.util.log.Logger)1 File (java.io.File)1 FileReader (java.io.FileReader)1 Reader (java.io.Reader)1 Writer (java.io.Writer)1 Arrays (java.util.Arrays)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)1 Insets (javafx.geometry.Insets)1 Scene (javafx.scene.Scene)1 Button (javafx.scene.control.Button)1 TableColumn (javafx.scene.control.TableColumn)1 TableView (javafx.scene.control.TableView)1 BorderPane (javafx.scene.layout.BorderPane)1 FlowPane (javafx.scene.layout.FlowPane)1 StackPane (javafx.scene.layout.StackPane)1 AbstractProcessor (javax.annotation.processing.AbstractProcessor)1 Filer (javax.annotation.processing.Filer)1