Skip to content

Commit

Permalink
Extracted ColummnNameKeywordMapper to its own class
Browse files Browse the repository at this point in the history
  • Loading branch information
grobmeier committed Oct 1, 2023
1 parent 21a1e25 commit 333dad7
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.apache.log4j.chainsaw.components.logpanel;

import org.apache.log4j.chainsaw.ChainsawConstants;
import org.apache.log4j.helpers.Constants;
import org.apache.log4j.spi.LoggingEventFieldResolver;

import java.util.HashMap;
import java.util.Map;

public class ColumnNameKeywordMapper {

final Map<String, String> columnNameKeywordMap = new HashMap<>();

{
columnNameKeywordMap.put(ChainsawConstants.CLASS_COL_NAME, LoggingEventFieldResolver.CLASS_FIELD);
columnNameKeywordMap.put(ChainsawConstants.FILE_COL_NAME, LoggingEventFieldResolver.FILE_FIELD);
columnNameKeywordMap.put(ChainsawConstants.LEVEL_COL_NAME, LoggingEventFieldResolver.LEVEL_FIELD);
columnNameKeywordMap.put(ChainsawConstants.LINE_COL_NAME, LoggingEventFieldResolver.LINE_FIELD);
columnNameKeywordMap.put(ChainsawConstants.LOGGER_COL_NAME, LoggingEventFieldResolver.LOGGER_FIELD);
columnNameKeywordMap.put(ChainsawConstants.NDC_COL_NAME, LoggingEventFieldResolver.NDC_FIELD);
columnNameKeywordMap.put(ChainsawConstants.MESSAGE_COL_NAME, LoggingEventFieldResolver.MSG_FIELD);
columnNameKeywordMap.put(ChainsawConstants.THREAD_COL_NAME, LoggingEventFieldResolver.THREAD_FIELD);
columnNameKeywordMap.put(ChainsawConstants.THROWABLE_COL_NAME, LoggingEventFieldResolver.EXCEPTION_FIELD);
columnNameKeywordMap.put(ChainsawConstants.TIMESTAMP_COL_NAME, LoggingEventFieldResolver.TIMESTAMP_FIELD);
columnNameKeywordMap.put(ChainsawConstants.ID_COL_NAME.toUpperCase(), LoggingEventFieldResolver.PROP_FIELD + Constants.LOG4J_ID_KEY);
columnNameKeywordMap.put(ChainsawConstants.LOG4J_MARKER_COL_NAME_LOWERCASE.toUpperCase(), LoggingEventFieldResolver.PROP_FIELD + ChainsawConstants.LOG4J_MARKER_COL_NAME_LOWERCASE);
columnNameKeywordMap.put(ChainsawConstants.MILLIS_DELTA_COL_NAME_LOWERCASE.toUpperCase(), LoggingEventFieldResolver.PROP_FIELD + ChainsawConstants.MILLIS_DELTA_COL_NAME_LOWERCASE);
}

public boolean contains(String key) {
return columnNameKeywordMap.containsKey(key);
}

public String get(String key) {
return columnNameKeywordMap.get(key);
}

public void put(String key, String value) {
columnNameKeywordMap.put(key, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,20 +222,7 @@ public LogPanel(final ChainsawStatusBar statusBar,
findCombo.setPrototypeDisplayValue(prototypeValue);
buildCombo(findCombo, false, filterCombo.model);

final Map<Object, String> columnNameKeywordMap = new HashMap<>();
columnNameKeywordMap.put(ChainsawConstants.CLASS_COL_NAME, LoggingEventFieldResolver.CLASS_FIELD);
columnNameKeywordMap.put(ChainsawConstants.FILE_COL_NAME, LoggingEventFieldResolver.FILE_FIELD);
columnNameKeywordMap.put(ChainsawConstants.LEVEL_COL_NAME, LoggingEventFieldResolver.LEVEL_FIELD);
columnNameKeywordMap.put(ChainsawConstants.LINE_COL_NAME, LoggingEventFieldResolver.LINE_FIELD);
columnNameKeywordMap.put(ChainsawConstants.LOGGER_COL_NAME, LoggingEventFieldResolver.LOGGER_FIELD);
columnNameKeywordMap.put(ChainsawConstants.NDC_COL_NAME, LoggingEventFieldResolver.NDC_FIELD);
columnNameKeywordMap.put(ChainsawConstants.MESSAGE_COL_NAME, LoggingEventFieldResolver.MSG_FIELD);
columnNameKeywordMap.put(ChainsawConstants.THREAD_COL_NAME, LoggingEventFieldResolver.THREAD_FIELD);
columnNameKeywordMap.put(ChainsawConstants.THROWABLE_COL_NAME, LoggingEventFieldResolver.EXCEPTION_FIELD);
columnNameKeywordMap.put(ChainsawConstants.TIMESTAMP_COL_NAME, LoggingEventFieldResolver.TIMESTAMP_FIELD);
columnNameKeywordMap.put(ChainsawConstants.ID_COL_NAME.toUpperCase(), LoggingEventFieldResolver.PROP_FIELD + Constants.LOG4J_ID_KEY);
columnNameKeywordMap.put(ChainsawConstants.LOG4J_MARKER_COL_NAME_LOWERCASE.toUpperCase(), LoggingEventFieldResolver.PROP_FIELD + ChainsawConstants.LOG4J_MARKER_COL_NAME_LOWERCASE);
columnNameKeywordMap.put(ChainsawConstants.MILLIS_DELTA_COL_NAME_LOWERCASE.toUpperCase(), LoggingEventFieldResolver.PROP_FIELD + ChainsawConstants.MILLIS_DELTA_COL_NAME_LOWERCASE);
ColumnNameKeywordMapper columnNameKeywordMapper = new ColumnNameKeywordMapper();

logPanelPreferencesFrame.setTitle("'" + identifier + "' Log Panel Preferences");
logPanelPreferencesFrame.setIconImage(
Expand Down Expand Up @@ -626,7 +613,7 @@ public void propertyChange(PropertyChangeEvent evt) {
searchTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "none");

//add a listener to update the 'refine focus'
tableModel.addNewKeyListener(e -> columnNameKeywordMap.put(e.getKey(), "PROP." + e.getKey()));
tableModel.addNewKeyListener(e -> columnNameKeywordMapper.put(e.getKey().toString(), "PROP." + e.getKey()));

/*
* Set the Display rule to use the mediator, the model will add itself as
Expand Down Expand Up @@ -1301,9 +1288,9 @@ public FocusOn() {
String colName = currentTable.getColumnName(column).toUpperCase();
String value = getValueOf(row, column);

if (columnNameKeywordMap.containsKey(colName)) {
if (columnNameKeywordMapper.contains(colName)) {
filterText.setText(
columnNameKeywordMap.get(colName).toString() + " " + operator
columnNameKeywordMapper.get(colName) + " " + operator
+ " '" + value + "'");
}
}
Expand All @@ -1323,10 +1310,10 @@ public DefineAddCustomFilter() {
String value = getValueOf(row, column);
String colName = currentTable.getColumnName(column).toUpperCase();

if (columnNameKeywordMap.containsKey(colName)) {
if (columnNameKeywordMapper.contains(colName)) {
filterText.setText(
filterText.getText() + " && "
+ columnNameKeywordMap.get(colName).toString() + " "
+ columnNameKeywordMapper.get(colName) + " "
+ operator + " '" + value + "'");
}

Expand All @@ -1347,10 +1334,10 @@ public DefineAddCustomFind() {
String value = getValueOf(row, column);
String colName = currentTable.getColumnName(column).toUpperCase();

if (columnNameKeywordMap.containsKey(colName)) {
if (columnNameKeywordMapper.contains(colName)) {
findCombo.setSelectedItem(
findText.getText() + " && "
+ columnNameKeywordMap.get(colName).toString() + " "
+ columnNameKeywordMapper.get(colName) + " "
+ operator + " '" + value + "'");
findNext();
}
Expand All @@ -1371,10 +1358,10 @@ public BuildColorRule() {
String colName = currentTable.getColumnName(column).toUpperCase();
String value = getValueOf(row, column);

if (columnNameKeywordMap.containsKey(colName)) {
if (columnNameKeywordMapper.contains(colName)) {
Color c = JColorChooser.showDialog(getRootPane(), "Choose a color", Color.red);
if (c != null) {
String expression = columnNameKeywordMap.get(colName).toString() + " " + operator + " '" + value + "'";
String expression = columnNameKeywordMapper.get(colName) + " " + operator + " '" + value + "'";
colorizer.addRule(new ColorRule(expression,
ExpressionRule.getRule(expression), c, ChainsawConstants.COLOR_DEFAULT_FOREGROUND));
}
Expand Down Expand Up @@ -1483,9 +1470,9 @@ public Search() {
int row = currentTable.rowAtPoint(currentPoint);
String colName = currentTable.getColumnName(column).toUpperCase();
String value = getValueOf(row, column);
if (columnNameKeywordMap.containsKey(colName)) {
if (columnNameKeywordMapper.contains(colName)) {
findCombo.setSelectedItem(
columnNameKeywordMap.get(colName).toString() + " " + operator
columnNameKeywordMapper.get(colName) + " " + operator
+ " '" + value + "'");
findNext();
}
Expand Down

0 comments on commit 333dad7

Please sign in to comment.