Thursday, 22 June 2017

Command Parameter RCP (Eclipse RCP)

Command Parameter RCP (Eclipse RCP)

Open MANIFEST.MF file and right click on the Command and select "commandParameter" from "New".

After creating "commandParameter", enter the details, like "id", "name" and make optional as "false".

After adding the parameter in the command, in View (or Editor) at the time of calling the command set the parameter. Refer the following code to set the parameter at the time of execution.

Code in View (or Editor):

ICommandService commandService = (ICommandService) getSite().getService(ICommandService.class);
IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class);

// Enter the ID of the Command as the argument to getCommand() method in next line.
Command sysoComm = commandService.getCommand("ResumeParser.commands.sampleCommand");

HashMap<String, String> paramsForCommand = new HashMap<String, String>();
// Enter the Command Parameter id as the Key in the following line.

ParameterizedCommand paramCommand = ParameterizedCommand.generateCommand(sysoCommparamsForCommand);

try {
catch (Exception ee) {

Following is the code of execute() method of the Handler (AbstractHandler) class.

* the command has been executed, so extract extract the needed information
* from the application context.
public Object execute(ExecutionEvent event) throws ExecutionException {
        // Provide the id of the "Command Parameter" as the argument of the getParameter method.
String commandValue = event.getParameter("ResumeParser.commandParameter2");
return null;


Friday, 16 June 2017

Execute Command from View/Editor in Eclipse RCP

Execute Command from View/Editor in Eclipse RCP

All Commands will be registered to IHandlerService. If we get the IHandlerService instance then we can call the desired command and then execute it.

// Get the Instance of IHandlerService from View
// Alternate way of getting site object is this also:
// PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite()
// But we prefer  following so we get the appropriate IWorkbenchPartSite object.
IHandlerService service = (IHandlerService) getSite().getService(IHandlerService.class); 
try {
service.executeCommand("ResumeParser.commands.sampleCommand", null); 
} catch (ExecutionException e1) { 
} catch (NotDefinedException e1) { 
} catch (NotEnabledException e1) { 
} catch (NotHandledException e1) { 

Sunday, 11 June 2017

Fie Dialog and Folder Dialog in Eclipse RCP

Fie Dialog and Folder Dialog in Eclipse RCP

File Dialog in Eclipse:
- This will only allow you to select the files in the Dialog Box
FileDialog fileDialog = new FileDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); // Following line is Optional if you want to, enable filter for specific files. //fileDialog.setFilterExtensions(new String[] {"*.txt","*.csv"}); String filePath =; System.out.println(filePath);

Folder Dialog in Eclipse:
- This will allow you to select the folder in the Dialog box.
DirectoryDialog directoryDialog = new DirectoryDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); // Optional - if you want to open specific path //directoryDialog.setFilterPath("/home/hv185014/junk/"); String directoryPath =; System.out.println(directoryPath);