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
.Messages
;
12 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.TmfUiPlugin
;
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
.exceptions
.TmfTraceException
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
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 final CustomTxtParserWizard wizard
;
36 private CustomTxtTraceDefinition definition
;
37 List
<Output
> outputs
= new ArrayList
<Output
>();
38 // Output messageOutput;
41 // Text timestampFormatText;
42 // Text timestampPreviewText;
43 ScrolledComposite outputsScrolledComposite
;
44 Composite outputsContainer
;
45 // ScrolledComposite inputScrolledComposite;
46 Composite tableContainer
;
47 CustomEventsTable previewTable
;
50 protected CustomTxtParserOutputWizardPage(final 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(final 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 final 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 final 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
);
92 setControl(container
);
97 public void dispose() {
98 previewTable
.dispose();
102 private void loadDefinition(final CustomTxtTraceDefinition definition
) {
103 for (final OutputColumn outputColumn
: definition
.outputs
) {
104 final Output output
= new Output(outputsContainer
, outputColumn
.name
);
110 * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
113 public void setVisible(final boolean visible
) {
115 this.definition
= wizard
.inputPage
.getDefinition();
116 final List
<String
> outputNames
= wizard
.inputPage
.getInputNames();
118 // dispose outputs that have been removed in the input page
119 final Iterator
<Output
> iter
= outputs
.iterator();
120 while (iter
.hasNext()) {
121 final Output output
= iter
.next();
122 boolean found
= false;
123 for (final String name
: outputNames
)
124 if (output
.name
.equals(name
)) {
134 // create outputs that have been added in the input page
135 for (final String name
: outputNames
) {
136 boolean found
= false;
137 for (final Output output
: outputs
)
138 if (output
.name
.equals(name
)) {
143 outputs
.add(new Output(outputsContainer
, name
));
146 outputsContainer
.layout();
147 outputsScrolledComposite
.setMinSize(outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-5);
148 updatePreviewTable();
149 if (sash
.getSize().y
> outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
+ previewTable
.getTable().getItemHeight())
150 sash
.setWeights(new int[] {outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
, sash
.getSize().y
- outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
});
152 sash
.setWeights(new int[] {outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
, previewTable
.getTable().getItemHeight()});
153 setPageComplete(true);
155 setPageComplete(false);
156 super.setVisible(visible
);
159 private void moveBefore(final Output moved
) {
160 final int i
= outputs
.indexOf(moved
);
162 final Output previous
= outputs
.get(i
-1);
163 moved
.enabledButton
.moveAbove(previous
.enabledButton
);
164 moved
.nameLabel
.moveBelow(moved
.enabledButton
);
165 moved
.upButton
.moveBelow(moved
.nameLabel
);
166 moved
.downButton
.moveBelow(moved
.upButton
);
167 outputs
.add(i
-1, outputs
.remove(i
));
168 outputsContainer
.layout();
169 outputsScrolledComposite
.setMinSize(outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-5);
171 updatePreviewTable();
175 private void moveAfter(final Output moved
) {
176 final int i
= outputs
.indexOf(moved
);
177 if (i
+1 < outputs
.size()) {
178 final Output next
= outputs
.get(i
+1);
179 moved
.enabledButton
.moveBelow(next
.downButton
);
180 moved
.nameLabel
.moveBelow(moved
.enabledButton
);
181 moved
.upButton
.moveBelow(moved
.nameLabel
);
182 moved
.downButton
.moveBelow(moved
.upButton
);
183 outputs
.add(i
+1, outputs
.remove(i
));
184 outputsContainer
.layout();
185 outputsScrolledComposite
.setMinSize(outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-5);
187 updatePreviewTable();
191 private void updatePreviewTable() {
192 final int CACHE_SIZE
= 50;
193 definition
.outputs
= extractOutputs();
196 tmpFile
= TmfUiPlugin
.getDefault().getStateLocation().addTrailingSeparator().append("customwizard.tmp").toFile(); //$NON-NLS-1$
197 final FileWriter writer
= new FileWriter(tmpFile
);
198 writer
.write(wizard
.inputPage
.getInputText());
201 final ITmfTrace
<?
> trace
= new CustomTxtTrace(null, definition
, tmpFile
.getAbsolutePath(), CACHE_SIZE
);
202 previewTable
.dispose();
203 previewTable
= new CustomEventsTable(definition
, tableContainer
, CACHE_SIZE
);
204 previewTable
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
205 previewTable
.setTrace(trace
, true);
206 } catch (final TmfTraceException e
) {
207 TmfUiPlugin
.getDefault().logError("Error creating CustomTxtTrace. File:" + tmpFile
.getAbsolutePath(), e
); //$NON-NLS-1$
208 } catch (final IOException e
) {
209 TmfUiPlugin
.getDefault().logError("Error creating CustomTxtTrace. File:" + tmpFile
.getAbsolutePath(), e
); //$NON-NLS-1$
212 tableContainer
.layout();
216 public List
<OutputColumn
> extractOutputs() {
218 for (int i
= 0; i
< outputs
.size(); i
++)
219 if (outputs
.get(i
).enabledButton
.getSelection())
221 final List
<OutputColumn
> outputColumns
= new ArrayList
<OutputColumn
>(numColumns
);
223 for (int i
= 0; i
< outputs
.size(); i
++) {
224 final Output output
= outputs
.get(i
);
225 if (output
.enabledButton
.getSelection()) {
226 final OutputColumn column
= new OutputColumn();
227 column
.name
= output
.nameLabel
.getText();
228 outputColumns
.add(column
);
231 return outputColumns
;
234 private class Output
{
236 Button enabledButton
;
241 public Output(final Composite parent
, final String name
) {
244 enabledButton
= new Button(parent
, SWT
.CHECK
);
245 enabledButton
.setToolTipText(Messages
.CustomTxtParserOutputWizardPage_visible
);
246 enabledButton
.setSelection(true);
247 enabledButton
.addSelectionListener(new SelectionAdapter() {
249 public void widgetSelected(final SelectionEvent e
) {
250 updatePreviewTable();
253 // if (messageOutput != null) {
254 // enabledButton.moveAbove(messageOutput.enabledButton);
257 nameLabel
= new Text(parent
, SWT
.BORDER
| SWT
.READ_ONLY
| SWT
.SINGLE
);
258 nameLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
259 nameLabel
.setText(name
);
260 nameLabel
.moveBelow(enabledButton
);
262 upButton
= new Button(parent
, SWT
.PUSH
);
263 upButton
.setImage(upImage
);
264 upButton
.setToolTipText(Messages
.CustomTxtParserOutputWizardPage_moveBefore
);
265 upButton
.addSelectionListener(new SelectionAdapter() {
267 public void widgetSelected(final SelectionEvent e
) {
268 moveBefore(Output
.this);
271 upButton
.moveBelow(nameLabel
);
273 downButton
= new Button(parent
, SWT
.PUSH
);
274 downButton
.setImage(downImage
);
275 downButton
.setToolTipText(Messages
.CustomTxtParserOutputWizardPage_moveAfter
);
276 downButton
.addSelectionListener(new SelectionAdapter() {
278 public void widgetSelected(final SelectionEvent e
) {
279 moveAfter(Output
.this);
282 downButton
.moveBelow(upButton
);
285 private void dispose() {
286 enabledButton
.dispose();
289 downButton
.dispose();
293 public CustomTxtTraceDefinition
getDefinition() {