Example usage for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE

List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE.

Prototype

int CPE_SOURCE

To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE.

Click Source Link

Document

Entry kind constant describing a classpath entry identifying a folder containing package fragments with source code to be compiled.

Usage

From source file:com.redhat.ceylon.eclipse.code.preferences.CeylonBuildPathsBlock.java

License:Open Source License

private void fillBuildPathsSetsForComparison(IProject project, Set<String> sourceFoldersFromCeylonConfig,
        Set<String> sourceFoldersFromEclipseProject, Set<String> resourceFoldersFromCeylonConfig,
        Set<String> resourceFoldersFromEclipseProject) {
    CeylonProjectConfig ceylonConfig = CeylonProjectConfig.get(project);
    for (String path : ceylonConfig.getProjectSourceDirectories()) {
        sourceFoldersFromCeylonConfig.add(Path.fromOSString(path).toString());
    }//from  ww w .jav  a  2 s .c om
    for (String path : ceylonConfig.getProjectResourceDirectories()) {
        resourceFoldersFromCeylonConfig.add(Path.fromOSString(path).toString());
    }

    for (CPListElement elem : fClassPathList.getElements()) {
        if (elem.getClasspathEntry().getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath path = null;
            if (elem.getLinkTarget() == null) {
                path = elem.getPath().makeRelativeTo(project.getFullPath());
            } else {
                path = elem.getLinkTarget();
            }
            sourceFoldersFromEclipseProject.add(path.toString());
        }
    }
    for (CPListElement elem : fResourcePathList.getElements()) {
        if (elem.getClasspathEntry().getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath path = null;
            if (elem.getLinkTarget() == null) {
                path = elem.getPath().makeRelativeTo(project.getFullPath());
            } else {
                path = elem.getLinkTarget();
            }
            resourceFoldersFromEclipseProject.add(path.toString());
        }
    }
    if (sourceFoldersFromEclipseProject.isEmpty()) {
        sourceFoldersFromEclipseProject.add(Constants.DEFAULT_SOURCE_DIR);
    }
    if (resourceFoldersFromEclipseProject.isEmpty()) {
        resourceFoldersFromEclipseProject.add(Constants.DEFAULT_RESOURCE_DIR);
    }
}

From source file:com.redhat.ceylon.eclipse.code.preferences.CeylonBuildPathsBlock.java

License:Open Source License

/**
 * Initializes the classpath for the given project. Multiple calls to init are allowed,
 * but all existing settings will be cleared and replace by the given or default paths.
 * @param jproject The java project to configure. Does not have to exist.
 * @param javaOutputLocation The output location to be set in the page. If <code>null</code>
 * is passed, jdt default settings are used, or - if the project is an existing Java project- the
 * output location of the existing project
 * @param classpathEntries The classpath entries to be set in the page. If <code>null</code>
 * is passed, jdt default settings are used, or - if the project is an existing Java project - the
 * classpath entries of the existing project
 *//*w  w  w .ja va 2s .  c om*/
