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());
141 if (dialog
.getReturnCode() == Dialog
.OK
) {
146 editButton
= new Button(buttonContainer
, SWT
.PUSH
);
147 editButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
148 editButton
.setText(Messages
.ManageCustomParsersDialog_EditButtonLabel
);
149 editButton
.setEnabled(false);
150 editButton
.addSelectionListener(new SelectionListener(){
152 public void widgetDefaultSelected(SelectionEvent e
) {}
154 public void widgetSelected(SelectionEvent e
) {
155 WizardDialog dialog
= null;
156 if (txtButton
.getSelection()) {
157 dialog
= new WizardDialog(getShell(),
158 new CustomTxtParserWizard(CustomTxtTraceDefinition
.load(parserList
.getSelection()[0])));
159 } else if (xmlButton
.getSelection()) {
160 dialog
= new WizardDialog(getShell(),
161 new CustomXmlParserWizard(CustomXmlTraceDefinition
.load(parserList
.getSelection()[0])));
164 if (dialog
.getReturnCode() == Dialog
.OK
) {
169 deleteButton
= new Button(buttonContainer
, SWT
.PUSH
);
170 deleteButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
171 deleteButton
.setText(Messages
.ManageCustomParsersDialog_DeleteButtonLabel
);
172 deleteButton
.setEnabled(false);
173 deleteButton
.addSelectionListener(new SelectionListener(){
175 public void widgetDefaultSelected(SelectionEvent e
) {}
177 public void widgetSelected(SelectionEvent e
) {
178 boolean confirm
= MessageDialog
.openQuestion(
180 Messages
.ManageCustomParsersDialog_DeleteParserDialogHeader
,
181 Messages
.ManageCustomParsersDialog_DeleteConfirmation
+ parserList
.getSelection()[0] + "?"); //$NON-NLS-1$
183 if (txtButton
.getSelection()) {
184 CustomTxtTraceDefinition
.delete(parserList
.getSelection()[0]);
185 } else if (xmlButton
.getSelection()) {
186 CustomXmlTraceDefinition
.delete(parserList
.getSelection()[0]);
192 new Label(buttonContainer
, SWT
.NONE
); // filler
194 importButton
= new Button(buttonContainer
, SWT
.PUSH
);
195 importButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
196 importButton
.setText(Messages
.ManageCustomParsersDialog_ImportButtonLabel
);
197 importButton
.addSelectionListener(new SelectionListener(){
199 public void widgetDefaultSelected(SelectionEvent e
) {}
201 public void widgetSelected(SelectionEvent e
) {
202 FileDialog dialog
= new FileDialog(Display
.getCurrent().getActiveShell(), SWT
.OPEN
);
203 dialog
.setText(Messages
.ManageCustomParsersDialog_ImportParserSelection
);
204 dialog
.setFilterExtensions(new String
[] {"*.xml", "*"}); //$NON-NLS-1$ //$NON-NLS-2$
205 String path
= dialog
.open();
207 CustomTraceDefinition
[] defs
= null;
208 if (txtButton
.getSelection()) {
209 defs
= CustomTxtTraceDefinition
.loadAll(path
);
210 } else if (xmlButton
.getSelection()) {
211 defs
= CustomXmlTraceDefinition
.loadAll(path
);
213 if (defs
!= null && defs
.length
> 0) {
214 for (CustomTraceDefinition def
: defs
) {
222 exportButton
= new Button(buttonContainer
, SWT
.PUSH
);
223 exportButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
224 exportButton
.setText(Messages
.ManageCustomParsersDialog_ExportButtonLabel
);
225 exportButton
.setEnabled(false);
226 exportButton
.addSelectionListener(new SelectionListener(){
228 public void widgetDefaultSelected(SelectionEvent e
) {}
230 public void widgetSelected(SelectionEvent e
) {
231 FileDialog dialog
= new FileDialog(Display
.getCurrent().getActiveShell(), SWT
.SAVE
);
232 dialog
.setText(Messages
.ManageCustomParsersDialog_ExportParserSelection
+ parserList
.getSelection()[0]);
233 dialog
.setFilterExtensions(new String
[] {"*.xml", "*"}); //$NON-NLS-1$ //$NON-NLS-2$
234 String path
= dialog
.open();
236 CustomTraceDefinition def
= null;
237 if (txtButton
.getSelection()) {
238 def
= CustomTxtTraceDefinition
.load(parserList
.getSelection()[0]);
239 } else if (xmlButton
.getSelection()) {
240 def
= CustomXmlTraceDefinition
.load(parserList
.getSelection()[0]);
250 getShell().setMinimumSize(300, 275);
255 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
258 protected void createButtonsForButtonBar(Composite parent
) {
259 createButton(parent
, IDialogConstants
.OK_ID
, IDialogConstants
.CLOSE_LABEL
, false);
262 private void fillParserList() {
263 parserList
.removeAll();
264 if (txtButton
.getSelection()) {
265 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
266 parserList
.add(def
.definitionName
);
268 } else if (xmlButton
.getSelection()) {
269 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
270 parserList
.add(def
.definitionName
);
273 editButton
.setEnabled(false);
274 deleteButton
.setEnabled(false);
275 exportButton
.setEnabled(false);