1 package org
.eclipse
.linuxtools
.tmf
.ui
.wizards
;
4 import java
.io
.FileNotFoundException
;
5 import java
.io
.FileWriter
;
6 import java
.io
.IOException
;
7 import java
.util
.ArrayList
;
8 import java
.util
.Iterator
;
11 import org
.eclipse
.jface
.wizard
.WizardPage
;
12 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfTrace
;
13 import org
.eclipse
.linuxtools
.tmf
.ui
.TmfUiPlugin
;
14 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomEventsTable
;
15 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomTraceDefinition
.OutputColumn
;
16 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomTxtTrace
;
17 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
;
18 import org
.eclipse
.swt
.SWT
;
19 import org
.eclipse
.swt
.custom
.SashForm
;
20 import org
.eclipse
.swt
.custom
.ScrolledComposite
;
21 import org
.eclipse
.swt
.events
.SelectionAdapter
;
22 import org
.eclipse
.swt
.events
.SelectionEvent
;
23 import org
.eclipse
.swt
.graphics
.Image
;
24 import org
.eclipse
.swt
.layout
.GridData
;
25 import org
.eclipse
.swt
.layout
.GridLayout
;
26 import org
.eclipse
.swt
.widgets
.Button
;
27 import org
.eclipse
.swt
.widgets
.Composite
;
28 import org
.eclipse
.swt
.widgets
.Text
;
30 public class CustomTxtParserOutputWizardPage
extends WizardPage
{
32 private static final Image upImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/up_button.gif");
33 private static final Image downImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/down_button.gif");
34 private CustomTxtParserWizard wizard
;
35 private CustomTxtTraceDefinition definition
;
36 ArrayList
<Output
> outputs
= new ArrayList
<Output
>();
40 Text timestampFormatText
;
41 Text timestampPreviewText
;
42 ScrolledComposite outputsScrolledComposite
;
43 Composite outputsContainer
;
44 ScrolledComposite inputScrolledComposite
;
45 Composite tableContainer
;
46 CustomEventsTable previewTable
;
49 protected CustomTxtParserOutputWizardPage(CustomTxtParserWizard wizard
) {
50 super("CustomParserOutputWizardPage");
51 setTitle(wizard
.inputPage
.getTitle());
52 setDescription("Customize the output of the parser");
54 setPageComplete(false);
57 public void createControl(Composite parent
) {
58 container
= new Composite(parent
, SWT
.NULL
);
59 container
.setLayout(new GridLayout());
61 sash
= new SashForm(container
, SWT
.VERTICAL
);
62 sash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
63 sash
.setBackground(sash
.getDisplay().getSystemColor(SWT
.COLOR_GRAY
));
65 outputsScrolledComposite
= new ScrolledComposite(sash
, SWT
.V_SCROLL
);
66 outputsScrolledComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
67 outputsContainer
= new Composite(outputsScrolledComposite
, SWT
.NONE
);
68 GridLayout outputsLayout
= new GridLayout(4, false);
69 outputsLayout
.marginHeight
= 10;
70 outputsLayout
.marginWidth
= 0;
71 outputsContainer
.setLayout(outputsLayout
);
72 outputsScrolledComposite
.setContent(outputsContainer
);
73 outputsScrolledComposite
.setExpandHorizontal(true);
74 outputsScrolledComposite
.setExpandVertical(true);
76 outputsContainer
.layout();
78 outputsScrolledComposite
.setMinSize(outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-5);
80 tableContainer
= new Composite(sash
, SWT
.NONE
);
81 GridLayout tableLayout
= new GridLayout();
82 tableLayout
.marginHeight
= 0;
83 tableLayout
.marginWidth
= 0;
84 tableContainer
.setLayout(tableLayout
);
85 previewTable
= new CustomEventsTable(new CustomTxtTraceDefinition(), tableContainer
, 0);
87 if (wizard
.definition
!= null) {
88 loadDefinition(wizard
.definition
);
90 setControl(container
);
95 public void dispose() {
96 previewTable
.dispose();
100 private void loadDefinition(CustomTxtTraceDefinition definition
) {
101 for (OutputColumn outputColumn
: definition
.outputs
) {
102 Output output
= new Output(outputsContainer
, outputColumn
.name
);
108 * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
111 public void setVisible(boolean visible
) {
113 this.definition
= wizard
.inputPage
.getDefinition();
114 List
<String
> outputNames
= wizard
.inputPage
.getInputNames();
116 // dispose outputs that have been removed in the input page
117 Iterator
<Output
> iter
= outputs
.iterator();
118 while (iter
.hasNext()) {
119 Output output
= iter
.next();
120 boolean found
= false;
121 for (String name
: outputNames
) {
122 if (output
.name
.equals(name
)) {
133 // create outputs that have been added in the input page
134 for (String name
: outputNames
) {
135 boolean found
= false;
136 for (Output output
: outputs
) {
137 if (output
.name
.equals(name
)) {
143 outputs
.add(new Output(outputsContainer
, name
));
147 outputsContainer
.layout();
148 outputsScrolledComposite
.setMinSize(outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-5);
149 updatePreviewTable();
150 if (sash
.getSize().y
> outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
+ previewTable
.getTable().getItemHeight()) {
151 sash
.setWeights(new int[] {outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
, sash
.getSize().y
- outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
});
153 sash
.setWeights(new int[] {outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
, previewTable
.getTable().getItemHeight()});
155 setPageComplete(true);
157 setPageComplete(false);
159 super.setVisible(visible
);
162 private void moveBefore(Output moved
) {
163 int i
= outputs
.indexOf(moved
);
165 Output previous
= outputs
.get(i
-1);
166 moved
.enabledButton
.moveAbove(previous
.enabledButton
);
167 moved
.nameLabel
.moveBelow(moved
.enabledButton
);
168 moved
.upButton
.moveBelow(moved
.nameLabel
);
169 moved
.downButton
.moveBelow(moved
.upButton
);
170 outputs
.add(i
-1, outputs
.remove(i
));
171 outputsContainer
.layout();
172 outputsScrolledComposite
.setMinSize(outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-5);
174 updatePreviewTable();
178 private void moveAfter(Output moved
) {
179 int i
= outputs
.indexOf(moved
);
180 if (i
+1 < outputs
.size()) {
181 Output next
= outputs
.get(i
+1);
182 moved
.enabledButton
.moveBelow(next
.downButton
);
183 moved
.nameLabel
.moveBelow(moved
.enabledButton
);
184 moved
.upButton
.moveBelow(moved
.nameLabel
);
185 moved
.downButton
.moveBelow(moved
.upButton
);
186 outputs
.add(i
+1, outputs
.remove(i
));
187 outputsContainer
.layout();
188 outputsScrolledComposite
.setMinSize(outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-5);
190 updatePreviewTable();
194 private void updatePreviewTable() {
195 final int MAX_NUM_ENTRIES
= 50;
196 definition
.outputs
= extractOutputs();
199 tmpFile
= TmfUiPlugin
.getDefault().getStateLocation().addTrailingSeparator().append("customwizard.tmp").toFile();
200 FileWriter writer
= new FileWriter(tmpFile
);
201 writer
.write(wizard
.inputPage
.getInputText());
204 ITmfTrace trace
= new CustomTxtTrace(tmpFile
.getName(), definition
, tmpFile
.getAbsolutePath(), MAX_NUM_ENTRIES
);
205 previewTable
.dispose();
206 previewTable
= new CustomEventsTable(definition
, tableContainer
, MAX_NUM_ENTRIES
);
207 previewTable
.setTrace(trace
, true);
208 previewTable
.getTable().setItemCount(MAX_NUM_ENTRIES
); // Trigger parsing
209 } catch (FileNotFoundException e
) {
211 } catch (IOException e
) {
215 tableContainer
.layout();
219 public List
<OutputColumn
> extractOutputs() {
221 for (int i
= 0; i
< outputs
.size(); i
++) {
222 if (outputs
.get(i
).enabledButton
.getSelection()) {
226 List
<OutputColumn
> outputColumns
= new ArrayList
<OutputColumn
>(numColumns
);
228 for (int i
= 0; i
< outputs
.size(); i
++) {
229 Output output
= outputs
.get(i
);
230 if (output
.enabledButton
.getSelection()) {
231 OutputColumn column
= new OutputColumn();
232 column
.name
= output
.nameLabel
.getText();
233 outputColumns
.add(column
);
236 return outputColumns
;
239 private class Output
{
241 Button enabledButton
;
246 public Output(Composite parent
, String name
) {
249 enabledButton
= new Button(parent
, SWT
.CHECK
);
250 enabledButton
.setToolTipText("Visible");
251 enabledButton
.setSelection(true);
252 enabledButton
.addSelectionListener(new SelectionAdapter() {
254 public void widgetSelected(SelectionEvent e
) {
255 updatePreviewTable();
258 if (messageOutput
!= null) {
259 enabledButton
.moveAbove(messageOutput
.enabledButton
);
262 nameLabel
= new Text(parent
, SWT
.BORDER
| SWT
.READ_ONLY
| SWT
.SINGLE
);
263 nameLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
264 nameLabel
.setText(name
);
265 nameLabel
.moveBelow(enabledButton
);
267 upButton
= new Button(parent
, SWT
.PUSH
);
268 upButton
.setImage(upImage
);
269 upButton
.setToolTipText("Move Before");
270 upButton
.addSelectionListener(new SelectionAdapter() {
272 public void widgetSelected(SelectionEvent e
) {
273 moveBefore(Output
.this);
276 upButton
.moveBelow(nameLabel
);
278 downButton
= new Button(parent
, SWT
.PUSH
);
279 downButton
.setImage(downImage
);
280 downButton
.setToolTipText("Move After");
281 downButton
.addSelectionListener(new SelectionAdapter() {
283 public void widgetSelected(SelectionEvent e
) {
284 moveAfter(Output
.this);
287 downButton
.moveBelow(upButton
);
290 private void dispose() {
291 enabledButton
.dispose();
294 downButton
.dispose();
298 public CustomTxtTraceDefinition
getDefinition() {