Search in sources :

Example 1 with DeleteResourceChange

use of org.eclipse.ltk.core.refactoring.resource.DeleteResourceChange in project che by eclipse.

the class CreateFileChange method perform.

@Override
public Change perform(IProgressMonitor pm) throws CoreException, OperationCanceledException {
    InputStream is = null;
    try {
        pm.beginTask(NLSChangesMessages.createFile_creating_resource, 3);
        initializeEncoding();
        IFile file = getOldFile(new SubProgressMonitor(pm, 1));
        /*
			if (file.exists()) {
				CompositeChange composite= new CompositeChange(getName());
				composite.add(new DeleteFileChange(file));
				composite.add(new CreateFileChange(fPath, fSource, fEncoding, fStampToRestore, fExplicitEncoding));
				pm.worked(1);
				return composite.perform(new SubProgressMonitor(pm, 1));
			} else { */
        try {
            is = new ByteArrayInputStream(fSource.getBytes(fEncoding));
            file.create(is, false, new SubProgressMonitor(pm, 1));
            if (fStampToRestore != IResource.NULL_STAMP) {
                file.revertModificationStamp(fStampToRestore);
            }
            if (fExplicitEncoding) {
                file.setCharset(fEncoding, new SubProgressMonitor(pm, 1));
            } else {
                pm.worked(1);
            }
            return new DeleteResourceChange(file.getFullPath(), true);
        } catch (UnsupportedEncodingException e) {
            throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION);
        }
    } finally {
        try {
            if (is != null)
                is.close();
        } catch (IOException ioe) {
            throw new JavaModelException(ioe, IJavaModelStatusConstants.IO_EXCEPTION);
        } finally {
            pm.done();
        }
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DeleteResourceChange(org.eclipse.ltk.core.refactoring.resource.DeleteResourceChange) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 2 with DeleteResourceChange

use of org.eclipse.ltk.core.refactoring.resource.DeleteResourceChange in project che by eclipse.

the class UndoDeleteResourceChange method perform.

@Override
public Change perform(IProgressMonitor pm) throws CoreException {
    IResource created = fResourceDescription.createResource(pm);
    created.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(pm, 1));
    return new DeleteResourceChange(created.getFullPath(), true);
}
Also used : DeleteResourceChange(org.eclipse.ltk.core.refactoring.resource.DeleteResourceChange) IResource(org.eclipse.core.resources.IResource) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 3 with DeleteResourceChange

use of org.eclipse.ltk.core.refactoring.resource.DeleteResourceChange in project che by eclipse.

the class CreatePackageChange method perform.

@Override
public Change perform(IProgressMonitor pm) throws CoreException {
    try {
        pm.beginTask(RefactoringCoreMessages.CreatePackageChange_Creating_package, 1);
        if (fPackageFragment.exists()) {
            return new NullChange();
        } else {
            IPackageFragmentRoot root = (IPackageFragmentRoot) fPackageFragment.getParent();
            root.createPackageFragment(fPackageFragment.getElementName(), false, pm);
            return new DeleteResourceChange(fPackageFragment.getPath(), true);
        }
    } finally {
        pm.done();
    }
}
Also used : NullChange(org.eclipse.ltk.core.refactoring.NullChange) DeleteResourceChange(org.eclipse.ltk.core.refactoring.resource.DeleteResourceChange) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 4 with DeleteResourceChange

use of org.eclipse.ltk.core.refactoring.resource.DeleteResourceChange in project bndtools by bndtools.

the class CreateFileChange method perform.

@Override
public Change perform(IProgressMonitor monitor) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, encoding != null ? 2 : 1);
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IFile file = root.getFile(path);
    file.create(source, updateFlags, progress.newChild(1, SubMonitor.SUPPRESS_NONE));
    if (encoding != null)
        file.setCharset(encoding, progress.newChild(1, SubMonitor.SUPPRESS_NONE));
    return new DeleteResourceChange(path, true);
}
Also used : IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) SubMonitor(org.eclipse.core.runtime.SubMonitor) DeleteResourceChange(org.eclipse.ltk.core.refactoring.resource.DeleteResourceChange)

Example 5 with DeleteResourceChange

use of org.eclipse.ltk.core.refactoring.resource.DeleteResourceChange in project che by eclipse.

the class DeleteResourcesProcessor method createChange.

/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#createChange(org.eclipse.core.runtime.IProgressMonitor)
	 */
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
    pm.beginTask(RefactoringCoreMessages.DeleteResourcesProcessor_create_task, fResources.length);
    try {
        RefactoringChangeDescriptor descriptor = new RefactoringChangeDescriptor(createDescriptor());
        CompositeChange change = new CompositeChange(RefactoringCoreMessages.DeleteResourcesProcessor_change_name);
        change.markAsSynthetic();
        for (int i = 0; i < fResources.length; i++) {
            pm.worked(1);
            DeleteResourceChange dc = new DeleteResourceChange(fResources[i].getFullPath(), true, fDeleteContents);
            dc.setDescriptor(descriptor);
            change.add(dc);
        }
        return change;
    } finally {
        pm.done();
    }
}
Also used : DeleteResourceChange(org.eclipse.ltk.core.refactoring.resource.DeleteResourceChange) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor)

Aggregations

DeleteResourceChange (org.eclipse.ltk.core.refactoring.resource.DeleteResourceChange)6 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)3 IFile (org.eclipse.core.resources.IFile)2 IResource (org.eclipse.core.resources.IResource)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 CompositeChange (org.eclipse.ltk.core.refactoring.CompositeChange)1 NullChange (org.eclipse.ltk.core.refactoring.NullChange)1 RefactoringChangeDescriptor (org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor)1 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)1