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
.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
.wizard
.WizardDialog
;
19 import org
.eclipse
.linuxtools
.tmf
.ui
.TmfUiPlugin
;
20 import org
.eclipse
.linuxtools
.tmf
.ui
.internal
.Messages
;
21 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomTraceDefinition
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomXmlTraceDefinition
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.wizards
.CustomTxtParserWizard
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.wizards
.CustomXmlParserWizard
;
26 import org
.eclipse
.swt
.SWT
;
27 import org
.eclipse
.swt
.events
.SelectionEvent
;
28 import org
.eclipse
.swt
.events
.SelectionListener
;
29 import org
.eclipse
.swt
.graphics
.Image
;
30 import org
.eclipse
.swt
.layout
.GridData
;
31 import org
.eclipse
.swt
.layout
.GridLayout
;
32 import org
.eclipse
.swt
.widgets
.Button
;
33 import org
.eclipse
.swt
.widgets
.Composite
;
34 import org
.eclipse
.swt
.widgets
.Control
;
35 import org
.eclipse
.swt
.widgets
.Display
;
36 import org
.eclipse
.swt
.widgets
.FileDialog
;
37 import org
.eclipse
.swt
.widgets
.Label
;
38 import org
.eclipse
.swt
.widgets
.List
;
39 import org
.eclipse
.swt
.widgets
.Shell
;
41 public class ManageCustomParsersDialog
extends Dialog
{
43 private static final Image image
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/etool16/customparser_wizard.gif"); //$NON-NLS-1$
54 public ManageCustomParsersDialog(Shell parent
) {
56 setShellStyle(SWT
.RESIZE
| SWT
.MAX
| getShellStyle());
60 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
63 protected Control
createDialogArea(Composite parent
) {
64 getShell().setText(Messages
.ManageCustomParsersDialog_DialogHeader
);
65 getShell().setImage(image
);
67 Composite composite
= (Composite
) super.createDialogArea(parent
);
68 composite
.setLayout(new GridLayout(2, false));
70 Composite listContainer
= new Composite(composite
, SWT
.NONE
);
71 listContainer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
72 GridLayout lcgl
= new GridLayout();
73 lcgl
.marginHeight
= 0;
75 listContainer
.setLayout(lcgl
);
77 Composite radioContainer
= new Composite(listContainer
, SWT
.NONE
);
78 GridLayout rcgl
= new GridLayout(2, true);
79 rcgl
.marginHeight
= 0;
81 radioContainer
.setLayout(rcgl
);
83 txtButton
= new Button(radioContainer
, SWT
.RADIO
);
84 txtButton
.setText(Messages
.ManageCustomParsersDialog_TextButtonLabel
);
85 txtButton
.setSelection(true);
86 txtButton
.addSelectionListener(new SelectionListener(){
88 public void widgetDefaultSelected(SelectionEvent e
) {}
90 public void widgetSelected(SelectionEvent e
) {
94 xmlButton
= new Button(radioContainer
, SWT
.RADIO
);
95 xmlButton
.setText("XML"); //$NON-NLS-1$
96 xmlButton
.addSelectionListener(new SelectionListener(){
98 public void widgetDefaultSelected(SelectionEvent e
) {}
100 public void widgetSelected(SelectionEvent e
) {
104 parserList
= new List(listContainer
, SWT
.SINGLE
| SWT
.BORDER
| SWT
.H_SCROLL
| SWT
.V_SCROLL
);
105 parserList
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
106 parserList
.addSelectionListener(new SelectionListener(){
108 public void widgetDefaultSelected(SelectionEvent e
) {}
110 public void widgetSelected(SelectionEvent e
) {
111 if (parserList
.getSelectionCount() == 0) {
112 editButton
.setEnabled(false);
113 deleteButton
.setEnabled(false);
114 exportButton
.setEnabled(false);
116 editButton
.setEnabled(true);
117 deleteButton
.setEnabled(true);
118 exportButton
.setEnabled(true);
122 Composite buttonContainer
= new Composite(composite
, SWT
.NULL
);
123 buttonContainer
.setLayout(new GridLayout());
124 buttonContainer
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.TOP
, false, false));
126 newButton
= new Button(buttonContainer
, SWT
.PUSH
);
127 newButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
128 newButton
.setText(Messages
.ManageCustomParsersDialog_NewButtonLabel
);
129 newButton
.addSelectionListener(new SelectionListener(){
131 public void widgetDefaultSelected(SelectionEvent e
) {}
133 public void widgetSelected(SelectionEvent e
) {
134 WizardDialog dialog
= null;
135 if (txtButton
.getSelection()) {
136 dialog
= new WizardDialog(getShell(), new CustomTxtParserWizard());
137 } else if (xmlButton
.getSelection()) {
138 dialog
= new WizardDialog(getShell(), new CustomXmlParserWizard());
140 if (dialog
!= null) {
142 if (dialog
.getReturnCode() == Dialog
.OK
) {
148 editButton
= new Button(buttonContainer
, SWT
.PUSH
);
149 editButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
150 editButton
.setText(Messages
.ManageCustomParsersDialog_EditButtonLabel
);
151 editButton
.setEnabled(false);
152 editButton
.addSelectionListener(new SelectionListener(){
154 public void widgetDefaultSelected(SelectionEvent e
) {}
156 public void widgetSelected(SelectionEvent e
) {
157 WizardDialog dialog
= null;
158 if (txtButton
.getSelection()) {
159 dialog
= new WizardDialog(getShell(),
160 new CustomTxtParserWizard(CustomTxtTraceDefinition
.load(parserList
.getSelection()[0])));
161 } else if (xmlButton
.getSelection()) {
162 dialog
= new WizardDialog(getShell(),
163 new CustomXmlParserWizard(CustomXmlTraceDefinition
.load(parserList
.getSelection()[0])));
165 if (dialog
!= null) {
167 if (dialog
.getReturnCode() == Dialog
.OK
) {
173 deleteButton
= new Button(buttonContainer
, SWT
.PUSH
);
174 deleteButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
175 deleteButton
.setText(Messages
.ManageCustomParsersDialog_DeleteButtonLabel
);
176 deleteButton
.setEnabled(false);
177 deleteButton
.addSelectionListener(new SelectionListener(){
179 public void widgetDefaultSelected(SelectionEvent e
) {}
181 public void widgetSelected(SelectionEvent e
) {
182 boolean confirm
= MessageDialog
.openQuestion(
184 Messages
.ManageCustomParsersDialog_DeleteParserDialogHeader
,
185 Messages
.ManageCustomParsersDialog_DeleteConfirmation
+ parserList
.getSelection()[0] + "?"); //$NON-NLS-1$
187 if (txtButton
.getSelection()) {
188 CustomTxtTraceDefinition
.delete(parserList
.getSelection()[0]);
189 } else if (xmlButton
.getSelection()) {
190 CustomXmlTraceDefinition
.delete(parserList
.getSelection()[0]);
196 new Label(buttonContainer
, SWT
.NONE
); // filler
198 importButton
= new Button(buttonContainer
, SWT
.PUSH
);
199 importButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
200 importButton
.setText(Messages
.ManageCustomParsersDialog_ImportButtonLabel
);
201 importButton
.addSelectionListener(new SelectionListener(){
203 public void widgetDefaultSelected(SelectionEvent e
) {}
205 public void widgetSelected(SelectionEvent e
) {
206 FileDialog dialog
= new FileDialog(Display
.getCurrent().getActiveShell(), SWT
.OPEN
);
207 dialog
.setText(Messages
.ManageCustomParsersDialog_ImportParserSelection
);
208 dialog
.setFilterExtensions(new String
[] {"*.xml", "*"}); //$NON-NLS-1$ //$NON-NLS-2$
209 String path
= dialog
.open();
211 CustomTraceDefinition
[] defs
= null;
212 if (txtButton
.getSelection()) {
213 defs
= CustomTxtTraceDefinition
.loadAll(path
);
214 } else if (xmlButton
.getSelection()) {
215 defs
= CustomXmlTraceDefinition
.loadAll(path
);
217 if (defs
!= null && defs
.length
> 0) {
218 for (CustomTraceDefinition def
: defs
) {
226 exportButton
= new Button(buttonContainer
, SWT
.PUSH
);
227 exportButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
228 exportButton
.setText(Messages
.ManageCustomParsersDialog_ExportButtonLabel
);
229 exportButton
.setEnabled(false);
230 exportButton
.addSelectionListener(new SelectionListener(){
232 public void widgetDefaultSelected(SelectionEvent e
) {}
234 public void widgetSelected(SelectionEvent e
) {
235 FileDialog dialog
= new FileDialog(Display
.getCurrent().getActiveShell(), SWT
.SAVE
);
236 dialog
.setText(Messages
.ManageCustomParsersDialog_ExportParserSelection
+ parserList
.getSelection()[0]);
237 dialog
.setFilterExtensions(new String
[] {"*.xml", "*"}); //$NON-NLS-1$ //$NON-NLS-2$
238 String path
= dialog
.open();
240 CustomTraceDefinition def
= null;
241 if (txtButton
.getSelection()) {
242 def
= CustomTxtTraceDefinition
.load(parserList
.getSelection()[0]);
243 } else if (xmlButton
.getSelection()) {
244 def
= CustomXmlTraceDefinition
.load(parserList
.getSelection()[0]);
254 getShell().setMinimumSize(300, 275);
259 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
262 protected void createButtonsForButtonBar(Composite parent
) {
263 createButton(parent
, IDialogConstants
.OK_ID
, IDialogConstants
.CLOSE_LABEL
, false);
266 private void fillParserList() {
267 parserList
.removeAll();
268 if (txtButton
.getSelection()) {
269 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
270 parserList
.add(def
.definitionName
);
272 } else if (xmlButton
.getSelection()) {
273 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
274 parserList
.add(def
.definitionName
);
277 editButton
.setEnabled(false);
278 deleteButton
.setEnabled(false);
279 exportButton
.setEnabled(false);