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