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();
}
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;
}
Aggregations