ComponentWithBrowseButton - optional remove listener on hide
[fedora-idea.git] / plugins / maven / src / main / java / org / jetbrains / idea / maven / utils / MavenEditorTabTitleUpdater.java
blobaeb436324d1609c5eb0b5171df45eb238c8d05c0
1 /*
2 * Copyright 2000-2009 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.openapi.fileEditor.ex.FileEditorManagerEx;
20 import com.intellij.openapi.project.Project;
21 import com.intellij.openapi.util.Pair;
22 import org.jetbrains.idea.maven.project.MavenProject;
23 import org.jetbrains.idea.maven.project.MavenProjectChanges;
24 import org.jetbrains.idea.maven.project.MavenProjectsManager;
25 import org.jetbrains.idea.maven.project.MavenProjectsTree;
27 import java.util.List;
29 public class MavenEditorTabTitleUpdater extends SimpleProjectComponent {
30 public MavenEditorTabTitleUpdater(Project project) {
31 super(project);
34 @Override
35 public void initComponent() {
36 if (!isNormalProject()) return;
38 MavenProjectsManager.getInstance(myProject).addProjectsTreeListener(new MavenProjectsTree.ListenerAdapter() {
39 @Override
40 public void projectsUpdated(List<Pair<MavenProject, MavenProjectChanges>> updated, List<MavenProject> deleted, Object message) {
41 updateTabName(MavenUtil.collectFirsts(updated));
43 });
46 private void updateTabName(final List<MavenProject> projects) {
47 MavenUtil.invokeLater(myProject, new Runnable() {
48 public void run() {
49 for (MavenProject each : projects) {
50 FileEditorManagerEx.getInstanceEx(myProject).updateFilePresentation(each.getFile());
53 });