Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHE-4347 Error when adding a perspective #4348

Merged
merged 2 commits into from
Mar 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public BootstrapController(Provider<WorkspacePresenter> workspaceProvider,

@Inject
private void startComponents(Map<String, Provider<Component>> components) {
startComponents(components.values().iterator());
startComponents(components.entrySet().iterator());
}

@Inject
Expand Down Expand Up @@ -132,23 +132,37 @@ public void apply(PromiseError err) throws OperationException {
});
}

private void startComponents(final Iterator<Provider<Component>> componentProviderIterator) {
if (componentProviderIterator.hasNext()) {
Provider<Component> componentProvider = componentProviderIterator.next();
private void startComponents(final Iterator<Map.Entry<String, Provider<Component>>> componentIterator) {
if (componentIterator.hasNext()) {
Map.Entry<String, Provider<Component>> entry = componentIterator.next();
final String componentName = entry.getKey();

final Component component = componentProvider.get();
component.start(new Callback<Component, Exception>() {
@Override
public void onSuccess(Component result) {
startComponents(componentProviderIterator);
}
try {
Provider<Component> componentProvider = entry.getValue();

final Component component = componentProvider.get();
component.start(new Callback<Component, Exception>() {
@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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<WorkspaceAgent> workspaceAgentProvider,
final RequestTransmitter requestTransmitter,
final DtoFactory dtoFactory) {
this.view = view;
this.eventBus = eventBus;
this.nodeFactory = nodeFactory;
Expand Down Expand Up @@ -170,18 +174,23 @@ 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
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.che.ide.workspace;

import com.google.inject.Provider;
import elemental.json.Json;
import elemental.json.JsonObject;

Expand Down Expand Up @@ -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<PerspectiveManager> perspectiveManagerProvider;

private Perspective activePerspective;
private Perspective activePerspective;

@Inject
public WorkspacePresenter(WorkspaceView view,
PerspectiveManager perspectiveManager,
Provider<PerspectiveManager> perspectiveManagerProvider,
MainMenuPresenter mainMenu,
StatusPanelGroupPresenter bottomMenu,
@MainToolbar ToolbarPresenter toolbarPresenter,
Expand All @@ -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();
}
Expand All @@ -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());
Expand Down Expand Up @@ -151,7 +152,7 @@ public JsonObject getState() {
JsonObject state = Json.createObject();
JsonObject perspectivesJs = Json.createObject();
state.put("perspectives", perspectivesJs);
Map<String, Perspective> perspectives = perspectiveManager.getPerspectives();
Map<String, Perspective> perspectives = perspectiveManagerProvider.get().getPerspectives();
for (Map.Entry<String, Perspective> entry : perspectives.entrySet()) {
//store only default perspective
if (entry.getKey().equals(defaultPerspectiveId)) {
Expand All @@ -165,7 +166,7 @@ public JsonObject getState() {
public void loadState(JsonObject state) {
if (state.hasKey("perspectives")) {
JsonObject perspectives = state.getObject("perspectives");
Map<String, Perspective> perspectiveMap = perspectiveManager.getPerspectives();
Map<String, Perspective> perspectiveMap = perspectiveManagerProvider.get().getPerspectives();
for (String key : perspectives.keys()) {
if (perspectiveMap.containsKey(key)) {
perspectiveMap.get(key).loadState(perspectives.getObject(key));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.che.ide.workspace.state;

import com.google.inject.Provider;
import elemental.json.Json;
import elemental.json.JsonObject;

Expand Down Expand Up @@ -57,6 +58,10 @@ public class WorkspacePresenterPersistenceTest {
private PartPresenter part1;

private WorkspacePresenter presenter;

@Mock
private Provider<PerspectiveManager> perspectiveManagerProvider;

private PerspectiveManager perspectiveManager;

@Before
Expand All @@ -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,
Expand Down