From 1266700dc067745c5fd1f6a8ba7fd1d0aae193e7 Mon Sep 17 00:00:00 2001 From: "hyunsik.noh" Date: Wed, 2 Nov 2011 11:06:01 +0900 Subject: [PATCH] [Title] Adapt sdb in LogView [Type] Feature [Module] common [Priority] Minor [Redmine#]Feature #3124 --- .../icons/Export Log.gif | Bin 0 -> 378 bytes com.samsung.slp.common.connection/plugin.xml | 11 +- .../slp/common/connection/ConnectionPlugin.java | 50 +- .../connection/ddmuilib/FileDialogUtils.java | 2 +- .../ConnectionExplorerContentProvider.java | 2 +- .../ConnectionExplorerLabelProvider.java | 2 +- .../{ui => explorer}/ConnectionExplorerPanel.java | 212 +++--- .../connection/{ui => explorer}/Messages.java | 2 +- .../{ui => explorer}/messages.properties | 0 .../common/connection/handler/ClearLogHandler.java | 45 ++ .../connection/handler/ExportLogHandler.java | 52 ++ .../connection/handler/ImportLogHandler.java | 56 ++ .../slp/common/connection/log/LogController.java | 815 +++++++++++++++++++++ .../slp/common/connection/log/LogFilter.java | 111 +++ .../common/connection/ui/ConnectionExplorer.java | 14 +- .../samsung/slp/common/connection/ui/LogView.java | 487 ++++++++++++ com.samsung.slp.connection/plugin.xml | 12 +- .../src/com/samsung/slp/common/conn/Activator.java | 1 - 18 files changed, 1720 insertions(+), 154 deletions(-) create mode 100644 com.samsung.slp.common.connection/icons/Export Log.gif rename com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/{ui => explorer}/ConnectionExplorerContentProvider.java (99%) rename com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/{ui => explorer}/ConnectionExplorerLabelProvider.java (98%) rename com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/{ui => explorer}/ConnectionExplorerPanel.java (87%) rename com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/{ui => explorer}/Messages.java (95%) rename com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/{ui => explorer}/messages.properties (100%) create mode 100644 com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/handler/ClearLogHandler.java create mode 100644 com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/handler/ExportLogHandler.java create mode 100644 com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/handler/ImportLogHandler.java create mode 100644 com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/log/LogController.java create mode 100644 com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/log/LogFilter.java create mode 100644 com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/LogView.java diff --git a/com.samsung.slp.common.connection/icons/Export Log.gif b/com.samsung.slp.common.connection/icons/Export Log.gif new file mode 100644 index 0000000000000000000000000000000000000000..0c7a2cea0514914967315730088a759d067f90c1 GIT binary patch literal 378 zcmV-=0fqiYNk%w1VGsZi0M!5h00030|Nl>YuTp@qR)VuccB)2qt44UMNO`PFd#zG{ zuv(nVZnolex#NDl<%h!OlgH_u%{)${-B`Tyzp|M2_&>iYld`v3R+|NH*` z@%;bt{Qvg-|N8#_`Tqa@{qOtmwEO9v^yaSl-ForbgZtiv|NQccb2Ec(HTlzKb7VVg zU_EABKVexxmU%Cdb})QtII(sPrE3hVaSfkj3Y%aGpJWT4WeY+=LjV8&0000000000 z00000A^8LW0027xEC2ui01yBW000J;z`_BM5DW-}fgo`x?4Aoo!|{MbB9MoJv3TwZ z2BJWLR4fh7Cyc^wyD2bljH0XSES8J@67!}g7#SHA92^se6DeLQbar)zC=)7PG87jb z9Uh2>Gc#T+jgC5;A)Y%e6dDpB8;G4VAtatI6dxO{oFclqCN(d=z`r&l#Ka{uUdc~3 YI5;OOIm*&IH!C;O(l^)G+&e)4JF=IwivR!s literal 0 HcmV?d00001 diff --git a/com.samsung.slp.common.connection/plugin.xml b/com.samsung.slp.common.connection/plugin.xml index 090956f..5248a23 100644 --- a/com.samsung.slp.common.connection/plugin.xml +++ b/com.samsung.slp.common.connection/plugin.xml @@ -129,10 +129,10 @@ - + diff --git a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ConnectionPlugin.java b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ConnectionPlugin.java index 5c1ca3f..5005d2e 100644 --- a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ConnectionPlugin.java +++ b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ConnectionPlugin.java @@ -1,14 +1,14 @@ package com.samsung.slp.common.connection; +import java.util.ArrayList; import java.util.Properties; -import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; -import com.samsung.slp.common.connection.ddmuilib.DdmUiPreferences; import com.samsung.slp.sdblib.FileListingService.FileEntry; import com.samsung.slp.sdblib.IDevice; +import com.samsung.slp.sdblib.Log; //import com.samsung.slp.common.connection.device.DeviceMonitor; //import com.samsung.slp.common.connection.sdb.SdbHelper; @@ -20,12 +20,12 @@ public class ConnectionPlugin extends AbstractUIPlugin { // The plug-in ID public static final String PLUGIN_ID = "com.samsung.slp.common.connection"; //$NON-NLS-1$ - + public static final String ID_LOGS_VIEW= "com.samsung.slp.common.conn.ui.LogView"; //$NON-NLS-1$ // The shared instance private static ConnectionPlugin plugin; private IDevice mCurrentDevice; -// private final ArrayList mListeners = new ArrayList(); + private final ArrayList mListeners = new ArrayList(); public int OS; public final int LINUX = 0; @@ -68,11 +68,11 @@ public class ConnectionPlugin extends AbstractUIPlugin { // AndroidDebugBridge.createBridge("/home/mustafa/mywork/source/sdb/bin/adb",true); // get the eclipse store - final IPreferenceStore eclipseStore = getPreferenceStore(); +// final IPreferenceStore eclipseStore = getPreferenceStore(); //AndroidDebugBridge.addDeviceChangeListener(this); - DdmUiPreferences.setStore(eclipseStore); +// DdmUiPreferences.setStore(eclipseStore); // DeviceMonitor monitor = new DeviceMonitor(); // monitor.processDeviceData(); @@ -108,15 +108,33 @@ public class ConnectionPlugin extends AbstractUIPlugin { return mCurrentDevice; } -// public synchronized void addSelectionListener(ISelectionListener listener) { -// mListeners.add(listener); -// -// // notify the new listener of the current selection -//// listener.selectionChanged(mCurrentDevice); -// } -// -// public synchronized void removeSelectionListener(ISelectionListener listener) { -// mListeners.remove(listener); -// } + + public void addSelectionListener(ISelectionListener listener) { + mListeners.add(listener); + } + public void removeSelectionListener(ISelectionListener listener) { + mListeners.remove(listener); + } + + public void notifySelectionListeners(FileEntry file) { + + ISelectionListener[] mlistenersCopy = mListeners.toArray( + new ISelectionListener[mListeners.size()]); + + for (ISelectionListener listener : mlistenersCopy) + { + // notify the listener with a try/catch-all to make sure this thread won't die + // because of an uncaught exception before all the listeners were notified. + + try + { + listener.selectionChanged( file ); + } + catch (Exception e) + { + Log.e("ConnectionPlugin", e); + } + } + } } diff --git a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ddmuilib/FileDialogUtils.java b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ddmuilib/FileDialogUtils.java index 30c9d80..1caba77 100644 --- a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ddmuilib/FileDialogUtils.java +++ b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ddmuilib/FileDialogUtils.java @@ -6,7 +6,7 @@ import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.ui.PlatformUI; -import com.samsung.slp.common.connection.ui.Messages; +import com.samsung.slp.common.connection.explorer.Messages; public class FileDialogUtils { private static FileDialogUtils instance; diff --git a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/ConnectionExplorerContentProvider.java b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/explorer/ConnectionExplorerContentProvider.java similarity index 99% rename from com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/ConnectionExplorerContentProvider.java rename to com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/explorer/ConnectionExplorerContentProvider.java index 8cad523..b0588da 100644 --- a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/ConnectionExplorerContentProvider.java +++ b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/explorer/ConnectionExplorerContentProvider.java @@ -1,4 +1,4 @@ -package com.samsung.slp.common.connection.ui; +package com.samsung.slp.common.connection.explorer; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.TreeViewer; diff --git a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/ConnectionExplorerLabelProvider.java b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/explorer/ConnectionExplorerLabelProvider.java similarity index 98% rename from com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/ConnectionExplorerLabelProvider.java rename to com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/explorer/ConnectionExplorerLabelProvider.java index abd2ad6..cefc139 100644 --- a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/ConnectionExplorerLabelProvider.java +++ b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/explorer/ConnectionExplorerLabelProvider.java @@ -1,4 +1,4 @@ -package com.samsung.slp.common.connection.ui; +package com.samsung.slp.common.connection.explorer; import org.eclipse.jface.viewers.ILabelProviderListener; import org.eclipse.jface.viewers.ITableLabelProvider; diff --git a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/ConnectionExplorerPanel.java b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/explorer/ConnectionExplorerPanel.java similarity index 87% rename from com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/ConnectionExplorerPanel.java rename to com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/explorer/ConnectionExplorerPanel.java index 879f9fd..a97ff7d 100644 --- a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/ConnectionExplorerPanel.java +++ b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/explorer/ConnectionExplorerPanel.java @@ -1,4 +1,4 @@ -package com.samsung.slp.common.connection.ui; +package com.samsung.slp.common.connection.explorer; import java.io.BufferedReader; import java.io.File; @@ -61,7 +61,7 @@ import com.samsung.slp.sdblib.SyncService; import com.samsung.slp.sdblib.SyncService.ISyncProgressMonitor; import com.samsung.slp.sdblib.SyncService.SyncResult; -public class ConnectionExplorerPanel extends Panel implements SmartDevelopmentBridge.IDeviceChangeListener, SmartDevelopmentBridge.IDebugBridgeChangeListener{ +public class ConnectionExplorerPanel extends Panel implements IDeviceChangeListener, IDebugBridgeChangeListener{ private final static String TRACE_KEY_EXT = ".key"; // $NON-NLS-1S private final static String TRACE_DATA_EXT = ".data"; // $NON-NLS-1S @@ -96,7 +96,7 @@ public class ConnectionExplorerPanel extends Panel implements SmartDevelopmentBr private String mDefaultSave; - private final ArrayList mListeners = new ArrayList(); +// private final ArrayList mListeners = new ArrayList(); private final ArrayList mDevicesToExpand = new ArrayList(); private final ArrayList mDevicesList = new ArrayList(); @@ -153,39 +153,10 @@ public class ConnectionExplorerPanel extends Panel implements SmartDevelopmentBr mTree.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - notifyListeners(); + notifyListeners(); } }); - // setup a listener for selection -// mTreeViewer -// .addSelectionChangedListener(new ISelectionChangedListener() { -// public void selectionChanged(SelectionChangedEvent event) { -// ISelection sel = event.getSelection(); -// if (sel.isEmpty()) { -// mPullAction.setEnabled(false); -// mPushAction.setEnabled(false); -// mDeleteAction.setEnabled(false); -// return; -// } -// if (sel instanceof IStructuredSelection) { -// IStructuredSelection selection = (IStructuredSelection) sel; -// Object element = selection.getFirstElement(); -// if (element == null) -// return; -// if (element instanceof FileEntry) { -// mPullAction.setEnabled(true); -// mPushAction.setEnabled(selection.size() == 1); -// if (selection.size() == 1) { -// setDeleteEnabledState((FileEntry) element); -// } else { -// mDeleteAction.setEnabled(false); -// } -// } -// } -// } -// }); - // add support for double click mTreeViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { @@ -390,6 +361,9 @@ public class ConnectionExplorerPanel extends Panel implements SmartDevelopmentBr @Override protected void postCreation() { SmartDevelopmentBridge sdbBridge = SmartDevelopmentBridge.getBridge(); + SmartDevelopmentBridge.addDebugBridgeChangeListener(this); + SmartDevelopmentBridge.addDeviceChangeListener(this); + IDevice[] devices = null; if ( sdbBridge != null ) { @@ -402,8 +376,6 @@ public class ConnectionExplorerPanel extends Panel implements SmartDevelopmentBr this.deviceConnected(device); } } - SmartDevelopmentBridge.addDebugBridgeChangeListener(this); - SmartDevelopmentBridge.addDeviceChangeListener(this); } /** @@ -857,14 +829,12 @@ public class ConnectionExplorerPanel extends Panel implements SmartDevelopmentBr if (mTree.isDisposed() == false) { // set up the data source. mTreeViewer.setInput(bridge); - - // notify the listener of a possible selection change. - notifyListeners(); + } else { // tree is disposed, we need to do something. // lets remove ourselves from the listener. SmartDevelopmentBridge.removeDebugBridgeChangeListener(ConnectionExplorerPanel.this); - SmartDevelopmentBridge.removeDeviceChangeListener(ConnectionExplorerPanel.this); + SmartDevelopmentBridge.removeDeviceChangeListener(ConnectionExplorerPanel.this); } } }); @@ -1132,49 +1102,61 @@ public class ConnectionExplorerPanel extends Panel implements SmartDevelopmentBr * * @see IDeviceChangeListener#deviceConnected(IDevice) */ - public void deviceConnected(IDevice device) { - mDevicesList.add( device ); - exec(new Runnable() { - public void run() { - if (mTree.isDisposed() == false) { - // refresh all - mTreeViewer.refresh(); - - // notify the listener of a possible selection change. - notifyListeners(); - } else { - // tree is disposed, we need to do something. - // lets remove ourselves from the listener. - SmartDevelopmentBridge.removeDebugBridgeChangeListener(ConnectionExplorerPanel.this); - SmartDevelopmentBridge.removeDeviceChangeListener(ConnectionExplorerPanel.this); - } - } - }); - - // if it doesn't have clients yet, it'll need to be manually expanded when it gets them. -// if (device.hasClients() == false) { - synchronized (mDevicesToExpand) { - mDevicesToExpand.add(device); - } + public void deviceConnected(IDevice device) + { + mDevicesList.add( device ); + exec(new Runnable() + { + public void run() + { + if (mTree.isDisposed() == false) + { + // refresh all + mTreeViewer.refresh(); + + // notify the listener of a possible selection change. + notifyListeners(); + } + else + { + // tree is disposed, we need to do something. + // lets remove ourselves from the listener. + SmartDevelopmentBridge.removeDebugBridgeChangeListener(ConnectionExplorerPanel.this); + SmartDevelopmentBridge.removeDeviceChangeListener(ConnectionExplorerPanel.this); + } + } + }); + + // if it doesn't have clients yet, it'll need to be manually expanded when it gets them. + //if (device.hasClients() == false) { + synchronized (mDevicesToExpand) { + mDevicesToExpand.add(device); + } // } } @Override - public void deviceDisconnected(IDevice device) { + public void deviceDisconnected(IDevice device) + { mDevicesList.remove( device ); - exec(new Runnable() { - public void run() { - if (mTree.isDisposed() == false) { - // refresh all - mTreeViewer.refresh(); - - // notify the listener of a possible selection change. - notifyListeners(); - } else { - // tree is disposed, we need to do something. - // lets remove ourselves from the listener. - SmartDevelopmentBridge.removeDebugBridgeChangeListener(ConnectionExplorerPanel.this); - SmartDevelopmentBridge.removeDeviceChangeListener(ConnectionExplorerPanel.this); + exec(new Runnable() + { + public void run() + { + if (mTree.isDisposed() == false) + { + // refresh all + mTreeViewer.refresh(); + + // notify the listener of a possible selection change. + notifyListeners(); + } + else + { + // tree is disposed, we need to do something. + // lets remove ourselves from the listener. + SmartDevelopmentBridge.removeDebugBridgeChangeListener(ConnectionExplorerPanel.this); + SmartDevelopmentBridge.removeDeviceChangeListener(ConnectionExplorerPanel.this); } } }); @@ -1190,8 +1172,6 @@ public class ConnectionExplorerPanel extends Panel implements SmartDevelopmentBr @Override public void deviceChanged(IDevice device, int changeMask) { - // TODO Auto-generated method stub - } public ArrayList getDeviceList() @@ -1211,58 +1191,50 @@ public class ConnectionExplorerPanel extends Panel implements SmartDevelopmentBr } } - private void notifyListeners() { - // get the selection - TreeItem[] items = mTree.getSelection(); - -// Client client = null; - FileEntry file = null; - - if (items.length == 1) { - Object object = items[0].getData(); - if (object instanceof FileEntry) { - file = (FileEntry)object; - } + private void notifyListeners() + { + // get the selection + TreeItem[] items = mTree.getSelection(); + + FileEntry file = null; + + if (items.length == 1) + { + Object object = items[0].getData(); + if (object instanceof FileEntry) + { + file = (FileEntry)object; + } } - - notifyListeners(file); - } - - private void notifyListeners(FileEntry file) { - if( file!= null) - { - IDevice device = file.getFileListingService().getDevice(); - if( mCurrentDevice != device ) - { - mCurrentDevice = device; + + notifySelectionListeners(file); + } + + private void notifySelectionListeners(FileEntry file) + { + if( file!= null) + { + IDevice device = file.getFileListingService().getDevice(); + if( mCurrentDevice != device ) + { + mCurrentDevice = device; } - } - else + } + else { mCurrentDevice = null; } - - ConnectionPlugin.getDefault().setCurrentDevice(mCurrentDevice); -// if (selectedDevice != mCurrentDevice) { -// mCurrentDevice = selectedDevice; -// - for (ISelectionListener listener : mListeners) { - // notify the listener with a try/catch-all to make sure this thread won't die - // because of an uncaught exception before all the listeners were notified. - try { - listener.selectionChanged( file ); - } catch (Exception e) { - } - } -// } + + ConnectionPlugin.getDefault().setCurrentDevice(mCurrentDevice); + ConnectionPlugin.getDefault().notifySelectionListeners(file); } public void addSelectionListener(ISelectionListener listener) { - mListeners.add(listener); + ConnectionPlugin.getDefault().addSelectionListener(listener); } public void removeSelectionListener(ISelectionListener listener) { - mListeners.remove(listener); + ConnectionPlugin.getDefault().removeSelectionListener(listener); } public void changeColumn( String infoName ) diff --git a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/Messages.java b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/explorer/Messages.java similarity index 95% rename from com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/Messages.java rename to com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/explorer/Messages.java index 256d8c8..f2f241e 100644 --- a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/Messages.java +++ b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/explorer/Messages.java @@ -16,7 +16,7 @@ * - S-Core Co., Ltd * */ -package com.samsung.slp.common.connection.ui; +package com.samsung.slp.common.connection.explorer; import java.util.MissingResourceException; import java.util.ResourceBundle; diff --git a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/messages.properties b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/explorer/messages.properties similarity index 100% rename from com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/messages.properties rename to com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/explorer/messages.properties diff --git a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/handler/ClearLogHandler.java b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/handler/ClearLogHandler.java new file mode 100644 index 0000000..e18d733 --- /dev/null +++ b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/handler/ClearLogHandler.java @@ -0,0 +1,45 @@ +/* + * {common-plugins} + * + * Copyright (C) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Hyunsik Noh + * Hoon Kang + * + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * - S-Core Co., Ltd + * + */ +package com.samsung.slp.common.connection.handler; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.handlers.HandlerUtil; + +import com.samsung.slp.common.conn.device.DeviceManager; +import com.samsung.slp.common.connection.ui.LogView; + +public class ClearLogHandler extends AbstractHandler { + private IViewPart part; + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + if( DeviceManager.getSelectedDevice() != null ) + { + part = (IViewPart) HandlerUtil.getActivePart(event); + LogView viewer = (LogView)part; + viewer.clearTable(); + viewer.getController().removeMsg(); + } + return null; + } + +} diff --git a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/handler/ExportLogHandler.java b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/handler/ExportLogHandler.java new file mode 100644 index 0000000..1a81290 --- /dev/null +++ b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/handler/ExportLogHandler.java @@ -0,0 +1,52 @@ +/* + * {common-plugins} + * + * Copyright (C) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Hyunsik Noh + * Hoon Kang + * + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * - S-Core Co., Ltd + * + */ +package com.samsung.slp.common.connection.handler; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.handlers.HandlerUtil; + +import com.samsung.slp.common.connection.log.LogController; +import com.samsung.slp.common.connection.ui.LogView; + +public class ExportLogHandler extends AbstractHandler { + private IViewPart part; + private LogView viewer; + private LogController controller; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + part = (IViewPart) HandlerUtil.getActivePart(event); + viewer = (LogView)part; + controller = viewer.getController(); + + if(controller == null ) + return null; + else + controller.exportLog(); + + return null; + } + + + +} diff --git a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/handler/ImportLogHandler.java b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/handler/ImportLogHandler.java new file mode 100644 index 0000000..45476e9 --- /dev/null +++ b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/handler/ImportLogHandler.java @@ -0,0 +1,56 @@ +/* + * {common-plugins} + * + * Copyright (C) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Hyunsik Noh + * Hoon Kang + * + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * - S-Core Co., Ltd + * + */ +package com.samsung.slp.common.connection.handler; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.handlers.HandlerUtil; + +import java.io.IOException; + +import com.samsung.slp.common.connection.log.LogController; +import com.samsung.slp.common.connection.ui.LogView; + +public class ImportLogHandler extends AbstractHandler { + private IViewPart part; + private LogView viewer; + private LogController controller; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + part = (IViewPart) HandlerUtil.getActivePart(event); + viewer = (LogView)part; + controller = viewer.getController(); + + if(controller == null ) + return null; + else + try { + controller.importLog(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return null; + } + +} diff --git a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/log/LogController.java b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/log/LogController.java new file mode 100644 index 0000000..c5c8982 --- /dev/null +++ b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/log/LogController.java @@ -0,0 +1,815 @@ +/* + * {common-plugins} + * + * Copyright (C) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Hyunsik Noh + * Hoon Kang + * + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * - S-Core Co., Ltd + * + */ +package com.samsung.slp.common.connection.log; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.swt.SWT; +import org.eclipse.swt.SWTException; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Date; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import com.samsung.slp.common.connection.ui.LogView.LogColors; +import com.samsung.slp.sdblib.IDevice; +import com.samsung.slp.sdblib.Log; +import com.samsung.slp.sdblib.SdbShellProcess; + + +public class LogController { + + private Table table; + + public String deviceId = null; + public String deviceType = null; + public IDevice device = null; + + private LogOuputReceiver receiver; + private BufferedReader logReader = null; + private static int STRING_BUFFER_LENGTH = 0; + + //all messages + private LogMessage[] allMessageArray; + private ArrayList filteredMessagesList = new ArrayList(); + private ArrayList newMessagesList = new ArrayList(); + + private LogMessageInfo lastMessageInfo = null; + private boolean mPendingAsyncRefresh = false; + private LogColors colors = null; + public boolean isSeletected = false; + + public LogFilter filter = null; + + private int countRemoveMsg = 0; + + /** Represents the oldest message in the buffer */ + private int startIndex = -1; + private String savePath; + private String loadPath; + + /** + * Represents the next usable item in the buffer to receive new message. + * This can be equal to startIndex, but when used startIndex will be + * incremented as well. + */ + private int endIndex = -1; + + +// ISession session = null; + + private static Pattern sLogPattern = Pattern.compile( + "^\\[\\s(\\d\\d-\\d\\d\\s\\d\\d:\\d\\d:\\d\\d\\.\\d+)" + //$NON-NLS-1$ + "\\s+(\\d*):[\\s]+([0-9a-fA-F]+)\\s([VDIWE])/(.*)\\]$"); //$NON-NLS-1$ + + private static Pattern colorPattern = Pattern.compile("\\[\\d+[mn]"); + + + public LogController( IDevice d, Table t, LogColors c ) + { + //make or find LogFilter related in Selected DeviceMachine + filter = new LogFilter(); + + device = d; + table = t; + colors = c; + } + + public void Start() + { + StartLogJob startLog = new StartLogJob("Starting LogViewer"); + startLog.schedule(); + } + + private class StartLogJob extends Job { + + public StartLogJob(String name) { + super(name); + } + + @Override + protected IStatus run(IProgressMonitor monitor) { + try { + startGetLog(monitor); + } catch (Exception e) { +// DialogUtil.openErrorDialog("LogUtil cannot run . \n " + e.getMessage()); + } finally { + monitor.done(); + } + return Status.OK_STATUS; + } + } + + + private void startGetLog(IProgressMonitor monitor )throws Exception + { + STRING_BUFFER_LENGTH = filter.getLineCount(); + allMessageArray = new LogMessage[STRING_BUFFER_LENGTH]; + + resetUI(false); + + if (device != null) { + // create a new output receiver + receiver = new LogOuputReceiver(); + + // start the logcat in a different thread + new Thread(device.getSerialNumber()) { //$NON-NLS-1$ + @Override + public void run() { + + if (receiver == null || receiver.isCancelled) { + // logcat was stopped/cancelled before the device became ready. + return; + } + + try { + executeLogUtil("dlogutil -v long *:v", receiver, device); //$NON-NLS-1$ + } catch (Exception e) { + Log.e("LogController", e); + } finally { + // at this point the command is terminated. + receiver = null; + + } + } + }.start(); + } + } + + public void resetUI(boolean inUiThread) { + + // the ui is static we just empty it. + if (table.isDisposed() == false) { + if (inUiThread) { + table.removeAll(); + } else { + Display d = table.getDisplay(); + + // run sync as we need to update right now. + d.syncExec(new Runnable() { + public void run() { + if (table.isDisposed() == false) { + table.removeAll(); + } + } + }); + } + } + } + + + public void stopGetLog(boolean inUiThread) { + if (receiver != null) { + receiver.isCancelled = true; + + // when the thread finishes, no one will reference that object + // and it'll be destroyed + receiver = null; + + // reset the content buffer + for (int i = 0 ; i < STRING_BUFFER_LENGTH; i++) { + allMessageArray[i] = null; + } + + // because it's a circular buffer, it's hard to know if + // the array is empty with both start/end at 0 or if it's full + // with both start/end at 0 as well. So to mean empty, we use -1 + startIndex = -1; + endIndex = -1; + + resetUI(inUiThread); + +// if(session != null) { +// session.close(); +// session = null; +// } + } + } + + private void executeLogUtil(String command, LogOuputReceiver rcvr, IDevice d) { + try { + ArrayList mArray = new ArrayList(); + String str = null; + SdbShellProcess logProc = d.executeShell(); + logProc.executeShellCommand(command); + InputStream input = logProc.getInputStream(); + logReader = new BufferedReader(new InputStreamReader(input)); + + while (true) { + + if (rcvr != null && rcvr.isCancelled()) { +// Log.v("ddms", "execute: cancelled"); + break; + } + + mArray.clear(); + + while((str = logReader.readLine()) != null) { + for( int i = 0; i 0) { + // at this point we've split all the lines. + // make the array + String[] lines = mArray.toArray(new String[mArray.size()]); + rcvr.processNewLines(lines); + } + + } + } catch (Exception e) { + } finally { + if (logReader != null) { + try { + logReader.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + logReader = null; + } +// Log.v("ddms", "execute: returning"); + } + } + + private final class LogOuputReceiver { + + public boolean isCancelled = false; + + public void processNewLines(String[] lines) { + if (isCancelled == false) { + processLogLines(lines); + } + } + + public boolean isCancelled() { + return isCancelled; + } + + } + + protected void processLogLines(String[] lines) { + // WARNING: this will not work if the string contains more line than + // the buffer holds. + + if (lines.length > STRING_BUFFER_LENGTH) { +// Log.e("LogCat", "Receiving more lines than STRING_BUFFER_LENGTH"); + } + + // parse the lines and create LogMessage that are stored in a temporary list + + synchronized (allMessageArray) { + for (String line : lines) { + + // ignore empty lines. + if (line.length() > 0) { + // check for header lines. + Matcher matcher = sLogPattern.matcher(line); + if (matcher.matches()) { + // this is a header line, parse the header and keep it around. + lastMessageInfo = new LogMessageInfo(); + + lastMessageInfo.time = matcher.group(1); + lastMessageInfo.pid = Integer.valueOf(matcher.group(2)); + if( matcher.group(4).length() > 0) + lastMessageInfo.type = String.valueOf(matcher.group(4).charAt(0)); + else + lastMessageInfo.type = " "; + lastMessageInfo.tag = matcher.group(5).trim(); + + } else { + + // This is not a header line. + // Create a new LogMessage and process it. + LogMessage mc = new LogMessage(); + + if (lastMessageInfo == null) { + // The first line of output wasn't preceded + // by a header line; make something up so + // that users of mc.data don't NPE. + lastMessageInfo = new LogMessageInfo(); + lastMessageInfo.time = "00-00 00:00:00.000 "; //$NON-NLS1$ + lastMessageInfo.pid = 0; + lastMessageInfo.type = "I"; + lastMessageInfo.tag = "No Tag"; //$NON-NLS1$ + } + + // If someone printed a log message with + // embedded '\n' characters, there will + // one header line followed by multiple text lines. + // Use the last header that we saw. + mc.data = lastMessageInfo; + + // tabs seem to display as only 1 tab so we replace the leading tabs + // by 4 spaces. + + mc.msg = line.replaceAll("\t", " "); //$NON-NLS-1$ //$NON-NLS-2$ +// Matcher matcher2 = sLogPattern2.matcher(mc.msg); +// if(matcher2.find()) +// mc.msg = matcher2.replaceAll(""); + + + // process the new LogMessage. + processNewMessage( mc ); + + + } + } + } + + // if we don't have a pending Runnable that will do the refresh, we ask the Display + // to run one in the UI thread. + if (mPendingAsyncRefresh == false) { + mPendingAsyncRefresh = true; + + try { + Display display = table.getDisplay(); + + // run in sync because this will update the buffer start/end indexes + display.asyncExec(new Runnable() { + public void run() { + + asyncRefresh(); + } + }); + } catch (SWTException e) { + // display is disposed, we're probably quitting. Let's stop. + + stopGetLog(false); + } + } + } + } + + private static class LogMessage { + public LogMessageInfo data; + public String msg; + + @Override + public String toString() { + return "[ " + data.time + " " //$NON-NLS-1$ + + data.pid + ": " + + data.pid + " " + + data.type + "/" //$NON-NLS-1$ + + data.tag + " ]\n" + //$NON-NLS-1$ + + msg; + } + } + + /** message data, separated from content for multi line messages */ + private static class LogMessageInfo { + public String type; + public int pid; + public String time; + public String tag; + } + + /** + * Refreshes the UI with new messages. + */ + private void asyncRefresh() { + if (table.isDisposed() == false) { + synchronized (allMessageArray) { + try { + // the circular buffer has been updated, let have the filter flush their + // display with the new messages. + flush(); + } finally { + // the pending refresh is done. + mPendingAsyncRefresh = false; + } + } + } else { + stopGetLog(true); + } + } + + /** + * Processes a new Message. + *

This adds the new message to the buffer, and gives it to the existing filters. + * @param newMessage + */ + private void processNewMessage( LogMessage newMessage ) { + + // compute the index where the message goes. + // was the buffer empty? + int messageIndex = -1; + if (startIndex == -1) { + messageIndex = startIndex = 0; + endIndex = 1; + } else { + messageIndex = endIndex; + + // check we aren't overwriting start + if (startIndex == endIndex) { + startIndex = (startIndex + 1) % STRING_BUFFER_LENGTH; + } + + // increment the next usable slot index + endIndex = (endIndex + 1) % STRING_BUFFER_LENGTH; + } + + LogMessage oldMessage = null; + if( allMessageArray[messageIndex] != null ) + oldMessage = allMessageArray[ messageIndex]; + // then add the new one + allMessageArray[messageIndex] = newMessage; + + synchronized (filteredMessagesList) { + if (oldMessage != null) + { + if( filteredMessagesList.size() > STRING_BUFFER_LENGTH) + { + int index = filteredMessagesList.indexOf(oldMessage); + if (index != -1) { + // TODO check that index will always be -1 or 0, as only the oldest message is ever removed. + filteredMessagesList.remove(index); + countRemoveMsg++; + } + } + } + } + + boolean filter = accept(newMessage); + if (filter) { + // at this point the message is accepted, we add it to the list + filteredMessagesList.add(newMessage); + newMessagesList.add( newMessage ); + } + + } + + + + /** + * Filters a message. + * @param logMessage the Message + * @return true if the message is accepted by the filter. + */ + boolean accept(LogMessage logMessage) { + if( logMessage == null ) + return false; + // do the regular filtering now + + String msgLogType = logMessage.data.type; + + if( filter.isLevelD() || filter.isLevelE() || filter.isLevelI() || filter.isLevelV() || filter.isLevelW() || filter.isUserlog()) + { + boolean result = false; + if( msgLogType.equals("V")) + { + result = result | filter.isLevelV(); + } + if( msgLogType.equals("D")) + { + result = result | filter.isLevelD(); + } + if( msgLogType.equals("I")) + { + result = result | filter.isLevelI(); + } + if( msgLogType.equals("W")) + { + result = result | filter.isLevelW(); + } + if( msgLogType.equals("E")) + { + result = result | filter.isLevelE(); + } + if( logMessage.data.tag.equals("")) + { + result = result | filter.isUserlog(); + } + if( !result ) + return result; + } + + if ((filter.getComboIndex() == 0)) + { + if( filter.getKeyword().equals("") ) + { + } + else + { + if( !filter.getKeyword().equals( Integer.toString(logMessage.data.pid))) + { + return false; + } + } + } + + if ((filter.getComboIndex() == 1)) + { + if( filter.getKeyword().equals("") ) + { + } + else + { +// if( !filter.getKeyword().equals( logMessage.data.tag)) + if( !logMessage.data.tag.contains( filter.getKeyword())) + { + return false; + } + } + } + + if ( filter.getComboIndex() == 2 ) + { + String msg = logMessage.msg; + if( filter.getKeyword().equals("") ) + { + } + else + { + if (!msg.contains( filter.getKeyword() )) + { + return false; + } + } + } + + return true; + } + /** + * Takes all the accepted messages and display them. + * This must be called from a UI thread. + */ + public void flush() { + + if( !isSeletected ) + return ; + // if we are not going to scroll, get the current first item being shown. +// int topIndex = table.getTopIndex(); + + // disable drawing + table.setRedraw(false); + + int totalCount = newMessagesList.size(); + + try { + // remove the items of the old messages. + for (int i = 0 ; i < countRemoveMsg && table.getItemCount() > 0 ; i++) { + table.remove(0); + } + + // add the new items + for (int i = 0 ; i < totalCount ; i++) { + LogMessage msg = newMessagesList.get(i); + addTableItem(msg); + } + } catch (SWTException e) { + // log the error and keep going. Content of the logcat table maybe unexpected + // but at least ddms won't crash. +// Log.e("LogFilter", e); + } + + // redraw + table.setRedraw(true); + + totalCount = table.getItemCount(); + + if (totalCount < 9) { + + table.setTopIndex( 0 ); + } + else + { + table.setTopIndex(totalCount-7); + } + + newMessagesList.clear(); + countRemoveMsg = 0; + + } + + synchronized public void addOldMsg() + { + ArrayList tmpMessages = new ArrayList(); + for( int i =0 ; i < filteredMessagesList.size() ; i++) + { + tmpMessages.add(filteredMessagesList.get( i )); + } + + for( int i =0 ; i < newMessagesList.size() ; i++) + { + tmpMessages.add(newMessagesList.get( i )); + } + + newMessagesList.clear(); + newMessagesList = tmpMessages; + flush(); + } + + private void addTableItem(LogMessage msg) { + TableItem item = new TableItem(table, SWT.NONE); + item.setText(0, msg.data.time); + item.setText(2, Integer.toString(msg.data.pid)); + item.setText(3, msg.data.tag); + item.setText(4, msg.msg); + // add the buffer index as data + item.setData(msg); + + if (msg.data.type.equals("I")) { + item.setText(1, "Info"); + item.setForeground(colors.infoColor); + } else if (msg.data.type.equals("D")) { + item.setText(1, "Debug"); + item.setForeground(colors.debugColor); + } else if (msg.data.type.equals("E")) { + item.setText(1,"Error"); + item.setForeground(colors.errorColor); + } else if (msg.data.type.equals("W")) { + item.setText(1, "Warning"); + item.setForeground(colors.warningColor); + } else if (msg.data.type.equals("V")) { + item.setText(1, "Verbose"); + item.setForeground(colors.verboseColor); + } + else { + item.setText(1," "); + item.setForeground(colors.verboseColor); + } + } + + synchronized public void refiltering() + { + table.removeAll(); + + filteredMessagesList.clear(); + ArrayList tmpMessages = new ArrayList(); + +// for( LogMessage logMsg : allMessageArray) + for( int i = 0; i < allMessageArray.length ; i++) + { + LogMessage logMsg = allMessageArray[i]; + if( accept(logMsg)) + { + filteredMessagesList.add( logMsg ); + tmpMessages.add( logMsg ); + } + } + + for( LogMessage nLogMsg : newMessagesList ) + { + if( accept( nLogMsg )) + { + filteredMessagesList.add( nLogMsg ); + tmpMessages.add( nLogMsg ); + } + } + newMessagesList.clear(); + newMessagesList = tmpMessages; + flush(); + } + + public boolean importLog() throws IOException { + + FileDialog dlg = new FileDialog(table.getParent().getShell(), SWT.SEARCH); + String fileName; + + dlg.setText("Import log..."); + Date date = new Date(); + dlg.setFileName( date.toString() + ".txt"); + String defaultPath = loadPath; + if (defaultPath == null) { + defaultPath = System.getProperty("user.home"); //$NON-NLS-1$ + } + dlg.setFilterPath(defaultPath); + dlg.setFilterNames(new String[] { + "Text Files (*.txt)" + }); + dlg.setFilterExtensions(new String[] { + "*.txt" + }); + + fileName = dlg.open(); + ArrayList array = new ArrayList(); + if (fileName != null) { + savePath = dlg.getFilterPath(); + BufferedReader bufReader = new BufferedReader( new FileReader(fileName)); + String tmpStr = null; + while((tmpStr = bufReader.readLine()) != null) + { + array.add( tmpStr ); + } + + + if (array.size() > 0) { + // at this point we've split all the lines. + // make the array + String[] lines = array.toArray(new String[array.size()]); + receiver.processNewLines(lines); + } + } + return true; + } + + public boolean exportLog() { + + FileDialog dlg = new FileDialog(table.getParent().getShell(), SWT.SAVE); + String fileName; + + dlg.setText("Export log..."); + Date date = new Date(); + dlg.setFileName( date.toString() + ".txt"); + String defaultPath = savePath; + if (defaultPath == null) { + defaultPath = System.getProperty("user.home"); //$NON-NLS-1$ + } + dlg.setFilterPath(defaultPath); + dlg.setFilterNames(new String[] { + "Text Files (*.txt)" + }); + dlg.setFilterExtensions(new String[] { + "*.txt" + }); + + fileName = dlg.open(); + if (fileName != null) { + savePath = dlg.getFilterPath(); + + int count = table.getItemCount(); + + // loop on the selection and output the file. + try { + FileWriter writer = new FileWriter(fileName); + + for (int i=0 ; i < count ; i++) + { + TableItem item = table.getItem(i); + LogMessage msg = (LogMessage)item.getData(); + String line = msg.toString(); + writer.write(line); + writer.write('\n'); + } + writer.flush(); + + } catch (IOException e) { + return false; + } + } + + return true; + } + + public void removeMsg() + { + for (int i = 0 ; i < STRING_BUFFER_LENGTH; i++) { + allMessageArray[i] = null; + } + filteredMessagesList.clear(); + newMessagesList.clear(); + } + + public void setSelected( boolean select ) + { + isSeletected = select; + } +} diff --git a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/log/LogFilter.java b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/log/LogFilter.java new file mode 100644 index 0000000..151c2e4 --- /dev/null +++ b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/log/LogFilter.java @@ -0,0 +1,111 @@ +/* + * {common-plugins} + * + * Copyright (C) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Hyunsik Noh + * Hoon Kang + * + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * - S-Core Co., Ltd + * + */ +package com.samsung.slp.common.connection.log; + +public class LogFilter { + + private boolean levelV = false; + private boolean levelD = false; + private boolean levelW = false; + private boolean levelI = false; + private boolean levelE = false; + private boolean userlog = false; + + private int lineCount = 2000; + + //0: For Pid + //1: For Tag + //2: For Message + private int comboIndex = 3; + + private String keyword = null; + + public boolean isLevelV() { + return levelV; + } + + public void setLevelV(boolean levelV) { + this.levelV = levelV; + } + + public boolean isLevelD() { + return levelD; + } + + public void setLevelD(boolean levelD) { + this.levelD = levelD; + } + + public boolean isLevelW() { + return levelW; + } + + public void setLevelW(boolean levelW) { + this.levelW = levelW; + } + + public boolean isLevelI() { + return levelI; + } + + public void setLevelI(boolean levelI) { + this.levelI = levelI; + } + + public boolean isLevelE() { + return levelE; + } + + public void setLevelE(boolean levelE) { + this.levelE = levelE; + } + + public int getLineCount() { + return lineCount; + } + + public void setLineCount(int lineCount) { + this.lineCount = lineCount; + } + + public int getComboIndex() { + return comboIndex; + } + + public void setComboIndex(int index) { + this.comboIndex = index; + } + + public String getKeyword() { + return keyword; + } + + public void setKeyword(String keyword) { + this.keyword = keyword; + } + + public boolean isUserlog() { + return userlog; + } + + public void setUserlog(boolean userlog) { + this.userlog = userlog; + } + +} diff --git a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/ConnectionExplorer.java b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/ConnectionExplorer.java index 96d702c..fab524e 100644 --- a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/ConnectionExplorer.java +++ b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/ConnectionExplorer.java @@ -36,6 +36,7 @@ import com.samsung.slp.common.connection.ConnectionPlugin; import com.samsung.slp.common.connection.ConnectionPlugin.ISelectionListener; import com.samsung.slp.common.connection.ddmuilib.FileDialogUtils; import com.samsung.slp.common.connection.ddmuilib.ImageLoader; +import com.samsung.slp.common.connection.explorer.ConnectionExplorerPanel; import com.samsung.slp.common.properties.InstallPathConfig; import com.samsung.slp.common.util.HostUtil; import com.samsung.slp.sdblib.FileListingService; @@ -80,6 +81,7 @@ public class ConnectionExplorer extends ViewPart implements ISelectionListener { private Action actionDelete; private MenuManager menuMgr; + private static ConnectionExplorer explorer; private FileEntry currentFileEntry; private static final String binaryMessage = "Emulator is not installed or install path is not valid."; @@ -91,6 +93,16 @@ public class ConnectionExplorer extends ViewPart implements ISelectionListener { public ConnectionExplorer() { } + + public static ConnectionExplorer gerDefault() + { + if( explorer != null ) + { + explorer = new ConnectionExplorer(); + } + + return explorer; + } @Override public void createPartControl(Composite parent) { @@ -114,7 +126,7 @@ public class ConnectionExplorer extends ViewPart implements ISelectionListener { top.setLayoutData( gridData ); top.setLayout( gridLayout ); - createToolBar( top, gridData ); + createToolBar( top, gridData ); // Composite mid = new Composite( parent, SWT.NONE ); // mid.setLayoutData(new GridData()); diff --git a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/LogView.java b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/LogView.java new file mode 100644 index 0000000..f5a53da --- /dev/null +++ b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/LogView.java @@ -0,0 +1,487 @@ +/* + * {common-plugins} + * + * Copyright (C) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Hyunsik Noh + * Hoon Kang + * + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * - S-Core Co., Ltd + * + */ +package com.samsung.slp.common.connection.ui; + +import java.util.HashMap; +import java.util.Iterator; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.part.ViewPart; + +import com.samsung.slp.common.connection.ConnectionPlugin; +import com.samsung.slp.common.connection.ConnectionPlugin.ISelectionListener; +import com.samsung.slp.common.connection.log.LogController; +import com.samsung.slp.sdblib.FileListingService.FileEntry; +import com.samsung.slp.sdblib.IDevice; +import com.samsung.slp.sdblib.SmartDevelopmentBridge; +import com.samsung.slp.sdblib.SmartDevelopmentBridge.IDeviceChangeListener; + +public class LogView extends ViewPart implements ISelectionListener, IDeviceChangeListener { + + private LogColors colors; + private Table table; + private Button buttonV; + private Button buttonD; + private Button buttonI; + private Button buttonW; + private Button buttonE; + private Button buttonSearch; + private Button buttonUser; + + private LogController controller = null; + private static HashMap controllerList = new HashMap(); + + @Override + public void createPartControl(Composite parent) + { + ConnectionPlugin.getDefault().addSelectionListener(this); + SmartDevelopmentBridge.getBridge().addDeviceChangeListener( this ); + setColor( parent ); + makecontroller( parent ); + } + + @Override + public void dispose() + { + super.dispose(); + ConnectionPlugin.getDefault().removeSelectionListener(this); + SmartDevelopmentBridge.getBridge().removeDeviceChangeListener( this ); + } + + + @Override + public void setFocus() { + } + + private void setColor( Composite parent ) + { + Display d=parent.getDisplay(); + colors = new LogColors(); + colors.infoColor=new Color(d, 0, 127, 0); + colors.debugColor = new Color(d, 0, 0, 127); + colors.errorColor = new Color(d, 255, 0, 0); + colors.warningColor = new Color(d, 255, 127, 0); + colors.verboseColor = new Color(d, 0, 0, 0); + } + + private void makecontroller( Composite parent ) + { + parent.setLayoutData(new GridData(GridData.FILL_VERTICAL)); + parent.setLayout(new GridLayout(1, false)); + + Composite top = new Composite( parent, SWT.NONE ); + top.setLayoutData(new GridData()); + top.setLayout(new GridLayout(6, false)); + + buttonV = new Button( top, SWT.CHECK); + buttonV.setText(" V "); + buttonV.setToolTipText("Verbose"); + buttonV.addSelectionListener(new SelectionListener(){ + + @Override + public void widgetSelected(SelectionEvent e) { + + if(buttonV.getSelection()) + controller.filter.setLevelV( true ); + else + controller.filter.setLevelV( false); + + controller.refiltering(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + + buttonD = new Button( top, SWT.CHECK); + buttonD.setText(" D "); + buttonD.setToolTipText("Debug"); + buttonD.addSelectionListener(new SelectionListener(){ + + @Override + public void widgetSelected(SelectionEvent e) { + if(buttonD.getSelection()) + controller.filter.setLevelD( true ); + else + controller.filter.setLevelD( false); + controller.refiltering(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + + buttonI = new Button( top, SWT.CHECK); + buttonI.setText(" I "); + buttonI.setToolTipText("Info"); + buttonI.addSelectionListener(new SelectionListener(){ + + @Override + public void widgetSelected(SelectionEvent e) { + if(buttonI.getSelection()) + controller.filter.setLevelI( true ); + else + controller.filter.setLevelI( false); + controller.refiltering(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + + + buttonW = new Button( top, SWT.CHECK); + buttonW.setText(" W "); + buttonW.setToolTipText("Warning"); + buttonW.addSelectionListener(new SelectionListener(){ + + @Override + public void widgetSelected(SelectionEvent e) { + if(buttonW.getSelection()) + controller.filter.setLevelW( true ); + else + controller.filter.setLevelW( false); + controller.refiltering(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + + + buttonE = new Button( top, SWT.CHECK); + buttonE.setText(" E "); + buttonE.setToolTipText("Error"); + buttonE.addSelectionListener(new SelectionListener(){ + + @Override + public void widgetSelected(SelectionEvent e) { + if(buttonE.getSelection()) + controller.filter.setLevelE( true ); + else + controller.filter.setLevelE( false); + controller.refiltering(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + + buttonUser = new Button( top, SWT.CHECK ); + buttonUser.setText(" UserLog"); + buttonUser.setToolTipText("User Defined Log"); + buttonUser.addSelectionListener(new SelectionListener(){ + + @Override + public void widgetSelected(SelectionEvent e) { + if(buttonUser.getSelection()) + controller.filter.setUserlog( true ); + else + controller.filter.setUserlog( false ); + controller.refiltering(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + + Composite mid = new Composite( parent, SWT.NONE ); + mid.setLayoutData(new GridData(GridData.FILL_BOTH)); + mid.setLayout(new FillLayout()); + + table = new Table( mid, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION); + table.setHeaderVisible( true ); + table.setLinesVisible( true ); + + TableColumn colTime = createTableColumn(table, "Time", SWT.LEFT, + "00-00 00:00:00.000" ); +// colTime.setResizable(false); + + TableColumn colLevel = createTableColumn(table, "Level", SWT.LEFT, + "Verbose"); +// colLevel.setResizable(false); + + TableColumn colPid = createTableColumn(table, "pid", SWT.LEFT, + "99999"); +// colPid.setResizable(false); + + TableColumn colTag = createTableColumn(table, "tag", SWT.LEFT, + "ABCDEFGHIJKLMN"); +// colTag.setResizable(false); + + TableColumn colMsg = createTableColumn(table, "Message", SWT.LEFT, + "mnopqrstuvwxyz0123456789"); + + Composite bottom = new Composite(parent, SWT.NONE); + bottom.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + bottom.setLayout(new GridLayout(3, false)); + + final Combo combo =new Combo( bottom, SWT.READ_ONLY ); + String comboItems[] = { "Pid", "Tag", "Message" }; + combo.setItems( comboItems ); + combo.setToolTipText("Keyword Search: Pid or Tag, Message"); + + final Text filterText = new Text(bottom, SWT.SINGLE | SWT.BORDER); + filterText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + filterText.setMessage( " Input Keyword "); + filterText.addKeyListener( new KeyListener(){ + + @Override + public void keyPressed(KeyEvent e) { + if( e.keyCode == 13) + { + int selection = combo.getSelectionIndex(); + if( selection != 0 && selection != 1) + return ; + + controller.filter.setComboIndex( selection ); + controller.filter.setKeyword( filterText.getText() ); + controller.refiltering(); + } + } + + @Override + public void keyReleased(KeyEvent e) { + } + }); + + buttonSearch = new Button(bottom, SWT.NONE); + buttonSearch.setText("Search"); + buttonSearch.addMouseListener(new MouseListener(){ + + @Override + public void mouseDoubleClick(MouseEvent e) { + } + + @Override + public void mouseDown(MouseEvent e) { + int selection = combo.getSelectionIndex(); + if( selection != 0 && selection != 1) + return ; + + controller.filter.setComboIndex( selection ); + controller.filter.setKeyword( filterText.getText() ); + controller.refiltering(); + } + + @Override + public void mouseUp(MouseEvent e) { + } + }); + + turnOnButtons( false ); + } + + public static TableColumn createTableColumn(Table parent, String header, + int style, String sample_text) { + + // create the column + TableColumn col = new TableColumn(parent, style); + + // if there is no pref store or the entry is missing, we use the sample + // text and pack the column. + // Otherwise we just read the width from the prefs and apply it. + col.setText(sample_text); + col.pack(); + + // set the header + col.setText(header); + + return col; + } + + public void selectLogController() + { + IDevice device = ConnectionPlugin.getDefault().getCurrentDevice(); + if( device == null ) + return ; + String deviceSn = device.getSerialNumber(); + + if((controller != null )&&(controller == controllerList.get(deviceSn))) + return ; + //clear the table + clearTable(); + Iterator ite = controllerList.values().iterator(); + if ( !controllerList.isEmpty()) + { + while(ite.hasNext()){ + controller = (LogController)ite.next(); + controller.setSelected(false); + } + } + + controller = controllerList.get(deviceSn); + if( controller == null){ + controller = new LogController( device, table, colors ); + controller.Start(); + controllerList.put( deviceSn, controller ); + controller.setSelected( true ); + } + else + { + controller.setSelected( true ); + controller.addOldMsg(); + } + + turnOnButtons( true ); + resetButtons( controller ); + } + + public LogController getController() { + return controller; + } + + public void turnOnButtons( boolean on ) + { + buttonV.setEnabled(on); + buttonD.setEnabled(on); + buttonI.setEnabled(on); + buttonW.setEnabled(on); + buttonE.setEnabled(on); + buttonSearch.setEnabled(on); + buttonUser.setEnabled(on); + } + + public void resetButtons( LogController con ) + { + if( con == null ) + { + buttonV.setSelection( false); + buttonD.setSelection( false); + buttonI.setSelection( false); + buttonW.setSelection( false); + buttonE.setSelection( false); + buttonSearch.setSelection( false ); + buttonUser.setSelection( false ); + } + else + { + buttonV.setSelection( con.filter.isLevelV()); + buttonD.setSelection( con.filter.isLevelD()); + buttonI.setSelection( con.filter.isLevelI()); + buttonW.setSelection( con.filter.isLevelW()); + buttonE.setSelection( con.filter.isLevelE()); + buttonSearch.setSelection( true ); + buttonUser.setSelection( con.filter.isUserlog()); + } + } + + public void clearTable() + { + Display display = table.getDisplay(); + + display.asyncExec(new Runnable() { + public void run() { + + table.removeAll(); + table.setTopIndex( 0 ); + } + }); + } + + public class LogColors { + public Color infoColor; + public Color debugColor; + public Color errorColor; + public Color warningColor; + public Color verboseColor; + } + + @Override + public void selectionChanged(FileEntry selectedEntry) { + + if( selectedEntry != null) + { + selectLogController(); + } + + } + + @Override + public void deviceConnected(IDevice device) { + } + + @Override + public void deviceDisconnected(IDevice device) + { + clearTable(); + + if ( !controllerList.isEmpty()) + { + synchronized( controllerList ) + { + LogController controller = controllerList.get( device.getSerialNumber()); + if( controller != null ) + { + controller.removeMsg(); + controllerList.remove( device.getSerialNumber() ); + } + } + } + +// if ( !controllerList.isEmpty()) +// { +// synchronized( controllerList ) +// { +// CopyOnWriteArrayList deviceList = DeviceModelProvider.INSTANCE.getDevices(); +// Device device = deviceList.get(0); +// if( device != null ) +// { +// controller = controllerList.get( device.getDeviceId() ); +// if( controller == null) +// { +// return ; +// } +// else +// { +// controller.setSelected( true ); +// controller.addOldMsg(); +// } +// } +// } +// } + } + + @Override + public void deviceChanged(IDevice device, int changeMask) { + } +} diff --git a/com.samsung.slp.connection/plugin.xml b/com.samsung.slp.connection/plugin.xml index 27e696c..a6d3a97 100644 --- a/com.samsung.slp.connection/plugin.xml +++ b/com.samsung.slp.connection/plugin.xml @@ -28,7 +28,7 @@ - @@ -81,7 +81,7 @@ commandId="com.samsung.slp.common.conn.ui.command.ClearLog"> - + --> - - + --> @@ -127,7 +127,7 @@ - @@ -141,7 +141,7 @@ id="com.samsung.slp.common.conn.ui.LogView"> - + --> diff --git a/com.samsung.slp.connection/src/com/samsung/slp/common/conn/Activator.java b/com.samsung.slp.connection/src/com/samsung/slp/common/conn/Activator.java index 564946a..515fd2c 100644 --- a/com.samsung.slp.connection/src/com/samsung/slp/common/conn/Activator.java +++ b/com.samsung.slp.connection/src/com/samsung/slp/common/conn/Activator.java @@ -39,7 +39,6 @@ public class Activator extends AbstractUIPlugin { // The plug-in ID public static final String PLUGIN_ID = "com.samsung.slp.common.conn"; //$NON-NLS-1$ - public static final String ID_LOGS_VIEW= "com.samsung.slp.common.conn.ui.LogView"; //$NON-NLS-1$ public static final String ID_CONNECTIONS_VIEW= "com.samsung.slp.common.conn.ui.DeviceView"; //$NON-NLS-1$ public static int OS; -- 2.7.4