/*
 * Copyright 2012 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.guvnor.m2repo.client.perspectives;

import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

import org.uberfire.client.annotations.Perspective;
import org.uberfire.client.annotations.WorkbenchMenu;
import org.uberfire.client.annotations.WorkbenchPerspective;
import org.uberfire.client.annotations.WorkbenchToolBar;
import org.uberfire.client.mvp.PlaceManager;
import org.uberfire.mvp.Command;
import org.uberfire.mvp.impl.DefaultPlaceRequest;
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 org.uberfire.workbench.model.menu.MenuFactory;
import org.uberfire.workbench.model.menu.Menus;
import org.uberfire.workbench.model.toolbar.ToolBar;

/**
 * A Perspective to show Guvnor's M2_REPO related screens
 */
@ApplicationScoped
@WorkbenchPerspective(identifier = "org.guvnor.m2repo.client.perspectives.GuvnorM2RepoPerspective", isDefault = false)
public class GuvnorM2RepoPerspective {

    @Inject
    private PlaceManager placeManager;

    private Menus menus;

    private ToolBar toolBar;

    private PerspectiveDefinition perspective;

    @PostConstruct
    public void init() {
        buildPerspective();
        buildMenuBar();
    }

    @Perspective
    public PerspectiveDefinition getPerspective() {
        return this.perspective;
    }

    @WorkbenchMenu
    public Menus getMenus() {
        return this.menus;
    }

    @WorkbenchToolBar
    public ToolBar getToolBar() {
        return this.toolBar;
    }

    private void buildPerspective() {
/*        final PlaceRequest place1 = new DefaultPlaceRequest( "FileExplorer" );
        place1.addParameter( "instance",
                             "1" );*/
/*        final PlaceRequest place2 = new DefaultPlaceRequest( "M2RepoEditor" );
        place2.addParameter( "instance",
                             "2" );*/

        this.perspective = new PerspectiveDefinitionImpl();
        this.perspective.setName( "Guvnor M2 Repository Explorer" );

        this.perspective.getRoot().addPart( new PartDefinitionImpl( new DefaultPlaceRequest( "M2RepoEditor" ) ) );

        final PanelDefinition west = new PanelDefinitionImpl();
        west.setWidth( 300 );
        west.setMinWidth( 200 );
        west.addPart( new PartDefinitionImpl( new DefaultPlaceRequest( "FileExplorer" ) ) );

        this.perspective.getRoot().insertChild( Position.WEST, west );
    }

    private void buildMenuBar() {
        this.menus = MenuFactory
                .newTopLevelMenu( "Explore" )
                .menus()
                .menu( "Guvnor M2 Repository Explorer" )
                .respondsWith( new Command() {
                    @Override
                    public void execute() {
                        placeManager.goTo( "M2RepoEditor" );
                    }
                } )
                .endMenu()
                .endMenus()
                .endMenu().build();
    }

}

@@ -923,65 +923,8 @@
 ve;%0A
-import org.uberfire.client.annotations.WorkbenchToolBar;%0A
 impo
@@ -1092,32 +1092,79 @@
 anelDefinition;%0A
+import org.uberfire.workbench.model.PanelType;%0A
 import org.uberf
@@ -1548,61 +1548,8 @@
 nus;
-%0Aimport org.uberfire.workbench.model.toolbar.ToolBar;
 %0A%0A/*
@@ -1872,38 +1872,8 @@
 s;%0A%0A
-    private ToolBar toolBar;%0A%0A
     
@@ -2219,454 +2219,41 @@
     
-@WorkbenchToolBar%0A    public ToolBar getToolBar() %7B%0A        return this.toolBar;%0A    %7D%0A%0A    private void buildPerspective() %7B%0A/*        final PlaceRequest place1 = new DefaultPlaceRequest( %22FileExplorer%22 );%0A        place1.addParameter( %22instance%22,%0A                             %221%22 );*/%0A/*        final PlaceRequest place2 = new DefaultPlaceRequest( %22M2RepoEditor%22 );%0A        place2.addParameter( %22instance%22,%0A                             %222%22 );*/%0A
+private void buildPerspective() %7B
 %0A   
@@ -2298,32 +2298,53 @@
 eDefinitionImpl(
+ PanelType.ROOT_LIST 
 );%0A        this.
@@ -2577,16 +2577,38 @@
 ionImpl(
+ PanelType.MULTI_LIST 
 );%0A     

Fix Perspective definition