use of org.python.pydev.shared_core.structure.TreeNode in project Pydev by fabioz.
the class AttachToProcess method doIt.
protected void doIt() throws Exception {
IProcessList processList = PlatformUtils.getProcessList();
IProcessInfo[] processList2 = processList.getProcessList();
TreeNode<Object> root = new TreeNode<Object>(null, null);
for (IProcessInfo iProcessInfo : processList2) {
new TreeNode<>(root, iProcessInfo);
}
TreeNode<Object> element = new Select1Dialog() {
@Override
protected String getInitialFilter() {
return "*python*";
}
@Override
protected ILabelProvider getLabelProvider() {
return new TreeNodeLabelProvider() {
@Override
public Image getImage(Object element) {
return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.PUBLIC_ATTR_ICON));
}
@SuppressWarnings("unchecked")
@Override
public String getText(Object element) {
if (element == null) {
return "null";
}
TreeNode<Object> node = (TreeNode<Object>) element;
Object data = node.data;
if (data instanceof IProcessInfo) {
IProcessInfo iProcessInfo = (IProcessInfo) data;
return iProcessInfo.getPid() + " - " + iProcessInfo.getName();
}
return "Unexpected: " + data;
}
};
}
}.selectElement(root);
if (element != null) {
IProcessInfo p = (IProcessInfo) element.data;
int pid = p.getPid();
if (!PydevRemoteDebuggerServer.isRunning()) {
// I.e.: the remote debugger server must be on so that we can attach to it.
PydevRemoteDebuggerServer.startServer();
}
// Select interpreter
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IInterpreterManager interpreterManager = InterpreterManagersAPI.getPythonInterpreterManager();
if (interpreterManager == null) {
MessageDialog.openError(workbenchWindow.getShell(), "No interpreter manager.", "No interpreter manager was available for attaching to a process.");
}
IInterpreterInfo[] interpreters = interpreterManager.getInterpreterInfos();
if (interpreters == null || interpreters.length == 0) {
MessageDialog.openError(workbenchWindow.getShell(), "No interpreters for creating console", "An interpreter that matches the architecture of the target process must be configured in the interpreter preferences.");
return;
}
SelectionDialog listDialog = AbstractInterpreterPreferencesPage.createChooseIntepreterInfoDialog(workbenchWindow, interpreters, "Select interpreter which matches the architecture of the target process (i.e.: 32/64 bits).", false);
int open = listDialog.open();
if (open != ListDialog.OK || listDialog.getResult().length != 1) {
return;
}
Object[] result = listDialog.getResult();
IInterpreterInfo interpreter;
if (result == null || result.length == 0) {
interpreter = interpreters[0];
} else {
interpreter = ((IInterpreterInfo) result[0]);
}
SimplePythonRunner runner = new SimplePythonRunner();
IPath relative = new Path("pysrc").append("pydevd_attach_to_process").append("attach_pydevd.py");
String script = CorePlugin.getBundleInfo().getRelativePath(relative).getAbsolutePath();
String[] args = new String[] { "--port", "" + DebugPluginPrefsInitializer.getRemoteDebuggerPort(), "--pid", "" + pid, "--protocol", "http" };
IPythonNature nature = new SystemPythonNature(interpreterManager, interpreter);
String[] s = SimplePythonRunner.preparePythonCallParameters(interpreter.getExecutableOrJar(), script, args);
Tuple<Process, String> run = runner.run(s, (File) null, nature, new NullProgressMonitor());
if (run.o1 != null) {
ShowProcessOutputDialog dialog = new ShowProcessOutputDialog(UIUtils.getActiveShell(), run.o1);
dialog.open();
}
}
}
use of org.python.pydev.shared_core.structure.TreeNode in project Pydev by fabioz.
the class SyncSystemModulesManager method createInitialSelectionForDialogConsideringPreviouslyIgnored.
public List<TreeNode> createInitialSelectionForDialogConsideringPreviouslyIgnored(DataAndImageTreeNode root, IEclipsePreferences iPreferenceStore) {
List<TreeNode> initialSelection = new ArrayList<>();
for (DataAndImageTreeNode<IInterpreterInfo> interpreterNode : (List<DataAndImageTreeNode<IInterpreterInfo>>) root.getChildren()) {
IInterpreterInfo info = interpreterNode.getData();
String key = createKeyForInfo(info);
String ignoredValue = iPreferenceStore.get(key, "");
if (ignoredValue != null && ignoredValue.length() > 0) {
Set<String> previouslyIgnored = new HashSet(StringUtils.split(ignoredValue, "|||"));
boolean added = false;
for (TreeNode<PythonpathChange> pathNode : interpreterNode.getChildren()) {
if (!previouslyIgnored.contains(pathNode.data.path)) {
initialSelection.add(pathNode);
added = true;
} else {
if (SyncSystemModulesManager.DEBUG) {
System.out.println("Removed from initial selection: " + pathNode);
}
}
}
if (added) {
initialSelection.add(interpreterNode);
}
} else {
// Node and children all selected initially (nothing ignored).
initialSelection.add(interpreterNode);
initialSelection.addAll(interpreterNode.getChildren());
}
}
if (SyncSystemModulesManager.DEBUG) {
for (TreeNode treeNode : initialSelection) {
System.out.println("Initial selection: " + treeNode.getData());
}
}
return initialSelection;
}
use of org.python.pydev.shared_core.structure.TreeNode in project Pydev by fabioz.
the class SyncSystemModulesManager method computeChanges.
/**
* Given the tree structure we created initially with all the changes (root) and the elements
* that the user selected in the tree (selectElements), return a list of infos updated with the
* proper pythonpath.
*/
private List<IInterpreterInfo> computeChanges(final DataAndImageTreeNode root, List<TreeNode> selectElements) {
List<IInterpreterInfo> changedInfos = new ArrayList<>();
HashSet<TreeNode> set = new HashSet<TreeNode>(selectElements.size());
set.addAll(selectElements);
for (Object n : root.getChildren()) {
DataAndImageTreeNode interpreterNode = (DataAndImageTreeNode) n;
if (set.contains(interpreterNode)) {
IInterpreterInfo info = (IInterpreterInfo) interpreterNode.getData();
List<String> pythonPath = info.getPythonPath();
boolean changed = false;
OrderedSet<String> newPythonPath = new OrderedSet<String>(pythonPath);
for (Object entryNode : interpreterNode.getChildren()) {
DataAndImageTreeNode pythonpathNode = (DataAndImageTreeNode) entryNode;
if (set.contains(pythonpathNode)) {
PythonpathChange change = (PythonpathChange) pythonpathNode.data;
change.apply(newPythonPath);
changed = true;
}
}
if (changed) {
InterpreterInfo copy = (InterpreterInfo) info.makeCopy();
copy.libs.clear();
copy.libs.addAll(newPythonPath);
changedInfos.add(copy);
}
}
}
return changedInfos;
}
use of org.python.pydev.shared_core.structure.TreeNode in project Pydev by fabioz.
the class SyncSystemModulesManager method saveUnselected.
/**
* When the user selects changes in selectElementsInDialog, it's possible that he doesn't check some of the
* proposed changes, thus, in this case, we should save the unselected items in the preferences and the next
* time such a change is proposed, it should appear unchecked (and if all changes are unchecked, we shouldn't
* present the user with a dialog).
*
* @param root this is the initial structure, containing all the proposed changes.
* @param selectedElements this is a structure which will hold only the selected changes.
* @param iPreferenceStore this is the store where we'll keep the selected changes.
*/
public void saveUnselected(DataAndImageTreeNode root, List<TreeNode> selectedElements, IEclipsePreferences iPreferenceStore) {
// root has null data, level 1 has IInterpreterInfo and level 2 has PythonpathChange.
HashSet<TreeNode> selectionSet = new HashSet<>();
if (selectedElements != null && selectedElements.size() > 0) {
selectionSet.addAll(selectedElements);
}
boolean changed = false;
for (DataAndImageTreeNode<IInterpreterInfo> interpreterNode : (List<DataAndImageTreeNode<IInterpreterInfo>>) root.getChildren()) {
Set<TreeNode> addToIgnore = new HashSet<>();
if (!selectionSet.contains(interpreterNode)) {
// ignore all the entries below this interpreter.
addToIgnore.addAll(interpreterNode.getChildren());
} else {
// check each entry and only add the ones not selected.
for (TreeNode<PythonpathChange> pathNode : interpreterNode.getChildren()) {
if (!selectionSet.contains(pathNode)) {
addToIgnore.add(pathNode);
}
}
}
if (addToIgnore.size() > 0) {
IInterpreterInfo info = interpreterNode.getData();
String key = createKeyForInfo(info);
ArrayList<String> addToIgnorePaths = new ArrayList<String>(addToIgnore.size());
for (TreeNode<PythonpathChange> node : addToIgnore) {
PythonpathChange data = node.getData();
addToIgnorePaths.add(data.path);
}
if (DEBUG) {
System.out.println("Setting key: " + key);
System.out.println("Paths ignored: " + addToIgnorePaths);
}
changed = true;
iPreferenceStore.put(key, StringUtils.join("|||", addToIgnorePaths));
}
}
if (changed) {
try {
iPreferenceStore.flush();
} catch (BackingStoreException e) {
Log.log(e);
}
}
}
use of org.python.pydev.shared_core.structure.TreeNode in project Pydev by fabioz.
the class SearchIndexLabelProvider method getImage.
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
*/
@Override
public Image getImage(Object element) {
if (element instanceof TreeNode) {
TreeNode treeNode = (TreeNode) element;
element = treeNode.data;
}
if (element instanceof ICustomLineElement) {
return fLineMatchImage;
}
if (element instanceof ICustomModule) {
return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.PY_FILE_ICON));
}
if (!(element instanceof IResource)) {
return null;
}
IResource resource = (IResource) element;
Image image = fLabelProvider.getImage(resource);
return image;
}
Aggregations