From ced8bf91aeb2ce003435d3df9c4d7789e1f79ebd Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 31 May 2011 18:58:02 +0200 Subject: [PATCH] display the last log message in the status bar --- .../com/intellij/notification/EventLog.java | 12 +-- .../intellij/openapi/wm/ex/StatusBarEx.java | 2 + .../openapi/wm/impl/TestWindowManager.java | 4 + .../wm/impl/status/IdeStatusBarImpl.java | 6 ++ .../wm/impl/status/InfoAndProgressPanel.java | 36 ++++++--- .../openapi/wm/impl/status/StatusPanel.java | 73 +++++++++++++++++++ 6 files changed, 118 insertions(+), 15 deletions(-) create mode 100644 platform/platform-impl/src/com/intellij/openapi/wm/impl/status/StatusPanel.java diff --git a/platform/lang-impl/src/com/intellij/notification/EventLog.java b/platform/lang-impl/src/com/intellij/notification/EventLog.java index ee26463f0465..a37ab6d0953b 100644 --- a/platform/lang-impl/src/com/intellij/notification/EventLog.java +++ b/platform/lang-impl/src/com/intellij/notification/EventLog.java @@ -26,8 +26,8 @@ import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.wm.ToolWindow; -import com.intellij.openapi.wm.ToolWindowFactory; +import com.intellij.openapi.wm.*; +import com.intellij.openapi.wm.ex.StatusBarEx; import com.intellij.ui.content.Content; import com.intellij.ui.content.ContentFactory; import org.jetbrains.annotations.NotNull; @@ -74,14 +74,14 @@ public class EventLog implements Notifications { getApplicationComponent().addGlobalNotifications(notification); } for (Project p : openProjects) { - printNotification(getProjectComponent(p).myConsoleView, notification); + printNotification(getProjectComponent(p).myConsoleView, p, notification); } } else { - printNotification(getProjectComponent(project).myConsoleView, notification); + printNotification(getProjectComponent(project).myConsoleView, project, notification); } } - private static void printNotification(ConsoleViewImpl view, final Notification notification) { + private static void printNotification(ConsoleViewImpl view, Project project, final Notification notification) { view.print(DateFormat.getTimeInstance(DateFormat.MEDIUM).format(new Date()) + " ", ConsoleViewContentType.NORMAL_OUTPUT); boolean showLink = notification.getListener() != null; @@ -119,6 +119,8 @@ public class EventLog implements Notifications { view.print(" ", ConsoleViewContentType.NORMAL_OUTPUT); } view.print("\n", ConsoleViewContentType.NORMAL_OUTPUT); + + ((StatusBarEx)WindowManager.getInstance().getIdeFrame(project).getStatusBar()).setLogMessage(mainText); } private static int eolIndex(String mainText) { diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/ex/StatusBarEx.java b/platform/platform-impl/src/com/intellij/openapi/wm/ex/StatusBarEx.java index f6920f33b941..e36f58a11c6a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/ex/StatusBarEx.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/ex/StatusBarEx.java @@ -53,4 +53,6 @@ public interface StatusBarEx extends StatusBar, Disposable { @Nullable String getInfoRequestor(); + + void setLogMessage(String text); } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/TestWindowManager.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/TestWindowManager.java index 5eb9c1c3aee5..0f7ef80f0eba 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/TestWindowManager.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/TestWindowManager.java @@ -109,6 +109,10 @@ public final class TestWindowManager extends WindowManagerEx implements Applicat return null; } + @Override + public void setLogMessage(String text) { + } + public boolean isVisible() { return false; } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/IdeStatusBarImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/IdeStatusBarImpl.java index 8aa42baf7d5d..b6ecd5c66a83 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/IdeStatusBarImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/IdeStatusBarImpl.java @@ -403,6 +403,12 @@ public class IdeStatusBarImpl extends JComponent implements StatusBarEx { return myRequestor; } + @Override + public void setLogMessage(String text) { + myInfoAndProgressPanel.setLogMessage(text); + setInfo(null, "Log message"); + } + public void addProgress(ProgressIndicatorEx indicator, TaskInfo info) { myInfoAndProgressPanel.addProgress(indicator, info); } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/InfoAndProgressPanel.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/InfoAndProgressPanel.java index 49c4b99b04da..f2bfb0edd7f3 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/InfoAndProgressPanel.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/InfoAndProgressPanel.java @@ -55,15 +55,12 @@ import javax.swing.event.HyperlinkListener; import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; +import java.util.*; public class InfoAndProgressPanel extends JPanel implements CustomStatusBarWidget { private final ProcessPopup myPopup; - private final TextPanel myInfoPanel = new TextPanel(); + private final StatusPanel myInfoPanel = new StatusPanel(); private final JPanel myRefreshAndInfoPanel = new JPanel(); private final AsyncProcessIcon myProgressIcon; @@ -177,7 +174,11 @@ public class InfoAndProgressPanel extends JPanel implements CustomStatusBarWidge public void addProgress(final ProgressIndicatorEx original, TaskInfo info) { synchronized (myOriginals) { - final boolean veryFirst = myOriginals.isEmpty(); + final boolean veryFirst = !hasProgressIndicators(); + + if (veryFirst) { + myInfoPanel.hideLog(); + } myOriginals.add(original); myInfos.add(info); @@ -202,6 +203,12 @@ public class InfoAndProgressPanel extends JPanel implements CustomStatusBarWidge } } + private boolean hasProgressIndicators() { + synchronized (myOriginals) { + return !myOriginals.isEmpty(); + } + } + private void removeProgress(InlineProgressIndicator progress) { synchronized (myOriginals) { if (!myInline2Original.containsKey(progress)) return; @@ -233,6 +240,10 @@ public class InfoAndProgressPanel extends JPanel implements CustomStatusBarWidge } runQuery(); + + if (last) { + myInfoPanel.restoreLogIfNeeded(); + } } } @@ -254,7 +265,7 @@ public class InfoAndProgressPanel extends JPanel implements CustomStatusBarWidge private void openProcessPopup(boolean requestFocus) { synchronized (myOriginals) { if (myPopup.isShowing()) return; - if (!myOriginals.isEmpty()) { + if (hasProgressIndicators()) { myShouldClosePopupAndOnProcessFinish = true; buildInProcessCount(); } @@ -273,7 +284,7 @@ public class InfoAndProgressPanel extends JPanel implements CustomStatusBarWidge if (myOriginals.size() == 1) { buildInInlineIndicator(createInlineDelegate(myInfos.get(0), myOriginals.get(0), true)); } - else if (myOriginals.isEmpty()) { + else if (!hasProgressIndicators()) { restoreEmptyStatus(); } else { @@ -351,8 +362,9 @@ public class InfoAndProgressPanel extends JPanel implements CustomStatusBarWidge return Pair.create(myInfoPanel.getText(), myCurrentRequestor); } - myInfoPanel.setText(text); - myCurrentRequestor = requestor; + final boolean logMode = StringUtil.isEmpty(text) && !hasProgressIndicators(); + myInfoPanel.updateText(logMode, text); + myCurrentRequestor = logMode ? requestor : null; return Pair.create(text, requestor); } @@ -410,6 +422,10 @@ public class InfoAndProgressPanel extends JPanel implements CustomStatusBarWidge }; } + public void setLogMessage(String text) { + myInfoPanel.setLogMessage(text); + } + private static class InlineLayout extends AbstractLayoutManager { public Dimension preferredLayoutSize(final Container parent) { diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/StatusPanel.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/StatusPanel.java new file mode 100644 index 000000000000..bc792573d642 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/StatusPanel.java @@ -0,0 +1,73 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.wm.impl.status; + +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.util.Alarm; +import com.intellij.util.text.DateFormatUtil; +import org.jetbrains.annotations.Nullable; + +import java.util.Date; + +/** + * @author peter + */ +class StatusPanel extends TextPanel { + private boolean myLogMode; + private String myLogMessage; + private Date myLogTime; + private final Alarm myLogAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD); + + public void setLogMessage(String text) { + myLogMessage = text; + myLogTime = new Date(); + } + + public void updateText(boolean logMode, @Nullable String nonLogText) { + myLogMode = logMode; + + if (logMode) { + new Runnable() { + @Override + public void run() { + setText(myLogMessage + " (" + StringUtil.decapitalize(DateFormatUtil.formatPrettyDateTime(myLogTime)) + ")"); + myLogAlarm.addRequest(this, 30000); + } + }.run(); + } else { + setText(nonLogText); + myLogAlarm.cancelAllRequests(); + } + + } + + public void hideLog() { + if (myLogMode) { + updateText(false, ""); + } + } + + public void restoreLogIfNeeded() { + myLogAlarm.addRequest(new Runnable() { + @Override + public void run() { + if (StringUtil.isEmpty(getText())) { + updateText(true, ""); + } + } + }, 500); + } +}