org.eclipse.core.resources.IFolder Java Examples

The following examples show how to use org.eclipse.core.resources.IFolder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Repository.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public IRepositoryFileStore getFileStore(final IResource resource) {
    if (resource == null) {
        return null;
    }
    for (final IRepositoryStore<? extends IRepositoryFileStore> store : getAllStores()) {
        IFolder container = store.getResource();
        if (Objects.equals(resource.getParent(), container)
                || Objects.equals(resource.getParent(), resource.getWorkspace().getRoot())) {
            IRepositoryFileStore fStore = store.getChild(resource.getName(), false);
            if (fStore != null) {
                return fStore;
            }
        }
    }
    return null;
}
 
Example #2
Source File: JavaClasspathTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testJavaSourceLevelMismatch() throws Exception {
	IProject project = testHelper.getProject();

	// create a fake java.util.List without type param
	IFolder folder = project.getFolder(new Path("src/java/util"));
	IResourcesSetupUtil.createFolder(folder.getFullPath());
	IFile list = folder.getFile("List.xtend");
	list.create(new StringInputStream("package java.util; class List {}"), true, null);

	IFile file = project.getFile("src/Foo.xtend");
	if (!file.exists())
		file.create(new StringInputStream(TEST_CLAZZ),
				true, null);
	IResourcesSetupUtil.cleanBuild();
	IResourcesSetupUtil.waitForBuild();
	markerAssert.assertErrorMarker(file, IssueCodes.JDK_NOT_ON_CLASSPATH);

	list.delete(true, null);
	IResourcesSetupUtil.cleanBuild();
	IResourcesSetupUtil.waitForBuild();
	markerAssert.assertNoErrorMarker(file);
}
 
Example #3
Source File: LaunchShortcutStrategyTest.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public void testWebAppLaunchShortcutStrategy() throws CoreException,
    UnsupportedEncodingException {
  IJavaProject javaProject = getTestProject();
  ILaunchShortcutStrategy strategy = new WebAppLaunchShortcutStrategy();

  WebAppUtilities.verifyIsWebApp(javaProject.getProject());
  IFolder warFolder = WebAppUtilities.getWarSrc(javaProject.getProject());

  IResource selection = warFolder.getFile("Hello.html");
  String url = strategy.generateUrl(selection, false);
  assertTrue(url.equals("Hello.html"));

  // Now we'll add a file in a subdirectory of war.
  IFolder warSubDir = warFolder.getFolder("subdir");
  warSubDir.create(true, true, null);
  IFile otherHello = warSubDir.getFile("OtherHello.html");
  ResourceUtils.createFile(otherHello.getFullPath(), "(other hello)");

  String otherUrl = strategy.generateUrl(otherHello, false);
  assertTrue(otherUrl.equals("subdir/OtherHello.html"));
}
 
Example #4
Source File: ModuleFile.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns whether a folder is on the public path of this module. The public paths include the
 * paths explicitly declared with <code>&lt;public&gt;</code> tags and all of their descendant
 * sub-folders.
 *
 * @param folder the folder to check
 * @return <code>true</code> if this folder is on a public path, and <code>false</code> otherwise
 */
public boolean isPublicPath(IFolder folder) {
  IFolder[] publicFolders = getFolders(getPublicPaths());

  IContainer moduleContainer = getFile().getParent();
  IContainer container = folder;

  // Walk up the ancestor chain looking for a public path matching this folder
  while (container.getType() == IResource.FOLDER) {
    // If we reach the module's container, we're done searching
    if (container.equals(moduleContainer)) {
      return false;
    }

    for (IFolder publicFolder : publicFolders) {
      if (container.equals(publicFolder)) {
        return true;
      }
    }

    container = container.getParent();
  }

  return false;
}
 
