Search in sources :

Example 11 with Facet

use of com.intellij.facet.Facet in project intellij-plugins by JetBrains.

the class OsmorcPostStartupActivity method runActivity.

@Override
public void runActivity(@NotNull Project project) {
    if (project.isDefault()) {
        return;
    }
    MessageBusConnection connection = project.getMessageBus().connect();
    connection.subscribe(FacetManager.FACETS_TOPIC, new FacetManagerAdapter() {

        @Override
        public void facetAdded(@NotNull Facet facet) {
            handleFacetChange(facet, project);
        }

        @Override
        public void facetConfigurationChanged(@NotNull Facet facet) {
            handleFacetChange(facet, project);
        }
    });
    connection.subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {

        @Override
        public void projectClosing(Project project) {
            for (Module module : ModuleManager.getInstance(project).getModules()) {
                AdditionalJARContentsWatcherManager.getInstance(module).cleanup();
            }
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ProjectManagerListener(com.intellij.openapi.project.ProjectManagerListener) Module(com.intellij.openapi.module.Module) FacetManagerAdapter(com.intellij.facet.FacetManagerAdapter) Facet(com.intellij.facet.Facet)

Example 12 with Facet

use of com.intellij.facet.Facet in project intellij-community by JetBrains.

the class AddFacetOfTypeAction method addSubFacet.

private void addSubFacet(FacetType type, FacetTypeId<?> underlyingType) {
    final ProjectFacetsConfigurator facetsConfigurator = myContext.getModulesConfigurator().getFacetsConfigurator();
    List<Facet> suitableParents = new ArrayList<>();
    for (Module module : myContext.getModules()) {
        if (type.isSuitableModuleType(ModuleType.get(module))) {
            suitableParents.addAll(facetsConfigurator.getFacetsByType(module, underlyingType));
        }
    }
    final Iterator<Facet> iterator = suitableParents.iterator();
    while (iterator.hasNext()) {
        Facet parent = iterator.next();
        if (type.isOnlyOneFacetAllowed() && facetsConfigurator.hasFacetOfType(parent.getModule(), parent, type.getId())) {
            iterator.remove();
        }
    }
    final Project project = myContext.getProject();
    if (suitableParents.isEmpty()) {
        final String parentType = FacetTypeRegistry.getInstance().findFacetType(underlyingType).getPresentableName();
        Messages.showErrorDialog(project, "No suitable parent " + parentType + " facets found", "Cannot Create " + type.getPresentableName() + " Facet");
        return;
    }
    ChooseParentFacetDialog dialog = new ChooseParentFacetDialog(project, suitableParents);
    dialog.show();
    final List<Facet> chosen = dialog.getChosenElements();
    if (!dialog.isOK() || chosen.size() != 1)
        return;
    final Facet parent = chosen.get(0);
    final Facet facet = ModuleStructureConfigurable.getInstance(project).getFacetEditorFacade().createAndAddFacet(type, parent.getModule(), parent);
    ProjectStructureConfigurable.getInstance(project).select(facet, true);
}
Also used : Project(com.intellij.openapi.project.Project) ArrayList(java.util.ArrayList) ProjectFacetsConfigurator(com.intellij.facet.impl.ProjectFacetsConfigurator) Module(com.intellij.openapi.module.Module) Facet(com.intellij.facet.Facet)

Example 13 with Facet

use of com.intellij.facet.Facet in project intellij-community by JetBrains.

the class FacetTypeEditor method createAllFacetsEditor.

@Nullable
private MultipleFacetSettingsEditor createAllFacetsEditor() {
    ProjectFacetsConfigurator facetsConfigurator = myContext.myModulesConfigurator.getFacetsConfigurator();
    List<Facet> facets = new ArrayList<>();
    for (Module module : myContext.getModules()) {
        facets.addAll(facetsConfigurator.getFacetsByType(module, myFacetType.getId()));
    }
    if (!facets.isEmpty()) {
        final FacetEditor[] editors = new FacetEditor[facets.size()];
        for (int i = 0; i < facets.size(); i++) {
            editors[i] = facetsConfigurator.getOrCreateEditor(facets.get(i));
        }
        return myFacetType.createMultipleConfigurationsEditor(myProject, editors);
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) FacetEditor(com.intellij.facet.ui.FacetEditor) ProjectFacetsConfigurator(com.intellij.facet.impl.ProjectFacetsConfigurator) Module(com.intellij.openapi.module.Module) Facet(com.intellij.facet.Facet) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with Facet

use of com.intellij.facet.Facet in project intellij-community by JetBrains.

the class FacetModelBase method addUnderlyingFacets.

private static void addUnderlyingFacets(final LinkedHashSet<Facet> facets, final Facet facet) {
    final Facet underlyingFacet = facet.getUnderlyingFacet();
    if (underlyingFacet != null && !facets.contains(facet)) {
        addUnderlyingFacets(facets, underlyingFacet);
    }
    facets.add(facet);
}
Also used : Facet(com.intellij.facet.Facet)

Example 15 with Facet

use of com.intellij.facet.Facet in project intellij-community by JetBrains.

the class FacetModelBase method getFacetsByType.

@Override
@NotNull
public <F extends Facet> Collection<F> getFacetsByType(@NotNull Facet underlyingFacet, FacetTypeId<F> typeId) {
    if (myChildFacets == null) {
        MultiValuesMap<Pair<Facet, FacetTypeId>, Facet> children = new MultiValuesMap<>();
        for (Facet facet : getAllFacets()) {
            final Facet underlying = facet.getUnderlyingFacet();
            if (underlying != null) {
                children.put(Pair.create(underlying, facet.getTypeId()), facet);
            }
        }
        Map<Pair<Facet, FacetTypeId>, Collection<Facet>> childFacets = new HashMap<>();
        for (Pair<Facet, FacetTypeId> pair : children.keySet()) {
            final Collection<Facet> facets = children.get(pair);
            childFacets.put(pair, Collections.unmodifiableCollection(facets));
        }
        myChildFacets = childFacets;
    }
    //noinspection unchecked
    final Collection<F> facets = (Collection<F>) myChildFacets.get(new Pair(underlyingFacet, typeId));
    return facets != null ? facets : Collections.<F>emptyList();
}
Also used : MultiValuesMap(com.intellij.openapi.util.MultiValuesMap) FacetTypeId(com.intellij.facet.FacetTypeId) Pair(com.intellij.openapi.util.Pair) Facet(com.intellij.facet.Facet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Facet (com.intellij.facet.Facet)17 Module (com.intellij.openapi.module.Module)8 Project (com.intellij.openapi.project.Project)4 ArrayList (java.util.ArrayList)4 NotNull (org.jetbrains.annotations.NotNull)4 FacetManagerAdapter (com.intellij.facet.FacetManagerAdapter)3 ProjectFacetsConfigurator (com.intellij.facet.impl.ProjectFacetsConfigurator)3 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)3 Nullable (org.jetbrains.annotations.Nullable)3 FacetTypeId (com.intellij.facet.FacetTypeId)2 MultiValuesMap (com.intellij.openapi.util.MultiValuesMap)2 Pair (com.intellij.openapi.util.Pair)2 PythonFacetSettings (com.jetbrains.python.facet.PythonFacetSettings)2 FacetConfiguration (com.intellij.facet.FacetConfiguration)1 ModifiableFacetModel (com.intellij.facet.ModifiableFacetModel)1 FacetPointerListener (com.intellij.facet.pointers.FacetPointerListener)1 FacetEditor (com.intellij.facet.ui.FacetEditor)1 CompilerManager (com.intellij.openapi.compiler.CompilerManager)1 ModuleType (com.intellij.openapi.module.ModuleType)1 ModuleListener (com.intellij.openapi.project.ModuleListener)1