<commit_before>package org.csstudio.trends.databrowser.editor;

import java.io.File;

import org.csstudio.apputil.ui.elog.ElogDialog;
import org.csstudio.apputil.ui.elog.SendToElogActionHelper;
import org.csstudio.logbook.ILogbook;
import org.csstudio.swt.xygraph.figures.XYGraph;
import org.csstudio.trends.databrowser.Messages;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.ImageLoader;
import org.eclipse.swt.widgets.Shell;

/** Action to send image of plot to logbook.
 *  @author <NAME>
 */
public class SendToElogAction extends SendToElogActionHelper
{
    final private Shell shell;
    final private XYGraph graph;

    /** Initialize
     *  @param shell Parent shell
     *  @param graph Graph to print
     */
    public SendToElogAction(final Shell shell, final XYGraph graph)
    {
        this.shell = shell;
        this.graph = graph;
    }
 
    @Override
    public void run()
    {
        // Get name for snapshot file
        final File tmp_file;
        try
        {
            tmp_file = 
                File.createTempFile("DataBrowser", "png");  //$NON-NLS-1$//$NON-NLS-2$
            tmp_file.deleteOnExit();
        }
        catch (Exception ex)
        {
            final String error = "Cannot create tmp. file:\n" + ex.getMessage(); //$NON-NLS-1$
            MessageDialog.openError(shell, Messages.Error, error);
            return;
        }
        final String filename = tmp_file.getAbsolutePath();
        
        // Create snapshot file
        try
        {
            final ImageLoader loader = new ImageLoader();
            final Image image = graph.getImage();
            loader.data = new ImageData[]{image.getImageData()};
            image.dispose();
            loader.save(filename, SWT.IMAGE_PNG);
        }
        catch (Exception ex)
        {
            MessageDialog.openError(shell, Messages.Error,
                    NLS.bind("Cannot create snapshot in {0}:\n{1}", //$NON-NLS-1$
                            filename, ex.getMessage()));
            return;
        }
        
        // Display dialog, create entry
        try
        {
            final ElogDialog dialog =
                new ElogDialog(shell, Messages.SendToElog,
                        Messages.LogentryDefaultTitle,
                        Messages.LogentryDefaultBody,
                        filename)
            {
                @Override
                public void makeElogEntry(final String logbook_name, final String user,
                        final String password, final String title, final String body)
                        throws Exception
                {
                    final ILogbook logbook = getLogbook_factory()
                                        .connect(logbook_name, user, password);
                    try
                    {
                        logbook.createEntry(title, body, filename);
                    }
                    finally
                    {
                        logbook.close();
                    }
                }
                
            };
            dialog.open();
        }
        catch (Exception ex)
        {
            MessageDialog.openError(shell, Messages.Error,
                    NLS.bind(Messages.ErrorFmt, ex.getMessage()));
        }
    }
}
<commit_msg>extension<commit_after>package org.csstudio.trends.databrowser.editor;

import java.io.File;

import org.csstudio.apputil.ui.elog.ElogDialog;
import org.csstudio.apputil.ui.elog.SendToElogActionHelper;
import org.csstudio.logbook.ILogbook;
import org.csstudio.swt.xygraph.figures.XYGraph;
import org.csstudio.trends.databrowser.Messages;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.ImageLoader;
import org.eclipse.swt.widgets.Shell;

/** Action to send image of plot to logbook.
 *  @author <NAME>
 */
public class SendToElogAction extends SendToElogActionHelper
{
    final private Shell shell;
    final private XYGraph graph;

    /** Initialize
     *  @param shell Parent shell
     *  @param graph Graph to print
     */
    public SendToElogAction(final Shell shell, final XYGraph graph)
    {
        this.shell = shell;
        this.graph = graph;
    }
 
    @Override
    public void run()
    {
        // Get name for snapshot file
        final File tmp_file;
        try
        {
            tmp_file = File.createTempFile("DataBrowser", ".png");  //$NON-NLS-1$//$NON-NLS-2$
            tmp_file.deleteOnExit();
        }
        catch (Exception ex)
        {
            final String error = "Cannot create tmp. file:\n" + ex.getMessage(); //$NON-NLS-1$
            MessageDialog.openError(shell, Messages.Error, error);
            return;
        }
        final String filename = tmp_file.getAbsolutePath();
        
        // Create snapshot file
        try
        {
            final ImageLoader loader = new ImageLoader();
            final Image image = graph.getImage();
            loader.data = new ImageData[]{image.getImageData()};
            image.dispose();
            loader.save(filename, SWT.IMAGE_PNG);
        }
        catch (Exception ex)
        {
            MessageDialog.openError(shell, Messages.Error,
                    NLS.bind("Cannot create snapshot in {0}:\n{1}", //$NON-NLS-1$
                            filename, ex.getMessage()));
            return;
        }
        
        // Display dialog, create entry
        try
        {
            final ElogDialog dialog =
                new ElogDialog(shell, Messages.SendToElog,
                        Messages.LogentryDefaultTitle,
                        Messages.LogentryDefaultBody,
                        filename)
            {
                @Override
                public void makeElogEntry(final String logbook_name, final String user,
                        final String password, final String title, final String body)
                        throws Exception
                {
                    final ILogbook logbook = getLogbook_factory()
                                        .connect(logbook_name, user, password);
                    try
                    {
                        logbook.createEntry(title, body, filename);
                    }
                    finally
                    {
                        logbook.close();
                    }
                }
                
            };
            dialog.open();
        }
        catch (Exception ex)
        {
            MessageDialog.openError(shell, Messages.Error,
                    NLS.bind(Messages.ErrorFmt, ex.getMessage()));
        }
    }
}

{'fraction_non_alphanumeric': 0.09147398843930636, 'fraction_numerical': 0.0017341040462427746, 'mean_word_length': 1.5231498359460445, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5665974', 'n_tokens_mistral': 1873, 'n_tokens_neox': 1806, 'n_words': 398}