2 * Copyright (C) 2007 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.ddms;
19 import com.android.ddmlib.AndroidDebugBridge;
20 import com.android.ddmlib.Client;
21 import com.android.ddmlib.ClientData;
22 import com.android.ddmlib.IDevice;
23 import com.android.ddmlib.Log;
24 import com.android.ddmlib.SyncException;
25 import com.android.ddmlib.SyncService;
26 import com.android.ddmlib.AndroidDebugBridge.IClientChangeListener;
27 import com.android.ddmlib.ClientData.IHprofDumpHandler;
28 import com.android.ddmlib.ClientData.MethodProfilingStatus;
29 import com.android.ddmlib.Log.ILogOutput;
30 import com.android.ddmlib.Log.LogLevel;
31 import com.android.ddmuilib.AllocationPanel;
32 import com.android.ddmuilib.DevicePanel;
33 import com.android.ddmuilib.EmulatorControlPanel;
34 import com.android.ddmuilib.HeapPanel;
35 import com.android.ddmuilib.ITableFocusListener;
36 import com.android.ddmuilib.ImageLoader;
37 import com.android.ddmuilib.InfoPanel;
38 import com.android.ddmuilib.NativeHeapPanel;
39 import com.android.ddmuilib.ScreenShotDialog;
40 import com.android.ddmuilib.SysinfoPanel;
41 import com.android.ddmuilib.TablePanel;
42 import com.android.ddmuilib.ThreadPanel;
43 import com.android.ddmuilib.DevicePanel.IUiSelectionListener;
44 import com.android.ddmuilib.actions.ToolItemAction;
45 import com.android.ddmuilib.explorer.DeviceExplorer;
46 import com.android.ddmuilib.handler.BaseFileHandler;
47 import com.android.ddmuilib.handler.MethodProfilingHandler;
48 import com.android.ddmuilib.log.event.EventLogPanel;
49 import com.android.ddmuilib.logcat.LogColors;
50 import com.android.ddmuilib.logcat.LogFilter;
51 import com.android.ddmuilib.logcat.LogPanel;
52 import com.android.ddmuilib.logcat.LogPanel.ILogFilterStorageManager;
54 import org.eclipse.jface.dialogs.MessageDialog;
55 import org.eclipse.jface.preference.IPreferenceStore;
56 import org.eclipse.jface.preference.PreferenceStore;
57 import org.eclipse.swt.SWT;
58 import org.eclipse.swt.SWTError;
59 import org.eclipse.swt.SWTException;
60 import org.eclipse.swt.dnd.Clipboard;
61 import org.eclipse.swt.events.ControlEvent;
62 import org.eclipse.swt.events.ControlListener;
63 import org.eclipse.swt.events.MenuAdapter;
64 import org.eclipse.swt.events.MenuEvent;
65 import org.eclipse.swt.events.SelectionAdapter;
66 import org.eclipse.swt.events.SelectionEvent;
67 import org.eclipse.swt.events.ShellEvent;
68 import org.eclipse.swt.events.ShellListener;
69 import org.eclipse.swt.graphics.Color;
70 import org.eclipse.swt.graphics.Font;
71 import org.eclipse.swt.graphics.FontData;
72 import org.eclipse.swt.graphics.Image;
73 import org.eclipse.swt.graphics.Rectangle;
74 import org.eclipse.swt.layout.FillLayout;
75 import org.eclipse.swt.layout.FormAttachment;
76 import org.eclipse.swt.layout.FormData;
77 import org.eclipse.swt.layout.FormLayout;
78 import org.eclipse.swt.layout.GridData;
79 import org.eclipse.swt.layout.GridLayout;
80 import org.eclipse.swt.widgets.Composite;
81 import org.eclipse.swt.widgets.Display;
82 import org.eclipse.swt.widgets.Event;
83 import org.eclipse.swt.widgets.Label;
84 import org.eclipse.swt.widgets.Listener;
85 import org.eclipse.swt.widgets.Menu;
86 import org.eclipse.swt.widgets.MenuItem;
87 import org.eclipse.swt.widgets.MessageBox;
88 import org.eclipse.swt.widgets.Sash;
89 import org.eclipse.swt.widgets.Shell;
90 import org.eclipse.swt.widgets.TabFolder;
91 import org.eclipse.swt.widgets.TabItem;
92 import org.eclipse.swt.widgets.ToolBar;
93 import org.eclipse.swt.widgets.ToolItem;
96 import java.util.ArrayList;
99 * This acts as the UI builder. This cannot be its own thread since this prevent using AWT in an
100 * SWT application. So this class mainly builds the ui, and manages communication between the panels
101 * when {@link IDevice} / {@link Client} selection changes.
103 public class UIThread implements IUiSelectionListener, IClientChangeListener {
105 * UI tab panel definitions. The constants here must match up with the array
106 * indices in mPanels. PANEL_CLIENT_LIST is a "virtual" panel representing
109 public static final int PANEL_CLIENT_LIST = -1;
111 public static final int PANEL_INFO = 0;
113 public static final int PANEL_THREAD = 1;
115 public static final int PANEL_HEAP = 2;
117 public static final int PANEL_NATIVE_HEAP = 3;
119 private static final int PANEL_ALLOCATIONS = 4;
121 private static final int PANEL_SYSINFO = 5;
123 private static final int PANEL_COUNT = 6;
125 /** Content is setup in the constructor */
126 private static TablePanel[] mPanels = new TablePanel[PANEL_COUNT];
128 private static final String[] mPanelNames = new String[] {
129 "Info", "Threads", "VM Heap", "Native Heap", "Allocation Tracker", "Sysinfo"
132 private static final String[] mPanelTips = new String[] {
133 "Client information", "Thread status", "VM heap status",
134 "Native heap status", "Allocation Tracker", "Sysinfo graphs"
137 private static final String PREFERENCE_LOGSASH =
138 "logSashLocation"; //$NON-NLS-1$
139 private static final String PREFERENCE_SASH =
140 "sashLocation"; //$NON-NLS-1$
142 private static final String PREFS_COL_TIME =
143 "logcat.time"; //$NON-NLS-1$
144 private static final String PREFS_COL_LEVEL =
145 "logcat.level"; //$NON-NLS-1$
146 private static final String PREFS_COL_PID =
147 "logcat.pid"; //$NON-NLS-1$
148 private static final String PREFS_COL_TAG =
149 "logcat.tag"; //$NON-NLS-1$
150 private static final String PREFS_COL_MESSAGE =
151 "logcat.message"; //$NON-NLS-1$
153 private static final String PREFS_FILTERS = "logcat.filter"; //$NON-NLS-1$
155 // singleton instance
156 private static UIThread mInstance = new UIThread();
159 private Display mDisplay;
161 // the table we show in the left-hand pane
162 private DevicePanel mDevicePanel;
164 private IDevice mCurrentDevice = null;
165 private Client mCurrentClient = null;
167 // status line at the bottom of the app window
168 private Label mStatusLine;
170 // some toolbar items we need to update
171 private ToolItem mTBShowThreadUpdates;
172 private ToolItem mTBShowHeapUpdates;
173 private ToolItem mTBHalt;
174 private ToolItem mTBCauseGc;
175 private ToolItem mTBDumpHprof;
176 private ToolItem mTBProfiling;
178 private final class FilterStorage implements ILogFilterStorageManager {
180 public LogFilter[] getFilterFromStore() {
181 String filterPrefs = PrefsDialog.getStore().getString(
184 // split in a string per filter
185 String[] filters = filterPrefs.split("\\|"); //$NON-NLS-1$
187 ArrayList<LogFilter> list =
188 new ArrayList<LogFilter>(filters.length);
190 for (String f : filters) {
191 if (f.length() > 0) {
192 LogFilter logFilter = new LogFilter();
193 if (logFilter.loadFromString(f)) {
199 return list.toArray(new LogFilter[list.size()]);
202 public void saveFilters(LogFilter[] filters) {
203 StringBuilder sb = new StringBuilder();
204 for (LogFilter f : filters) {
205 String filterString = f.toString();
206 sb.append(filterString);
210 PrefsDialog.getStore().setValue(PREFS_FILTERS, sb.toString());
213 public boolean requiresDefaultFilter() {
219 private LogPanel mLogPanel;
221 private ToolItemAction mCreateFilterAction;
222 private ToolItemAction mDeleteFilterAction;
223 private ToolItemAction mEditFilterAction;
224 private ToolItemAction mExportAction;
225 private ToolItemAction mClearAction;
227 private ToolItemAction[] mLogLevelActions;
228 private String[] mLogLevelIcons = {
229 "v.png", //$NON-NLS-1S
230 "d.png", //$NON-NLS-1S
231 "i.png", //$NON-NLS-1S
232 "w.png", //$NON-NLS-1S
233 "e.png", //$NON-NLS-1S
236 protected Clipboard mClipboard;
238 private MenuItem mCopyMenuItem;
240 private MenuItem mSelectAllMenuItem;
242 private TableFocusListener mTableListener;
244 private DeviceExplorer mExplorer = null;
245 private Shell mExplorerShell = null;
247 private EmulatorControlPanel mEmulatorPanel;
249 private EventLogPanel mEventLogPanel;
251 private Image mTracingStartImage;
253 private Image mTracingStopImage;
255 private ImageLoader mDdmUiLibLoader;
257 private class TableFocusListener implements ITableFocusListener {
259 private IFocusedTableActivator mCurrentActivator;
261 public void focusGained(IFocusedTableActivator activator) {
262 mCurrentActivator = activator;
263 if (mCopyMenuItem.isDisposed() == false) {
264 mCopyMenuItem.setEnabled(true);
265 mSelectAllMenuItem.setEnabled(true);
269 public void focusLost(IFocusedTableActivator activator) {
270 // if we move from one table to another, it's unclear
271 // if the old table lose its focus before the new
272 // one gets the focus, so we need to check.
273 if (activator == mCurrentActivator) {
275 if (mCopyMenuItem.isDisposed() == false) {
276 mCopyMenuItem.setEnabled(false);
277 mSelectAllMenuItem.setEnabled(false);
282 public void copy(Clipboard clipboard) {
283 if (mCurrentActivator != null) {
284 mCurrentActivator.copy(clipboard);
288 public void selectAll() {
289 if (mCurrentActivator != null) {
290 mCurrentActivator.selectAll();
296 * Handler for HPROF dumps.
297 * This will always prompt the user to save the HPROF file.
299 private class HProfHandler extends BaseFileHandler implements IHprofDumpHandler {
301 public HProfHandler(Shell parentShell) {
305 public void onEndFailure(final Client client, final String message) {
306 mDisplay.asyncExec(new Runnable() {
309 displayErrorFromUiThread(
310 "Unable to create HPROF file for application '%1$s'\n\n%2$s" +
311 "Check logcat for more information.",
312 client.getClientData().getClientDescription(),
313 message != null ? message + "\n\n" : "");
315 // this will make sure the dump hprof button is re-enabled for the
316 // current selection. as the client is finished dumping an hprof file
323 public void onSuccess(final String remoteFilePath, final Client client) {
324 mDisplay.asyncExec(new Runnable() {
326 final IDevice device = client.getDevice();
328 // get the sync service to pull the HPROF file
329 final SyncService sync = client.getDevice().getSyncService();
332 client.getClientData().getClientDescription() + ".hprof",
333 remoteFilePath, "Save HPROF file");
335 displayErrorFromUiThread(
336 "Unable to download HPROF file from device '%1$s'.",
337 device.getSerialNumber());
339 } catch (SyncException e) {
340 if (e.wasCanceled() == false) {
341 displayErrorFromUiThread(
342 "Unable to download HPROF file from device '%1$s'.\n\n%2$s",
343 device.getSerialNumber(), e.getMessage());
345 } catch (Exception e) {
346 displayErrorFromUiThread("Unable to download HPROF file from device '%1$s'.",
347 device.getSerialNumber());
350 // this will make sure the dump hprof button is re-enabled for the
351 // current selection. as the client is finished dumping an hprof file
358 public void onSuccess(final byte[] data, final Client client) {
359 mDisplay.asyncExec(new Runnable() {
361 promptAndSave(client.getClientData().getClientDescription() + ".hprof", data,
368 protected String getDialogTitle() {
369 return "HPROF Error";
375 * Generic constructor.
378 mPanels[PANEL_INFO] = new InfoPanel();
379 mPanels[PANEL_THREAD] = new ThreadPanel();
380 mPanels[PANEL_HEAP] = new HeapPanel();
381 if (PrefsDialog.getStore().getBoolean(PrefsDialog.SHOW_NATIVE_HEAP)) {
382 mPanels[PANEL_NATIVE_HEAP] = new NativeHeapPanel();
384 mPanels[PANEL_NATIVE_HEAP] = null;
386 mPanels[PANEL_ALLOCATIONS] = new AllocationPanel();
387 mPanels[PANEL_SYSINFO] = new SysinfoPanel();
391 * Get singleton instance of the UI thread.
393 public static UIThread getInstance() {
398 * Return the Display. Don't try this unless you're in the UI thread.
400 public Display getDisplay() {
404 public void asyncExec(Runnable r) {
405 if (mDisplay != null && mDisplay.isDisposed() == false) {
406 mDisplay.asyncExec(r);
410 /** returns the IPreferenceStore */
411 public IPreferenceStore getStore() {
412 return PrefsDialog.getStore();
416 * Create SWT objects and drive the user interface event loop.
417 * @param location location of the folder that contains ddms.
419 public void runUI(String ddmsParentLocation) {
420 Display.setAppName("ddms");
421 mDisplay = new Display();
422 final Shell shell = new Shell(mDisplay);
424 // create the image loaders for DDMS and DDMUILIB
425 mDdmUiLibLoader = ImageLoader.getDdmUiLibLoader();
427 shell.setImage(ImageLoader.getLoader(this.getClass()).loadImage(mDisplay,
428 "ddms-icon.png", //$NON-NLS-1$
431 Log.setLogOutput(new ILogOutput() {
432 public void printAndPromptLog(final LogLevel logLevel, final String tag,
433 final String message) {
434 Log.printLog(logLevel, tag, message);
435 // dialog box only run in UI thread..
436 mDisplay.asyncExec(new Runnable() {
438 Shell shell = mDisplay.getActiveShell();
439 if (logLevel == LogLevel.ERROR) {
440 MessageDialog.openError(shell, tag, message);
442 MessageDialog.openWarning(shell, tag, message);
448 public void printLog(LogLevel logLevel, String tag, String message) {
449 Log.printLog(logLevel, tag, message);
453 // set the handler for hprof dump
454 ClientData.setHprofDumpHandler(new HProfHandler(shell));
455 ClientData.setMethodProfilingHandler(new MethodProfilingHandler(shell));
457 // [try to] ensure ADB is running
458 // in the new SDK, adb is in the platform-tools, but when run from the command line
459 // in the Android source tree, then adb is next to ddms.
461 if (ddmsParentLocation != null && ddmsParentLocation.length() != 0) {
462 // check if there's a platform-tools folder
463 File platformTools = new File(new File(ddmsParentLocation).getParent(),
464 "platform-tools"); //$NON-NLS-1$
465 if (platformTools.isDirectory()) {
466 adbLocation = platformTools.getAbsolutePath() + File.separator + "adb"; //$NON-NLS-1$
468 adbLocation = ddmsParentLocation + File.separator + "adb"; //$NON-NLS-1$
471 adbLocation = "adb"; //$NON-NLS-1$
474 AndroidDebugBridge.init(true /* debugger support */);
475 AndroidDebugBridge.createBridge(adbLocation, true /* forceNewBridge */);
477 // we need to listen to client change to be notified of client status (profiling) change
478 AndroidDebugBridge.addClientChangeListener(this);
480 shell.setText("Dalvik Debug Monitor");
481 setConfirmClose(shell);
483 createWidgets(shell);
486 setSizeAndPosition(shell);
489 Log.d("ddms", "UI is up");
491 while (!shell.isDisposed()) {
492 if (!mDisplay.readAndDispatch())
495 mLogPanel.stopLogCat(true);
497 mDevicePanel.dispose();
498 for (TablePanel panel : mPanels) {
504 ImageLoader.dispose();
507 Log.d("ddms", "UI is down");
511 * Set the size and position of the main window from the preference, and
512 * setup listeners for control events (resize/move of the window)
514 private void setSizeAndPosition(final Shell shell) {
515 shell.setMinimumSize(400, 200);
517 // get the x/y and w/h from the prefs
518 PreferenceStore prefs = PrefsDialog.getStore();
519 int x = prefs.getInt(PrefsDialog.SHELL_X);
520 int y = prefs.getInt(PrefsDialog.SHELL_Y);
521 int w = prefs.getInt(PrefsDialog.SHELL_WIDTH);
522 int h = prefs.getInt(PrefsDialog.SHELL_HEIGHT);
524 // check that we're not out of the display area
525 Rectangle rect = mDisplay.getClientArea();
526 // first check the width/height
527 if (w > rect.width) {
529 prefs.setValue(PrefsDialog.SHELL_WIDTH, rect.width);
531 if (h > rect.height) {
533 prefs.setValue(PrefsDialog.SHELL_HEIGHT, rect.height);
535 // then check x. Make sure the left corner is in the screen
538 prefs.setValue(PrefsDialog.SHELL_X, rect.x);
539 } else if (x >= rect.x + rect.width) {
540 x = rect.x + rect.width - w;
541 prefs.setValue(PrefsDialog.SHELL_X, rect.x);
543 // then check y. Make sure the left corner is in the screen
546 prefs.setValue(PrefsDialog.SHELL_Y, rect.y);
547 } else if (y >= rect.y + rect.height) {
548 y = rect.y + rect.height - h;
549 prefs.setValue(PrefsDialog.SHELL_Y, rect.y);
552 // now we can set the location/size
553 shell.setBounds(x, y, w, h);
555 // add listener for resize/move
556 shell.addControlListener(new ControlListener() {
557 public void controlMoved(ControlEvent e) {
559 Rectangle rect = shell.getBounds();
560 // store in pref file
561 PreferenceStore prefs = PrefsDialog.getStore();
562 prefs.setValue(PrefsDialog.SHELL_X, rect.x);
563 prefs.setValue(PrefsDialog.SHELL_Y, rect.y);
566 public void controlResized(ControlEvent e) {
568 Rectangle rect = shell.getBounds();
569 // store in pref file
570 PreferenceStore prefs = PrefsDialog.getStore();
571 prefs.setValue(PrefsDialog.SHELL_WIDTH, rect.width);
572 prefs.setValue(PrefsDialog.SHELL_HEIGHT, rect.height);
578 * Set the size and position of the file explorer window from the
579 * preference, and setup listeners for control events (resize/move of
582 private void setExplorerSizeAndPosition(final Shell shell) {
583 shell.setMinimumSize(400, 200);
585 // get the x/y and w/h from the prefs
586 PreferenceStore prefs = PrefsDialog.getStore();
587 int x = prefs.getInt(PrefsDialog.EXPLORER_SHELL_X);
588 int y = prefs.getInt(PrefsDialog.EXPLORER_SHELL_Y);
589 int w = prefs.getInt(PrefsDialog.EXPLORER_SHELL_WIDTH);
590 int h = prefs.getInt(PrefsDialog.EXPLORER_SHELL_HEIGHT);
592 // check that we're not out of the display area
593 Rectangle rect = mDisplay.getClientArea();
594 // first check the width/height
595 if (w > rect.width) {
597 prefs.setValue(PrefsDialog.EXPLORER_SHELL_WIDTH, rect.width);
599 if (h > rect.height) {
601 prefs.setValue(PrefsDialog.EXPLORER_SHELL_HEIGHT, rect.height);
603 // then check x. Make sure the left corner is in the screen
606 prefs.setValue(PrefsDialog.EXPLORER_SHELL_X, rect.x);
607 } else if (x >= rect.x + rect.width) {
608 x = rect.x + rect.width - w;
609 prefs.setValue(PrefsDialog.EXPLORER_SHELL_X, rect.x);
611 // then check y. Make sure the left corner is in the screen
614 prefs.setValue(PrefsDialog.EXPLORER_SHELL_Y, rect.y);
615 } else if (y >= rect.y + rect.height) {
616 y = rect.y + rect.height - h;
617 prefs.setValue(PrefsDialog.EXPLORER_SHELL_Y, rect.y);
620 // now we can set the location/size
621 shell.setBounds(x, y, w, h);
623 // add listener for resize/move
624 shell.addControlListener(new ControlListener() {
625 public void controlMoved(ControlEvent e) {
627 Rectangle rect = shell.getBounds();
628 // store in pref file
629 PreferenceStore prefs = PrefsDialog.getStore();
630 prefs.setValue(PrefsDialog.EXPLORER_SHELL_X, rect.x);
631 prefs.setValue(PrefsDialog.EXPLORER_SHELL_Y, rect.y);
634 public void controlResized(ControlEvent e) {
636 Rectangle rect = shell.getBounds();
637 // store in pref file
638 PreferenceStore prefs = PrefsDialog.getStore();
639 prefs.setValue(PrefsDialog.EXPLORER_SHELL_WIDTH, rect.width);
640 prefs.setValue(PrefsDialog.EXPLORER_SHELL_HEIGHT, rect.height);
646 * Set the confirm-before-close dialog. TODO: enable/disable in prefs. TODO:
647 * is there any point in having this?
649 private void setConfirmClose(final Shell shell) {
653 shell.addListener(SWT.Close, new Listener() {
654 public void handleEvent(Event event) {
655 int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO;
656 MessageBox msgBox = new MessageBox(shell, style);
657 msgBox.setText("Confirm...");
658 msgBox.setMessage("Close DDM?");
659 event.doit = (msgBox.open() == SWT.YES);
665 * Create the menu bar and items.
667 private void createMenus(final Shell shell) {
669 Menu menuBar = new Menu(shell, SWT.BAR);
671 // create top-level items
672 MenuItem fileItem = new MenuItem(menuBar, SWT.CASCADE);
673 fileItem.setText("&File");
674 MenuItem editItem = new MenuItem(menuBar, SWT.CASCADE);
675 editItem.setText("&Edit");
676 MenuItem actionItem = new MenuItem(menuBar, SWT.CASCADE);
677 actionItem.setText("&Actions");
678 MenuItem deviceItem = new MenuItem(menuBar, SWT.CASCADE);
679 deviceItem.setText("&Device");
680 MenuItem helpItem = new MenuItem(menuBar, SWT.CASCADE);
681 helpItem.setText("&Help");
683 // create top-level menus
684 Menu fileMenu = new Menu(menuBar);
685 fileItem.setMenu(fileMenu);
686 Menu editMenu = new Menu(menuBar);
687 editItem.setMenu(editMenu);
688 Menu actionMenu = new Menu(menuBar);
689 actionItem.setMenu(actionMenu);
690 Menu deviceMenu = new Menu(menuBar);
691 deviceItem.setMenu(deviceMenu);
692 Menu helpMenu = new Menu(menuBar);
693 helpItem.setMenu(helpMenu);
697 // create File menu items
698 item = new MenuItem(fileMenu, SWT.NONE);
699 item.setText("&Preferences...");
700 item.addSelectionListener(new SelectionAdapter() {
702 public void widgetSelected(SelectionEvent e) {
703 PrefsDialog.run(shell);
707 item = new MenuItem(fileMenu, SWT.NONE);
708 item.setText("&Static Port Configuration...");
709 item.addSelectionListener(new SelectionAdapter() {
711 public void widgetSelected(SelectionEvent e) {
712 StaticPortConfigDialog dlg = new StaticPortConfigDialog(shell);
717 new MenuItem(fileMenu, SWT.SEPARATOR);
719 item = new MenuItem(fileMenu, SWT.NONE);
720 item.setText("E&xit\tCtrl-Q");
721 item.setAccelerator('Q' | (Main.isMac() ? SWT.COMMAND : SWT.CONTROL));
722 item.addSelectionListener(new SelectionAdapter() {
724 public void widgetSelected(SelectionEvent e) {
729 // create edit menu items
730 mCopyMenuItem = new MenuItem(editMenu, SWT.NONE);
731 mCopyMenuItem.setText("&Copy\tCtrl-C");
732 mCopyMenuItem.setAccelerator('C' | SWT.COMMAND);
733 mCopyMenuItem.addSelectionListener(new SelectionAdapter() {
735 public void widgetSelected(SelectionEvent e) {
736 mTableListener.copy(mClipboard);
740 new MenuItem(editMenu, SWT.SEPARATOR);
742 mSelectAllMenuItem = new MenuItem(editMenu, SWT.NONE);
743 mSelectAllMenuItem.setText("Select &All\tCtrl-A");
744 mSelectAllMenuItem.setAccelerator('A' | SWT.COMMAND);
745 mSelectAllMenuItem.addSelectionListener(new SelectionAdapter() {
747 public void widgetSelected(SelectionEvent e) {
748 mTableListener.selectAll();
752 // create Action menu items
753 // TODO: this should come with a confirmation dialog
754 final MenuItem actionHaltItem = new MenuItem(actionMenu, SWT.NONE);
755 actionHaltItem.setText("&Halt VM");
756 actionHaltItem.addSelectionListener(new SelectionAdapter() {
758 public void widgetSelected(SelectionEvent e) {
759 mDevicePanel.killSelectedClient();
763 final MenuItem actionCauseGcItem = new MenuItem(actionMenu, SWT.NONE);
764 actionCauseGcItem.setText("Cause &GC");
765 actionCauseGcItem.addSelectionListener(new SelectionAdapter() {
767 public void widgetSelected(SelectionEvent e) {
768 mDevicePanel.forceGcOnSelectedClient();
772 // configure Action items based on current state
773 actionMenu.addMenuListener(new MenuAdapter() {
775 public void menuShown(MenuEvent e) {
776 actionHaltItem.setEnabled(mTBHalt.getEnabled() && mCurrentClient != null);
777 actionCauseGcItem.setEnabled(mTBCauseGc.getEnabled() && mCurrentClient != null);
781 // create Device menu items
782 final MenuItem screenShotItem = new MenuItem(deviceMenu, SWT.NONE);
784 // The \tCtrl-S "keybinding text" here isn't right for the Mac - but
785 // it's stripped out and replaced by the proper keyboard accelerator
786 // text (e.g. the unicode symbol for the command key + S) anyway
787 // so it's fine to leave it there for the other platforms.
788 screenShotItem.setText("&Screen capture...\tCtrl-S");
789 screenShotItem.setAccelerator('S' | (Main.isMac() ? SWT.COMMAND : SWT.CONTROL));
790 screenShotItem.addSelectionListener(new SelectionAdapter() {
792 public void widgetSelected(SelectionEvent e) {
793 if (mCurrentDevice != null) {
794 ScreenShotDialog dlg = new ScreenShotDialog(shell);
795 dlg.open(mCurrentDevice);
800 new MenuItem(deviceMenu, SWT.SEPARATOR);
802 final MenuItem explorerItem = new MenuItem(deviceMenu, SWT.NONE);
803 explorerItem.setText("File Explorer...");
804 explorerItem.addSelectionListener(new SelectionAdapter() {
806 public void widgetSelected(SelectionEvent e) {
807 createFileExplorer();
811 new MenuItem(deviceMenu, SWT.SEPARATOR);
813 final MenuItem processItem = new MenuItem(deviceMenu, SWT.NONE);
814 processItem.setText("Show &process status...");
815 processItem.addSelectionListener(new SelectionAdapter() {
817 public void widgetSelected(SelectionEvent e) {
818 DeviceCommandDialog dlg;
819 dlg = new DeviceCommandDialog("ps -x", "ps-x.txt", shell);
820 dlg.open(mCurrentDevice);
824 final MenuItem deviceStateItem = new MenuItem(deviceMenu, SWT.NONE);
825 deviceStateItem.setText("Dump &device state...");
826 deviceStateItem.addSelectionListener(new SelectionAdapter() {
828 public void widgetSelected(SelectionEvent e) {
829 DeviceCommandDialog dlg;
830 dlg = new DeviceCommandDialog("/system/bin/dumpstate /proc/self/fd/0",
831 "device-state.txt", shell);
832 dlg.open(mCurrentDevice);
836 final MenuItem appStateItem = new MenuItem(deviceMenu, SWT.NONE);
837 appStateItem.setText("Dump &app state...");
838 appStateItem.setEnabled(false);
839 appStateItem.addSelectionListener(new SelectionAdapter() {
841 public void widgetSelected(SelectionEvent e) {
842 DeviceCommandDialog dlg;
843 dlg = new DeviceCommandDialog("dumpsys", "app-state.txt", shell);
844 dlg.open(mCurrentDevice);
848 final MenuItem radioStateItem = new MenuItem(deviceMenu, SWT.NONE);
849 radioStateItem.setText("Dump &radio state...");
850 radioStateItem.addSelectionListener(new SelectionAdapter() {
852 public void widgetSelected(SelectionEvent e) {
853 DeviceCommandDialog dlg;
854 dlg = new DeviceCommandDialog(
855 "cat /data/logs/radio.4 /data/logs/radio.3"
856 + " /data/logs/radio.2 /data/logs/radio.1"
857 + " /data/logs/radio",
858 "radio-state.txt", shell);
859 dlg.open(mCurrentDevice);
863 final MenuItem logCatItem = new MenuItem(deviceMenu, SWT.NONE);
864 logCatItem.setText("Run &logcat...");
865 logCatItem.addSelectionListener(new SelectionAdapter() {
867 public void widgetSelected(SelectionEvent e) {
868 DeviceCommandDialog dlg;
869 dlg = new DeviceCommandDialog("logcat '*:d jdwp:w'", "log.txt",
871 dlg.open(mCurrentDevice);
875 // configure Action items based on current state
876 deviceMenu.addMenuListener(new MenuAdapter() {
878 public void menuShown(MenuEvent e) {
879 boolean deviceEnabled = mCurrentDevice != null;
880 screenShotItem.setEnabled(deviceEnabled);
881 explorerItem.setEnabled(deviceEnabled);
882 processItem.setEnabled(deviceEnabled);
883 deviceStateItem.setEnabled(deviceEnabled);
884 appStateItem.setEnabled(deviceEnabled);
885 radioStateItem.setEnabled(deviceEnabled);
886 logCatItem.setEnabled(deviceEnabled);
890 // create Help menu items
891 item = new MenuItem(helpMenu, SWT.NONE);
892 item.setText("&Contents...");
893 item.addSelectionListener(new SelectionAdapter() {
895 public void widgetSelected(SelectionEvent e) {
896 int style = SWT.APPLICATION_MODAL | SWT.OK;
897 MessageBox msgBox = new MessageBox(shell, style);
898 msgBox.setText("Help!");
899 msgBox.setMessage("Help wanted.");
904 new MenuItem(helpMenu, SWT.SEPARATOR);
906 item = new MenuItem(helpMenu, SWT.NONE);
907 item.setText("&About...");
908 item.addSelectionListener(new SelectionAdapter() {
910 public void widgetSelected(SelectionEvent e) {
911 AboutDialog dlg = new AboutDialog(shell);
916 // tell the shell to use this menu
917 shell.setMenuBar(menuBar);
921 * Create the widgets in the main application window. The basic layout is a
922 * two-panel sash, with a scrolling list of VMs on the left and detailed
923 * output for a single VM on the right.
925 private void createWidgets(final Shell shell) {
926 Color darkGray = shell.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY);
929 * Create three areas: tool bar, split panels, status line
931 shell.setLayout(new GridLayout(1, false));
934 final Composite panelArea = new Composite(shell, SWT.BORDER);
936 // make the panel area absorb all space
937 panelArea.setLayoutData(new GridData(GridData.FILL_BOTH));
940 mStatusLine = new Label(shell, SWT.NONE);
942 // make status line extend all the way across
943 mStatusLine.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
945 mStatusLine.setText("Initializing...");
948 * Configure the split-panel area.
950 final PreferenceStore prefs = PrefsDialog.getStore();
952 Composite topPanel = new Composite(panelArea, SWT.NONE);
953 final Sash sash = new Sash(panelArea, SWT.HORIZONTAL);
954 sash.setBackground(darkGray);
955 Composite bottomPanel = new Composite(panelArea, SWT.NONE);
957 panelArea.setLayout(new FormLayout());
959 createTopPanel(topPanel, darkGray);
960 createBottomPanel(bottomPanel);
963 FormData data = new FormData();
964 data.top = new FormAttachment(0, 0);
965 data.bottom = new FormAttachment(sash, 0);
966 data.left = new FormAttachment(0, 0);
967 data.right = new FormAttachment(100, 0);
968 topPanel.setLayoutData(data);
970 final FormData sashData = new FormData();
971 if (prefs != null && prefs.contains(PREFERENCE_LOGSASH)) {
972 sashData.top = new FormAttachment(0, prefs.getInt(
973 PREFERENCE_LOGSASH));
975 sashData.top = new FormAttachment(50,0); // 50% across
977 sashData.left = new FormAttachment(0, 0);
978 sashData.right = new FormAttachment(100, 0);
979 sash.setLayoutData(sashData);
981 data = new FormData();
982 data.top = new FormAttachment(sash, 0);
983 data.bottom = new FormAttachment(100, 0);
984 data.left = new FormAttachment(0, 0);
985 data.right = new FormAttachment(100, 0);
986 bottomPanel.setLayoutData(data);
988 // allow resizes, but cap at minPanelWidth
989 sash.addListener(SWT.Selection, new Listener() {
990 public void handleEvent(Event e) {
991 Rectangle sashRect = sash.getBounds();
992 Rectangle panelRect = panelArea.getClientArea();
993 int bottom = panelRect.height - sashRect.height - 100;
994 e.y = Math.max(Math.min(e.y, bottom), 100);
995 if (e.y != sashRect.y) {
996 sashData.top = new FormAttachment(0, e.y);
997 prefs.setValue(PREFERENCE_LOGSASH, e.y);
1003 // add a global focus listener for all the tables
1004 mTableListener = new TableFocusListener();
1006 // now set up the listener in the various panels
1007 mLogPanel.setTableFocusListener(mTableListener);
1008 mEventLogPanel.setTableFocusListener(mTableListener);
1009 for (TablePanel p : mPanels) {
1011 p.setTableFocusListener(mTableListener);
1015 mStatusLine.setText("");
1019 * Populate the tool bar.
1021 private void createDevicePanelToolBar(ToolBar toolBar) {
1022 Display display = toolBar.getDisplay();
1024 // add "show heap updates" button
1025 mTBShowHeapUpdates = new ToolItem(toolBar, SWT.CHECK);
1026 mTBShowHeapUpdates.setImage(mDdmUiLibLoader.loadImage(display,
1027 DevicePanel.ICON_HEAP, DevicePanel.ICON_WIDTH, DevicePanel.ICON_WIDTH, null));
1028 mTBShowHeapUpdates.setToolTipText("Show heap updates");
1029 mTBShowHeapUpdates.setEnabled(false);
1030 mTBShowHeapUpdates.addSelectionListener(new SelectionAdapter() {
1032 public void widgetSelected(SelectionEvent e) {
1033 if (mCurrentClient != null) {
1034 // boolean status = ((ToolItem)e.item).getSelection();
1035 // invert previous state
1036 boolean enable = !mCurrentClient.isHeapUpdateEnabled();
1037 mCurrentClient.setHeapUpdateEnabled(enable);
1039 e.doit = false; // this has no effect?
1044 // add "dump HPROF" button
1045 mTBDumpHprof = new ToolItem(toolBar, SWT.PUSH);
1046 mTBDumpHprof.setToolTipText("Dump HPROF file");
1047 mTBDumpHprof.setEnabled(false);
1048 mTBDumpHprof.setImage(mDdmUiLibLoader.loadImage(display,
1049 DevicePanel.ICON_HPROF, DevicePanel.ICON_WIDTH, DevicePanel.ICON_WIDTH, null));
1050 mTBDumpHprof.addSelectionListener(new SelectionAdapter() {
1052 public void widgetSelected(SelectionEvent e) {
1053 mDevicePanel.dumpHprof();
1055 // this will make sure the dump hprof button is disabled for the current selection
1056 // as the client is already dumping an hprof file
1061 // add "cause GC" button
1062 mTBCauseGc = new ToolItem(toolBar, SWT.PUSH);
1063 mTBCauseGc.setToolTipText("Cause an immediate GC");
1064 mTBCauseGc.setEnabled(false);
1065 mTBCauseGc.setImage(mDdmUiLibLoader.loadImage(display,
1066 DevicePanel.ICON_GC, DevicePanel.ICON_WIDTH, DevicePanel.ICON_WIDTH, null));
1067 mTBCauseGc.addSelectionListener(new SelectionAdapter() {
1069 public void widgetSelected(SelectionEvent e) {
1070 mDevicePanel.forceGcOnSelectedClient();
1074 new ToolItem(toolBar, SWT.SEPARATOR);
1076 // add "show thread updates" button
1077 mTBShowThreadUpdates = new ToolItem(toolBar, SWT.CHECK);
1078 mTBShowThreadUpdates.setImage(mDdmUiLibLoader.loadImage(display,
1079 DevicePanel.ICON_THREAD, DevicePanel.ICON_WIDTH, DevicePanel.ICON_WIDTH, null));
1080 mTBShowThreadUpdates.setToolTipText("Show thread updates");
1081 mTBShowThreadUpdates.setEnabled(false);
1082 mTBShowThreadUpdates.addSelectionListener(new SelectionAdapter() {
1084 public void widgetSelected(SelectionEvent e) {
1085 if (mCurrentClient != null) {
1086 // boolean status = ((ToolItem)e.item).getSelection();
1087 // invert previous state
1088 boolean enable = !mCurrentClient.isThreadUpdateEnabled();
1090 mCurrentClient.setThreadUpdateEnabled(enable);
1092 e.doit = false; // this has no effect?
1097 // add a start/stop method tracing
1098 mTracingStartImage = mDdmUiLibLoader.loadImage(display,
1099 DevicePanel.ICON_TRACING_START,
1100 DevicePanel.ICON_WIDTH, DevicePanel.ICON_WIDTH, null);
1101 mTracingStopImage = mDdmUiLibLoader.loadImage(display,
1102 DevicePanel.ICON_TRACING_STOP,
1103 DevicePanel.ICON_WIDTH, DevicePanel.ICON_WIDTH, null);
1104 mTBProfiling = new ToolItem(toolBar, SWT.PUSH);
1105 mTBProfiling.setToolTipText("Start Method Profiling");
1106 mTBProfiling.setEnabled(false);
1107 mTBProfiling.setImage(mTracingStartImage);
1108 mTBProfiling.addSelectionListener(new SelectionAdapter() {
1110 public void widgetSelected(SelectionEvent e) {
1111 mDevicePanel.toggleMethodProfiling();
1115 new ToolItem(toolBar, SWT.SEPARATOR);
1117 // add "kill VM" button; need to make this visually distinct from
1118 // the status update buttons
1119 mTBHalt = new ToolItem(toolBar, SWT.PUSH);
1120 mTBHalt.setToolTipText("Halt the target VM");
1121 mTBHalt.setEnabled(false);
1122 mTBHalt.setImage(mDdmUiLibLoader.loadImage(display,
1123 DevicePanel.ICON_HALT, DevicePanel.ICON_WIDTH, DevicePanel.ICON_WIDTH, null));
1124 mTBHalt.addSelectionListener(new SelectionAdapter() {
1126 public void widgetSelected(SelectionEvent e) {
1127 mDevicePanel.killSelectedClient();
1134 private void createTopPanel(final Composite comp, Color darkGray) {
1135 final PreferenceStore prefs = PrefsDialog.getStore();
1137 comp.setLayout(new FormLayout());
1139 Composite leftPanel = new Composite(comp, SWT.NONE);
1140 final Sash sash = new Sash(comp, SWT.VERTICAL);
1141 sash.setBackground(darkGray);
1142 Composite rightPanel = new Composite(comp, SWT.NONE);
1144 createLeftPanel(leftPanel);
1145 createRightPanel(rightPanel);
1147 FormData data = new FormData();
1148 data.top = new FormAttachment(0, 0);
1149 data.bottom = new FormAttachment(100, 0);
1150 data.left = new FormAttachment(0, 0);
1151 data.right = new FormAttachment(sash, 0);
1152 leftPanel.setLayoutData(data);
1154 final FormData sashData = new FormData();
1155 sashData.top = new FormAttachment(0, 0);
1156 sashData.bottom = new FormAttachment(100, 0);
1157 if (prefs != null && prefs.contains(PREFERENCE_SASH)) {
1158 sashData.left = new FormAttachment(0, prefs.getInt(
1161 // position the sash 380 from the right instead of x% (done by using
1162 // FormAttachment(x, 0)) in order to keep the sash at the same
1164 // from the left when the window is resized.
1165 // 380px is just enough to display the left table with no horizontal
1166 // scrollbar with the default font.
1167 sashData.left = new FormAttachment(0, 380);
1169 sash.setLayoutData(sashData);
1171 data = new FormData();
1172 data.top = new FormAttachment(0, 0);
1173 data.bottom = new FormAttachment(100, 0);
1174 data.left = new FormAttachment(sash, 0);
1175 data.right = new FormAttachment(100, 0);
1176 rightPanel.setLayoutData(data);
1178 final int minPanelWidth = 60;
1180 // allow resizes, but cap at minPanelWidth
1181 sash.addListener(SWT.Selection, new Listener() {
1182 public void handleEvent(Event e) {
1183 Rectangle sashRect = sash.getBounds();
1184 Rectangle panelRect = comp.getClientArea();
1185 int right = panelRect.width - sashRect.width - minPanelWidth;
1186 e.x = Math.max(Math.min(e.x, right), minPanelWidth);
1187 if (e.x != sashRect.x) {
1188 sashData.left = new FormAttachment(0, e.x);
1189 prefs.setValue(PREFERENCE_SASH, e.x);
1196 private void createBottomPanel(final Composite comp) {
1197 final PreferenceStore prefs = PrefsDialog.getStore();
1200 Display display = comp.getDisplay();
1201 mClipboard = new Clipboard(display);
1203 LogColors colors = new LogColors();
1205 colors.infoColor = new Color(display, 0, 127, 0);
1206 colors.debugColor = new Color(display, 0, 0, 127);
1207 colors.errorColor = new Color(display, 255, 0, 0);
1208 colors.warningColor = new Color(display, 255, 127, 0);
1209 colors.verboseColor = new Color(display, 0, 0, 0);
1211 // set the preferences names
1212 LogPanel.PREFS_TIME = PREFS_COL_TIME;
1213 LogPanel.PREFS_LEVEL = PREFS_COL_LEVEL;
1214 LogPanel.PREFS_PID = PREFS_COL_PID;
1215 LogPanel.PREFS_TAG = PREFS_COL_TAG;
1216 LogPanel.PREFS_MESSAGE = PREFS_COL_MESSAGE;
1218 comp.setLayout(new GridLayout(1, false));
1220 ToolBar toolBar = new ToolBar(comp, SWT.HORIZONTAL);
1222 mCreateFilterAction = new ToolItemAction(toolBar, SWT.PUSH);
1223 mCreateFilterAction.item.setToolTipText("Create Filter");
1224 mCreateFilterAction.item.setImage(mDdmUiLibLoader.loadImage(mDisplay,
1225 "add.png", //$NON-NLS-1$
1226 DevicePanel.ICON_WIDTH, DevicePanel.ICON_WIDTH, null));
1227 mCreateFilterAction.item.addSelectionListener(new SelectionAdapter() {
1229 public void widgetSelected(SelectionEvent e) {
1230 mLogPanel.addFilter();
1234 mEditFilterAction = new ToolItemAction(toolBar, SWT.PUSH);
1235 mEditFilterAction.item.setToolTipText("Edit Filter");
1236 mEditFilterAction.item.setImage(mDdmUiLibLoader.loadImage(mDisplay,
1237 "edit.png", //$NON-NLS-1$
1238 DevicePanel.ICON_WIDTH, DevicePanel.ICON_WIDTH, null));
1239 mEditFilterAction.item.addSelectionListener(new SelectionAdapter() {
1241 public void widgetSelected(SelectionEvent e) {
1242 mLogPanel.editFilter();
1246 mDeleteFilterAction = new ToolItemAction(toolBar, SWT.PUSH);
1247 mDeleteFilterAction.item.setToolTipText("Delete Filter");
1248 mDeleteFilterAction.item.setImage(mDdmUiLibLoader.loadImage(mDisplay,
1249 "delete.png", //$NON-NLS-1$
1250 DevicePanel.ICON_WIDTH, DevicePanel.ICON_WIDTH, null));
1251 mDeleteFilterAction.item.addSelectionListener(new SelectionAdapter() {
1253 public void widgetSelected(SelectionEvent e) {
1254 mLogPanel.deleteFilter();
1259 new ToolItem(toolBar, SWT.SEPARATOR);
1261 LogLevel[] levels = LogLevel.values();
1262 mLogLevelActions = new ToolItemAction[mLogLevelIcons.length];
1263 for (int i = 0 ; i < mLogLevelActions.length; i++) {
1264 String name = levels[i].getStringValue();
1265 final ToolItemAction newAction = new ToolItemAction(toolBar, SWT.CHECK);
1266 mLogLevelActions[i] = newAction;
1267 //newAction.item.setText(name);
1268 newAction.item.addSelectionListener(new SelectionAdapter() {
1270 public void widgetSelected(SelectionEvent e) {
1271 // disable the other actions and record current index
1272 for (int i = 0 ; i < mLogLevelActions.length; i++) {
1273 ToolItemAction a = mLogLevelActions[i];
1274 if (a == newAction) {
1277 // set the log level
1278 mLogPanel.setCurrentFilterLogLevel(i+2);
1280 a.setChecked(false);
1286 newAction.item.setToolTipText(name);
1287 newAction.item.setImage(mDdmUiLibLoader.loadImage(mDisplay,
1289 DevicePanel.ICON_WIDTH, DevicePanel.ICON_WIDTH, null));
1292 new ToolItem(toolBar, SWT.SEPARATOR);
1294 mClearAction = new ToolItemAction(toolBar, SWT.PUSH);
1295 mClearAction.item.setToolTipText("Clear Log");
1297 mClearAction.item.setImage(mDdmUiLibLoader.loadImage(mDisplay,
1298 "clear.png", //$NON-NLS-1$
1299 DevicePanel.ICON_WIDTH, DevicePanel.ICON_WIDTH, null));
1300 mClearAction.item.addSelectionListener(new SelectionAdapter() {
1302 public void widgetSelected(SelectionEvent e) {
1307 new ToolItem(toolBar, SWT.SEPARATOR);
1309 mExportAction = new ToolItemAction(toolBar, SWT.PUSH);
1310 mExportAction.item.setToolTipText("Export Selection As Text...");
1311 mExportAction.item.setImage(mDdmUiLibLoader.loadImage(mDisplay,
1312 "save.png", //$NON-NLS-1$
1313 DevicePanel.ICON_WIDTH, DevicePanel.ICON_WIDTH, null));
1314 mExportAction.item.addSelectionListener(new SelectionAdapter() {
1316 public void widgetSelected(SelectionEvent e) {
1324 // now create the log view
1325 mLogPanel = new LogPanel(colors, new FilterStorage(), LogPanel.FILTER_MANUAL);
1327 mLogPanel.setActions(mDeleteFilterAction, mEditFilterAction, mLogLevelActions);
1329 String colMode = prefs.getString(PrefsDialog.LOGCAT_COLUMN_MODE);
1330 if (PrefsDialog.LOGCAT_COLUMN_MODE_AUTO.equals(colMode)) {
1331 mLogPanel.setColumnMode(LogPanel.COLUMN_MODE_AUTO);
1334 String fontStr = PrefsDialog.getStore().getString(PrefsDialog.LOGCAT_FONT);
1335 if (fontStr != null) {
1337 FontData fdat = new FontData(fontStr);
1338 mLogPanel.setFont(new Font(display, fdat));
1339 } catch (IllegalArgumentException e) {
1340 // Looks like fontStr isn't a valid font representation.
1341 // We do nothing in this case, the logcat view will use the default font.
1342 } catch (SWTError e2) {
1343 // Looks like the Font() constructor failed.
1344 // We do nothing in this case, the logcat view will use the default font.
1348 mLogPanel.createPanel(comp);
1350 // and start the logcat
1351 mLogPanel.startLogCat(mCurrentDevice);
1355 * Create the contents of the left panel: a table of VMs.
1357 private void createLeftPanel(final Composite comp) {
1358 comp.setLayout(new GridLayout(1, false));
1359 ToolBar toolBar = new ToolBar(comp, SWT.HORIZONTAL | SWT.RIGHT | SWT.WRAP);
1360 toolBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
1361 createDevicePanelToolBar(toolBar);
1363 Composite c = new Composite(comp, SWT.NONE);
1364 c.setLayoutData(new GridData(GridData.FILL_BOTH));
1366 mDevicePanel = new DevicePanel(true /* showPorts */);
1367 mDevicePanel.createPanel(c);
1369 // add ourselves to the device panel selection listener
1370 mDevicePanel.addSelectionListener(this);
1374 * Create the contents of the right panel: tabs with VM information.
1376 private void createRightPanel(final Composite comp) {
1378 TabFolder tabFolder;
1380 comp.setLayout(new FillLayout());
1382 tabFolder = new TabFolder(comp, SWT.NONE);
1384 for (int i = 0; i < mPanels.length; i++) {
1385 if (mPanels[i] != null) {
1386 item = new TabItem(tabFolder, SWT.NONE);
1387 item.setText(mPanelNames[i]);
1388 item.setToolTipText(mPanelTips[i]);
1389 item.setControl(mPanels[i].createPanel(tabFolder));
1393 // add the emulator control panel to the folders.
1394 item = new TabItem(tabFolder, SWT.NONE);
1395 item.setText("Emulator Control");
1396 item.setToolTipText("Emulator Control Panel");
1397 mEmulatorPanel = new EmulatorControlPanel();
1398 item.setControl(mEmulatorPanel.createPanel(tabFolder));
1400 // add the event log panel to the folders.
1401 item = new TabItem(tabFolder, SWT.NONE);
1402 item.setText("Event Log");
1403 item.setToolTipText("Event Log");
1405 // create the composite that will hold the toolbar and the event log panel.
1406 Composite eventLogTopComposite = new Composite(tabFolder, SWT.NONE);
1407 item.setControl(eventLogTopComposite);
1408 eventLogTopComposite.setLayout(new GridLayout(1, false));
1410 // create the toolbar and the actions
1411 ToolBar toolbar = new ToolBar(eventLogTopComposite, SWT.HORIZONTAL);
1412 toolbar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
1414 ToolItemAction optionsAction = new ToolItemAction(toolbar, SWT.PUSH);
1415 optionsAction.item.setToolTipText("Opens the options panel");
1416 optionsAction.item.setImage(mDdmUiLibLoader.loadImage(comp.getDisplay(),
1417 "edit.png", //$NON-NLS-1$
1418 DevicePanel.ICON_WIDTH, DevicePanel.ICON_WIDTH, null));
1420 ToolItemAction clearAction = new ToolItemAction(toolbar, SWT.PUSH);
1421 clearAction.item.setToolTipText("Clears the event log");
1422 clearAction.item.setImage(mDdmUiLibLoader.loadImage(comp.getDisplay(),
1423 "clear.png", //$NON-NLS-1$
1424 DevicePanel.ICON_WIDTH, DevicePanel.ICON_WIDTH, null));
1426 new ToolItem(toolbar, SWT.SEPARATOR);
1428 ToolItemAction saveAction = new ToolItemAction(toolbar, SWT.PUSH);
1429 saveAction.item.setToolTipText("Saves the event log");
1430 saveAction.item.setImage(mDdmUiLibLoader.loadImage(comp.getDisplay(),
1431 "save.png", //$NON-NLS-1$
1432 DevicePanel.ICON_WIDTH, DevicePanel.ICON_WIDTH, null));
1434 ToolItemAction loadAction = new ToolItemAction(toolbar, SWT.PUSH);
1435 loadAction.item.setToolTipText("Loads an event log");
1436 loadAction.item.setImage(mDdmUiLibLoader.loadImage(comp.getDisplay(),
1437 "load.png", //$NON-NLS-1$
1438 DevicePanel.ICON_WIDTH, DevicePanel.ICON_WIDTH, null));
1440 ToolItemAction importBugAction = new ToolItemAction(toolbar, SWT.PUSH);
1441 importBugAction.item.setToolTipText("Imports a bug report");
1442 importBugAction.item.setImage(mDdmUiLibLoader.loadImage(comp.getDisplay(),
1443 "importBug.png", //$NON-NLS-1$
1444 DevicePanel.ICON_WIDTH, DevicePanel.ICON_WIDTH, null));
1446 // create the event log panel
1447 mEventLogPanel = new EventLogPanel();
1449 // set the external actions
1450 mEventLogPanel.setActions(optionsAction, clearAction, saveAction, loadAction,
1454 mEventLogPanel.createPanel(eventLogTopComposite);
1457 private void createFileExplorer() {
1458 if (mExplorer == null) {
1459 mExplorerShell = new Shell(mDisplay);
1462 mExplorerShell.setLayout(new GridLayout(1, false));
1465 ToolBar toolBar = new ToolBar(mExplorerShell, SWT.HORIZONTAL);
1466 toolBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
1468 ToolItemAction pullAction = new ToolItemAction(toolBar, SWT.PUSH);
1469 pullAction.item.setToolTipText("Pull File from Device");
1470 Image image = mDdmUiLibLoader.loadImage("pull.png", mDisplay); //$NON-NLS-1$
1471 if (image != null) {
1472 pullAction.item.setImage(image);
1474 // this is for debugging purpose when the icon is missing
1475 pullAction.item.setText("Pull"); //$NON-NLS-1$
1478 ToolItemAction pushAction = new ToolItemAction(toolBar, SWT.PUSH);
1479 pushAction.item.setToolTipText("Push file onto Device");
1480 image = mDdmUiLibLoader.loadImage("push.png", mDisplay); //$NON-NLS-1$
1481 if (image != null) {
1482 pushAction.item.setImage(image);
1484 // this is for debugging purpose when the icon is missing
1485 pushAction.item.setText("Push"); //$NON-NLS-1$
1488 ToolItemAction deleteAction = new ToolItemAction(toolBar, SWT.PUSH);
1489 deleteAction.item.setToolTipText("Delete");
1490 image = mDdmUiLibLoader.loadImage("delete.png", mDisplay); //$NON-NLS-1$
1491 if (image != null) {
1492 deleteAction.item.setImage(image);
1494 // this is for debugging purpose when the icon is missing
1495 deleteAction.item.setText("Delete"); //$NON-NLS-1$
1499 mExplorer = new DeviceExplorer();
1500 mExplorer.setActions(pushAction, pullAction, deleteAction);
1502 pullAction.item.addSelectionListener(new SelectionAdapter() {
1504 public void widgetSelected(SelectionEvent e) {
1505 mExplorer.pullSelection();
1508 pullAction.setEnabled(false);
1510 pushAction.item.addSelectionListener(new SelectionAdapter() {
1512 public void widgetSelected(SelectionEvent e) {
1513 mExplorer.pushIntoSelection();
1516 pushAction.setEnabled(false);
1518 deleteAction.item.addSelectionListener(new SelectionAdapter() {
1520 public void widgetSelected(SelectionEvent e) {
1521 mExplorer.deleteSelection();
1524 deleteAction.setEnabled(false);
1526 Composite parent = new Composite(mExplorerShell, SWT.NONE);
1527 parent.setLayoutData(new GridData(GridData.FILL_BOTH));
1529 mExplorer.createPanel(parent);
1530 mExplorer.switchDevice(mCurrentDevice);
1532 mExplorerShell.addShellListener(new ShellListener() {
1533 public void shellActivated(ShellEvent e) {
1537 public void shellClosed(ShellEvent e) {
1539 mExplorerShell = null;
1542 public void shellDeactivated(ShellEvent e) {
1546 public void shellDeiconified(ShellEvent e) {
1550 public void shellIconified(ShellEvent e) {
1555 mExplorerShell.pack();
1556 setExplorerSizeAndPosition(mExplorerShell);
1557 mExplorerShell.open();
1559 if (mExplorerShell != null) {
1560 mExplorerShell.forceActive();
1566 * Set the status line. TODO: make this a stack, so we can safely have
1567 * multiple things trying to set it all at once. Also specify an expiration?
1569 public void setStatusLine(final String str) {
1571 mDisplay.asyncExec(new Runnable() {
1573 doSetStatusLine(str);
1576 } catch (SWTException swte) {
1577 if (!mDisplay.isDisposed())
1582 private void doSetStatusLine(String str) {
1583 if (mStatusLine.isDisposed())
1586 if (!mStatusLine.getText().equals(str)) {
1587 mStatusLine.setText(str);
1589 // try { Thread.sleep(100); }
1590 // catch (InterruptedException ie) {}
1594 public void displayError(final String msg) {
1596 mDisplay.syncExec(new Runnable() {
1598 MessageDialog.openError(mDisplay.getActiveShell(), "Error",
1602 } catch (SWTException swte) {
1603 if (!mDisplay.isDisposed())
1608 private void enableButtons() {
1609 if (mCurrentClient != null) {
1610 mTBShowThreadUpdates.setSelection(mCurrentClient.isThreadUpdateEnabled());
1611 mTBShowThreadUpdates.setEnabled(true);
1612 mTBShowHeapUpdates.setSelection(mCurrentClient.isHeapUpdateEnabled());
1613 mTBShowHeapUpdates.setEnabled(true);
1614 mTBHalt.setEnabled(true);
1615 mTBCauseGc.setEnabled(true);
1617 ClientData data = mCurrentClient.getClientData();
1619 if (data.hasFeature(ClientData.FEATURE_HPROF)) {
1620 mTBDumpHprof.setEnabled(data.hasPendingHprofDump() == false);
1621 mTBDumpHprof.setToolTipText("Dump HPROF file");
1623 mTBDumpHprof.setEnabled(false);
1624 mTBDumpHprof.setToolTipText("Dump HPROF file (not supported by this VM)");
1627 if (data.hasFeature(ClientData.FEATURE_PROFILING)) {
1628 mTBProfiling.setEnabled(true);
1629 if (data.getMethodProfilingStatus() == MethodProfilingStatus.ON) {
1630 mTBProfiling.setToolTipText("Stop Method Profiling");
1631 mTBProfiling.setImage(mTracingStopImage);
1633 mTBProfiling.setToolTipText("Start Method Profiling");
1634 mTBProfiling.setImage(mTracingStartImage);
1637 mTBProfiling.setEnabled(false);
1638 mTBProfiling.setImage(mTracingStartImage);
1639 mTBProfiling.setToolTipText("Start Method Profiling (not supported by this VM)");
1642 // list is empty, disable these
1643 mTBShowThreadUpdates.setSelection(false);
1644 mTBShowThreadUpdates.setEnabled(false);
1645 mTBShowHeapUpdates.setSelection(false);
1646 mTBShowHeapUpdates.setEnabled(false);
1647 mTBHalt.setEnabled(false);
1648 mTBCauseGc.setEnabled(false);
1650 mTBDumpHprof.setEnabled(false);
1651 mTBDumpHprof.setToolTipText("Dump HPROF file");
1653 mTBProfiling.setEnabled(false);
1654 mTBProfiling.setImage(mTracingStartImage);
1655 mTBProfiling.setToolTipText("Start Method Profiling");
1660 * Sent when a new {@link IDevice} and {@link Client} are selected.
1661 * @param selectedDevice the selected device. If null, no devices are selected.
1662 * @param selectedClient The selected client. If null, no clients are selected.
1664 * @see IUiSelectionListener
1666 public void selectionChanged(IDevice selectedDevice, Client selectedClient) {
1667 if (mCurrentDevice != selectedDevice) {
1668 mCurrentDevice = selectedDevice;
1669 for (TablePanel panel : mPanels) {
1670 if (panel != null) {
1671 panel.deviceSelected(mCurrentDevice);
1675 mEmulatorPanel.deviceSelected(mCurrentDevice);
1676 mLogPanel.deviceSelected(mCurrentDevice);
1677 if (mEventLogPanel != null) {
1678 mEventLogPanel.deviceSelected(mCurrentDevice);
1681 if (mExplorer != null) {
1682 mExplorer.switchDevice(mCurrentDevice);
1686 if (mCurrentClient != selectedClient) {
1687 AndroidDebugBridge.getBridge().setSelectedClient(selectedClient);
1688 mCurrentClient = selectedClient;
1689 for (TablePanel panel : mPanels) {
1690 if (panel != null) {
1691 panel.clientSelected(mCurrentClient);
1699 public void clientChanged(Client client, int changeMask) {
1700 if ((changeMask & Client.CHANGE_METHOD_PROFILING_STATUS) ==
1701 Client.CHANGE_METHOD_PROFILING_STATUS) {
1702 if (mCurrentClient == client) {
1703 mDisplay.asyncExec(new Runnable() {
1705 // force refresh of the button enabled state.