use of org.eclipse.core.resources.IWorkspaceRoot in project che by eclipse.
the class Util method getPackageFragment.
public static IPackageFragment getPackageFragment(char[] fileName, int pkgEnd, int jarSeparator) {
if (jarSeparator != -1) {
String jarMemento = new String(fileName, 0, jarSeparator);
PackageFragmentRoot root = (PackageFragmentRoot) JavaCore.create(jarMemento);
if (pkgEnd == jarSeparator)
return root.getPackageFragment(CharOperation.NO_STRINGS);
char[] pkgName = CharOperation.subarray(fileName, jarSeparator + 1, pkgEnd);
char[][] compoundName = CharOperation.splitOn('/', pkgName);
return root.getPackageFragment(CharOperation.toStrings(compoundName));
} else {
Path path = new Path(new String(fileName, 0, pkgEnd));
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IContainer folder = path.segmentCount() == 1 ? workspaceRoot.getProject(path.lastSegment()) : (IContainer) workspaceRoot.getFolder(path);
IJavaElement element = JavaCore.create(folder);
if (element == null)
return null;
switch(element.getElementType()) {
case IJavaElement.PACKAGE_FRAGMENT:
return (IPackageFragment) element;
case IJavaElement.PACKAGE_FRAGMENT_ROOT:
return ((PackageFragmentRoot) element).getPackageFragment(CharOperation.NO_STRINGS);
case IJavaElement.JAVA_PROJECT:
PackageFragmentRoot root = (PackageFragmentRoot) ((IJavaProject) element).getPackageFragmentRoot(folder);
if (root == null)
return null;
return root.getPackageFragment(CharOperation.NO_STRINGS);
}
return null;
}
}
use of org.eclipse.core.resources.IWorkspaceRoot in project che by eclipse.
the class ImportOperation method collectExistingReadonlyFiles.
/**
* Prompts if existing resources should be overwritten. Recursively collects
* existing read-only files to overwrite and resources that should not be
* overwritten.
*
* @param sourceStart destination path to check for existing files
* @param sources file system objects that may exist in the destination
* @param noOverwrite files that were selected to be skipped (don't overwrite).
* object type IPath
* @param overwriteReadonly the collected existing read-only files to overwrite.
* object type IPath
* @param policy on of the POLICY constants defined in the
* class.
*/
void collectExistingReadonlyFiles(IPath sourceStart, List sources, ArrayList noOverwrite, ArrayList overwriteReadonly, int policy) {
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
Iterator sourceIter = sources.iterator();
IPath sourceRootPath = null;
if (this.source != null) {
sourceRootPath = new Path(provider.getFullPath(this.source));
}
while (sourceIter.hasNext()) {
Object nextSource = sourceIter.next();
IPath sourcePath = new Path(provider.getFullPath(nextSource));
IPath newDestinationPath;
IResource newDestination;
if (sourceRootPath == null) {
newDestinationPath = sourceStart.append(provider.getLabel(nextSource));
} else {
int prefixLength = sourcePath.matchingFirstSegments(sourceRootPath);
IPath relativeSourcePath = sourcePath.removeFirstSegments(prefixLength);
newDestinationPath = this.destinationPath.append(relativeSourcePath);
}
newDestination = workspaceRoot.findMember(newDestinationPath);
if (newDestination == null) {
continue;
}
IFolder folder = getFolder(newDestination);
if (folder != null) {
if (policy != POLICY_FORCE_OVERWRITE) {
if (this.overwriteState == OVERWRITE_NONE || !queryOverwrite(newDestinationPath)) {
noOverwrite.add(folder);
continue;
}
}
if (provider.isFolder(nextSource)) {
collectExistingReadonlyFiles(newDestinationPath, provider.getChildren(nextSource), noOverwrite, overwriteReadonly, POLICY_FORCE_OVERWRITE);
}
} else {
IFile file = getFile(newDestination);
if (file != null) {
if (!queryOverwriteFile(file, policy)) {
noOverwrite.add(file.getFullPath());
} else if (file.isReadOnly()) {
overwriteReadonly.add(file);
}
}
}
}
}
use of org.eclipse.core.resources.IWorkspaceRoot in project che by eclipse.
the class ImportOperation method createFromRoot.
/**
* Creates the folders that appear in the specified resource path
* assuming that the destinationContainer begins at the root. Do not create projects.
*
* @param path the relative path of the resource
* @return the container resource coresponding to the given path
* @exception CoreException if this method failed
*/
private IContainer createFromRoot(IPath path) throws CoreException {
int segmentCount = path.segmentCount();
//Assume the project exists
IContainer currentFolder = ((IWorkspaceRoot) destinationContainer).getProject(path.segment(0));
for (int i = 1; i < segmentCount; i++) {
currentFolder = currentFolder.getFolder(new Path(path.segment(i)));
if (!currentFolder.exists()) {
((IFolder) currentFolder).create(false, true, null);
}
}
return currentFolder;
}
use of org.eclipse.core.resources.IWorkspaceRoot in project che by eclipse.
the class FileUndoState method createResourceHandle.
public IResource createResourceHandle() {
IWorkspaceRoot workspaceRoot = parent.getWorkspace().getRoot();
IPath fullPath = parent.getFullPath().append(name);
return workspaceRoot.getFile(fullPath);
}
use of org.eclipse.core.resources.IWorkspaceRoot in project che by eclipse.
the class FolderUndoState method createResourceHandle.
public IResource createResourceHandle() {
IWorkspaceRoot workspaceRoot = getWorkspace().getRoot();
IPath folderPath = parent.getFullPath().append(name);
return workspaceRoot.getFolder(folderPath);
}
Aggregations