public void init(IJavaProject jproject, IPath javaOutputLocation, IClasspathEntry[] classpathEntries,
        boolean javaCompilationEnabled) {
    fCurrJProject = jproject;
    boolean projectExists = false;
    someFoldersNeedToBeCreated = false;
    final List<CPListElement> newClassPath;
    IProject project = fCurrJProject.getProject();
    projectExists = (project.exists() && project.getFile(".classpath").exists()); //$NON-NLS-1$

    List<String> configSourceDirectories;
    List<String> configResourceDirectories;
    if (projectExists) {
        CeylonProjectConfig config = CeylonProjectConfig.get(project);
        configSourceDirectories = config.getProjectSourceDirectories();
        configResourceDirectories = config.getProjectResourceDirectories();
    } else {
        File configFile = jproject.getProject().getFile(".ceylon/config").getLocation().toFile();
        CeylonConfig ceylonConfig;
        try {
            ceylonConfig = CeylonConfigFinder.DEFAULT.loadConfigFromFile(configFile);
            configSourceDirectories = CeylonProjectConfig.getConfigSourceDirectories(ceylonConfig);
            configResourceDirectories = CeylonProjectConfig.getConfigResourceDirectories(ceylonConfig);
        } catch (IOException e) {
            configSourceDirectories = Collections.emptyList();
            configResourceDirectories = Collections.emptyList();
        }
    }

    IClasspathEntry[] existingEntries = null;
    if (projectExists) {
        if (javaOutputLocation == null) {
            javaOutputLocation = fCurrJProject.readOutputLocation();
        }
        existingEntries = fCurrJProject.readRawClasspath();
        if (classpathEntries == null) {
            classpathEntries = existingEntries;
            //TODO: read existing ceylon output location from classpathEntries
        }
    }
    if (javaOutputLocation == null) {
        javaOutputLocation = getDefaultJavaOutputLocation(jproject);
    }

    if (classpathEntries != null) {
        newClassPath = getCPListElements(classpathEntries, existingEntries);
    } else {
        newClassPath = getDefaultClassPath(jproject);
    }

    Set<String> newFolderNames = new HashSet<>();
    final List<CPListElement> newResourcePath = new ArrayList<CPListElement>();

    if (!configResourceDirectories.isEmpty()) {
        someFoldersNeedToBeCreated = resourcePathsFromStrings(fCurrJProject, configResourceDirectories,
                newFolderNames, newResourcePath);
    } else {
        IFolder defaultResourceFolder = fCurrJProject.getProject().getFolder(DEFAULT_RESOURCE_FOLDER);
        newResourcePath.add(new CPListElement(fCurrJProject, IClasspathEntry.CPE_SOURCE,
                defaultResourceFolder.getFullPath(), defaultResourceFolder));
    }

    List<CPListElement> exportedEntries = new ArrayList<CPListElement>();
    for (int i = 0; i < newClassPath.size(); i++) {
        CPListElement curr = newClassPath.get(i);
        if (curr.isExported() || curr.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            exportedEntries.add(curr);
        }
    }

    fJavaOutputLocationPath = javaOutputLocation.makeRelative();

    // inits the dialog field
    fJavaBuildPathDialogField.setText(fJavaOutputLocationPath.toString());
    fJavaBuildPathDialogField.enableButton(project.exists());
    fClassPathList.setElements(newClassPath);
    fClassPathList.setCheckedElements(exportedEntries);

    if (!projectExists) {
        IPreferenceStore store = PreferenceConstants.getPreferenceStore();
        if (!configSourceDirectories.isEmpty()
                && store.getBoolean(PreferenceConstants.SRCBIN_FOLDERS_IN_NEWPROJ)) {
            updateClassPathsFromConfigFile(configSourceDirectories, newFolderNames);
        }
    }
    fClassPathList.selectFirstElement();

    fResourcePathList.setElements(newResourcePath);
    //        fResourcePathList.setCheckedElements(exportedEntries);

    fResourcePathList.selectFirstElement();

    if (fSourceContainerPage != null) {
        fSourceContainerPage.init(fCurrJProject);
        fResourceContainerPage.init(fCurrJProject);
        fProjectsPage.init(fCurrJProject);
        //            fLibrariesPage.init(fCurrJProject);
    }

    initializeTimeStamps();
    updateUI();
}

From source file:com.redhat.ceylon.eclipse.code.preferences.CeylonBuildPathsBlock.java

License:Open Source License

