1

I want to know whether there is any platform independent Eclipse platform API as part of IResource to open the folder or directory in Explorer. As part of eclipse plugin development, I know that it can be developed specific to OS like Windows, Mac or Linux. But I am interested to know any such functionality of Eclipse platform. Eclipse also provides such functionality as part of IDE to Show in System Explorer. You can see the following image. Basically I am interested to know about any such IResource API. In windows we can execute the command from command prompt to open the folder in explorer using explorer.exe . Please suggest me. I have also gone through the following SO links.

Eclipse show project in explorer

In eclipse, reveal current file in filesystem

enter image description here

Sambit
  • 7,625
  • 7
  • 34
  • 65

2 Answers2

3

You could call the Show in System Explorer command which has the ID org.eclipse.ui.ide.showInSystemExplorer for that.

howlger
  • 31,050
  • 11
  • 59
  • 99
  • Thanks for providing information, how can I pass folder or file path in the api? Let us say I have `IFile` or `IFolder`, I want to pass it in the api method. Besides, I am not usine eclipse e4, it is a traditional plugin. Please suggest me. By the way, for the information +1 from my side. – Sambit Jul 12 '20 at 07:51
  • @Sambit That's not e4 specific. See [here](https://stackoverflow.com/q/9666818/6505250) and [here](https://wiki.eclipse.org/Platform_Command_Framework#Executing_a_command_with_parameters). – howlger Jul 12 '20 at 08:03
2

This is the code that the Resource Info page uses:

ECommandService commandService = PlatformUI.getWorkbench().getService(ECommandService.class);
EHandlerService handlerService = PlatformUI.getWorkbench().getService(EHandlerService.class);

Command command = commandService.getCommand(ShowInSystemExplorerHandler.ID);
if (command.isDefined()) {
    ParameterizedCommand parameterizedCommand = commandService
        .createCommand(ShowInSystemExplorerHandler.ID, Collections.singletonMap(
                        ShowInSystemExplorerHandler.RESOURCE_PATH_PARAMETER, locationStr));
    if (handlerService.canExecute(parameterizedCommand)) {
        handlerService.executeHandler(parameterizedCommand);
    }
}

where locationStr is the full path of the resource.

Note the ShowInSystemExplorerHandler class is internal so accessing the static fields is really against the rules, but should be OK here or you can just copy the strings to your own constants.

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • Superb, Sir I was expecting the answer from you. – Sambit Jul 12 '20 at 08:05
  • Sir, I have posted a similar question, please help me. https://stackoverflow.com/questions/62865684/unable-to-open-multiple-selected-files-and-folders-using-eclipse-showinsystemexp – Sambit Jul 12 '20 at 19:35