Example #5
Source File: BuilderParticipantTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDisabled() throws Exception {
	IJavaProject project = createJavaProject("foo");
	participant.getBuilderPreferenceAccess().setAutoBuildEnabled(project, false);
	addNature(project.getProject(), XtextProjectHelper.NATURE_ID);
	IFolder folder = project.getProject().getFolder("src");
	IFile file = folder.getFile("Foo" + F_EXT);
	file.create(new StringInputStream("object Foo"), true, monitor());
	build();
	IFile generatedFile = project.getProject().getFile("./src-gen/Foo.txt");
	assertFalse(generatedFile.exists());
	participant.getBuilderPreferenceAccess().setAutoBuildEnabled(project, true);
	file.touch(monitor());
	build();
	assertTrue(generatedFile.exists());
}
 
Example #6
Source File: NewPackageWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the resource handle that corresponds to the element that was created or
 * will be created.
 * @return A resource or null if the page contains illegal values.
 * @since 3.0
 */
public IResource getModifiedResource() {
	IPackageFragmentRoot root= getPackageFragmentRoot();
	if (root != null) {
		IPackageFragment pack= root.getPackageFragment(getPackageText());
		IResource packRes= pack.getResource();
		if (isCreatePackageDocumentation()) {
			if (JavaModelUtil.is50OrHigher(getJavaProject())) {
				return pack.getCompilationUnit(PACKAGE_INFO_JAVA_FILENAME).getResource();
			} else if (packRes instanceof IFolder){
				return ((IFolder) packRes).getFile(PACKAGE_HTML_FILENAME);
			}
		}

		return packRes;
	}
	return null;
}
 
Example #7
Source File: PlatformContentProvider.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object[] getChildren(Object parentElement) {
	if (!(parentElement instanceof IFolder)) {
		return new Object[0];
	}
	IFolder folder = (IFolder) parentElement;
	if (folder.getProjectRelativePath().segmentCount() > 1) {// only platforms folder at the root of the project
		return new Object[0];
	}
	List<HybridPlatformFolder> platformFolders = new ArrayList<>();
	try {
		HybridProject project = HybridProject.getHybridProject(folder.getProject());
		for (IResource member : folder.members()) {
			if (member instanceof IFolder) {
				IFolder platformFolder = (IFolder) member;
				platformFolders.add(
						new HybridPlatformFolder((IFolder) member, getPlatform(project, platformFolder.getName())));
			}
		}
		
	} catch (CoreException e) {
		HybridUI.log(IStatus.ERROR, "Error reading cordova platforms", e);
	}
	return platformFolders.toArray();
}
 
Example #8
Source File: WorkspaceFile.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
@Override
public IFileStore mkdir(int options, IProgressMonitor monitor) throws CoreException {
	ensureLocalFileStore(IFolder.class);
	if (resource != null && !resource.exists()) {
		monitor = Policy.monitorFor(monitor);
		monitor.beginTask(MessageFormat.format("Creating folder {0}", path.lastSegment()), 100); //$NON-NLS-1$
		try {
			if ((options & EFS.SHALLOW) == 0) {
				createParentsRecursive(resource, Policy.subMonitorFor(monitor, 80));
			} else {
				Policy.subMonitorFor(monitor, 80).done();
			}
			((IFolder) resource).create(IResource.FORCE, true, Policy.subMonitorFor(monitor, 20));
		} catch (CoreException e) {
			fileNotFoundError(e, path);
		}
	}
	return this;
}
 
Example #9
Source File: PackagesViewHierarchicalContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private List<IAdaptable> getFoldersAndElements(IResource[] resources) {
	List<IAdaptable> list= new ArrayList<IAdaptable>();
	for (int i= 0; i < resources.length; i++) {
		IResource resource= resources[i];

		if (resource instanceof IFolder) {
			IFolder folder= (IFolder) resource;
			IJavaElement element= JavaCore.create(folder);

			if (element instanceof IPackageFragment) {
				list.add(element);
			} else {
				list.add(folder);
			}
		}
	}
	return list;
}
 
Example #10
Source File: ProjectCustomizer.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a folder, if it does not exist, in a given container
 * 
 * @param container
 *          an IContainer
 * @param folderName
 *          The folder name
 * @return the handle (IFolder) to the folder
 * @throws PearException
 *           If a problem occurs
 */
