Closed ebocher closed 7 years ago
Good idea. Please use the existing mechanism of editable element as done for all editors in OrbisGIS. Use the same template as the SQL editor:
Action to open a new editor: https://github.com/orbisgis/orbisgis/blob/master/bundles/sqlconsole/src/main/java/org/orbisgis/sqlconsole/MainWindowMenu.java
Implementation of editor factory: https://github.com/orbisgis/orbisgis/blob/master/bundles/sqlconsole/src/main/java/org/orbisgis/sqlconsole/SQLConsoleFactory.java
Implementation of the editor itself: https://github.com/orbisgis/orbisgis/blob/master/bundles/sqlconsole/src/main/java/org/orbisgis/sqlconsole/SQLConsole.java
I understand how to create the editor factory. The main problem is to build a ChartService that exposes several methods :
ChartService chart = Services.getService(ChartService.class); chart.createBarChart(String title, String categoryAxisLabel, String valueAxisLabel, String query)
ChartService chart = Services.getService(ChartService.class); chart.createXYChart(String title, String categoryAxisLabel, String valueAxisLabel, String query)
...
Forgot to said thanks for comments.
Services static class is a thing of the past.
An implementation of EditableElement will store all the data related to the chart. Then this EditableElement feed an instance of EditorManager:
editorManager.openEditable(new ChartElement(title, label, valueLabel ...));
As all OSGi services, in order to get the instance of editor manager you have multiple choice:
private EditorManager editorManager;
@Reference
public void setEditorManager(EditorManager editorManager) {
this.editorManager = editorManager;
}
public void unsetEditorManager(EditorManager editorManager) {
this.editorManager = null;
}
OR
BundleContext thisBundle = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
ServiceReference<?> serviceReference = thisBundle .getServiceReference(EditorManager.class.getName());
// serviceReference may be null if not available
if(serviceReference != null) {
EditorManager editorManager= (EditorManager ) thisBundle .
getService(serviceReference );
}
https://osgi.org/javadoc/r4v43/core/org/osgi/framework/FrameworkUtil.html
Open the connection only when used by the application into a try with resources. Store the datasource.
Done
The idea is to offer a way to display a JfreeChart object onto a docking element.
The user , developer access to a factory that permits to create a chart from any point in OrbisGIS (Groovy, menu on a table or on a layer in the TOC).
The syntax could be
The implementation will be
Any comments are welcome.