public static boolean resourcePathsFromStrings(final IJavaProject javaProject,
        List<String> configResourceDirectories, Set<String> newFolderNames,
        final List<CPListElement> newResourcePath) {
    boolean someFoldersNeedToBeCreated = false;
    IProject project = javaProject.getProject();
    for (final String path : configResourceDirectories) {
        final IPath iPath = Path.fromOSString(path);
        if (!iPath.isAbsolute()) {
            IFolder folder = project.getFolder(iPath);
            newResourcePath.add(//from   w  w  w .java  2  s  .  c  o m
                    new CPListElement(javaProject, IClasspathEntry.CPE_SOURCE, folder.getFullPath(), folder));
            if (!folder.exists()) {
                someFoldersNeedToBeCreated = true;
            }
        } else {
            try {
                class CPListElementHolder {
                    public CPListElement value = null;
                }
                final CPListElementHolder cpListElement = new CPListElementHolder();
                project.accept(new IResourceVisitor() {
                    @Override
                    public boolean visit(IResource resource) throws CoreException {
                        if (resource instanceof IFolder && resource.isLinked() && resource.getLocation() != null
                                && resource.getLocation().equals(iPath)) {
                            cpListElement.value = new CPListElement(null, javaProject,
                                    IClasspathEntry.CPE_SOURCE, resource.getFullPath(), resource,
                                    resource.getLocation());
                            return false;
                        }
                        return resource instanceof IFolder || resource instanceof IProject;
                    }
                });
                if (cpListElement.value == null) {
                    String newFolderName = iPath.lastSegment();
                    IFolder newFolder = project.getFolder(newFolderName);
                    int counter = 1;
                    while (newFolderNames.contains(newFolderName) || newFolder.exists()) {
                        newFolderName = iPath.lastSegment() + "_" + counter++;
                        newFolder = project.getFolder(newFolderName);
                    }
                    newFolderNames.add(newFolderName);
                    cpListElement.value = new CPListElement(null, javaProject, IClasspathEntry.CPE_SOURCE,
                            newFolder.getFullPath(), newFolder, iPath);
                    someFoldersNeedToBeCreated = true;
                }
                newResourcePath.add(cpListElement.value);
            } catch (CoreException e) {
                e.printStackTrace();
            }
        }
    }
    return someFoldersNeedToBeCreated;
}

From source file:com.redhat.ceylon.eclipse.code.preferences.CeylonBuildPathsBlock.java

License:Open Source License

private List<CPListElement> getDefaultClassPath(IJavaProject jproj) {
    List<CPListElement> list = new ArrayList<CPListElement>();
    IResource srcFolder;/*from w ww .j  av a2 s .co m*/
    IPreferenceStore store = PreferenceConstants.getPreferenceStore();
    String sourceFolderName = DEFAULT_SOURCE_FOLDER;//store.getString(PreferenceConstants.SRCBIN_SRCNAME);
    if (store.getBoolean(PreferenceConstants.SRCBIN_FOLDERS_IN_NEWPROJ) && sourceFolderName.length() > 0) {
        srcFolder = jproj.getProject().getFolder(sourceFolderName);
    } else {
        srcFolder = jproj.getProject();
    }

    list.add(new CPListElement(jproj, IClasspathEntry.CPE_SOURCE, srcFolder.getFullPath(), srcFolder));

    IClasspathEntry[] jreEntries = PreferenceConstants.getDefaultJRELibrary();
    list.addAll(getCPListElements(jreEntries, null));
    return list;
}

From source file:com.redhat.ceylon.eclipse.code.preferences.CeylonBuildPathsBlock.java

License:Open Source License

/**
 * Validates the build path.//from   w  w w  .j a v a2 s  . co  m
 */