public static IFolder createFolder(IContainer container, String folderName) throws PearException {
  try {
    IFolder folder = container.getFolder(new Path(folderName));
    // If the folder does not exist, create and return, failure returns null
    if (!folder.exists()) {
      folder.create(true, true, null);
      return folder;
    } else {
      // return what already exisited
      return folder;
    }
  } catch (Throwable e) {
    PearException subEx = new PearException("folderName could not be created properly.", e);
    throw subEx;
  }
}
 
Example #11
Source File: PythonPackageWizard.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates the complete package path given by the user (all filled with __init__) 
 * and returns the last __init__ module created.
 */
public static IFile createPackage(IProgressMonitor monitor, IContainer validatedSourceFolder, String packageName)
        throws CoreException {
    IFile lastFile = null;
    if (validatedSourceFolder == null) {
        return null;
    }
    IContainer parent = validatedSourceFolder;
    for (String packagePart : StringUtils.dotSplit(packageName)) {
        IFolder folder = parent.getFolder(new Path(packagePart));
        if (!folder.exists()) {
            folder.create(true, true, monitor);
        }
        parent = folder;
        IFile file = parent.getFile(new Path("__init__"
                + FileTypesPreferences.getDefaultDottedPythonExtension()));
        if (!file.exists()) {
            file.create(new ByteArrayInputStream(new byte[0]), true, monitor);
        }
        lastFile = file;
    }

    return lastFile;
}
 
Example #12
Source File: JavaElementResourceMapping.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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()]);
}
 
Example #13
Source File: LaunchTargetTester.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * WAR projects: Is this resource an html or jsp page under the war directory or one of its
 * subdirectories? Legacy GWT projects: Is this resource an html file?
 *
 * @param resource
 * @return whether the resource matches the specified conditions (a servable html/jsp page).
 */
private boolean resourceIsHostPage(IResource resource) {
  IProject project = resource.getProject();

  if (WebAppUtilities.isWebApp(project)) {
    IFolder war = WebAppUtilities.getWarSrc(project);

    if (war != null) {
      if (war.getFullPath().isPrefixOf(resource.getFullPath())) {
        return ResourceUtils.hasJspOrHtmlExtension(resource);
      }
    }
  } else {
    // Legacy GWT project
    return "html".equalsIgnoreCase(resource.getFileExtension());
  }

  return false;
}
 
Example #14
Source File: PluginContentProvider.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object[] getChildren(Object parentElement) {
	if (!(parentElement instanceof IFolder)) {
		return new Object[0];
	}
	IFolder folder = (IFolder) parentElement;
	if (folder.getProjectRelativePath().segmentCount() > 1) {// only plugins folder at the root of the project
		return new Object[0];
	}
	List<HybridPluginFolder> plugins = new ArrayList<>();
	HybridProject project = HybridProject.getHybridProject(folder.getProject());
	try {
		for (IResource member : folder.members()) {
			if (member instanceof IFolder) {
				IFolder pluginFolder = (IFolder) member;
				plugins.add(new HybridPluginFolder(pluginFolder, getPlugin(pluginFolder.getName(), project)));
			}
		}
	} catch (CoreException e) {
		HybridUI.log(IStatus.ERROR, "Error retrieving the installed plugins", e);
	}

	return plugins.toArray();
}
 
Example #15
Source File: DeleteHandler.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected boolean selectionCanBeDeleted(IStructuredSelection selection, Repository currentRepository) {
    for (Object sel : selection.toList()) {
        if (sel instanceof IAdaptable) {
            IResource adapter = ((IAdaptable) sel).getAdapter(IResource.class);
            if (adapter != null) {
                if (Objects.equals(currentRepository.getProject(), adapter)) {
                    return false;
                }
                IRepositoryFileStore fileStore = currentRepository.getFileStore(adapter);
                if (fileStore != null && !fileStore.canBeDeleted()) {
                    return false;
                } else if (fileStore == null && currentRepository.getRepositoryStore(adapter) != null
                        && adapter instanceof IFolder) {
                    return false;
                }
            }
        } else {
            return false;
        }
    }
    return selection.size() > 0;
}
 
