本文整理匯總了Java中org.eclipse.core.resources.IWorkspace類的典型用法代碼示例。如果您正苦於以下問題:Java IWorkspace類的具體用法?Java IWorkspace怎麽用?Java IWorkspace使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
IWorkspace類屬於org.eclipse.core.resources包,在下文中一共展示了IWorkspace類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: collectIndexableFiles
import org.eclipse.core.resources.IWorkspace; //導入依賴的package包/類
/**
* Scans workspace for files that may end up in XtextIndex when given location is processed by the builder. This is
* naive filtering based on {@link IndexableFilesDiscoveryUtil#INDEXABLE_FILTERS file extensions}. Symlinks are not
* followed.
*
* @param workspace
* to scan
* @return collection of indexable locations
* @throws CoreException
* if scanning of the workspace is not possible.
*/
public static Collection<String> collectIndexableFiles(IWorkspace workspace) throws CoreException {
Set<String> result = new HashSet<>();
workspace.getRoot().accept(new IResourceVisitor() {
@Override
public boolean visit(IResource resource) throws CoreException {
if (resource.getType() == IResource.FILE) {
IFile file = (IFile) resource;
if (INDEXABLE_FILTERS.contains(file.getFileExtension().toLowerCase())) {
result.add(file.getFullPath().toString());
}
}
return true;
}
});
return result;
}
示例2: getContentProvider
import org.eclipse.core.resources.IWorkspace; //導入依賴的package包/類
/**
* Returns a content provider for the list dialog. It will return all projects in the workspace except the given
* project, plus any projects referenced by the given project which do no exist in the workspace.
*
* @return the content provider that shows the project content
*/
private IStructuredContentProvider getContentProvider() {
return new WorkbenchContentProvider() {
@Override
public Object[] getChildren(Object o) {
if (!(o instanceof IWorkspace)) {
return new Object[0];
}
// Collect all the projects in the workspace except the given project
IProject[] projects = ((IWorkspace) o).getRoot().getProjects();
List<IProject> applicableProjects = Lists.newArrayList();
Optional<? extends IN4JSEclipseProject> projectOpt = null;
for (IProject candidate : projects) {
projectOpt = n4jsCore.create(candidate);
if (projectOpt.isPresent() && projectOpt.get().exists()) {
applicableProjects.add(candidate);
}
}
return applicableProjects.toArray(new IProject[applicableProjects.size()]);
}
};
}
示例3: createProjectPluginResource
import org.eclipse.core.resources.IWorkspace; //導入依賴的package包/類
public IProject createProjectPluginResource(String projectName, IProgressMonitor monitor) throws CoreException {
IWorkspace myWorkspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot myWorkspaceRoot = myWorkspace.getRoot();
IProject resourceProject = myWorkspaceRoot.getProject(projectName);
if (!resourceProject.exists()) {
if(myWorkspaceRoot.getLocation().toFile().equals(new Path(Engine.PROJECTS_PATH).toFile())){
logDebug("createProjectPluginResource : project is in the workspace folder");
resourceProject.create(monitor);
}else{
logDebug("createProjectPluginResource: project isn't in the workspace folder");
IPath projectPath = new Path(Engine.PROJECTS_PATH + "/" + projectName).makeAbsolute();
IProjectDescription description = myWorkspace.newProjectDescription(projectName);
description.setLocation(projectPath);
resourceProject.create(description, monitor);
}
}
return resourceProject;
}
示例4: setGW4ENature
import org.eclipse.core.resources.IWorkspace; //導入依賴的package包/類
/**
* Set the GW4E Nature to the passed project
*
* @param project
* @return
* @throws CoreException
*/
public static IStatus setGW4ENature(IProject project) throws CoreException {
IProjectDescription description = project.getDescription();
String[] natures = description.getNatureIds();
String[] newNatures = new String[natures.length + 1];
System.arraycopy(natures, 0, newNatures, 0, natures.length);
// add our id
newNatures[natures.length] = GW4ENature.NATURE_ID;
// validate the natures
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IStatus status = workspace.validateNatureSet(newNatures);
if (status.getCode() == IStatus.OK) {
description.setNatureIds(newNatures);
project.setDescription(description, null);
}
return status;
}
示例5: validateContainer
import org.eclipse.core.resources.IWorkspace; //導入依賴的package包/類
/**
* @return
*/
protected boolean validateContainer(Problem pb) {
if (selectedContainer==null) {
pb.raiseProblem(MessageUtil.getString("select_a_folder"), Problem.PROBLEM_RESOURCE_EMPTY);
return false;
}
if (!selectedContainer.exists()) {
pb.raiseProblem(MessageUtil.getString("folder_does_not_exists"), Problem.FOLDER_PROJECT_DOES_NOT_EXIST);
return false;
}
IPath path = selectedContainer.getFullPath();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
String projectName = path.segment(0);
if (projectName == null
|| !workspace.getRoot().getProject(projectName).exists()) {
pb.raiseProblem(MessageUtil.getString("project_does_not_exist"), Problem.PROBLEM_PROJECT_DOES_NOT_EXIST);
return false;
}
return true;
}
示例6: validateAndConvertOperationField
import org.eclipse.core.resources.IWorkspace; //導入依賴的package包/類
private void validateAndConvertOperationField(TransformMapping transformMapping, TypeOperationsOutSocket externalMapping, String componentName) {
transformMapping.clear();
for (Object field : externalMapping.getPassThroughFieldOrOperationFieldOrExpressionField()) {
if (field instanceof TypeInputField) {
if(STAR_PROPERTY.equals(((TypeInputField) field).getName())){
transformMapping.setAllInputFieldsArePassthrough(true);
}else{
addPassThroughField((TypeInputField) field, transformMapping);
}
} else if (field instanceof TypeMapField) {
addMapField((TypeMapField) field, transformMapping);
} else if (field instanceof TypeOperationField) {
addOperationField((TypeOperationField)field, transformMapping, componentName);
} else if (field instanceof TypeExpressionField) {
addExpressionField((TypeExpressionField) field, transformMapping, componentName);
}else if(field instanceof TypeExternalSchema){
String filePath = StringUtils.replace(((TypeExternalSchema)field).getUri(), "../", "");
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IPath relativePath=null;
relativePath=workspace.getRoot().getFile(new Path(filePath)).getLocation();
ExternalOperationExpressionUtil.INSTANCE.importOutputFields(relativePath.toFile(), transformMapping, false,Constants.TRANSFORM_DISPLAYNAME);
transformMapping.getExternalOutputFieldsData().setExternal(true);
transformMapping.getExternalOutputFieldsData().setFilePath(filePath);
}
}
}
示例7: isFilteredByParent
import org.eclipse.core.resources.IWorkspace; //導入依賴的package包/類
private boolean isFilteredByParent() {
if ((linkedResourceGroup == null) || linkedResourceGroup.isEnabled())
return false;
IPath containerPath = resourceGroup.getContainerFullPath();
if (containerPath == null)
return false;
String resourceName = resourceGroup.getResource();
if (resourceName == null)
return false;
if (resourceName.length() > 0) {
IPath newFolderPath = containerPath.append(resourceName);
IFile newFileHandle = createFileHandle(newFolderPath);
IWorkspace workspace = newFileHandle.getWorkspace();
return !workspace.validateFiltered(newFileHandle).isOK();
}
return false;
}
示例8: addProjectsToList
import org.eclipse.core.resources.IWorkspace; //導入依賴的package包/類
private void addProjectsToList() {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
IProject[] projects = root.getProjects();
for (IProject project : projects){
try {
if (project.isNatureEnabled("jasonide.jasonNature")){
projectsList.add(project.getName());
}
} catch (CoreException e) {
//e.printStackTrace();
//MessageDialog.openError(shell, "CoreException", e.getMessage());
}
}
}
示例9: createLinkedProject
import org.eclipse.core.resources.IWorkspace; //導入依賴的package包/類
public IProject createLinkedProject(String projectName, Plugin plugin, IPath linkPath) throws CoreException {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject project = workspace.getRoot().getProject(projectName);
IProjectDescription desc = workspace.newProjectDescription(projectName);
File file = getFileInPlugin(plugin, linkPath);
IPath projectLocation = new Path(file.getAbsolutePath());
if (Platform.getLocation().equals(projectLocation))
projectLocation = null;
desc.setLocation(projectLocation);
project.create(desc, NULL_MONITOR);
if (!project.isOpen())
project.open(NULL_MONITOR);
return project;
}
示例10: getIFileFromResource
import org.eclipse.core.resources.IWorkspace; //導入依賴的package包/類
private IFile getIFileFromResource() {
Resource linkTargetResource = linkTarget.eResource();
if (linkTargetResource == null) {
return null;
}
URI resourceURI = linkTargetResource.getURI();
if (linkTargetResource.getResourceSet() != null && linkTargetResource.getResourceSet().getURIConverter() != null) {
resourceURI = linkTargetResource.getResourceSet().getURIConverter().normalize(resourceURI);
}
if (resourceURI.isPlatformResource()) {
String platformString = resourceURI.toPlatformString(true);
if (platformString != null) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
return root.getFile(new Path(platformString));
}
}
return null;
}
示例11: createFileInPath
import org.eclipse.core.resources.IWorkspace; //導入依賴的package包/類
public static File createFileInPath(String fileName, IPath path){
path = path.append(fileName);
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot workspaceRoot = workspace.getRoot();
IFile outputFile = workspaceRoot.getFile(path);
File file = new File(outputFile.getLocationURI());
if(!file.exists())
try {
if(!file.createNewFile()){
return null;
}
} catch (IOException e) {
e.printStackTrace();
return null;
}
return file;
}
示例12: getLayoutFile
import org.eclipse.core.resources.IWorkspace; //導入依賴的package包/類
/**
* Returns the file object of the feature model
* @param featureModel
* @return
*/
private static File getLayoutFile(DwFeatureModelWrapped featureModel){
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot workspaceRoot = workspace.getRoot();
IFile file = workspaceRoot.getFile(new Path(featureModel.getModel().eResource().getURI().toPlatformString(true)));
IPath path = ((IPath)file.getFullPath().clone()).removeFileExtension().addFileExtension("hylayout");
IResource resourceInRuntimeWorkspace = workspaceRoot.findMember(path.toString());
if(resourceInRuntimeWorkspace != null){
return new File(resourceInRuntimeWorkspace.getLocationURI());
}else{
return null;
}
}
示例13: testNewSpecHandlerFail
import org.eclipse.core.resources.IWorkspace; //導入依賴的package包/類
public void testNewSpecHandlerFail() throws InterruptedException, IOException, CoreException {
// Create a project (not a specification) that is going to be in the way
// of the NewSpecHandler and which will make it fail.
final IWorkspace ws = ResourcesPlugin.getWorkspace();
ws.getRoot().getProject("TestNewSpecHandlerFail").create(new NullProgressMonitor());
assertTrue(ws.getRoot().getProject("TestNewSpecHandlerFail").exists());
// Above only creates a project but not a spec.
assertNull(Activator.getSpecManager().getSpecByName("TestNewSpecHandlerFail"));
// Try to create a spec the Toolbox way which is supposed to fail.
final IStatus iStatus = runJob("TestNewSpecHandlerFail");
assertEquals(Status.ERROR, iStatus.getSeverity());
// As a result of the above failed attempt to create a spec
// 'TestNewSpecHandlerFail', a spec should appear in the SpecManager
// with a file named "Delete me".
final Spec spec = Activator.getSpecManager().getSpecByName("TestNewSpecHandlerFail");
assertEquals("Failed to find 'Delete me' spec in ToolboxExplorer", "Delete me", spec.getRootFile().getName());
// Verify that this spec can be deleted and is gone afterwards
// (including the dangling project this is all about).
Activator.getSpecManager().removeSpec(spec, new NullProgressMonitor(), true);
assertNull(Activator.getSpecManager().getSpecByName("TestNewSpecHandlerFail"));
assertFalse(ws.getRoot().getProject("TestNewSpecHandlerFail").exists());
}
示例14: validateProjectName
import org.eclipse.core.resources.IWorkspace; //導入依賴的package包/類
public static IStatus validateProjectName(final IWorkspace workspace, final String name) {
final IStatus status = workspace.validateName(name, IResource.PROJECT);
if (!status.isOK()) {
return status;
}
if (name.startsWith(".")) //$NON-NLS-1$
{
return new Status(
IStatus.ERROR,
TFSCommonClientPlugin.PLUGIN_ID,
Messages.getString("EclipseProjectInfo.NameStartsWithDotError")); //$NON-NLS-1$
}
return Status.OK_STATUS;
}
示例15: appendText
import org.eclipse.core.resources.IWorkspace; //導入依賴的package包/類
public synchronized void appendText(final String text)
{
try
{
ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException
{
// System.out.print(Thread.currentThread().getId() + " : " + message);
outFile.appendContents(new ByteArrayInputStream(text.getBytes()), IResource.FORCE, monitor);
}
}, rule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
// if the console output is active, print to it
} catch (CoreException e)
{
TLCActivator.logError("Error writing the TLC process output file for " + model.getName(), e);
}
}