1 package org
.eclipse
.linuxtools
.internal
.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
.internal
.tmf
.ui
.Messages
;
13 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.TmfUiPlugin
;
14 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomEventsTable
;
15 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTraceDefinition
;
16 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTraceDefinition
.OutputColumn
;
17 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomXmlTrace
;
18 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomXmlTraceDefinition
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
20 import org
.eclipse
.swt
.SWT
;
21 import org
.eclipse
.swt
.custom
.SashForm
;
22 import org
.eclipse
.swt
.custom
.ScrolledComposite
;
23 import org
.eclipse
.swt
.events
.SelectionAdapter
;
24 import org
.eclipse
.swt
.events
.SelectionEvent
;
25 import org
.eclipse
.swt
.graphics
.Image
;
26 import org
.eclipse
.swt
.layout
.GridData
;
27 import org
.eclipse
.swt
.layout
.GridLayout
;
28 import org
.eclipse
.swt
.widgets
.Button
;
29 import org
.eclipse
.swt
.widgets
.Composite
;
30 import org
.eclipse
.swt
.widgets
.Text
;
32 public class CustomXmlParserOutputWizardPage
extends WizardPage
{
34 private static final Image upImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/elcl16/up_button.gif"); //$NON-NLS-1$
35 private static final Image downImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/elcl16/down_button.gif"); //$NON-NLS-1$
36 private final CustomXmlParserWizard wizard
;
37 private CustomXmlTraceDefinition definition
;
38 ArrayList
<Output
> outputs
= new ArrayList
<Output
>();
39 // Output messageOutput;
42 // Text timestampFormatText;
43 // Text timestampPreviewText;
44 ScrolledComposite outputsScrolledComposite
;
45 Composite outputsContainer
;
46 // ScrolledComposite inputScrolledComposite;
47 Composite tableContainer
;
48 CustomEventsTable previewTable
;
51 protected CustomXmlParserOutputWizardPage(final CustomXmlParserWizard wizard
) {
52 super("CustomParserOutputWizardPage"); //$NON-NLS-1$
53 setTitle(wizard
.inputPage
.getTitle());
54 setDescription(Messages
.CustomXmlParserOutputWizardPage_description
);
56 setPageComplete(false);
60 public void createControl(final Composite parent
) {
61 container
= new Composite(parent
, SWT
.NULL
);
62 container
.setLayout(new GridLayout());
64 sash
= new SashForm(container
, SWT
.VERTICAL
);
65 sash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
66 sash
.setBackground(sash
.getDisplay().getSystemColor(SWT
.COLOR_GRAY
));
68 outputsScrolledComposite
= new ScrolledComposite(sash
, SWT
.V_SCROLL
);
69 outputsScrolledComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
70 outputsContainer
= new Composite(outputsScrolledComposite
, SWT
.NONE
);
71 final GridLayout outputsLayout
= new GridLayout(4, false);
72 outputsLayout
.marginHeight
= 10;
73 outputsLayout
.marginWidth
= 0;
74 outputsContainer
.setLayout(outputsLayout
);
75 outputsScrolledComposite
.setContent(outputsContainer
);
76 outputsScrolledComposite
.setExpandHorizontal(true);
77 outputsScrolledComposite
.setExpandVertical(true);
79 outputsContainer
.layout();
81 outputsScrolledComposite
.setMinSize(outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-5);
83 tableContainer
= new Composite(sash
, SWT
.NONE
);
84 final GridLayout tableLayout
= new GridLayout();
85 tableLayout
.marginHeight
= 0;
86 tableLayout
.marginWidth
= 0;
87 tableContainer
.setLayout(tableLayout
);
88 previewTable
= new CustomEventsTable(new CustomXmlTraceDefinition(), tableContainer
, 0);
89 previewTable
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
91 if (wizard
.definition
!= null)
92 loadDefinition(wizard
.definition
);
93 setControl(container
);
98 public void dispose() {
99 previewTable
.dispose();
103 private void loadDefinition(final CustomTraceDefinition definition
) {
104 for (final OutputColumn outputColumn
: definition
.outputs
) {
105 final Output output
= new Output(outputsContainer
, outputColumn
.name
);
111 * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
114 public void setVisible(final boolean visible
) {
116 this.definition
= wizard
.inputPage
.getDefinition();
117 final List
<String
> outputNames
= wizard
.inputPage
.getInputNames();
119 // dispose outputs that have been removed in the input page
120 final Iterator
<Output
> iter
= outputs
.iterator();
121 while (iter
.hasNext()) {
122 final Output output
= iter
.next();
123 boolean found
= false;
124 for (final String name
: outputNames
)
125 if (output
.name
.equals(name
)) {
135 // create outputs that have been added in the input page
136 for (final String name
: outputNames
) {
137 boolean found
= false;
138 for (final Output output
: outputs
)
139 if (output
.name
.equals(name
)) {
144 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()});
154 setPageComplete(true);
156 setPageComplete(false);
157 super.setVisible(visible
);
160 private void moveBefore(final Output moved
) {
161 final int i
= outputs
.indexOf(moved
);
163 final Output previous
= outputs
.get(i
-1);
164 moved
.enabledButton
.moveAbove(previous
.enabledButton
);
165 moved
.nameLabel
.moveBelow(moved
.enabledButton
);
166 moved
.upButton
.moveBelow(moved
.nameLabel
);
167 moved
.downButton
.moveBelow(moved
.upButton
);
168 outputs
.add(i
-1, outputs
.remove(i
));
169 outputsContainer
.layout();
170 outputsScrolledComposite
.setMinSize(outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-5);
172 updatePreviewTable();
176 private void moveAfter(final Output moved
) {
177 final int i
= outputs
.indexOf(moved
);
178 if (i
+1 < outputs
.size()) {
179 final Output next
= outputs
.get(i
+1);
180 moved
.enabledButton
.moveBelow(next
.downButton
);
181 moved
.nameLabel
.moveBelow(moved
.enabledButton
);
182 moved
.upButton
.moveBelow(moved
.nameLabel
);
183 moved
.downButton
.moveBelow(moved
.upButton
);
184 outputs
.add(i
+1, outputs
.remove(i
));
185 outputsContainer
.layout();
186 outputsScrolledComposite
.setMinSize(outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, outputsContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-5);
188 updatePreviewTable();
192 private void updatePreviewTable() {
193 final int CACHE_SIZE
= 50;
194 definition
.outputs
= extractOutputs();
197 tmpFile
= TmfUiPlugin
.getDefault().getStateLocation().addTrailingSeparator().append("customwizard.tmp").toFile(); //$NON-NLS-1$
198 final FileWriter writer
= new FileWriter(tmpFile
);
199 writer
.write(wizard
.inputPage
.getInputText());
202 final ITmfTrace
<?
> trace
= new CustomXmlTrace(null, definition
, tmpFile
.getAbsolutePath(), CACHE_SIZE
);
203 previewTable
.dispose();
204 previewTable
= new CustomEventsTable(definition
, tableContainer
, CACHE_SIZE
);
205 previewTable
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
206 previewTable
.setTrace(trace
, true);
207 } catch (final FileNotFoundException e
) {
209 } catch (final IOException e
) {
213 tableContainer
.layout();
217 public List
<OutputColumn
> extractOutputs() {
219 for (int i
= 0; i
< outputs
.size(); i
++)
220 if (outputs
.get(i
).enabledButton
.getSelection())
222 final List
<OutputColumn
> outputColumns
= new ArrayList
<OutputColumn
>(numColumns
);
224 for (int i
= 0; i
< outputs
.size(); i
++) {
225 final Output output
= outputs
.get(i
);
226 if (output
.enabledButton
.getSelection()) {
227 final OutputColumn column
= new OutputColumn();
228 column
.name
= output
.nameLabel
.getText();
229 outputColumns
.add(column
);
232 return outputColumns
;
235 private class Output
{
237 Button enabledButton
;
242 public Output(final Composite parent
, final String name
) {
245 enabledButton
= new Button(parent
, SWT
.CHECK
);
246 enabledButton
.setToolTipText(Messages
.CustomXmlParserOutputWizardPage_visible
);
247 enabledButton
.setSelection(true);
248 enabledButton
.addSelectionListener(new SelectionAdapter() {
250 public void widgetSelected(final SelectionEvent e
) {
251 updatePreviewTable();
254 // if (messageOutput != null) {
255 // enabledButton.moveAbove(messageOutput.enabledButton);
258 nameLabel
= new Text(parent
, SWT
.BORDER
| SWT
.READ_ONLY
| SWT
.SINGLE
);
259 nameLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
260 nameLabel
.setText(name
);
261 nameLabel
.moveBelow(enabledButton
);
263 upButton
= new Button(parent
, SWT
.PUSH
);
264 upButton
.setImage(upImage
);
265 upButton
.setToolTipText(Messages
.CustomXmlParserOutputWizardPage_moveBefore
);
266 upButton
.addSelectionListener(new SelectionAdapter() {
268 public void widgetSelected(final SelectionEvent e
) {
269 moveBefore(Output
.this);
272 upButton
.moveBelow(nameLabel
);
274 downButton
= new Button(parent
, SWT
.PUSH
);
275 downButton
.setImage(downImage
);
276 downButton
.setToolTipText(Messages
.CustomXmlParserOutputWizardPage_moveAfter
);
277 downButton
.addSelectionListener(new SelectionAdapter() {
279 public void widgetSelected(final SelectionEvent e
) {
280 moveAfter(Output
.this);
283 downButton
.moveBelow(upButton
);
286 private void dispose() {
287 enabledButton
.dispose();
290 downButton
.dispose();
294 public CustomXmlTraceDefinition
getDefinition() {