• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
17 package com.android.ddmuilib;
18 
19 import com.android.ddmlib.Client;
20 import com.android.ddmlib.ClientData;
21 import com.android.ddmlib.AndroidDebugBridge.IClientChangeListener;
22 
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.swt.widgets.Control;
26 import org.eclipse.swt.widgets.Table;
27 import org.eclipse.swt.widgets.TableColumn;
28 import org.eclipse.swt.widgets.TableItem;
29 
30 /**
31  * Display client info in a two-column format.
32  */
33 public class InfoPanel extends TablePanel {
34     private Table mTable;
35     private TableColumn mCol2;
36 
37     private static final String mLabels[] = {
38         "DDM-aware?",
39         "App description:",
40         "VM version:",
41         "Process ID:",
42         "Supports Profiling Control:",
43         "Supports HPROF Control:",
44     };
45     private static final int ENT_DDM_AWARE          = 0;
46     private static final int ENT_APP_DESCR          = 1;
47     private static final int ENT_VM_VERSION         = 2;
48     private static final int ENT_PROCESS_ID         = 3;
49     private static final int ENT_SUPPORTS_PROFILING = 4;
50     private static final int ENT_SUPPORTS_HPROF     = 5;
51 
52     /**
53      * Create our control(s).
54      */
55     @Override
createControl(Composite parent)56     protected Control createControl(Composite parent) {
57         mTable = new Table(parent, SWT.MULTI | SWT.FULL_SELECTION);
58         mTable.setHeaderVisible(false);
59         mTable.setLinesVisible(false);
60 
61         TableColumn col1 = new TableColumn(mTable, SWT.RIGHT);
62         col1.setText("name");
63         mCol2 = new TableColumn(mTable, SWT.LEFT);
64         mCol2.setText("PlaceHolderContentForWidth");
65 
66         TableItem item;
67         for (int i = 0; i < mLabels.length; i++) {
68             item = new TableItem(mTable, SWT.NONE);
69             item.setText(0, mLabels[i]);
70             item.setText(1, "-");
71         }
72 
73         col1.pack();
74         mCol2.pack();
75 
76         return mTable;
77     }
78 
79     /**
80      * Sets the focus to the proper control inside the panel.
81      */
82     @Override
setFocus()83     public void setFocus() {
84         mTable.setFocus();
85     }
86 
87 
88     /**
89      * Sent when an existing client information changed.
90      * <p/>
91      * This is sent from a non UI thread.
92      * @param client the updated client.
93      * @param changeMask the bit mask describing the changed properties. It can contain
94      * any of the following values: {@link Client#CHANGE_PORT}, {@link Client#CHANGE_NAME}
95      * {@link Client#CHANGE_DEBUGGER_STATUS}, {@link Client#CHANGE_THREAD_MODE},
96      * {@link Client#CHANGE_THREAD_DATA}, {@link Client#CHANGE_HEAP_MODE},
97      * {@link Client#CHANGE_HEAP_DATA}, {@link Client#CHANGE_NATIVE_HEAP_DATA}
98      *
99      * @see IClientChangeListener#clientChanged(Client, int)
100      */
clientChanged(final Client client, int changeMask)101     public void clientChanged(final Client client, int changeMask) {
102         if (client == getCurrentClient()) {
103             if ((changeMask & Client.CHANGE_INFO) == Client.CHANGE_INFO) {
104                 if (mTable.isDisposed())
105                     return;
106 
107                 mTable.getDisplay().asyncExec(new Runnable() {
108                     public void run() {
109                         clientSelected();
110                     }
111                 });
112             }
113         }
114     }
115 
116 
117     /**
118      * Sent when a new device is selected. The new device can be accessed
119      * with {@link #getCurrentDevice()}
120      */
121     @Override
deviceSelected()122     public void deviceSelected() {
123         // pass
124     }
125 
126     /**
127      * Sent when a new client is selected. The new client can be accessed
128      * with {@link #getCurrentClient()}
129      */
130     @Override
clientSelected()131     public void clientSelected() {
132         if (mTable.isDisposed())
133             return;
134 
135         Client client = getCurrentClient();
136 
137         if (client == null) {
138             for (int i = 0; i < mLabels.length; i++) {
139                 TableItem item = mTable.getItem(i);
140                 item.setText(1, "-");
141             }
142         } else {
143             TableItem item;
144             String clientDescription, vmIdentifier, isDdmAware,
145                 pid;
146 
147             ClientData cd = client.getClientData();
148             synchronized (cd) {
149                 clientDescription = (cd.getClientDescription() != null) ?
150                         cd.getClientDescription() : "?";
151                 vmIdentifier = (cd.getVmIdentifier() != null) ?
152                         cd.getVmIdentifier() : "?";
153                 isDdmAware = cd.isDdmAware() ?
154                         "yes" : "no";
155                 pid = (cd.getPid() != 0) ?
156                         String.valueOf(cd.getPid()) : "?";
157             }
158 
159             item = mTable.getItem(ENT_APP_DESCR);
160             item.setText(1, clientDescription);
161             item = mTable.getItem(ENT_VM_VERSION);
162             item.setText(1, vmIdentifier);
163             item = mTable.getItem(ENT_DDM_AWARE);
164             item.setText(1, isDdmAware);
165             item = mTable.getItem(ENT_PROCESS_ID);
166             item.setText(1, pid);
167             item = mTable.getItem(ENT_SUPPORTS_PROFILING);
168             item.setText(1, Boolean.toString(cd.hasFeature(ClientData.FEATURE_PROFILING)));
169             item = mTable.getItem(ENT_SUPPORTS_HPROF);
170             item.setText(1, Boolean.toString(cd.hasFeature(ClientData.FEATURE_HPROF)));
171         }
172 
173         mCol2.pack();
174 
175         //Log.i("ddms", "InfoPanel: changed " + client);
176     }
177 
178     @Override
setTableFocusListener()179     protected void setTableFocusListener() {
180         addTableToFocusListener(mTable);
181     }
182 }
183 
184