From f59db912f9884f54ece38312ccf6caaf7f1c9914 Mon Sep 17 00:00:00 2001 From: nik Date: Wed, 27 Oct 2010 17:19:22 +0400 Subject: [PATCH] show invalid facets in Project Structure dialog --- .../projectRoot/FacetConfigurable.java | 3 +- .../com/intellij/facet/FacetManagerImpl.java | 62 +++++++--------- .../impl/FacetLoadingErrorDescription.java | 35 ++------- .../com/intellij/facet/impl/FacetUtil.java | 1 + .../facet/impl/invalid/InvalidFacet.java | 36 +++++++++ .../invalid/InvalidFacetConfiguration.java | 74 +++++++++++++++++++ .../impl/invalid/InvalidFacetEditor.form | 26 +++++++ .../impl/invalid/InvalidFacetEditor.java | 61 +++++++++++++++ .../impl/invalid/InvalidFacetManager.java | 32 ++++++++ .../impl/invalid/InvalidFacetManagerImpl.java | 39 ++++++++++ .../facet/impl/invalid/InvalidFacetType.java | 66 +++++++++++++++++ .../src/META-INF/LangExtensions.xml | 3 +- 12 files changed, 374 insertions(+), 64 deletions(-) create mode 100644 platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacet.java create mode 100644 platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacetConfiguration.java create mode 100644 platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacetEditor.form create mode 100644 platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacetEditor.java create mode 100644 platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacetManager.java create mode 100644 platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacetManagerImpl.java create mode 100644 platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacetType.java diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetConfigurable.java index f4a95c6e8f10..4a3ed0c67da0 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetConfigurable.java @@ -18,6 +18,7 @@ package com.intellij.openapi.roots.ui.configuration.projectRoot; import com.intellij.facet.Facet; import com.intellij.facet.impl.ProjectFacetsConfigurator; +import com.intellij.facet.impl.invalid.InvalidFacet; import com.intellij.facet.impl.ui.FacetEditorImpl; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.project.ProjectBundle; @@ -38,7 +39,7 @@ public class FacetConfigurable extends NamedConfigurable { private String myFacetName; public FacetConfigurable(final Facet facet, final ModulesConfigurator modulesConfigurator, final Runnable updateTree) { - super(!facet.getType().isOnlyOneFacetAllowed(), updateTree); + super(!facet.getType().isOnlyOneFacetAllowed() && !(facet instanceof InvalidFacet), updateTree); myFacet = facet; myModulesConfigurator = modulesConfigurator; myFacetName = myFacet.getName(); diff --git a/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java b/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java index 3d838663d356..247bc597b22d 100644 --- a/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java @@ -17,6 +17,10 @@ package com.intellij.facet; import com.intellij.facet.impl.*; +import com.intellij.facet.impl.invalid.InvalidFacet; +import com.intellij.facet.impl.invalid.InvalidFacetConfiguration; +import com.intellij.facet.impl.invalid.InvalidFacetManager; +import com.intellij.facet.impl.invalid.InvalidFacetType; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.State; @@ -28,6 +32,7 @@ import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.module.ProjectLoadingErrorsNotifier; import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.util.*; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.messages.MessageBus; import org.jdom.Element; import org.jetbrains.annotations.NonNls; @@ -59,7 +64,6 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P private final Module myModule; private final FacetTypeRegistry myFacetTypeRegistry; private final FacetManagerModel myModel = new FacetManagerModel(); - private final MultiValuesMap myInvalidFacets = new MultiValuesMap(true); private boolean myInsideCommit = false; private final MessageBus myMessageBus; private boolean myModuleAdded; @@ -152,29 +156,24 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P } } - public void removeInvalidFacet(@Nullable Facet underlyingFacet, @NotNull FacetState facetState) { - myInvalidFacets.remove(underlyingFacet, facetState); - } - - private void addFacets(final List facetStates, final Facet underlyingFacet, ModifiableFacetModel model) { for (FacetState child : facetStates) { final String typeId = child.getFacetType(); if (typeId == null) { - registerLoadingError(underlyingFacet, child, ProjectBundle.message("error.message.facet.type.isn.t.specified")); + addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.facet.type.isn.t.specified")); continue; } final FacetType type = myFacetTypeRegistry.findFacetType(typeId); if (type == null) { - registerLoadingError(underlyingFacet, child, ProjectBundle.message("error.message.unknown.facet.type.0", typeId)); + addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.unknown.facet.type.0", typeId)); continue; } ModuleType moduleType = myModule.getModuleType(); if (!type.isSuitableModuleType(moduleType)) { - registerLoadingError(underlyingFacet, child, ProjectBundle.message("error.message.0.facets.are.not.allowed.in.1", - type.getPresentableName(), moduleType.getName())); + addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.0.facets.are.not.allowed.in.1", + type.getPresentableName(), moduleType.getName())); continue; } @@ -183,21 +182,22 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P if (underlyingTypeId != null) { expectedUnderlyingType = myFacetTypeRegistry.findFacetType(underlyingTypeId); if (expectedUnderlyingType == null) { - registerLoadingError(underlyingFacet, child, ProjectBundle.message("error.message.cannot.find.underlying.facet.type.for.0", typeId)); + addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.cannot.find.underlying.facet.type.for.0", typeId)); continue; } } FacetType actualUnderlyingType = underlyingFacet != null ? underlyingFacet.getType() : null; if (expectedUnderlyingType != null) { if (!expectedUnderlyingType.equals(actualUnderlyingType)) { - registerLoadingError(underlyingFacet, child, ProjectBundle.message("error.message.0.facet.must.be.placed.under.1.facet", - type.getPresentableName(), expectedUnderlyingType.getPresentableName())); + addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.0.facet.must.be.placed.under.1.facet", + type.getPresentableName(), + expectedUnderlyingType.getPresentableName())); continue; } } else if (actualUnderlyingType != null) { - registerLoadingError(underlyingFacet, child, ProjectBundle.message("error.message.0.cannot.be.placed.under.1", - type.getPresentableName(), actualUnderlyingType.getPresentableName())); + addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.0.cannot.be.placed.under.1", + type.getPresentableName(), actualUnderlyingType.getPresentableName())); continue; } @@ -206,14 +206,18 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P } catch (InvalidDataException e) { LOG.info(e); - registerLoadingError(underlyingFacet, child, ProjectBundle.message("error.message.cannot.load.facet.condiguration.0", e.getMessage())); + addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.cannot.load.facet.condiguration.0", e.getMessage())); } } } - private void registerLoadingError(final Facet underlyingFacet, final FacetState child, final String errorMessage) { - myInvalidFacets.put(underlyingFacet, child); - FacetLoadingErrorDescription description = new FacetLoadingErrorDescription(myModule, errorMessage, underlyingFacet, child); + private void addInvalidFacet(final FacetState state, ModifiableFacetModel model, final Facet underlyingFacet, final String errorMessage) { + final String typeId = StringUtil.notNullize(state.getFacetType()); + final InvalidFacetType type = InvalidFacetManager.getInstance(myModule.getProject()).getOrCreateType(typeId); + final InvalidFacetConfiguration configuration = new InvalidFacetConfiguration(state, errorMessage); + final InvalidFacet facet = createFacet(type, StringUtil.notNullize(state.getName()), configuration, underlyingFacet); + model.addFacet(facet); + FacetLoadingErrorDescription description = new FacetLoadingErrorDescription(facet); ProjectLoadingErrorsNotifier.getInstance(myModule.getProject()).registerError(description); } @@ -242,7 +246,6 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P public void loadState(final FacetManagerState state) { ModifiableFacetModel model = new FacetModelImpl(this); - myInvalidFacets.clear(); addFacets(state.getFacets(), null, model); commit(model, false); @@ -267,6 +270,9 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P try { FacetConfiguration configuration = facet.getConfiguration(); config = FacetUtil.saveFacetConfiguration(configuration); + if (configuration instanceof InvalidFacetConfiguration) { + facetState.getSubFacets().addAll(((InvalidFacetConfiguration)configuration).getSubFacetsStates()); + } if (facet instanceof JDOMExternalizable) { //todo[nik] remove ((JDOMExternalizable)facet).writeExternal(config); @@ -278,21 +284,11 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P facetState.setConfiguration(config); parent.add(facetState); - List subFacets = facetState.getSubFacets(); - addInvalidFacets(facet, subFacets); - states.put(facet, subFacets); + states.put(facet, facetState.getSubFacets()); } - addInvalidFacets(null, managerState.getFacets()); - return managerState; } - private void addInvalidFacets(@Nullable Facet facet, final List subFacets) { - Collection invalidFacets = myInvalidFacets.get(facet); - if (invalidFacets != null) { - subFacets.addAll(invalidFacets); - } - } public void commit(final ModifiableFacetModel model) { ApplicationManager.getApplication().assertWriteAccessAllowed(); @@ -345,10 +341,6 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P } } - for (Facet facet : toRemove) { - myInvalidFacets.removeAll(facet); - } - for (FacetRenameInfo info : toRename) { info.myFacet.setName(info.myNewName); } diff --git a/platform/lang-impl/src/com/intellij/facet/impl/FacetLoadingErrorDescription.java b/platform/lang-impl/src/com/intellij/facet/impl/FacetLoadingErrorDescription.java index 4742da31ff57..e525849c232f 100644 --- a/platform/lang-impl/src/com/intellij/facet/impl/FacetLoadingErrorDescription.java +++ b/platform/lang-impl/src/com/intellij/facet/impl/FacetLoadingErrorDescription.java @@ -16,9 +16,7 @@ package com.intellij.facet.impl; -import com.intellij.facet.Facet; -import com.intellij.facet.FacetManagerImpl; -import com.intellij.openapi.module.Module; +import com.intellij.facet.impl.invalid.InvalidFacet; import com.intellij.openapi.module.ConfigurationErrorDescription; import com.intellij.openapi.project.ProjectBundle; @@ -26,42 +24,25 @@ import com.intellij.openapi.project.ProjectBundle; * @author nik */ public class FacetLoadingErrorDescription extends ConfigurationErrorDescription { - private final Facet myUnderlyingFacet; - private final FacetState myState; - private final Module myModule; + private final InvalidFacet myFacet; - public FacetLoadingErrorDescription(final Module module, final String errorMessage, final Facet underlyingFacet, final FacetState state) { - super(state.getName() + " (" + module.getName() + ")", ProjectBundle.message("element.kind.name.facet"), errorMessage); - myModule = module; - myUnderlyingFacet = underlyingFacet; - myState = state; - } - - public Facet getUnderlyingFacet() { - return myUnderlyingFacet; - } - - public FacetState getState() { - return myState; - } - - public Module getModule() { - return myModule; + public FacetLoadingErrorDescription(final InvalidFacet facet) { + super(facet.getName() + " (" + facet.getModule().getName() + ")", ProjectBundle.message("element.kind.name.facet"), facet.getErrorMessage()); + myFacet = facet; } @Override public String getRemoveConfirmationMessage() { - return ProjectBundle.message("confirmation.message.would.you.like.to.remove.facet", myState.getName(), myModule.getName()); + return ProjectBundle.message("confirmation.message.would.you.like.to.remove.facet", myFacet.getName(), myFacet.getModule().getName()); } @Override public void removeInvalidElement() { - FacetManagerImpl manager = (FacetManagerImpl)FacetManagerImpl.getInstance(myModule); - manager.removeInvalidFacet(myUnderlyingFacet, myState); + FacetUtil.deleteFacet(myFacet); } @Override public boolean isValid() { - return !myModule.isDisposed(); + return !myFacet.isDisposed(); } } diff --git a/platform/lang-impl/src/com/intellij/facet/impl/FacetUtil.java b/platform/lang-impl/src/com/intellij/facet/impl/FacetUtil.java index 6d0a65031946..98ee7e32af01 100644 --- a/platform/lang-impl/src/com/intellij/facet/impl/FacetUtil.java +++ b/platform/lang-impl/src/com/intellij/facet/impl/FacetUtil.java @@ -74,6 +74,7 @@ public class FacetUtil { public static Element saveFacetConfiguration(final FacetConfiguration configuration) throws WriteExternalException { if (configuration instanceof PersistentStateComponent) { Object state = ((PersistentStateComponent)configuration).getState(); + if (state instanceof Element) return ((Element)state); return XmlSerializer.serialize(state, new SkipDefaultValuesSerializationFilters()); } else { diff --git a/platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacet.java b/platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacet.java new file mode 100644 index 000000000000..18ca8ab8d27e --- /dev/null +++ b/platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacet.java @@ -0,0 +1,36 @@ +/* + * Copyright 2000-2010 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.facet.impl.invalid; + +import com.intellij.facet.Facet; +import com.intellij.openapi.module.Module; + +/** + * @author nik + */ +public class InvalidFacet extends Facet { + public InvalidFacet(InvalidFacetType invalidFacetType, + Module module, + String name, + InvalidFacetConfiguration configuration, + Facet underlyingFacet) { + super(invalidFacetType, module, name, configuration, underlyingFacet); + } + + public String getErrorMessage() { + return getConfiguration().getErrorMessage(); + } +} diff --git a/platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacetConfiguration.java b/platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacetConfiguration.java new file mode 100644 index 000000000000..f032d1d96b14 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacetConfiguration.java @@ -0,0 +1,74 @@ +/* + * Copyright 2000-2010 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.facet.impl.invalid; + +import com.intellij.facet.FacetConfiguration; +import com.intellij.facet.impl.FacetState; +import com.intellij.facet.ui.FacetEditorContext; +import com.intellij.facet.ui.FacetEditorTab; +import com.intellij.facet.ui.FacetValidatorsManager; +import com.intellij.openapi.components.PersistentStateComponent; +import com.intellij.openapi.util.InvalidDataException; +import com.intellij.openapi.util.WriteExternalException; +import org.jdom.Element; + +import java.util.List; + +/** + * @author nik + */ +public class InvalidFacetConfiguration implements FacetConfiguration, PersistentStateComponent { + private FacetState myFacetState; + private final String myErrorMessage; + + public InvalidFacetConfiguration(FacetState facetState, String errorMessage) { + myFacetState = facetState; + myErrorMessage = errorMessage; + } + + public List getSubFacetsStates() { + return myFacetState.getSubFacets(); + } + + @Override + public FacetEditorTab[] createEditorTabs(FacetEditorContext editorContext, FacetValidatorsManager validatorsManager) { + return new FacetEditorTab[] { + new InvalidFacetEditor(myErrorMessage) + }; + } + + @Override + public void readExternal(Element element) throws InvalidDataException { + } + + @Override + public void writeExternal(Element element) throws WriteExternalException { + } + + public String getErrorMessage() { + return myErrorMessage; + } + + @Override + public Element getState() { + return myFacetState.getConfiguration(); + } + + @Override + public void loadState(Element state) { + myFacetState.setConfiguration(state); + } +} diff --git a/platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacetEditor.form b/platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacetEditor.form new file mode 100644 index 000000000000..806a7d3c083f --- /dev/null +++ b/platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacetEditor.form @@ -0,0 +1,26 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacetEditor.java b/platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacetEditor.java new file mode 100644 index 000000000000..4a8f1ecf1ef9 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacetEditor.java @@ -0,0 +1,61 @@ +/* + * Copyright 2000-2010 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.facet.impl.invalid; + +import com.intellij.facet.ui.FacetEditorTab; +import com.intellij.openapi.util.IconLoader; +import org.jetbrains.annotations.Nls; + +import javax.swing.*; + +/** + * @author nik + */ +public class InvalidFacetEditor extends FacetEditorTab { + private final String myErrorMessage; + private JPanel myMainPanel; + private JLabel myErrorLabel; + + public InvalidFacetEditor(String errorMessage) { + myErrorMessage = errorMessage; + } + + @Nls + @Override + public String getDisplayName() { + return ""; + } + + @Override + public JComponent createComponent() { + myErrorLabel.setText(myErrorMessage); + myErrorLabel.setIcon(IconLoader.getIcon("/runConfigurations/configurationWarning.png")); + return myMainPanel; + } + + @Override + public boolean isModified() { + return false; + } + + @Override + public void reset() { + } + + @Override + public void disposeUIResources() { + } +} diff --git a/platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacetManager.java b/platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacetManager.java new file mode 100644 index 000000000000..2590694f51fb --- /dev/null +++ b/platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacetManager.java @@ -0,0 +1,32 @@ +/* + * Copyright 2000-2010 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.facet.impl.invalid; + +import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; + +/** + * @author nik + */ +public abstract class InvalidFacetManager { + public static InvalidFacetManager getInstance(@NotNull Project project) { + return ServiceManager.getService(project, InvalidFacetManager.class); + } + + @NotNull + public abstract InvalidFacetType getOrCreateType(@NotNull String typeId); +} diff --git a/platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacetManagerImpl.java b/platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacetManagerImpl.java new file mode 100644 index 000000000000..af2b4083bc37 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacetManagerImpl.java @@ -0,0 +1,39 @@ +/* + * Copyright 2000-2010 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.facet.impl.invalid; + +import com.intellij.util.containers.FactoryMap; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +/** + * @author nik + */ +public class InvalidFacetManagerImpl extends InvalidFacetManager { + private Map myTypes = new FactoryMap() { + @Override + protected InvalidFacetType create(String key) { + return new InvalidFacetType(key); + } + }; + + @NotNull + @Override + public InvalidFacetType getOrCreateType(@NotNull String typeId) { + return myTypes.get(typeId); + } +} diff --git a/platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacetType.java b/platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacetType.java new file mode 100644 index 000000000000..9803de9a4865 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/facet/impl/invalid/InvalidFacetType.java @@ -0,0 +1,66 @@ +/* + * Copyright 2000-2010 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.facet.impl.invalid; + +import com.intellij.facet.Facet; +import com.intellij.facet.FacetType; +import com.intellij.facet.FacetTypeId; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; +import com.intellij.openapi.util.IconLoader; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; + +/** + * @author nik + */ +public class InvalidFacetType extends FacetType { + private static final Icon ICON = IconLoader.getIcon("/fileTypes/unknown.png"); + + public InvalidFacetType(String typeId) { + super(new FacetTypeId("invalid:" + typeId), typeId, typeId, null); + } + + @Override + public InvalidFacetConfiguration createDefaultConfiguration() { + throw new UnsupportedOperationException(); + } + + @Override + public InvalidFacet createFacet(@NotNull Module module, + String name, + @NotNull InvalidFacetConfiguration configuration, + @Nullable Facet underlyingFacet) { + return new InvalidFacet(this, module, name, configuration, underlyingFacet); + } + + @Override + public boolean isSuitableModuleType(ModuleType moduleType) { + return true; + } + + @Override + public boolean isOnlyOneFacetAllowed() { + return false; + } + + @Override + public Icon getIcon() { + return ICON; + } +} diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index 2713d389dd7a..77d47188cc77 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -184,7 +184,8 @@ - +