aboutsummaryrefslogtreecommitdiffstats
path: root/ddms
diff options
context:
space:
mode:
authorSiva Velusamy <vsiva@google.com>2012-05-04 14:48:26 -0700
committerSiva Velusamy <vsiva@google.com>2012-05-04 14:55:04 -0700
commit6e8efa22a0b375e141daf7497272fe70c6425bc0 (patch)
treebee76f5b2e32bd4fbbb394a750f1756559c6b73e /ddms
parent95bd6a5840caaec69c686587ae2b56d74aec8bff (diff)
downloadsdk-6e8efa22a0b375e141daf7497272fe70c6425bc0.zip
sdk-6e8efa22a0b375e141daf7497272fe70c6425bc0.tar.gz
sdk-6e8efa22a0b375e141daf7497272fe70c6425bc0.tar.bz2
logcat: Validate regex patterns before creating filters.
Currently, when users create regex based filters, any error in the regex pattern is logged. When the error is logged, context switches to the Eclipse console view. As a result, users have to switch back to the logcat view and fix the error. This patch validates the text on entry and sets the text color to be red if the pattern is incorrect. There are no context switches as a result. This fixes issue: http://code.google.com/p/android/issues/detail?id=22019 Change-Id: I5b571e34c1517b0a78046b56ad83c2aa8632abdb
Diffstat (limited to 'ddms')
-rw-r--r--ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilter.java7
-rw-r--r--ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java22
2 files changed, 22 insertions, 7 deletions
diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilter.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilter.java
index 509449d..7bdd98a 100644
--- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilter.java
+++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilter.java
@@ -15,7 +15,6 @@
*/
package com.android.ddmuilib.logcat;
-import com.android.ddmlib.Log;
import com.android.ddmlib.Log.LogLevel;
import java.util.ArrayList;
@@ -96,8 +95,6 @@ public final class LogCatFilter {
mAppNamePattern = Pattern.compile(mAppName, getPatternCompileFlags(mAppName));
mCheckAppName = true;
} catch (PatternSyntaxException e) {
- Log.e("LogCatFilter", "Ignoring invalid app name regex.");
- Log.e("LogCatFilter", e.getMessage());
mCheckAppName = false;
}
}
@@ -107,8 +104,6 @@ public final class LogCatFilter {
mTagPattern = Pattern.compile(mTag, getPatternCompileFlags(mTag));
mCheckTag = true;
} catch (PatternSyntaxException e) {
- Log.e("LogCatFilter", "Ignoring invalid tag regex.");
- Log.e("LogCatFilter", e.getMessage());
mCheckTag = false;
}
}
@@ -118,8 +113,6 @@ public final class LogCatFilter {
mTextPattern = Pattern.compile(mText, getPatternCompileFlags(mText));
mCheckText = true;
} catch (PatternSyntaxException e) {
- Log.e("LogCatFilter", "Ignoring invalid text regex.");
- Log.e("LogCatFilter", e.getMessage());
mCheckText = false;
}
}
diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java
index 54381fb..d4da8e4 100644
--- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java
+++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java
@@ -78,6 +78,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
/**
* LogCatPanel displays a table listing the logcat messages.
@@ -129,6 +131,12 @@ public final class LogCatPanel extends SelectionDependentPanel
/** Index of the default filter in the saved filters column. */
private static final int DEFAULT_FILTER_INDEX = 0;
+ /* Text colors for the filter box */
+ private static final Color VALID_FILTER_REGEX_COLOR =
+ Display.getDefault().getSystemColor(SWT.COLOR_BLACK);
+ private static final Color INVALID_FILTER_REGEX_COLOR =
+ Display.getDefault().getSystemColor(SWT.COLOR_RED);
+
private LogCatReceiver mReceiver;
private IPreferenceStore mPrefStore;
@@ -542,6 +550,7 @@ public final class LogCatPanel extends SelectionDependentPanel
mLiveFilterText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent arg0) {
+ updateFilterTextColor();
updateAppliedFilters();
}
});
@@ -617,6 +626,19 @@ public final class LogCatPanel extends SelectionDependentPanel
});
}
+ /** Sets the foreground color of filter text based on whether the regex is valid. */
+ private void updateFilterTextColor() {
+ String text = mLiveFilterText.getText();
+ Color c;
+ try {
+ Pattern.compile(text.trim());
+ c = VALID_FILTER_REGEX_COLOR;
+ } catch (PatternSyntaxException e) {
+ c = INVALID_FILTER_REGEX_COLOR;
+ }
+ mLiveFilterText.setForeground(c);
+ }
+
private void updateFiltersColumn(boolean showFilters) {
if (showFilters) {
mSash.setWeights(WEIGHTS_SHOW_FILTERS);