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