public void updateClassPathStatus() {
    fClassPathStatus.setOK();

    List<CPListElement> elements = fClassPathList.getElements();

    CPListElement entryMissing = null;
    CPListElement entryDeprecated = null;
    int nEntriesMissing = 0;
    IClasspathEntry[] entries = new IClasspathEntry[elements.size()];

    for (int i = elements.size() - 1; i >= 0; i--) {
        CPListElement currElement = elements.get(i);
        boolean isChecked = fClassPathList.isChecked(currElement);
        if (currElement.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            if (!isChecked) {
                fClassPathList.setCheckedWithoutUpdate(currElement, true);
            }
            if (!fClassPathList.isGrayed(currElement)) {
                fClassPathList.setGrayedWithoutUpdate(currElement, true);
            }
        } else {
            currElement.setExported(isChecked);
        }

        entries[i] = currElement.getClasspathEntry();
        if (currElement.isMissing()) {
            nEntriesMissing++;
            if (entryMissing == null) {
                entryMissing = currElement;
            }
        }
        if (entryDeprecated == null & currElement.isDeprecated()) {
            entryDeprecated = currElement;
        }
    }

    if (nEntriesMissing > 0) {
        if (nEntriesMissing == 1) {
            fClassPathStatus.setWarning(Messages.format(NewWizardMessages.BuildPathsBlock_warning_EntryMissing,
                    BasicElementLabels.getPathLabel(entryMissing.getPath(), false)));
        } else {
            fClassPathStatus.setWarning(Messages.format(
                    NewWizardMessages.BuildPathsBlock_warning_EntriesMissing, String.valueOf(nEntriesMissing)));
        }
    } else if (entryDeprecated != null) {
        fClassPathStatus.setInfo(entryDeprecated.getDeprecationMessage());
    }

    /*        if (fCurrJProject.hasClasspathCycle(entries)) {
    fClassPathStatus.setWarning(NewWizardMessages.getString("BuildPathsBlock.warning.CycleInClassPath")); //$NON-NLS-1$
            }
    */
    updateBuildPathStatus();
}

From source file:com.redhat.ceylon.eclipse.code.preferences.CeylonBuildPathsBlock.java

License:Open Source License

/**
 * Sets the configured build path and output location to the given Java project.
 * If the project already exists, only build paths are updated.
 * <p>/*w w w . j  a  v  a 2s. com*/
 * If the classpath contains an Execution Environment entry, the EE's compiler compliance options
 * are used as project-specific options (unless the classpath already contained the same Execution Environment)
 * 
 * @param classPathEntries the new classpath entries (list of {@link CPListElement})
 * @param javaOutputLocation the output location
 * @param javaProject the Java project
 * @param newProjectCompliance compliance to set for a new project, can be <code>null</code>
 * @param monitor a progress monitor, or <code>null</code>
 * @throws CoreException if flushing failed
 * @throws OperationCanceledException if flushing has been cancelled
 */
