/**
 * Copyright (C) 2014 JBoss Inc
 *
 * 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.dashbuilder.client.perspectives;

import java.util.HashMap;
import java.util.Map;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

import org.dashbuilder.displayer.DisplayerSettings;
import org.dashbuilder.displayer.client.json.DisplayerSettingsJSONMarshaller;
import org.uberfire.client.annotations.Perspective;
import org.uberfire.client.annotations.WorkbenchPerspective;
import org.uberfire.client.workbench.panels.impl.MultiTabWorkbenchPanelPresenter;
import org.uberfire.client.workbench.panels.impl.StaticWorkbenchPanelPresenter;
import org.uberfire.mvp.PlaceRequest;
import org.uberfire.mvp.impl.DefaultPlaceRequest;
import org.uberfire.workbench.model.CompassPosition;
import org.uberfire.workbench.model.PanelDefinition;
import org.uberfire.workbench.model.PerspectiveDefinition;
import org.uberfire.workbench.model.Position;
import org.uberfire.workbench.model.impl.PanelDefinitionImpl;
import org.uberfire.workbench.model.impl.PartDefinitionImpl;
import org.uberfire.workbench.model.impl.PerspectiveDefinitionImpl;

import static org.dashbuilder.client.sales.SalesOppsDisplayers.*;

/**
 * A sample dashboard perspective
 */
@ApplicationScoped
@WorkbenchPerspective(identifier = "SalesDashboardPerspective")
public class SalesDashboardPerspective {

    @Inject
    DisplayerSettingsJSONMarshaller jsonHelper;

    @Perspective
    public PerspectiveDefinition buildPerspective() {

        PerspectiveDefinition perspective = new PerspectiveDefinitionImpl(MultiTabWorkbenchPanelPresenter.class.getName());
        perspective.setName("Sales summary");

        perspective.getRoot().addPart(new PartDefinitionImpl(createPlaceRequest(OPPS_BY_STATUS)));
        perspective.getRoot().addPart(new PartDefinitionImpl(createPlaceRequest(OPPS_BY_SALESMAN)));
        perspective.getRoot().addPart(new PartDefinitionImpl(createPlaceRequest(OPPS_BY_PRODUCT)));
        perspective.getRoot().addPart(new PartDefinitionImpl(createPlaceRequest(OPPS_BY_COUNTRY)));
        perspective.getRoot().addPart(new PartDefinitionImpl(createPlaceRequest(OPPS_COUNTRY_SUMMARY)));

        PanelDefinition east = new PanelDefinitionImpl(StaticWorkbenchPanelPresenter.class.getName());
        east.setMinWidth(500);
        east.setWidth(550);
        east.setMinHeight(350);
        east.setHeight(350);
        east.addPart(new PartDefinitionImpl(createPlaceRequest(OPPS_BY_PIPELINE)));

        PanelDefinition north = new PanelDefinitionImpl(StaticWorkbenchPanelPresenter.class.getName());
        north.setMinWidth(500);
        north.setWidth(550);
        north.setMinHeight(350);
        north.setHeight(350);
        north.addPart(new PartDefinitionImpl(createPlaceRequest(OPPS_EXPECTED_PIPELINE)));
        north.insertChild(CompassPosition.EAST, east);

        perspective.getRoot().insertChild(CompassPosition.NORTH, north);
        return perspective;
    }

    private PlaceRequest createPlaceRequest(DisplayerSettings displayerSettings) {
        String json = jsonHelper.toJsonString(displayerSettings);
        Map<String,String> params = new HashMap<String,String>();
        params.put("json", json);
        params.put("edit", "false");
        return new DefaultPlaceRequest("DisplayerScreen", params);
    }
}

@@ -1060,36 +1060,195 @@
 s.impl.Multi
-TabWorkbench
+ListWorkbenchPanelPresenter;%0Aimport org.uberfire.client.workbench.panels.impl.MultiTabWorkbenchPanelPresenter;%0Aimport org.uberfire.client.workbench.panels.impl.SplitLayout
 PanelPresent
@@ -2894,354 +2894,49 @@
 ion 
-east = new PanelDefinitionImpl(StaticWorkbenchPanelPresenter.class.getName());%0A        east.setMinWidth(500);%0A        east.setWidth(550);%0A        east.setMinHeight(350);%0A        east.setHeight(350);%0A        east.addPart(new PartDefinitionImpl(createPlaceRequest(OPPS_BY_PIPELINE)));%0A%0A        PanelDefinition north = new PanelDefinitionImpl(Static
+north = new PanelDefinitionImpl(MultiList
 Work
@@ -3191,63 +3191,8 @@
 )));
-%0A        north.insertChild(CompassPosition.EAST, east);
 %0A%0A  

Fix sample dashboard