/*
 * Copyright (c) 2012-2018 Red Hat, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Red Hat, Inc. - initial API and implementation
 */
package org.eclipse.che.ide.part.perspectives.project;

import static org.eclipse.che.ide.api.parts.PartStackType.EDITING;
import static org.eclipse.che.ide.api.parts.PartStackType.INFORMATION;
import static org.eclipse.che.ide.api.parts.PartStackType.NAVIGATION;
import static org.eclipse.che.ide.api.parts.PartStackType.TOOLING;

import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.web.bindery.event.shared.EventBus;
import javax.validation.constraints.NotNull;
import org.eclipse.che.ide.api.notification.NotificationManager;
import org.eclipse.che.ide.api.parts.PartStack;
import org.eclipse.che.ide.command.explorer.CommandsExplorerPresenter;
import org.eclipse.che.ide.part.PartStackPresenterFactory;
import org.eclipse.che.ide.part.PartStackViewFactory;
import org.eclipse.che.ide.part.WorkBenchControllerFactory;
import org.eclipse.che.ide.part.editor.multipart.EditorMultiPartStackPresenter;
import org.eclipse.che.ide.part.explorer.project.ProjectExplorerPresenter;
import org.eclipse.che.ide.part.perspectives.general.AbstractPerspective;
import org.eclipse.che.ide.part.perspectives.general.PerspectiveViewImpl;
import org.eclipse.che.ide.processes.panel.ProcessesPanelPresenter;
import org.eclipse.che.providers.DynaProvider;

/**
 * General-purpose, displaying all the PartStacks in a default manner: Navigation at the left side;
 * Tooling at the right side; Information at the bottom of the page; Editors in the center.
 *
 * @author Nikolay Zamosenchuk
 * @author Dmitry Shnurenko
 */
@Singleton
public class ProjectPerspective extends AbstractPerspective {

  public static final String PROJECT_PERSPECTIVE_ID = "Project Perspective";

  @Inject
  public ProjectPerspective(
      PerspectiveViewImpl view,
      EditorMultiPartStackPresenter editorMultiPartStackPresenter,
      PartStackPresenterFactory stackPresenterFactory,
      PartStackViewFactory partViewFactory,
      WorkBenchControllerFactory controllerFactory,
      EventBus eventBus,
      DynaProvider dynaProvider,
      ProjectExplorerPresenter projectExplorerPresenter,
      CommandsExplorerPresenter commandsExplorerPresenter,
      NotificationManager notificationManager,
      ProcessesPanelPresenter processesPanelPresenter) {
    super(
        PROJECT_PERSPECTIVE_ID,
        view,
        stackPresenterFactory,
        partViewFactory,
        controllerFactory,
        eventBus,
        dynaProvider);

    partStacks.put(EDITING, editorMultiPartStackPresenter);

    addPart(projectExplorerPresenter, NAVIGATION);
    addPart(commandsExplorerPresenter, NAVIGATION);
    addPart(notificationManager, INFORMATION);
    addPart(processesPanelPresenter, INFORMATION);

    PartStack navigatorPanel = getPartStack(NAVIGATION);
    PartStack editorPanel = getPartStack(EDITING);
    PartStack toolPanel = getPartStack(TOOLING);
    PartStack infoPanel = getPartStack(INFORMATION);

    if (navigatorPanel == null || editorPanel == null || toolPanel == null || infoPanel == null) {
      return;
    }

    navigatorPanel.go(view.getNavigationPanel());
    editorPanel.go(view.getEditorPanel());
    toolPanel.go(view.getToolPanel());
    infoPanel.go(view.getInformationPanel());
  }

  @Override
  public String getPerspectiveId() {
    return PROJECT_PERSPECTIVE_ID;
  }

  @Override
  public String getPerspectiveName() {
    return PROJECT_PERSPECTIVE_ID;
  }

  /** {@inheritDoc} */
  @Override
  public void go(@NotNull AcceptsOneWidget container) {
    container.setWidget(view);
  }
}

@@ -419,284 +419,8 @@
 t;%0A%0A
-import static org.eclipse.che.ide.api.parts.PartStackType.EDITING;%0Aimport static org.eclipse.che.ide.api.parts.PartStackType.INFORMATION;%0Aimport static org.eclipse.che.ide.api.parts.PartStackType.NAVIGATION;%0Aimport static org.eclipse.che.ide.api.parts.PartStackType.TOOLING;%0A%0A
 impo
@@ -596,53 +596,8 @@
 us;%0A
-import javax.validation.constraints.NotNull;%0A
 impo
@@ -1368,16 +1368,338 @@
 vider;%0A%0A
+import javax.validation.constraints.NotNull;%0A%0Aimport static org.eclipse.che.ide.api.parts.PartStackType.EDITING;%0Aimport static org.eclipse.che.ide.api.parts.PartStackType.INFORMATION;%0Aimport static org.eclipse.che.ide.api.parts.PartStackType.NAVIGATION;%0Aimport static org.eclipse.che.ide.api.parts.PartStackType.TOOLING;%0A%0A
 /**%0A * G
@@ -3897,24 +3897,568 @@
 ontainer) %7B%0A
+    PartStack navigatorPanel = getPartStack(NAVIGATION);%0A    PartStack editorPanel = getPartStack(EDITING);%0A    PartStack toolPanel = getPartStack(TOOLING);%0A    PartStack infoPanel = getPartStack(INFORMATION);%0A%0A    if (navigatorPanel != null) %7B%0A      navigatorPanel.go(view.getNavigationPanel());%0A    %7D%0A    if (editorPanel != null) %7B%0A      editorPanel.go(view.getEditorPanel());%0A    %7D%0A    if (toolPanel != null) %7B%0A      toolPanel.go(view.getToolPanel());%0A    %7D%0A    if (infoPanel != null) %7B%0A      infoPanel.go(view.getInformationPanel());%0A    %7D%0A
     containe

Fix perspetive initialization in case switching perspective (#8664)