Example #16
Source File: ScopedPreferences.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the contents of the configuration file to be used or null.
 */
private static IFile getProjectConfigFile(IProject project, String filename, boolean createPath) {
    try {
        if (project != null && project.exists()) {
            IFolder folder = project.getFolder(".settings");
            if (createPath) {
                if (!folder.exists()) {
                    folder.create(true, true, new NullProgressMonitor());
                }
            }
            return folder.getFile(filename);
        }
    } catch (Exception e) {
        Log.log(e);
    }
    return null;
}
 
Example #17
Source File: AbstractWorkbenchTestCase.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a package structure below a source folder.
 */
protected IFile createPackageStructure(IContainer sourceFolder, String packageName, IProgressMonitor monitor)
        throws CoreException {
    IFile lastFile = null;
    if (sourceFolder == null) {
        return null;
    }
    IContainer parent = sourceFolder;
    for (String packagePart : StringUtils.dotSplit(packageName)) {
        IFolder folder = parent.getFolder(new Path(packagePart));
        if (!folder.exists()) {
            folder.create(true, true, monitor);
        }
        parent = folder;
        IFile file = parent.getFile(new Path("__init__"
                + FileTypesPreferences.getDefaultDottedPythonExtension()));
        if (!file.exists()) {
            file.create(new ByteArrayInputStream(new byte[0]), true, monitor);
        }
        lastFile = file;
    }

    return lastFile;
}
 
Example #18
Source File: PreviewTranslationHandler.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 得到子文件
 * @param folder
 *            文件夹
 * @param fileExtension
 *            子文件后缀名
 * @param list
 *            子文件集合
 * @throws CoreException
 *             ;
 */
public static void getChildFiles(IFolder folder, String fileExtension, List<IFile> list) throws CoreException {
	if (list == null) {
		list = new ArrayList<IFile>();
	}
	if (folder.isAccessible() && folder.exists()) {
		IResource[] members = folder.members();
		for (IResource resource : members) {
			if (resource instanceof IFile && (fileExtension).equalsIgnoreCase(resource.getFileExtension())) {
				list.add((IFile) resource);
			} else if (resource instanceof IFolder) {
				getChildFiles((IFolder) resource, fileExtension, list);
			}
		}
	}
}
 
Example #19
Source File: ProjectExplorerTraceActionsTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
private static void importTraceAsSymlink() throws TmfTraceImportException, CoreException {
    TraceTypeHelper helper = TmfTraceTypeUIUtils.selectTraceType(fTestFile.getAbsolutePath(), null, null);
    final boolean IS_WINDOWS = System.getProperty("os.name").contains("Windows"); //$NON-NLS-1$ //$NON-NLS-2$
    IProject project = TmfProjectRegistry.createProject(TRACE_PROJECT_NAME, null, new NullProgressMonitor());
    assertNotNull(project);
    TmfProjectElement projectElement = TmfProjectRegistry.getProject(project);
    TmfTraceFolder folder = projectElement.getTracesFolder();
    assertNotNull(folder);

    IFolder subFolder = folder.getResource().getFolder(SYMBOLIC_FOLDER_NAME);
    TraceUtils.createFolder(subFolder, new NullProgressMonitor());

    IFile file = subFolder.getFile(fTestFile.getName());
    assertNotNull(file);
    ResourceUtil.createSymbolicLink(file, new Path(fTestFile.getAbsolutePath()), !IS_WINDOWS, null);
    folder.getResource().refreshLocal(IResource.DEPTH_INFINITE, null);
    TmfTraceTypeUIUtils.setTraceType(file, helper, false);
}
 
Example #20
Source File: GWTCompileRunnerTest.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Create a source entry (including the dir structure) and add it to the raw
 * classpath.
 * 
 * @param javaProject The Java project that receives the source entry
 * @param directoryName The source directory name
 * @param outputDirectoryName The optional output location of this source
 *          directory. Pass null for the default output location.
 */
