1 /*******************************************************************************
2 * Copyright (c) 2010 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
;
42 public class ManageCustomParsersDialog
extends Dialog
{
44 private static final Image image
= Activator
.getDefault().getImageFromPath("/icons/etool16/customparser_wizard.gif"); //$NON-NLS-1$
55 public ManageCustomParsersDialog(Shell parent
) {
57 setShellStyle(SWT
.RESIZE
| SWT
.MAX
| getShellStyle());
61 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
64 protected Control
createDialogArea(Composite parent
) {
65 getShell().setText(Messages
.ManageCustomParsersDialog_DialogHeader
);
66 getShell().setImage(image
);
68 Composite composite
= (Composite
) super.createDialogArea(parent
);
69 composite
.setLayout(new GridLayout(2, false));
71 Composite listContainer
= new Composite(composite
, SWT
.NONE
);
72 listContainer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
73 GridLayout lcgl
= new GridLayout();
74 lcgl
.marginHeight
= 0;
76 listContainer
.setLayout(lcgl
);
78 Composite radioContainer
= new Composite(listContainer
, SWT
.NONE
);
79 GridLayout rcgl
= new GridLayout(2, true);
80 rcgl
.marginHeight
= 0;
82 radioContainer
.setLayout(rcgl
);
84 txtButton
= new Button(radioContainer
, SWT
.RADIO
);
85 txtButton
.setText(Messages
.ManageCustomParsersDialog_TextButtonLabel
);
86 txtButton
.setSelection(true);
87 txtButton
.addSelectionListener(new SelectionListener(){
89 public void widgetDefaultSelected(SelectionEvent e
) {}
91 public void widgetSelected(SelectionEvent e
) {
95 xmlButton
= new Button(radioContainer
, SWT
.RADIO
);
96 xmlButton
.setText("XML"); //$NON-NLS-1$
97 xmlButton
.addSelectionListener(new SelectionListener(){
99 public void widgetDefaultSelected(SelectionEvent e
) {}
101 public void widgetSelected(SelectionEvent e
) {
105 parserList
= new List(listContainer
, SWT
.SINGLE
| SWT
.BORDER
| SWT
.H_SCROLL
| SWT
.V_SCROLL
);
106 parserList
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
107 parserList
.addSelectionListener(new SelectionListener(){
109 public void widgetDefaultSelected(SelectionEvent e
) {}
111 public void widgetSelected(SelectionEvent e
) {
112 if (parserList
.getSelectionCount() == 0) {
113 editButton
.setEnabled(false);
114 deleteButton
.setEnabled(false);
115 exportButton
.setEnabled(false);
117 editButton
.setEnabled(true);
118 deleteButton
.setEnabled(true);
119 exportButton
.setEnabled(true);
123 Composite buttonContainer
= new Composite(composite
, SWT
.NULL
);
124 buttonContainer
.setLayout(new GridLayout());
125 buttonContainer
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.TOP
, false, false));
127 newButton
= new Button(buttonContainer
, SWT
.PUSH
);
128 newButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
129 newButton
.setText(Messages
.ManageCustomParsersDialog_NewButtonLabel
);
130 newButton
.addSelectionListener(new SelectionListener(){
132 public void widgetDefaultSelected(SelectionEvent e
) {}
134 public void widgetSelected(SelectionEvent e
) {
135 WizardDialog dialog
= null;
136 if (txtButton
.getSelection()) {
137 dialog
= new WizardDialog(getShell(), new CustomTxtParserWizard());
138 } else if (xmlButton
.getSelection()) {
139 dialog
= new WizardDialog(getShell(), new CustomXmlParserWizard());
141 if (dialog
!= null) {
143 if (dialog
.getReturnCode() == Window
.OK
) {
149 editButton
= new Button(buttonContainer
, SWT
.PUSH
);
150 editButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
151 editButton
.setText(Messages
.ManageCustomParsersDialog_EditButtonLabel
);
152 editButton
.setEnabled(false);
153 editButton
.addSelectionListener(new SelectionListener(){
155 public void widgetDefaultSelected(SelectionEvent e
) {}
157 public void widgetSelected(SelectionEvent e
) {
158 WizardDialog dialog
= null;
159 if (txtButton
.getSelection()) {
160 dialog
= new WizardDialog(getShell(),
161 new CustomTxtParserWizard(CustomTxtTraceDefinition
.load(parserList
.getSelection()[0])));
162 } else if (xmlButton
.getSelection()) {
163 dialog
= new WizardDialog(getShell(),
164 new CustomXmlParserWizard(CustomXmlTraceDefinition
.load(parserList
.getSelection()[0])));
166 if (dialog
!= null) {
168 if (dialog
.getReturnCode() == Window
.OK
) {
174 deleteButton
= new Button(buttonContainer
, SWT
.PUSH
);
175 deleteButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
176 deleteButton
.setText(Messages
.ManageCustomParsersDialog_DeleteButtonLabel
);
177 deleteButton
.setEnabled(false);
178 deleteButton
.addSelectionListener(new SelectionListener(){
180 public void widgetDefaultSelected(SelectionEvent e
) {}
182 public void widgetSelected(SelectionEvent e
) {
183 boolean confirm
= MessageDialog
.openQuestion(
185 Messages
.ManageCustomParsersDialog_DeleteParserDialogHeader
,
186 Messages
.ManageCustomParsersDialog_DeleteConfirmation
+ parserList
.getSelection()[0] + "?"); //$NON-NLS-1$
188 if (txtButton
.getSelection()) {
189 CustomTxtTraceDefinition
.delete(parserList
.getSelection()[0]);
190 } else if (xmlButton
.getSelection()) {
191 CustomXmlTraceDefinition
.delete(parserList
.getSelection()[0]);
197 new Label(buttonContainer
, SWT
.NONE
); // filler
199 importButton
= new Button(buttonContainer
, SWT
.PUSH
);
200 importButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
201 importButton
.setText(Messages
.ManageCustomParsersDialog_ImportButtonLabel
);
202 importButton
.addSelectionListener(new SelectionListener(){
204 public void widgetDefaultSelected(SelectionEvent e
) {}
206 public void widgetSelected(SelectionEvent e
) {
207 FileDialog dialog
= new FileDialog(Display
.getCurrent().getActiveShell(), SWT
.OPEN
);
208 dialog
.setText(Messages
.ManageCustomParsersDialog_ImportParserSelection
);
209 dialog
.setFilterExtensions(new String
[] {"*.xml", "*"}); //$NON-NLS-1$ //$NON-NLS-2$
210 String path
= dialog
.open();
212 CustomTraceDefinition
[] defs
= null;
213 if (txtButton
.getSelection()) {
214 defs
= CustomTxtTraceDefinition
.loadAll(path
);
215 } else if (xmlButton
.getSelection()) {
216 defs
= CustomXmlTraceDefinition
.loadAll(path
);
218 if (defs
!= null && defs
.length
> 0) {
219 for (CustomTraceDefinition def
: defs
) {
227 exportButton
= new Button(buttonContainer
, SWT
.PUSH
);
228 exportButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
229 exportButton
.setText(Messages
.ManageCustomParsersDialog_ExportButtonLabel
);
230 exportButton
.setEnabled(false);
231 exportButton
.addSelectionListener(new SelectionListener(){
233 public void widgetDefaultSelected(SelectionEvent e
) {}
235 public void widgetSelected(SelectionEvent e
) {
236 FileDialog dialog
= new FileDialog(Display
.getCurrent().getActiveShell(), SWT
.SAVE
);
237 dialog
.setText(Messages
.ManageCustomParsersDialog_ExportParserSelection
+ parserList
.getSelection()[0]);
238 dialog
.setFilterExtensions(new String
[] {"*.xml", "*"}); //$NON-NLS-1$ //$NON-NLS-2$
239 String path
= dialog
.open();
241 CustomTraceDefinition def
= null;
242 if (txtButton
.getSelection()) {
243 def
= CustomTxtTraceDefinition
.load(parserList
.getSelection()[0]);
244 } else if (xmlButton
.getSelection()) {
245 def
= CustomXmlTraceDefinition
.load(parserList
.getSelection()[0]);
255 getShell().setMinimumSize(300, 275);
260 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
263 protected void createButtonsForButtonBar(Composite parent
) {
264 createButton(parent
, IDialogConstants
.OK_ID
, IDialogConstants
.CLOSE_LABEL
, false);
267 private void fillParserList() {
268 parserList
.removeAll();
269 if (txtButton
.getSelection()) {
270 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
271 parserList
.add(def
.definitionName
);
273 } else if (xmlButton
.getSelection()) {
274 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
275 parserList
.add(def
.definitionName
);
278 editButton
.setEnabled(false);
279 deleteButton
.setEnabled(false);
280 exportButton
.setEnabled(false);