text filter for LogConsole
authorEugene Kudelevsky <Eugene.Kudelevsky@jetbrains.com>
Mon, 14 Sep 2009 11:29:53 +0000 (15:29 +0400)
committerEugene Kudelevsky <Eugene.Kudelevsky@jetbrains.com>
Mon, 14 Sep 2009 11:29:53 +0000 (15:29 +0400)
platform/lang-impl/src/com/intellij/diagnostic/logging/LogConsoleBase.java
platform/lang-impl/src/com/intellij/diagnostic/logging/LogConsolePreferences.java
platform/lang-impl/src/com/intellij/diagnostic/logging/LogSearchComponent.form [new file with mode: 0644]

index 92831bb5e646d2c3c35671f64de3a464e8ceee03..abf8198e5a2bbabadb53a72d8e10c829ada8edb6 100644 (file)
@@ -19,6 +19,7 @@ import com.intellij.openapi.util.Comparing;
 import com.intellij.openapi.util.Condition;
 import com.intellij.openapi.util.Disposer;
 import com.intellij.openapi.util.io.FileUtil;
+import com.intellij.ui.FilterComponent;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -27,6 +28,7 @@ import javax.swing.event.ChangeEvent;
 import java.awt.*;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
 import java.io.*;
 import java.util.ArrayList;
 import java.util.List;
@@ -58,11 +60,14 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L
   private final boolean myBuildInActions;
   private final List<LogFilter> myLogFilters = new ArrayList<LogFilter>();
 
-  /*private final FilterComponent myFilter = new FilterComponent("LOG_FILTER_HISTORY", 5) {
+  private FilterComponent myFilter = new FilterComponent("LOG_FILTER_HISTORY", 5) {
     public void filter() {
       getPreferences().updateCustomFilter(getFilter());
     }
-  };*/
+  };
+  private JPanel mySearchComponent;
+  private JComboBox myLogFilterCombo;
+  private JPanel myTextFilterWrapper;
 
   public LogConsoleBase(Project project, @Nullable Reader reader, String title, final boolean buildInActions) {
     super(new BorderLayout());
@@ -146,25 +151,26 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L
 
   @SuppressWarnings({"NonStaticInitializer"})
   private JComponent createToolbar() {
+    final LogConsolePreferences registrar = getPreferences();
 
-    /*myFilter.reset();
+    myFilter.reset();
     myFilter.setSelectedItem(registrar.CUSTOM_FILTER != null ? registrar.CUSTOM_FILTER : "");
     new AnAction() {
       {
         registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_DOWN_MASK)),
-                                  LogConsoleImpl.this);
+                                  LogConsoleBase.this);
       }
 
       public void actionPerformed(final AnActionEvent e) {
         myFilter.requestFocusInWindow();
       }
-    };*/
+    };
 
     if (myBuildInActions) {
       final JComponent tbComp =
         ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, getOrCreateActions(), true).getComponent();
       myTopComponent.add(tbComp, BorderLayout.CENTER);
-      //myTopComponent.add(myFilter, BorderLayout.EAST);
+      myTopComponent.add(myFilter, BorderLayout.EAST);
     }
 
 
@@ -210,7 +216,7 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L
   public void onTextFilterChange() {
     filterConsoleOutput(new Condition<String>() {
       public boolean value(final String line) {
-        return getPreferences().isApplicable(line, myPrevType);
+        return getPreferences().isApplicable(line, myPrevType, myShowStandardFilters);
       }
     });
   }
@@ -230,7 +236,7 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L
   public void activate() {
     if (myReaderThread == null) return;
     if (isActive() && !myReaderThread.myRunning) {
-      //myFilter.setSelectedItem(getPreferences().CUSTOM_FILTER);
+      myFilter.setSelectedItem(getPreferences().CUSTOM_FILTER);
       myReaderThread.startRunning();
       ApplicationManager.getApplication().executeOnPooledThread(myReaderThread);
     }
@@ -264,10 +270,10 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L
       Disposer.dispose(myConsole);
       myConsole = null;
     }
-    /*if (myFilter != null) {
+    if (myFilter != null) {
       myFilter.dispose();
       myFilter = null;
-    }*/
+    }
     myOriginalDocument = null;
   }
 
