Tuesday, August 23, 2011

Change the Icon of Eclipse internal XML Editor

Eclipse IDE is very popular since it can be easily configurable according to the developer's  requirements. Creating plugins for third party applications made our life too easy.So during this summer I thought of involving Google Summer of codes 2011 program and contribute for the project Apache Cayenne. Here My task was to create an external editor for Eclipse which supports Cayenne Modeler which is a Java bases application.
     There I had to deal with a bit tricky problem which I have to filter cayenne related xml files and load them with the cayenne icon.But When we double click it should be opened with default eclipse xml editor. Initially I thought it is going to be a bit harder task and thought of writing a new mxl editor for eclipse. But after few hours research i found an easy way of implementing this.
Pre-Requirements for this example : Basic knowledge is Eclipse PDE.



        
            
                
            
        



                         
            
            
         
 
As describes in above plugin.xml file we are using an external editor call "testing.other.validator" which has the content type binding called "internal.editor". In this binding it filter all xml files which has the root element as "domian-map". In your case you can ad the root element of your preferred xml files which you want to load it with your own icon. So after it find that specific xml file in your eclipse workspace it loads that xml file with the the "cayenne.png" as in above example. Once you double click on this icon the launcher is executed.(Actually it's open method is fired)

Follwoing is the Launcher class mentioned in pulugin.xml.
public void open(IPath file) {
 System.out.println("Launch Successful : file Location = "+ file.toString());
 File fileToOpen = file.toFile();
 if (fileToOpen.exists() && fileToOpen.isFile()) {
   IFileStore fileStore = EFS.getLocalFileSystem().getStore(fileToOpen.toURI());
   IWorkbenchPage page = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage( );
 try {
            // Select the appropriate internal editor and launch the file
     IDE.openInternalEditorOnFileStore(page, fileStore);
 } catch (PartInitException e) {
  logger.error("error while opening cayenne file");
     }
}

1 comment: