IDEA-51739
[fedora-idea.git] / platform / platform-impl / src / com / intellij / openapi / editor / impl / DocumentMarkupModelManager.java
blob3e8384ff3eb7ac033b1951a6afb4557c44aec4ea
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.
16 package com.intellij.openapi.editor.impl;
18 import com.intellij.openapi.components.ProjectComponent;
19 import com.intellij.openapi.diagnostic.Logger;
20 import com.intellij.openapi.project.Project;
21 import com.intellij.util.containers.WeakHashMap;
22 import org.jetbrains.annotations.NotNull;
24 import java.util.Set;
26 /**
27 * @author max
29 public class DocumentMarkupModelManager implements ProjectComponent {
30 private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.editor.impl.DocumentMarkupModelManager");
32 private final WeakHashMap<DocumentImpl,String> myDocumentSet = new WeakHashMap<DocumentImpl, String>();
33 private final Project myProject;
34 private boolean myIsDisposed = false;
36 public static DocumentMarkupModelManager getInstance(Project project) {
37 return project.getComponent(DocumentMarkupModelManager.class);
40 public DocumentMarkupModelManager(Project project) {
41 myProject = project;
44 public void projectOpened() {
47 public void projectClosed() {
48 cleanup();
51 public void registerDocument(DocumentImpl doc) {
52 LOG.assertTrue(!myIsDisposed);
53 myDocumentSet.put(doc, "");
56 @NotNull
57 public String getComponentName() {
58 return "DocumentMarkupModelManager";
61 public boolean isDisposed() {
62 return myIsDisposed;
65 public void initComponent() { }
67 public void disposeComponent() {
68 cleanup();
71 private void cleanup() {
72 if (!myIsDisposed) {
73 myIsDisposed = true;
74 Set<DocumentImpl> docs = myDocumentSet.keySet();
75 for (DocumentImpl doc : docs) {
76 doc.removeMarkupModel(myProject);