The uDig "application model" is maintained with EMF (the eclipse modeling framework). As such it is very easy to morph uDig to meet your needs. That is the good part. The bad part is uDig (indeed all EMF projects) do not look that "normal", and trying to tell when something changes falls into the this category. Step 0 - Look for a ListenerWe have set up add/remove listener methods as people request them: layer.addListener( new ILayerListener(){ public refresh( LayerEvent event ){ if( event.getType() == LayerEvent.EventType.STYLE ){ ILayer layer = event.getSource(); IStyleBlackboard style = (IStyleBlackboard ) event.getNewValue(); // layer has changed style } } }); Step 1 - Ask for HelpEmail the list and ask "How to I tell when this changes". We will set up a normal add/remove listener. Step 2 - Use an AdapterOn the off chance you have a deadline, and need to figure it out now you can listen to anything using the following code example: Example: layer.eAdapters().add( new AdapterImpl(){ public void notifyChanged( Notificaiton msg ) { if( msg.getNotifier() instnaceof Layer ){ Layer layer = (Layer) msg.getNotifier(); switch( msg.getFeatureID(Layer.class) ) { case ProjectPackage.LAYER__NAME: System.out.println( layer.getName() +" renamed"); break; case ProjectPackage.LAYER__GEO_RESOURCES: System.out.println( "We have new data!"); FeatureType schema = layer.getSchema(); if( schema != null ){ System.out.println( "changed to "+schema.getTypeName() ); } break; } } } }); Backgroun: an adapter is a traditional pater when you want to use one data model and "morph" it to fit another interface. One of the side effects of this is you need to pay attention to the origional data, and pass any changes along. You can see lots of examples of this idea in Java code. People setting up custom JTreeModels to visualize an internal data structure etc... Since this need happens all the time the EMF crew decided design for it in mind. It is a much more difficult, and interesting, problem them simply listening for changes (Indeed it is a superset of change notification - basically change notification with interface change). The benifit is that you can "force" EMF models (and thus uDig) into about anything. So the above example is "an adapter", and we are only paying attention to the changes. Examples of AnythingHere is how you can watch the "Viewport Model" (ie. Zoom, Pan, CRS): map.getViewportModel().addViewportModelListener(new IViewportModelListener()){ public void changed(ViewportModel event){ if( event.getType()==EventType.CRS } // crs has changed do something else if( event.getType()==EventType.BOUNDS ){ // bounds have changed do something else } } } |
(c) Copyright (c) 2004,2005 Refractions Research Inc. and others. |