private static void addAndCreateSourceEntry(IJavaProject javaProject,
    String directoryName, String outputDirectoryName) throws CoreException {
  IFolder srcFolder = javaProject.getProject().getFolder(directoryName);
  ResourceUtils.createFolderStructure(javaProject.getProject(),
      srcFolder.getProjectRelativePath());
  
  IPath workspaceRelOutPath = null;
  if (outputDirectoryName != null) {
    // Ensure output directory exists
    IFolder outFolder = javaProject.getProject().getFolder(outputDirectoryName);
    ResourceUtils.createFolderStructure(javaProject.getProject(),
        outFolder.getProjectRelativePath());
    workspaceRelOutPath = outFolder.getFullPath();
  }
  
  JavaProjectUtilities.addRawClassPathEntry(javaProject,
      JavaCore.newSourceEntry(srcFolder.getFullPath(),
          ClasspathEntry.EXCLUDE_NONE, workspaceRelOutPath));
}
 
Example #21
Source File: TmfExperimentElement.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
private List<IResource> getTraceResources() {
    IFolder folder = getResource();
    final List<IResource> list = new ArrayList<>();
    try {
        folder.accept(new IResourceProxyVisitor() {
            @Override
            public boolean visit(IResourceProxy resource) throws CoreException {
                /*
                 * Trace represented by a file, or a link for backward compatibility
                 */
                if (resource.getType() == IResource.FILE || resource.isLinked()) {
                    list.add(resource.requestResource());
                    /* don't visit linked folders, as they might contain files */
                    return false;
                }
                return true;
            }
        }, IResource.NONE);
    } catch (CoreException e) {
    }
    list.sort(Comparator.comparing(resource -> resource.getFullPath().toString()));
    return list;
}
 
Example #22
Source File: IgnoreMavenTargetFolderContribution.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean isRejected(IFolder folder) {
	IMavenProjectFacade mavenProjectFacade = MavenPlugin.getMavenProjectRegistry().getProject(folder.getProject());
	if (mavenProjectFacade == null) {
		return false;
	}
	IPath outputLocation = mavenProjectFacade.getOutputLocation();
	if (outputLocation == null) {
		return false;
	} else if (folder.getFullPath().equals(outputLocation)) {
		return true;
	}
	IPath testOutputLocation = mavenProjectFacade.getTestOutputLocation();
	if (testOutputLocation == null) {
		return false;
	} else if (folder.getFullPath().equals(testOutputLocation)) {
		return true;
	}
	return false;
}
 
Example #23
Source File: WebProjectUtilTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateWebInfFile_dynamicWebProject() throws CoreException, IOException {
  IProject project = testProjectCreator
      .withFacets(JavaFacet.VERSION_1_7, WebFacetUtils.WEB_25).getProject();
  IFile webXml = WebProjectUtil.findInWebInf(project, new Path("web.xml"));
  assertNotNull(webXml);
  assertTrue(webXml.exists());
  IFolder webInfDir = (IFolder) webXml.getParent();

  // should be found alongside the web.xml
  IFile fooTxt =
      WebProjectUtil.createFileInWebInf(
          project, new Path("foo.txt"), asInputStream("foo"), false /*overwrite*/, null);
  assertNotNull(fooTxt);
  assertTrue(fooTxt.exists());
  assertEquals(webInfDir.getProjectRelativePath().append("foo.txt").toString(),
      fooTxt.getProjectRelativePath().toString());
  assertEquals("foo", readAsString(fooTxt));
}
 
Example #24
Source File: FileUtils.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
private static IFile findExistingLinkedFile(final IFolder folder, final String name) {
	final IFile[] result = new IFile[1];
	try {
		folder.accept((IResourceVisitor) resource -> {
			if (resource.isLinked()) {
				final String p = resource.getLocation().toString();
				if (p.equals(name)) {
					result[0] = (IFile) resource;
					return false;
				}
			}
			return true;

		}, IResource.DEPTH_INFINITE, IResource.FILE);
	} catch (final CoreException e1) {
		e1.printStackTrace();
	}
	final IFile file = result[0];
	return file;
}
 
