use of org.python.pydev.core.IPythonPathNature in project Pydev by fabioz.
the class CustomizationCommons method getPythonPathNatureFromObject.
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;
}
use of org.python.pydev.core.IPythonPathNature in project Pydev by fabioz.
the class AppEngineConfigWizardPageTestWorkbench method testCreateLaunchAndDebugGoogleAppProject.
public void testCreateLaunchAndDebugGoogleAppProject() throws Exception {
final Display display = Display.getDefault();
final Boolean[] executed = new Boolean[] { false };
display.syncExec(new Runnable() {
@Override
public void run() {
final Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
Composite pageContainer = new Composite(shell, 0);
AppEngineWizard appEngineWizard = new AppEngineWizard();
appEngineWizard.setContainer(new IWizardContainer() {
@Override
public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException {
runnable.run(new NullProgressMonitor());
}
@Override
public void updateWindowTitle() {
throw new RuntimeException("Not implemented");
}
@Override
public void updateTitleBar() {
throw new RuntimeException("Not implemented");
}
@Override
public void updateMessage() {
throw new RuntimeException("Not implemented");
}
@Override
public void updateButtons() {
throw new RuntimeException("Not implemented");
}
@Override
public void showPage(IWizardPage page) {
throw new RuntimeException("Not implemented");
}
@Override
public Shell getShell() {
throw new RuntimeException("Not implemented");
}
@Override
public IWizardPage getCurrentPage() {
return null;
}
});
appEngineWizard.init(PlatformUI.getWorkbench(), new StructuredSelection());
appEngineWizard.addPages();
appEngineWizard.createPageControls(pageContainer);
IWizardPage[] pages = appEngineWizard.getPages();
NewProjectNameAndLocationWizardPage nameAndLocation = (NewProjectNameAndLocationWizardPage) pages[0];
AppEngineConfigWizardPage appEnginePage = (AppEngineConfigWizardPage) pages[1];
assertFalse(nameAndLocation.isPageComplete());
nameAndLocation.setProjectName("AppEngineTest");
assertTrue(nameAndLocation.isPageComplete());
assertFalse(appEnginePage.isPageComplete());
appEnginePage.setAppEngineLocationFieldValue(TestDependent.GOOGLE_APP_ENGINE_LOCATION + "invalid_path_xxx");
assertFalse(appEnginePage.isPageComplete());
appEnginePage.setAppEngineLocationFieldValue(TestDependent.GOOGLE_APP_ENGINE_LOCATION);
assertTrue(appEnginePage.isPageComplete());
assertTrue(appEngineWizard.performFinish());
IProject createdProject = appEngineWizard.getCreatedProject();
PythonNature nature = PythonNature.getPythonNature(createdProject);
Map<String, String> expected = new HashMap<String, String>();
expected.put(AppEngineConstants.GOOGLE_APP_ENGINE_VARIABLE, new File(TestDependent.GOOGLE_APP_ENGINE_LOCATION).getAbsolutePath());
IPythonPathNature pythonPathNature = nature.getPythonPathNature();
try {
assertEquals(expected, pythonPathNature.getVariableSubstitution());
String projectExternalSourcePath = pythonPathNature.getProjectExternalSourcePath(false);
assertTrue(projectExternalSourcePath.indexOf(AppEngineConstants.GOOGLE_APP_ENGINE_VARIABLE) != -1);
projectExternalSourcePath = pythonPathNature.getProjectExternalSourcePath(true);
assertTrue(projectExternalSourcePath.indexOf(AppEngineConstants.GOOGLE_APP_ENGINE_VARIABLE) == -1);
} catch (Exception e) {
throw new RuntimeException(e);
}
// goToManual();
executed[0] = true;
}
});
assertTrue(executed[0]);
}
use of org.python.pydev.core.IPythonPathNature in project Pydev by fabioz.
the class AbstractPythonWizardPage method createSourceFolderSelect.
/**
* @param topLevel
* @return
*/
private boolean createSourceFolderSelect(Composite topLevel) {
Label label;
label = new Label(topLevel, SWT.NONE);
label.setText("Source Folder");
textSourceFolder = new Text(topLevel, SWT.BORDER);
textSourceFolder.addKeyListener(this);
btBrowseSourceFolder = new Button(topLevel, SWT.NONE);
setLayout(label, textSourceFolder, btBrowseSourceFolder);
btBrowseSourceFolder.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
try {
PythonPackageSelectionDialog dialog = new PythonPackageSelectionDialog(getShell(), true);
dialog.setTitle("Source folder selection");
dialog.setMessage("Select a source folder.");
dialog.open();
Object firstResult = dialog.getFirstResult();
if (firstResult instanceof SourceFolder) {
SourceFolder f = (SourceFolder) firstResult;
textSourceFolder.setText(f.folder.getFullPath().toString());
}
} catch (Exception e1) {
Log.log(e1);
}
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
Object element = selection.getFirstElement();
try {
if (element instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) element;
element = adaptable.getAdapter(IFile.class);
if (element == null) {
element = adaptable.getAdapter(IProject.class);
}
if (element == null) {
element = adaptable.getAdapter(IFolder.class);
}
}
if (element instanceof IFile) {
IFile f = (IFile) element;
element = f.getParent();
}
if (element instanceof IProject) {
IPythonPathNature nature = PythonNature.getPythonPathNature((IProject) element);
if (nature != null) {
String[] srcPaths = PythonNature.getStrAsStrItems(nature.getProjectSourcePath(true));
if (srcPaths.length > 0) {
textSourceFolder.setText(srcPaths[0]);
return true;
}
}
}
if (element instanceof IFolder) {
IFolder f = (IFolder) element;
String srcPath = getSrcFolderFromFolder(f);
if (srcPath == null) {
return true;
}
textSourceFolder.setText(srcPath);
return true;
}
} catch (Exception e) {
Log.log(e);
}
return false;
}
use of org.python.pydev.core.IPythonPathNature in project Pydev by fabioz.
the class AbstractPythonWizardPage method getSrcFolderFromFolder.
/**
* @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;
}
use of org.python.pydev.core.IPythonPathNature in project Pydev by fabioz.
the class PackageContentProvider method getChildren.
@Override
public Object[] getChildren(Object parentElement) {
// workspace root
if (parentElement instanceof IWorkspaceRoot) {
this.workspaceRoot = (IWorkspaceRoot) parentElement;
List<IProject> ret = new ArrayList<IProject>();
IProject[] projects = workspaceRoot.getProjects();
for (IProject project : projects) {
PythonNature nature = PythonNature.getPythonNature(project);
if (nature != null) {
ret.add(project);
}
}
return ret.toArray(new IProject[0]);
}
// project
if (parentElement instanceof IProject) {
List<Object> ret = new ArrayList<Object>();
IProject project = (IProject) parentElement;
IPythonPathNature nature = PythonNature.getPythonPathNature(project);
if (nature != null) {
try {
String[] srcPaths = PythonNature.getStrAsStrItems(nature.getProjectSourcePath(true));
for (String str : srcPaths) {
IResource resource = this.workspaceRoot.findMember(new Path(str));
if (resource instanceof IFolder) {
IFolder folder = (IFolder) resource;
if (folder.exists()) {
if (folder != null) {
ret.add(new SourceFolder(folder));
}
}
}
if (resource instanceof IProject) {
IProject folder = (IProject) resource;
if (folder.exists()) {
if (folder != null) {
ret.add(new SourceFolder(folder));
}
}
}
}
return ret.toArray();
} catch (CoreException e) {
Log.log(e);
}
}
}
// source folder
SourceFolder sourceFolder = null;
if (parentElement instanceof SourceFolder) {
sourceFolder = (SourceFolder) parentElement;
parentElement = ((SourceFolder) parentElement).folder;
}
// package
if (parentElement instanceof Package) {
sourceFolder = ((Package) parentElement).sourceFolder;
parentElement = ((Package) parentElement).folder;
}
if (parentElement instanceof IFolder) {
IFolder f = (IFolder) parentElement;
ArrayList<Package> ret = new ArrayList<Package>();
try {
IResource[] resources = f.members();
for (IResource resource : resources) {
if (resource instanceof IFolder) {
ret.add(new Package((IFolder) resource, sourceFolder));
}
}
} catch (CoreException e) {
Log.log(e);
}
return ret.toArray();
}
return new Object[0];
}
Aggregations