/*******************************************************************************
 * Copyright 2014, 2016 gwt-ol3
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
package com.github.tdesjardins.ol3.demo.client;

import com.github.tdesjardins.ol3.demo.client.example.OL3ExampleType;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.dom.client.Style;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.TabLayoutPanel;

/**
 * EntryPoint for playing with GwtOL3-Features.
 *
 * @author Tino Desjardins
 */
public class GwtOL3Playground implements EntryPoint {

    @Override
    public void onModuleLoad() {

        // choose your example
        TabLayoutPanel tabs = new TabLayoutPanel(27, Style.Unit.PX);
        for (OL3ExampleType example : OL3ExampleType.values()) {
            tabs.add(new LazyExampleWidget(example), example.name().replace("Example", ""));
        }
        RootLayoutPanel.get().add(tabs);
    }

    private static class LazyExampleWidget extends SimplePanel {

        private final OL3ExampleType example;
        private boolean initialized = false;

        private LazyExampleWidget(OL3ExampleType example) {
            this.example = example;
            this.setSize("100%", "100%");
            this.getElement().setId(example.getExample().toString());
            // set tabindex to "0" to make it focusable (needed for keyboard navigation)
            this.getElement().setTabIndex(0);
        }

        @Override public void setVisible(boolean visible) {
            if (visible && !initialized) {
                Scheduler.get().scheduleDeferred(() -> example.getExample().show(example.getExample().toString()));
                initialized = true;
            }
            super.setVisible(visible);
        }

    }
}

@@ -100,9 +100,9 @@
  201
-6
+7
  gwt
@@ -995,16 +995,59 @@
 .Style;%0A
+import com.google.gwt.user.client.History;%0A
 import c
@@ -1196,16 +1196,65 @@
 Panel;%0A%0A
+import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 /**%0A * E
@@ -1430,24 +1430,89 @@
 leLoad() %7B%0A%0A
+        Map%3CString, Integer%3E exampleIndexMap = new HashMap%3C%3E();%0A%0A
         // c
@@ -1599,16 +1599,41 @@
 it.PX);%0A
+%0A        int index = 0;%0A%0A
         
@@ -1794,50 +1794,305 @@
     
-%7D%0A        RootLayoutPanel.get().add(tabs);
+    exampleIndexMap.put(example.name(), index);%0A            index++;%0A        %7D%0A        RootLayoutPanel.get().add(tabs);%0A%0A        String token = History.getToken();%0A%0A        if (token != null && exampleIndexMap.containsKey(token)) %7B%0A            tabs.selectTab(exampleIndexMap.get(token));%0A        %7D
 %0A   
@@ -2914,16 +2914,107 @@
 isible);
+%0A%0A            if (visible) %7B%0A                History.newItem(example.name());%0A            %7D
 %0A       
@@ -3023,10 +3023,11 @@
 %0A%0A    %7D%0A
+%0A
 %7D%0A

Add dynamic anchors for example linking