public static void flush(List<CPListElement> classPathEntries, List<CPListElement> resourcePathEntries,
        IPath javaOutputLocation, IJavaProject javaProject, String newProjectCompliance,
        IProgressMonitor monitor) throws CoreException, OperationCanceledException {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    monitor.setTaskName(NewWizardMessages.BuildPathsBlock_operationdesc_java);
    monitor.beginTask("", classPathEntries.size() * 4 + 4); //$NON-NLS-1$
    try {
        IProject project = javaProject.getProject();
        IPath projPath = project.getFullPath();

        IPath oldOutputLocation;
        try {
            oldOutputLocation = javaProject.getOutputLocation();
        } catch (CoreException e) {
            oldOutputLocation = projPath.append(
                    PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_BINNAME));
        }

        if (oldOutputLocation.equals(projPath) && !javaOutputLocation.equals(projPath)) {
            if (CeylonBuildPathsBlock.hasClassfiles(project)) {
                if (CeylonBuildPathsBlock.getRemoveOldBinariesQuery(JavaPlugin.getActiveWorkbenchShell())
                        .doQuery(false, projPath)) {
                    CeylonBuildPathsBlock.removeOldClassfiles(project);
                }
            }
        } else if (!javaOutputLocation.equals(oldOutputLocation)) {
            IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(oldOutputLocation);
            if (folder.exists()) {
                if (folder.members().length == 0) {
                    CeylonBuildPathsBlock.removeOldClassfiles(folder);
                } else {
                    if (CeylonBuildPathsBlock.getRemoveOldBinariesQuery(JavaPlugin.getActiveWorkbenchShell())
                            .doQuery(folder.isDerived(), oldOutputLocation)) {
                        CeylonBuildPathsBlock.removeOldClassfiles(folder);
                    }
                }
            }
        }

        getCeylonModulesOutputFolder(project).delete(true, monitor);

        monitor.worked(1);

        IWorkspaceRoot fWorkspaceRoot = JavaPlugin.getWorkspace().getRoot();

        //create and set the output path first
        if (!fWorkspaceRoot.exists(javaOutputLocation)) {
            CoreUtility.createDerivedFolder(fWorkspaceRoot.getFolder(javaOutputLocation), true, true,
                    new SubProgressMonitor(monitor, 1));
        } else {
            monitor.worked(1);
        }
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }

        for (Iterator<CPListElement> iter = resourcePathEntries.iterator(); iter.hasNext();) {
            CPListElement entry = iter.next();
            IResource res = entry.getResource();
            //1 tick
            if (res instanceof IFolder && entry.getLinkTarget() == null && !res.exists()) {
                CoreUtility.createFolder((IFolder) res, true, true, new SubProgressMonitor(monitor, 1));
            } else {
                monitor.worked(1);
            }

            //3 ticks
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath folderOutput = (IPath) entry.getAttribute(CPListElement.OUTPUT);
                if (folderOutput != null && folderOutput.segmentCount() > 1) {
                    IFolder folder = fWorkspaceRoot.getFolder(folderOutput);
                    CoreUtility.createDerivedFolder(folder, true, true, new SubProgressMonitor(monitor, 1));
                } else {
                    monitor.worked(1);
                }

                IPath path = entry.getPath();
                if (projPath.equals(path)) {
                    monitor.worked(2);
                    continue;
                }

                if (projPath.isPrefixOf(path)) {
                    path = path.removeFirstSegments(projPath.segmentCount());
                }
                IFolder folder = project.getFolder(path);
                IPath orginalPath = entry.getOrginalPath();
                if (orginalPath == null) {
                    if (!folder.exists()) {
                        //New source folder needs to be created
                        if (entry.getLinkTarget() == null) {
                            CoreUtility.createFolder(folder, true, true, new SubProgressMonitor(monitor, 2));
                        } else {
                            folder.createLink(entry.getLinkTarget(), IResource.ALLOW_MISSING_LOCAL,
                                    new SubProgressMonitor(monitor, 2));
                        }
                    }
                } else {
                    if (projPath.isPrefixOf(orginalPath)) {
                        orginalPath = orginalPath.removeFirstSegments(projPath.segmentCount());
                    }
                    IFolder orginalFolder = project.getFolder(orginalPath);
                    if (entry.getLinkTarget() == null) {
                        if (!folder.exists()) {
                            //Source folder was edited, move to new location
                            IPath parentPath = entry.getPath().removeLastSegments(1);
                            if (projPath.isPrefixOf(parentPath)) {
                                parentPath = parentPath.removeFirstSegments(projPath.segmentCount());
                            }
                            if (parentPath.segmentCount() > 0) {
                                IFolder parentFolder = project.getFolder(parentPath);
                                if (!parentFolder.exists()) {
                                    CoreUtility.createFolder(parentFolder, true, true,
                                            new SubProgressMonitor(monitor, 1));
                                } else {
                                    monitor.worked(1);
                                }
                            } else {
                                monitor.worked(1);
                            }
                            orginalFolder.move(entry.getPath(), true, true, new SubProgressMonitor(monitor, 1));
                        }
                    } else {
                        if (!folder.exists() || !entry.getLinkTarget().equals(entry.getOrginalLinkTarget())) {
                            orginalFolder.delete(true, new SubProgressMonitor(monitor, 1));
                            folder.createLink(entry.getLinkTarget(), IResource.ALLOW_MISSING_LOCAL,
                                    new SubProgressMonitor(monitor, 1));
                        }
                    }
                }
            }
            if (monitor.isCanceled()) {
                throw new OperationCanceledException();
            }
        }

        int nEntries = classPathEntries.size();
        IClasspathEntry[] classpath = new IClasspathEntry[nEntries];
        int i = 0;

        for (Iterator<CPListElement> iter = classPathEntries.iterator(); iter.hasNext();) {
            CPListElement entry = iter.next();
            classpath[i] = entry.getClasspathEntry();
            i++;

            IResource res = entry.getResource();
            //1 tick
            if (res instanceof IFolder && entry.getLinkTarget() == null && !res.exists()) {
                CoreUtility.createFolder((IFolder) res, true, true, new SubProgressMonitor(monitor, 1));
            } else {
                monitor.worked(1);
            }

            //3 ticks
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath folderOutput = (IPath) entry.getAttribute(CPListElement.OUTPUT);
                if (folderOutput != null && folderOutput.segmentCount() > 1) {
                    IFolder folder = fWorkspaceRoot.getFolder(folderOutput);
                    CoreUtility.createDerivedFolder(folder, true, true, new SubProgressMonitor(monitor, 1));
                } else {
                    monitor.worked(1);
                }

                IPath path = entry.getPath();
                if (projPath.equals(path)) {
                    monitor.worked(2);
                    continue;
                }

                if (projPath.isPrefixOf(path)) {
                    path = path.removeFirstSegments(projPath.segmentCount());
                }
                IFolder folder = project.getFolder(path);
                IPath orginalPath = entry.getOrginalPath();
                if (orginalPath == null) {
                    if (!folder.exists()) {
                        //New source folder needs to be created
                        if (entry.getLinkTarget() == null) {
                            CoreUtility.createFolder(folder, true, true, new SubProgressMonitor(monitor, 2));
                        } else {
                            folder.createLink(entry.getLinkTarget(), IResource.ALLOW_MISSING_LOCAL,
                                    new SubProgressMonitor(monitor, 2));
                        }
                    }
                } else {
                    if (projPath.isPrefixOf(orginalPath)) {
                        orginalPath = orginalPath.removeFirstSegments(projPath.segmentCount());
                    }
                    IFolder orginalFolder = project.getFolder(orginalPath);
                    if (entry.getLinkTarget() == null) {
                        if (!folder.exists()) {
                            //Source folder was edited, move to new location
                            IPath parentPath = entry.getPath().removeLastSegments(1);
                            if (projPath.isPrefixOf(parentPath)) {
                                parentPath = parentPath.removeFirstSegments(projPath.segmentCount());
                            }
                            if (parentPath.segmentCount() > 0) {
                                IFolder parentFolder = project.getFolder(parentPath);
                                if (!parentFolder.exists()) {
                                    CoreUtility.createFolder(parentFolder, true, true,
                                            new SubProgressMonitor(monitor, 1));
                                } else {
                                    monitor.worked(1);
                                }
                            } else {
                                monitor.worked(1);
                            }
                            orginalFolder.move(entry.getPath(), true, true, new SubProgressMonitor(monitor, 1));
                        }
                    } else {
                        if (!folder.exists() || !entry.getLinkTarget().equals(entry.getOrginalLinkTarget())) {
                            orginalFolder.delete(true, new SubProgressMonitor(monitor, 1));
                            folder.createLink(entry.getLinkTarget(), IResource.ALLOW_MISSING_LOCAL,
                                    new SubProgressMonitor(monitor, 1));
                        }
                    }
                }
            } else {
                if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                    IPath path = entry.getPath();
                    if (!path.equals(entry.getOrginalPath())) {
                        String eeID = JavaRuntime.getExecutionEnvironmentId(path);
                        if (eeID != null) {
                            BuildPathSupport.setEEComplianceOptions(javaProject, eeID, newProjectCompliance);
                            newProjectCompliance = null; // don't set it again below
                        }
                    }
                    if (newProjectCompliance != null) {
                        setOptionsFromJavaProject(javaProject, newProjectCompliance);
                    }
                }
                monitor.worked(3);
            }
            if (monitor.isCanceled()) {
                throw new OperationCanceledException();
            }
        }

        javaProject.setRawClasspath(classpath, javaOutputLocation, new SubProgressMonitor(monitor, 2));

        CeylonProjectConfig config = CeylonProjectConfig.get(project);
        List<String> srcDirs = new ArrayList<String>();
        for (CPListElement cpe : classPathEntries) {
            if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                srcDirs.add(configFilePath(project, cpe));
            }
        }
        config.setProjectSourceDirectories(srcDirs);
        List<String> rsrcDirs = new ArrayList<String>();
        for (CPListElement cpe : resourcePathEntries) {
            rsrcDirs.add(configFilePath(project, cpe));
        }
        config.setProjectResourceDirectories(rsrcDirs);
        config.save();

    } finally {
        monitor.done();
    }

}

