Package com.googlecode.grinderstone.debug.ui.blocks

Source Code of com.googlecode.grinderstone.debug.ui.blocks.GrinderPathBlock

package com.googlecode.grinderstone.debug.ui.blocks;

import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.python.pydev.core.IInterpreterManager;
import org.python.pydev.core.docutils.StringUtils;
import org.python.pydev.debug.ui.launching.PythonRunnerConfig;
import org.python.pydev.plugin.PydevPlugin;
import org.python.pydev.runners.SimpleRunner;

/**
* @author Andruschuk Borislav
*/
public class GrinderPathBlock extends AbstractLaunchConfigurationTab {

    private List fPythonPathList;

    /**
     * Default constructor.
     */
    public GrinderPathBlock() {
        super();
    }

    /**
     * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
     */
    public void createControl(Composite parent) {
        Label label = new Label(parent, SWT.NONE);
        label.setText("PYTHONPATH that will be used in the run:");
        fPythonPathList = new List(parent, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL);

        GridData gd = new GridData(GridData.FILL_BOTH);
        fPythonPathList.setLayoutData(gd);
    }

    /**
     * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
     */
    public String getName() {
        return "Python path";
    }

    public void initializeFrom(ILaunchConfiguration configuration) {
        try {
            IInterpreterManager manager = PydevPlugin.getJythonInterpreterManager();
            String pythonPath = PythonRunnerConfig.getPythonpathFromConfiguration(configuration,
                                                                                  manager);

            fPythonPathList.removeAll();
            java.util.List<String> paths = SimpleRunner.splitPythonpath(pythonPath);
            for (String p : paths) {
                fPythonPathList.add(p);
            }
            setErrorMessage(null);
        } catch (Exception e) {
            // Exceptions here may have several reasons
            // - The interpreter is incorrectly configured
            // - The arguments use an unresolved variable.
            // In each case, the exception contains a meaningful message, that is displayed
            String errorMsg = StringUtils.replaceNewLines(e.getMessage(), " ");

            fPythonPathList.removeAll();
            fPythonPathList.add(errorMsg);
            PydevPlugin.log(e);
            setErrorMessage(errorMsg);
        }
    }

    /**
     * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
     */
    public void performApply(ILaunchConfigurationWorkingCopy configuration) {
        // Nothing to apply, this is a read-only control
        initializeFrom(configuration);
    }

    /**
     * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
     */
    public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
        // No defaults to set
    }

}
TOP

Related Classes of com.googlecode.grinderstone.debug.ui.blocks.GrinderPathBlock

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.