Search in sources :

Example 31 with IContainer

use of org.eclipse.core.resources.IContainer in project generator by mybatis.

the class ConfigurationComposite method getViewerFilter.

@Override
protected ViewerFilter getViewerFilter() {
    return new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (element instanceof IContainer) {
                return true;
            }
            if (element instanceof IFile) {
                IFile file = (IFile) element;
                ConfigVerifyer cv = new ConfigVerifyer(file);
                return cv.isConfigurationFile();
            }
            return false;
        }
    };
}
Also used : IFile(org.eclipse.core.resources.IFile) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Viewer(org.eclipse.jface.viewers.Viewer) ConfigVerifyer(org.mybatis.generator.eclipse.ui.content.ConfigVerifyer) IContainer(org.eclipse.core.resources.IContainer)

Example 32 with IContainer

use of org.eclipse.core.resources.IContainer in project che by eclipse.

the class JavaProjectHelper method addClassFolder.

/**
     * Creates and adds a class folder to the class path.
     * @param jproject The parent project
     * @param containerName
     * @param sourceAttachPath The source attachment path
     * @param sourceAttachRoot The source attachment root path
     * @return The handle of the created root
     * @throws CoreException
     */
public static IPackageFragmentRoot addClassFolder(IJavaProject jproject, String containerName, IPath sourceAttachPath, IPath sourceAttachRoot) throws CoreException {
    IProject project = jproject.getProject();
    IContainer container = null;
    if (containerName == null || containerName.length() == 0) {
        container = project;
    } else {
        IFolder folder = project.getFolder(containerName);
        if (!folder.exists()) {
            CoreUtility.createFolder(folder, false, true, null);
        }
        container = folder;
    }
    IClasspathEntry cpe = JavaCore.newLibraryEntry(container.getFullPath(), sourceAttachPath, sourceAttachRoot);
    addToClasspath(jproject, cpe);
    return jproject.getPackageFragmentRoot(container);
}
Also used : IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IContainer(org.eclipse.core.resources.IContainer) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 33 with IContainer

use of org.eclipse.core.resources.IContainer in project che by eclipse.

the class JavaModelOperation method deleteEmptyPackageFragment.

/**
	 * Convenience method to delete an empty package fragment
	 */
protected void deleteEmptyPackageFragment(IPackageFragment fragment, boolean forceFlag, IResource rootResource) throws JavaModelException {
    IContainer resource = (IContainer) ((JavaElement) fragment).resource();
    try {
        resource.delete(forceFlag ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY, getSubProgressMonitor(1));
        setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
        while (resource instanceof IFolder) {
            // deleting a package: delete the parent if it is empty (e.g. deleting x.y where folder x doesn't have resources but y)
            // without deleting the package fragment root
            resource = resource.getParent();
            if (!resource.equals(rootResource) && resource.members().length == 0) {
                resource.delete(forceFlag ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY, getSubProgressMonitor(1));
                setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
            }
        }
    } catch (CoreException e) {
        throw new JavaModelException(e);
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) IContainer(org.eclipse.core.resources.IContainer) IFolder(org.eclipse.core.resources.IFolder)

Example 34 with IContainer

use of org.eclipse.core.resources.IContainer in project che by eclipse.

the class JavaElementResourceMapping method getPackageFragmentTraversals.

private static ResourceTraversal[] getPackageFragmentTraversals(IPackageFragment pack) throws CoreException {
    ArrayList<ResourceTraversal> res = new ArrayList<ResourceTraversal>();
    IContainer container = (IContainer) pack.getResource();
    if (container != null) {
        res.add(new ResourceTraversal(new IResource[] { container }, IResource.DEPTH_ONE, 0));
        if (pack.exists()) {
            // folder may not exist any more, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=269167
            Object[] nonJavaResources = pack.getNonJavaResources();
            for (int i = 0; i < nonJavaResources.length; i++) {
                Object resource = nonJavaResources[i];
                if (resource instanceof IFolder) {
                    res.add(new ResourceTraversal(new IResource[] { (IResource) resource }, IResource.DEPTH_INFINITE, 0));
                }
            }
        }
    }
    return res.toArray(new ResourceTraversal[res.size()]);
}
Also used : ResourceTraversal(org.eclipse.core.resources.mapping.ResourceTraversal) ArrayList(java.util.ArrayList) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 35 with IContainer

use of org.eclipse.core.resources.IContainer in project che by eclipse.

the class JavaElementResourceMapping method getRemotePackageFragmentTraversals.

private static ResourceTraversal[] getRemotePackageFragmentTraversals(IPackageFragment pack, RemoteResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
    ArrayList<ResourceTraversal> res = new ArrayList<ResourceTraversal>();
    IContainer container = (IContainer) pack.getResource();
    if (container != null) {
        res.add(new ResourceTraversal(new IResource[] { container }, IResource.DEPTH_ONE, 0));
        IResource[] remoteMembers = context.fetchRemoteMembers(container, monitor);
        if (remoteMembers == null) {
            remoteMembers = context.fetchMembers(container, monitor);
        }
        if (remoteMembers != null) {
            for (int i = 0; i < remoteMembers.length; i++) {
                IResource member = remoteMembers[i];
                if (member instanceof IFolder && JavaConventionsUtil.validatePackageName(member.getName(), pack).getSeverity() == IStatus.ERROR) {
                    res.add(new ResourceTraversal(new IResource[] { member }, IResource.DEPTH_INFINITE, 0));
                }
            }
        }
    }
    return res.toArray(new ResourceTraversal[res.size()]);
}
Also used : ResourceTraversal(org.eclipse.core.resources.mapping.ResourceTraversal) ArrayList(java.util.ArrayList) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IContainer (org.eclipse.core.resources.IContainer)199 IResource (org.eclipse.core.resources.IResource)89 IFile (org.eclipse.core.resources.IFile)71 IPath (org.eclipse.core.runtime.IPath)47 CoreException (org.eclipse.core.runtime.CoreException)46 IFolder (org.eclipse.core.resources.IFolder)45 Path (org.eclipse.core.runtime.Path)43 IProject (org.eclipse.core.resources.IProject)28 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)26 ArrayList (java.util.ArrayList)25 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)21 IOException (java.io.IOException)13 IStatus (org.eclipse.core.runtime.IStatus)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 File (java.io.File)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)12 Status (org.eclipse.core.runtime.Status)10 PartInitException (org.eclipse.ui.PartInitException)10 InputStream (java.io.InputStream)9