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();
}
}
});
}
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);
}
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;
}
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);
}
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();
}
Aggregations