[Desc.] separate filtering module from logtab, apply consistent code convention, fix keyword search algorithm, and so on
[Issue]
Change-Id: I63a9972134deecd140e432faadce566f2d6022c4
name="%view.log"
icon="icons/log/logview.gif"
category="org.tizen.nativeapp.viewCategory"
- class="org.tizen.common.connection.ui.LogView"
- id="org.tizen.common.connection.ui.LogView"
+ class="org.tizen.common.connection.log.LogView"
+ id="org.tizen.common.connection.log.LogView"
allowMultiple = "true">
</view>
</extension>
<perspectiveExtension
targetID="org.tizen.nativeapp.perspective">
<view
- id="org.tizen.common.connection.ui.LogView"
+ id="org.tizen.common.connection.log.LogView"
ratio="1"
relationship="stack"
relative="org.eclipse.ui.views.TaskList">
</view>
<viewShortcut
- id="org.tizen.common.connection.ui.LogView">
+ id="org.tizen.common.connection.log.LogView">
</viewShortcut>
</perspectiveExtension>
<perspectiveExtension
targetID="org.eclipse.debug.ui.DebugPerspective">
<view
- id="org.tizen.common.connection.ui.LogView"
+ id="org.tizen.common.connection.log.LogView"
ratio="1"
relationship="stack"
relative="org.eclipse.ui.views.TaskList">
</view>
<viewShortcut
- id="org.tizen.common.connection.ui.LogView">
+ id="org.tizen.common.connection.log.LogView">
</viewShortcut>
</perspectiveExtension>
</extension>
}
device = tab.getDeviceSerialNumber();
- pidKeyword = tab.getPidFilter();
- tagKeyword = tab.getTagFilter();
- msgKeyword = tab.getMsgFilter();
+ pidKeyword = tab.getLogFilter().getPidInput();
+ tagKeyword = tab.getLogFilter().getTagInput();
+ msgKeyword = tab.getLogFilter().getMsgInput();
oldTab = tab;
}
break;
}
}
- } else
+ }
+ else
{
dCombo.select(0);
device = dCombo.getItem(0);
}
bOk = true;
-
- if ( isEmpty( tabNameText.getText() ) )
+
+ if (isEmpty(tabNameText.getText()))
{
tabName = TEMPNAME + cnt++;
}
tabName = tabNameText.getText();
}
- if ( isEmpty( tagText.getText() ) )
+ if (isEmpty(tagText.getText()))
{
tagKeyword = null;
}
tagKeyword = tagText.getText();
}
- if ( isEmpty( pidText.getText() ) )
+ if (isEmpty(pidText.getText()))
{
pidKeyword = null;
}
pidKeyword = pidText.getText();
}
- if ( isEmpty( msgText.getText() ) )
+ if (isEmpty(msgText.getText()))
{
msgKeyword = null;
}
import org.eclipse.swt.widgets.Display;
import org.tizen.common.util.SWTUtil;
-public class LogColors {
+public class LogColors
+{
public Color fatalColor;
public Color errorColor;
public Color warningColor;
--- /dev/null
+package org.tizen.common.connection.log;
+
+import org.tizen.common.util.StringUtil;
+
+public class LogFilter
+{
+ public static final int FILTER_NONE = -1;
+ public static final int FILTER_PID = 0;
+ public static final int FILTER_TAG = 1;
+ public static final int FILTER_MESSAGE = 2;
+ public static final int FILTER_LOG_LEVEL_ALL = 0x3F;
+
+ // log tab dialog keyword
+ private String pidInput;
+ private String tagInput;
+ private String msgInput;
+
+ // log tab dialog keyword filters
+ private String[] pidFilters;
+ private String[] tagFilters;
+ private String[] msgFilters;
+
+ // combo filter
+ private int comboFilter = FILTER_MESSAGE;
+
+ // keyword filter
+ private String keywordFilter = "";
+
+ // log level filter
+ private int logLevelFilter = FILTER_LOG_LEVEL_ALL;
+
+ public String getPidInput()
+ {
+ return pidInput;
+ }
+
+ public String getTagInput()
+ {
+ return tagInput;
+ }
+
+ public String getMsgInput()
+ {
+ return msgInput;
+ }
+
+ public String[] getPidFilters()
+ {
+ return pidFilters;
+ }
+
+ public String[] getTagFilters()
+ {
+ return pidFilters;
+ }
+
+ public String[] getMsgFilters()
+ {
+ return pidFilters;
+ }
+
+ public int getComboFilter()
+ {
+ return comboFilter;
+ }
+
+ public String getKeywordFilter()
+ {
+ return keywordFilter;
+ }
+
+ public int getLogLevelFilter()
+ {
+ return logLevelFilter;
+ }
+
+ public void setPidFilter(String pidInput)
+ {
+ this.pidInput = pidInput;
+ if (pidInput != null)
+ {
+ this.pidFilters = pidInput.split("[\\s,]", 0);
+ }
+ else
+ {
+ this.pidFilters = null;
+ }
+ }
+
+ public void setTagFilter(String tagInput)
+ {
+ this.tagInput = tagInput;
+ if (tagInput != null)
+ {
+ this.tagFilters = tagInput.split("[\\s,]", 0);
+ }
+ else
+ {
+ this.tagFilters = null;
+ }
+ }
+
+ public void setMsgFilter(String msgInput)
+ {
+ this.msgInput = msgInput;
+ if (msgInput != null)
+ {
+ this.msgFilters = msgInput.split("[\\s,]", 0);
+ }
+ else
+ {
+ this.msgFilters = null;
+ }
+ }
+
+ public void setComboFilter(int comboFilter)
+ {
+ this.comboFilter = comboFilter;
+ }
+
+ public void setKeywordFilter(String keywordFilter)
+ {
+ this.keywordFilter = keywordFilter;
+ }
+
+ public void setLogLevelFilter(int logLevelFilter)
+ {
+ this.logLevelFilter = logLevelFilter;
+ }
+
+ /**
+ * Filter with AddTab/EditTab dialog keyword
+ *
+ * @param logMessage
+ * @return
+ */
+ public boolean filteredByDefaultKeyword(LogMessage logMessage)
+ {
+ if (logMessage == null)
+ {
+ return false;
+ }
+
+ if (pidFilters != null || tagFilters != null || msgFilters != null)
+ {
+ if (pidFilters != null)
+ {
+ for (String filter : pidFilters)
+ {
+ if (!logMessage.data.pidString.contains(filter))
+ {
+ return false;
+ }
+ }
+ }
+
+ if (tagFilters != null)
+ {
+ for (String filter : tagFilters)
+ {
+ if (!logMessage.data.tag.toLowerCase().contains(filter.toLowerCase()))
+ {
+ return false;
+ }
+ }
+ }
+
+ if (msgFilters != null)
+ {
+ for (String filter : msgFilters)
+ {
+ if (!logMessage.msg.toLowerCase().contains(filter.toLowerCase()))
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+ return true;
+ }
+
+ /**
+ * Filter with log level
+ *
+ * @param logMessage
+ * @return
+ */
+ public boolean filteredByLoglevel(LogMessage logMessage)
+ {
+ if (logMessage == null)
+ {
+ return false;
+ }
+
+ if (logLevelFilter != FILTER_LOG_LEVEL_ALL)
+ {
+ int a = 0;
+ a = (logLevelFilter & (0x1 << (logMessage.data.logLevel.ordinal())));
+
+ if (a == 0)
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Filter with keyword
+ *
+ * @param logMessage
+ * @return
+ */
+ public boolean filteredByKeyword(LogMessage logMessage)
+ {
+ if (logMessage == null)
+ {
+ return false;
+ }
+
+ if (StringUtil.isEmpty(keywordFilter))
+ {
+ return true;
+ }
+
+ String msg = null;
+ String filter = keywordFilter.toLowerCase();
+
+ switch (comboFilter) {
+ case FILTER_PID:
+ msg = logMessage.data.pidString;
+ break;
+
+ case FILTER_TAG:
+ msg = logMessage.data.tag.toLowerCase();
+ break;
+
+ case FILTER_MESSAGE:
+ msg = logMessage.msg.toLowerCase();
+ break;
+
+ default:
+ return false;
+ }
+
+ if (msg.contains(filter))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /**
+ * Filter with log level and keyword
+ *
+ * @param logMessage
+ * @return
+ */
+ public boolean filteredByLogLevelAndKeyword(LogMessage logMessage)
+ {
+ if (filteredByLoglevel(logMessage) && filteredByKeyword(logMessage))
+ return true;
+ else
+ return false;
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.tizen.common.connection.log;
+
+import org.tizen.sdblib.util.LogLevel;
+
+/** message data, separated from content for multi line messages */
+public class LogMessage
+{
+ public LogMessageInfo data;
+ public String msg;
+
+ @Override
+ public String toString()
+ {
+ return data.time + " : " + data.logLevel + " / " + data.tag + " ( " + data.pidString + " : " + data.tidString + " ) : " + msg;
+ }
+}
+
+/** message data, separated from content for multi line messages */
+class LogMessageInfo
+{
+ public LogLevel logLevel;
+ public String pidString;
+ public String tidString;
+ public String tag;
+ public String time;
+}
\ No newline at end of file
import org.tizen.common.connection.ddmuilib.FileDialogUtils;
import org.tizen.common.connection.ddmuilib.ITableFocusListener;
import org.tizen.common.connection.ddmuilib.ITableFocusListener.IFocusedTableActivator;
-import org.tizen.common.connection.ddmuilib.Panel;
import org.tizen.common.connection.explorer.ConnectionExplorerLabelProvider;
import org.tizen.common.connection.preference.TizenLogPreferencePage;
import org.tizen.common.util.DialogUtil;
import org.tizen.sdblib.IDeviceChangeListener;
import org.tizen.sdblib.util.LogLevel;
-public class LogPanel extends Panel implements IDeviceChangeListener
+public class LogPanel implements IDeviceChangeListener
{
- //Nothing enabled
+ // Nothing enabled
public static final int NO_TAB = 0;
- //Only remove disabled
+ // Only remove disabled
public static final int DEVICE_TAB = 1;
- //Everything enabled
+ // Everything enabled
public static final int ADDITIONAL_TAB = 2;
- //Only add, edit disabled
+ // Only add, edit disabled
public static final int DISCONNECTED_TAB = 3;
-
+
private final int ENABLE_ADD = 0x0000001;
private final int ENABLE_REMOVE = 0x0000010;
- private final int ENABLE_EDIT = 0x0000100;
+ private final int ENABLE_EDIT = 0x0000100;
private final int ENABLE_SCROLL_LOCK = 0x0001000;
private final int ENABLE_EXPORT = 0x0010000;
private final int ENABLE_CLEAR = 0x0100000;
private final int ENABLE_LEVEL = 0x1000000;
- private final int[] ENABLE_VIEW_ACTIONS= { ENABLE_ADD, ENABLE_REMOVE, ENABLE_EDIT,
- ENABLE_SCROLL_LOCK, ENABLE_EXPORT, ENABLE_CLEAR};
+ private final int[] ENABLE_VIEW_ACTIONS = { ENABLE_ADD, ENABLE_REMOVE, ENABLE_EDIT, ENABLE_SCROLL_LOCK, ENABLE_EXPORT, ENABLE_CLEAR };
private String defaultLogSave;
private Action[] levelActions;
private Action[] viewActions;
-
+
private IActionBars actionBars;
private StackLayout stackLayout;
public static List<LogTab> logTabList = new ArrayList<LogTab>();
- /** message data, separated from content for multi line messages */
- protected static class LogMessageInfo
- {
- public LogLevel logLevel;
- public String pidString;
- public String tidString;
- public String tag;
- public String time;
- }
-
private ITableFocusListener globalListener;
- /** message data, separated from content for multi line messages */
- protected static class LogMessage
- {
- public LogMessageInfo data;
- public String msg;
-
- @Override
- public String toString()
- {
- return data.time + " : " + data.logLevel + " / " + data.tag + " ( " + data.pidString
- + " : " + data.tidString + " ) : " + msg;
-
- }
- }
-
/**
* Create the log panel with some default parameters
*
* Creates a control capable of displaying some information. This is called
* once, when the application is initializing, from the UI thread.
*/
- @Override
protected Control createControl(Composite p)
{
parent = p;
// create the tab folder
tabFolder = new TabFolder(parent, SWT.NONE);
tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
- //use stack layout
+ // use stack layout
stackLayout = new StackLayout();
tabFolder.setLayout(stackLayout);
tabFolder.addSelectionListener(new SelectionAdapter()
return null;
}
- @Override
- protected void postCreation()
- {
- }
-
- /**
- * Sets the focus to the proper object.
- */
- @Override
- public void setFocus()
- {
- }
-
/**
* do something when select TabItem
*/
private void selectTabItem()
{
int index = tabFolder.getSelectionIndex();
- if(index == -1)
+ if (index == -1)
{
- return ;
+ return;
}
TabItem item = tabFolder.getItem(index);
LogTab logTab = getSelectionLogTab();
- if(logTab == null)
+ if (logTab == null)
{
- return ;
+ return;
}
setEnableAndCheckState(logTab);
stackLayout.topControl = item.getControl();
}
-
/**
- * Set action enable state depending on a logTab type.
- * And then set check state.
+ * Set action enable state depending on a logTab type. And then set check
+ * state.
+ *
* @param logTab
*/
private void setEnableAndCheckState(LogTab logTab)
{
String serial = logTab.getDeviceSerialNumber();
- //if device is disconnected, only remove enabled.
- if(serial == null)
+ // if device is disconnected, only remove enabled.
+ if (serial == null)
{
setEnableState(LogPanel.DISCONNECTED_TAB, logTab);
}
/**
* When user selects level icons, update level value and filter messages.
- * @param level level type(Debug, Info, Error..)
- * @param beChecked is Checked or not
+ *
+ * @param level
+ * level type(Debug, Info, Error..)
+ * @param beChecked
+ * is Checked or not
*/
public void changeLogLevelAndFilterMessages(int level, boolean beChecked)
{
private void updateLevelMode(int level, boolean setCheck)
{
level = (int) Math.pow(2, level);
- int levelMode = getSelectionLogTab().getLevelMode();
-
+ int levelMode = getSelectionLogTab().getLogFilter().getLogLevelFilter();
+
if (setCheck)
{
levelMode |= level;
{
levelMode &= (~level);
}
- getSelectionLogTab().setLevelMode(levelMode);
+ getSelectionLogTab().getLogFilter().setLogLevelFilter(levelMode);
}
/**
- * Create LogTab and TabItem and
- * set action and icon status
- * @param device IDevice to get logs
- * @param name logtab name
- * @param isDefault check this is default logtab for device
+ * Create LogTab and TabItem and set action and icon status
+ *
+ * @param device
+ * IDevice to get logs
+ * @param name
+ * logtab name
+ * @param isDefault
+ * check this is default logtab for device
* @return
*/
private LogTab createLogTab(String name, IDevice device, boolean isDefault)
{
Iterator<LogTab> iter = logTabList.iterator();
- while( iter.hasNext())
+ while (iter.hasNext())
{
LogTab oldTab = iter.next();
- if(oldTab.getLogTabName().equals(name))
+ if (oldTab.getLogTabName().equals(name))
{
removeTab(oldTab);
iter.remove();
logTabList.add(logTab);
createTabItem(tabFolder, logTab);
-
+
if (isDefault)
{
logTab.setDefault();
setEnableState(LogPanel.DEVICE_TAB, null);
- } else
+ }
+ else
{
setEnableState(LogPanel.ADDITIONAL_TAB, null);
}
/**
* create TabItem and set to LogTab
+ *
* @param tabFolder
* @param logTab
* @return
table.setHeaderVisible(true);
table.setLinesVisible(true);
- table.addSelectionListener(new SelectionListener(){
+ table.addSelectionListener(new SelectionListener()
+ {
@Override
public void widgetSelected(SelectionEvent e)
{
- String msg = ((LogMessage)e.item.getData()).msg;
- if(msg == null)
- return ;
+ String msg = ((LogMessage) e.item.getData()).msg;
+ if (msg == null)
+ return;
IStatusLineManager statusLineManager = actionBars.getStatusLineManager();
- if( statusLineManager == null )
- return ;
- statusLineManager.setMessage( msg );
+ if (statusLineManager == null)
+ return;
+ statusLineManager.setMessage(msg);
}
+
@Override
public void widgetDefaultSelected(SelectionEvent e)
- {}
+ {
+ }
});
if (globalListener != null)
{
if (checkFile.exists())
{
int ret = FileDialogUtils.allowFileOverwrite(fileName);
- if( ret == IDialogConstants.CANCEL_ID)
+ if (ret == IDialogConstants.CANCEL_ID)
{
again = true;
}
} catch (IOException e)
{
return false;
- } finally {
- IOUtil.tryClose(writer);
+ } finally
+ {
+ IOUtil.tryClose(writer);
}
return true;
public void clear()
{
LogTab tab = getSelectionLogTab();
- if ( tab != null)
+ if (tab != null)
{
tab.clear();
}
}
/**
- * check whether device is still connected or not
- * then notify with dialog
+ * check whether device is still connected or not then notify with dialog
*
- * @param tab target to check device connection
- * @param title dialog title
- * @return if device is disconnected, return false
+ * @param tab
+ * target to check device connection
+ * @param title
+ * dialog title
+ * @return if device is disconnected, return false
*/
private boolean checkTabConnection(LogTab tab, String title)
{
LogTab newTab = createLogTab(dlg.getName(), device, false);
// set filter values from addViewDialog
- newTab.setPidFilter(dlg.getPidKeyword());
- newTab.setTagFilter(dlg.getTagKeyword());
- newTab.setMsgFilter(dlg.getMsgKeyword());
+ newTab.getLogFilter().setPidFilter(dlg.getPidKeyword());
+ newTab.getLogFilter().setTagFilter(dlg.getTagKeyword());
+ newTab.getLogFilter().setMsgFilter(dlg.getMsgKeyword());
newTab.start();
break;
}
}
- } else
+ }
+ else
{
return;
}
LogTab tab = logTabList.get(index);
removeTab(tab);
logTabList.remove(tab);
- if(logTabList.isEmpty())
+ if (logTabList.isEmpty())
{
setEnableState(NO_TAB, null);
}
}
}
- oldTab.setPidFilter(dlg.getPidKeyword());
- oldTab.setTagFilter(dlg.getTagKeyword());
- oldTab.setMsgFilter(dlg.getMsgKeyword());
+ oldTab.getLogFilter().setPidFilter(dlg.getPidKeyword());
+ oldTab.getLogFilter().setTagFilter(dlg.getTagKeyword());
+ oldTab.getLogFilter().setMsgFilter(dlg.getMsgKeyword());
oldTab.start();
/**
* Create table column has width as same as sample text length
- * @param parent table
- * @param header column header text
- * @param style column style
- * @param sampleText sample text to measure column width
+ *
+ * @param parent
+ * table
+ * @param header
+ * column header text
+ * @param style
+ * column style
+ * @param sampleText
+ * sample text to measure column width
* @return
*/
public static TableColumn createTableColumn(Table parent, String header, int style, String sampleText)
/**
* get selected logtab from tabitem on folder
+ *
* @return
*/
public LogTab getSelectionLogTab()
int index = tabFolder.getSelectionIndex();
TabItem item = tabFolder.getItem(index);
- for(LogTab logTab : logTabList)
+ for (LogTab logTab : logTabList)
{
- if(logTab.getTabItem() == item)
+ if (logTab.getTabItem() == item)
{
return logTab;
}
{
IDevice[] devices;
SmartDevelopmentBridge sdbBridge = SmartDevelopmentBridge.getBridge();
- if(sdbBridge != null)
+ if (sdbBridge != null)
{
devices = sdbBridge.getDevices();
}
String title = LogUIMessages.Log_Title_View_Device_Disconnected;
String message = String.format(LogUIMessages.Log_Message_View_Device_Disconnected, name, name);
NotifierDialog.notify(title, message, NotificationType.DISCONNECTED);
- for( LogTab tab : logTabList)
+ for (LogTab tab : logTabList)
{
- if(device.getSerialNumber().equals(tab.getDeviceSerialNumber()))
+ if (device.getSerialNumber().equals(tab.getDeviceSerialNumber()))
{
tab.setDevice(null);
}
}
setEnableState(LogPanel.DISCONNECTED_TAB, null);
- } else
+ }
+ else
{
SmartDevelopmentBridge.removeDeviceChangeListener(LogPanel.this);
}
{
LogTab tab = createLogTab(ConnectionExplorerLabelProvider.getDeviceSerialWithName(device), device, true);
tab.start();
- } else
+ }
+ else
{
SmartDevelopmentBridge.removeDeviceChangeListener(LogPanel.this);
}
/**
* Get enabled state for each action with state value.
+ *
* @param state
* @param action
* @return
/**
* Change actions enabled state
- * @param state action enabled state
- * @param oldTab if old tab is not null, re-set oldtab's enable state
+ *
+ * @param state
+ * action enabled state
+ * @param oldTab
+ * if old tab is not null, re-set oldtab's enable state
*/
private void changeEnableState(int state, LogTab oldTab)
{
- for(int i = 0; i < viewActions.length; i++)
+ for (int i = 0; i < viewActions.length; i++)
{
viewActions[i].setEnabled(getEnabled(state, ENABLE_VIEW_ACTIONS[i]));
}
boolean check = getEnabled(state, ENABLE_LEVEL);
- boolean[] bEnable = {false, false, false, false, false, false};
- //if level is enabled,
- if(check)
+ boolean[] bEnable = { false, false, false, false, false, false };
+ // if level is enabled,
+ if (check)
{
LogLevel level = null;
- if(oldTab == null)
+ if (oldTab == null)
{
level = LogLevel.getByName(ConnectionPlugin.getDefault().getPreferenceStore().getString(TizenLogPreferencePage.KEY_DEFAULT_LEVEL));
}
{
level = oldTab.getLogLevel();
}
-
- for(int i = level.ordinal(); i < bEnable.length; i++)
+
+ for (int i = level.ordinal(); i < bEnable.length; i++)
{
bEnable[i] = true;
- if(oldTab == null)
+ if (oldTab == null)
{
updateLevelMode(i, true);
}
}
}
- for(int i = 0; i < levelActions.length; i++)
+ for (int i = 0; i < levelActions.length; i++)
{
levelActions[i].setEnabled(bEnable[i]);
}
*/
private void setCheckState(LogTab tab)
{
- int levelMode = tab.getLevelMode();
+ int levelMode = tab.getLogFilter().getLogLevelFilter();
for (int i = 0; i < levelActions.length; i++)
{
int a = levelMode & (0x1 << i);
levelActions[i].setChecked(a == (int) Math.pow(2, i));
}
- //Scroll lock action is toggle action
+ // Scroll lock action is toggle action
viewActions[3].setChecked(tab.getScrollLock());
}
-
+
/**
* Get enabled state for action depending on a logTab type.
*/
}
/**
- * Set enabled state for action depending on a logTab type
- * (NO_TAB, DEVICE_TAB, ADDITIONAL_TAB).
+ * Set enabled state for action depending on a logTab type (NO_TAB,
+ * DEVICE_TAB, ADDITIONAL_TAB).
+ *
* @param tabType
*/
public void setEnableState(int tabType, LogTab tab)
/**
* Set scroll locked or unlocked.
+ *
* @param lock
*/
public void setScrollLock(boolean lock)
import org.eclipse.swt.widgets.TableItem;
import org.tizen.common.TizenPlatformConstants;
import org.tizen.common.connection.ConnectionPlugin;
-import org.tizen.common.connection.log.LogPanel.LogMessage;
-import org.tizen.common.connection.log.LogPanel.LogMessageInfo;
import org.tizen.common.connection.preference.TizenLogPreferencePage;
+import org.tizen.common.connection.log.LogMessage;
+import org.tizen.common.connection.log.LogFilter;
import org.tizen.common.ui.view.console.AnsicodeAdapter;
-import org.tizen.common.util.StringUtil;
import org.tizen.common.util.log.Logger;
import org.tizen.sdblib.IDevice;
import org.tizen.sdblib.receiver.MultiLineReceiver;
private static final int STRING_BUFFER_LENGTH = 5000;
- public static final int FILTER_NONE = -1;
- public static final int FILTER_PID = 0;
- public static final int FILTER_TAG = 1;
- public static final int FILTER_MESSAGE = 2;
-
- public static final int LEVEL_ALL = 0x3F;
- private int levelMode;
private LogLevel defaultLevel;
-
- //words to filter
- private String[] pidFilters = null;
- private String[] tagFilters = null;
- private String[] msgFilters = null;
-
- //need to show previous input value when tab dialog is opened
- private String pidInput = null;
- private String tagInput = null;
- private String msgInput = null;
-
- private int filterCombo = FILTER_MESSAGE;
- private String filterText = "";
private String logTabName = null;
private IDevice device = null;
private boolean isScrollLocked;
- private static Pattern logPattern = Pattern.compile("^\\[\\s(\\d\\d-\\d\\d\\s\\d\\d:\\d\\d:\\d\\d\\.\\d+)"
- + "\\s+(\\d*):\\s*(\\d+)\\s([VDIWEF])/(.+)\\s+\\]$");
+ private static Pattern logPattern = Pattern.compile("^\\[\\s(\\d\\d-\\d\\d\\s\\d\\d:\\d\\d:\\d\\d\\.\\d+)" + "\\s+(\\d*):\\s*(\\d+)\\s([VDIWEF])/(.+)\\s+\\]$");
- //Array to keep all messages from device
+ // Array to keep all messages from device
private final LogMessage[] allMessages = new LogMessage[STRING_BUFFER_LENGTH];
- //List about filtered messages with pidFilters, tagFilters, msgFilters
+ // List about filtered messages with pidFilters, tagFilters, msgFilters
private final List<LogMessage> filteredMessages = new ArrayList<LogMessage>();
- //List about messages need to added table contents
+ // List about messages need to added table contents
private final List<LogMessage> newMessages = new ArrayList<LogMessage>();
private LogMessageInfo lastMessageInfo = null;
private boolean isDefault = false;
- //index for allMessages
+ // index for allMessages
private int indexStart = -1;
private int indexEnd = -1;
+ private LogFilter logFilter = new LogFilter();
+
+ public LogFilter getLogFilter()
+ {
+ return logFilter;
+ }
+
public LogTab(String pName, IDevice pDevice, LogColors pColors)
{
logTabName = pName;
/**
* Get logTab name
+ *
* @return String
*/
public String getLogTabName()
return logTabName;
}
- public void setPidFilter(String pid)
- {
- pidInput = pid;
- if (pid != null)
- {
- pidFilters = setFilter(pid.split("[\\s\t,]"));
- }
- else
- {
- pidFilters = null;
- }
- }
-
- public void setTagFilter(String tag)
- {
- tagInput = tag;
- if (tag != null)
- {
- tagFilters = setFilter(tag.split("[\\s\t,]"));
- }
- else
- {
- tagFilters = null;
- }
- }
-
- public void setMsgFilter(String msg)
- {
- msgInput = msg;
- if (msg != null)
- {
- msgFilters = setFilter(msg.split("[\\s\t,]"));
- }
- else
- {
- msgFilters = null;
- }
- }
-
- private String[] setFilter(String[] array)
- {
- ArrayList<String> result = new ArrayList<String>();
- for (String s : array)
- {
- if (s.length() > 0)
- {
- result.add(s);
- }
- }
- return result.toArray(new String[(result.size())]);
- }
-
- public void setLevelMode(int level)
- {
- levelMode = level;
- }
-
- public int getLevelMode()
- {
- return levelMode;
- }
-
- public String getPidFilter()
- {
- return pidInput;
- }
-
- public String getTagFilter()
- {
- return tagInput;
- }
-
- public String getMsgFilter()
- {
- return msgInput;
- }
-
public String getDeviceSerialNumber()
{
if (device != null)
return null;
}
}
-
+
public LogLevel getLogLevel()
{
return defaultLevel;
{
return table;
}
-
+
public void start()
{
LogLevel level = LogLevel.getByName(ConnectionPlugin.getDefault().getPreferenceStore().getString(TizenLogPreferencePage.KEY_DEFAULT_LEVEL));
}
/**
- * Stop current logger and start with new level
- * It can be lost some log messages in time interval between stop and restart
- * @param level start logger with level
+ * Stop current logger and start with new level It can be lost some log
+ * messages in time interval between stop and restart
+ *
+ * @param level
+ * start logger with level
*/
public void restart(LogLevel level)
{
}
}
- boolean isValid = filteredByFilterString(newMessage);
+ boolean isValid = logFilter.filteredByDefaultKeyword(newMessage);
if (isValid)
{
filteredMessages.add(newMessage);
- if(filteredByIconAndText(newMessage))
+ if (logFilter.filteredByLogLevelAndKeyword(newMessage))
{
newMessages.add(newMessage);
}
*/
public void filterMessages()
{
- //1. remove table contents
+ // 1. remove table contents
initialize();
- //2. filtering
+ // 2. filtering
synchronized (filteredMessages)
{
for (LogMessage logMsg : filteredMessages)
{
- if (filteredByIconAndText(logMsg))
+ if (logFilter.filteredByLogLevelAndKeyword(logMsg))
{
newMessages.add(logMsg);
}
}
- //3. refill new messages
+ // 3. refill new messages
flush();
}
}
/**
- * Filter with tab dialog(AddTab, EditTab) input value
- * @param logMessage
- * @return
- */
- private boolean filteredByFilterString(LogMessage logMessage)
- {
- if (logMessage == null)
- {
- return false;
- }
- if (pidFilters != null || tagFilters != null || msgFilters != null)
- {
- if (pidFilters != null)
- {
- for (String filter : pidFilters)
- {
- if (logMessage.data.pidString.contains(filter))
- {
- return true;
- }
- }
- }
-
- if (tagFilters != null)
- {
- for (String filter : tagFilters)
- {
- if (logMessage.data.tag.toLowerCase().contains(filter.toLowerCase()))
- {
- return true;
- }
- }
- }
-
- if (msgFilters != null)
- {
- for (String filter : msgFilters)
- {
- if (logMessage.msg.toLowerCase().contains(filter.toLowerCase()))
- {
- return true;
- }
- }
- }
- return false;
- }
-
- return true;
- }
-
- /**
- * Filter with level icon on LogView toolbar
- * @param logMessage
- * @return
- */
- boolean filteredByIconAndText(LogMessage logMessage)
- {
- if (logMessage == null)
- {
- return false;
- }
-
- if (levelMode != LEVEL_ALL)
- {
- int a = 0;
- a = (levelMode & (0x1 << (logMessage.data.logLevel.ordinal())));
-
- if (a == 0)
- {
- return false;
- }
- }
-
- if (filteredByText(logMessage))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
- /**
- * Filter with text and combo input from TabItem bottom
- * @param logMessage
- * @return
- */
- boolean filteredByText(LogMessage logMessage)
- {
- if (logMessage == null)
- {
- return false;
- }
-
- if (StringUtil.isEmpty(filterText))
- {
- return true;
- }
-
- String msg = null;
- String filter = filterText.toLowerCase();
-
- switch (filterCombo)
- {
- case FILTER_PID:
- msg = logMessage.data.pidString;
- break;
-
- case FILTER_TAG:
- msg = logMessage.data.tag.toLowerCase();
- break;
-
- case FILTER_MESSAGE:
- msg = logMessage.msg.toLowerCase();
- break;
-
- default:
- return false;
- }
-
- if( msg.contains(filter))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
- /**
* flush valid messages to table and remove
*/
public void flush()
try
{
int totalCount = table.getItemCount() + newCount;
- if(totalCount > STRING_BUFFER_LENGTH)
+ if (totalCount > STRING_BUFFER_LENGTH)
{
int removeCount = totalCount - STRING_BUFFER_LENGTH;
- //remove over than STRING_BUFFER_LENGTH
+ // remove over than STRING_BUFFER_LENGTH
for (int i = 0; i < removeCount && table.getItemCount() > 0; i++)
{
table.remove(0);
Logger.error("LogFilter", e);
}
- //if isScollLocked is false, always shows last table item
- if(!getScrollLock())
+ // if isScollLocked is false, always shows last table item
+ if (!getScrollLock())
{
int count = table.getItemCount();
- if( count > 1)
+ if (count > 1)
{
table.showItem(table.getItem(table.getItemCount() - 1));
}
{
item.setForeground(colors.fatalColor);
item.setText(1, "Fatal");
- } else if (msg.data.logLevel == LogLevel.ERROR)
+ }
+ else if (msg.data.logLevel == LogLevel.ERROR)
{
item.setForeground(colors.errorColor);
item.setText(1, "Error");
- }else if (msg.data.logLevel == LogLevel.WARN)
+ }
+ else if (msg.data.logLevel == LogLevel.WARN)
{
item.setForeground(colors.warningColor);
item.setText(1, "Warning");
- } else if (msg.data.logLevel == LogLevel.INFO)
+ }
+ else if (msg.data.logLevel == LogLevel.INFO)
{
item.setForeground(colors.infoColor);
item.setText(1, "Info");
- } else if (msg.data.logLevel == LogLevel.DEBUG)
+ }
+ else if (msg.data.logLevel == LogLevel.DEBUG)
{
item.setForeground(colors.debugColor);
item.setText(1, "Debug");
- } else if (msg.data.logLevel == LogLevel.VERBOSE)
+ }
+ else if (msg.data.logLevel == LogLevel.VERBOSE)
{
item.setForeground(colors.verboseColor);
item.setText(1, "Verbose");
if (lines.length > STRING_BUFFER_LENGTH)
{
Logger.error("LogTab : Receiving more lines than " + STRING_BUFFER_LENGTH, "");
- return ;
+ return;
}
// parse the lines and create LogMessage that are stored in a temporary
lastMessageInfo.tidString = matcher.group(3);
lastMessageInfo.logLevel = LogLevel.getByLetterString(matcher.group(4));
lastMessageInfo.tag = matcher.group(5).trim();
- } else
+ }
+ else
{
if (lastMessageInfo == null)
indexStart = 0;
messageIndex = indexStart;
indexEnd = 1;
- } else
+ }
+ else
{
messageIndex = indexEnd;
{
flush();
}
- } else
+ }
+ else
{
stop(true);
}
if (inUiThread)
{
table.removeAll();
- } else
+ }
+ else
{
// run sync as we need to update right now.
syncExec(new Runnable()
}
}
-
public void setFilterCombo(int index)
{
- filterCombo = index;
+ logFilter.setComboFilter(index);
}
public void setFilterText(String text)
{
- filterText = text;
+ logFilter.setKeywordFilter(text);
}
// remove all filtered messages and tableMessages to refill or fill messages
// buffer and messages clear
public void clear()
{
- synchronized(allMessages)
+ synchronized (allMessages)
{
for (int i = 0; i < STRING_BUFFER_LENGTH; i++)
{
/*
-* Common
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact:
-* Kangho Kim <kh5225.kim@samsung.com>
-* Hyunsik Noh <hyunsik.noh@samsung.com>
-*
+ * Common
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Kangho Kim <kh5225.kim@samsung.com>
+ * Hyunsik Noh <hyunsik.noh@samsung.com>
+ *
* 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.
-*
-* Contributors:
-* - S-Core Co., Ltd
-*
-*/
+ * 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.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
package org.tizen.common.connection.log;
import org.eclipse.osgi.util.NLS;
-public class LogUIMessages extends NLS {
- private static final String BUNDLE_NAME = LogUIMessages.class.getPackage().getName() + ".LogUIMessages"; //$NON-NLS-1$
+public class LogUIMessages extends NLS
+{
+ private static final String BUNDLE_NAME = LogUIMessages.class.getPackage().getName() + ".LogUIMessages"; //$NON-NLS-1$
- public static String Log;
- public static String Log_Title_Tab_AddTab_Error;
- public static String Log_Title_Tab_EditTab_Error;
- public static String Log_Title_View_Device_Disconnected;
- public static String Log_Message_Tab_Device_Disconnected;
- public static String Log_Message_View_Device_Disconnected;
- public static String Log_Message_View_Filter_Text;
- public static String Log_Tooltip_View_Filter_Combo;
- public static String Log_Title_Tab_Export;
- public static String Log_File_Tab_Export_Postfix;
- public static String Log_File_Tab_Export_Filter;
- public static String Log_File_Tab_Export_Filter_Extensions;
+ public static String Log;
+ public static String Log_Title_Tab_AddTab_Error;
+ public static String Log_Title_Tab_EditTab_Error;
+ public static String Log_Title_View_Device_Disconnected;
+ public static String Log_Message_Tab_Device_Disconnected;
+ public static String Log_Message_View_Device_Disconnected;
+ public static String Log_Message_View_Filter_Text;
+ public static String Log_Tooltip_View_Filter_Combo;
+ public static String Log_Title_Tab_Export;
+ public static String Log_File_Tab_Export_Postfix;
+ public static String Log_File_Tab_Export_Filter;
+ public static String Log_File_Tab_Export_Filter_Extensions;
- static {
- // initialize resource bundle
- NLS.initializeMessages(BUNDLE_NAME, LogUIMessages.class);
- }
+ static
+ {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, LogUIMessages.class);
+ }
- private LogUIMessages() {
- }
+ private LogUIMessages()
+ {
+ }
}
* - S-Core Co., Ltd
*
*/
-package org.tizen.common.connection.ui;
+package org.tizen.common.connection.log;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory;
-import org.eclipse.ui.dialogs.PreferencesUtil;
import org.eclipse.ui.part.ViewPart;
import org.tizen.common.TizenHelpContextIds;
import org.tizen.common.connection.ConnectionPlugin;
import org.tizen.common.connection.log.LogColors;
import org.tizen.common.connection.log.LogPanel;
-import org.tizen.common.connection.preference.TizenLogPreferencePage;
import org.tizen.sdblib.util.LogLevel;
/**
public final class LogView extends ViewPart
{
- public static final String ID = "org.tizen.common.connection.ui.LogView"; //$NON-NLS-1$
+ public static final String ID = "org.tizen.common.connection.log.LogView"; //$NON-NLS-1$
private LogPanel logPanel;
private Composite parent;
private Action scrollLockAction;
private Action exportAction;
private Action clearAction;
- private Action preferenceAction;
private Action[] viewActions;
private Action[] levelFilterActions;
- private final String[] logLevelIcons = { "icons/log/v.png", //$NON-NLS-1S
- "icons/log/d.png", //$NON-NLS-1S
- "icons/log/i.png", //$NON-NLS-1S
- "icons/log/w.png", //$NON-NLS-1S
- "icons/log/e.png", //$NON-NLS-1S
- "icons/log/f.png"
+ private final String[] logLevelIcons =
+ {
+ "icons/log/v.png", //$NON-NLS-1S
+ "icons/log/d.png", //$NON-NLS-1S
+ "icons/log/i.png", //$NON-NLS-1S
+ "icons/log/w.png", //$NON-NLS-1S
+ "icons/log/e.png", //$NON-NLS-1S
+ "icons/log/f.png"
};
private Clipboard clipboard;
clearAction.setToolTipText("Clear the log");
clearAction.setImageDescriptor(ConnectionPlugin.getImageDescriptorFromPlugin("icons/log/clear_log.png")); //$NON-NLS-1$
- preferenceAction = new Action("Preference")
- {
- @Override
- public void run()
- {
- PreferencesUtil.createPreferenceDialogOn(parent.getShell(), TizenLogPreferencePage.id, null, null).open();
- }
- };
-
final LogLevel[] levels = LogLevel.values();
levelFilterActions = new Action[logLevelIcons.length];
for (int i = 0; i < levelFilterActions.length; i++)
levelFilterActions[i].setToolTipText(name);
levelFilterActions[i].setImageDescriptor(ConnectionPlugin.getImageDescriptorFromPlugin(logLevelIcons[i]));
}
-
+
IActionBars actionBars = getViewSite().getActionBars();
// now create the log view
logPanel = new LogPanel(colors, actionBars);
- viewActions = new Action[]{addAction, removeAction, editAction, scrollLockAction, exportAction, clearAction};
+ viewActions = new Action[] { addAction, removeAction, editAction, scrollLockAction, exportAction, clearAction };
logPanel.setActions(levelFilterActions, viewActions);
placeActions();
logPanel.setEnableState(LogPanel.NO_TAB, null);
- logPanel.createPanel(parent);
+ logPanel.createControl(parent);
// setup the copy action
clipboard = new Clipboard(d);
@Override
public void setFocus()
{
- if(parent != null)
+ if (parent != null)
{
parent.setFocus();
}
- logPanel.setFocus();
}
/**
menuManager.add(new Separator());
menuManager.add(exportAction);
menuManager.add(clearAction);
-// menuManager.add(new Separator());
-// menuManager.add(preferenceAction);
// and then in the toolbar
IToolBarManager toolBarManager = actionBars.getToolBarManager();