1 package org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.wizards
;
4 import java
.io
.FileWriter
;
5 import java
.io
.IOException
;
6 import java
.util
.ArrayList
;
7 import java
.util
.Iterator
;
10 import org
.eclipse
.jface
.wizard
.WizardPage
;
11 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
12 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Messages
;
13 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomEventsTable
;
14 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTraceDefinition
.OutputColumn
;
15 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtTrace
;
16 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceRangeUpdatedSignal
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
21 import org
.eclipse
.swt
.SWT
;
22 import org
.eclipse
.swt
.custom
.SashForm
;
23 import org
.eclipse
.swt
.custom
.ScrolledComposite
;
24 import org
.eclipse
.swt
.events
.SelectionAdapter
;
25 import org
.eclipse
.swt
.events
.SelectionEvent
;
26 import org
.eclipse
.swt
.graphics
.Image
;
27 import org
.eclipse
.swt
.layout
.GridData
;
28 import org
.eclipse
.swt
.layout
.GridLayout
;
29 import org
.eclipse
.swt
.widgets
.Button
;
30 import org
.eclipse
.swt
.widgets
.Composite
;
31 import org
.eclipse
.swt
.widgets
.Text
;
33 public class CustomTxtParserOutputWizardPage
extends WizardPage
{
35 private static final Image upImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/up_button.gif"); //$NON-NLS-1$
36 private static final Image downImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/down_button.gif"); //$NON-NLS-1$
37 private final CustomTxtParserWizard wizard
;
38 private CustomTxtTraceDefinition definition
;
39 List
<Output
> outputs
= new ArrayList
<Output
>();
40 // Output messageOutput;
43 // Text timestampFormatText;
44 // Text timestampPreviewText;
45 ScrolledComposite outputsScrolledComposite
;
46 Composite outputsContainer
;
47 // ScrolledComposite inputScrolledComposite;
48 Composite tableContainer
;
49 CustomEventsTable previewTable
;
52 protected CustomTxtParserOutputWizardPage(final CustomTxtParserWizard wizard
) {
53 super("CustomParserOutputWizardPage"); //$NON-NLS-1$
54 setTitle(wizard
.inputPage
.getTitle());
55 setDescription(Messages
.CustomTxtParserOutputWizardPage_description
);
57 setPageComplete(false);
61 public void createControl(final Composite parent
) {
62 container
= new Composite(parent
, SWT
.NULL
);
63 container
.setLayout(new GridLayout());
65 sash
= new SashForm(container
, SWT
.VERTICAL
);
66 sash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
67 sash
.setBackground(sash
.getDisplay().getSystemColor(SWT
.COLOR_GRAY
));
69 outputsScrolledComposite
= new ScrolledComposite(sash
, SWT
.V_SCROLL
);
70 outputsScrolledComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
71 outputsContainer
= new Composite(outputsScrolledComposite
, SWT
.NONE
);
72 final GridLayout outputsLayout
= new GridLayout(4, false);
73 outputsLayout
.marginHeight
= 10;
74 outputsLayout
.marginWidth
= 0;
75 outputsContainer
.setLayout(outputsLayout
);
76 outputsScrolledComposite
.setContent(outputsContainer
);
77 outputsScrolledComposite
.setExpandHorizontal(true);
78 outputsScrolledComposite
.setExpandVertical(true);
80 outputsContainer
.layout();
82 outputsScrolledComposite
.setMinSize(outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-5);
84 tableContainer
= new Composite(sash
, SWT
.NONE
);
85 final GridLayout tableLayout
= new GridLayout();
86 tableLayout
.marginHeight
= 0;
87 tableLayout
.marginWidth
= 0;
88 tableContainer
.setLayout(tableLayout
);
89 previewTable
= new CustomEventsTable(new CustomTxtTraceDefinition(), tableContainer
, 0);
90 previewTable
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
92 if (wizard
.definition
!= null) {
93 loadDefinition(wizard
.definition
);
95 setControl(container
);
100 public void dispose() {
101 previewTable
.dispose();
105 private void loadDefinition(final CustomTxtTraceDefinition definition
) {
106 for (final OutputColumn outputColumn
: definition
.outputs
) {
107 final Output output
= new Output(outputsContainer
, outputColumn
.name
);
113 * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
116 public void setVisible(final boolean visible
) {
118 this.definition
= wizard
.inputPage
.getDefinition();
119 final List
<String
> outputNames
= wizard
.inputPage
.getInputNames();
121 // dispose outputs that have been removed in the input page
122 final Iterator
<Output
> iter
= outputs
.iterator();
123 while (iter
.hasNext()) {
124 final Output output
= iter
.next();
125 boolean found
= false;
126 for (final String name
: outputNames
) {
127 if (output
.name
.equals(name
)) {
138 // create outputs that have been added in the input page
139 for (final String name
: outputNames
) {
140 boolean found
= false;
141 for (final Output output
: outputs
) {
142 if (output
.name
.equals(name
)) {
148 outputs
.add(new Output(outputsContainer
, name
));
152 outputsContainer
.layout();
153 outputsScrolledComposite
.setMinSize(outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-5);
154 updatePreviewTable();
155 if (sash
.getSize().y
> outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
+ previewTable
.getTable().getItemHeight()) {
156 sash
.setWeights(new int[] {outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
, sash
.getSize().y
- outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
});
158 sash
.setWeights(new int[] {outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
, previewTable
.getTable().getItemHeight()});
160 setPageComplete(true);
162 setPageComplete(false);
164 super.setVisible(visible
);
167 private void moveBefore(final Output moved
) {
168 final int i
= outputs
.indexOf(moved
);
170 final Output previous
= outputs
.get(i
-1);
171 moved
.enabledButton
.moveAbove(previous
.enabledButton
);
172 moved
.nameLabel
.moveBelow(moved
.enabledButton
);
173 moved
.upButton
.moveBelow(moved
.nameLabel
);
174 moved
.downButton
.moveBelow(moved
.upButton
);
175 outputs
.add(i
-1, outputs
.remove(i
));
176 outputsContainer
.layout();
177 outputsScrolledComposite
.setMinSize(outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-5);
179 updatePreviewTable();
183 private void moveAfter(final Output moved
) {
184 final int i
= outputs
.indexOf(moved
);
185 if (i
+1 < outputs
.size()) {
186 final Output next
= outputs
.get(i
+1);
187 moved
.enabledButton
.moveBelow(next
.downButton
);
188 moved
.nameLabel
.moveBelow(moved
.enabledButton
);
189 moved
.upButton
.moveBelow(moved
.nameLabel
);
190 moved
.downButton
.moveBelow(moved
.upButton
);
191 outputs
.add(i
+1, outputs
.remove(i
));
192 outputsContainer
.layout();
193 outputsScrolledComposite
.setMinSize(outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-5);
195 updatePreviewTable();
199 private void updatePreviewTable() {
200 final int CACHE_SIZE
= 50;
201 definition
.outputs
= extractOutputs();
204 tmpFile
= Activator
.getDefault().getStateLocation().addTrailingSeparator().append("customwizard.tmp").toFile(); //$NON-NLS-1$
205 final FileWriter writer
= new FileWriter(tmpFile
);
206 writer
.write(wizard
.inputPage
.getInputText());
209 final CustomTxtTrace trace
= new CustomTxtTrace(null, definition
, tmpFile
.getAbsolutePath(), CACHE_SIZE
);
210 trace
.getIndexer().buildIndex(0, TmfTimeRange
.ETERNITY
, false);
211 previewTable
.dispose();
212 previewTable
= new CustomEventsTable(definition
, tableContainer
, CACHE_SIZE
);
213 previewTable
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
214 previewTable
.setTrace(trace
, true);
215 } catch (final TmfTraceException e
) {
216 Activator
.getDefault().logError("Error creating CustomTxtTrace. File:" + tmpFile
.getAbsolutePath(), e
); //$NON-NLS-1$
217 } catch (final IOException e
) {
218 Activator
.getDefault().logError("Error creating CustomTxtTrace. File:" + tmpFile
.getAbsolutePath(), e
); //$NON-NLS-1$
221 tableContainer
.layout();
225 public List
<OutputColumn
> extractOutputs() {
227 for (int i
= 0; i
< outputs
.size(); i
++) {
228 if (outputs
.get(i
).enabledButton
.getSelection()) {
232 final List
<OutputColumn
> outputColumns
= new ArrayList
<OutputColumn
>(numColumns
);
234 for (int i
= 0; i
< outputs
.size(); i
++) {
235 final Output output
= outputs
.get(i
);
236 if (output
.enabledButton
.getSelection()) {
237 final OutputColumn column
= new OutputColumn();
238 column
.name
= output
.nameLabel
.getText();
239 outputColumns
.add(column
);
242 return outputColumns
;
245 private class Output
{
247 Button enabledButton
;
252 public Output(final Composite parent
, final String name
) {
255 enabledButton
= new Button(parent
, SWT
.CHECK
);
256 enabledButton
.setToolTipText(Messages
.CustomTxtParserOutputWizardPage_visible
);
257 enabledButton
.setSelection(true);
258 enabledButton
.addSelectionListener(new SelectionAdapter() {
260 public void widgetSelected(final SelectionEvent e
) {
261 updatePreviewTable();
264 // if (messageOutput != null) {
265 // enabledButton.moveAbove(messageOutput.enabledButton);
268 nameLabel
= new Text(parent
, SWT
.BORDER
| SWT
.READ_ONLY
| SWT
.SINGLE
);
269 nameLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
270 nameLabel
.setText(name
);
271 nameLabel
.moveBelow(enabledButton
);
273 upButton
= new Button(parent
, SWT
.PUSH
);
274 upButton
.setImage(upImage
);
275 upButton
.setToolTipText(Messages
.CustomTxtParserOutputWizardPage_moveBefore
);
276 upButton
.addSelectionListener(new SelectionAdapter() {
278 public void widgetSelected(final SelectionEvent e
) {
279 moveBefore(Output
.this);
282 upButton
.moveBelow(nameLabel
);
284 downButton
= new Button(parent
, SWT
.PUSH
);
285 downButton
.setImage(downImage
);
286 downButton
.setToolTipText(Messages
.CustomTxtParserOutputWizardPage_moveAfter
);
287 downButton
.addSelectionListener(new SelectionAdapter() {
289 public void widgetSelected(final SelectionEvent e
) {
290 moveAfter(Output
.this);
293 downButton
.moveBelow(upButton
);
296 private void dispose() {
297 enabledButton
.dispose();
300 downButton
.dispose();
304 public CustomTxtTraceDefinition
getDefinition() {