layerInterceptor

Identifier:
net.refractions.udig.project.layerInterceptor

Since:
1.1

Description:
Layer Interceptors allow customized actions to be executed at certain points in a Layer's life cycle. The points available are: Layer creation, Layer being added to a Map and layer being removed from a map.

Configuration Markup:

<!ELEMENT extension (layerAdded | layerCreated | layerRemoved)*>

<!ATTLIST extension

point CDATA #REQUIRED

id    CDATA #IMPLIED

name  CDATA #IMPLIED

>


<!ELEMENT layerCreated EMPTY>

<!ATTLIST layerCreated

id    CDATA #REQUIRED

name  CDATA #IMPLIED

class CDATA #REQUIRED

>

An interceptor that will be ran when a layer is created. This is only ran if the layer is created by a Map's LayerFactory class. Not ProjectPackage's createLayer() methods.



<!ELEMENT layerAdded EMPTY>

<!ATTLIST layerAdded

id    CDATA #REQUIRED

name  CDATA #IMPLIED

class CDATA #REQUIRED

>

An interceptor that will be ran when a layer is added to a map.



<!ELEMENT layerRemoved EMPTY>

<!ATTLIST layerRemoved

id    CDATA #REQUIRED

name  CDATA #IMPLIED

class CDATA #REQUIRED

>

An interceptor that will be ran when a layer is about to be removed from a map. The method is called before the layer has been removed.



Examples:
An example use is:

<layerCreated
  class="net.refractions.udig.project.internal.impl.SetStyleInterceptor"
  id="net.refractions.udig.project.setStyleInterceptor"
  name="Set Layer Style"/>
This entry is used to advertise the SetStyleInterceptor to uDig so that it can be used to configure a layer as it is created. A layer interceptor is free to change more then just the layer under observation; as an example a layer interceptor is used to expand or set the bounds of a map when it is added.

public class InitMapBoundsInterceptor implements LayerInterceptor {
    public void run( Layer layer ) {
        if(layer.getMap()==null ){
            return; // this check is here because we could be doing a copy            
        }
        Map map = layer.getMapInternal();
        ReferencedEnvelope bounds = map.getViewportModelInternal().getBounds();
        
        //  If first layer or if the crs has been unchanged from the original BBox
  if( map.getMapLayers().size()==1 || bounds==ViewportModel.NIL_BBOX){
            bounds = map.getBounds(ProgressManager.instance().get());
            map.getViewportModelInternal().setBounds(bounds);
        }
    }
}

API Information:
Implementors are responsible for providing an implementation of LayerInterceptor.

Supplied Implementation:
The developers guide has a page on Interceptors.


2007 udig.refractions.net