Skip to content

Commit

Permalink
CHE-8240: Switch to project explorer tab for reavel resources action.
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksandr Andriienko <oandriie@redhat.com>
  • Loading branch information
AndrienkoAleksandr committed Jan 25, 2018
1 parent 507ffaa commit 922ed68
Showing 1 changed file with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@

import static com.google.common.base.Preconditions.checkState;
import static java.util.Collections.singletonList;
import static org.eclipse.che.ide.api.parts.PartStackType.NAVIGATION;
import static org.eclipse.che.ide.part.perspectives.project.ProjectPerspective.PROJECT_PERSPECTIVE_ID;
import static org.eclipse.che.ide.resource.Path.valueOf;

import com.google.common.annotations.Beta;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import com.google.web.bindery.event.shared.EventBus;
import java.util.Map;
Expand All @@ -25,7 +27,11 @@
import org.eclipse.che.ide.api.action.AbstractPerspectiveAction;
import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.parts.PartPresenter;
import org.eclipse.che.ide.api.parts.PartStack;
import org.eclipse.che.ide.api.parts.WorkspaceAgent;
import org.eclipse.che.ide.api.resources.Resource;
import org.eclipse.che.ide.part.explorer.project.ProjectExplorerPresenter;
import org.eclipse.che.ide.resource.Path;
import org.eclipse.che.ide.resources.reveal.RevealResourceEvent;

Expand All @@ -43,16 +49,24 @@ public class RevealResourceAction extends AbstractPerspectiveAction {

private final AppContext appContext;
private final EventBus eventBus;
private final Provider<ProjectExplorerPresenter> projectExplorerPresenterProvider;
private final WorkspaceAgent workspaceAgent;

@Inject
public RevealResourceAction(
AppContext appContext, EventBus eventBus, CoreLocalizationConstant localizedConstant) {
AppContext appContext,
EventBus eventBus,
CoreLocalizationConstant localizedConstant,
Provider<ProjectExplorerPresenter> projectExplorerPresenterProvider,
WorkspaceAgent workspaceAgent) {
super(
singletonList(PROJECT_PERSPECTIVE_ID),
localizedConstant.actionRevealResourceText(),
localizedConstant.actionRevealResourceDescription());
this.appContext = appContext;
this.eventBus = eventBus;
this.projectExplorerPresenterProvider = projectExplorerPresenterProvider;
this.workspaceAgent = workspaceAgent;
}

/** {@inheritDoc} */
Expand All @@ -74,13 +88,28 @@ public void actionPerformed(ActionEvent e) {

checkState(!path.isEmpty());

ensureProjectExplorerPart();
eventBus.fireEvent(new RevealResourceEvent(path));
} else {
final Resource[] resources = appContext.getResources();

checkState(resources != null && resources.length == 1);

ensureProjectExplorerPart();
eventBus.fireEvent(new RevealResourceEvent(resources[0]));
}
}

private void ensureProjectExplorerPart() {
PartStack navigationPartStack = workspaceAgent.getPartStack(NAVIGATION);
PartPresenter activePart = navigationPartStack.getActivePart();

if (!(activePart instanceof ProjectExplorerPresenter)) {
ProjectExplorerPresenter projectExplorerPresenter = projectExplorerPresenterProvider.get();
if (activePart == null) {
workspaceAgent.openPart(projectExplorerPresenter, NAVIGATION);
}
workspaceAgent.setActivePart(projectExplorerPresenter);
}
}
}

0 comments on commit 922ed68

Please sign in to comment.