From source file:com.redhat.ceylon.eclipse.code.preferences.CeylonBuildPathsBlock.java

License:Open Source License

private int getPageIndex(int entryKind) {
    switch (entryKind) {
    case IClasspathEntry.CPE_CONTAINER:
    case IClasspathEntry.CPE_LIBRARY:
    case IClasspathEntry.CPE_VARIABLE:
        return 2;
    case IClasspathEntry.CPE_PROJECT:
        return 1;
    case IClasspathEntry.CPE_SOURCE:
        return 0;
    }/*from   w  w  w  .j av  a 2  s . com*/
    return 0;
}

From source file:com.redhat.ceylon.eclipse.code.preferences.CeylonBuildPathsBlock.java

License:Open Source License

private void updateClassPathsFromConfigFile(List<String> sourceDirectories, final Set<String> newFolderNames) {
    final IProject project = fCurrJProject.getProject();
    final List<CPListElement> newSourcePath = new ArrayList<CPListElement>();
    for (final String path : sourceDirectories) {
        final IPath iPath = Path.fromOSString(path);
        if (!iPath.isAbsolute()) {
            IFolder folder = project.getFolder(iPath);
            newSourcePath.add(/*from w w  w  . ja  va  2s  .c o m*/
                    new CPListElement(fCurrJProject, IClasspathEntry.CPE_SOURCE, folder.getFullPath(), folder));
            if (!folder.exists()) {
                someFoldersNeedToBeCreated = true;
            }
        } else {
            try {
                class CPListElementHolder {
                    public CPListElement value = null;
                }
                final CPListElementHolder cpListElement = new CPListElementHolder();
                project.accept(new IResourceVisitor() {
                    @Override
                    public boolean visit(IResource resource) throws CoreException {
                        if (resource instanceof IFolder && resource.isLinked() && resource.getLocation() != null
                                && resource.getLocation().equals(iPath)) {
                            cpListElement.value = new CPListElement(null, fCurrJProject,
                                    IClasspathEntry.CPE_SOURCE, resource.getFullPath(), resource,
                                    resource.getLocation());
                            return false;
                        }
                        return resource instanceof IFolder || resource instanceof IProject;
                    }
                });
                if (cpListElement.value == null) {
                    String newFolderName = iPath.lastSegment();
                    IFolder newFolder = project.getFolder(newFolderName);
                    int counter = 1;
                    while (newFolderNames.contains(newFolderName) || newFolder.exists()) {
                        newFolderName = iPath.lastSegment() + "_" + counter++;
                        newFolder = project.getFolder(newFolderName);
                    }
                    newFolderNames.add(newFolderName);
                    cpListElement.value = new CPListElement(null, fCurrJProject, IClasspathEntry.CPE_SOURCE,
                            newFolder.getFullPath(), newFolder, iPath);
                    someFoldersNeedToBeCreated = true;
                }
                newSourcePath.add(cpListElement.value);
            } catch (CoreException ex) {
                ex.printStackTrace();
            }
        }
    }
    ArrayList<CPListElement> exportedEntries = new ArrayList<>();
    ArrayList<CPListElement> newClassPath = new ArrayList<>();
    // Don't change all the non-source classpath entries
    for (CPListElement elem : fClassPathList.getElements()) {
        if (elem.getClasspathEntry().getEntryKind() != IClasspathEntry.CPE_SOURCE) {
            newClassPath.add(elem);
        }
    }
    for (CPListElement elem : fClassPathList.getCheckedElements()) {
        if (elem.getClasspathEntry().getEntryKind() != IClasspathEntry.CPE_SOURCE) {
            exportedEntries.add(elem);
        }
    }

    // Now all the new source entries
    newClassPath.addAll(newSourcePath);

    for (CPListElement elem : fClassPathList.getCheckedElements()) {
        if (newSourcePath.contains(elem)) {
            exportedEntries.add(elem);
        }
    }

    fClassPathList.setElements(newClassPath);
    fClassPathList.setCheckedElements(exportedEntries);
    fClassPathList.selectFirstElement();
}

