Java Code Examples for org.eclipse.core.resources.IFile#isLinked()

The following examples show how to use org.eclipse.core.resources.IFile#isLinked() . These examples are extracted from open source projects. 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 Project: tlaplus   File: ResourceHelper.java    License: MIT License 6 votes vote down vote up
public static IFile getLinkedFileUnchecked(IContainer project, String name, boolean createNew) throws CoreException
{
    if (name == null || project == null)
    {
        return null;
    }
    IPath location = new Path(name);
    IFile file = project.getFile(new Path(location.lastSegment()));
    if (createNew)
    {
        if (!file.isLinked())
        {
                file.createLink(location, IResource.NONE, new NullProgressMonitor());
                return file;
        }
        if (file.exists())
        {
            return file;
        } else
        {
            return null;
        }
    }
    return file;
}
 
Example 2
Source Project: gama   File: FileOpener.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static IEditorPart openFileInWorkspace(final URI uri) throws PartInitException {
	final IFile file = FileUtils.getWorkspaceFile(uri);
	if (file == null) {
		MessageDialog.openWarning(WorkbenchHelper.getShell(), "No file found",
				"The file'" + uri.toString() + "' cannot be found.");
		return null;
	}
	if (file.isLinked()) {
		if (!NavigatorRoot.getInstance().getManager().validateLocation(file)) {
			MessageDialog.openWarning(WorkbenchHelper.getShell(), "No file found", "The file'"
					+ file.getRawLocation() + "' referenced by '" + file.getName() + "' cannot be found.");
			return null;
		}
	}
	return IDE.openEditor(PAGE, file);
}
 
Example 3
Source Project: uima-uimaj   File: DocumentUimaImpl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Sets the content. The XCAS {@link InputStream} gets parsed.
 *
 * @param casFile the new content
 * @throws CoreException the core exception
 */
private void setContent(IFile casFile) throws CoreException {

  IPreferenceStore store = CasEditorPlugin.getDefault().getPreferenceStore();
  boolean withPartialTypesystem = store
          .getBoolean(AnnotationEditorPreferenceConstants.ANNOTATION_EDITOR_PARTIAL_TYPESYSTEM);

  URI uri = casFile.getLocationURI();
  if (casFile.isLinked()) {
    uri = casFile.getRawLocationURI();
  }
  File file = EFS.getStore(uri).toLocalFile(0, new NullProgressMonitor());
  try {
    format = CasIOUtils.load(file.toURI().toURL(), null, mCAS, withPartialTypesystem);
  } catch (IOException e) {
    throwCoreException(e);
  }

}
 
Example 4
Source Project: tlaplus   File: ResourceHelper.java    License: MIT License 5 votes vote down vote up
/**
 * Retrieves a a resource from the project, creates a link if createNew is true and the file is not present 
 * TODO improve this, if the name is wrong
 * 
 * @param name full filename of the resource
 * @param project
 * @param createNew, a boolean flag indicating if the new link should be created if it does not exist
 */
public static IFile getLinkedFile(IContainer project, String name, boolean createNew)
{
    if (name == null || project == null)
    {
        return null;
    }
    IPath location = new Path(name);
    IFile file = project.getFile(new Path(location.lastSegment()));
    if (createNew)
    {
        if (!file.isLinked())
        {
            try
            {
                file.createLink(location, IResource.NONE, new NullProgressMonitor());
                return file;

            } catch (CoreException e)
            {
                Activator.getDefault().logError("Error creating resource link to " + name, e);
            }
        }
        if (file.exists())
        {
            return file;
        } else
        {
            return null;
        }
    }
    return file;
}
 
Example 5
IFile createUnclassifiedModelsProjectAndAdd(final IPath location) {
	IFile iFile = null;
	try {
		final IFolder modelFolder = createUnclassifiedModelsProject(location);
		iFile = modelFolder.getFile(location.lastSegment());
		if ( iFile.exists() ) {
			if ( iFile.isLinked() ) {
				final IPath path = iFile.getLocation();
				if ( path.equals(location) ) {
					// First case, this is a linked resource to the same location. In that case, we simply return
					// its name.
					return iFile;
				} else {
					// Second case, this resource is a link to another location. We create a filename that is
					// guaranteed not to exist and change iFile accordingly.
					iFile = createUniqueFileFrom(iFile, modelFolder);
				}
			} else {
				// Third case, this resource is local and we do not want to overwrite it. We create a filename that
				// is guaranteed not to exist and change iFile accordingly.
				iFile = createUniqueFileFrom(iFile, modelFolder);
			}
		}
		iFile.createLink(location, IResource.NONE, null);
		// RefreshHandler.run();
		return iFile;
	} catch (final CoreException e) {
		e.printStackTrace();
		MessageDialog.openInformation(Display.getDefault().getActiveShell(), "Error in creation",
			"The file " + (iFile == null ? location.lastSegment() : iFile.getFullPath().lastSegment()) +
				" cannot be created because of the following exception " + e.getMessage());
		return null;
	}
}
 
Example 6
public boolean validateLocation(final IFile resource) {
	if (!resource.isLinked()) { return true; }
	if (DEBUG.IS_ON()) {
		DEBUG.OUT("Validating link location of " + resource);
	}
	final boolean internal =
			ResourcesPlugin.getWorkspace().validateLinkLocation(resource, resource.getLocation()).isOK();
	if (!internal) { return false; }
	final IFileStore file = EFS.getLocalFileSystem().getStore(resource.getLocation());
	final IFileInfo info = file.fetchInfo();
	return info.exists();
}
 
Example 7
Source Project: tlaplus   File: ResourceHelper.java    License: MIT License 2 votes vote down vote up
/**
 * Projects can have linked files (resources more generally). Linked resources a listed in the
 * project's .project metadata.
 * 
 * @param project The project of which the given file (name) is assumed to be a linked file
 * @param name The name of the link
 * @return true iff the given name is indeed a *linked* file of the given project.
 */
public static boolean isLinkedFile(IProject project, String name) throws CoreException {
       final IFile file = project.getFile(new Path(new Path(name).lastSegment()));
       return file.isLinked(IResource.CHECK_ANCESTORS);
}