tmf: Simple warning fixes in tmf.core and tests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / dialogs / ManageCustomParsersDialog.java
1 /*******************************************************************************
2 * Copyright (c) 2010 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.internal.tmf.ui.dialogs;
14
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.internal.tmf.ui.Messages;
20 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
21 import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition;
22 import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition;
23 import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition;
24 import org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards.CustomTxtParserWizard;
25 import org.eclipse.linuxtools.internal.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;
40
41 public class ManageCustomParsersDialog extends Dialog {
42
43 private static final Image image = Activator.getDefault().getImageFromPath("/icons/etool16/customparser_wizard.gif"); //$NON-NLS-1$
44
45 Button txtButton;
46 Button xmlButton;
47 List parserList;
48 Button newButton;
49 Button editButton;
50 Button deleteButton;
51 Button importButton;
52 Button exportButton;
53
54 public ManageCustomParsersDialog(Shell parent) {
55 super(parent);
56 setShellStyle(SWT.RESIZE | SWT.MAX | getShellStyle());
57 }
58
59 /* (non-Javadoc)
60 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
61 */
62 @Override
63 protected Control createDialogArea(Composite parent) {
64 getShell().setText(Messages.ManageCustomParsersDialog_DialogHeader);
65 getShell().setImage(image);
66
67 Composite composite = (Composite) super.createDialogArea(parent);
68 composite.setLayout(new GridLayout(2, false));
69
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;
74 lcgl.marginWidth = 0;
75 listContainer.setLayout(lcgl);
76
77 Composite radioContainer = new Composite(listContainer, SWT.NONE);
78 GridLayout rcgl = new GridLayout(2, true);
79 rcgl.marginHeight = 0;
80 rcgl.marginWidth = 0;
81 radioContainer.setLayout(rcgl);
82
83 txtButton = new Button(radioContainer, SWT.RADIO);
84 txtButton.setText(Messages.ManageCustomParsersDialog_TextButtonLabel);
85 txtButton.setSelection(true);
86 txtButton.addSelectionListener(new SelectionListener(){
87 @Override
88 public void widgetDefaultSelected(SelectionEvent e) {}
89 @Override
90 public void widgetSelected(SelectionEvent e) {
91 fillParserList();
92 }});
93
94 xmlButton = new Button(radioContainer, SWT.RADIO);
95 xmlButton.setText("XML"); //$NON-NLS-1$
96 xmlButton.addSelectionListener(new SelectionListener(){
97 @Override
98 public void widgetDefaultSelected(SelectionEvent e) {}
99 @Override
100 public void widgetSelected(SelectionEvent e) {
101 fillParserList();
102 }});
103
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(){
107 @Override
108 public void widgetDefaultSelected(SelectionEvent e) {}
109 @Override
110 public void widgetSelected(SelectionEvent e) {
111 if (parserList.getSelectionCount() == 0) {
112 editButton.setEnabled(false);
113 deleteButton.setEnabled(false);
114 exportButton.setEnabled(false);
115 } else {
116 editButton.setEnabled(true);
117 deleteButton.setEnabled(true);
118 exportButton.setEnabled(true);
119 }
120 }});
121
122 Composite buttonContainer = new Composite(composite, SWT.NULL);
123 buttonContainer.setLayout(new GridLayout());
124 buttonContainer.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, false, false));
125
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(){
130 @Override
131 public void widgetDefaultSelected(SelectionEvent e) {}
132 @Override
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());
139 }
140 if (dialog != null) {
141 dialog.open();
142 if (dialog.getReturnCode() == Dialog.OK) {
143 fillParserList();
144 }
145 }
146 }});
147
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(){
153 @Override
154 public void widgetDefaultSelected(SelectionEvent e) {}
155 @Override
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])));
164 }
165 if (dialog != null) {
166 dialog.open();
167 if (dialog.getReturnCode() == Dialog.OK) {
168 fillParserList();
169 }
170 }
171 }});
172
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(){
178 @Override
179 public void widgetDefaultSelected(SelectionEvent e) {}
180 @Override
181 public void widgetSelected(SelectionEvent e) {
182 boolean confirm = MessageDialog.openQuestion(
183 getShell(),
184 Messages.ManageCustomParsersDialog_DeleteParserDialogHeader,
185 Messages.ManageCustomParsersDialog_DeleteConfirmation + parserList.getSelection()[0] + "?"); //$NON-NLS-1$
186 if (confirm) {
187 if (txtButton.getSelection()) {
188 CustomTxtTraceDefinition.delete(parserList.getSelection()[0]);
189 } else if (xmlButton.getSelection()) {
190 CustomXmlTraceDefinition.delete(parserList.getSelection()[0]);
191 }
192 fillParserList();
193 }
194 }});
195
196 new Label(buttonContainer, SWT.NONE); // filler
197
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(){
202 @Override
203 public void widgetDefaultSelected(SelectionEvent e) {}
204 @Override
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();
210 if (path != null) {
211 CustomTraceDefinition[] defs = null;
212 if (txtButton.getSelection()) {
213 defs = CustomTxtTraceDefinition.loadAll(path);
214 } else if (xmlButton.getSelection()) {
215 defs = CustomXmlTraceDefinition.loadAll(path);
216 }
217 if (defs != null && defs.length > 0) {
218 for (CustomTraceDefinition def : defs) {
219 def.save();
220 }
221 fillParserList();
222 }
223 }
224 }});
225
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(){
231 @Override
232 public void widgetDefaultSelected(SelectionEvent e) {}
233 @Override
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();
239 if (path != null) {
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]);
245 }
246 if (def != null) {
247 def.save(path);
248 }
249 }
250 }});
251
252 fillParserList();
253
254 getShell().setMinimumSize(300, 275);
255 return composite;
256 }
257
258 /* (non-Javadoc)
259 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
260 */
261 @Override
262 protected void createButtonsForButtonBar(Composite parent) {
263 createButton(parent, IDialogConstants.OK_ID, IDialogConstants.CLOSE_LABEL, false);
264 }
265
266 private void fillParserList() {
267 parserList.removeAll();
268 if (txtButton.getSelection()) {
269 for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
270 parserList.add(def.definitionName);
271 }
272 } else if (xmlButton.getSelection()) {
273 for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
274 parserList.add(def.definitionName);
275 }
276 }
277 editButton.setEnabled(false);
278 deleteButton.setEnabled(false);
279 exportButton.setEnabled(false);
280 }
281
282 }
This page took 0.036742 seconds and 5 git commands to generate.