Reputation: 665
How can I add my own implementation to Rename context menu of eclipse explorer view. When I click on Rename I want to do some verification before I rename the project
<extension
point="org.eclipse.ltk.core.refactoring.renameParticipants">
<renameParticipant
class="core.ui.project.RenameProject"
id="core.ui.renameParticipant"
name="Rename">
</renameParticipant>
public class RenameProject extends RenameParticipant {
@Override
protected boolean initialize(Object element) {
System.out.println("HERE");
return false;
}
@Override
public String getName() {
System.out.println("HERE");
return null;
}
@Override
public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context)
throws OperationCanceledException {
System.out.println("HERE");
return null;
}
@Override
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
System.out.println("HERE");
return null;
}
}
Thanks
Upvotes: 0
Views: 120
Reputation: 111142
You don't need to change the implementation of the menu in order to verify something during a rename.
Instead use the org.eclipse.ltk.core.refactoring.renameParticipants
extension point to define a 'rename participant' which will be called during rename operations. The participant can check that the rename is valid and add additional work to be done during the rename.
The participant code extends the org.eclipse.ltk.core.refactoring.participants.RenameParticipant
class which is in the org.eclipse.ltk.core.refactoring
plug-in.
There are also participants for create, copy, move and delete.
An example participant for file renames from the Ant plugin:
<extension point="org.eclipse.ltk.core.refactoring.renameParticipants">
<renameParticipant
class="org.eclipse.ant.internal.ui.refactoring.LaunchConfigurationBuildfileRenameParticipant"
name="%AntRenameParticipant.name"
id="org.eclipse.ant.ui.refactoring.launchConfiguration.buildfileRename">
<enablement>
<with variable="element">
<instanceof value="org.eclipse.core.resources.IFile"/>
</with>
</enablement>
</renameParticipant>
Upvotes: 1