supported find usages for facets in Project Structure dialog (IDEA-50753)
authornik <Nikolay.Chashnikov@jetbrains.com>
Fri, 8 Apr 2011 10:35:58 +0000 (14:35 +0400)
committernik <Nikolay.Chashnikov@jetbrains.com>
Fri, 8 Apr 2011 10:36:56 +0000 (14:36 +0400)
19 files changed:
java/compiler/impl/src/com/intellij/packaging/impl/elements/FacetBasedPackagingElement.java [new file with mode: 0644]
java/compiler/impl/src/com/intellij/packaging/impl/ui/ArtifactElementPresentation.java
java/compiler/impl/src/com/intellij/packaging/impl/ui/DelegatedPackagingElementPresentation.java
java/compiler/impl/src/com/intellij/packaging/impl/ui/LibraryElementPresentation.java
java/compiler/impl/src/com/intellij/packaging/impl/ui/ModuleElementPresentation.java
java/compiler/openapi/src/com/intellij/packaging/ui/TreeNodePresentation.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactProjectStructureElement.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/ArtifactEditorFindUsagesActionBase.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/LayoutTreeFindUsagesAction.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/DelegatedSourceItemPresentation.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/LibrarySourceItem.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ModuleOutputSourceItem.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ModuleSourceItemGroup.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/SourceItemNode.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/actions/SourceItemFindUsagesAction.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetConfigurable.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetEditorFacadeImpl.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetStructureConfigurable.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/FacetProjectStructureElement.java [new file with mode: 0644]

diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/FacetBasedPackagingElement.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/FacetBasedPackagingElement.java
new file mode 100644 (file)
index 0000000..a34fdaf
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2000-2011 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.packaging.impl.elements;
+
+import com.intellij.facet.Facet;
+import com.intellij.packaging.elements.PackagingElementResolvingContext;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * @author nik
+ */
+public interface FacetBasedPackagingElement {
+  @Nullable
+  Facet findFacet(@NotNull PackagingElementResolvingContext context);
+}
index a9dabbf9f02db5842318582394ddd55691bdf1e2..a013fea361b548322f0f6bef665927fdf0d9b40a 100644 (file)
@@ -48,11 +48,6 @@ public class ArtifactElementPresentation extends TreeNodePresentation {
   }
 
   @Override
