external system: customizable view node names

This commit is contained in:
Vladislav.Soroka
2018-06-03 20:59:32 +03:00
parent 08632d306a
commit 6fffd5a4dd
9 changed files with 59 additions and 30 deletions
@@ -476,6 +476,16 @@ public class ExternalProjectsViewImpl extends SimpleToolWindowPanel implements D
}
}
@Nullable
String getDisplayName(@Nullable DataNode node) {
if (node == null) return null;
return myViewContributors.stream()
.map(contributor -> contributor.getDisplayName(node))
.filter(Objects::nonNull)
.findFirst()
.orElse(null);
}
private void scheduleTasksRebuild() {
scheduleStructureRequest(() -> {
assert myStructure != null;
@@ -116,6 +116,12 @@ public abstract class ExternalSystemNode<T> extends SimpleNode implements Compar
return myParent;
}
@Override
public String getName() {
String displayName = ((ExternalProjectsViewImpl)getExternalProjectsView()).getDisplayName(myDataNode);
return displayName == null ? super.getName() : displayName;
}
protected ExternalProjectsView getExternalProjectsView() {
return myExternalProjectsView;
}
@@ -21,6 +21,7 @@ import com.intellij.openapi.externalSystem.model.Key;
import com.intellij.openapi.externalSystem.model.ProjectSystemId;
import com.intellij.util.containers.MultiMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
@@ -41,4 +42,9 @@ public abstract class ExternalSystemViewContributor {
@NotNull
public abstract List<ExternalSystemNode<?>> createNodes(
ExternalProjectsView externalProjectsView, MultiMap<Key<?>, DataNode<?>> dataNodes);
@Nullable
public String getDisplayName(@NotNull DataNode node) {
return null;
}
}
@@ -22,6 +22,7 @@ import com.intellij.openapi.externalSystem.model.Key;
import com.intellij.openapi.externalSystem.model.ProjectKeys;
import com.intellij.openapi.externalSystem.model.ProjectSystemId;
import com.intellij.openapi.externalSystem.model.project.*;
import com.intellij.openapi.externalSystem.model.task.TaskData;
import com.intellij.openapi.externalSystem.service.project.IdeModelsProviderImpl;
import com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings;
import com.intellij.openapi.externalSystem.settings.ExternalProjectSettings;
@@ -97,6 +98,12 @@ public class ExternalSystemViewDefaultContributor extends ExternalSystemViewCont
return result;
}
@Nullable
@Override
public String getDisplayName(@NotNull DataNode node) {
return getNodeDisplayName(node);
}
private static void addDependenciesNode(@NotNull ExternalProjectsView externalProjectsView,
@NotNull MultiMap<Key<?>, DataNode<?>> dataNodes,
@NotNull List<ExternalSystemNode<?>> result) {
@@ -282,12 +289,6 @@ public class ExternalSystemViewDefaultContributor extends ExternalSystemViewCont
setNameAndTooltip(getName(), null, data.getScope().getDisplayName());
}
}
@Override
public String getName() {
final ModuleDependencyData data = getData();
return data != null ? data.getExternalName() : "";
}
}
private static class LibraryDependencyDataExternalSystemNode extends DependencyDataExternalSystemNode<LibraryDependencyData> {
@@ -306,18 +307,20 @@ public class ExternalSystemViewDefaultContributor extends ExternalSystemViewCont
setNameAndTooltip(getName(), null, data.getScope().getDisplayName());
}
}
}
@Override
public String getName() {
final LibraryDependencyData data = getData();
if (data == null) return "";
String externalName = data.getExternalName();
@NotNull
private static String getNodeDisplayName(@NotNull DataNode node) {
Object data = node.getData();
if (data instanceof LibraryDependencyData) {
LibraryDependencyData libraryDependencyData = (LibraryDependencyData)data;
String externalName = libraryDependencyData.getExternalName();
if (StringUtil.isEmpty(externalName)) {
Set<String> paths = data.getTarget().getPaths(LibraryPathType.BINARY);
Set<String> paths = libraryDependencyData.getTarget().getPaths(LibraryPathType.BINARY);
if (paths.size() == 1) {
String relativePathToRoot = null;
String path = ExternalSystemApiUtil.toCanonicalPath(paths.iterator().next());
DataNode<ProjectData> projectDataDataNode = ExternalSystemApiUtil.findParent(myDataNode, PROJECT);
DataNode<ProjectData> projectDataDataNode = ExternalSystemApiUtil.findParent(node, PROJECT);
if (projectDataDataNode != null) {
relativePathToRoot = FileUtil.getRelativePath(projectDataDataNode.getData().getLinkedExternalProjectPath(), path, '/');
relativePathToRoot = relativePathToRoot != null && StringUtil.startsWith(relativePathToRoot, "../../")
@@ -332,5 +335,12 @@ public class ExternalSystemViewDefaultContributor extends ExternalSystemViewCont
}
return externalName;
}
if (data instanceof Named) {
return ((Named)data).getExternalName();
}
if (data instanceof TaskData) {
return ((TaskData)data).getName();
}
return StringUtil.notNullize(node.toString());
}
}
@@ -69,11 +69,6 @@ public class ModuleNode extends ExternalSystemNode<ModuleData> {
return myChildNodes;
}
@Override
public String getName() {
return myData.getId();
}
@Nullable
@Override
protected String getMenuId() {
@@ -78,12 +78,6 @@ public class ProjectNode extends ExternalSystemNode<ProjectData> {
getStructure().updateFrom(getParent());
}
@Override
public String getName() {
final ProjectData projectData = getData();
return projectData != null ? projectData.getExternalName() : "unspecified";
}
@Override
protected void doUpdate() {
String autoImportHint = null;
@@ -77,11 +77,6 @@ public class TaskNode extends ExternalSystemNode<TaskData> {
return !myTaskData.isInherited() || getExternalProjectsView().showInheritedTasks();
}
@Override
public String getName() {
return myTaskData.getName();
}
public String getModuleOwnerName() {
return moduleOwnerName;
}
@@ -58,7 +58,8 @@
<!--Tool window services-->
<externalProjectDataService implementation="com.intellij.openapi.externalSystem.service.task.ToolWindowModuleService"/>
<externalProjectDataService implementation="com.intellij.openapi.externalSystem.service.task.ToolWindowTaskService"/>
<externalSystemViewContributor implementation="com.intellij.openapi.externalSystem.view.ExternalSystemViewDefaultContributor"/>
<externalSystemViewContributor id="default" order="last"
implementation="com.intellij.openapi.externalSystem.view.ExternalSystemViewDefaultContributor"/>
<!--Execution-->
<programRunner implementation="com.intellij.openapi.externalSystem.service.execution.ExternalSystemTaskRunner"/>
@@ -19,7 +19,9 @@ import com.intellij.icons.AllIcons;
import com.intellij.ide.projectView.PresentationData;
import com.intellij.openapi.externalSystem.model.DataNode;
import com.intellij.openapi.externalSystem.model.Key;
import com.intellij.openapi.externalSystem.model.ProjectKeys;
import com.intellij.openapi.externalSystem.model.ProjectSystemId;
import com.intellij.openapi.externalSystem.model.project.ModuleData;
import com.intellij.openapi.externalSystem.util.Order;
import com.intellij.openapi.externalSystem.view.ExternalProjectsView;
import com.intellij.openapi.externalSystem.view.ExternalSystemNode;
@@ -28,6 +30,7 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.SmartList;
import com.intellij.util.containers.MultiMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData;
import org.jetbrains.plugins.gradle.util.GradleConstants;
@@ -65,6 +68,15 @@ public class GradleViewContributor extends ExternalSystemViewContributor {
return result;
}
@Nullable
@Override
public String getDisplayName(@NotNull DataNode node) {
if (ProjectKeys.MODULE.equals(node.getKey())) {
return ((ModuleData)node.getData()).getId();
}
return super.getDisplayName(node);
}
private static void addCustomSourceSetsNodes(@NotNull ExternalProjectsView externalProjectsView,
@NotNull MultiMap<Key<?>, DataNode<?>> dataNodes,
@NotNull List<ExternalSystemNode<?>> result) {