[project view] ProjectView.changeViewCB(viewId, subId) update

LOG.error when view has no subviews but subId is not null.
Select default subview when subId is null.
If view had been selected then use last selected subview.
If view had never been selected then select first subview.

(IDEA-CR-21127)
This commit is contained in:
Daniil Ovchinnikov
2017-05-25 18:58:07 +03:00
parent 9a53ae7ebe
commit 6d46999c1a
2 changed files with 34 additions and 11 deletions
@@ -39,13 +39,19 @@ public abstract class ProjectView {
public abstract ActionCallback selectCB(Object element, VirtualFile file, boolean requestFocus);
/**
* Changes currently selected view and subview (if any).<br/>
* If a view (which is identified by {@code viewId}) has subviews but {@code subId} is {@code null} then no action is taken.
* Changes currently selected view and subview (if any).
* <p>
* When default subview is requested:<br/>
* - if the view had never been selected then the first subview is selected <br/>
* - otherwise subview won't be changed
* <p>
* It's an error when a view has no subviews and {@code subId} is not null.
*
* @param subId subview id. {@code null} means view should not have subviews
* @param viewId id of view to be selected
* @param subId id of subview to be selected
*/
@NotNull
public abstract ActionCallback changeViewCB(@NotNull String viewId, @Nullable String subId);
public abstract ActionCallback changeViewCB(@NotNull String viewId, @Nullable("default subview") String subId);
@Nullable
public abstract PsiElement getParentOfCurrentSelection();
@@ -934,17 +934,34 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
@NotNull
@Override
public ActionCallback changeViewCB(@NotNull String viewId, String subId) {
public ActionCallback changeViewCB(@NotNull String viewId, @Nullable String subId) {
AbstractProjectViewPane pane = getProjectViewPaneById(viewId);
LOG.assertTrue(pane != null, "Project view pane not found: " + viewId + "; subId:" + subId + "; project: " + myProject);
if (!viewId.equals(getCurrentViewId())
|| subId != null && !subId.equals(pane.getSubId())) {
for (Content content : getContentManager().getContents()) {
if (viewId.equals(content.getUserData(ID_KEY)) && StringUtil.equals(subId, content.getUserData(SUB_ID_KEY))) {
return getContentManager().setSelectedContentCB(content);
}
boolean hasSubViews = pane.getSubIds().length > 0;
if (hasSubViews) {
if (subId == null) {
// we try not to change subview
// get currently selected subId from the pane
subId = pane.getSubId();
}
}
else {
if (subId != null) {
LOG.error("View doesn't have subviews: " + viewId + "; subId:" + subId + "; project: " + myProject);
}
}
if (viewId.equals(myCurrentViewId) && Objects.equals(subId, myCurrentViewSubId)) return ActionCallback.REJECTED;
// at this point null subId means that view has no subviews OR subview was never selected
// we then search first content with the right viewId ignoring subIds of contents
for (Content content : getContentManager().getContents()) {
if (viewId.equals(content.getUserData(ID_KEY)) && (subId == null || subId.equals(content.getUserData(SUB_ID_KEY)))) {
return getContentManager().setSelectedContentCB(content);
}
}
return ActionCallback.REJECTED;
}