From 68c92781853cfe014134fde06b58b4f827e29111 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 19 Mar 2009 17:48:13 +0300 Subject: [PATCH] MessageView -> service --- .../intellij/compiler/progress/CompilerTask.java | 6 ++-- .../ide/errorTreeView/NewErrorTreeViewPanel.java | 2 +- .../errorTreeView/actions/TestErrorViewAction.java | 2 +- .../src/com/intellij/ui/content/MessageView.java | 12 ++++++++ .../intellij/ui/content/impl/MessageViewImpl.java | 35 ++++------------------ .../src/META-INF/PlatformExtensions.xml | 2 ++ platform-resources/src/componentSets/Platform.xml | 6 ---- .../ant/config/execution/AntBuildMessageView.java | 4 +-- .../openapi/vcs/impl/AbstractVcsHelperImpl.java | 4 +-- .../xml/actions/ValidateXmlActionHandler.java | 4 +-- 10 files changed, 31 insertions(+), 46 deletions(-) diff --git a/compiler/impl/com/intellij/compiler/progress/CompilerTask.java b/compiler/impl/com/intellij/compiler/progress/CompilerTask.java index 3755f7c05f..c28714b935 100644 --- a/compiler/impl/com/intellij/compiler/progress/CompilerTask.java +++ b/compiler/impl/com/intellij/compiler/progress/CompilerTask.java @@ -385,7 +385,7 @@ public class CompilerTask extends Task.Backgroundable { component = myErrorTreeView.getComponent(); } - final MessageView messageView = myProject.getComponent(MessageView.class); + final MessageView messageView = MessageView.SERVICE.getInstance(myProject); final Content content = PeerFactory.getInstance().getContentFactory().createContent(component, myContentName, true); content.putUserData(CONTENT_ID_KEY, myContentId); messageView.getContentManager().addContent(content); @@ -398,7 +398,7 @@ public class CompilerTask extends Task.Backgroundable { public void showCompilerContent() { synchronized (myMessageViewLock) { if (myErrorTreeView != null) { - final MessageView messageView = myProject.getComponent(MessageView.class); + final MessageView messageView = MessageView.SERVICE.getInstance(myProject); Content[] contents = messageView.getContentManager().getContents(); for (Content content : contents) { if (content.getUserData(CONTENT_ID_KEY) != null) { @@ -411,7 +411,7 @@ public class CompilerTask extends Task.Backgroundable { } public static void removeAllContents(Project project, Content notRemove) { - MessageView messageView = project.getComponent(MessageView.class); + MessageView messageView = MessageView.SERVICE.getInstance(project); Content[] contents = messageView.getContentManager().getContents(); for (Content content : contents) { if (content.isPinned()) continue; diff --git a/platform-impl/src/com/intellij/ide/errorTreeView/NewErrorTreeViewPanel.java b/platform-impl/src/com/intellij/ide/errorTreeView/NewErrorTreeViewPanel.java index 2b4f04a6c9..00690035be 100644 --- a/platform-impl/src/com/intellij/ide/errorTreeView/NewErrorTreeViewPanel.java +++ b/platform-impl/src/com/intellij/ide/errorTreeView/NewErrorTreeViewPanel.java @@ -300,7 +300,7 @@ public class NewErrorTreeViewPanel extends JPanel implements DataProvider, Occur } public void close() { - MessageView messageView = myProject.getComponent(MessageView.class); + MessageView messageView = MessageView.SERVICE.getInstance(myProject); Content content = messageView.getContentManager().getContent(this); if (content != null) { messageView.getContentManager().removeContent(content, true); diff --git a/platform-impl/src/com/intellij/ide/errorTreeView/actions/TestErrorViewAction.java b/platform-impl/src/com/intellij/ide/errorTreeView/actions/TestErrorViewAction.java index 16754f1219..84f5566e5a 100644 --- a/platform-impl/src/com/intellij/ide/errorTreeView/actions/TestErrorViewAction.java +++ b/platform-impl/src/com/intellij/ide/errorTreeView/actions/TestErrorViewAction.java @@ -94,7 +94,7 @@ public abstract class TestErrorViewAction extends AnAction{ protected abstract String getContentName(); protected void openView(Project project, JComponent component) { - final MessageView messageView = project.getComponent(MessageView.class); + final MessageView messageView = MessageView.SERVICE.getInstance(project); final Content content = ContentFactory.SERVICE.getInstance().createContent(component, getContentName(), true); messageView.getContentManager().addContent(content); messageView.getContentManager().setSelectedContent(content); diff --git a/platform-impl/src/com/intellij/ui/content/MessageView.java b/platform-impl/src/com/intellij/ui/content/MessageView.java index 0166a44d5e..9ed1c1437d 100644 --- a/platform-impl/src/com/intellij/ui/content/MessageView.java +++ b/platform-impl/src/com/intellij/ui/content/MessageView.java @@ -1,8 +1,20 @@ package com.intellij.ui.content; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.components.ServiceManager; + public interface MessageView { ContentManager getContentManager(); void runWhenInitialized(final Runnable runnable); + + class SERVICE { + private SERVICE() { + } + + public static MessageView getInstance(Project project) { + return ServiceManager.getService(project, MessageView.class); + } + } } diff --git a/platform-impl/src/com/intellij/ui/content/impl/MessageViewImpl.java b/platform-impl/src/com/intellij/ui/content/impl/MessageViewImpl.java index 80d25dd01d..1dd92fbc81 100644 --- a/platform-impl/src/com/intellij/ui/content/impl/MessageViewImpl.java +++ b/platform-impl/src/com/intellij/ui/content/impl/MessageViewImpl.java @@ -2,7 +2,7 @@ package com.intellij.ui.content.impl; import com.intellij.ide.impl.ContentManagerWatcher; -import com.intellij.openapi.components.ProjectComponent; +import com.intellij.openapi.project.Project; import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.wm.ToolWindow; @@ -11,35 +11,21 @@ import com.intellij.openapi.wm.ToolWindowId; import com.intellij.openapi.wm.ToolWindowManager; import com.intellij.ui.content.ContentManager; import com.intellij.ui.content.MessageView; -import org.jetbrains.annotations.NotNull; -import java.util.List; import java.util.ArrayList; +import java.util.List; /** * @author Eugene Belyaev */ -public class MessageViewImpl implements ProjectComponent, MessageView { - private final StartupManager myStartupManager; - private final ToolWindowManager myToolWindowManager; +public class MessageViewImpl implements MessageView { private ToolWindow myToolWindow; private final List myPostponedRunnables = new ArrayList(); - public MessageViewImpl(final StartupManager startupManager, final ToolWindowManager toolWindowManager) { - myStartupManager = startupManager; - myToolWindowManager = toolWindowManager; - } - - public void initComponent() { - } - - public void disposeComponent() { - } - - public void projectOpened() { - myStartupManager.registerPostStartupActivity(new Runnable() { + public MessageViewImpl(final Project project, final StartupManager startupManager, final ToolWindowManager toolWindowManager) { + startupManager.runWhenProjectIsInitialized(new Runnable() { public void run() { - myToolWindow = myToolWindowManager.registerToolWindow(ToolWindowId.MESSAGES_WINDOW, true, ToolWindowAnchor.BOTTOM); + myToolWindow = toolWindowManager.registerToolWindow(ToolWindowId.MESSAGES_WINDOW, true, ToolWindowAnchor.BOTTOM, project); myToolWindow.setIcon(IconLoader.getIcon("/general/toolWindowMessages.png")); new ContentManagerWatcher(myToolWindow, getContentManager()); for (Runnable postponedRunnable : myPostponedRunnables) { @@ -62,13 +48,4 @@ public class MessageViewImpl implements ProjectComponent, MessageView { myPostponedRunnables.add(runnable); } } - - public void projectClosed() { - myToolWindowManager.unregisterToolWindow(ToolWindowId.MESSAGES_WINDOW); - } - - @NotNull - public String getComponentName() { - return "MessageViewImpl"; - } } diff --git a/platform-resources/src/META-INF/PlatformExtensions.xml b/platform-resources/src/META-INF/PlatformExtensions.xml index 9a040b3c38..5338d086db 100644 --- a/platform-resources/src/META-INF/PlatformExtensions.xml +++ b/platform-resources/src/META-INF/PlatformExtensions.xml @@ -94,6 +94,8 @@ serviceImplementation="com.intellij.ide.impl.SelectInEditorManagerImpl"/> + diff --git a/platform-resources/src/componentSets/Platform.xml b/platform-resources/src/componentSets/Platform.xml index 34bf9de93e..93425a0306 100644 --- a/platform-resources/src/componentSets/Platform.xml +++ b/platform-resources/src/componentSets/Platform.xml @@ -116,12 +116,6 @@ - com.intellij.ui.content.MessageView - com.intellij.ui.content.impl.MessageViewImpl - - - - com.intellij.ide.util.PropertiesComponent com.intellij.ide.util.ProjectPropertiesComponentImpl