Issue
This is related to a tool(Software AG Web Designer) which has added functionalities on top of Eclipse IDE as plugins.
As seen below, the custom navigator is called Package Navigator
.
Also seen is the Refresh
button selected on the top node(Default
name in this case).
Is there a way to programmatically call the Refresh
functionality from a custom plugin which I am working on?
Update
All I am able to find is the below-
<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>
And the class is 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]);
}
}
}
}
}
}
Do you need to create its object first and then do the needful. Or is there any standard way to call the command?
Solution
This action appears to be implementing a handler for the org.eclipse.ui.file.refresh
command. So you should be able to use the IHandlerService
to execute that command.
You will need to call the handler service for that view since other views / editors will have different handlers for this command.
IViewPart view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("view id");
IHandlerService handlerService = view.getSite().getService(IHandlerService.class);
handlerService.executeCommand("org.eclipse.ui.file.refresh", null);
Answered By - greg-449