ShowTable of Contents
The sample application in this article demonstrates how the Program API can be used to get information about the registered file extensions on the client machines and how files can be launched with the associated programs in a platform independent way.
This is how it looks like:
You get access to the Program API classes by using various methods in the
IRemoteProgramController
that you get from the ProgramAPI class:
var conn=X2E.createConnection();
var progCtrl=com.x2e.ProgramAPI.getController(conn);
The Program API wraps the functionality of the Eclipse class
Program.
File extensions
By calling
getExtensions()
you get an array of file extensions that are registered in the system.
Our sample application goes through this list and uses another method
findProgram(String)
to get the name of the associated programs:
var conn=X2E.createConnection();
var progCtrl=com.x2e.ProgramAPI.getController(conn);
var extensions=progCtrl.getExtensions();
var result="";
for (var i=0; i<extensions.length; i++) {
var currProg=progCtrl.findProgram(extensions[i]);
if (currProg!=null) {
var currProgDsp=currProg.getName();
result=result+extensions[i]+"\n\t"+currProgDsp+"\n";
}
else {
result=result+extensions[i]+"\n\t-no program found-\n";
}
}
getComponent("extensions").setValue(result);
Launch files with associated programs
To launch a file, just call the launch method with the filepath:
var path=getComponent("filePath").getValue();
if (path) {
var conn=X2E.createConnection();
var platformUI=com.x2e.PlatformUIAPI.getUI(conn);
var programCtrl=com.x2e.ProgramAPI.getController(conn);
platformUI.logToStatusBar("Launching file "+path);
programCtrl.launch(path);
}
The sample application can be downloaded
here.