From source file:com.redhat.ceylon.eclipse.code.preferences.ResourceContainerWorkbookPage.java

License:Open Source License

private void updateFoldersList() {
    if (fSWTControl == null || fSWTControl.isDisposed()) {
        return;// www .  j  a va 2 s.  co  m
    }

    ArrayList<CPListElement> folders = new ArrayList<CPListElement>();

    //        boolean useFolderOutputs= false;
    List<CPListElement> cpelements = fClassPathList.getElements();
    for (int i = 0; i < cpelements.size(); i++) {
        CPListElement cpe = cpelements.get(i);
        if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            folders.add(cpe);
            //                boolean hasOutputFolder= cpe.getAttribute(CPListElement.OUTPUT)!=null;
            //                if (hasOutputFolder) {
            //                    useFolderOutputs= true;
            //                }

        }
    }
    fFoldersList.setElements(folders);
    //        fUseFolderOutputs.setSelection(useFolderOutputs);

    //        for (int i= 0; i < folders.size(); i++) {
    //            CPListElement cpe= folders.get(i);
    //            IPath[] ePatterns= (IPath[]) cpe.getAttribute(CPListElement.EXCLUSION);
    //            IPath[] iPatterns= (IPath[])cpe.getAttribute(CPListElement.INCLUSION);
    //            boolean hasOutputFolder= cpe.getAttribute(CPListElement.OUTPUT)!=null;
    //            if (ePatterns.length > 0 || iPatterns.length > 0 || hasOutputFolder) {
    //                fFoldersList.expandElement(cpe, 3);
    //            }
    //        }
}

