本文整理汇总了Java中org.eclipse.core.resources.IContainer.getFolder方法的典型用法代码示例。如果您正苦于以下问题:Java IContainer.getFolder方法的具体用法?Java IContainer.getFolder怎么用?Java IContainer.getFolder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.core.resources.IContainer
的用法示例。
在下文中一共展示了IContainer.getFolder方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processFile
import org.eclipse.core.resources.IContainer; //导入方法依赖的package包/类
public static void processFile ( final IContainer parent, final Definition definition, final Profile profile, final IProgressMonitor monitor ) throws Exception
{
monitor.beginTask ( makeJobLabel ( definition, profile ), 100 );
final IFolder output = parent.getFolder ( new Path ( "output" ) ); //$NON-NLS-1$
if ( output.exists () )
{
output.delete ( true, new SubProgressMonitor ( monitor, 9 ) );
}
output.create ( true, true, new SubProgressMonitor ( monitor, 1 ) );
final Builder builder = new Builder ( definition, profile );
final Recipe recipe = builder.build ();
try
{
final Map<String, Object> initialContent = new HashMap<String, Object> ();
initialContent.put ( "output", output ); //$NON-NLS-1$
recipe.execute ( initialContent, new SubProgressMonitor ( monitor, 90 ) );
}
finally
{
monitor.done ();
}
}
示例2: copyFiles
import org.eclipse.core.resources.IContainer; //导入方法依赖的package包/类
public static void copyFiles(File srcFolder, IContainer destFolder) throws CoreException, FileNotFoundException {
for (File f : srcFolder.listFiles()) {
if (f.isDirectory()) {
IFolder newFolder = destFolder.getFolder(new Path(f.getName()));
newFolder.create(true, true, null);
copyFiles(f, newFolder);
} else {
IFile newFile = destFolder.getFile(new Path(f.getName()));
InputStream in = new FileInputStream(f);
try {
newFile.create(in, true, null);
} finally {
try {
if (in != null)
in.close();
} catch (IOException e) {
}
}
}
}
}
示例3: doFinish
import org.eclipse.core.resources.IContainer; //导入方法依赖的package包/类
private void doFinish(IPath containerPath, String[] path, IProgressMonitor monitor) throws CoreException {
monitor.beginTask("Creating package " + String.join(".", path), path.length);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource resource = root.findMember(containerPath);
if (!resource.exists() || !(resource instanceof IContainer)) {
throwCoreException("Container \"" + containerPath + "\" does not exist.");
}
IContainer container = (IContainer) resource;
for(int i = 0; i < path.length; i++) {
Path p = new Path(path[i]);
final IFolder folder = container.getFolder(p);
if(!folder.exists())
folder.create(true, false, monitor);
container = container.getFolder(p);
monitor.worked(1);
}
}
示例4: createFolderPath
import org.eclipse.core.resources.IContainer; //导入方法依赖的package包/类
/**
* Creates all non-existing segments of the given path.
*
* @param path
* The path to create
* @param parent
* The container in which the path should be created in
* @param monitor
* A progress monitor. May be {@code null}
*
* @return The folder specified by the path
*/
private IContainer createFolderPath(IPath path, IContainer parent, IProgressMonitor monitor) {
IContainer activeContainer = parent;
if (null != monitor) {
monitor.beginTask("Creating folders", path.segmentCount());
}
for (String segment : path.segments()) {
IFolder folderToCreate = activeContainer.getFolder(new Path(segment));
try {
if (!folderToCreate.exists()) {
createFolder(segment, activeContainer, monitor);
}
if (null != monitor) {
monitor.worked(1);
}
activeContainer = folderToCreate;
} catch (CoreException e) {
LOGGER.error("Failed to create module folders.", e);
MessageDialog.open(MessageDialog.ERROR, getShell(),
FAILED_TO_CREATE_FOLDER_TITLE, String.format(FAILED_TO_CREATE_FOLDER_MESSAGE,
folderToCreate.getFullPath().toString(), e.getMessage()),
SWT.NONE);
break;
}
}
return activeContainer;
}
示例5: addResource
import org.eclipse.core.resources.IContainer; //导入方法依赖的package包/类
private void addResource ( final IProject project, final String name, final InputStream stream, final IProgressMonitor monitor ) throws CoreException
{
try
{
final String[] toks = name.split ( "\\/" ); //$NON-NLS-1$
IContainer container = project;
for ( int i = 0; i < toks.length - 1; i++ )
{
final IFolder folder = container.getFolder ( new Path ( toks[i] ) );
if ( !folder.exists () )
{
folder.create ( true, true, null );
}
container = folder;
}
final IFile file = project.getFile ( name );
if ( file.exists () )
{
file.setContents ( stream, IResource.FORCE, monitor );
}
else
{
file.create ( stream, true, monitor );
}
}
finally
{
try
{
stream.close ();
}
catch ( final IOException e )
{
}
}
monitor.done ();
}
示例6: createFolder
import org.eclipse.core.resources.IContainer; //导入方法依赖的package包/类
public static void createFolder(String path, IProject project, IProgressMonitor monitor) throws CoreException {
String[] strings = path.split("/");
IContainer currentContainer = project;
for ( String s : strings ) {
IFolder folder = currentContainer.getFolder( new Path(s) );
folder.create(true, true, monitor);
currentContainer = folder;
}
}
示例7: getProposals
import org.eclipse.core.resources.IContainer; //导入方法依赖的package包/类
@Override
public IContentProposal[] getProposals(String contents, int position) {
IContainer proposalRootFolder;
if (null == rootFolder) {
return EMPTY_PROPOSAL;
}
if (rootFolder.isEmpty()) {
proposalRootFolder = ResourcesPlugin.getWorkspace().getRoot();
} else if (rootFolder.segmentCount() == 1) {
proposalRootFolder = ResourcesPlugin.getWorkspace().getRoot().getProject(rootFolder.segment(0));
} else {
proposalRootFolder = findContainerForPath(rootFolder);
}
if (null == proposalRootFolder || !proposalRootFolder.exists()) {
return EMPTY_PROPOSAL;
}
// The field content as path
IPath contentsPath = new Path(contents);
// The directory to look for prefix matches
IPath workingDirectoryPath;
// If the contents path has a trailing separator...
if (contentsPath.hasTrailingSeparator()) {
// Use the full content as working directory path
workingDirectoryPath = contentsPath;
} else {
// Otherwise only use complete segments as working directory
workingDirectoryPath = contentsPath.removeLastSegments(1);
}
IContainer workingDirectory;
if (workingDirectoryPath.segmentCount() > 0) {
workingDirectory = proposalRootFolder.getFolder(workingDirectoryPath);
} else {
workingDirectory = proposalRootFolder;
}
// Return an empty proposal list for non-existing working directories
if (null == workingDirectory || !workingDirectory.exists()) {
return EMPTY_PROPOSAL;
}
try {
return Arrays.asList(workingDirectory.members()).stream()
// Only work with files and folders
.filter(r -> (r instanceof IFile || r instanceof IFolder))
// Filter by prefix matching
.filter(resource -> {
IPath rootRelativePath = resource.getFullPath().makeRelativeTo(rootFolder);
return rootRelativePath.toString().startsWith(contentsPath.toString());
})
// Transform to a ModuleSpecifierProposal
.map(resource -> {
// Create proposal path
IPath proposalPath = resource.getFullPath()
.makeRelativeTo(proposalRootFolder.getFullPath());
// Set the proposal type
ModuleSpecifierProposal.ModuleProposalType type = resource instanceof IFile
? ModuleSpecifierProposal.ModuleProposalType.MODULE
: ModuleSpecifierProposal.ModuleProposalType.FOLDER;
// Create a new module specifier proposal
return ModuleSpecifierProposal.createFromPath(proposalPath, type);
})
.toArray(IContentProposal[]::new);
} catch (CoreException e) {
return EMPTY_PROPOSAL;
}
}
示例8: createFolder
import org.eclipse.core.resources.IContainer; //导入方法依赖的package包/类
/**
* Creates the folder in the given container.
*
* @param name
* The name of the new folder
* @param parent
* The parent container
* @param monitor
* The progress monitor. May be {@code null}.
* @throws CoreException
* for {@link IFolder#create(boolean, boolean, IProgressMonitor)} exceptions
* @return The created folder
*/
private IFolder createFolder(String name, IContainer parent, IProgressMonitor monitor) throws CoreException {
IFolder folder = parent.getFolder(new Path(name));
folder.create(true, true, monitor);
return folder;
}