Commit | Line | Data |
---|---|---|
b0d3496e ASL |
1 | /*****************************************************************************\r |
2 | * Copyright (c) 2008 Intel Corporation.\r | |
3 | * All rights reserved. This program and the accompanying materials\r | |
4 | * are made available under the terms of the Eclipse Public License v1.0\r | |
5 | * which accompanies this distribution, and is available at\r | |
6 | * http://www.eclipse.org/legal/epl-v10.html\r | |
7 | *\r | |
8 | * Contributors:\r | |
9 | * Intel Corporation - Initial API and implementation\r | |
10 | *\r | |
11 | * $Id: ThreadFilterDialog.java,v 1.2 2008/03/05 17:31:07 ewchan Exp $ \r | |
12 | *****************************************************************************/\r | |
13 | \r | |
14 | package org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.dialogs;\r | |
15 | \r | |
16 | import org.eclipse.jface.dialogs.TitleAreaDialog;\r | |
17 | import org.eclipse.jface.viewers.CheckStateChangedEvent;\r | |
18 | import org.eclipse.jface.viewers.CheckboxTableViewer;\r | |
19 | import org.eclipse.jface.viewers.ICheckStateListener;\r | |
20 | import org.eclipse.jface.viewers.IStructuredContentProvider;\r | |
21 | import org.eclipse.jface.viewers.ITableLabelProvider;\r | |
22 | import org.eclipse.jface.viewers.LabelProvider;\r | |
23 | import org.eclipse.jface.viewers.Viewer;\r | |
24 | import org.eclipse.jface.viewers.ViewerComparator;\r | |
25 | import org.eclipse.jface.window.Window;\r | |
26 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.Messages;\r | |
27 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITmfTimeAnalysisEntry;\r | |
28 | import org.eclipse.swt.SWT;\r | |
29 | import org.eclipse.swt.graphics.Image;\r | |
30 | import org.eclipse.swt.layout.GridData;\r | |
31 | import org.eclipse.swt.widgets.Composite;\r | |
32 | import org.eclipse.swt.widgets.Control;\r | |
33 | import org.eclipse.swt.widgets.Shell;\r | |
34 | import org.eclipse.swt.widgets.Table;\r | |
35 | import org.eclipse.swt.widgets.TableColumn;\r | |
36 | \r | |
37 | public class TmfTimeFilterDialog extends TitleAreaDialog {\r | |
38 | private CheckboxTableViewer viewer;\r | |
39 | private Object[] threads;\r | |
40 | private boolean[] filter;\r | |
41 | private ViewContentProvider viewContentProvider;\r | |
42 | private TraceComparator viewTraceComparator;\r | |
43 | private ViewLabelProvider viewViewLabelProvider;\r | |
44 | \r | |
45 | public TmfTimeFilterDialog(Shell parentShell, Object[] threads,\r | |
46 | boolean[] filter) {\r | |
47 | super(parentShell);\r | |
48 | \r | |
49 | this.threads = threads;\r | |
50 | if (filter != null)\r | |
51 | this.filter = (boolean[]) filter.clone();\r | |
52 | \r | |
53 | viewContentProvider = new ViewContentProvider();\r | |
54 | viewTraceComparator = new TraceComparator();\r | |
55 | viewViewLabelProvider = new ViewLabelProvider();\r | |
56 | }\r | |
57 | \r | |
58 | public static boolean getTraceFilter(Shell parentShell, Object[] threads,\r | |
59 | boolean[] filter) {\r | |
60 | TmfTimeFilterDialog dlg = new TmfTimeFilterDialog(parentShell, threads,\r | |
61 | filter);\r | |
62 | if (dlg.open() != Window.OK)\r | |
63 | return false;\r | |
64 | \r | |
65 | boolean f[] = dlg.getFilter();\r | |
66 | if (java.util.Arrays.equals(f, filter))\r | |
67 | return false;\r | |
68 | for (int i = f.length - 1; i >= 0; i--)\r | |
69 | filter[i] = f[i];\r | |
70 | \r | |
71 | return true;\r | |
72 | }\r | |
73 | \r | |
b0d3496e ASL |
74 | protected Control createDialogArea(Composite parent) {\r |
75 | Composite composite = (Composite) super.createDialogArea(parent);\r | |
76 | \r | |
77 | viewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER\r | |
78 | | SWT.V_SCROLL);\r | |
79 | \r | |
80 | Table table = viewer.getTable();\r | |
81 | table.setLayoutData(new GridData(GridData.FILL_BOTH));\r | |
82 | table.setBackground(parent.getBackground());\r | |
83 | createColumns(table);\r | |
84 | \r | |
85 | //Assign providers to the viewer.\r | |
86 | viewer.setContentProvider(viewContentProvider);\r | |
87 | viewer.setComparator(viewTraceComparator);\r | |
88 | viewer.setLabelProvider(viewViewLabelProvider);\r | |
89 | \r | |
90 | viewer.setInput(new Object());\r | |
91 | \r | |
92 | viewer.addCheckStateListener(new ICheckStateListener() {\r | |
93 | public void checkStateChanged(CheckStateChangedEvent event) {\r | |
94 | Object o = event.getElement();\r | |
95 | for (int i = threads.length - 1; i >= 0; i--) {\r | |
96 | if (threads[i].equals(o))\r | |
97 | filter[i] = event.getChecked();\r | |
98 | }\r | |
99 | }\r | |
100 | });\r | |
101 | \r | |
102 | if (filter != null) {\r | |
103 | for (int i = 0; i < filter.length; i++)\r | |
104 | viewer.setChecked(threads[i], filter[i]);\r | |
105 | }\r | |
106 | \r | |
107 | setMessage(Messages._TRACE_FILTER_DESC);\r | |
108 | setTitle(Messages._TRACE_FILTER);\r | |
109 | setDialogHelpAvailable(false);\r | |
110 | setHelpAvailable(false);\r | |
111 | \r | |
112 | // setTitleImage(org.eclipse.hyades.trace.internal.ui.PDPluginImages.DESC_IMG_UI_WZ_EDITPROFSET\r | |
113 | // .createImage());\r | |
114 | \r | |
115 | return composite;\r | |
116 | }\r | |
117 | \r | |
118 | private void createColumns(Table table) {\r | |
119 | table.setHeaderVisible(true);\r | |
120 | \r | |
121 | String headers[] = { "", Messages._TRACE_ID, Messages._TRACE_NAME };\r | |
122 | int width[] = { 20, 80, 400 };\r | |
123 | \r | |
124 | for (int i = 0; i < headers.length; i++) {\r | |
125 | TableColumn tc = new TableColumn(table, SWT.NONE, i);\r | |
126 | tc.setResizable(true);\r | |
127 | tc.setText(headers[i]);\r | |
128 | tc.setWidth(width[i]);\r | |
129 | }\r | |
130 | }\r | |
131 | \r | |
b0d3496e ASL |
132 | protected void configureShell(Shell shell) {\r |
133 | super.configureShell(shell);\r | |
134 | shell.setText(Messages._EDIT_PROFILING_OPTIONS);\r | |
135 | }\r | |
136 | \r | |
137 | public boolean[] getFilter() {\r | |
138 | return filter;\r | |
139 | }\r | |
140 | \r | |
141 | /**\r | |
142 | * @param viewContentProvider\r | |
143 | */\r | |
144 | public void setViewContentProvider(ViewContentProvider viewContentProvider) {\r | |
145 | this.viewContentProvider = viewContentProvider;\r | |
146 | }\r | |
147 | \r | |
148 | /**\r | |
149 | * @param viewThreadComparator\r | |
150 | */\r | |
151 | public void setViewThreadComparator(TraceComparator viewThreadComparator) {\r | |
152 | this.viewTraceComparator = viewThreadComparator;\r | |
153 | }\r | |
154 | \r | |
155 | /**\r | |
156 | * @param viewViewLabelProvider\r | |
157 | */\r | |
158 | public void setViewViewLabelProvider(ViewLabelProvider viewViewLabelProvider) {\r | |
159 | this.viewViewLabelProvider = viewViewLabelProvider;\r | |
160 | }\r | |
161 | \r | |
162 | class ViewContentProvider implements IStructuredContentProvider {\r | |
163 | public void dispose() {\r | |
164 | }\r | |
165 | \r | |
166 | public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {\r | |
167 | }\r | |
168 | \r | |
169 | public Object[] getElements(Object input) {\r | |
170 | return threads;\r | |
171 | }\r | |
172 | }\r | |
173 | \r | |
174 | class ViewLabelProvider extends LabelProvider implements\r | |
175 | ITableLabelProvider {\r | |
b0d3496e ASL |
176 | public Image getImage(Object obj) {\r |
177 | return null;\r | |
178 | }\r | |
179 | \r | |
180 | public Image getColumnImage(Object element, int columnIndex) {\r | |
181 | return null;\r | |
182 | }\r | |
183 | \r | |
184 | public String getColumnText(Object element, int columnIndex) {\r | |
185 | // TODO: AA: Provide Label Provider externally\r | |
186 | ITmfTimeAnalysisEntry t = (ITmfTimeAnalysisEntry) element;\r | |
187 | \r | |
188 | if (columnIndex == 1)\r | |
189 | return String.valueOf(t.getId());\r | |
190 | else if (columnIndex == 2)\r | |
191 | return t.getName();\r | |
192 | else\r | |
193 | return "";\r | |
194 | }\r | |
195 | }\r | |
196 | \r | |
197 | class TraceComparator extends ViewerComparator {\r | |
b0d3496e ASL |
198 | public int compare(Viewer viewer, Object e1, Object e2) {\r |
199 | // TODO: AA: Provide comparator externally\r | |
200 | int id1 = ((ITmfTimeAnalysisEntry) e1).getId();\r | |
201 | int id2 = ((ITmfTimeAnalysisEntry) e2).getId();\r | |
202 | \r | |
203 | if (id1 == id2)\r | |
204 | return 0;\r | |
205 | \r | |
206 | return (id1 < id2) ? -1 : 1;\r | |
207 | // return 0;\r | |
208 | }\r | |
209 | }\r | |
210 | }\r |