From source file:com.redhat.ceylon.eclipse.code.preferences.ResourceContainerWorkbookPage.java

License:Open Source License

protected void sourcePageCustomButtonPressed(DialogField field, int index) {
    if (field == fFoldersList) {
        if (index == IDX_ADD) {
            IProject project = fCurrJProject.getProject();
            if (project.isAccessible() && hasFolders(project)) {
                List<CPListElement> existingElements = fFoldersList.getElements();
                CPListElement[] existing = existingElements.toArray(new CPListElement[existingElements.size()]);
                CreateMultipleResourceFoldersDialog dialog = new CreateMultipleResourceFoldersDialog(
                        fCurrJProject, existing, fJavaOutputLocationField.getText(), "Resource",
                        NEW_FOLDER_ICON, getShell());
                if (dialog.open() == Window.OK) {
                    refresh(dialog.getInsertedElements(), dialog.getRemovedElements(),
                            dialog.getModifiedElements(), dialog.getOutputLocation());
                }/*from  ww  w. j a v  a2  s  .  c  o  m*/
            } else {
                CPListElement newElement = new CPListElement(fCurrJProject, IClasspathEntry.CPE_SOURCE);
                AddResourceFolderWizard wizard = newResourceFolderWizard(newElement, fFoldersList.getElements(),
                        fJavaOutputLocationField.getText(), true);
                OpenBuildPathWizardAction action = new OpenBuildPathWizardAction(wizard);
                action.run();
            }
        } else if (index == IDX_ADD_LINK) {
            CPListElement newElement = new CPListElement(fCurrJProject, IClasspathEntry.CPE_SOURCE);
            AddResourceFolderWizard wizard = newLinkedResourceFolderWizard(newElement,
                    fFoldersList.getElements(), fJavaOutputLocationField.getText(), true);
            OpenBuildPathWizardAction action = new OpenBuildPathWizardAction(wizard);
            action.run();
        } else if (index == IDX_EDIT/*||index == IDX_TOGGLE*/) {
            editEntry();
        } else if (index == IDX_REMOVE) {
            removeEntry();
        }
    }
}