Search in sources :

Example 1 with CellGraphContentProvider

use of eu.esdihumboldt.hale.ui.common.graph.content.CellGraphContentProvider in project hale by halestudio.

the class HtmlMappingExporter method saveImageToFile.

private void saveImageToFile(final Cell cell, File filesDir) {
    Display display;
    if (Display.getCurrent() != null) {
        // use the current display if available
        display = Display.getCurrent();
    } else {
        try {
            // use workbench display if available
            display = PlatformUI.getWorkbench().getDisplay();
        } catch (Throwable e) {
            // use a dedicated display thread if no workbench is
            // available
            display = DisplayThread.getInstance().getDisplay();
        }
    }
    // creates a unique id for each cell
    String cellId = cellIds.getId(cell);
    final File file = new File(filesDir, "img_" + cellId + ".png");
    display.syncExec(new Runnable() {

        @Override
        public void run() {
            OffscreenGraph offscreenGraph = new OffscreenGraph(600, 200) {

                @Override
                protected void configureViewer(GraphViewer viewer) {
                    IContentProvider contentProvider = new CellGraphContentProvider();
                    GraphLabelProvider labelProvider = new GraphLabelProvider(null, HaleUI.getServiceProvider());
                    viewer.setContentProvider(contentProvider);
                    viewer.setLabelProvider(labelProvider);
                    viewer.setInput(cell);
                }
            };
            Graph graph = offscreenGraph.getGraph();
            Dimension dimension = computeSize(graph);
            // minimum width = 600
            offscreenGraph.resize(dimension.width > 600 ? dimension.width : 600, dimension.height);
            try {
                offscreenGraph.saveImage(new BufferedOutputStream(new FileOutputStream(file)), null);
            } catch (Exception e) {
                reporter.error(new IOMessageImpl("Can not create image", e));
            } finally {
                offscreenGraph.dispose();
            }
        }
    });
}
Also used : IContentProvider(org.eclipse.jface.viewers.IContentProvider) GraphLabelProvider(eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) CellGraphContentProvider(eu.esdihumboldt.hale.ui.common.graph.content.CellGraphContentProvider) Dimension(java.awt.Dimension) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) GraphViewer(org.eclipse.zest.core.viewers.GraphViewer) OffscreenGraph(eu.esdihumboldt.hale.ui.util.graph.OffscreenGraph) Graph(org.eclipse.zest.core.widgets.Graph) FileOutputStream(java.io.FileOutputStream) OffscreenGraph(eu.esdihumboldt.hale.ui.util.graph.OffscreenGraph) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) Display(org.eclipse.swt.widgets.Display)

Aggregations

IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)1 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)1 CellGraphContentProvider (eu.esdihumboldt.hale.ui.common.graph.content.CellGraphContentProvider)1 GraphLabelProvider (eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider)1 OffscreenGraph (eu.esdihumboldt.hale.ui.util.graph.OffscreenGraph)1 Dimension (java.awt.Dimension)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 IContentProvider (org.eclipse.jface.viewers.IContentProvider)1 Display (org.eclipse.swt.widgets.Display)1 GraphViewer (org.eclipse.zest.core.viewers.GraphViewer)1 Graph (org.eclipse.zest.core.widgets.Graph)1