Maven: action names
[idea/community.git] / plugins / maven / src / main / java / org / jetbrains / idea / maven / dom / generate / MavenCodeInsightGenerateAction.java
1 package org.jetbrains.idea.maven.dom.generate;
2
3 import com.intellij.openapi.editor.Editor;
4 import com.intellij.openapi.project.Project;
5 import com.intellij.psi.PsiFile;
6 import com.intellij.psi.xml.XmlFile;
7 import com.intellij.util.Function;
8 import com.intellij.util.xml.DomElement;
9 import com.intellij.util.xml.ElementPresentationManager;
10 import com.intellij.util.xml.TypeNameManager;
11 import com.intellij.util.xml.ui.actions.generate.GenerateDomElementAction;
12 import com.intellij.util.xml.ui.actions.generate.GenerateDomElementProvider;
13 import org.jetbrains.annotations.NotNull;
14 import org.jetbrains.annotations.Nullable;
15 import org.jetbrains.idea.maven.dom.MavenDomUtil;
16 import org.jetbrains.idea.maven.dom.model.MavenDomProjectModel;
17
18 /**
19  * User: Sergey.Vasiliev
20  */
21 public class MavenCodeInsightGenerateAction extends GenerateDomElementAction {
22
23   public MavenCodeInsightGenerateAction(@NotNull Class<? extends DomElement> childElementClass,
24                                         @Nullable final String mappingId,
25                                         @NotNull Function<MavenDomProjectModel, DomElement> parentFunction) {
26     this(TypeNameManager.getTypeName(childElementClass), childElementClass, mappingId, parentFunction);
27   }
28
29   public MavenCodeInsightGenerateAction(@NotNull final String description,
30                                         @NotNull final Class<? extends DomElement> childElementClass,
31                                         @Nullable final String mappingId,
32                                         @NotNull Function<MavenDomProjectModel, DomElement> parentFunction) {
33     super(new MavenGenerateDomElementProvider(description, childElementClass, mappingId, parentFunction));
34
35     getTemplatePresentation().setIcon(ElementPresentationManager.getIconForClass(childElementClass));
36   }                       
37
38   public MavenCodeInsightGenerateAction(final GenerateDomElementProvider generateProvider) {
39     super(generateProvider);
40   }
41
42   protected boolean isValidForFile(Project project, Editor editor, PsiFile file) {
43     return file instanceof XmlFile && MavenDomUtil.getMavenDomModel(file, MavenDomProjectModel.class) != null;
44   }
45
46 }