From a6ddba5f4cfe3e73f0ae0001a5a5fdff6b043068 Mon Sep 17 00:00:00 2001 From: Vitaliy Guliy Date: Thu, 9 Mar 2017 10:58:51 +0200 Subject: [PATCH] CHE-4347 Error when adding a perspective (#4348) * CHE-4347 Error when adding a perspective * CHE-4347 Error when adding a perspective --- .../ide/api/action/DefaultActionGroup.java | 5 +- .../api/action/DefaultActionGroupTest.java | 4 +- .../che/ide/client/BootstrapController.java | 46 ++++++++++++------- .../project/ProjectExplorerPresenter.java | 27 +++++++---- .../che/ide/workspace/WorkspacePresenter.java | 29 ++++++------ .../WorkspacePresenterPersistenceTest.java | 10 +++- 6 files changed, 79 insertions(+), 42 deletions(-) diff --git a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/action/DefaultActionGroup.java b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/action/DefaultActionGroup.java index 99262726e0a..8a18871349a 100644 --- a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/action/DefaultActionGroup.java +++ b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/action/DefaultActionGroup.java @@ -12,6 +12,7 @@ import org.eclipse.che.ide.api.constraints.Anchor; import org.eclipse.che.ide.api.constraints.Constraints; +import org.eclipse.che.ide.util.loging.Log; import java.util.ArrayList; import java.util.Collection; @@ -137,11 +138,13 @@ public final void addAction(Action action, Constraints constraint, ActionManager if (action == this) { throw new IllegalArgumentException("Cannot add a group to itself"); } + // Check that action isn't already registered if (!(action instanceof Separator)) { for (Action actionInList : actionList) { if (action.equals(actionInList)) { - throw new IllegalArgumentException("cannot add an action twice: " + action); + Log.error(getClass(), "Can not add an action twice: " + action); + return; } } } diff --git a/ide/che-core-ide-api/src/test/java/org/eclipse/che/ide/api/action/DefaultActionGroupTest.java b/ide/che-core-ide-api/src/test/java/org/eclipse/che/ide/api/action/DefaultActionGroupTest.java index f4c2ac1ba3f..67bc68c884b 100644 --- a/ide/che-core-ide-api/src/test/java/org/eclipse/che/ide/api/action/DefaultActionGroupTest.java +++ b/ide/che-core-ide-api/src/test/java/org/eclipse/che/ide/api/action/DefaultActionGroupTest.java @@ -62,12 +62,14 @@ public void setup() { defaultActionGroup = new DefaultActionGroup(actionManager); } - @Test(expected = IllegalArgumentException.class) + @Test public void shouldNotAddSameActionTwice() { Action action = mock(Action.class); defaultActionGroup.add(action, new Constraints(AFTER, "someAction")); defaultActionGroup.add(action, new Constraints(BEFORE, "someAction")); + + assertThat(defaultActionGroup.getChildrenCount()).isEqualTo(1); } @Test diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/client/BootstrapController.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/client/BootstrapController.java index 33dff90115f..4ab157663a3 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/client/BootstrapController.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/client/BootstrapController.java @@ -97,7 +97,7 @@ public BootstrapController(Provider workspaceProvider, @Inject private void startComponents(Map> components) { - startComponents(components.values().iterator()); + startComponents(components.entrySet().iterator()); } @Inject @@ -132,23 +132,37 @@ public void apply(PromiseError err) throws OperationException { }); } - private void startComponents(final Iterator> componentProviderIterator) { - if (componentProviderIterator.hasNext()) { - Provider componentProvider = componentProviderIterator.next(); + private void startComponents(final Iterator>> componentIterator) { + if (componentIterator.hasNext()) { + Map.Entry> entry = componentIterator.next(); + final String componentName = entry.getKey(); - final Component component = componentProvider.get(); - component.start(new Callback() { - @Override - public void onSuccess(Component result) { - startComponents(componentProviderIterator); - } + try { + Provider componentProvider = entry.getValue(); + + final Component component = componentProvider.get(); + component.start(new Callback() { + @Override + public void onSuccess(Component result) { + Scheduler.get().scheduleDeferred(new ScheduledCommand() { + @Override + public void execute() { + startComponents(componentIterator); + } + }); + } + + @Override + public void onFailure(Exception reason) { + Log.error(getClass(), "Unable to start " + componentName, reason); + initializationFailed(reason.getMessage()); + } + }); + } catch (Exception e) { + Log.error(getClass(), "Unable to start " + componentName, e); + initializationFailed(e.getMessage()); + } - @Override - public void onFailure(Exception reason) { - Log.error(component.getClass(), reason); - initializationFailed(reason.getMessage()); - } - }); } else { startExtensionsAndDisplayUI(); } diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/part/explorer/project/ProjectExplorerPresenter.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/part/explorer/project/ProjectExplorerPresenter.java index 4a2c734f768..1c99256b3ad 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/part/explorer/project/ProjectExplorerPresenter.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/part/explorer/project/ProjectExplorerPresenter.java @@ -11,8 +11,10 @@ package org.eclipse.che.ide.part.explorer.project; import com.google.common.collect.Sets; +import com.google.gwt.core.client.Scheduler; import com.google.gwt.user.client.ui.AcceptsOneWidget; import com.google.inject.Inject; +import com.google.inject.Provider; import com.google.inject.Singleton; import com.google.web.bindery.event.shared.EventBus; @@ -108,13 +110,15 @@ public class ProjectExplorerPresenter extends BasePresenter implements ActionDel @Inject public ProjectExplorerPresenter(final ProjectExplorerView view, - EventBus eventBus, - CoreLocalizationConstant locale, - Resources resources, + final EventBus eventBus, + final CoreLocalizationConstant locale, + final Resources resources, final ResourceNode.NodeFactory nodeFactory, final SettingsProvider settingsProvider, final AppContext appContext, - final WorkspaceAgent workspaceAgent, RequestTransmitter requestTransmitter, DtoFactory dtoFactory) { + final Provider workspaceAgentProvider, + final RequestTransmitter requestTransmitter, + final DtoFactory dtoFactory) { this.view = view; this.eventBus = eventBus; this.nodeFactory = nodeFactory; @@ -170,11 +174,6 @@ public void onPostLoad(PostLoadEvent event) { registerNative(); - final PartStack partStack = checkNotNull(workspaceAgent.getPartStack(PartStackType.NAVIGATION), - "Navigation part stack should not be a null"); - partStack.addPart(this); - partStack.setActivePart(this); - // when ide has already initialized, then we force set focus to the current part eventBus.addHandler(ExtensionsInitializedEvent.getType(), new ExtensionsInitializedHandler() { @Override @@ -182,6 +181,16 @@ public void onExtensionsInitialized(ExtensionsInitializedEvent event) { partStack.setActivePart(ProjectExplorerPresenter.this); } }); + + Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() { + @Override + public void execute() { + final PartStack partStack = checkNotNull(workspaceAgentProvider.get().getPartStack(PartStackType.NAVIGATION), + "Navigation part stack should not be a null"); + partStack.addPart(ProjectExplorerPresenter.this); + partStack.setActivePart(ProjectExplorerPresenter.this); + } + }); } @Inject diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/WorkspacePresenter.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/WorkspacePresenter.java index 7eb41d321ae..9067d24c2da 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/WorkspacePresenter.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/WorkspacePresenter.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.che.ide.workspace; +import com.google.inject.Provider; import elemental.json.Json; import elemental.json.JsonObject; @@ -49,18 +50,18 @@ public class WorkspacePresenter implements Presenter, WorkspaceView.ActionDelegate, WorkspaceAgent, PerspectiveTypeListener, StateComponent { - private final WorkspaceView view; - private final String defaultPerspectiveId; - private final MainMenuPresenter mainMenu; - private final StatusPanelGroupPresenter bottomMenu; - private final ToolbarPresenter toolbarPresenter; - private final PerspectiveManager perspectiveManager; + private final WorkspaceView view; + private final String defaultPerspectiveId; + private final MainMenuPresenter mainMenu; + private final StatusPanelGroupPresenter bottomMenu; + private final ToolbarPresenter toolbarPresenter; + private final Provider perspectiveManagerProvider; - private Perspective activePerspective; + private Perspective activePerspective; @Inject public WorkspacePresenter(WorkspaceView view, - PerspectiveManager perspectiveManager, + Provider perspectiveManagerProvider, MainMenuPresenter mainMenu, StatusPanelGroupPresenter bottomMenu, @MainToolbar ToolbarPresenter toolbarPresenter, @@ -73,8 +74,8 @@ public WorkspacePresenter(WorkspaceView view, this.mainMenu = mainMenu; this.bottomMenu = bottomMenu; - this.perspectiveManager = perspectiveManager; - this.perspectiveManager.addListener(this); + this.perspectiveManagerProvider = perspectiveManagerProvider; + perspectiveManagerProvider.get().addListener(this); onPerspectiveChanged(); } @@ -92,10 +93,10 @@ public void go(AcceptsOneWidget container) { /** {@inheritDoc} */ @Override public void onPerspectiveChanged() { - activePerspective = perspectiveManager.getActivePerspective(); + activePerspective = perspectiveManagerProvider.get().getActivePerspective(); if (activePerspective == null) { - throw new IllegalStateException("Current perspective isn't defined " + perspectiveManager.getPerspectiveId()); + throw new IllegalStateException("Current perspective isn't defined " + perspectiveManagerProvider.get().getPerspectiveId()); } activePerspective.go(view.getPerspectivePanel()); @@ -151,7 +152,7 @@ public JsonObject getState() { JsonObject state = Json.createObject(); JsonObject perspectivesJs = Json.createObject(); state.put("perspectives", perspectivesJs); - Map perspectives = perspectiveManager.getPerspectives(); + Map perspectives = perspectiveManagerProvider.get().getPerspectives(); for (Map.Entry entry : perspectives.entrySet()) { //store only default perspective if (entry.getKey().equals(defaultPerspectiveId)) { @@ -165,7 +166,7 @@ public JsonObject getState() { public void loadState(JsonObject state) { if (state.hasKey("perspectives")) { JsonObject perspectives = state.getObject("perspectives"); - Map perspectiveMap = perspectiveManager.getPerspectives(); + Map perspectiveMap = perspectiveManagerProvider.get().getPerspectives(); for (String key : perspectives.keys()) { if (perspectiveMap.containsKey(key)) { perspectiveMap.get(key).loadState(perspectives.getObject(key)); diff --git a/ide/che-core-ide-app/src/test/java/org/eclipse/che/ide/workspace/state/WorkspacePresenterPersistenceTest.java b/ide/che-core-ide-app/src/test/java/org/eclipse/che/ide/workspace/state/WorkspacePresenterPersistenceTest.java index 8bdbe623d21..d4c1e05bb61 100644 --- a/ide/che-core-ide-app/src/test/java/org/eclipse/che/ide/workspace/state/WorkspacePresenterPersistenceTest.java +++ b/ide/che-core-ide-app/src/test/java/org/eclipse/che/ide/workspace/state/WorkspacePresenterPersistenceTest.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.che.ide.workspace.state; +import com.google.inject.Provider; import elemental.json.Json; import elemental.json.JsonObject; @@ -57,6 +58,10 @@ public class WorkspacePresenterPersistenceTest { private PartPresenter part1; private WorkspacePresenter presenter; + + @Mock + private Provider perspectiveManagerProvider; + private PerspectiveManager perspectiveManager; @Before @@ -65,8 +70,11 @@ public void setUp() throws Exception { map.put("perspective1", perspective1); map.put("perspective2", perspective2); perspectiveManager = new PerspectiveManager(map, "perspective1"); + + when(perspectiveManagerProvider.get()).thenReturn(perspectiveManager); + presenter = new WorkspacePresenter(workspaceView, - perspectiveManager, + perspectiveManagerProvider, mainMenuPresenter, statusPanelGroupPresenter, toolbarPresenter,