java - 重命名前保存更改

标签 java eclipse eclipse-rcp rcp

如何将我自己的实现添加到 Eclipse 资源管理器 View 的重命名上下文菜单。当我单击“重命名”时,我想在重命名项目之前进行一些验证

  <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;
}

}

谢谢

最佳答案

您无需更改菜单的实现即可在重命名期间验证某些内容。

而是使用org.eclipse.ltk.core.refactoring.renameParticipants扩展点来定义将在重命名操作期间调用的“重命名参与者”。参与者可以检查重命名是否有效,并在重命名期间添加要完成的其他工作。

参与者代码扩展了 org.eclipse.ltk.core.refactoring.participants.RenameParticipant org.eclipse.ltk.core.refactoring 中的类插件。

还有创建、复制、移动和删除的参与者。

通过 Ant 插件进行文件重命名的示例参与者:

<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>

关于java - 重命名前保存更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56338551/

相关文章:

java - 实例A = 实例B,这到底是做什么的?

eclipse - IBM TRIRIGA BIRT 功能在 Eclipse 3.6.2 中安装后不显示

java - 按源文件夹过滤调用层次结构

java - Bndtools:准备运行时环境时出现问题

java - Dockerize Java Cucumber

java - 来自 vertx RoutingContext 的 KeycloakSecurityContext

java - 为什么要在包上使用许多子项目和依赖项?

java - Eclipse RCP 并通过透视图和 View 进行迭代

java - SWT 堆积条形图显示总值

java - 在 RCP 插件中哪里可以找到notes.exe