Example #25
Source File: TmfProjectElement.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
static TmfProjectConfig getFolderStructure(IProject project) {
    TmfProjectConfig.Builder builder = new TmfProjectConfig.Builder();

    IFolder folder = project.getFolder(new Path(TmfTracesFolder.TRACES_RESOURCE_NAME));
    builder.setTracesFolder(folder);

    folder = project.getFolder(new Path(TmfExperimentFolder.EXPER_RESOURCE_NAME));
    builder.setExperimentsFolder(folder);

    // create folder for supplementary tracing files
    folder = project.getFolder(new Path(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER_NAME));
    builder.setSupplementaryFolder(folder);
    return builder.build();
}
 
Example #26
Source File: TestedWorkspaceWithJDT.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public IFolder createSubFolder(IProject project, String name) {
	try {
		return IResourcesSetupUtil.createFolder(project.getFolder(name).getFullPath());
	} catch(Exception e) {
		return Exceptions.throwUncheckedException(e);
	}
}
 
Example #27
Source File: NewContainerDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isFolderExisting(IFolder folder) {
	for (int i= 0; i < fExistingFolders.length; i++) {
		if (folder.getFullPath().equals(fExistingFolders[i])) {
			return true;
		}
	}
	return false;
}
 
Example #28
Source File: SourceAttachmentPackageFragmentRootWalker.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public T traverse(IFolder folder, boolean stopOnFirstResult, TraversalState state) {
	T result = null;
	try {
		IPath path = new Path("");
		List<?> parents = state.getParents();
		for (int i = 1, count = parents.size(); i < count; ++i) {
			path = path.append(((IFolder) parents.get(i)).getName());
		}
		for (IResource resource : folder.members()) {
			switch (resource.getType()) {
				case IResource.FOLDER: {
					// If something in this folder might be in the bin includes, traverse it.
					//
					if (isBinInclude(path.append(resource.getName()).toString() + "/") != NO) {
						state.push(resource);
						result = traverse((IFolder) resource, stopOnFirstResult, state);
						state.pop();
					}
					break;
				}
				case IResource.FILE: {
					// If the file is definitely in the bin includes, handle it.
					//
					if (isBinInclude(path.append(resource.getName()).toString()) == YES) {
						result = handle((IFile) resource, state);
					}
					break;
				}
			}
			if (stopOnFirstResult && result != null) {
				break;
			}
		}
	} catch (CoreException e) {
		LOG.error(e.getMessage(), e);
	}
	return result;
}
 
Example #29
Source File: WorkbenchLabelProvider.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public final Image getImage(Object element) {
	// obtain the base image by querying the element
	ImageDescriptor descriptor = null;
	if (element instanceof IProject) {
		IProject project = (IProject) element;
		if (project.isOpen()) {
			descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
					"net.heartsome.cat.common.ui.navigator.resources", "icons/full/obj16/prj_open.png");
		}else {
			descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
					"net.heartsome.cat.common.ui.navigator.resources", "icons/full/obj16/prj_close.png");
		}
	} else if(element instanceof IFolder){
		 descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
					"net.heartsome.cat.common.ui.navigator.resources", "icons/full/obj16/folder.png");
	}
	
	else {
		IWorkbenchAdapter adapter = getAdapter(element);
		if (adapter == null) {
			return null;
		}
		descriptor = adapter.getImageDescriptor(element);
		if (descriptor == null) {
			return null;
		}

		// add any annotations to the image descriptor
		descriptor = decorateImage(descriptor, element);
	}
	return (Image) getResourceManager().get(descriptor);
}
 
Example #30
Source File: DialogUtils.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public static IFolder chooseProjectFolder(Shell shell, IProject container) {
    FilteredResourcesSelectionDialog dlg = new FilteredResourcesSelectionDialog(shell, false, container, IResource.FOLDER & (~IResource.HIDDEN));
    dlg.setInitialPattern("**"); //$NON-NLS-1$
    if (dlg.open() == FilteredResourcesSelectionDialog.OK ) {
        return (IFolder)(dlg.getResult()[0]);
    }
    
    return null;
}