From 9da374819b803d43856f00cc3583b604d5b6a6ae Mon Sep 17 00:00:00 2001 From: "hyunsik.noh" Date: Thu, 1 Dec 2011 13:54:49 +0900 Subject: [PATCH] [Title] add auto start in logview [Type] Enhancement [Module] common [Priority] Minor --- .../tizen/common/connection/log/LogPanel.java | 163 +++++++++++++-------- .../tizen/common/connection/log/LogTab.java | 7 +- 2 files changed, 106 insertions(+), 64 deletions(-) diff --git a/com.samsung.tizen.common.connection/src/com/samsung/tizen/common/connection/log/LogPanel.java b/com.samsung.tizen.common.connection/src/com/samsung/tizen/common/connection/log/LogPanel.java index 2437442..7139fa4 100644 --- a/com.samsung.tizen.common.connection/src/com/samsung/tizen/common/connection/log/LogPanel.java +++ b/com.samsung.tizen.common.connection/src/com/samsung/tizen/common/connection/log/LogPanel.java @@ -41,6 +41,7 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.TabFolder; import org.eclipse.swt.widgets.TabItem; @@ -55,8 +56,9 @@ import com.samsung.tizen.common.connection.ddmuilib.Panel; import com.samsung.tizen.sdblib.IDevice; import com.samsung.tizen.sdblib.Log.LogLevel; import com.samsung.tizen.sdblib.SmartDevelopmentBridge; +import com.samsung.tizen.sdblib.SmartDevelopmentBridge.IDeviceChangeListener; -public class LogPanel extends Panel { +public class LogPanel extends Panel implements IDeviceChangeListener { private String mDefaultLogSave; @@ -144,6 +146,8 @@ public class LogPanel extends Panel { } }); + SmartDevelopmentBridge sdbBridge = SmartDevelopmentBridge.getBridge(); + SmartDevelopmentBridge.addDeviceChangeListener(this); createTabs(); return null; @@ -157,9 +161,7 @@ public class LogPanel extends Panel { private void createTabs() { IDevice[] devices = SmartDevelopmentBridge.getBridge().getDevices(); for (IDevice device : devices) { - LogTab tab = new LogTab(device.getSerialNumber(), device, colors); - tabs.add(tab); - createTab(tab, tabCnt++, false); + LogTab tab = createTab(device, null); tab.setSupportsDelete(false); tab.setSupportsEdit(false); tab.startLogTab(); @@ -167,29 +169,40 @@ public class LogPanel extends Panel { } - private TabItem createTab(final LogTab tab, int index, boolean fillTable) { - TabItem item = null; - if (index != -1) { - item = new TabItem(folders, SWT.NONE, index); - } else { - item = new TabItem(folders, SWT.NONE); - } + private LogTab createTab(IDevice device, String tabName) { + + LogTab tab = null; + if( tabName == null) + tab = new LogTab(device.getSerialNumber(), device, colors); + else + tab = new LogTab( tabName, device, colors); + + TabItem item = new TabItem(folders, SWT.NONE, tabCnt++); + item.setText(tab.getFilterName()); - Composite top = new Composite(folders, SWT.NONE); - top.setLayoutData(new GridData(GridData.FILL_VERTICAL)); - top.setLayout(new GridLayout(1, false)); - item.setControl(top); + item.setControl(getTabControl(folders, tab)); + tab.setTab(item); + + folders.setSelection(item); + tabs.add(tab); + + return tab; + } + + private Control getTabControl(TabFolder tabFolder, final LogTab tab) { + // Create a composite and add four buttons to it - // top.setLayout(new FillLayout()); + Composite composite = new Composite(tabFolder, SWT.NONE); + composite.setLayoutData(new GridData(GridData.FILL_VERTICAL)); + composite.setLayout(new GridLayout(1, false)); - Composite mid = new Composite(top, SWT.NONE); + Composite mid = new Composite(composite, SWT.NONE); mid.setLayoutData(new GridData(GridData.FILL_BOTH)); mid.setLayout(new FillLayout()); final Table table = new Table(mid, SWT.MULTI | SWT.FULL_SELECTION); - tab.setWidgets(item, table); table.setHeaderVisible(true); table.setLinesVisible(true); @@ -238,7 +251,7 @@ public class LogPanel extends Panel { "abcdefghijklmnopqrstuvwxyz0123456789"); col.setResizable(false); - Composite bottom = new Composite(top, SWT.NONE); + Composite bottom = new Composite(composite, SWT.NONE); bottom.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); bottom.setLayout(new GridLayout(3, false)); @@ -263,9 +276,8 @@ public class LogPanel extends Panel { } }); - folders.setSelection(item); - - return item; + tab.setTable(table); + return composite; } @Override @@ -738,41 +750,41 @@ public class LogPanel extends Panel { * @return false if the saving failed. */ public boolean save() { -// synchronized (g) { - FileDialog dlg = new FileDialog(parent.getShell(), SWT.SAVE); - String fileName; - - dlg.setText("Save log..."); - dlg.setFileName("log.txt"); - String defaultPath = mDefaultLogSave; - 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) { - mDefaultLogSave = dlg.getFilterPath(); - - // loop on the selection and output the file. - try { - FileWriter writer = new FileWriter(fileName); - - for (TableItem item : getCurrentLogTab().getTable().getItems()) { - LogMessage msg = (LogMessage) item.getData(); - String line = msg.toString(); - writer.write(line); - writer.write('\n'); - } - writer.flush(); - - } catch (IOException e) { - return false; + // synchronized (g) { + FileDialog dlg = new FileDialog(parent.getShell(), SWT.SAVE); + String fileName; + + dlg.setText("Save log..."); + dlg.setFileName("log.txt"); + String defaultPath = mDefaultLogSave; + 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) { + mDefaultLogSave = dlg.getFilterPath(); + + // loop on the selection and output the file. + try { + FileWriter writer = new FileWriter(fileName); + + for (TableItem item : getCurrentLogTab().getTable().getItems()) { + LogMessage msg = (LogMessage) item.getData(); + String line = msg.toString(); + writer.write(line); + writer.write('\n'); } + writer.flush(); + + } catch (IOException e) { + return false; } -// } + } + // } return true; } @@ -792,9 +804,7 @@ public class LogPanel extends Panel { .getDevices()) { if (device.getSerialNumber().equals(dlg.getDevice())) { - LogTab newTab = new LogTab(device.getSerialNumber(), - device, colors); - newTab.setFilterName(dlg.getName()); + LogTab newTab = createTab( device, dlg.getName()); int filterMode = 0; @@ -810,8 +820,6 @@ public class LogPanel extends Panel { newTab.setFilterMode(filterMode); - tabs.add(newTab); - createTab(newTab, tabCnt++, false); newTab.startLogTab(); break; @@ -840,8 +848,8 @@ public class LogPanel extends Panel { public void editTab() { LogTab oldTab = getCurrentLogTab(); - if( !oldTab.supportsEdit()) - return ; + if (!oldTab.supportsEdit()) + return; AddViewDialog dlg = new AddViewDialog(parent.getShell(), oldTab); if (dlg.open()) { for (IDevice device : SmartDevelopmentBridge.getBridge() @@ -944,4 +952,35 @@ public class LogPanel extends Panel { tabCnt = 0; } + @Override + public void deviceConnected(IDevice device) { + // TODO Auto-generated method stub + + } + + @Override + public void deviceDisconnected(IDevice device) { + // TODO Auto-generated method stub + + } + + @Override + public void deviceChanged(final IDevice device, int changeMask) { + if (changeMask == 1) { + Display display = parent.getDisplay(); + display.asyncExec(new Runnable() { + public void run() { + if (folders.isDisposed() == false) { + LogTab tab = createTab(device, null); + tab.startLogTab(); + } else { + SmartDevelopmentBridge + .removeDeviceChangeListener(LogPanel.this); + } + } + }); + } + + } + } \ No newline at end of file diff --git a/com.samsung.tizen.common.connection/src/com/samsung/tizen/common/connection/log/LogTab.java b/com.samsung.tizen.common.connection/src/com/samsung/tizen/common/connection/log/LogTab.java index d59bdfc..56de40d 100644 --- a/com.samsung.tizen.common.connection/src/com/samsung/tizen/common/connection/log/LogTab.java +++ b/com.samsung.tizen.common.connection/src/com/samsung/tizen/common/connection/log/LogTab.java @@ -125,10 +125,13 @@ public class LogTab { * @param table * The Table object */ - public void setWidgets(TabItem tabItem, Table table) { - this.table = table; + public void setTab(TabItem tabItem) { this.tabItem = tabItem; } + + public void setTable(Table table) { + this.table = table; + } /** * Returns true if the filter is ready for ui. -- 2.7.4