Search in sources :

Example 1 with RenameResourceProcessor

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

the class RenameResourceDescriptor method createRefactoring.

/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.RefactoringDescriptor#createRefactoring(org.eclipse.ltk.core.refactoring.RefactoringStatus)
	 */
public Refactoring createRefactoring(RefactoringStatus status) throws CoreException {
    IPath resourcePath = getResourcePath();
    if (resourcePath == null) {
        status.addFatalError(RefactoringCoreMessages.RenameResourceDescriptor_error_path_not_set);
        return null;
    }
    IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(resourcePath);
    if (resource == null || !resource.exists()) {
        status.addFatalError(Messages.format(RefactoringCoreMessages.RenameResourceDescriptor_error_resource_not_existing, BasicElementLabels.getPathLabel(resourcePath, false)));
        return null;
    }
    String newName = getNewName();
    if (newName == null || newName.length() == 0) {
        status.addFatalError(RefactoringCoreMessages.RenameResourceDescriptor_error_name_not_defined);
        return null;
    }
    RenameResourceProcessor processor = new RenameResourceProcessor(resource);
    processor.setNewResourceName(newName);
    processor.setUpdateReferences(isUpdateReferences());
    return new RenameRefactoring(processor);
}
Also used : RenameResourceProcessor(org.eclipse.ltk.internal.core.refactoring.resource.RenameResourceProcessor) IPath(org.eclipse.core.runtime.IPath) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) IResource(org.eclipse.core.resources.IResource)

Example 2 with RenameResourceProcessor

use of org.eclipse.ltk.internal.core.refactoring.resource.RenameResourceProcessor in project tdi-studio-se by Talend.

the class ChangeProjectTechinicalNameMigrationTask method renameProject.

/**
     * 
     * DOC ggu Comment method "renameProject".
     * 
     * @param localProject
     * @param newProjectName
     * @return
     */
@SuppressWarnings("restriction")
protected boolean renameProject(IProject localProject, String newProjectName) {
    RenameResourceProcessor renameProcessor = new RenameResourceProcessor(localProject);
    renameProcessor.setNewResourceName(newProjectName);
    CheckConditionsOperation condictionOperation = new CheckConditionsOperation(new RenameRefactoring(renameProcessor), CheckConditionsOperation.FINAL_CONDITIONS);
    CreateChangeOperation operation = new CreateChangeOperation(condictionOperation, RefactoringCore.getConditionCheckingFailedSeverity());
    PerformChangeOperation performChangeOp = new PerformChangeOperation(operation);
    try {
        performChangeOp.run(null);
    } catch (CoreException e) {
        ExceptionHandler.process(e);
        return false;
    }
    return true;
}
Also used : CreateChangeOperation(org.eclipse.ltk.core.refactoring.CreateChangeOperation) PerformChangeOperation(org.eclipse.ltk.core.refactoring.PerformChangeOperation) RenameResourceProcessor(org.eclipse.ltk.internal.core.refactoring.resource.RenameResourceProcessor) CoreException(org.eclipse.core.runtime.CoreException) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) CheckConditionsOperation(org.eclipse.ltk.core.refactoring.CheckConditionsOperation)

Example 3 with RenameResourceProcessor

use of org.eclipse.ltk.internal.core.refactoring.resource.RenameResourceProcessor in project xtext-xtend by eclipse.

the class AbstractXtendRenameRefactoringTest method renameTo.

protected IFile renameTo(IFile file, String newFileName, IProgressMonitor monitor) throws OperationCanceledException, CoreException {
    RenameResourceProcessor renameResourceProcessor = new RenameResourceProcessor(file);
    renameResourceProcessor.setNewResourceName(newFileName);
    RenameRefactoring renameRefactoring = new RenameRefactoring(renameResourceProcessor);
    renameRefactoring.checkAllConditions(monitor);
    Change change = renameRefactoring.createChange(monitor);
    workspace.run(new ICoreRunnable() {

        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            change.perform(monitor);
        }
    }, monitor);
    IResource newFile = testHelper.getProject().findMember(new Path("src/" + newFileName));
    assertTrue(newFile.exists());
    assertTrue(newFile instanceof IFile);
    return (IFile) newFile;
}
Also used : Path(org.eclipse.core.runtime.Path) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) RenameResourceProcessor(org.eclipse.ltk.internal.core.refactoring.resource.RenameResourceProcessor) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) ICoreRunnable(org.eclipse.core.runtime.ICoreRunnable) Change(org.eclipse.ltk.core.refactoring.Change) IResource(org.eclipse.core.resources.IResource)

Example 4 with RenameResourceProcessor

use of org.eclipse.ltk.internal.core.refactoring.resource.RenameResourceProcessor in project mdw-designer by CenturyLinkCloud.

the class WorkflowProjectManager method renameRemoteProject.

public static void renameRemoteProject(WorkflowProject workflowProject, String newName) {
    if (!workflowProject.isRemote())
        throw new RuntimeException("Can only rename remote projects");
    try {
        deRegisterProject(workflowProject);
        IProject workflowSourceProject = workflowProject.getSourceProject();
        if (workflowSourceProject != null && workflowSourceProject.exists()) {
            RenameResourceProcessor renameProc = new RenameResourceProcessor(workflowSourceProject);
            renameProc.setNewResourceName(newName);
            RenameRefactoring refactoring = new RenameRefactoring(renameProc);
            refactoring.checkAllConditions(new NullProgressMonitor());
            Change change = refactoring.createChange(new NullProgressMonitor());
            change.perform(new NullProgressMonitor());
        }
        workflowProject.setSourceProjectName(newName);
        registerProject(workflowProject);
    } catch (CoreException ex) {
        // fail silently since older remote projects don't have physical
        // counterparts
        PluginMessages.log(ex);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RenameResourceProcessor(org.eclipse.ltk.internal.core.refactoring.resource.RenameResourceProcessor) CoreException(org.eclipse.core.runtime.CoreException) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) Change(org.eclipse.ltk.core.refactoring.Change) IProject(org.eclipse.core.resources.IProject)

Aggregations

RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)4 RenameResourceProcessor (org.eclipse.ltk.internal.core.refactoring.resource.RenameResourceProcessor)4 CoreException (org.eclipse.core.runtime.CoreException)3 IResource (org.eclipse.core.resources.IResource)2 Change (org.eclipse.ltk.core.refactoring.Change)2 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 ICoreRunnable (org.eclipse.core.runtime.ICoreRunnable)1 IPath (org.eclipse.core.runtime.IPath)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Path (org.eclipse.core.runtime.Path)1 CheckConditionsOperation (org.eclipse.ltk.core.refactoring.CheckConditionsOperation)1 CreateChangeOperation (org.eclipse.ltk.core.refactoring.CreateChangeOperation)1 PerformChangeOperation (org.eclipse.ltk.core.refactoring.PerformChangeOperation)1