java - 如何以编程方式调用自定义导航器中节点上的 `Refresh` 功能?

标签 java eclipse eclipse-plugin swt

这与一个工具(Software AG Web Designer)相关,该工具以插件的形式在 Eclipse IDE 之上添加了功能。

如下所示,自定义导航器称为Package Navigator。 还可以看到在顶部节点上选择的Refresh 按钮(在本例中为Default 名称)。

有没有办法以编程方式从我正在开发的自定义插件中调用Refresh功能?

enter image description here

<小时/>

更新

我能找到的就是以下内容-

enter image description here

<extension
         point="org.eclipse.ui.popupMenus">
      <objectContribution
            adaptable="false"
            id="com.softwareag.is.ui.navigator.actions.refresh"
            objectClass="com.softwareag.is.ui.navigator.model.ISLazyTreeParent">
         <action
               class="com.softwareag.is.ui.navigator.actions.RefreshFromServerAction"
               definitionId="org.eclipse.ui.file.refresh"
               enablesFor="1"
               helpContextId="org.eclipse.ui.edit.delete"
               icon="icons/tree/refresh.gif"
               id="com.softwareag.is.ui.navigator.actions.refresh"
               label="%refresh_label"
               menubarPath="group.edit"
               tooltip="%refresh_tooltip">
          </action>
          <enablement>
            <or>
                <test property="com.softwareag.is.navigator.property.vcsEnabled"
                    value="true" forcePluginActivation="true"/>
                <test property="com.softwareag.is.navigator.property.vcsNotEnabled"
                    value="true" forcePluginActivation="true"/>
            </or>
          </enablement>
      </objectContribution> 

该类是RefreshFromServerAction-

public class RefreshFromServerAction extends Action implements IActionDelegate {
    private IStructuredSelection selection;

    public RefreshFromServerAction() {
        this.selection = StructuredSelection.EMPTY;
        this.setId(ActionFactory.REFRESH.getId());
        this.setActionDefinitionId("org.eclipse.ui.file.refresh");
    }

    public void selectionChanged(IAction action, ISelection sel) {
        if (sel instanceof IStructuredSelection) {
            this.selection = (IStructuredSelection) sel;
        } else {
            this.selection = StructuredSelection.EMPTY;
        }

    }

    public void run() {
        this.run((IAction) null);
    }

    public void run(IAction action) {
        ISServerNode[] servers = AssetUtils.getSelectedServersFromSelection(this.selection);
        if (servers != null) {
            NavigatorHelper.getInstance().setExpandAllPath((ISServerObjectBase) null, (ISServerNode) null);
            List<ISServerNode> refreshedServers = new ArrayList();

            for (int i = 0; i < servers.length; ++i) {
                if (!refreshedServers.contains(servers[i])) {
                    ServerConnection serverConnection = servers[i].getServerConnection();
                    if (serverConnection != null && !serverConnection.isConnected()) {
                        return;
                    }

                    ISTreeParent[] selectedAssetsFromSelection = AssetUtils
                            .getSelectedAssetsFromSelection(this.selection);
                    ISTreeParent[] var7 = selectedAssetsFromSelection;
                    int var8 = selectedAssetsFromSelection.length;

                    for (int var9 = 0; var9 < var8; ++var9) {
                        ISTreeParent isTreeParent = var7[var9];
                        ServerElementsCache.getInstance().clearCache(serverConnection, isTreeParent);
                    }

                    if ((new ISAssetSaver()).askAndSaveDirtyEditors(servers[i].getServerConnection())) {
                        ISNavigatorPlugin.getDefault().notifyListeners(new NavigatorEvent(5, servers[i], this));
                        refreshedServers.add(servers[i]);
                    }
                }
            }

        }
    }
}

是否需要先创建它的对象,然后再执行需要的操作。或者有没有标准的方法来调用命令?

最佳答案

此操作似乎正在实现 org.eclipse.ui.file.refresh 命令的处理程序。因此,您应该能够使用 IHandlerService 来执行该命令。

您将需要调用该 View 的处理程序服务,因为其他 View /编辑器对此命令将具有不同的处理程序。

IViewPart view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("view id"); 

IHandlerService handlerService = view.getSite().getService(IHandlerService.class);

handlerService.executeCommand("org.eclipse.ui.file.refresh", null);

关于java - 如何以编程方式调用自定义导航器中节点上的 `Refresh` 功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60599139/

相关文章:

java - Java中关闭静态资源

java - 整个矩阵的 block 列表 - java

java - 如何在不添加 IE 驱动程序或 Chrome 驱动程序的情况下启动已安装的浏览器?

php - apache/2.4.29 (ubuntu) 服务器在 localhost 端口 80

javascript - Eclipse 中的 HTML/JavaScript 调试

java - 无法在 itextSharp 5.5/Prop_Build 中添加签名创建器未正确渲染

java - 通过在 Eclipse 中突出显示方法名称,将测试方法添加到现有测试用例

java - 从 MySQL 数据库验证散列密码

java - 如何使用 Maven 构建 SonarLint 源代码?

Eclipse XWT 已投入生产?