• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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.traceview;
18 
19 import org.eclipse.jface.dialogs.Dialog;
20 import org.eclipse.jface.dialogs.IDialogConstants;
21 import org.eclipse.jface.viewers.ArrayContentProvider;
22 import org.eclipse.jface.viewers.ColumnLabelProvider;
23 import org.eclipse.jface.viewers.TableViewer;
24 import org.eclipse.jface.viewers.TableViewerColumn;
25 import org.eclipse.swt.SWT;
26 import org.eclipse.swt.layout.GridData;
27 import org.eclipse.swt.layout.GridLayout;
28 import org.eclipse.swt.widgets.Composite;
29 import org.eclipse.swt.widgets.Control;
30 import org.eclipse.swt.widgets.Shell;
31 
32 import java.util.HashMap;
33 import java.util.Map.Entry;
34 
35 public class PropertiesDialog extends Dialog {
36     private HashMap<String, String> mProperties;
37 
PropertiesDialog(Shell parent)38     public PropertiesDialog(Shell parent) {
39         super(parent);
40 
41         setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE);
42     }
43 
setProperties(HashMap<String, String> properties)44     public void setProperties(HashMap<String, String> properties) {
45         mProperties = properties;
46     }
47 
48     @Override
createButtonsForButtonBar(Composite parent)49     protected void createButtonsForButtonBar(Composite parent) {
50         createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
51     }
52 
53     @Override
createDialogArea(Composite parent)54     protected Control createDialogArea(Composite parent) {
55         Composite container = (Composite) super.createDialogArea(parent);
56         GridLayout gridLayout = new GridLayout(1, false);
57         gridLayout.marginWidth = 0;
58         gridLayout.marginHeight = 0;
59         gridLayout.horizontalSpacing = 0;
60         gridLayout.verticalSpacing = 0;
61         container.setLayout(gridLayout);
62 
63         TableViewer tableViewer = new TableViewer(container, SWT.HIDE_SELECTION
64                 | SWT.V_SCROLL | SWT.BORDER);
65         tableViewer.getTable().setLinesVisible(true);
66         tableViewer.getTable().setHeaderVisible(true);
67 
68         TableViewerColumn propertyColumn = new TableViewerColumn(tableViewer, SWT.NONE);
69         propertyColumn.getColumn().setText("Property");
70         propertyColumn.setLabelProvider(new ColumnLabelProvider() {
71             @Override
72             @SuppressWarnings("unchecked")
73             public String getText(Object element) {
74                 Entry<String, String> entry = (Entry<String, String>) element;
75                 return entry.getKey();
76             }
77         });
78         propertyColumn.getColumn().setWidth(400);
79 
80         TableViewerColumn valueColumn = new TableViewerColumn(tableViewer, SWT.NONE);
81         valueColumn.getColumn().setText("Value");
82         valueColumn.setLabelProvider(new ColumnLabelProvider() {
83             @Override
84             @SuppressWarnings("unchecked")
85             public String getText(Object element) {
86                 Entry<String, String> entry = (Entry<String, String>) element;
87                 return entry.getValue();
88             }
89         });
90         valueColumn.getColumn().setWidth(200);
91 
92         tableViewer.setContentProvider(new ArrayContentProvider());
93         tableViewer.setInput(mProperties.entrySet().toArray());
94 
95         GridData gridData = new GridData();
96         gridData.verticalAlignment = GridData.FILL;
97         gridData.horizontalAlignment = GridData.FILL;
98         gridData.grabExcessHorizontalSpace = true;
99         gridData.grabExcessVerticalSpace = true;
100         tableViewer.getControl().setLayoutData(gridData);
101 
102         return container;
103     }
104 }
105