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
;
16 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomXmlTrace
;
17 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomXmlTraceDefinition
;
18 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomTraceDefinition
.OutputColumn
;
19 import org
.eclipse
.swt
.SWT
;
20 import org
.eclipse
.swt
.custom
.SashForm
;
21 import org
.eclipse
.swt
.custom
.ScrolledComposite
;
22 import org
.eclipse
.swt
.events
.SelectionAdapter
;
23 import org
.eclipse
.swt
.events
.SelectionEvent
;
24 import org
.eclipse
.swt
.graphics
.Image
;
25 import org
.eclipse
.swt
.layout
.GridData
;
26 import org
.eclipse
.swt
.layout
.GridLayout
;
27 import org
.eclipse
.swt
.widgets
.Button
;
28 import org
.eclipse
.swt
.widgets
.Composite
;
29 import org
.eclipse
.swt
.widgets
.Text
;
31 public class CustomXmlParserOutputWizardPage
extends WizardPage
{
33 private static final Image upImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/up_button.gif");
34 private static final Image downImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/down_button.gif");
35 private CustomXmlParserWizard wizard
;
36 private CustomXmlTraceDefinition definition
;
37 ArrayList
<Output
> outputs
= new ArrayList
<Output
>();
41 Text timestampFormatText
;
42 Text timestampPreviewText
;
43 ScrolledComposite outputsScrolledComposite
;
44 Composite outputsContainer
;
45 ScrolledComposite inputScrolledComposite
;
46 Composite tableContainer
;
47 CustomEventsTable previewTable
;
50 protected CustomXmlParserOutputWizardPage(CustomXmlParserWizard wizard
) {
51 super("CustomParserOutputWizardPage");
52 setTitle(wizard
.inputPage
.getTitle());
53 setDescription("Customize the output of the parser");
55 setPageComplete(false);
59 public void createControl(Composite parent
) {
60 container
= new Composite(parent
, SWT
.NULL
);
61 container
.setLayout(new GridLayout());
63 sash
= new SashForm(container
, SWT
.VERTICAL
);
64 sash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
65 sash
.setBackground(sash
.getDisplay().getSystemColor(SWT
.COLOR_GRAY
));
67 outputsScrolledComposite
= new ScrolledComposite(sash
, SWT
.V_SCROLL
);
68 outputsScrolledComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
69 outputsContainer
= new Composite(outputsScrolledComposite
, SWT
.NONE
);
70 GridLayout outputsLayout
= new GridLayout(4, false);
71 outputsLayout
.marginHeight
= 10;
72 outputsLayout
.marginWidth
= 0;
73 outputsContainer
.setLayout(outputsLayout
);
74 outputsScrolledComposite
.setContent(outputsContainer
);
75 outputsScrolledComposite
.setExpandHorizontal(true);
76 outputsScrolledComposite
.setExpandVertical(true);
78 outputsContainer
.layout();
80 outputsScrolledComposite
.setMinSize(outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-5);
82 tableContainer
= new Composite(sash
, SWT
.NONE
);
83 GridLayout tableLayout
= new GridLayout();
84 tableLayout
.marginHeight
= 0;
85 tableLayout
.marginWidth
= 0;
86 tableContainer
.setLayout(tableLayout
);
87 previewTable
= new CustomEventsTable(new CustomXmlTraceDefinition(), tableContainer
, 0);
89 if (wizard
.definition
!= null) {
90 loadDefinition(wizard
.definition
);
92 setControl(container
);
97 public void dispose() {
98 previewTable
.dispose();
102 private void loadDefinition(CustomTraceDefinition definition
) {
103 for (OutputColumn outputColumn
: definition
.outputs
) {
104 Output output
= new Output(outputsContainer
, outputColumn
.name
);
110 * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
113 public void setVisible(boolean visible
) {
115 this.definition
= wizard
.inputPage
.getDefinition();
116 List
<String
> outputNames
= wizard
.inputPage
.getInputNames();
118 // dispose outputs that have been removed in the input page
119 Iterator
<Output
> iter
= outputs
.iterator();
120 while (iter
.hasNext()) {
121 Output output
= iter
.next();
122 boolean found
= false;
123 for (String name
: outputNames
) {
124 if (output
.name
.equals(name
)) {
135 // create outputs that have been added in the input page
136 for (String name
: outputNames
) {
137 boolean found
= false;
138 for (Output output
: outputs
) {
139 if (output
.name
.equals(name
)) {
145 outputs
.add(new Output(outputsContainer
, name
));
149 outputsContainer
.layout();
150 outputsScrolledComposite
.setMinSize(outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-5);
151 updatePreviewTable();
152 if (sash
.getSize().y
> outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
+ previewTable
.getTable().getItemHeight()) {
153 sash
.setWeights(new int[] {outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
, sash
.getSize().y
- outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
});
155 sash
.setWeights(new int[] {outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
, previewTable
.getTable().getItemHeight()});
157 setPageComplete(true);
159 setPageComplete(false);
161 super.setVisible(visible
);
164 private void moveBefore(Output moved
) {
165 int i
= outputs
.indexOf(moved
);
167 Output previous
= outputs
.get(i
-1);
168 moved
.enabledButton
.moveAbove(previous
.enabledButton
);
169 moved
.nameLabel
.moveBelow(moved
.enabledButton
);
170 moved
.upButton
.moveBelow(moved
.nameLabel
);
171 moved
.downButton
.moveBelow(moved
.upButton
);
172 outputs
.add(i
-1, outputs
.remove(i
));
173 outputsContainer
.layout();
174 outputsScrolledComposite
.setMinSize(outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-5);
176 updatePreviewTable();
180 private void moveAfter(Output moved
) {
181 int i
= outputs
.indexOf(moved
);
182 if (i
+1 < outputs
.size()) {
183 Output next
= outputs
.get(i
+1);
184 moved
.enabledButton
.moveBelow(next
.downButton
);
185 moved
.nameLabel
.moveBelow(moved
.enabledButton
);
186 moved
.upButton
.moveBelow(moved
.nameLabel
);
187 moved
.downButton
.moveBelow(moved
.upButton
);
188 outputs
.add(i
+1, outputs
.remove(i
));
189 outputsContainer
.layout();
190 outputsScrolledComposite
.setMinSize(outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-5);
192 updatePreviewTable();
196 private void updatePreviewTable() {
197 final int MAX_NUM_ENTRIES
= 50;
198 definition
.outputs
= extractOutputs();
201 tmpFile
= TmfUiPlugin
.getDefault().getStateLocation().addTrailingSeparator().append("customwizard.tmp").toFile();
202 FileWriter writer
= new FileWriter(tmpFile
);
203 writer
.write(wizard
.inputPage
.getInputText());
206 ITmfTrace trace
= new CustomXmlTrace(tmpFile
.getName(), definition
, tmpFile
.getAbsolutePath(), MAX_NUM_ENTRIES
);
207 previewTable
.dispose();
208 previewTable
= new CustomEventsTable(definition
, tableContainer
, MAX_NUM_ENTRIES
);
209 previewTable
.setTrace(trace
, true);
210 previewTable
.getTable().setItemCount(MAX_NUM_ENTRIES
); // Trigger parsing
211 } catch (FileNotFoundException e
) {
213 } catch (IOException e
) {
217 tableContainer
.layout();
221 public List
<OutputColumn
> extractOutputs() {
223 for (int i
= 0; i
< outputs
.size(); i
++) {
224 if (outputs
.get(i
).enabledButton
.getSelection()) {
228 List
<OutputColumn
> outputColumns
= new ArrayList
<OutputColumn
>(numColumns
);
230 for (int i
= 0; i
< outputs
.size(); i
++) {
231 Output output
= outputs
.get(i
);
232 if (output
.enabledButton
.getSelection()) {
233 OutputColumn column
= new OutputColumn();
234 column
.name
= output
.nameLabel
.getText();
235 outputColumns
.add(column
);
238 return outputColumns
;
241 private class Output
{
243 Button enabledButton
;
248 public Output(Composite parent
, String name
) {
251 enabledButton
= new Button(parent
, SWT
.CHECK
);
252 enabledButton
.setToolTipText("Visible");
253 enabledButton
.setSelection(true);
254 enabledButton
.addSelectionListener(new SelectionAdapter() {
256 public void widgetSelected(SelectionEvent e
) {
257 updatePreviewTable();
260 if (messageOutput
!= null) {
261 enabledButton
.moveAbove(messageOutput
.enabledButton
);
264 nameLabel
= new Text(parent
, SWT
.BORDER
| SWT
.READ_ONLY
| SWT
.SINGLE
);
265 nameLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
266 nameLabel
.setText(name
);
267 nameLabel
.moveBelow(enabledButton
);
269 upButton
= new Button(parent
, SWT
.PUSH
);
270 upButton
.setImage(upImage
);
271 upButton
.setToolTipText("Move Before");
272 upButton
.addSelectionListener(new SelectionAdapter() {
274 public void widgetSelected(SelectionEvent e
) {
275 moveBefore(Output
.this);
278 upButton
.moveBelow(nameLabel
);
280 downButton
= new Button(parent
, SWT
.PUSH
);
281 downButton
.setImage(downImage
);
282 downButton
.setToolTipText("Move After");
283 downButton
.addSelectionListener(new SelectionAdapter() {
285 public void widgetSelected(SelectionEvent e
) {
286 moveAfter(Output
.this);
289 downButton
.moveBelow(upButton
);
292 private void dispose() {
293 enabledButton
.dispose();
296 downButton
.dispose();
300 public CustomXmlTraceDefinition
getDefinition() {