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

import org.csstudio.apputil.time.StartEndTimeParser;
import org.csstudio.apputil.xml.DOMHelper;
import org.csstudio.platform.data.TimestampFactory;
import org.csstudio.platform.logging.CentralLogger;
import org.csstudio.platform.model.IProcessVariable;
import org.csstudio.platform.ui.internal.dataexchange.ProcessVariablePopupAction;
import org.csstudio.trends.databrowser.model.ArchiveRescale;
import org.csstudio.trends.databrowser.model.AxisConfig;
import org.csstudio.trends.databrowser.model.FormulaItem;
import org.csstudio.trends.databrowser.model.Model;
import org.csstudio.trends.databrowser.model.PVItem;
import org.csstudio.trends.databrowser.ui.Controller;
import org.csstudio.trends.databrowser.ui.Plot;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Shell;
import org.w3c.dom.Element;

public class OpenDataBrowserShellPopupAction extends ProcessVariablePopupAction {


	@Override
	public void handlePVs(IProcessVariable[] pv_names) {
		Shell shell = new Shell();
		shell.setText(pv_names[0].getName());
		shell.setLocation(10, 10);
		shell.setSize(800, 600);
        Model model = new Model();
        //Create a default model because there is no workspace file.
        createModel(model, pv_names);
        
        // Create GUI elements (Plot)
        GridLayout layout = new GridLayout();
		shell.setLayout(layout);
        
        // Canvas that holds the graph
        final Canvas plot_box = new Canvas(shell, 0);
        plot_box.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, layout.numColumns, 1));

        Plot plot = new Plot(plot_box);
        
        // Create and start controller
        Controller controller = new Controller(shell, model, plot);
        try
        {
            controller.start();
        }
        catch (Exception ex)
        {
            MessageDialog.openError(shell, Messages.Error,
                    NLS.bind(Messages.ControllerStartErrorFmt, ex.getMessage()));
        }

		// open the shell
		shell.open();

	}

	private void createModel(Model model, IProcessVariable[] pv_names) {

//        scroll_enabled = DOMHelper.getSubelementBoolean(root_node, TAG_SCROLL, scroll_enabled);
//        update_period = DOMHelper.getSubelementDouble(root_node, TAG_PERIOD, update_period);
        
//        final String start = DOMHelper.getSubelementString(root_node, TAG_START);
//        final String end = DOMHelper.getSubelementString(root_node, TAG_END);
//        if (start.length() > 0  &&  end.length() > 0)
//        {<commit_msg>o.c.trends.databrowser2.shell.fragment: set pv name correctly<commit_after>package org.csstudio.trends.databrowser;

import org.csstudio.platform.model.IProcessVariable;
import org.csstudio.platform.ui.internal.dataexchange.ProcessVariablePopupAction;
import org.csstudio.trends.databrowser.model.ArchiveRescale;
import org.csstudio.trends.databrowser.model.AxisConfig;
import org.csstudio.trends.databrowser.model.Model;
import org.csstudio.trends.databrowser.model.PVItem;
import org.csstudio.trends.databrowser.ui.Controller;
import org.csstudio.trends.databrowser.ui.Plot;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Shell;

public class OpenDataBrowserShellPopupAction extends ProcessVariablePopupAction {


	@Override
	public void handlePVs(IProcessVariable[] pv_names) {
		Shell shell = new Shell();
		shell.setText(pv_names[0].getName());
		shell.setLocation(10, 10);
		shell.setSize(800, 600);
        Model model = new Model();
        //Create a default model because there is no workspace file.
        createModel(model, pv_names);
        
        // Create GUI elements (Plot)
        GridLayout layout = new GridLayout();
		shell.setLayout(layout);
        
        // Canvas that holds the graph
        final Canvas plot_box = new Canvas(shell, 0);
        plot_box.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, layout.numColumns, 1));

        Plot plot = Plot.forCanvas(plot_box);
        
        // Create and start controller
        Controller controller = new Controller(shell, model, plot);
        try
        {
            controller.start();
        }
        catch (Exception ex)
        {
            MessageDialog.openError(shell, Messages.Error,
                    NLS.bind(Messages.ControllerStartErrorFmt, ex.getMessage()));
        }

		// open the shell
		shell.open();

	}

	private void createModel(Model model, IProcessVariable[] pv_names) {

//        scroll_enabled = DOMHelper.getSubelementBoolean(root_node, TAG_SCROLL, scroll_enabled);
//        update_period = DOMHelper.getSubelementDouble(root_node, TAG_PERIOD, update_period);
        
//        final String start = DOMHelper.getSubelementString(root_node, TAG_START);
//        final String end = DOMHelper.getSubelementString(root_node, TAG_END);
//        if (start.length() > 0  &&  end.length() > 0)
//        {
{'fraction_non_alphanumeric': 0.10655888296895094, 'fraction_numerical': 0.005879110784493846, 'mean_word_length': 3.4260162601626014, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2568494', 'n_tokens_mistral': 1756, 'n_tokens_neox': 1656, 'n_words': 321}