如何以编程方式调用自定义导航器中节点上的“刷新”功能?
How to programmatically call the `Refresh` functionality on a node in Custom Navigator?
这与一个工具 (Software AG Web Designer) 有关,该工具在 Eclipse IDE 之上作为插件添加了功能。
如下所示,自定义导航器称为 Package Navigator
。
还可以看到在顶部节点上选择的 Refresh
按钮(在本例中为 Default
名称)。
有没有一种方法可以从我正在开发的自定义插件中以编程方式调用 Refresh
功能?
更新
我能找到的只有下面-
<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>
而 class 是 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
来执行那个命令。
您将需要为该视图调用处理程序服务,因为其他视图/编辑器对此命令有不同的处理程序。
IViewPart view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("view id");
IHandlerService handlerService = view.getSite().getService(IHandlerService.class);
handlerService.executeCommand("org.eclipse.ui.file.refresh", null);
这与一个工具 (Software AG Web Designer) 有关,该工具在 Eclipse IDE 之上作为插件添加了功能。
如下所示,自定义导航器称为 Package Navigator
。
还可以看到在顶部节点上选择的 Refresh
按钮(在本例中为 Default
名称)。
有没有一种方法可以从我正在开发的自定义插件中以编程方式调用 Refresh
功能?
更新
我能找到的只有下面-
<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>
而 class 是 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
来执行那个命令。
您将需要为该视图调用处理程序服务,因为其他视图/编辑器对此命令有不同的处理程序。
IViewPart view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("view id");
IHandlerService handlerService = view.getSite().getService(IHandlerService.class);
handlerService.executeCommand("org.eclipse.ui.file.refresh", null);