/**
 * 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 org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.openengsb.core.common.DomainProvider;
import org.openengsb.core.common.ServiceManager;
import org.openengsb.ui.web.service.DomainService;

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

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

    @SpringBean
    private DomainService domainService;

    public Index() {
        IModel<List<DomainProvider>> domainsModel = new LoadableDetachableModel<List<DomainProvider>>() {
            @Override
            protected List<DomainProvider> load() {
                return domainService.domains();
            }
        };
        add(new ListView<DomainProvider>("domains", domainsModel) {

            @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()));
            }
        });
        IModel<List<ServiceManager>> servicesModel = new LoadableDetachableModel<List<ServiceManager>>() {
            @Override
            protected List<ServiceManager> load() {
                List<ServiceManager> managers = new ArrayList<ServiceManager>(domainService.domains().size());
                for (DomainProvider provider : domainService.domains()) {
                    managers.addAll(domainService.serviceManagersForDomain(provider.getDomainInterface()));
                }
                return managers;
            }
        };

    }

}

@@ -659,16 +659,40 @@
 i.web;%0A%0A
+import java.util.List;%0A%0A
 import o
@@ -729,24 +729,24 @@
 asic.Label;%0A
-
 import org.a
@@ -1045,57 +1045,8 @@
 er;%0A
-import org.openengsb.core.common.ServiceManager;%0A
 impo
@@ -1097,60 +1097,8 @@
 e;%0A%0A
-import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 @Sup
@@ -1985,32 +1985,32 @@
 ;%0A            %7D%0A
+
         %7D);%0A    
@@ -2008,558 +2008,8 @@
  %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%3CServiceManager%3E managers = new ArrayList%3CServiceManager%3E(domainService.domains().size());%0A                for (DomainProvider provider : domainService.domains()) %7B%0A                    managers.addAll(domainService.serviceManagersForDomain(provider.getDomainInterface()));%0A                %7D%0A                return managers;%0A            %7D%0A        %7D;
 %0A%0A  

remove unused variable