1 /*******************************************************************************
2 * Copyright (c) 2010, 2013 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.tmf
.ui
.dialogs
;
15 import org
.eclipse
.jface
.dialogs
.Dialog
;
16 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
17 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
18 import org
.eclipse
.jface
.window
.Window
;
19 import org
.eclipse
.jface
.wizard
.WizardDialog
;
20 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
21 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Messages
;
22 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTraceDefinition
;
23 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
;
24 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomXmlTraceDefinition
;
25 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.wizards
.CustomTxtParserWizard
;
26 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.wizards
.CustomXmlParserWizard
;
27 import org
.eclipse
.swt
.SWT
;
28 import org
.eclipse
.swt
.events
.SelectionEvent
;
29 import org
.eclipse
.swt
.events
.SelectionListener
;
30 import org
.eclipse
.swt
.graphics
.Image
;
31 import org
.eclipse
.swt
.layout
.GridData
;
32 import org
.eclipse
.swt
.layout
.GridLayout
;
33 import org
.eclipse
.swt
.widgets
.Button
;
34 import org
.eclipse
.swt
.widgets
.Composite
;
35 import org
.eclipse
.swt
.widgets
.Control
;
36 import org
.eclipse
.swt
.widgets
.Display
;
37 import org
.eclipse
.swt
.widgets
.FileDialog
;
38 import org
.eclipse
.swt
.widgets
.Label
;
39 import org
.eclipse
.swt
.widgets
.List
;
40 import org
.eclipse
.swt
.widgets
.Shell
;
43 * Dialog for custom text parsers.
45 * @author Patrick Tassé
47 public class ManageCustomParsersDialog
extends Dialog
{
49 private static final Image image
= Activator
.getDefault().getImageFromPath("/icons/etool16/customparser_wizard.gif"); //$NON-NLS-1$
64 * Parent shell of this dialog
66 public ManageCustomParsersDialog(Shell parent
) {
68 setShellStyle(SWT
.RESIZE
| SWT
.MAX
| getShellStyle());
72 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
75 protected Control
createDialogArea(Composite parent
) {
76 getShell().setText(Messages
.ManageCustomParsersDialog_DialogHeader
);
77 getShell().setImage(image
);
79 Composite composite
= (Composite
) super.createDialogArea(parent
);
80 composite
.setLayout(new GridLayout(2, false));
82 Composite listContainer
= new Composite(composite
, SWT
.NONE
);
83 listContainer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
84 GridLayout lcgl
= new GridLayout();
85 lcgl
.marginHeight
= 0;
87 listContainer
.setLayout(lcgl
);
89 Composite radioContainer
= new Composite(listContainer
, SWT
.NONE
);
90 GridLayout rcgl
= new GridLayout(2, true);
91 rcgl
.marginHeight
= 0;
93 radioContainer
.setLayout(rcgl
);
95 txtButton
= new Button(radioContainer
, SWT
.RADIO
);
96 txtButton
.setText(Messages
.ManageCustomParsersDialog_TextButtonLabel
);
97 txtButton
.setSelection(true);
98 txtButton
.addSelectionListener(new SelectionListener() {
100 public void widgetDefaultSelected(SelectionEvent e
) {}
103 public void widgetSelected(SelectionEvent e
) {
108 xmlButton
= new Button(radioContainer
, SWT
.RADIO
);
109 xmlButton
.setText("XML"); //$NON-NLS-1$
110 xmlButton
.addSelectionListener(new SelectionListener() {
112 public void widgetDefaultSelected(SelectionEvent e
) {
116 public void widgetSelected(SelectionEvent e
) {
121 parserList
= new List(listContainer
, SWT
.SINGLE
| SWT
.BORDER
| SWT
.H_SCROLL
| SWT
.V_SCROLL
);
122 parserList
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
123 parserList
.addSelectionListener(new SelectionListener() {
125 public void widgetDefaultSelected(SelectionEvent e
) {}
128 public void widgetSelected(SelectionEvent e
) {
129 if (parserList
.getSelectionCount() == 0) {
130 editButton
.setEnabled(false);
131 deleteButton
.setEnabled(false);
132 exportButton
.setEnabled(false);
134 editButton
.setEnabled(true);
135 deleteButton
.setEnabled(true);
136 exportButton
.setEnabled(true);
141 Composite buttonContainer
= new Composite(composite
, SWT
.NULL
);
142 buttonContainer
.setLayout(new GridLayout());
143 buttonContainer
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.TOP
, false, false));
145 newButton
= new Button(buttonContainer
, SWT
.PUSH
);
146 newButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
147 newButton
.setText(Messages
.ManageCustomParsersDialog_NewButtonLabel
);
148 newButton
.addSelectionListener(new SelectionListener() {
150 public void widgetDefaultSelected(SelectionEvent e
) {}
153 public void widgetSelected(SelectionEvent e
) {
154 WizardDialog dialog
= null;
155 if (txtButton
.getSelection()) {
156 dialog
= new WizardDialog(getShell(), new CustomTxtParserWizard());
157 } else if (xmlButton
.getSelection()) {
158 dialog
= new WizardDialog(getShell(), new CustomXmlParserWizard());
160 if (dialog
!= null) {
162 if (dialog
.getReturnCode() == Window
.OK
) {
169 editButton
= new Button(buttonContainer
, SWT
.PUSH
);
170 editButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
171 editButton
.setText(Messages
.ManageCustomParsersDialog_EditButtonLabel
);
172 editButton
.setEnabled(false);
173 editButton
.addSelectionListener(new SelectionListener() {
175 public void widgetDefaultSelected(SelectionEvent e
) {}
178 public void widgetSelected(SelectionEvent e
) {
179 WizardDialog dialog
= null;
180 if (txtButton
.getSelection()) {
181 dialog
= new WizardDialog(getShell(),
182 new CustomTxtParserWizard(CustomTxtTraceDefinition
.load(parserList
.getSelection()[0])));
183 } else if (xmlButton
.getSelection()) {
184 dialog
= new WizardDialog(getShell(),
185 new CustomXmlParserWizard(CustomXmlTraceDefinition
.load(parserList
.getSelection()[0])));
187 if (dialog
!= null) {
189 if (dialog
.getReturnCode() == Window
.OK
) {
196 deleteButton
= new Button(buttonContainer
, SWT
.PUSH
);
197 deleteButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
198 deleteButton
.setText(Messages
.ManageCustomParsersDialog_DeleteButtonLabel
);
199 deleteButton
.setEnabled(false);
200 deleteButton
.addSelectionListener(new SelectionListener() {
202 public void widgetDefaultSelected(SelectionEvent e
) {}
205 public void widgetSelected(SelectionEvent e
) {
206 boolean confirm
= MessageDialog
.openQuestion(
208 Messages
.ManageCustomParsersDialog_DeleteParserDialogHeader
,
209 Messages
.ManageCustomParsersDialog_DeleteConfirmation
+ parserList
.getSelection()[0] + "?"); //$NON-NLS-1$
211 if (txtButton
.getSelection()) {
212 CustomTxtTraceDefinition
.delete(parserList
.getSelection()[0]);
213 } else if (xmlButton
.getSelection()) {
214 CustomXmlTraceDefinition
.delete(parserList
.getSelection()[0]);
221 new Label(buttonContainer
, SWT
.NONE
); // filler
223 importButton
= new Button(buttonContainer
, SWT
.PUSH
);
224 importButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
225 importButton
.setText(Messages
.ManageCustomParsersDialog_ImportButtonLabel
);
226 importButton
.addSelectionListener(new SelectionListener() {
228 public void widgetDefaultSelected(SelectionEvent e
) {}
231 public void widgetSelected(SelectionEvent e
) {
232 FileDialog dialog
= new FileDialog(Display
.getCurrent().getActiveShell(), SWT
.OPEN
);
233 dialog
.setText(Messages
.ManageCustomParsersDialog_ImportParserSelection
);
234 dialog
.setFilterExtensions(new String
[] { "*.xml", "*" }); //$NON-NLS-1$ //$NON-NLS-2$
235 String path
= dialog
.open();
237 CustomTraceDefinition
[] defs
= null;
238 if (txtButton
.getSelection()) {
239 defs
= CustomTxtTraceDefinition
.loadAll(path
);
240 } else if (xmlButton
.getSelection()) {
241 defs
= CustomXmlTraceDefinition
.loadAll(path
);
243 if (defs
!= null && defs
.length
> 0) {
244 for (CustomTraceDefinition def
: defs
) {
253 exportButton
= new Button(buttonContainer
, SWT
.PUSH
);
254 exportButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
255 exportButton
.setText(Messages
.ManageCustomParsersDialog_ExportButtonLabel
);
256 exportButton
.setEnabled(false);
257 exportButton
.addSelectionListener(new SelectionListener() {
259 public void widgetDefaultSelected(SelectionEvent e
) {}
262 public void widgetSelected(SelectionEvent e
) {
263 FileDialog dialog
= new FileDialog(Display
.getCurrent().getActiveShell(), SWT
.SAVE
);
264 dialog
.setText(Messages
.ManageCustomParsersDialog_ExportParserSelection
+ parserList
.getSelection()[0]);
265 dialog
.setFilterExtensions(new String
[] { "*.xml", "*" }); //$NON-NLS-1$ //$NON-NLS-2$
266 String path
= dialog
.open();
268 CustomTraceDefinition def
= null;
269 if (txtButton
.getSelection()) {
270 def
= CustomTxtTraceDefinition
.load(parserList
.getSelection()[0]);
271 } else if (xmlButton
.getSelection()) {
272 def
= CustomXmlTraceDefinition
.load(parserList
.getSelection()[0]);
283 getShell().setMinimumSize(300, 275);
288 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
291 protected void createButtonsForButtonBar(Composite parent
) {
292 createButton(parent
, IDialogConstants
.OK_ID
, IDialogConstants
.CLOSE_LABEL
, false);
295 private void fillParserList() {
296 parserList
.removeAll();
297 if (txtButton
.getSelection()) {
298 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
299 parserList
.add(def
.definitionName
);
301 } else if (xmlButton
.getSelection()) {
302 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
303 parserList
.add(def
.definitionName
);
306 editButton
.setEnabled(false);
307 deleteButton
.setEnabled(false);
308 exportButton
.setEnabled(false);