1 package org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.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
.internal
.Messages
;
15 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomEventsTable
;
16 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomTraceDefinition
.OutputColumn
;
17 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomTxtTrace
;
18 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
;
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 CustomTxtParserOutputWizardPage
extends WizardPage
{
33 private static final Image upImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/elcl16/up_button.gif"); //$NON-NLS-1$
34 private static final Image downImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/elcl16/down_button.gif"); //$NON-NLS-1$
35 private CustomTxtParserWizard wizard
;
36 private CustomTxtTraceDefinition 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 CustomTxtParserOutputWizardPage(CustomTxtParserWizard wizard
) {
51 super("CustomParserOutputWizardPage"); //$NON-NLS-1$
52 setTitle(wizard
.inputPage
.getTitle());
53 setDescription(Messages
.CustomTxtParserOutputWizardPage_description
);
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 CustomTxtTraceDefinition(), tableContainer
, 0);
88 previewTable
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
90 if (wizard
.definition
!= null) {
91 loadDefinition(wizard
.definition
);
93 setControl(container
);
98 public void dispose() {
99 previewTable
.dispose();
103 private void loadDefinition(CustomTxtTraceDefinition definition
) {
104 for (OutputColumn outputColumn
: definition
.outputs
) {
105 Output output
= new Output(outputsContainer
, outputColumn
.name
);
111 * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
114 public void setVisible(boolean visible
) {
116 this.definition
= wizard
.inputPage
.getDefinition();
117 List
<String
> outputNames
= wizard
.inputPage
.getInputNames();
119 // dispose outputs that have been removed in the input page
120 Iterator
<Output
> iter
= outputs
.iterator();
121 while (iter
.hasNext()) {
122 Output output
= iter
.next();
123 boolean found
= false;
124 for (String name
: outputNames
) {
125 if (output
.name
.equals(name
)) {
136 // create outputs that have been added in the input page
137 for (String name
: outputNames
) {
138 boolean found
= false;
139 for (Output output
: outputs
) {
140 if (output
.name
.equals(name
)) {
146 outputs
.add(new Output(outputsContainer
, name
));
150 outputsContainer
.layout();
151 outputsScrolledComposite
.setMinSize(outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-5);
152 updatePreviewTable();
153 if (sash
.getSize().y
> outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
+ previewTable
.getTable().getItemHeight()) {
154 sash
.setWeights(new int[] {outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
, sash
.getSize().y
- outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
});
156 sash
.setWeights(new int[] {outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
, previewTable
.getTable().getItemHeight()});
158 setPageComplete(true);
160 setPageComplete(false);
162 super.setVisible(visible
);
165 private void moveBefore(Output moved
) {
166 int i
= outputs
.indexOf(moved
);
168 Output previous
= outputs
.get(i
-1);
169 moved
.enabledButton
.moveAbove(previous
.enabledButton
);
170 moved
.nameLabel
.moveBelow(moved
.enabledButton
);
171 moved
.upButton
.moveBelow(moved
.nameLabel
);
172 moved
.downButton
.moveBelow(moved
.upButton
);
173 outputs
.add(i
-1, outputs
.remove(i
));
174 outputsContainer
.layout();
175 outputsScrolledComposite
.setMinSize(outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-5);
177 updatePreviewTable();
181 private void moveAfter(Output moved
) {
182 int i
= outputs
.indexOf(moved
);
183 if (i
+1 < outputs
.size()) {
184 Output next
= outputs
.get(i
+1);
185 moved
.enabledButton
.moveBelow(next
.downButton
);
186 moved
.nameLabel
.moveBelow(moved
.enabledButton
);
187 moved
.upButton
.moveBelow(moved
.nameLabel
);
188 moved
.downButton
.moveBelow(moved
.upButton
);
189 outputs
.add(i
+1, outputs
.remove(i
));
190 outputsContainer
.layout();
191 outputsScrolledComposite
.setMinSize(outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-5);
193 updatePreviewTable();
197 private void updatePreviewTable() {
198 final int MAX_NUM_ENTRIES
= 50;
199 definition
.outputs
= extractOutputs();
202 tmpFile
= TmfUiPlugin
.getDefault().getStateLocation().addTrailingSeparator().append("customwizard.tmp").toFile(); //$NON-NLS-1$
203 FileWriter writer
= new FileWriter(tmpFile
);
204 writer
.write(wizard
.inputPage
.getInputText());
207 ITmfTrace
<?
> trace
= new CustomTxtTrace(tmpFile
.getName(), definition
, tmpFile
.getAbsolutePath(), MAX_NUM_ENTRIES
);
208 previewTable
.dispose();
209 previewTable
= new CustomEventsTable(definition
, tableContainer
, MAX_NUM_ENTRIES
);
210 previewTable
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
211 previewTable
.setTrace(trace
, true);
212 } catch (FileNotFoundException e
) {
214 } catch (IOException e
) {
218 tableContainer
.layout();
222 public List
<OutputColumn
> extractOutputs() {
224 for (int i
= 0; i
< outputs
.size(); i
++) {
225 if (outputs
.get(i
).enabledButton
.getSelection()) {
229 List
<OutputColumn
> outputColumns
= new ArrayList
<OutputColumn
>(numColumns
);
231 for (int i
= 0; i
< outputs
.size(); i
++) {
232 Output output
= outputs
.get(i
);
233 if (output
.enabledButton
.getSelection()) {
234 OutputColumn column
= new OutputColumn();
235 column
.name
= output
.nameLabel
.getText();
236 outputColumns
.add(column
);
239 return outputColumns
;
242 private class Output
{
244 Button enabledButton
;
249 public Output(Composite parent
, String name
) {
252 enabledButton
= new Button(parent
, SWT
.CHECK
);
253 enabledButton
.setToolTipText(Messages
.CustomTxtParserOutputWizardPage_visible
);
254 enabledButton
.setSelection(true);
255 enabledButton
.addSelectionListener(new SelectionAdapter() {
257 public void widgetSelected(SelectionEvent e
) {
258 updatePreviewTable();
261 if (messageOutput
!= null) {
262 enabledButton
.moveAbove(messageOutput
.enabledButton
);
265 nameLabel
= new Text(parent
, SWT
.BORDER
| SWT
.READ_ONLY
| SWT
.SINGLE
);
266 nameLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
267 nameLabel
.setText(name
);
268 nameLabel
.moveBelow(enabledButton
);
270 upButton
= new Button(parent
, SWT
.PUSH
);
271 upButton
.setImage(upImage
);
272 upButton
.setToolTipText(Messages
.CustomTxtParserOutputWizardPage_moveBefore
);
273 upButton
.addSelectionListener(new SelectionAdapter() {
275 public void widgetSelected(SelectionEvent e
) {
276 moveBefore(Output
.this);
279 upButton
.moveBelow(nameLabel
);
281 downButton
= new Button(parent
, SWT
.PUSH
);
282 downButton
.setImage(downImage
);
283 downButton
.setToolTipText(Messages
.CustomTxtParserOutputWizardPage_moveAfter
);
284 downButton
.addSelectionListener(new SelectionAdapter() {
286 public void widgetSelected(SelectionEvent e
) {
287 moveAfter(Output
.this);
290 downButton
.moveBelow(upButton
);
293 private void dispose() {
294 enabledButton
.dispose();
297 downButton
.dispose();
301 public CustomTxtTraceDefinition
getDefinition() {