

import cds.aladin.*;

public class CatalogManipulationPlug extends AladinPlugin {
   
   public String menu()        { return "Column creation"; }
   public String description() {
      return "PLUGIN TUTORIAL:\n" +
      "This plugin is an example for manipulating the catalog sources.\n" +
      "It will add a new column to a catalog and will set values";
   }   
   public String category()    { return "Plugin tutorial/Catalog"; }
   public String version()     { return "1.0 - January 2007"; }
   public String author()      { return "Pierre Fernique [CDS]"; }
   public String url()         { return "http://aladin.u-strasbg.fr/java/Plugins/CatalogManipulationPlug.java"; }
   
   public void exec() {
      
      try {
         // Access to the selected catalog plane
         AladinData ad = aladin.getAladinData();
         int n = ad.getNbObj();
         if( n==0 ) return;
         
         // Access to the catalog objects
         Obj [] o = ad.seeObj();
         
         // Add a new column on one object of this catalog
         // => these metadata will be automatically set for all other objects of the same table
         Obj source1 = o[0];
         int pos = source1.getSize();
         source1.setColumn(pos,"My Column","Km/s","phys.veloc",15);
         
         // Add new column values
         for( int i=0; i<n; i++ ) {
            o[i].setValue(pos,"My value "+i);
            o[i].setSelected(true) ;
         }

         // Notify to Aladin that catalog plane has been modified
         ad.objModified();
         
      } catch( AladinException e ) { 
         aladin.warning("Plugin error: "+e.getMessage()+"\n" +
                        "You have to selected the concerned catalog plane !");
      }
   }
}