📄 abstractinterpretereditor.java
字号:
/*
* Author: atotic
* Created: Sep 8, 2003
* License: Common Public License v1.0
*/
package org.python.pydev.ui.pythonpathconf;
import java.io.CharArrayWriter;
import java.io.File;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.Iterator;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.ProgressMonitorWrapper;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.swt.widgets.Widget;
import org.python.copiedfromeclipsesrc.JDTNotAvailableException;
import org.python.copiedfromeclipsesrc.PythonListEditor;
import org.python.pydev.core.IInterpreterManager;
import org.python.pydev.plugin.PydevPlugin;
import org.python.pydev.runners.SimpleJythonRunner;
import org.python.pydev.ui.UIConstants;
/**
* Field editor for a list of python interpreter with executable verifier.
*
* <p>
* heavily inspired by org.eclipse.jface.preference.PathEditor
* <p>
* Tries to run python binary to make sure it exists
*
* Subclasses must implement :<code>parseString</code>,<code>createList</code>,<code>getNewInputObject</code>
*/
public abstract class AbstractInterpreterEditor extends PythonListEditor {
public static boolean USE_ICONS = true;
/**
* The last path, or <code>null</code> if none.
* It is used so that we can open the editor in the specified place.
*/
private String lastPath;
/**
* Interpreter manager we are using (given at init)
*/
private IInterpreterManager interpreterManager;
/**
* Tree to add libs.
*/
private Tree tree;
/**
* This is the control where the interpreters are shown
*/
private List listControl;
/**
* Images
*/
private Image imageSystemLibRoot;
/**
* Images
*/
private Image imageSystemLib;
private Composite box;
private Button addBtOthers;
private Button removeBtOthers;
private SelectionListener selectionListenerOthers;
private List listBuiltins;
boolean changed = false;
private Composite boxSystem;
private Button addBtSystemFolder;
private Button removeBtSystemFolder;
private Button addBtSystemJar;
private SelectionListener selectionListenerSystem;
public List getExesList(){
return listControl;
}
/**
* Creates a path field editor linked to the preference name passed
*
* @param labelText the label text of the field editor
* @param parent the parent of the field editor's control
*/
protected AbstractInterpreterEditor(String preferenceName, String labelText, Composite parent, IInterpreterManager interpreterManager) {
init(preferenceName, labelText);
this.interpreterManager = interpreterManager;
if(USE_ICONS){
imageSystemLibRoot = PydevPlugin.getImageCache().get(UIConstants.LIB_SYSTEM_ROOT);
imageSystemLib = PydevPlugin.getImageCache().get(UIConstants.LIB_SYSTEM);
}
createControl(parent);
updateTree();
}
/**
* @see org.eclipse.jface.preference.FieldEditor#createControl(org.eclipse.swt.widgets.Composite)
*/
protected void createControl(Composite parent) {
super.createControl(parent);
listControl = getListControl(parent);
listControl.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
updateTree();
}
public void widgetDefaultSelected(SelectionEvent e) {
updateTree();
}
});
}
/**
* @param parent
* @return
*/
private Tree getTreeLibsControl(Composite parent) {
if (tree == null){
tree = new Tree(parent, SWT.BORDER);
tree.setFont(parent.getFont());
tree.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent event) {
tree = null;
}
});
}
return tree;
}
/**
* Notifies that the Remove button has been pressed.
*/
protected void removePressed() {
super.removePressed();
updateTree();
changed = true;
//we need that because when the user remove something, we want to remove the cache for that.
this.store();
}
protected void addPressed() {
super.addPressed();
updateTree();
changed = true;
}
protected void upPressed() {
super.upPressed();
changed = true;
}
protected void downPressed() {
super.downPressed();
changed = true;
}
protected void adjustForNumColumns(int numColumns) {
super.adjustForNumColumns(numColumns);
((GridData) l1.getLayoutData()).horizontalSpan = numColumns;
((GridData) tree.getLayoutData()).horizontalSpan = numColumns-1;
((GridData) boxSystem.getLayoutData()).horizontalSpan = 1;
((GridData) l2.getLayoutData()).horizontalSpan = numColumns;
((GridData) listBuiltins.getLayoutData()).horizontalSpan = numColumns-1;
((GridData) box.getLayoutData()).horizontalSpan = 1;
}
Label l1;
Label l2;
/**
* @see org.eclipse.jface.preference.ListEditor#doFillIntoGrid(org.eclipse.swt.widgets.Composite, int)
*/
protected void doFillIntoGrid(Composite parent, int numColumns) {
super.doFillIntoGrid(parent, numColumns);
l1 = new Label(parent, SWT.None);
l1.setText("System PYTHONPATH");
GridData gd = new GridData();
gd.horizontalSpan = numColumns;
l1.setLayoutData(gd);
//the tree
tree = getTreeLibsControl(parent);
gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.verticalAlignment = SWT.FILL;
gd.grabExcessVerticalSpace = true;
tree.setLayoutData(gd);
//buttons at the side of the tree
Composite control = getButtonBoxControlSystem(parent);
gd = new GridData();
gd.verticalAlignment = GridData.BEGINNING;
control.setLayoutData(gd);
//label
l2 = new Label(parent, SWT.None);
l2.setText("Forced builtin libs (check http://pydev.sf.net/faq.html for more info).");
gd = new GridData();
l2.setLayoutData(gd);
//the list with the builtins
List list = getBuiltinsListControl(parent);
gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = false;
gd.heightHint = 100;
list.setLayoutData(gd);
//the builtins buttons
control = getButtonBoxControlOthers(parent);
gd = new GridData();
gd.verticalAlignment = GridData.BEGINNING;
control.setLayoutData(gd);
}
/**
* @param parent
* @return
*/
private List getBuiltinsListControl(Composite parent) {
if (listBuiltins == null) {
listBuiltins = new List(parent, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL);
listBuiltins.setFont(parent.getFont());
listBuiltins.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent event) {
listBuiltins = null;
}
});
} else {
checkParent(listBuiltins, parent);
}
return listBuiltins;
}
/**
* Returns this field editor's button box containing the Add Source Folder, Add Jar and Remove
*
* @param parent the parent control
* @return the button box
*/
public Composite getButtonBoxControlSystem(Composite parent) {
if (boxSystem == null) {
boxSystem = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
boxSystem.setLayout(layout);
addBtSystemFolder = createBt(boxSystem, "New Folder", getSelectionListenerSystem());//$NON-NLS-1$
if(this.interpreterManager.isJython()){
addBtSystemJar = createBt(boxSystem, "New Jar", getSelectionListenerSystem());//$NON-NLS-1$
}
removeBtSystemFolder = createBt(boxSystem, "ListEditor.remove", getSelectionListenerSystem());//$NON-NLS-1$
boxSystem.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent event) {
addBtSystemJar = null;
addBtSystemFolder = null;
removeBtSystemFolder = null;
boxSystem = null;
}
});
} else {
checkParent(boxSystem, parent);
}
return boxSystem;
}
/**
* Returns this field editor's button box containing the Add and Remove
*
* @param parent the parent control
* @return the button box
*/
public Composite getButtonBoxControlOthers(Composite parent) {
if (box == null) {
box = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
box.setLayout(layout);
addBtOthers = createBt(box, "ListEditor.add", getSelectionListenerOthers());//$NON-NLS-1$
removeBtOthers = createBt(box, "ListEditor.remove", getSelectionListenerOthers());//$NON-NLS-1$
box.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent event) {
addBtOthers = null;
removeBtOthers = null;
box = null;
}
});
} else {
checkParent(box, parent);
}
return box;
}
/**
* Returns this field editor's selection listener. The listener is created if nessessary.
*
* @return the selection listener
*/
private SelectionListener getSelectionListenerOthers() {
if (selectionListenerOthers == null){
selectionListenerOthers = new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
Widget widget = event.widget;
if (widget == addBtOthers) {
addOthers();
} else if (widget == removeBtOthers) {
removeOthers();
}
}
};
}
return selectionListenerOthers;
}
private static String lastDirectoryDialogPath = null;
private static String lastFileDialogPath = null;
/**
* Returns this field editor's selection listener. The listener is created if nessessary.
*
* @return the selection listener
*/
private SelectionListener getSelectionListenerSystem() {
if (selectionListenerSystem == null){
selectionListenerSystem = new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (listControl.getSelectionCount() == 1) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -