/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.lofidewanto.demo.client;

import java.util.logging.Logger;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.RootPanel;
import com.lofidewanto.demo.client.common.ServicePreparator;
import com.lofidewanto.demo.shared.DemoGwtServiceEndpoint;

public class DemoGwtEntryPoint implements EntryPoint {

    private static Logger logger = Logger
            .getLogger(DemoGwtEntryPoint.class.getName());

    private static final String INTEGRATION_AREA_ID = "entsorgerportal_integration_area";

    private static final String ATTRIBUTE_BASE_URL_INTEGRATION = "data-baseurl_integration";

    // Create Gin Injector
    private final DemoGwtWebAppGinjector injector = GWT
            .create(DemoGwtWebAppGinjector.class);

    @Override
    public void onModuleLoad() {
        logger.info("DemoGwtEntryPoint onModuleLoad...");

        // We need to prepare the services with RestyGwt before...
        RootPanel integrationArea = getWidgets(INTEGRATION_AREA_ID);
        String baseUrl = DemoGwtServiceEndpoint.SERVER_CONTEXT_PATH;
        if (integrationArea != null) {
            baseUrl = integrationArea.getElement()
                    .getAttribute(ATTRIBUTE_BASE_URL_INTEGRATION);
        }

        logger.info("Base URL: " + baseUrl);

        ServicePreparator servicePreparator = injector.getServicePreparator();
        servicePreparator.prepare(baseUrl);

        // Create webapp
        DemoGwtWebApp demoGwtWebApp = injector.getDemoGwtWebApp();
    }

    private RootPanel getWidgets(String element) {
        return RootPanel.get(element);
    }

}

@@ -1465,24 +1465,99 @@
 egration%22;%0A%0A
+    private static final String APP_VIEW_AREA_ID = %22applicationViewArea%22;%0A%0A
     // Creat
@@ -1783,16 +1783,64 @@
 ad...%22);
+%0A        String baseUrl = loadIntegrationArea();
 %0A%0A      
@@ -1900,16 +1900,322 @@
 fore...%0A
+        ServicePreparator servicePreparator = injector.getServicePreparator();%0A        servicePreparator.prepare(baseUrl);%0A%0A        // Create webapp%0A        DemoGwtWebApp demoGwtWebApp = injector.getDemoGwtWebApp();%0A    %7D%0A%0A    private String loadIntegrationArea() %7B%0A        // Prepare for integration area%0A
         
@@ -2501,24 +2501,25 @@
 ATION);%0A
+%0A
         
 %7D%0A%0A     
@@ -2514,271 +2514,336 @@
     
-%7D%0A%0A
     
-    logger.info(%22Base URL: %22 + baseUrl);%0A%0A        ServicePreparator servicePreparator = injector.getServicePreparator();%0A        servicePreparator.prepare(baseUrl);%0A%0A        // Create webapp%0A        DemoGwtWebApp demoGwtWebApp = injector.getDemoGwtWebApp()
+RootPanel appViewArea = getWidgets(APP_VIEW_AREA_ID);%0A            if (appViewArea != null) %7B%0A                appViewArea.removeFromParent();%0A                integrationArea.clear();%0A                integrationArea.add(appViewArea);%0A            %7D%0A        %7D%0A%0A        logger.info(%22Base URL: %22 + baseUrl);%0A        return baseUrl
 ;%0A  

add baseUrl