本文整理汇总了Java中org.python.pydev.plugin.nature.PythonNature.getPythonPathNature方法的典型用法代码示例。如果您正苦于以下问题:Java PythonNature.getPythonPathNature方法的具体用法?Java PythonNature.getPythonPathNature怎么用?Java PythonNature.getPythonPathNature使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.python.pydev.plugin.nature.PythonNature
的用法示例。
在下文中一共展示了PythonNature.getPythonPathNature方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResourcePythonPathMap
import org.python.pydev.plugin.nature.PythonNature; //导入方法依赖的package包/类
private static OrderedMap<String, String> getResourcePythonPathMap(
Map<IProject, OrderedMap<String, String>> projectSourcePathMapsCache, IResource resource) {
IProject project = resource.getProject();
OrderedMap<String, String> sourceMap = projectSourcePathMapsCache.get(project);
if (sourceMap == null) {
IPythonPathNature pythonPathNature = PythonNature.getPythonPathNature(project);
// Ignore resources that come from a non-Python project.
if (pythonPathNature == null) {
sourceMap = new OrderedMap<String, String>();
} else {
try {
sourceMap = pythonPathNature
.getProjectSourcePathResolvedToUnresolvedMap();
} catch (CoreException e) {
sourceMap = new OrderedMap<String, String>();
Log.log(e);
}
}
projectSourcePathMapsCache.put(project, sourceMap);
}
return sourceMap;
}
示例2: doActionOnContainer
import org.python.pydev.plugin.nature.PythonNature; //导入方法依赖的package包/类
@Override
protected int doActionOnContainer(IContainer container, IProgressMonitor monitor) {
try {
IProject project = container.getProject();
IPythonPathNature pythonPathNature = PythonNature.getPythonPathNature(project);
if (pythonPathNature == null) {
Log.log("Unable to get PythonNature on project: " + project);
return 0;
}
OrderedMap<String, String> projectSourcePathMap = pythonPathNature
.getProjectSourcePathResolvedToUnresolvedMap();
String pathToRemove = container.getFullPath().toString();
if (projectSourcePathMap.remove(pathToRemove) == null) {
return 0;
}
//Set back the map with the variables, not the one with resolved vars.
pythonPathNature.setProjectSourcePath(StringUtils.join("|", projectSourcePathMap.values()));
PythonNature.getPythonNature(project).rebuildPath();
return 1;
} catch (CoreException e) {
Log.log(IStatus.ERROR, "Unexpected error setting project properties", e);
}
return 0;
}
示例3: getPythonPathFolders
import org.python.pydev.plugin.nature.PythonNature; //导入方法依赖的package包/类
@Override
protected Set<String> getPythonPathFolders() {
PythonNature pythonNature = PythonNature.getPythonNature(project);
IPythonPathNature pythonPathNature = pythonNature.getPythonPathNature();
Set<String> ret = new HashSet<>();
try {
ret.addAll(StringUtils.split(pythonPathNature.getOnlyProjectPythonPathStr(true), "|"));
} catch (CoreException e) {
Log.log(e);
}
return ret;
}
示例4: getFileInProject
import org.python.pydev.plugin.nature.PythonNature; //导入方法依赖的package包/类
@Override
protected IFile getFileInProject(IPath location, IProject project) {
IFile file = super.getFileInProject(location, project);
if (file != null) {
return file;
}
PythonNature nature = PythonNature.getPythonNature(project);
if (nature != null) {
IPythonPathNature pythonPathNature = nature.getPythonPathNature();
try {
//Paths
Set<IResource> projectSourcePathSet = pythonPathNature.getProjectSourcePathFolderSet();
for (IResource iResource : projectSourcePathSet) {
if (iResource instanceof IContainer) {
//I.e.: don't consider zip files
IContainer iContainer = (IContainer) iResource;
file = getFileInContainer(location, iContainer);
if (file != null) {
return file;
}
}
}
} catch (CoreException e) {
Log.log(e);
}
}
return null;
}
示例5: getContainerInProject
import org.python.pydev.plugin.nature.PythonNature; //导入方法依赖的package包/类
@Override
protected IContainer getContainerInProject(IPath location, IProject project) {
IContainer file = super.getContainerInProject(location, project);
if (file != null) {
return file;
}
PythonNature nature = PythonNature.getPythonNature(project);
if (nature != null) {
IPythonPathNature pythonPathNature = nature.getPythonPathNature();
try {
//Paths
Set<IResource> projectSourcePathSet = pythonPathNature.getProjectSourcePathFolderSet();
for (IResource iResource : projectSourcePathSet) {
if (iResource instanceof IContainer) {
//I.e.: don't consider zip files
IContainer iContainer = (IContainer) iResource;
file = getContainerInContainer(location, iContainer);
if (file != null) {
return file;
}
}
}
} catch (CoreException e) {
Log.log(e);
}
}
return null;
}
示例6: doActionOnContainer
import org.python.pydev.plugin.nature.PythonNature; //导入方法依赖的package包/类
@Override
protected int doActionOnContainer(IContainer container, IProgressMonitor monitor) {
try {
IProject project = container.getProject();
IPythonPathNature pythonPathNature = PythonNature.getPythonPathNature(project);
if (pythonPathNature == null) {
Log.log("Unable to get PythonNature on project: " + project);
return 0;
}
OrderedMap<String, String> projectSourcePathMap = pythonPathNature
.getProjectSourcePathResolvedToUnresolvedMap();
String pathToAdd = container.getFullPath().toString();
if (projectSourcePathMap.containsKey(pathToAdd)) {
return 0;
}
pathToAdd = PyStructureConfigHelpers.convertToProjectRelativePath(project.getFullPath().toString(),
pathToAdd);
Collection<String> values = new ArrayList<String>(projectSourcePathMap.values());
values.add(pathToAdd);
pythonPathNature.setProjectSourcePath(StringUtils.join("|", values));
PythonNature.getPythonNature(project).rebuildPath();
return 1;
} catch (CoreException e) {
Log.log(IStatus.ERROR, "Unexpected error setting project properties", e);
}
return 0;
}
示例7: getSrcFolderFromFolder
import org.python.pydev.plugin.nature.PythonNature; //导入方法依赖的package包/类
/**
* @param f
* @return
* @throws CoreException
*/
public String getSrcFolderFromFolder(IFolder f) throws CoreException {
IPythonPathNature nature = PythonNature.getPythonPathNature(f.getProject());
if (nature != null) {
String[] srcPaths = PythonNature.getStrAsStrItems(nature.getProjectSourcePath(true));
String relFolder = f.getFullPath().toString() + "/";
for (String src : srcPaths) {
if (relFolder.startsWith(src + "/")) {
return src;
}
}
}
return null;
}
示例8: checkValidSourceFolder
import org.python.pydev.plugin.nature.PythonNature; //导入方法依赖的package包/类
private String checkValidSourceFolder(String text) throws CoreException {
validatedSourceFolder = null;
if (text == null || text.trim().length() == 0) {
return "The source folder must be filled.";
}
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource resource = root.findMember(new Path(text));
if (resource == null) {
return "The source folder was not found in the workspace.";
}
if (!(resource instanceof IContainer)) {
return "The source folder was found in the workspace but is not a container.";
}
IProject project = resource.getProject();
if (project == null) {
return "Unable to find the project related to the source folder.";
}
IPythonPathNature nature = PythonNature.getPythonPathNature(project);
if (nature == null) {
return "The pydev nature is not configured on the project: " + project.getName();
}
String full = resource.getFullPath().toString();
String[] srcPaths = PythonNature.getStrAsStrItems(nature.getProjectSourcePath(true));
for (String str : srcPaths) {
if (str.equals(full)) {
validatedSourceFolder = (IContainer) resource;
return null;
}
}
return "The selected source folder is not recognized as a valid source folder.";
}
示例9: performOk
import org.python.pydev.plugin.nature.PythonNature; //导入方法依赖的package包/类
/**
* Saves values.
*/
@Override
public boolean performOk() {
try {
IPythonPathNature pythonPathNature = PythonNature.getPythonPathNature(project);
Map<String, String> variableSubstitution = pythonPathNature.getVariableSubstitution(false);
boolean changed = update(DjangoConstants.DJANGO_MANAGE_VARIABLE, variableSubstitution,
textDjangoManage.getText(), pythonPathNature);
changed = update(DjangoConstants.DJANGO_SETTINGS_MODULE, variableSubstitution,
textDjangoSettings.getText(), pythonPathNature) || changed;
if (changed) {
pythonPathNature.setVariableSubstitution(variableSubstitution);
PythonNature pythonNature = PythonNature.getPythonNature(project);
if (pythonNature != null && (changed || pythonNature.getAstManager() == null)) {
pythonNature.rebuildPath();
}
}
} catch (Exception e) {
Log.log(e);
}
return true;
}
示例10: getPythonPathNatureFromObject
import org.python.pydev.plugin.nature.PythonNature; //导入方法依赖的package包/类
public static IPythonPathNature getPythonPathNatureFromObject(Object receiver) {
IResource resource = getResourceFromObject(receiver);
if (resource == null) {
return null;
}
IProject project = resource.getProject();
if (project == null) {
return null;
}
IPythonPathNature nature = PythonNature.getPythonPathNature(project);
return nature;
}
示例11: createContents
import org.python.pydev.plugin.nature.PythonNature; //导入方法依赖的package包/类
/**
* Creates contents given its parent.
*/
@Override
protected Control createContents(Composite p) {
project = (IProject) getElement().getAdapter(IProject.class);
Composite topComp = new Composite(p, SWT.NONE);
GridLayout innerLayout = new GridLayout();
innerLayout.numColumns = 1;
innerLayout.marginHeight = 0;
innerLayout.marginWidth = 0;
topComp.setLayout(innerLayout);
GridData gd = new GridData(GridData.FILL_BOTH);
topComp.setLayoutData(gd);
Label label = new Label(topComp, SWT.None);
label.setText("The final PYTHONPATH used for a launch is composed of the paths\n"
+ "defined here, joined with the paths defined by the selected interpreter.");
tabFolder = new TabFolder(topComp, SWT.None);
gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.verticalAlignment = SWT.FILL;
gd.grabExcessVerticalSpace = true;
gd.grabExcessHorizontalSpace = true;
gd.horizontalSpan = 1;
tabFolder.setLayoutData(gd);
if (project != null) {
try {
IPythonPathNature nature = PythonNature.getPythonPathNature(project);
createTabProjectSourceFolders(nature.getProjectSourcePath(false));
createTabExternalSourceFolders(nature.getProjectExternalSourcePath(false));
tabVariables = new TabVariables(tabFolder, nature.getVariableSubstitution(false));
createRestoreButton(topComp);
} catch (Exception e) {
Log.log(e);
}
}
return topComp;
}
示例12: doIt
import org.python.pydev.plugin.nature.PythonNature; //导入方法依赖的package包/类
/**
* Save the pythonpath - only updates model if asked to.
* @return
*/
private boolean doIt(boolean force) {
if (project != null) {
try {
boolean changed = false;
IPythonPathNature pythonPathNature = PythonNature.getPythonPathNature(project);
String sourcePath = pythonPathNature.getProjectSourcePath(false);
String externalSourcePath = pythonPathNature.getProjectExternalSourcePath(false);
Map<String, String> variableSubstitution = pythonPathNature.getVariableSubstitution(false);
String newSourcePath = StringUtils.leftAndRightTrim(treeSourceFolders.getTreeItemsAsStr(), '|');
String newExternalSourcePath = StringUtils.leftAndRightTrim(treeExternalLibs.getTreeItemsAsStr(), '|');
Map<String, String> newVariableSubstitution = tabVariables.getTreeItemsAsMap();
if (checkIfShouldBeSet(sourcePath, newSourcePath)) {
pythonPathNature.setProjectSourcePath(newSourcePath);
changed = true;
}
if (checkIfShouldBeSet(externalSourcePath, newExternalSourcePath)) {
pythonPathNature.setProjectExternalSourcePath(newExternalSourcePath);
changed = true;
}
if (checkIfShouldBeSet(variableSubstitution, newVariableSubstitution)) {
pythonPathNature.setVariableSubstitution(newVariableSubstitution);
changed = true;
}
PythonNature pythonNature = PythonNature.getPythonNature(project);
if (pythonNature != null && (changed || force || pythonNature.getAstManager() == null)) {
pythonNature.rebuildPath();
}
} catch (Exception e) {
Log.log(IStatus.ERROR, "Unexpected error setting project properties", e);
}
}
return true;
}
示例13: doCreateNew
import org.python.pydev.plugin.nature.PythonNature; //导入方法依赖的package包/类
@Override
protected IFile doCreateNew(IProgressMonitor monitor) throws CoreException {
IProject project = filePage.getValidatedProject();
String name = filePage.getValidatedName();
IPath source = filePage.getSourceToLink();
if (project == null || !project.exists()) {
throw new RuntimeException("The project selected does not exist in the workspace.");
}
IPythonPathNature pathNature = PythonNature.getPythonPathNature(project);
if (pathNature == null) {
IPythonNature nature = PythonNature.addNature(project, monitor, null, null, null, null, null);
pathNature = nature.getPythonPathNature();
if (pathNature == null) {
throw new RuntimeException("Unable to add the nature to the seleted project.");
}
}
if (source == null || !source.toFile().exists()) {
throw new RuntimeException("The source to link to, " + source.toString() + ", does not exist.");
}
IFolder folder = project.getFolder(name);
if (!folder.exists()) {
folder.createLink(source, IResource.BACKGROUND_REFRESH, monitor);
}
String newPath = folder.getFullPath().toString();
String curr = pathNature.getProjectSourcePath(true);
if (curr == null) {
curr = "";
}
if (curr.endsWith("|")) {
curr = curr.substring(0, curr.length() - 1);
}
String newPathRel = PyStructureConfigHelpers.convertToProjectRelativePath(
project.getFullPath().toString(), newPath);
if (curr.length() > 0) {
//there is already some path
Set<String> projectSourcePathSet = pathNature.getProjectSourcePathSet(true);
if (!projectSourcePathSet.contains(newPath)) {
//only add to the path if it doesn't already contain the new path
curr += "|" + newPathRel;
}
} else {
//there is still no other path
curr = newPathRel;
}
pathNature.setProjectSourcePath(curr);
PythonNature.getPythonNature(project).rebuildPath();
return null;
}
示例14: doCreateNew
import org.python.pydev.plugin.nature.PythonNature; //导入方法依赖的package包/类
@Override
protected IFile doCreateNew(IProgressMonitor monitor) throws CoreException {
IProject project = filePage.getValidatedProject();
String name = filePage.getValidatedName();
if (project == null || !project.exists()) {
throw new RuntimeException("The project selected does not exist in the workspace.");
}
IPythonPathNature pathNature = PythonNature.getPythonPathNature(project);
if (pathNature == null) {
IPythonNature nature = PythonNature.addNature(project, monitor, null, null, null, null, null);
pathNature = nature.getPythonPathNature();
if (pathNature == null) {
throw new RuntimeException("Unable to add the nature to the seleted project.");
}
}
IFolder folder = project.getFolder(name);
if (folder.exists()) {
Log.log("Source folder already exists. Nothing new was created");
return null;
}
folder.create(true, true, monitor);
String newPath = folder.getFullPath().toString();
String curr = pathNature.getProjectSourcePath(false);
if (curr == null) {
curr = "";
}
if (curr.endsWith("|")) {
curr = curr.substring(0, curr.length() - 1);
}
String newPathRel = PyStructureConfigHelpers.convertToProjectRelativePath(
project.getFullPath().toString(), newPath);
if (curr.length() > 0) {
//there is already some path
Set<String> projectSourcePathSet = pathNature.getProjectSourcePathSet(true);
if (!projectSourcePathSet.contains(newPath)) {
//only add to the path if it doesn't already contain the new path
curr += "|" + newPathRel;
}
} else {
//there is still no other path
curr = newPathRel;
}
pathNature.setProjectSourcePath(curr);
PythonNature.getPythonNature(project).rebuildPath();
return null;
}