diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradleColorAndFontPreviewPanel.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradleColorAndFontPreviewPanel.java index 7ee329145955..aae66ecd6b45 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradleColorAndFontPreviewPanel.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradleColorAndFontPreviewPanel.java @@ -18,6 +18,7 @@ import com.intellij.ui.treeStructure.Tree; import com.intellij.util.containers.hash.HashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.gradle.model.id.GradleSyntheticId; import org.jetbrains.plugins.gradle.ui.GradleIcons; import org.jetbrains.plugins.gradle.ui.GradleProjectStructureNodeDescriptor; import org.jetbrains.plugins.gradle.util.GradleBundle; @@ -257,7 +258,8 @@ public class GradleColorAndFontPreviewPanel implements PreviewPanel { } private DefaultMutableTreeNode createNode(@NotNull String text, @NotNull Icon icon, @Nullable TextAttributesKey textAttributesKey) { - final GradleProjectStructureNodeDescriptor descriptor = new GradleProjectStructureNodeDescriptor(text, text, icon); + final GradleProjectStructureNodeDescriptor descriptor + = new GradleProjectStructureNodeDescriptor(new GradleSyntheticId(text), text, icon); DefaultMutableTreeNode result = new DefaultMutableTreeNode(descriptor); if (textAttributesKey != null) { final PresentationData presentation = descriptor.getPresentation(); diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/diff/PlatformFacade.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/diff/PlatformFacade.java index bc8c9302a5a3..042fae1757d5 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/diff/PlatformFacade.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/diff/PlatformFacade.java @@ -8,7 +8,6 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.pom.java.LanguageLevel; import org.jetbrains.annotations.NotNull; -import javax.swing.*; import java.util.Collection; /** @@ -41,12 +40,6 @@ public interface PlatformFacade { @NotNull Collection getOrderEntries(@NotNull Module module); - /** - * @return icon that should be used for representation project root node at the tree UI controls used by the gradle integration - */ - @NotNull - Icon getProjectIcon(); - /** * Allows to derive from the given VFS file path that may be compared to the path used by the gradle api. *

diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/diff/PlatformFacadeImpl.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/diff/PlatformFacadeImpl.java index 84ae46eda4a4..587ffa7c7500 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/diff/PlatformFacadeImpl.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/diff/PlatformFacadeImpl.java @@ -1,6 +1,5 @@ package org.jetbrains.plugins.gradle.diff; -import com.intellij.openapi.application.ex.ApplicationInfoEx; import com.intellij.openapi.fileTypes.FileTypes; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; @@ -10,13 +9,11 @@ import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.roots.OrderEntry; import com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable; import com.intellij.openapi.roots.libraries.LibraryTable; -import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.pom.java.LanguageLevel; import org.jetbrains.annotations.NotNull; -import javax.swing.*; import java.util.Arrays; import java.util.Collection; @@ -50,12 +47,6 @@ public class PlatformFacadeImpl implements PlatformFacade { return Arrays.asList(ModuleRootManager.getInstance(module).getOrderEntries()); } - @NotNull - @Override - public Icon getProjectIcon() { - return IconLoader.getIcon(ApplicationInfoEx.getInstanceEx().getSmallIconUrl()); - } - @NotNull @Override public String getLocalFileSystemPath(@NotNull VirtualFile file) { diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/GradleLocalNodeImportHelper.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/GradleLocalNodeImportHelper.java index b21482025706..f7ae2ecbbe71 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/GradleLocalNodeImportHelper.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/GradleLocalNodeImportHelper.java @@ -98,35 +98,31 @@ public class GradleLocalNodeImportHelper { // Collect up. for (GradleProjectStructureNode n = node.getParent(); n != null; n = n.getParent()) { final GradleProjectStructureNodeDescriptor descriptor = n.getDescriptor(); - if (n.getType() == GradleEntityType.SYNTHETIC) { + if (n.getDescriptor().getElement().getType() == GradleEntityType.SYNTHETIC) { continue; } if (descriptor.getAttributes() != GradleTextAttributes.GRADLE_LOCAL_CHANGE) { break; } Object id = descriptor.getElement(); - if (id instanceof GradleEntityId) { - final Object entity = myIdMapper.mapIdToEntity((GradleEntityId)id); - if (entity instanceof GradleEntity) { - ((GradleEntity)entity).invite(context.visitor); - } + final Object entity = myIdMapper.mapIdToEntity((GradleEntityId)id); + if (entity instanceof GradleEntity) { + ((GradleEntity)entity).invite(context.visitor); } } // Collect down. final Stack toProcess = new Stack(); final Object id = node.getDescriptor().getElement(); - if (id instanceof GradleEntityId) { - final Object entity = myIdMapper.mapIdToEntity((GradleEntityId)id); - if (entity instanceof GradleEntity) { - toProcess.push((GradleEntity)entity); - } + final Object entity = myIdMapper.mapIdToEntity((GradleEntityId)id); + if (entity instanceof GradleEntity) { + toProcess.push((GradleEntity)entity); } - + context.recursive = true; while (!toProcess.isEmpty()) { - final GradleEntity entity = toProcess.pop(); - entity.invite(context.visitor); + final GradleEntity e = toProcess.pop(); + e.invite(context.visitor); } } diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/wizard/adjust/GradleAdjustImportSettingsStep.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/wizard/adjust/GradleAdjustImportSettingsStep.java index 122ee89ee76c..81e35d435fd7 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/wizard/adjust/GradleAdjustImportSettingsStep.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/wizard/adjust/GradleAdjustImportSettingsStep.java @@ -8,9 +8,10 @@ import com.intellij.ui.treeStructure.Tree; import com.intellij.util.containers.HashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.gradle.importing.GradleProjectImportBuilder; -import org.jetbrains.plugins.gradle.model.*; import org.jetbrains.plugins.gradle.importing.wizard.AbstractImportFromGradleWizardStep; import org.jetbrains.plugins.gradle.model.gradle.*; +import org.jetbrains.plugins.gradle.model.id.GradleEntityId; +import org.jetbrains.plugins.gradle.model.id.GradleSyntheticId; import org.jetbrains.plugins.gradle.ui.GradleProjectStructureNode; import org.jetbrains.plugins.gradle.util.GradleBundle; import org.jetbrains.plugins.gradle.util.GradleConstants; @@ -18,7 +19,10 @@ import org.jetbrains.plugins.gradle.util.GradleConstants; import javax.swing.*; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; -import javax.swing.tree.*; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.MutableTreeNode; +import javax.swing.tree.TreePath; import java.awt.*; import java.util.*; import java.util.List; @@ -175,7 +179,7 @@ public class GradleAdjustImportSettingsStep extends AbstractImportFromGradleWiza Map>> entity2nodes = new HashMap>>(); int counter = 0; - GradleProjectStructureNode root = buildNode(project, entity2nodes, counter++); + GradleProjectStructureNode root = buildNode(project, entity2nodes, counter++); List modules = new ArrayList(project.getModules()); Collections.sort(modules, Named.COMPARATOR); @@ -186,15 +190,15 @@ public class GradleAdjustImportSettingsStep extends AbstractImportFromGradleWiza for (GradleModule module : modules) { GradleModule moduleCopy = module.clone(cloneContext); moduleMappings.put(module, moduleCopy); - GradleProjectStructureNode moduleNode = buildNode(module, entity2nodes, counter++); + GradleProjectStructureNode moduleNode = buildNode(module, entity2nodes, counter++); moduleNodes.add(moduleNode); for (GradleContentRoot contentRoot : moduleCopy.getContentRoots()) { moduleNode.add(buildNode(contentRoot, entity2nodes, counter++)); } Collection dependencies = module.getDependencies(); if (!dependencies.isEmpty()) { - GradleProjectStructureNode dependenciesNode - = new GradleProjectStructureNode(GradleConstants.DEPENDENCIES_NODE_DESCRIPTOR, GradleEntityType.SYNTHETIC); + GradleProjectStructureNode dependenciesNode + = new GradleProjectStructureNode(GradleConstants.DEPENDENCIES_NODE_DESCRIPTOR); final List moduleDependencies = new ArrayList(); final List libraryDependencies = new ArrayList(); GradleEntityVisitor visitor = new GradleEntityVisitorAdapter() { @@ -234,8 +238,8 @@ public class GradleAdjustImportSettingsStep extends AbstractImportFromGradleWiza } else { // Insert intermediate 'modules' and 'libraries' nodes if the project has both libraries and nodes. - GradleProjectStructureNode modulesNode - = new GradleProjectStructureNode(GradleConstants.MODULES_NODE_DESCRIPTOR, GradleEntityType.SYNTHETIC); + GradleProjectStructureNode modulesNode + = new GradleProjectStructureNode(GradleConstants.MODULES_NODE_DESCRIPTOR); for (MutableTreeNode node : moduleNodes) { modulesNode.add(node); } @@ -243,8 +247,8 @@ public class GradleAdjustImportSettingsStep extends AbstractImportFromGradleWiza List sortedLibraries = new ArrayList(libraries); Collections.sort(sortedLibraries, Named.COMPARATOR); - GradleProjectStructureNode librariesNode - = new GradleProjectStructureNode(GradleConstants.LIBRARIES_NODE_DESCRIPTOR, GradleEntityType.SYNTHETIC); + GradleProjectStructureNode librariesNode + = new GradleProjectStructureNode(GradleConstants.LIBRARIES_NODE_DESCRIPTOR); for (GradleLibrary library : sortedLibraries) { librariesNode.add(buildNode(library, entity2nodes, counter++)); } @@ -258,13 +262,13 @@ public class GradleAdjustImportSettingsStep extends AbstractImportFromGradleWiza builder.setModuleMappings(moduleMappings); } - private GradleProjectStructureNode buildNode( - @NotNull T entity, @NotNull Map>> processed, int counter) + private GradleProjectStructureNode buildNode( + @NotNull GradleEntity entity, @NotNull Map>> processed, int counter) { // We build tree node, its settings control and map them altogether. The only trick here is that nodes can reuse the same // settings control (e.g. more than one node may have the same library as a dependency, so, library dependency node for // every control will use the same settings control). - GradleProjectStructureNode result = new GradleProjectStructureNode(myFactory.buildDescriptor(entity), GradleEntityType.SYNTHETIC); + GradleProjectStructureNode result = new GradleProjectStructureNode(myFactory.buildDescriptor(entity)); Pair> pair = processed.get(entity); if (pair == null) { String cardName = String.valueOf(counter); diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/wizard/adjust/GradleProjectStructureFactory.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/wizard/adjust/GradleProjectStructureFactory.java index 273f95ba4087..14a3a0cb6758 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/wizard/adjust/GradleProjectStructureFactory.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/wizard/adjust/GradleProjectStructureFactory.java @@ -1,14 +1,14 @@ package org.jetbrains.plugins.gradle.importing.wizard.adjust; -import com.intellij.openapi.application.ex.ApplicationInfoEx; -import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.util.Ref; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.gradle.model.gradle.*; -import org.jetbrains.plugins.gradle.ui.GradleIcons; +import org.jetbrains.plugins.gradle.model.id.GradleEntityId; +import org.jetbrains.plugins.gradle.model.id.GradleEntityIdMapper; import org.jetbrains.plugins.gradle.ui.GradleProjectStructureNode; import org.jetbrains.plugins.gradle.ui.GradleProjectStructureNodeDescriptor; import org.jetbrains.plugins.gradle.util.GradleBundle; +import org.jetbrains.plugins.gradle.util.GradleUtil; import javax.swing.tree.DefaultTreeModel; import java.beans.PropertyChangeEvent; @@ -32,32 +32,27 @@ public class GradleProjectStructureFactory { @SuppressWarnings({"MethodMayBeStatic", "unchecked"}) @NotNull - public GradleProjectStructureNodeDescriptor buildDescriptor(@NotNull T entity) { - final Ref> result = new Ref>(); + public GradleProjectStructureNodeDescriptor buildDescriptor(@NotNull T entity) { + final Ref text = new Ref(); entity.invite(new GradleEntityVisitor() { @Override public void visit(@NotNull GradleProject project) { - result.set(new GradleProjectStructureNodeDescriptor( - project, project.getName(), IconLoader.getIcon(ApplicationInfoEx.getInstanceEx().getSmallIconUrl()) - )); + text.set(project.getName()); } @Override public void visit(@NotNull GradleModule module) { - result.set(new GradleProjectStructureNodeDescriptor(module, module.getName(), GradleIcons.MODULE_ICON)); + text.set(module.getName()); } @Override public void visit(@NotNull GradleContentRoot contentRoot) { - result.set(new GradleProjectStructureNodeDescriptor( - contentRoot, - GradleBundle.message("gradle.import.structure.tree.node.content.root"), GradleIcons.CONTENT_ROOT_ICON - )); + text.set(GradleBundle.message("gradle.import.structure.tree.node.content.root")); } @Override public void visit(@NotNull GradleLibrary library) { - result.set(new GradleProjectStructureNodeDescriptor(library, library.getName(), GradleIcons.LIB_ICON)); + text.set(library.getName()); } @Override @@ -70,7 +65,7 @@ public class GradleProjectStructureFactory { visit(dependency.getTarget()); } }); - return (GradleProjectStructureNodeDescriptor)result.get(); + return GradleUtil.buildDescriptor(GradleEntityIdMapper.mapEntityToId(entity), text.get()); } @SuppressWarnings("MethodMayBeStatic") diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/GradleEntityType.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/GradleEntityType.java index 59006b9f09a6..4f43cc086056 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/GradleEntityType.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/GradleEntityType.java @@ -1,8 +1,6 @@ package org.jetbrains.plugins.gradle.model; -import com.intellij.openapi.components.ServiceManager; import org.jetbrains.annotations.Nullable; -import org.jetbrains.plugins.gradle.diff.PlatformFacade; import org.jetbrains.plugins.gradle.ui.GradleIcons; import javax.swing.*; @@ -12,14 +10,8 @@ import javax.swing.*; * @since 2/7/12 11:18 AM */ public enum GradleEntityType { - MODULE(GradleIcons.MODULE_ICON), MODULE_DEPENDENCY(GradleIcons.MODULE_ICON), LIBRARY_DEPENDENCY(GradleIcons.LIB_ICON), SYNTHETIC(null), - PROJECT(null) { - @Nullable - @Override - public Icon getIcon() { - return ServiceManager.getService(PlatformFacade.class).getProjectIcon(); - } - }; + PROJECT(GradleIcons.PROJECT_ICON), MODULE(GradleIcons.MODULE_ICON), MODULE_DEPENDENCY(GradleIcons.MODULE_ICON), + LIBRARY_DEPENDENCY(GradleIcons.LIB_ICON), CONTENT_ROOT(GradleIcons.CONTENT_ROOT_ICON), SYNTHETIC(null); @Nullable private final Icon myIcon; diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/AbstractGradleEntityId.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleAbstractEntityId.java similarity index 85% rename from plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/AbstractGradleEntityId.java rename to plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleAbstractEntityId.java index f60d42e3a9ee..17405eda7805 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/AbstractGradleEntityId.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleAbstractEntityId.java @@ -12,12 +12,12 @@ import java.util.concurrent.atomic.AtomicReference; * @author Denis Zhdanov * @since 2/14/12 1:32 PM */ -public abstract class AbstractGradleEntityId implements GradleEntityId { +public abstract class GradleAbstractEntityId implements GradleEntityId { @NotNull private final AtomicReference myOwner = new AtomicReference(); @NotNull private final GradleEntityType myType; - public AbstractGradleEntityId(@NotNull GradleEntityType type, @NotNull GradleEntityOwner owner) { + public GradleAbstractEntityId(@NotNull GradleEntityType type, @NotNull GradleEntityOwner owner) { myType = type; myOwner.set(owner); } @@ -49,7 +49,7 @@ public abstract class AbstractGradleEntityId implements GradleEntityId { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - AbstractGradleEntityId that = (AbstractGradleEntityId)o; + GradleAbstractEntityId that = (GradleAbstractEntityId)o; return myType.equals(that.myType); } } diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleContentRootId.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleContentRootId.java new file mode 100644 index 000000000000..e73b70937e44 --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleContentRootId.java @@ -0,0 +1,42 @@ +package org.jetbrains.plugins.gradle.model.id; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.gradle.model.GradleEntityOwner; +import org.jetbrains.plugins.gradle.model.GradleEntityType; +import org.jetbrains.plugins.gradle.model.gradle.GradleContentRoot; +import org.jetbrains.plugins.gradle.model.gradle.GradleModule; + +/** + * @author Denis Zhdanov + * @since 2/16/12 12:22 PM + */ +public class GradleContentRootId extends GradleAbstractEntityId { + + @NotNull private final String myModuleName; + @NotNull private final String myRootPath; + + public GradleContentRootId(@NotNull GradleEntityOwner owner, @NotNull String moduleName, @NotNull String rootPath) { + super(GradleEntityType.CONTENT_ROOT, owner); + myModuleName = moduleName; + myRootPath = rootPath; + } + + @Override + public Object mapToEntity(@NotNull GradleEntityMappingContext context) { + switch (getOwner()) { + case GRADLE: + final GradleModule module = context.getProjectStructureHelper().findGradleModule(myModuleName); + if (module == null) { + return null; + } + for (GradleContentRoot root : module.getContentRoots()) { + if (myRootPath.equals(root.getRootPath())) { + return root; + } + } + return null; + case INTELLIJ: return null; + } + return null; + } +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleEntityIdMapper.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleEntityIdMapper.java index a9313ce9592b..4d5f08219d8f 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleEntityIdMapper.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleEntityIdMapper.java @@ -69,7 +69,7 @@ public class GradleEntityIdMapper { @Override public void visit(@NotNull GradleContentRoot contentRoot) { - // TODO den implement + result.set(new GradleContentRootId(GradleEntityOwner.GRADLE, contentRoot.getOwnerModule().getName(), contentRoot.getRootPath())); } @Override diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleLibraryDependencyId.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleLibraryDependencyId.java index 4500d6a715b3..b0584a9dc072 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleLibraryDependencyId.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleLibraryDependencyId.java @@ -8,7 +8,7 @@ import org.jetbrains.plugins.gradle.model.GradleEntityType; * @author Denis Zhdanov * @since 2/14/12 1:59 PM */ -public class GradleLibraryDependencyId extends AbstractGradleEntityId { +public class GradleLibraryDependencyId extends GradleAbstractEntityId { @NotNull private final String myModuleName; @NotNull private final String myLibraryName; diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleModuleDependencyId.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleModuleDependencyId.java index 52d886877b54..285626fdb950 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleModuleDependencyId.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleModuleDependencyId.java @@ -8,7 +8,7 @@ import org.jetbrains.plugins.gradle.model.GradleEntityType; * @author Denis Zhdanov * @since 2/14/12 2:06 PM */ -public class GradleModuleDependencyId extends AbstractGradleEntityId { +public class GradleModuleDependencyId extends GradleAbstractEntityId { @NotNull private final String myOwnerModuleName; @NotNull private final String myDependencyModuleName; diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleModuleId.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleModuleId.java index fb995c3c3b21..e447f2189540 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleModuleId.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleModuleId.java @@ -8,7 +8,7 @@ import org.jetbrains.plugins.gradle.model.GradleEntityType; * @author Denis Zhdanov * @since 2/14/12 1:55 PM */ -public class GradleModuleId extends AbstractGradleEntityId { +public class GradleModuleId extends GradleAbstractEntityId { @NotNull private final String myModuleName; diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleProjectId.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleProjectId.java index abca15d1065f..1f1e869dd5e9 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleProjectId.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleProjectId.java @@ -8,7 +8,7 @@ import org.jetbrains.plugins.gradle.model.GradleEntityType; * @author Denis Zhdanov * @since 2/14/12 1:34 PM */ -public class GradleProjectId extends AbstractGradleEntityId { +public class GradleProjectId extends GradleAbstractEntityId { public GradleProjectId(@NotNull GradleEntityOwner owner) { super(GradleEntityType.PROJECT, owner); diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleSyntheticId.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleSyntheticId.java new file mode 100644 index 000000000000..1eb78d1fc595 --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/id/GradleSyntheticId.java @@ -0,0 +1,36 @@ +package org.jetbrains.plugins.gradle.model.id; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.gradle.model.GradleEntityOwner; +import org.jetbrains.plugins.gradle.model.GradleEntityType; + +/** + * Whole 'entity id' thing is necessary for mapping 'sync project structures' tree nodes to the domain entities. However, there are + * special types of nodes that don't map to any entity - {@link GradleEntityType#SYNTHETIC synthetic nodes}. + *

+ * This class is designed to serve as a data object for such a nodes. + *

+ * Thread-safe. + * + * @author Denis Zhdanov + * @since 2/16/12 11:40 AM + */ +public class GradleSyntheticId extends GradleAbstractEntityId { + + @NotNull private final String myText; + + public GradleSyntheticId(@NotNull String text) { + super(GradleEntityType.SYNTHETIC, GradleEntityOwner.GRADLE/* no matter what owner is used */); + myText = text; + } + + @Override + public String toString() { + return myText; + } + + @Override + public Object mapToEntity(@NotNull GradleEntityMappingContext context) { + return null; + } +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/sync/GradleProjectStructureTreeModel.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/sync/GradleProjectStructureTreeModel.java index 500429da01ab..e4420b95e60c 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/sync/GradleProjectStructureTreeModel.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/sync/GradleProjectStructureTreeModel.java @@ -11,13 +11,12 @@ import com.intellij.util.containers.hash.HashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.gradle.config.GradleTextAttributes; import org.jetbrains.plugins.gradle.diff.*; -import org.jetbrains.plugins.gradle.model.GradleEntityType; import org.jetbrains.plugins.gradle.model.id.*; import org.jetbrains.plugins.gradle.ui.GradleProjectStructureNode; import org.jetbrains.plugins.gradle.ui.GradleProjectStructureNodeDescriptor; import org.jetbrains.plugins.gradle.util.GradleConstants; +import org.jetbrains.plugins.gradle.util.GradleUtil; -import javax.swing.*; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeNode; import java.util.ArrayList; @@ -45,8 +44,8 @@ public class GradleProjectStructureTreeModel extends DefaultTreeModel { * |_dependency2 * */ - private final Map> myModuleDependencies - = new HashMap>(); + private final Map> myModuleDependencies + = new HashMap>(); private final Map> myModules = new HashMap>(); @@ -109,7 +108,7 @@ public class GradleProjectStructureTreeModel extends DefaultTreeModel { if (dependencies.isEmpty()) { continue; } - GradleProjectStructureNode dependenciesNode = getDependenciesNode(moduleId); + GradleProjectStructureNode dependenciesNode = getDependenciesNode(moduleId); for (GradleProjectStructureNode dependency : dependencies) { dependenciesNode.add(dependency); } @@ -123,28 +122,21 @@ public class GradleProjectStructureTreeModel extends DefaultTreeModel { public Project getProject() { return myProject; } - - private static GradleProjectStructureNodeDescriptor buildDescriptor(@NotNull T entity, @NotNull String name, @NotNull Icon icon) { - return new GradleProjectStructureNodeDescriptor(entity, name, icon); - } - private GradleProjectStructureNode buildNode(@NotNull T entityId, @NotNull String name) { - final Icon icon = entityId.getType().getIcon(); - assert icon != null; - final GradleProjectStructureNode result - = new GradleProjectStructureNode(buildDescriptor(entityId, name, icon), entityId.getType()); + private GradleProjectStructureNode buildNode(@NotNull T id, @NotNull String name) { + final GradleProjectStructureNode result = GradleUtil.buildNode(id, name); result.addListener(myNodeListener); return result; } - private GradleProjectStructureNode getDependenciesNode(@NotNull GradleModuleId id) { - final GradleProjectStructureNode cached = myModuleDependencies.get(id.getModuleName()); + private GradleProjectStructureNode getDependenciesNode(@NotNull GradleModuleId id) { + final GradleProjectStructureNode cached = myModuleDependencies.get(id.getModuleName()); if (cached != null) { return cached; } GradleProjectStructureNode moduleNode = getModuleNode(id); - GradleProjectStructureNode result - = new GradleProjectStructureNode(GradleConstants.DEPENDENCIES_NODE_DESCRIPTOR, GradleEntityType.SYNTHETIC); + GradleProjectStructureNode result + = new GradleProjectStructureNode(GradleConstants.DEPENDENCIES_NODE_DESCRIPTOR); moduleNode.add(result); myModuleDependencies.put(id.getModuleName(), result); @@ -201,7 +193,7 @@ public class GradleProjectStructureTreeModel extends DefaultTreeModel { } private void processNewMismatchedLibraryPathChange(@NotNull GradleMismatchedLibraryPathChange change) { - for (GradleProjectStructureNode holder : myModuleDependencies.values()) { + for (GradleProjectStructureNode holder : myModuleDependencies.values()) { for (GradleProjectStructureNode dependencyNode : holder.getChildren(GradleLibraryDependencyId.class)) { final GradleLibraryDependencyId id = dependencyNode.getDescriptor().getElement(); if (change.getLibraryName().equals(id.getLibraryName())) { @@ -220,7 +212,7 @@ public class GradleProjectStructureTreeModel extends DefaultTreeModel { attributes = GradleTextAttributes.INTELLIJ_LOCAL_CHANGE; } assert id != null; - final GradleProjectStructureNode dependenciesNode = getDependenciesNode(id.getModuleId()); + final GradleProjectStructureNode dependenciesNode = getDependenciesNode(id.getModuleId()); for (GradleProjectStructureNode node : dependenciesNode.getChildren(GradleLibraryDependencyId.class)) { GradleProjectStructureNodeDescriptor d = node.getDescriptor(); if (id.equals(d.getElement())) { @@ -261,7 +253,7 @@ public class GradleProjectStructureTreeModel extends DefaultTreeModel { } private void processObsoleteMismatchedLibraryPathChange(@NotNull GradleMismatchedLibraryPathChange change) { - for (GradleProjectStructureNode holder : myModuleDependencies.values()) { + for (GradleProjectStructureNode holder : myModuleDependencies.values()) { for (GradleProjectStructureNode node : holder.getChildren(GradleLibraryDependencyId.class)) { final GradleLibraryDependencyId id = node.getDescriptor().getElement(); if (id.getLibraryName().equals(change.getLibraryName())) { @@ -285,7 +277,7 @@ public class GradleProjectStructureTreeModel extends DefaultTreeModel { else { removeNode = !myProjectStructureHelper.isGradleLibraryDependencyExist(id); } - final GradleProjectStructureNode holder = myModuleDependencies.get(id.getModuleName()); + final GradleProjectStructureNode holder = myModuleDependencies.get(id.getModuleName()); if (holder == null) { return; } diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/ui/GradleIcons.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/ui/GradleIcons.java index 0dbc2256ae2b..80c211ba48ac 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/ui/GradleIcons.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/ui/GradleIcons.java @@ -1,6 +1,8 @@ package org.jetbrains.plugins.gradle.ui; +import com.intellij.openapi.application.ex.ApplicationInfoEx; import com.intellij.openapi.util.IconLoader; +import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -14,7 +16,19 @@ public class GradleIcons { public static final Icon LIB_ICON = IconLoader.getIcon("/nodes/ppLib.png"); public static final Icon MODULE_ICON = IconLoader.getIcon("/nodes/ModuleOpen.png"); public static final Icon CONTENT_ROOT_ICON = IconLoader.getIcon("/modules/addContentEntry.png"); + public static final Icon PROJECT_ICON = getProjectIcon(); private GradleIcons() { } + + @NotNull + private static Icon getProjectIcon() { + try { + return IconLoader.getIcon(ApplicationInfoEx.getInstanceEx().getSmallIconUrl()); + } + catch (Exception e) { + // Control flow may reach this place if we run tests and platform IoC has not been initialised. + return IconLoader.getIcon("/nodes/ideProject.png"); + } + } } diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/ui/GradleProjectStructureNode.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/ui/GradleProjectStructureNode.java index 77582a42af93..ca12256aa0a1 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/ui/GradleProjectStructureNode.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/ui/GradleProjectStructureNode.java @@ -4,7 +4,7 @@ import com.intellij.openapi.editor.colors.TextAttributesKey; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.gradle.config.GradleTextAttributes; import org.jetbrains.plugins.gradle.diff.GradleProjectStructureChange; -import org.jetbrains.plugins.gradle.model.GradleEntityType; +import org.jetbrains.plugins.gradle.model.id.GradleEntityId; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.MutableTreeNode; @@ -18,7 +18,9 @@ import java.util.concurrent.CopyOnWriteArrayList; * @since 8/23/11 3:50 PM * @param type of the target entity {@link GradleProjectStructureNodeDescriptor#getElement() associated} with the current node */ -public class GradleProjectStructureNode extends DefaultMutableTreeNode implements Iterable> { +public class GradleProjectStructureNode extends DefaultMutableTreeNode + implements Iterable> +{ public static final Comparator> NODE_COMPARATOR = new Comparator>() { @Override @@ -42,12 +44,10 @@ public class GradleProjectStructureNode extends DefaultMutableTreeNode implem private final List myListeners = new CopyOnWriteArrayList(); private final GradleProjectStructureNodeDescriptor myDescriptor; - private final GradleEntityType myType; - public GradleProjectStructureNode(@NotNull GradleProjectStructureNodeDescriptor descriptor, @NotNull GradleEntityType type) { + public GradleProjectStructureNode(@NotNull GradleProjectStructureNodeDescriptor descriptor) { super(descriptor); myDescriptor = descriptor; - myType = type; } @NotNull @@ -55,11 +55,6 @@ public class GradleProjectStructureNode extends DefaultMutableTreeNode implem return myDescriptor; } - @NotNull - public GradleEntityType getType() { - return myType; - } - @Override public GradleProjectStructureNode getChildAt(int index) { return (GradleProjectStructureNode)super.getChildAt(index); @@ -175,7 +170,7 @@ public class GradleProjectStructureNode extends DefaultMutableTreeNode implem */ @SuppressWarnings("unchecked") @NotNull - public Collection> getChildren(@NotNull Class clazz) { + public Collection> getChildren(@NotNull Class clazz) { List> result = null; for (int i = 0; i < getChildCount(); i++) { final GradleProjectStructureNode child = getChildAt(i); diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/ui/GradleProjectStructureNodeDescriptor.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/ui/GradleProjectStructureNodeDescriptor.java index 9f9f392b120c..b983ce7b658c 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/ui/GradleProjectStructureNodeDescriptor.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/ui/GradleProjectStructureNodeDescriptor.java @@ -20,16 +20,16 @@ import javax.swing.*; * @since 8/12/11 2:47 PM * @param target element type */ -public class GradleProjectStructureNodeDescriptor extends PresentableNodeDescriptor { +public class GradleProjectStructureNodeDescriptor extends PresentableNodeDescriptor { private TextAttributesKey myAttributes = GradleTextAttributes.GRADLE_NO_CHANGE; - private final T myData; + private final T myId; @SuppressWarnings("NullableProblems") - public GradleProjectStructureNodeDescriptor(@NotNull T data, @NotNull String text, @Nullable Icon icon) { + public GradleProjectStructureNodeDescriptor(@NotNull T id, @NotNull String text, @Nullable Icon icon) { super(null, null); - myData = data; + myId = id; myOpenIcon = myClosedIcon = icon; myName = text; } @@ -45,7 +45,7 @@ public class GradleProjectStructureNodeDescriptor extends PresentableNodeDesc @NotNull @Override public T getElement() { - return myData; + return myId; } public void setName(@NotNull String name) { @@ -59,18 +59,14 @@ public class GradleProjectStructureNodeDescriptor extends PresentableNodeDesc public void setAttributes(@NotNull TextAttributesKey attributes) { myAttributes = attributes; - // TODO den remove the type check - if (myData instanceof GradleEntityId) { - final GradleEntityId id = (GradleEntityId)myData; - GradleEntityOwner owner = id.getOwner(); - if (attributes == GradleTextAttributes.GRADLE_LOCAL_CHANGE) { - owner = GradleEntityOwner.GRADLE; - } - else if (attributes == GradleTextAttributes.GRADLE_NO_CHANGE || attributes == GradleTextAttributes.INTELLIJ_LOCAL_CHANGE) { - owner = GradleEntityOwner.INTELLIJ; - } - id.setOwner(owner); + GradleEntityOwner owner = myId.getOwner(); + if (attributes == GradleTextAttributes.GRADLE_LOCAL_CHANGE) { + owner = GradleEntityOwner.GRADLE; } + else if (attributes == GradleTextAttributes.GRADLE_NO_CHANGE || attributes == GradleTextAttributes.INTELLIJ_LOCAL_CHANGE) { + owner = GradleEntityOwner.INTELLIJ; + } + myId.setOwner(owner); update(); } } \ No newline at end of file diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/util/GradleConstants.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/util/GradleConstants.java index 880b002da811..ebb7978947da 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/util/GradleConstants.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/util/GradleConstants.java @@ -1,6 +1,8 @@ package org.jetbrains.plugins.gradle.util; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.gradle.model.id.GradleSyntheticId; import org.jetbrains.plugins.gradle.ui.GradleProjectStructureNodeDescriptor; /** @@ -20,27 +22,19 @@ public class GradleConstants { @NonNls public static final String ACTION_GROUP_SYNC_TREE = "Gradle.SyncTreeGroup"; - public static final GradleProjectStructureNodeDescriptor DEPENDENCIES_NODE_DESCRIPTOR - = new GradleProjectStructureNodeDescriptor( - GradleBundle.message("gradle.project.structure.tree.node.dependencies"), - GradleBundle.message("gradle.project.structure.tree.node.dependencies"), - null - ); + public static final GradleProjectStructureNodeDescriptor DEPENDENCIES_NODE_DESCRIPTOR + = buildSyntheticDescriptor(GradleBundle.message("gradle.project.structure.tree.node.dependencies")); - public static final GradleProjectStructureNodeDescriptor MODULES_NODE_DESCRIPTOR - = new GradleProjectStructureNodeDescriptor( - GradleBundle.message("gradle.import.structure.tree.node.modules"), - GradleBundle.message("gradle.import.structure.tree.node.modules"), - null - ); + public static final GradleProjectStructureNodeDescriptor MODULES_NODE_DESCRIPTOR + = buildSyntheticDescriptor(GradleBundle.message("gradle.import.structure.tree.node.modules")); - public static final GradleProjectStructureNodeDescriptor LIBRARIES_NODE_DESCRIPTOR - = new GradleProjectStructureNodeDescriptor( - GradleBundle.message("gradle.import.structure.tree.node.libraries"), - GradleBundle.message("gradle.import.structure.tree.node.libraries"), - null - ); + public static final GradleProjectStructureNodeDescriptor LIBRARIES_NODE_DESCRIPTOR + = buildSyntheticDescriptor(GradleBundle.message("gradle.import.structure.tree.node.libraries")); private GradleConstants() { } + + private static GradleProjectStructureNodeDescriptor buildSyntheticDescriptor(@NotNull String text) { + return new GradleProjectStructureNodeDescriptor(new GradleSyntheticId(text), text, null); + } } diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/util/GradleUtil.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/util/GradleUtil.java index 39e95dee88ff..b2327cf987f0 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/util/GradleUtil.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/util/GradleUtil.java @@ -25,10 +25,13 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.gradle.config.GradleSettings; import org.jetbrains.plugins.gradle.model.gradle.GradleProject; +import org.jetbrains.plugins.gradle.model.id.GradleEntityId; import org.jetbrains.plugins.gradle.model.intellij.IntellijEntityVisitor; import org.jetbrains.plugins.gradle.remote.GradleApiException; import org.jetbrains.plugins.gradle.task.GradleResolveProjectTask; import org.jetbrains.plugins.gradle.ui.GradleIcons; +import org.jetbrains.plugins.gradle.ui.GradleProjectStructureNode; +import org.jetbrains.plugins.gradle.ui.GradleProjectStructureNodeDescriptor; import javax.swing.*; import java.awt.*; @@ -219,6 +222,20 @@ public class GradleUtil { visitor.visit(((ModuleOrderEntry)entity)); } } + + public static GradleProjectStructureNodeDescriptor buildDescriptor(@NotNull T id, @NotNull String name) { + return new GradleProjectStructureNodeDescriptor(id, name, id.getType().getIcon()); + } + + @NotNull + public static GradleProjectStructureNode buildNode(@NotNull T id) { + return new GradleProjectStructureNode(buildDescriptor(id, id.toString())); + } + + @NotNull + public static GradleProjectStructureNode buildNode(@NotNull T id, @NotNull String name) { + return new GradleProjectStructureNode(buildDescriptor(id, name)); + } private interface TaskUnderProgress { void execute(@NotNull ProgressIndicator indicator); diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testutil/ProjectStructureChecker.groovy b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testutil/ProjectStructureChecker.groovy index 4c3980517d62..4e2caf61aed5 100644 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testutil/ProjectStructureChecker.groovy +++ b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testutil/ProjectStructureChecker.groovy @@ -10,6 +10,7 @@ import static junit.framework.Assert.assertEquals import static junit.framework.Assert.fail import org.jetbrains.plugins.gradle.model.GradleEntityOwner import org.jetbrains.plugins.gradle.model.id.GradleEntityId +import org.jetbrains.plugins.gradle.model.GradleEntityType /** * @author Denis Zhdanov @@ -64,7 +65,7 @@ class ProjectStructureChecker { def expectedMarkup = COLORS[node.children().find {it instanceof CharSequence}]?: GradleTextAttributes.GRADLE_NO_CHANGE assertEquals("node '$descriptor'", expectedMarkup, descriptor.attributes) - if (descriptor.element instanceof GradleEntityId) { + if (descriptor.element.type != GradleEntityType.SYNTHETIC) { def expectedOwner = expectedMarkup == GradleTextAttributes.GRADLE_LOCAL_CHANGE ? GradleEntityOwner.GRADLE : GradleEntityOwner.INTELLIJ assertEquals("node '$descriptor'", expectedOwner, descriptor.element.owner) }