@@ -279,6 +285,7 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L
 
   protected void addMessage(final String text) {
     if (text == null) return;
+    if (!getPreferences().isApplicable(text, myPrevType, myShowStandardFilters)) return;
     if (myContentPreprocessor != null) {
       final java.util.List<LogFragment> fragments = myContentPreprocessor.parseLogLine(text + "\n");
       myOriginalDocument = getOriginalDocument();
@@ -291,13 +298,11 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L
     }
     else {
       final String key = LogConsolePreferences.getType(text);
-      if (getPreferences().isApplicable(text, myPrevType)) {
-        myProcessHandler.notifyTextAvailable(text + "\n", key != null
-                                                          ? LogConsolePreferences.getProcessOutputTypes(key)
-                                                          : (myPrevType == LogConsolePreferences.ERROR
-                                                             ? ProcessOutputTypes.STDERR
-                                                             : ProcessOutputTypes.STDOUT));
-      }
+      myProcessHandler.notifyTextAvailable(text + "\n", key != null
+                                                        ? LogConsolePreferences.getProcessOutputTypes(key)
+                                                        : (myPrevType == LogConsolePreferences.ERROR
+                                                           ? ProcessOutputTypes.STDERR
+                                                           : ProcessOutputTypes.STDOUT));
       if (key != null) {
         myPrevType = key;
       }
@@ -376,6 +381,7 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L
   }
 
   private boolean printMessageToConsole(String line, Condition<String> isApplicable) {
+    if (!isApplicable.value(line)) return false;
     if (myContentPreprocessor != null) {
       List<LogFragment> fragments = myContentPreprocessor.parseLogLine(line + '\n');
       for (LogFragment fragment : fragments) {
@@ -384,23 +390,19 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L
           myConsole.print(fragment.getText(), consoleViewType);
         }
       }
-      return true;
     }
     else {
       final String contentType = LogConsolePreferences.getType(line);
-      boolean applicable = isApplicable.value(line);
-      if (applicable) {
-        myConsole.print(line + "\n", contentType != null
-                                     ? LogConsolePreferences.getContentType(contentType)
-                                     : (myPrevType == LogConsolePreferences.ERROR
-                                        ? ConsoleViewContentType.ERROR_OUTPUT
-                                        : ConsoleViewContentType.NORMAL_OUTPUT));
-      }
+      myConsole.print(line + "\n", contentType != null
+                                   ? LogConsolePreferences.getContentType(contentType)
+                                   : (myPrevType == LogConsolePreferences.ERROR
+                                      ? ConsoleViewContentType.ERROR_OUTPUT
+                                      : ConsoleViewContentType.NORMAL_OUTPUT));
       if (contentType != null) {
         myPrevType = contentType;
       }
-      return applicable;
     }
+    return true;
   }
 
   public ActionGroup getToolbarActions() {
@@ -432,7 +434,7 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L
     }
 
     public boolean isAcceptable(String line) {
-      return myPrefs.isApplicable(line, myPrevType);
+      return myPrefs.isApplicable(line, myPrevType, myShowStandardFilters);
     }
   }
 
@@ -491,20 +493,22 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L
   public JComponent getSearchComponent() {
     final LogConsolePreferences prefs = getPreferences();
     List<LogFilter> filters = getLogFilters(prefs);
-    final JComboBox combo = new JComboBox(filters.toArray(new LogFilter[filters.size()]));
+    myLogFilterCombo.setModel(new DefaultComboBoxModel(filters.toArray(new LogFilter[filters.size()])));
     for (LogFilter filter : filters) {
       if (prefs.isFilterSelected(filter)) {
-        combo.setSelectedItem(filter);
+        myLogFilterCombo.setSelectedItem(filter);
         break;
       }
     }
-    combo.addActionListener(new ActionListener() {
+    myLogFilterCombo.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent e) {
-        final LogFilter filter = (LogFilter)combo.getSelectedItem();
+        final LogFilter filter = (LogFilter)myLogFilterCombo.getSelectedItem();
         prefs.selectOnlyFilter(filter);
       }
     });
-    return combo;
+    myTextFilterWrapper.removeAll();
+    myTextFilterWrapper.add(myFilter);
+    return mySearchComponent;
   }
 
   public boolean isContentBuiltIn() {
index d0286d325c0e5fcc6f8fcf18f46fd402f6ffb592..045a3966e99a7f150175b0beb1c352b97aca2979 100644 (file)
@@ -98,21 +98,24 @@ public class LogConsolePreferences extends LogFilterRegistrar {
     return ourCustomPattern;
   }
 
-  public boolean isApplicable(@NotNull String text, String prevType) {
+  public boolean isApplicable(@NotNull String text, String prevType, boolean checkStandartFilters) {
     if (CUSTOM_FILTER != null) {
       final Pattern pattern = getCustomPattern();
       if (pattern != null && !pattern.matcher(text.toUpperCase()).matches()) return false;
     }
-    final String type = getType(text);
-    boolean selfTyped = false;
-    if (type != null) {
-      if (!isApplicable(type)) return false;
-      selfTyped = true;
-    }
     for (LogFilter filter : myRegisteredLogFilters.keySet()) {
       if (myRegisteredLogFilters.get(filter).booleanValue() && !filter.isAcceptable(text)) return false;
     }
-    return selfTyped || prevType == null || isApplicable(prevType);
+    if (checkStandartFilters) {
+      final String type = getType(text);
+      boolean selfTyped = false;
+      if (type != null) {
+        if (!isApplicable(type)) return false;
+        selfTyped = true;
+      }
+      return selfTyped || prevType == null || isApplicable(prevType);
+    }
+    return true;
   }
 
   private boolean isApplicable(final String type) {
diff --git a/platform/lang-impl/src/com/intellij/diagnostic/logging/LogSearchComponent.form b/platform/lang-impl/src/com/intellij/diagnostic/logging/LogSearchComponent.form
new file mode 100644 (file)
index 0000000..23b6edb
--- /dev/null
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.diagnostic.logging.LogConsoleBase">
+  <grid id="27dc6" binding="mySearchComponent" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+    <margin top="0" left="0" bottom="0" right="0"/>
+    <constraints>
+      <xy x="20" y="20" width="213" height="28"/>
+    </constraints>
+    <properties/>
+    <border type="none"/>
+    <children>
+      <component id="8b9ce" class="javax.swing.JComboBox" binding="myLogFilterCombo">
+        <constraints>
+          <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="1" indent="0" use-parent-layout="false">
+            <minimum-size width="100" height="-1"/>
+          </grid>
+        </constraints>
+        <properties/>
+      </component>
+      <grid id="c36b9" binding="myTextFilterWrapper" layout-manager="BorderLayout" hgap="0" vgap="0">
+        <constraints>
+          <grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
+        </constraints>
+        <properties/>
+        <border type="none"/>
+        <children/>
+      </grid>
+      <hspacer id="af0cf">
+        <constraints>
+          <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+        </constraints>
+      </hspacer>
+    </children>
+  </grid>
+</form>