Commit | Line | Data |
---|---|---|
12c155f5 | 1 | package org.eclipse.linuxtools.tmf.ui.parsers.wizards;\r |
c3c5c786 FC |
2 | \r |
3 | import java.io.File;\r | |
4 | import java.io.FileNotFoundException;\r | |
5 | import java.io.FileWriter;\r | |
6 | import java.io.IOException;\r | |
7 | import java.util.ArrayList;\r | |
8 | import java.util.Iterator;\r | |
9 | import java.util.List;\r | |
10 | \r | |
11 | import org.eclipse.jface.wizard.WizardPage;\r | |
12 | import org.eclipse.linuxtools.tmf.trace.ITmfTrace;\r | |
13 | import org.eclipse.linuxtools.tmf.ui.TmfUiPlugin;\r | |
7995b722 | 14 | import org.eclipse.linuxtools.tmf.ui.internal.Messages;\r |
c3c5c786 FC |
15 | import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomEventsTable;\r |
16 | import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomTraceDefinition;\r | |
7995b722 | 17 | import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomTraceDefinition.OutputColumn;\r |
c3c5c786 FC |
18 | import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomXmlTrace;\r |
19 | import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomXmlTraceDefinition;\r | |
c3c5c786 FC |
20 | import org.eclipse.swt.SWT;\r |
21 | import org.eclipse.swt.custom.SashForm;\r | |
22 | import org.eclipse.swt.custom.ScrolledComposite;\r | |
23 | import org.eclipse.swt.events.SelectionAdapter;\r | |
24 | import org.eclipse.swt.events.SelectionEvent;\r | |
25 | import org.eclipse.swt.graphics.Image;\r | |
26 | import org.eclipse.swt.layout.GridData;\r | |
27 | import org.eclipse.swt.layout.GridLayout;\r | |
28 | import org.eclipse.swt.widgets.Button;\r | |
29 | import org.eclipse.swt.widgets.Composite;\r | |
30 | import org.eclipse.swt.widgets.Text;\r | |
31 | \r | |
32 | public class CustomXmlParserOutputWizardPage extends WizardPage {\r | |
33 | \r | |
d7fcacc9 FC |
34 | private static final Image upImage = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/up_button.gif"); //$NON-NLS-1$\r |
35 | private static final Image downImage = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/down_button.gif"); //$NON-NLS-1$\r | |
c3c5c786 FC |
36 | private CustomXmlParserWizard wizard;\r |
37 | private CustomXmlTraceDefinition definition;\r | |
38 | ArrayList<Output> outputs = new ArrayList<Output>();\r | |
39 | Output messageOutput;\r | |
40 | Composite container;\r | |
41 | SashForm sash;\r | |
42 | Text timestampFormatText;\r | |
43 | Text timestampPreviewText;\r | |
44 | ScrolledComposite outputsScrolledComposite;\r | |
45 | Composite outputsContainer;\r | |
46 | ScrolledComposite inputScrolledComposite;\r | |
47 | Composite tableContainer;\r | |
48 | CustomEventsTable previewTable;\r | |
49 | File tmpFile;\r | |
50 | \r | |
51 | protected CustomXmlParserOutputWizardPage(CustomXmlParserWizard wizard) {\r | |
3b38ea61 | 52 | super("CustomParserOutputWizardPage"); //$NON-NLS-1$\r |
c3c5c786 | 53 | setTitle(wizard.inputPage.getTitle());\r |
3b38ea61 | 54 | setDescription(Messages.CustomXmlParserOutputWizardPage_description);\r |
c3c5c786 FC |
55 | this.wizard = wizard;\r |
56 | setPageComplete(false);\r | |
57 | }\r | |
58 | \r | |
d4011df2 FC |
59 | @Override\r |
60 | public void createControl(Composite parent) {\r | |
c3c5c786 FC |
61 | container = new Composite(parent, SWT.NULL);\r |
62 | container.setLayout(new GridLayout());\r | |
63 | \r | |
64 | sash = new SashForm(container, SWT.VERTICAL);\r | |
65 | sash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r | |
66 | sash.setBackground(sash.getDisplay().getSystemColor(SWT.COLOR_GRAY));\r | |
67 | \r | |
68 | outputsScrolledComposite = new ScrolledComposite(sash, SWT.V_SCROLL);\r | |
69 | outputsScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r | |
70 | outputsContainer = new Composite(outputsScrolledComposite, SWT.NONE);\r | |
71 | GridLayout outputsLayout = new GridLayout(4, false);\r | |
72 | outputsLayout.marginHeight = 10;\r | |
73 | outputsLayout.marginWidth = 0;\r | |
74 | outputsContainer.setLayout(outputsLayout);\r | |
75 | outputsScrolledComposite.setContent(outputsContainer);\r | |
76 | outputsScrolledComposite.setExpandHorizontal(true);\r | |
77 | outputsScrolledComposite.setExpandVertical(true);\r | |
78 | \r | |
79 | outputsContainer.layout();\r | |
80 | \r | |
81 | outputsScrolledComposite.setMinSize(outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-5);\r | |
82 | \r | |
83 | tableContainer = new Composite(sash, SWT.NONE);\r | |
84 | GridLayout tableLayout = new GridLayout();\r | |
85 | tableLayout.marginHeight = 0;\r | |
86 | tableLayout.marginWidth = 0;\r | |
87 | tableContainer.setLayout(tableLayout);\r | |
88 | previewTable = new CustomEventsTable(new CustomXmlTraceDefinition(), tableContainer, 0);\r | |
d7fcacc9 | 89 | previewTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r |
c3c5c786 FC |
90 | \r |
91 | if (wizard.definition != null) {\r | |
92 | loadDefinition(wizard.definition);\r | |
93 | }\r | |
94 | setControl(container);\r | |
95 | \r | |
96 | }\r | |
97 | \r | |
98 | @Override\r | |
99 | public void dispose() {\r | |
100 | previewTable.dispose();\r | |
101 | super.dispose();\r | |
102 | }\r | |
103 | \r | |
104 | private void loadDefinition(CustomTraceDefinition definition) {\r | |
105 | for (OutputColumn outputColumn : definition.outputs) {\r | |
106 | Output output = new Output(outputsContainer, outputColumn.name);\r | |
107 | outputs.add(output);\r | |
108 | }\r | |
109 | }\r | |
110 | \r | |
111 | /* (non-Javadoc)\r | |
112 | * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)\r | |
113 | */\r | |
114 | @Override\r | |
115 | public void setVisible(boolean visible) {\r | |
116 | if (visible) {\r | |
117 | this.definition = wizard.inputPage.getDefinition();\r | |
118 | List<String> outputNames = wizard.inputPage.getInputNames();\r | |
119 | \r | |
120 | // dispose outputs that have been removed in the input page\r | |
121 | Iterator<Output> iter = outputs.iterator();\r | |
122 | while (iter.hasNext()) {\r | |
123 | Output output = iter.next();\r | |
124 | boolean found = false;\r | |
125 | for (String name : outputNames) {\r | |
126 | if (output.name.equals(name)) {\r | |
127 | found = true;\r | |
128 | break;\r | |
129 | }\r | |
130 | }\r | |
131 | if (!found) {\r | |
132 | output.dispose();\r | |
133 | iter.remove();\r | |
134 | }\r | |
135 | }\r | |
136 | \r | |
137 | // create outputs that have been added in the input page\r | |
138 | for (String name : outputNames) {\r | |
139 | boolean found = false;\r | |
140 | for (Output output : outputs) {\r | |
141 | if (output.name.equals(name)) {\r | |
142 | found = true;\r | |
143 | break;\r | |
144 | }\r | |
145 | }\r | |
146 | if (!found) {\r | |
147 | outputs.add(new Output(outputsContainer, name));\r | |
148 | }\r | |
149 | }\r | |
150 | \r | |
151 | outputsContainer.layout();\r | |
152 | outputsScrolledComposite.setMinSize(outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-5);\r | |
153 | updatePreviewTable();\r | |
154 | if (sash.getSize().y > outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y + previewTable.getTable().getItemHeight()) {\r | |
155 | sash.setWeights(new int[] {outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y, sash.getSize().y - outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y});\r | |
156 | } else {\r | |
157 | sash.setWeights(new int[] {outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y, previewTable.getTable().getItemHeight()});\r | |
158 | }\r | |
159 | setPageComplete(true);\r | |
160 | } else {\r | |
161 | setPageComplete(false);\r | |
162 | }\r | |
163 | super.setVisible(visible);\r | |
164 | }\r | |
165 | \r | |
166 | private void moveBefore(Output moved) {\r | |
167 | int i = outputs.indexOf(moved);\r | |
168 | if (i > 0) {\r | |
169 | Output previous = outputs.get(i-1);\r | |
170 | moved.enabledButton.moveAbove(previous.enabledButton);\r | |
171 | moved.nameLabel.moveBelow(moved.enabledButton);\r | |
172 | moved.upButton.moveBelow(moved.nameLabel);\r | |
173 | moved.downButton.moveBelow(moved.upButton);\r | |
174 | outputs.add(i-1, outputs.remove(i));\r | |
175 | outputsContainer.layout();\r | |
176 | outputsScrolledComposite.setMinSize(outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-5);\r | |
177 | container.layout();\r | |
178 | updatePreviewTable();\r | |
179 | }\r | |
180 | }\r | |
181 | \r | |
182 | private void moveAfter(Output moved) {\r | |
183 | int i = outputs.indexOf(moved);\r | |
184 | if (i+1 < outputs.size()) {\r | |
185 | Output next = outputs.get(i+1);\r | |
186 | moved.enabledButton.moveBelow(next.downButton);\r | |
187 | moved.nameLabel.moveBelow(moved.enabledButton);\r | |
188 | moved.upButton.moveBelow(moved.nameLabel);\r | |
189 | moved.downButton.moveBelow(moved.upButton);\r | |
190 | outputs.add(i+1, outputs.remove(i));\r | |
191 | outputsContainer.layout();\r | |
192 | outputsScrolledComposite.setMinSize(outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, outputsContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-5);\r | |
193 | container.layout();\r | |
194 | updatePreviewTable();\r | |
195 | }\r | |
196 | }\r | |
197 | \r | |
198 | private void updatePreviewTable() {\r | |
199 | final int MAX_NUM_ENTRIES = 50;\r | |
200 | definition.outputs = extractOutputs();\r | |
201 | \r | |
202 | try {\r | |
3b38ea61 | 203 | tmpFile = TmfUiPlugin.getDefault().getStateLocation().addTrailingSeparator().append("customwizard.tmp").toFile(); //$NON-NLS-1$\r |
c3c5c786 FC |
204 | FileWriter writer = new FileWriter(tmpFile);\r |
205 | writer.write(wizard.inputPage.getInputText());\r | |
206 | writer.close();\r | |
207 | \r | |
12c155f5 | 208 | ITmfTrace<?> trace = new CustomXmlTrace(tmpFile.getName(), definition, tmpFile.getAbsolutePath(), MAX_NUM_ENTRIES);\r |
c3c5c786 FC |
209 | previewTable.dispose();\r |
210 | previewTable = new CustomEventsTable(definition, tableContainer, MAX_NUM_ENTRIES);\r | |
d7fcacc9 | 211 | previewTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r |
529ee6a9 | 212 | previewTable.setTrace(trace, true);\r |
c3c5c786 FC |
213 | } catch (FileNotFoundException e) {\r |
214 | e.printStackTrace();\r | |
215 | } catch (IOException e) {\r | |
216 | e.printStackTrace();\r | |
217 | }\r | |
218 | \r | |
219 | tableContainer.layout();\r | |
220 | container.layout();\r | |
221 | }\r | |
222 | \r | |
223 | public List<OutputColumn> extractOutputs() {\r | |
224 | int numColumns = 0;\r | |
225 | for (int i = 0; i < outputs.size(); i++) {\r | |
226 | if (outputs.get(i).enabledButton.getSelection()) {\r | |
227 | numColumns++;\r | |
228 | }\r | |
229 | }\r | |
230 | List<OutputColumn> outputColumns = new ArrayList<OutputColumn>(numColumns);\r | |
231 | numColumns = 0;\r | |
232 | for (int i = 0; i < outputs.size(); i++) {\r | |
233 | Output output = outputs.get(i);\r | |
234 | if (output.enabledButton.getSelection()) {\r | |
235 | OutputColumn column = new OutputColumn();\r | |
236 | column.name = output.nameLabel.getText();\r | |
237 | outputColumns.add(column); \r | |
238 | }\r | |
239 | }\r | |
240 | return outputColumns;\r | |
241 | }\r | |
242 | \r | |
243 | private class Output {\r | |
244 | String name;\r | |
245 | Button enabledButton;\r | |
246 | Text nameLabel;\r | |
247 | Button upButton;\r | |
248 | Button downButton;\r | |
249 | \r | |
250 | public Output(Composite parent, String name) {\r | |
251 | this.name = name;\r | |
252 | \r | |
253 | enabledButton = new Button(parent, SWT.CHECK);\r | |
3b38ea61 | 254 | enabledButton.setToolTipText(Messages.CustomXmlParserOutputWizardPage_visible);\r |
c3c5c786 FC |
255 | enabledButton.setSelection(true);\r |
256 | enabledButton.addSelectionListener(new SelectionAdapter() {\r | |
9ccc6d01 | 257 | @Override\r |
c3c5c786 FC |
258 | public void widgetSelected(SelectionEvent e) {\r |
259 | updatePreviewTable();\r | |
260 | }\r | |
261 | });\r | |
262 | if (messageOutput != null) {\r | |
263 | enabledButton.moveAbove(messageOutput.enabledButton);\r | |
264 | }\r | |
265 | \r | |
266 | nameLabel = new Text(parent, SWT.BORDER | SWT.READ_ONLY | SWT.SINGLE);\r | |
267 | nameLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));\r | |
268 | nameLabel.setText(name);\r | |
269 | nameLabel.moveBelow(enabledButton);\r | |
270 | \r | |
271 | upButton = new Button(parent, SWT.PUSH);\r | |
272 | upButton.setImage(upImage);\r | |
3b38ea61 | 273 | upButton.setToolTipText(Messages.CustomXmlParserOutputWizardPage_moveBefore);\r |
c3c5c786 | 274 | upButton.addSelectionListener(new SelectionAdapter() {\r |
9ccc6d01 | 275 | @Override\r |
c3c5c786 FC |
276 | public void widgetSelected(SelectionEvent e) {\r |
277 | moveBefore(Output.this);\r | |
278 | }\r | |
279 | });\r | |
280 | upButton.moveBelow(nameLabel);\r | |
281 | \r | |
282 | downButton = new Button(parent, SWT.PUSH);\r | |
283 | downButton.setImage(downImage);\r | |
3b38ea61 | 284 | downButton.setToolTipText(Messages.CustomXmlParserOutputWizardPage_moveAfter);\r |
c3c5c786 | 285 | downButton.addSelectionListener(new SelectionAdapter() {\r |
9ccc6d01 | 286 | @Override\r |
c3c5c786 FC |
287 | public void widgetSelected(SelectionEvent e) {\r |
288 | moveAfter(Output.this);\r | |
289 | }\r | |
290 | });\r | |
291 | downButton.moveBelow(upButton);\r | |
292 | }\r | |
293 | \r | |
294 | private void dispose() {\r | |
295 | enabledButton.dispose();\r | |
296 | nameLabel.dispose();\r | |
297 | upButton.dispose();\r | |
298 | downButton.dispose();\r | |
299 | }\r | |
300 | }\r | |
301 | \r | |
302 | public CustomXmlTraceDefinition getDefinition() {\r | |
303 | return definition;\r | |
304 | }\r | |
305 | \r | |
306 | }\r |