Index: /trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java	(revision 1916)
+++ /trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java	(revision 1917)
@@ -25,4 +25,5 @@
 import javax.swing.DefaultListSelectionModel;
 import javax.swing.Icon;
+import javax.swing.JComponent;
 import javax.swing.JLabel;
 import javax.swing.JList;
@@ -30,4 +31,5 @@
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
+import javax.swing.KeyStroke;
 import javax.swing.ListModel;
 import javax.swing.ListSelectionModel;
@@ -129,4 +131,8 @@
         //-- delete layer action
         DeleteLayerAction deleteLayerAction = new DeleteLayerAction();
+        layerList.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
+                KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0),"deleteLayer"
+        );
+        layerList.getActionMap().put("deleteLayer", deleteLayerAction);
         adaptTo(deleteLayerAction, selectionModel);
         buttonPanel.add(new SideButton(deleteLayerAction, "delete"));
@@ -136,5 +142,5 @@
 
     /**
-     * Create an layerlist and attach it to the given mapView.
+     * Create an layer list and attach it to the given mapView.
      */
     protected LayerListDialog(MapFrame mapFrame) {
@@ -186,4 +192,12 @@
     }
 
+    /**
+     * Wires <code>listener</code> to <code>listSelectionModel</code> in such a way, that
+     * <code>listener</code> receives a {@see IEnabledStateUpdating#updateEnabledState()}
+     * on every {@see ListSelectionEvent}.
+     * 
+     * @param listener  the listener
+     * @param listSelectionModel  the source emitting {@see ListSelectionEvent}s
+     */
     protected void adaptTo(final IEnabledStateUpdating listener, ListSelectionModel listSelectionModel) {
         listSelectionModel.addListSelectionListener(
@@ -196,4 +210,12 @@
     }
 
+    /**
+     * Wires <code>listener</code> to <code>listModel</code> in such a way, that
+     * <code>listener</code> receives a {@see IEnabledStateUpdating#updateEnabledState()}
+     * on every {@see ListDataEvent}.
+     * 
+     * @param listener  the listener
+     * @param listSelectionModel  the source emitting {@see ListDataEvent}s
+     */
     protected void adaptTo(final IEnabledStateUpdating listener, ListModel listModel) {
         listModel.addListDataListener(
@@ -213,5 +235,11 @@
         );
     }
-
+    /**
+     * Wires <code>listener</code> to {@see MapView} in such a way, that
+     * <code>listener</code> receives a {@see IEnabledStateUpdating#updateEnabledState()}
+     * on every {@see LayerChangeListener}-event emitted by {@see MapView}.
+     * 
+     * @param listener  the listener
+     */
     protected void adaptToLayerChanges(final IEnabledStateUpdating listener) {
         Layer.listeners.add(
@@ -374,4 +402,6 @@
             if (this.layer == null) {
                 List<Layer> selectedLayers = getModel().getSelectedLayers();
+                if (selectedLayers.isEmpty())
+                    return;
                 if (selectedLayers.size() == 1) {
                     deleteSingleLayer(selectedLayers.get(0));
@@ -473,5 +503,8 @@
                 toActivate = model.getSelectedLayers().get(0);
             }
-            getModel().activateLayer(toActivate);
+            // model is  going to be updated via LayerChangeListener
+            // and PropertyChangeEvents
+            Main.map.mapView.setActiveLayer(toActivate);
+            toActivate.setVisible(true);
         }
 
@@ -662,5 +695,5 @@
     /**
      * The layer list model. The model manages a list of layers and provides methods for
-     * moving layers up and down, for toggling their visibiliy, for activating a layer.
+     * moving layers up and down, for toggling their visibility, and for activating a layer.
      * 
      * The model is a {@see ListModel} and it provides a {@see ListSelectionModel}. It expectes
@@ -670,4 +703,7 @@
      * The model manages a list of {@see LayerListModelListener} which are mainly notified if
      * the model requires views to make a specific list entry visible.
+     * 
+     * It also listens to {@see PropertyChangeEvent}s of every {@see Layer} it manages, in particular to
+     * the properties {@see Layer#VISIBLE_PROP} and {@see Layer#NAME_PROP}.
      */
     public class LayerListModel extends DefaultListModel implements LayerChangeListener, PropertyChangeListener{
@@ -811,4 +847,5 @@
             if (layer == null)
                 return;
+            layer.removePropertyChangeListener(this);
             int size = getSize();
             List<Integer> rows = getSelectedRows();
@@ -829,4 +866,7 @@
             layer.addPropertyChangeListener(this);
             fireContentsChanged(this, 0, getSize());
+            int idx = getLayers().indexOf(layer);
+            selectionModel.setSelectionInterval(idx, idx);
+            ensureSelectedIsVisible();
         }
 
@@ -958,19 +998,4 @@
 
         /**
-         * Activates the layer <code>layer</code>
-         * 
-         * @param layer the layer
-         */
-        public void activateLayer(Layer layer) {
-            if (layer == null)
-                return;
-            Main.map.mapView.setActiveLayer(layer);
-            layer.setVisible(true);
-            int idx = getLayers().indexOf(layer);
-            selectionModel.setSelectionInterval(idx,idx);
-            ensureSelectedIsVisible();
-        }
-
-        /**
          * Replies the list of layers currently managed by {@see MapView}.
          * Never null, but can be empty.
@@ -983,4 +1008,34 @@
                 return Collections.<Layer>emptyList();
             return Main.map.mapView.getAllLayersAsList();
+        }
+
+        /**
+         * Ensures that at least one layer is selected in the layer dialog
+         * 
+         */
+        protected void ensureActiveSelected() {
+            if (getLayers().size() == 0) return;
+            if (getActiveLayer() != null) {
+                // there's an active layer - select it and make it
+                // visible
+                int idx = getLayers().indexOf(getActiveLayer());
+                selectionModel.setSelectionInterval(idx, idx);
+                ensureSelectedIsVisible();
+            } else {
+                // no active layer - select the first one and make
+                // it visible
+                selectionModel.setSelectionInterval(0, 0);
+                ensureSelectedIsVisible();
+            }
+        }
+
+        /**
+         * Replies the active layer. null, if no active layer is available
+         * 
+         * @return the active layer. null, if no active layer is available
+         */
+        protected Layer getActiveLayer() {
+            if (Main.map == null || Main.map.mapView == null) return null;
+            return Main.map.mapView.getActiveLayer();
         }
 
@@ -1017,4 +1072,5 @@
                 }
             }
+            ensureActiveSelected();
         }
 
