/**

Copyright 2010 OpenEngSB Division, Vienna University of Technology

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 org.openengsb.ui.web;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.openengsb.core.config.DomainProvider;
import org.openengsb.core.config.ServiceManager;
import org.openengsb.core.config.descriptor.ServiceDescriptor;
import org.openengsb.ui.web.service.DomainService;

@SuppressWarnings("serial")
public class Index extends BasePage {

    @SpringBean
    private DomainService domainService;

    public Index() {
        add(new ListView<DomainProvider>("domains", domainService.domains()) {

            @Override
            protected void populateItem(ListItem<DomainProvider> item) {
                item.add(new Label("domain.name", item.getModelObject().getName(item.getLocale())));
                item.add(new Label("domain.description", item.getModelObject().getDescription(item.getLocale())));
                item.add(new Label("domain.class", item.getModelObject().getDomainInterface().getName()));
            }
        });
        List<ServiceManager> managers = new ArrayList<ServiceManager>(domainService.domains().size());
        for (DomainProvider provider : domainService.domains()) {
            managers.addAll(this.domainService.serviceManagersForDomain(provider.getDomainInterface()));
        }
        add(new ListView<ServiceManager>("services", managers) {

            @Override
            protected void populateItem(ListItem<ServiceManager> item) {
                ServiceDescriptor desc = item.getModelObject().getDescriptor(item.getLocale());
                item.add(new Link<ServiceManager>("create.new", item.getModel()) {

                    @Override
                    public void onClick() {
                        setResponsePage(new EditorPage(getModelObject()));
                    }
                });
                item.add(new Label("service.name", desc.getName()));
                item.add(new Label("service.description", desc.getDescription()));
            }
        });
    }

}

@@ -876,16 +876,111 @@
 stView;%0A
+import org.apache.wicket.model.IModel;%0Aimport org.apache.wicket.model.LoadableDetachableModel;%0A
 import o
@@ -1402,75 +1402,317 @@
     
-add(new ListView%3CDomainProvider%3E(%22domains%22, domainService.domains()
+IModel%3CList%3CDomainProvider%3E%3E domainsModel = new LoadableDetachableModel%3CList%3CDomainProvider%3E%3E() %7B%0A            @Override%0A            protected List%3CDomainProvider%3E load() %7B%0A                return domainService.domains();%0A            %7D%0A        %7D;%0A        add(new ListView%3CDomainProvider%3E(%22domains%22, domainsModel
 ) %7B%0A
@@ -2148,32 +2148,221 @@
   %7D%0A        %7D);%0A
+        IModel%3CList%3CServiceManager%3E%3E servicesModel = new LoadableDetachableModel%3CList%3CServiceManager%3E%3E() %7B%0A            @Override%0A            protected List%3CServiceManager%3E load() %7B%0A        
         List%3CSer
@@ -2444,24 +2444,32 @@
 ().size());%0A
+        
         for 
@@ -2534,16 +2534,24 @@
         
+     
+   
 managers
@@ -2562,13 +2562,8 @@
 All(
-this.
 doma
@@ -2630,33 +2630,100 @@
 ce()));%0A        
-%7D
+        %7D%0A                return managers;%0A            %7D%0A        %7D;%0A
 %0A        add(new
@@ -2764,21 +2764,25 @@
 s%22, 
-managers
+servicesModel
 ) %7B%0A
-%0A
     
@@ -3047,25 +3047,24 @@
 tModel()) %7B%0A
-%0A
             

fix SerializeExceptions in Index-page