Search in sources :

Example 41 with IWorkspace

use of org.eclipse.core.resources.IWorkspace in project eclipse.platform.text by eclipse.

the class FileDocumentProvider method handleElementMoved.

/**
 * Sends out the notification that the file serving as document input has been moved.
 *
 * @param fileEditorInput the input of an text editor
 * @param path the path of the new location of the file
 */
protected void handleElementMoved(IFileEditorInput fileEditorInput, IPath path) {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IFile newFile = workspace.getRoot().getFile(path);
    fireElementMoved(fileEditorInput, new FileEditorInput(newFile));
}
Also used : IFile(org.eclipse.core.resources.IFile) IWorkspace(org.eclipse.core.resources.IWorkspace) IFileEditorInput(org.eclipse.ui.IFileEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput)

Example 42 with IWorkspace

use of org.eclipse.core.resources.IWorkspace in project eclipse.platform.text by eclipse.

the class FileDocumentProvider method doValidateState.

@Override
protected void doValidateState(Object element, Object computationContext) throws CoreException {
    if (element instanceof IFileEditorInput) {
        IFileEditorInput input = (IFileEditorInput) element;
        FileInfo info = (FileInfo) getElementInfo(input);
        if (info != null) {
            IFile file = input.getFile();
            if (file.isReadOnly()) {
                // do not use cached state here
                IWorkspace workspace = file.getWorkspace();
                info.fStatus = workspace.validateEdit(new IFile[] { file }, computationContext);
            }
            if (isDerived(file)) {
                IStatus status = new Status(IStatus.WARNING, EditorsUI.PLUGIN_ID, EditorsUI.DERIVED_FILE, TextEditorMessages.FileDocumentProvider_warning_fileIsDerived, null);
                if (info.fStatus == null || info.fStatus.isOK())
                    info.fStatus = status;
                else
                    info.fStatus = new MultiStatus(EditorsUI.PLUGIN_ID, EditorsUI.STATE_VALIDATION_FAILED, new IStatus[] { info.fStatus, status }, TextEditorMessages.FileDocumentProvider_stateValidationFailed, null);
            }
        }
    }
    super.doValidateState(element, computationContext);
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IResourceStatus(org.eclipse.core.resources.IResourceStatus) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) IFileEditorInput(org.eclipse.ui.IFileEditorInput) IWorkspace(org.eclipse.core.resources.IWorkspace) MultiStatus(org.eclipse.core.runtime.MultiStatus)

Example 43 with IWorkspace

use of org.eclipse.core.resources.IWorkspace in project eclipse.platform.text by eclipse.

the class ResourceHelper method createLinkedProject.

public static 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 = FileTool.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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) File(java.io.File) IFile(org.eclipse.core.resources.IFile) ZipFile(java.util.zip.ZipFile) IProject(org.eclipse.core.resources.IProject)

Example 44 with IWorkspace

use of org.eclipse.core.resources.IWorkspace in project eclipse.platform.text by eclipse.

the class NatureLabelHoverProvider method getHoverInfo.

@Override
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
    String contents = textViewer.getDocument().get();
    int offset = hoverRegion.getOffset();
    int endIndex = contents.indexOf("</nature>", offset);
    if (endIndex == -1)
        return "";
    int startIndex = contents.substring(0, offset).lastIndexOf("<nature>");
    if (startIndex == -1)
        return "";
    String selection = contents.substring(startIndex + "<nature>".length(), endIndex);
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IProjectNatureDescriptor[] natureDescriptors = workspace.getNatureDescriptors();
    for (int i = 0; i < natureDescriptors.length; i++) {
        if (natureDescriptors[i].getNatureId().equals(selection))
            return natureDescriptors[i].getLabel();
    }
    return null;
}
Also used : IProjectNatureDescriptor(org.eclipse.core.resources.IProjectNatureDescriptor) IWorkspace(org.eclipse.core.resources.IWorkspace)

Example 45 with IWorkspace

use of org.eclipse.core.resources.IWorkspace in project eclipse.platform.text by eclipse.

the class ResourceHelper method createLinkedProject.

public static 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 = FileTool.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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) File(java.io.File) IFile(org.eclipse.core.resources.IFile) IProject(org.eclipse.core.resources.IProject)

Aggregations

IWorkspace (org.eclipse.core.resources.IWorkspace)118 IProject (org.eclipse.core.resources.IProject)55 CoreException (org.eclipse.core.runtime.CoreException)54 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)37 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)36 IPath (org.eclipse.core.runtime.IPath)35 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)29 IStatus (org.eclipse.core.runtime.IStatus)27 IFile (org.eclipse.core.resources.IFile)24 PersistenceException (org.talend.commons.exception.PersistenceException)23 IProjectDescription (org.eclipse.core.resources.IProjectDescription)21 File (java.io.File)19 InvocationTargetException (java.lang.reflect.InvocationTargetException)19 Path (org.eclipse.core.runtime.Path)19 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)19 IResource (org.eclipse.core.resources.IResource)18 Status (org.eclipse.core.runtime.Status)14 IOException (java.io.IOException)13 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)13 ArrayList (java.util.ArrayList)12