@@ -1058,16 +1114,44 @@
     }
 
+    /**
+     * Creates a {@see ShowHideLayerAction} for <code>layer</code> in the
+     * context of this {@see LayerListDialog}.
+     * 
+     * @param layer the layer
+     * @return the action
+     */
     public ShowHideLayerAction createShowHideLayerAction(Layer layer) {
         return new ShowHideLayerAction(layer);
     }
 
+    /**
+     * Creates a {@see DeleteLayerAction} for <code>layer</code> in the
+     * context of this {@see LayerListDialog}.
+     * 
+     * @param layer the layer
+     * @return the action
+     */
     public DeleteLayerAction createDeleteLayerAction(Layer layer) {
         return new DeleteLayerAction(layer);
     }
 
+    /**
+     * Creates a {@see ActivateLayerAction} for <code>layer</code> in the
+     * context of this {@see LayerListDialog}.
+     * 
+     * @param layer the layer
+     * @return the action
+     */
     public ActivateLayerAction createActivateLayerAction(Layer layer) {
         return new ActivateLayerAction(layer);
     }
 
+    /**
+     * Creates a {@see MergeLayerAction} for <code>layer</code> in the
+     * context of this {@see LayerListDialog}.
+     * 
+     * @param layer the layer
+     * @return the action
+     */
     public MergeAction createMergeLayerAction(Layer layer) {
         return new MergeAction(layer);
