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 protected Control
createDialogArea(Composite parent
) {
73 getShell().setText(Messages
.ManageCustomParsersDialog_DialogHeader
);
74 getShell().setImage(image
);
76 Composite composite
= (Composite
) super.createDialogArea(parent
);
77 composite
.setLayout(new GridLayout(2, false));
79 Composite listContainer
= new Composite(composite
, SWT
.NONE
);
80 listContainer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
81 GridLayout lcgl
= new GridLayout();
82 lcgl
.marginHeight
= 0;
84 listContainer
.setLayout(lcgl
);
86 Composite radioContainer
= new Composite(listContainer
, SWT
.NONE
);
87 GridLayout rcgl
= new GridLayout(2, true);
88 rcgl
.marginHeight
= 0;
90 radioContainer
.setLayout(rcgl
);
92 txtButton
= new Button(radioContainer
, SWT
.RADIO
);
93 txtButton
.setText(Messages
.ManageCustomParsersDialog_TextButtonLabel
);
94 txtButton
.setSelection(true);
95 txtButton
.addSelectionListener(new SelectionListener() {
97 public void widgetDefaultSelected(SelectionEvent e
) {}
100 public void widgetSelected(SelectionEvent e
) {
105 xmlButton
= new Button(radioContainer
, SWT
.RADIO
);
106 xmlButton
.setText("XML"); //$NON-NLS-1$
107 xmlButton
.addSelectionListener(new SelectionListener() {
109 public void widgetDefaultSelected(SelectionEvent e
) {
113 public void widgetSelected(SelectionEvent e
) {
118 parserList
= new List(listContainer
, SWT
.SINGLE
| SWT
.BORDER
| SWT
.H_SCROLL
| SWT
.V_SCROLL
);
119 parserList
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
120 parserList
.addSelectionListener(new SelectionListener() {
122 public void widgetDefaultSelected(SelectionEvent e
) {}
125 public void widgetSelected(SelectionEvent e
) {
126 if (parserList
.getSelectionCount() == 0) {
127 editButton
.setEnabled(false);
128 deleteButton
.setEnabled(false);
129 exportButton
.setEnabled(false);
131 editButton
.setEnabled(true);
132 deleteButton
.setEnabled(true);
133 exportButton
.setEnabled(true);
138 Composite buttonContainer
= new Composite(composite
, SWT
.NULL
);
139 buttonContainer
.setLayout(new GridLayout());
140 buttonContainer
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.TOP
, false, false));
142 newButton
= new Button(buttonContainer
, SWT
.PUSH
);
143 newButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
144 newButton
.setText(Messages
.ManageCustomParsersDialog_NewButtonLabel
);
145 newButton
.addSelectionListener(new SelectionListener() {
147 public void widgetDefaultSelected(SelectionEvent e
) {}
150 public void widgetSelected(SelectionEvent e
) {
151 WizardDialog dialog
= null;
152 if (txtButton
.getSelection()) {
153 dialog
= new WizardDialog(getShell(), new CustomTxtParserWizard());
154 } else if (xmlButton
.getSelection()) {
155 dialog
= new WizardDialog(getShell(), new CustomXmlParserWizard());
157 if (dialog
!= null) {
159 if (dialog
.getReturnCode() == Window
.OK
) {
166 editButton
= new Button(buttonContainer
, SWT
.PUSH
);
167 editButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
168 editButton
.setText(Messages
.ManageCustomParsersDialog_EditButtonLabel
);
169 editButton
.setEnabled(false);
170 editButton
.addSelectionListener(new SelectionListener() {
172 public void widgetDefaultSelected(SelectionEvent e
) {}
175 public void widgetSelected(SelectionEvent e
) {
176 WizardDialog dialog
= null;
177 if (txtButton
.getSelection()) {
178 dialog
= new WizardDialog(getShell(),
179 new CustomTxtParserWizard(CustomTxtTraceDefinition
.load(parserList
.getSelection()[0])));
180 } else if (xmlButton
.getSelection()) {
181 dialog
= new WizardDialog(getShell(),
182 new CustomXmlParserWizard(CustomXmlTraceDefinition
.load(parserList
.getSelection()[0])));
184 if (dialog
!= null) {
186 if (dialog
.getReturnCode() == Window
.OK
) {
193 deleteButton
= new Button(buttonContainer
, SWT
.PUSH
);
194 deleteButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
195 deleteButton
.setText(Messages
.ManageCustomParsersDialog_DeleteButtonLabel
);
196 deleteButton
.setEnabled(false);
197 deleteButton
.addSelectionListener(new SelectionListener() {
199 public void widgetDefaultSelected(SelectionEvent e
) {}
202 public void widgetSelected(SelectionEvent e
) {
203 boolean confirm
= MessageDialog
.openQuestion(
205 Messages
.ManageCustomParsersDialog_DeleteParserDialogHeader
,
206 Messages
.ManageCustomParsersDialog_DeleteConfirmation
+ parserList
.getSelection()[0] + "?"); //$NON-NLS-1$
208 if (txtButton
.getSelection()) {
209 CustomTxtTraceDefinition
.delete(parserList
.getSelection()[0]);
210 } else if (xmlButton
.getSelection()) {
211 CustomXmlTraceDefinition
.delete(parserList
.getSelection()[0]);
218 new Label(buttonContainer
, SWT
.NONE
); // filler
220 importButton
= new Button(buttonContainer
, SWT
.PUSH
);
221 importButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
222 importButton
.setText(Messages
.ManageCustomParsersDialog_ImportButtonLabel
);
223 importButton
.addSelectionListener(new SelectionListener() {
225 public void widgetDefaultSelected(SelectionEvent e
) {}
228 public void widgetSelected(SelectionEvent e
) {
229 FileDialog dialog
= new FileDialog(Display
.getCurrent().getActiveShell(), SWT
.OPEN
);
230 dialog
.setText(Messages
.ManageCustomParsersDialog_ImportParserSelection
);
231 dialog
.setFilterExtensions(new String
[] { "*.xml", "*" }); //$NON-NLS-1$ //$NON-NLS-2$
232 String path
= dialog
.open();
234 CustomTraceDefinition
[] defs
= null;
235 if (txtButton
.getSelection()) {
236 defs
= CustomTxtTraceDefinition
.loadAll(path
);
237 } else if (xmlButton
.getSelection()) {
238 defs
= CustomXmlTraceDefinition
.loadAll(path
);
240 if (defs
!= null && defs
.length
> 0) {
241 for (CustomTraceDefinition def
: defs
) {
250 exportButton
= new Button(buttonContainer
, SWT
.PUSH
);
251 exportButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
252 exportButton
.setText(Messages
.ManageCustomParsersDialog_ExportButtonLabel
);
253 exportButton
.setEnabled(false);
254 exportButton
.addSelectionListener(new SelectionListener() {
256 public void widgetDefaultSelected(SelectionEvent e
) {}
259 public void widgetSelected(SelectionEvent e
) {
260 FileDialog dialog
= new FileDialog(Display
.getCurrent().getActiveShell(), SWT
.SAVE
);
261 dialog
.setText(Messages
.ManageCustomParsersDialog_ExportParserSelection
+ parserList
.getSelection()[0]);
262 dialog
.setFilterExtensions(new String
[] { "*.xml", "*" }); //$NON-NLS-1$ //$NON-NLS-2$
263 String path
= dialog
.open();
265 CustomTraceDefinition def
= null;
266 if (txtButton
.getSelection()) {
267 def
= CustomTxtTraceDefinition
.load(parserList
.getSelection()[0]);
268 } else if (xmlButton
.getSelection()) {
269 def
= CustomXmlTraceDefinition
.load(parserList
.getSelection()[0]);
280 getShell().setMinimumSize(300, 275);
285 protected void createButtonsForButtonBar(Composite parent
) {
286 createButton(parent
, IDialogConstants
.OK_ID
, IDialogConstants
.CLOSE_LABEL
, false);
289 private void fillParserList() {
290 parserList
.removeAll();
291 if (txtButton
.getSelection()) {
292 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
293 parserList
.add(def
.definitionName
);
295 } else if (xmlButton
.getSelection()) {
296 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
297 parserList
.add(def
.definitionName
);
300 editButton
.setEnabled(false);
301 deleteButton
.setEnabled(false);
302 exportButton
.setEnabled(false);