ComponentWithBrowseButton - optional remove listener on hide
[fedora-idea.git] / plugins / maven / src / main / java / org / jetbrains / idea / maven / utils / MavenDomApplicationComponent.java
blob6a0724e5d79d818a29c0f1e3fd5dbea7eb6f14bc
1 /*
2 * Copyright 2000-2010 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.jetbrains.idea.maven.utils;
19 import com.intellij.codeInsight.template.impl.TemplateSettings;
20 import com.intellij.ide.highlighter.XmlFileType;
21 import com.intellij.openapi.application.ApplicationManager;
22 import com.intellij.openapi.application.PathMacros;
23 import com.intellij.openapi.components.ApplicationComponent;
24 import com.intellij.openapi.diagnostic.Logger;
25 import com.intellij.openapi.fileTypes.FileTypeManager;
26 import com.intellij.openapi.util.JDOMUtil;
27 import com.intellij.util.xml.ElementPresentationManager;
28 import com.intellij.util.xml.TypeNameManager;
29 import org.jdom.Document;
30 import org.jetbrains.annotations.NonNls;
31 import org.jetbrains.annotations.NotNull;
32 import org.jetbrains.idea.maven.dom.MavenDomBundle;
33 import org.jetbrains.idea.maven.dom.model.MavenDomDependency;
34 import org.jetbrains.idea.maven.dom.model.MavenDomPlugin;
35 import org.jetbrains.idea.maven.dom.model.MavenDomRepository;
36 import org.jetbrains.idea.maven.embedder.MavenEmbedderFactory;
38 import java.io.File;
40 public class MavenDomApplicationComponent implements ApplicationComponent {
42 private static final Logger LOG = Logger.getInstance(MavenDomApplicationComponent.class.getName());
43 @NonNls private static final String LIVE_TEMPLATES_DIR = "/liveTemplates/";
44 @NonNls private static final String[] LIVE_TEMPLATES_FILES = {"maven_generate_dom.xml"};
47 @NotNull
48 public String getComponentName() {
49 return MavenDomApplicationComponent.class.getName();
52 public void initComponent() {
53 registerLiveTemplates();
54 registerPresentations();
57 private static void registerPresentations() {
58 TypeNameManager.registerTypeName(MavenDomRepository.class, MavenDomBundle.message("maven.repository"));
59 TypeNameManager.registerTypeName(MavenDomPlugin.class, MavenDomBundle.message("maven.plugin"));
60 TypeNameManager.registerTypeName(MavenDomDependency.class, MavenDomBundle.message("maven.dependency"));
62 ElementPresentationManager.registerIcon(MavenDomRepository.class, MavenIcons.PLUGIN_ICON);
63 ElementPresentationManager.registerIcon(MavenDomDependency.class, MavenIcons.DEPENDENCY_ICON);
64 ElementPresentationManager.registerIcon(MavenDomPlugin.class, MavenIcons.PLUGIN_ICON);
67 private static void registerLiveTemplates() {
68 final TemplateSettings settings = TemplateSettings.getInstance();
69 for (String templatesFile : LIVE_TEMPLATES_FILES) {
70 try {
71 final Document document =
72 JDOMUtil.loadDocument(MavenDomApplicationComponent.class.getResourceAsStream(LIVE_TEMPLATES_DIR + templatesFile));
73 settings.readHiddenTemplateFile(document);
75 catch (Exception e) {
76 LOG.error("Can't load " + templatesFile, e);
80 public void disposeComponent() {