-  public Object getSourceObject() {
-    return myArtifactPointer;
-  }
-
-  @Override
   public void navigateToSource() {
     final Artifact artifact = findArtifact();
     if (artifact != null) {
index ccda22172fd60201d9197921108e7c2571ecfde1..8c5ac7d0fd9333df0af150972c401934cd9de8aa 100644 (file)
@@ -57,11 +57,6 @@ public class DelegatedPackagingElementPresentation extends PackagingElementPrese
     myDelegate.navigateToSource();
   }
 
-  @Nullable
-  public Object getSourceObject() {
-    return myDelegate.getSourceObject();
-  }
-
   public int getWeight() {
     return myDelegate.getWeight();
   }
index b6a2a011796761b5ac9ff3c24f29495fc393f92c..ab3fc860ee379a7d802b484a3662eba65560f663 100644 (file)
@@ -58,11 +58,6 @@ public class LibraryElementPresentation extends PackagingElementPresentation {
   }
 
   @Override
-  public Object getSourceObject() {
-    return myLibrary;
-  }
-
-  @Override
   public void navigateToSource() {
     myContext.selectLibrary(myLibrary);
   }
index 47c793ba7b28093adde77b4abc0ba31b9badb31b..d01df08ad94927d4d44809ab5a6375dcfc0ec913 100644 (file)
@@ -51,11 +51,6 @@ public class ModuleElementPresentation extends TreeNodePresentation {
     return findModule() != null;
   }
 
-  @Override
-  public Object getSourceObject() {
-    return findModule();
-  }
-
   @Nullable
   private Module findModule() {
     return myModulePointer != null ? myModulePointer.getModule() : null;
index 6ef74756c8c1720923a50e7f6d0e8637692c5938..96fe6ec5f7c26fb691dc6ae2ee3c05aac2a6d934 100644 (file)
@@ -45,6 +45,9 @@ public abstract class TreeNodePresentation {
   public void navigateToSource() {
   }
 
+  /**
+   * @deprecated this method is not used and will be removed in the future
+   */
   @Nullable
   public Object getSourceObject() {
     return null;
index 5d1dc1d32061ea8cfaea0b693e48f016708cdb54..630f125a7b431db6ef7b3bf42863967a86a01290 100644 (file)
@@ -15,6 +15,7 @@
  */
 package com.intellij.openapi.roots.ui.configuration.artifacts;
 
+import com.intellij.facet.Facet;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.roots.libraries.Library;
 import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
@@ -25,9 +26,11 @@ import com.intellij.packaging.impl.artifacts.ArtifactUtil;
 import com.intellij.packaging.impl.artifacts.PackagingElementPath;
 import com.intellij.packaging.impl.artifacts.PackagingElementProcessor;
 import com.intellij.packaging.impl.elements.ArtifactPackagingElement;
+import com.intellij.packaging.impl.elements.FacetBasedPackagingElement;
 import com.intellij.packaging.impl.elements.LibraryPackagingElement;
 import com.intellij.packaging.impl.elements.ModuleOutputPackagingElement;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -64,25 +67,10 @@ public class ArtifactProjectStructureElement extends ProjectStructureElement {
     ArtifactUtil.processPackagingElements(myArtifactsStructureContext.getRootElement(artifact), null, new PackagingElementProcessor<PackagingElement<?>>() {
       @Override
       public boolean process(@NotNull PackagingElement<?> packagingElement, @NotNull PackagingElementPath path) {
-        if (packagingElement instanceof ModuleOutputPackagingElement) {
-          final Module module = ((ModuleOutputPackagingElement)packagingElement).findModule(myArtifactsStructureContext);
-          if (module != null) {
-            usages.add(createUsage(packagingElement, path, new ModuleProjectStructureElement(myContext, module)));
-          }
-        }
-        else if (packagingElement instanceof LibraryPackagingElement) {
-          final Library library = ((LibraryPackagingElement)packagingElement).findLibrary(myArtifactsStructureContext);
-          if (library != null) {
-            usages.add(createUsage(packagingElement, path,
-                                   new LibraryProjectStructureElement(ArtifactProjectStructureElement.this.myContext, library)));
-          }
-        }
-        else if (packagingElement instanceof ArtifactPackagingElement) {
-          final Artifact usedArtifact = ((ArtifactPackagingElement)packagingElement).findArtifact(myArtifactsStructureContext);
-          if (usedArtifact != null) {
-            final ArtifactProjectStructureElement artifactElement = myArtifactsStructureContext.getOrCreateArtifactElement(usedArtifact);
-            usages.add(createUsage(packagingElement, path, artifactElement));
-          }
+        ProjectStructureElement element = getProjectStructureElementFor(packagingElement, ArtifactProjectStructureElement.this.myContext,
+                                                                        ArtifactProjectStructureElement.this.myArtifactsStructureContext);
+        if (element != null) {
+          usages.add(createUsage(packagingElement, path, element));
         }
         return true;
       }
@@ -90,6 +78,37 @@ public class ArtifactProjectStructureElement extends ProjectStructureElement {
     return usages;
   }
 
+  @Nullable
+  public static ProjectStructureElement getProjectStructureElementFor(PackagingElement<?> packagingElement,
+                                                                       final StructureConfigurableContext context,
+                                                                       final ArtifactsStructureConfigurableContext artifactsStructureContext) {
+    if (packagingElement instanceof ModuleOutputPackagingElement) {
+      final Module module = ((ModuleOutputPackagingElement)packagingElement).findModule(artifactsStructureContext);
+      if (module != null) {
+        return new ModuleProjectStructureElement(context, module);
+      }
+    }
+    else if (packagingElement instanceof LibraryPackagingElement) {
+      final Library library = ((LibraryPackagingElement)packagingElement).findLibrary(artifactsStructureContext);
+      if (library != null) {
+        return new LibraryProjectStructureElement(context, library);
+      }
+    }
+    else if (packagingElement instanceof ArtifactPackagingElement) {
+      final Artifact usedArtifact = ((ArtifactPackagingElement)packagingElement).findArtifact(artifactsStructureContext);
+      if (usedArtifact != null) {
+        return artifactsStructureContext.getOrCreateArtifactElement(usedArtifact);
+      }
+    }
+    else if (packagingElement instanceof FacetBasedPackagingElement) {
+      Facet facet = ((FacetBasedPackagingElement)packagingElement).findFacet(artifactsStructureContext);
+      if (facet != null) {
+        return new FacetProjectStructureElement(context, facet);
+      }
+    }
+    return null;
+  }
+
   private UsageInArtifact createUsage(PackagingElement<?> packagingElement, PackagingElementPath path,
                                       final ProjectStructureElement element) {
     return new UsageInArtifact(myOriginalArtifact, myArtifactsStructureContext, element, this, path.getPathString(), packagingElement);
index e635eeeb7a7165b0cd81021c0356eea15e43486d..8ef65705503d78197223a70089dc75e683174819 100644 (file)
  */
 package com.intellij.openapi.roots.ui.configuration.artifacts.actions;
 
-import com.intellij.openapi.module.Module;
 import com.intellij.openapi.project.Project;
-import com.intellij.openapi.roots.libraries.Library;
-import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable;
 import com.intellij.openapi.roots.ui.configuration.artifacts.ArtifactsStructureConfigurableContext;
-import com.intellij.openapi.roots.ui.configuration.artifacts.nodes.ArtifactsTreeNode;
 import com.intellij.openapi.roots.ui.configuration.projectRoot.FindUsagesInProjectStructureActionBase;
-import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
-import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.LibraryProjectStructureElement;
-import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ModuleProjectStructureElement;
-import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
-import com.intellij.packaging.artifacts.Artifact;
 import com.intellij.ui.awt.RelativePoint;
 import com.intellij.ui.treeStructure.Tree;
-import org.jetbrains.annotations.Nullable;
 
 import java.awt.*;
 
@@ -38,7 +28,7 @@ import java.awt.*;
  */
 public abstract class ArtifactEditorFindUsagesActionBase extends FindUsagesInProjectStructureActionBase {
   private final Tree myTree;
-  private final ArtifactsStructureConfigurableContext myArtifactContext;
+  protected final ArtifactsStructureConfigurableContext myArtifactContext;
 
   public ArtifactEditorFindUsagesActionBase(Tree tree, Project project, ArtifactsStructureConfigurableContext artifactContext) {
     super(tree, project);
@@ -47,33 +37,9 @@ public abstract class ArtifactEditorFindUsagesActionBase extends FindUsagesInPro
   }
 
   protected boolean isEnabled() {
-    ArtifactsTreeNode node = getSelectedNode();
-    return node != null && node.getElementPresentation().getSourceObject() != null;
+    return getSelectedElement() != null;
   }
 
-  protected ProjectStructureElement getSelectedElement() {
-    ArtifactsTreeNode node = getSelectedNode();
-    if (node == null) {
-      return null;
-    }
-
-    final Object sourceObject = node.getElementPresentation().getSourceObject();
-    final StructureConfigurableContext context = ProjectStructureConfigurable.getInstance(getContext().getProject()).getContext();
-    if (sourceObject instanceof Module) {
-      return new ModuleProjectStructureElement(context, (Module)sourceObject);
-    }
-    else if (sourceObject instanceof Library) {
-      return new LibraryProjectStructureElement(context, (Library)sourceObject);
-    }
-    else if (sourceObject instanceof Artifact) {
-      return myArtifactContext.getOrCreateArtifactElement((Artifact)sourceObject);
-    }
-    return null;
-  }
-
-  @Nullable
-  protected abstract ArtifactsTreeNode getSelectedNode();
-
   protected RelativePoint getPointToShowResults() {
     final int selectedRow = myTree.getSelectionRows()[0];
     final Rectangle rowBounds = myTree.getRowBounds(selectedRow);
index 74d4fb7eb392c8e557d96cda235830ad1775bd7e..e61b036303690baa653d278d8aa70e73c160eec2 100644 (file)
 package com.intellij.openapi.roots.ui.configuration.artifacts.actions;
 
 import com.intellij.openapi.project.Project;
+import com.intellij.openapi.roots.ui.configuration.artifacts.ArtifactProjectStructureElement;
 import com.intellij.openapi.roots.ui.configuration.artifacts.ArtifactsStructureConfigurableContext;
 import com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeComponent;
-import com.intellij.openapi.roots.ui.configuration.artifacts.nodes.ArtifactsTreeNode;
-import org.jetbrains.annotations.Nullable;
+import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
+import com.intellij.packaging.elements.PackagingElement;
 
 /**
 * @author nik
@@ -32,10 +33,10 @@ public class LayoutTreeFindUsagesAction extends ArtifactEditorFindUsagesActionBa
     myLayoutTreeComponent = layoutTreeComponent;
   }
 
-  @Override
-  @Nullable
-  protected ArtifactsTreeNode getSelectedNode() {
-    return myLayoutTreeComponent.getSelection().getNodeIfSingle();
-  }
+  protected ProjectStructureElement getSelectedElement() {
+    PackagingElement<?> packagingElement = myLayoutTreeComponent.getSelection().getElementIfSingle();
+    if (packagingElement == null) return null;
 
+    return ArtifactProjectStructureElement.getProjectStructureElementFor(packagingElement, getContext(), myArtifactContext);
+  }
 }
index a55d66998b9033b7b1c21359d2d4935567efdd47..ed2f78236a81d1791f638a90e9480cf079e8e989 100644 (file)
@@ -57,11 +57,6 @@ public class DelegatedSourceItemPresentation extends SourceItemPresentation {
     myPresentation.navigateToSource();
   }
 
-  @Nullable
-  public Object getSourceObject() {
-    return myPresentation.getSourceObject();
-  }
-
   public int getWeight() {
     return myPresentation.getWeight();
   }
index 52671c68b9508defa82e42759164a8ce9e3362d6..9f84cd6522bceda156a3b6c5acccc27100243b35 100644 (file)
@@ -91,11 +91,6 @@ public class LibrarySourceItem extends PackagingSourceItem {
     }
 
     @Override
-    public Object getSourceObject() {
-      return myLibrary;
-    }
-
-    @Override
     public String getPresentableName() {
       final String name = myLibrary.getName();
       if (name != null) {
index 160f4c4e2599c09aaf8a3ca13852ea1f226b8da6..9a45d0ecf4ce64f6929a239fd8c8bb95fd861b70 100644 (file)
@@ -38,6 +38,10 @@ public class ModuleOutputSourceItem extends PackagingSourceItem {
     myModule = module;
   }
 
+  public Module getModule() {
+    return myModule;
+  }
+
   public boolean equals(Object obj) {
     return obj instanceof ModuleOutputSourceItem && myModule.equals(((ModuleOutputSourceItem)obj).myModule);
   }
index 302fdf74ce9a6aca6b73f2d1b7479efd6e0366cf..45a5ae41ebcb464be10ee9b745da1a72d3173441 100644 (file)
@@ -141,11 +141,6 @@ public class ModuleSourceItemGroup extends PackagingSourceItem {
     }
 
     @Override
-    public Object getSourceObject() {
-      return myModule;
-    }
-
-    @Override
     public int getWeight() {
       return SourceItemWeights.MODULE_WEIGHT;
     }
index 4e9d6b88a507fcce61dc8936be85d1b73624a033..35dcd13d1c2dc85f2e4174f0056424b30bc6d22d 100644 (file)
@@ -47,7 +47,7 @@ public class SourceItemNode extends SourceItemNodeBase {
     }
   }
 
-  protected PackagingSourceItem getSourceItem() {
+  public PackagingSourceItem getSourceItem() {
     return mySourceItem;
   }
 }
index b6a6bc66e296f9e7fbe603bf0e3dcd402538e806..332260de1ca3204e6195635a6643478941b4de9b 100644 (file)
@@ -19,8 +19,12 @@ import com.intellij.openapi.project.Project;
 import com.intellij.openapi.roots.ui.configuration.artifacts.ArtifactsStructureConfigurableContext;
 import com.intellij.openapi.roots.ui.configuration.artifacts.actions.ArtifactEditorFindUsagesActionBase;
 import com.intellij.openapi.roots.ui.configuration.artifacts.nodes.ArtifactsTreeNode;
-import com.intellij.openapi.roots.ui.configuration.artifacts.sourceItems.SourceItemNode;
-import com.intellij.openapi.roots.ui.configuration.artifacts.sourceItems.SourceItemsTree;
+import com.intellij.openapi.roots.ui.configuration.artifacts.sourceItems.*;
+import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
+import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.LibraryProjectStructureElement;
+import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ModuleProjectStructureElement;
+import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
+import com.intellij.packaging.ui.PackagingSourceItem;
 
 import java.util.List;
 
@@ -35,9 +39,27 @@ public class SourceItemFindUsagesAction extends ArtifactEditorFindUsagesActionBa
     myTree = tree;
   }
 
-  @Override
-  protected ArtifactsTreeNode getSelectedNode() {
+  protected ProjectStructureElement getSelectedElement() {
     final List<SourceItemNode> nodes = myTree.getSelectedSourceItemNodes();
-    return nodes.size() == 1 ? nodes.get(0) : null;
+    if (nodes.size() != 1) return null;
+    ArtifactsTreeNode node = nodes.get(0);
+    if (!(node instanceof SourceItemNode)) {
+      return null;
+    }
+
+    PackagingSourceItem sourceItem = ((SourceItemNode)node).getSourceItem();
+    if (sourceItem == null) return null;
+
+    final StructureConfigurableContext context = getContext();
+    if (sourceItem instanceof ModuleOutputSourceItem) {
+      return new ModuleProjectStructureElement(context, ((ModuleOutputSourceItem)sourceItem).getModule());
+    }
+    else if (sourceItem instanceof LibrarySourceItem) {
+      return new LibraryProjectStructureElement(context, ((LibrarySourceItem)sourceItem).getLibrary());
+    }
+    else if (sourceItem instanceof ArtifactSourceItem) {
+      return myArtifactContext.getOrCreateArtifactElement(((ArtifactSourceItem)sourceItem).getArtifact());
+    }
+    return null;
   }
 }
index 4a3ed0c67da01ee7f1fed8a6994166418f4ebc69..da6fd0bb6cc0885f5736ea7d98a0d535a8ac2403 100644 (file)
@@ -23,7 +23,8 @@ import com.intellij.facet.impl.ui.FacetEditorImpl;
 import com.intellij.openapi.options.ConfigurationException;
 import com.intellij.openapi.project.ProjectBundle;
 import com.intellij.openapi.roots.ui.configuration.ModulesConfigurator;
-import com.intellij.openapi.ui.NamedConfigurable;
+import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.FacetProjectStructureElement;
+import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
 import org.jetbrains.annotations.Nls;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.Nullable;
@@ -33,16 +34,18 @@ import javax.swing.*;
 /**
  * @author nik
  */
-public class FacetConfigurable extends NamedConfigurable<Facet> {
+public class FacetConfigurable extends ProjectStructureElementConfigurable<Facet> {
   private final Facet myFacet;
   private final ModulesConfigurator myModulesConfigurator;
   private String myFacetName;
+  private FacetProjectStructureElement myProjectStructureElement;
 
-  public FacetConfigurable(final Facet facet, final ModulesConfigurator modulesConfigurator, final Runnable updateTree) {
+  public FacetConfigurable(final Facet facet, final StructureConfigurableContext context, final Runnable updateTree) {
     super(!facet.getType().isOnlyOneFacetAllowed() && !(facet instanceof InvalidFacet), updateTree);
     myFacet = facet;
-    myModulesConfigurator = modulesConfigurator;
+    myModulesConfigurator = context.getModulesConfigurator();
     myFacetName = myFacet.getName();
+    myProjectStructureElement = new FacetProjectStructureElement(context, facet);
   }
 
 
@@ -54,6 +57,11 @@ public class FacetConfigurable extends NamedConfigurable<Facet> {
     }
   }
 
+  @Override
+  public ProjectStructureElement getProjectStructureElement() {
+    return myProjectStructureElement;
+  }
+
   private ProjectFacetsConfigurator getFacetsConfigurator() {
     return myModulesConfigurator.getFacetsConfigurator();
   }
index 59b641ded9e8e4f6f68452f51a5366762b2fbae6..92670f6b0fe8f9b78e4cc8cd4c2d43b599a11c88 100644 (file)
@@ -87,7 +87,7 @@ public class FacetEditorFacadeImpl implements FacetEditorFacade {
   public FacetConfigurable getOrCreateConfigurable(final Facet facet) {
     FacetConfigurable configurable = myConfigurables.get(facet);
     if (configurable == null) {
-      configurable = new FacetConfigurable(facet, myStructureConfigurable.getContext().getModulesConfigurator(), myTreeUpdater);
+      configurable = new FacetConfigurable(facet, myStructureConfigurable.getContext(), myTreeUpdater);
       myConfigurables.put(facet, configurable);
     }
     return configurable;
index b94f19f0b99d24399331f2597770965ebfd38dec..b56c5a1fc4be41ad1a734cecb786028b3060b83e 100644 (file)
@@ -36,6 +36,8 @@ import com.intellij.openapi.project.DumbAware;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.project.ProjectBundle;
 import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable;
+import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.FacetProjectStructureElement;
+import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
 import com.intellij.openapi.ui.DetailsComponent;
 import com.intellij.openapi.ui.NamedConfigurable;
 import com.intellij.openapi.util.IconLoader;
@@ -99,6 +101,19 @@ public class FacetStructureConfigurable extends BaseStructureConfigurable {
     }
   }
 
+  @NotNull
+  @Override
+  protected Collection<? extends ProjectStructureElement> getProjectStructureElements() {
+    List<ProjectStructureElement> elements = new ArrayList<ProjectStructureElement>();
+    for (Module module : myModuleManager.getModules()) {
+      Facet[] facets = FacetManager.getInstance(module).getAllFacets();
+      for (Facet facet : facets) {
+        elements.add(new FacetProjectStructureElement(myContext, facet));
+      }
+    }
+    return elements;
+  }
+
   public MyNode findFacetTypeNode(FacetType facetType) {
     return findNodeByObject(myRoot, facetType);
   }
@@ -106,6 +121,7 @@ public class FacetStructureConfigurable extends BaseStructureConfigurable {
   public void addFacetNode(@NotNull MyNode facetTypeNode, @NotNull Facet facet, @NotNull FacetEditorFacadeImpl editorFacade) {
     FacetConfigurable facetConfigurable = editorFacade.getOrCreateConfigurable(facet);
     addNode(new FacetConfigurableNode(facetConfigurable), facetTypeNode);
+    myContext.getDaemonAnalyzer().queueUpdate(new FacetProjectStructureElement(myContext, facet));
   }
 
   @Nullable
@@ -177,6 +193,9 @@ public class FacetStructureConfigurable extends BaseStructureConfigurable {
   protected List<Facet> removeFacet(final Facet facet) {
     List<Facet> removed = super.removeFacet(facet);
     ModuleStructureConfigurable.getInstance(myProject).removeFacetNodes(removed);
+    for (Facet removedFacet : removed) {
+      myContext.getDaemonAnalyzer().removeElement(new FacetProjectStructureElement(myContext, removedFacet));
+    }
     return removed;
   }
 
diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/FacetProjectStructureElement.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/FacetProjectStructureElement.java
new file mode 100644 (file)
index 0000000..c2a1ce1
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2000-2011 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.openapi.roots.ui.configuration.projectRoot.daemon;
+
+import com.intellij.facet.Facet;
+import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author nik
+ */
+public class FacetProjectStructureElement extends ProjectStructureElement {
+  private final Facet myFacet;
+
+  public FacetProjectStructureElement(@NotNull StructureConfigurableContext context, @NotNull Facet facet) {
+    super(context);
+    myFacet = facet;
+  }
+
+  @Override
+  public void check(ProjectStructureProblemsHolder problemsHolder) {
+  }
+
+  @Override
+  public List<ProjectStructureElementUsage> getUsagesInElement() {
+    return Collections.emptyList();
+  }
+
+  @Override
+  public boolean highlightIfUnused() {
+    return false;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    return obj instanceof FacetProjectStructureElement && myFacet.equals(((FacetProjectStructureElement)obj).myFacet);
+  }
+
+  @Override
+  public int hashCode() {
+    return myFacet.hashCode();
+  }
+
+  @Override
+  public String toString() {
+    return "facet:" + myFacet.getName() + " in " + myFacet.getModule().getName();
+  }
+}