Search in sources :

Example 1 with IPythonPathNature

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;
}
Also used : IPythonPathNature(org.python.pydev.core.IPythonPathNature) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Example 2 with IPythonPathNature

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]);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IPythonPathNature(org.python.pydev.core.IPythonPathNature) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IWizardContainer(org.eclipse.jface.wizard.IWizardContainer) Shell(org.eclipse.swt.widgets.Shell) NewProjectNameAndLocationWizardPage(org.python.pydev.ui.wizards.project.NewProjectNameAndLocationWizardPage) Composite(org.eclipse.swt.widgets.Composite) PythonNature(org.python.pydev.plugin.nature.PythonNature) FillLayout(org.eclipse.swt.layout.FillLayout) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IWizardPage(org.eclipse.jface.wizard.IWizardPage) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) Display(org.eclipse.swt.widgets.Display)

Example 3 with IPythonPathNature

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;
}
Also used : PythonPackageSelectionDialog(org.python.pydev.ui.dialogs.PythonPackageSelectionDialog) IAdaptable(org.eclipse.core.runtime.IAdaptable) IFile(org.eclipse.core.resources.IFile) Label(org.eclipse.swt.widgets.Label) IPythonPathNature(org.python.pydev.core.IPythonPathNature) Text(org.eclipse.swt.widgets.Text) CoreException(org.eclipse.core.runtime.CoreException) IProject(org.eclipse.core.resources.IProject) SourceFolder(org.python.pydev.ui.dialogs.SourceFolder) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener) IFolder(org.eclipse.core.resources.IFolder)

Example 4 with IPythonPathNature

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;
}
Also used : IPythonPathNature(org.python.pydev.core.IPythonPathNature)

Example 5 with IPythonPathNature

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];
}
Also used : Path(org.eclipse.core.runtime.Path) PythonNature(org.python.pydev.plugin.nature.PythonNature) ArrayList(java.util.ArrayList) IPythonPathNature(org.python.pydev.core.IPythonPathNature) IProject(org.eclipse.core.resources.IProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IPythonPathNature (org.python.pydev.core.IPythonPathNature)26 IProject (org.eclipse.core.resources.IProject)15 CoreException (org.eclipse.core.runtime.CoreException)10 PythonNature (org.python.pydev.plugin.nature.PythonNature)9 IPythonNature (org.python.pydev.core.IPythonNature)7 ArrayList (java.util.ArrayList)5 IFile (org.eclipse.core.resources.IFile)5 IFolder (org.eclipse.core.resources.IFolder)5 IResource (org.eclipse.core.resources.IResource)5 Path (org.eclipse.core.runtime.Path)5 File (java.io.File)3 IContainer (org.eclipse.core.resources.IContainer)3 IPath (org.eclipse.core.runtime.IPath)3 Composite (org.eclipse.swt.widgets.Composite)3 Label (org.eclipse.swt.widgets.Label)3 HashMap (java.util.HashMap)2 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Shell (org.eclipse.swt.widgets.Shell)2