Capita spesso di dover accedere a delle informazioni di definizione di un plugin RCP a run-time. Gli esempi piu' ricorrenti sono le immagini associate ad una applicazione RCP e i dati del bundle che definisce l'applicazione stessa (ad esempio il numero di versione). RCP mette a disposizione una serie di facilities per ottenere tali informazioni.
Il primo passo consiste nell'ottenere una istanza di IProduct, dal quale si può estrarre il defining bundle e da questo la lista delle immagini configurate nel file plugin.xml. Tale lista è in realtà una stringa unica con tutte le immagini alle varie dimensioni (16x16, 32x32, 48x48, ecc.) dalla quale occorre estrarre la lista effettiva dei percorsi (relativi al bundle) delle immagini. Avendo ottenuto la lista delle immagini è possibile inserirle nella shell corrente (ad esempio uno splash screen). Il seguente blocco di codice riassume i passi da fare:

        // get the product for the running instance
        IProduct product = Platform.getProduct();
       
        // get my shell
        Shell myShell = ...
       
        // the product can be null if the running instance is launched
        // as an eclipse application (e.g., during the development)
        if( product == null )
            return;
       
        // get the bundle symbolic name
        String bundleID = product.getDefiningBundle().getSymbolicName();
        // get the array of the application icons (defined thru the product)
        // the method will return a single string with the list of images
        // used at different sizes (16x16, 32x32, 48x48 and so on). The list is
        // comma separated, so I need to extract every single item.
        String imagePaths = product.getProperty( 
                                        IProductConstants.WINDOW_IMAGES );
        List imagePathList = new LinkedList();
        StringTokenizer commaTokenizer = new StringTokenizer(imagePaths, ",");
        while( commaTokenizer.hasMoreTokens() )
        imagePathList.add( commaTokenizer.nextToken() );
       
        // now that I've got the list of image paths (separated) 
        // I can create every
        // single image using an ImageDescriptor
        Image[] windowImages = new Image[ imagePathList.size() ];
        for( int i = 0; i < imagePathList.size(); i++ ){
           ImageDescriptor currentDescriptor =                    
               AbstractUIPlugin.imageDescriptorFromPlugin(    bundleID, 
                                                imagePathList.get(i) );
               windowImages[ i ] = currentDescriptor.createImage();
        }
       
        // now set the images for this window
        myShell.setImages( windowImages );




Analogamente, se si volessero ottenere informazioni circa la versione e il nome dell'applicativo si puo' usare il seguente pezzo di codice:


Bundle definingBundle = product.getDefiningBundle();
Label valueLabel = new Label(  definingBundle.getSymbolicName() );
Label versionLabel = new Label( definingBundle.getVersion().toString() );

o se si vuole cambiare il titolo della finestra principale del workspace affinché rifletta tali informazioni è sufficiente, nel metodo ApplicationWorkbenchWindowAdvisor.preWindowOpen() il seguente blocco di codice:

   // get the window configurer object
    IWorkbenchWindowConfigurer configurer = this.getWindowConfigurer();

   
   
    // set the title of the window
    StringBuffer title = new StringBuffer( 100 );
    title.append( "My App" );    // the fixed part of the title
   
    // get the information from the product
    IProduct product = Platform.getProduct();
    if( product == null )
        title.append( " [Eclipse Application - Development]" );
    else{
        title.append( " [RCP Product -" );
        title.append( product.getName() );
        title.append( " ~~ " );
       
        // get some information from the bundle
        Bundle definingBundle = product.getDefiningBundle();
        title.append(" ID: " );
        title.append( definingBundle.getSymbolicName() );
        title.append(" ~~ Ver.: " );
        title.append( definingBundle.getVersion() );
    }
   
    // set the real title
    configurer.setTitle( title.toString() );

The article RCP: ottenere le informazioni di plugin a run-time (immagini e versione del prodotto) has been posted by Luca Ferrari on November 10, 2010