tmf/lttng: Remove unneeded (non-Javadoc) comments
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / dialogs / ManageCustomParsersDialog.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2013 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 /**
43 * Dialog for custom text parsers.
44 *
45 * @author Patrick Tassé
46 */
47 public class ManageCustomParsersDialog extends Dialog {
48
49 private static final Image image = Activator.getDefault().getImageFromPath("/icons/etool16/customparser_wizard.gif"); //$NON-NLS-1$
50
51 Button txtButton;
52 Button xmlButton;
53 List parserList;
54 Button newButton;
55 Button editButton;
56 Button deleteButton;
57 Button importButton;
58 Button exportButton;
59
60 /**
61 * Constructor
62 *
63 * @param parent
64 * Parent shell of this dialog
65 */
66 public ManageCustomParsersDialog(Shell parent) {
67 super(parent);
68 setShellStyle(SWT.RESIZE | SWT.MAX | getShellStyle());
69 }
70
71 @Override
72 protected Control createDialogArea(Composite parent) {
73 getShell().setText(Messages.ManageCustomParsersDialog_DialogHeader);
74 getShell().setImage(image);
75
76 Composite composite = (Composite) super.createDialogArea(parent);
77 composite.setLayout(new GridLayout(2, false));
78
79 Composite listContainer = new Composite(composite, SWT.NONE);
80 listContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
81 GridLayout lcgl = new GridLayout();
82 lcgl.marginHeight = 0;
83 lcgl.marginWidth = 0;
84 listContainer.setLayout(lcgl);
85
86 Composite radioContainer = new Composite(listContainer, SWT.NONE);
87 GridLayout rcgl = new GridLayout(2, true);
88 rcgl.marginHeight = 0;
89 rcgl.marginWidth = 0;
90 radioContainer.setLayout(rcgl);
91
92 txtButton = new Button(radioContainer, SWT.RADIO);
93 txtButton.setText(Messages.ManageCustomParsersDialog_TextButtonLabel);
94 txtButton.setSelection(true);
95 txtButton.addSelectionListener(new SelectionListener() {
96 @Override
97 public void widgetDefaultSelected(SelectionEvent e) {}
98
99 @Override
100 public void widgetSelected(SelectionEvent e) {
101 fillParserList();
102 }
103 });
104
105 xmlButton = new Button(radioContainer, SWT.RADIO);
106 xmlButton.setText("XML"); //$NON-NLS-1$
107 xmlButton.addSelectionListener(new SelectionListener() {
108 @Override
109 public void widgetDefaultSelected(SelectionEvent e) {
110 }
111
112 @Override
113 public void widgetSelected(SelectionEvent e) {
114 fillParserList();
115 }
116 });
117
118 parserList = new List(listContainer, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
119 parserList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
120 parserList.addSelectionListener(new SelectionListener() {
121 @Override
122 public void widgetDefaultSelected(SelectionEvent e) {}
123
124 @Override
125 public void widgetSelected(SelectionEvent e) {
126 if (parserList.getSelectionCount() == 0) {
127 editButton.setEnabled(false);
128 deleteButton.setEnabled(false);
129 exportButton.setEnabled(false);
130 } else {
131 editButton.setEnabled(true);
132 deleteButton.setEnabled(true);
133 exportButton.setEnabled(true);
134 }
135 }
136 });
137
138 Composite buttonContainer = new Composite(composite, SWT.NULL);
139 buttonContainer.setLayout(new GridLayout());
140 buttonContainer.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, false, false));
141
142 newButton = new Button(buttonContainer, SWT.PUSH);
143 newButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
144 newButton.setText(Messages.ManageCustomParsersDialog_NewButtonLabel);
145 newButton.addSelectionListener(new SelectionListener() {
146 @Override
147 public void widgetDefaultSelected(SelectionEvent e) {}
148
149 @Override
150 public void widgetSelected(SelectionEvent e) {
151 WizardDialog dialog = null;
152 if (txtButton.getSelection()) {
153 dialog = new WizardDialog(getShell(), new CustomTxtParserWizard());
154 } else if (xmlButton.getSelection()) {
155 dialog = new WizardDialog(getShell(), new CustomXmlParserWizard());
156 }
157 if (dialog != null) {
158 dialog.open();
159 if (dialog.getReturnCode() == Window.OK) {
160 fillParserList();
161 }
162 }
163 }
164 });
165
166 editButton = new Button(buttonContainer, SWT.PUSH);
167 editButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
168 editButton.setText(Messages.ManageCustomParsersDialog_EditButtonLabel);
169 editButton.setEnabled(false);
170 editButton.addSelectionListener(new SelectionListener() {
171 @Override
172 public void widgetDefaultSelected(SelectionEvent e) {}
173
174 @Override
175 public void widgetSelected(SelectionEvent e) {
176 WizardDialog dialog = null;
177 if (txtButton.getSelection()) {
178 dialog = new WizardDialog(getShell(),
179 new CustomTxtParserWizard(CustomTxtTraceDefinition.load(parserList.getSelection()[0])));
180 } else if (xmlButton.getSelection()) {
181 dialog = new WizardDialog(getShell(),
182 new CustomXmlParserWizard(CustomXmlTraceDefinition.load(parserList.getSelection()[0])));
183 }
184 if (dialog != null) {
185 dialog.open();
186 if (dialog.getReturnCode() == Window.OK) {
187 fillParserList();
188 }
189 }
190 }
191 });
192
193 deleteButton = new Button(buttonContainer, SWT.PUSH);
194 deleteButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
195 deleteButton.setText(Messages.ManageCustomParsersDialog_DeleteButtonLabel);
196 deleteButton.setEnabled(false);
197 deleteButton.addSelectionListener(new SelectionListener() {
198 @Override
199 public void widgetDefaultSelected(SelectionEvent e) {}
200
201 @Override
202 public void widgetSelected(SelectionEvent e) {
203 boolean confirm = MessageDialog.openQuestion(
204 getShell(),
205 Messages.ManageCustomParsersDialog_DeleteParserDialogHeader,
206 Messages.ManageCustomParsersDialog_DeleteConfirmation + parserList.getSelection()[0] + "?"); //$NON-NLS-1$
207 if (confirm) {
208 if (txtButton.getSelection()) {
209 CustomTxtTraceDefinition.delete(parserList.getSelection()[0]);
210 } else if (xmlButton.getSelection()) {
211 CustomXmlTraceDefinition.delete(parserList.getSelection()[0]);
212 }
213 fillParserList();
214 }
215 }
216 });
217
218 new Label(buttonContainer, SWT.NONE); // filler
219
220 importButton = new Button(buttonContainer, SWT.PUSH);
221 importButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
222 importButton.setText(Messages.ManageCustomParsersDialog_ImportButtonLabel);
223 importButton.addSelectionListener(new SelectionListener() {
224 @Override
225 public void widgetDefaultSelected(SelectionEvent e) {}
226
227 @Override
228 public void widgetSelected(SelectionEvent e) {
229 FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.OPEN);
230 dialog.setText(Messages.ManageCustomParsersDialog_ImportParserSelection);
231 dialog.setFilterExtensions(new String[] { "*.xml", "*" }); //$NON-NLS-1$ //$NON-NLS-2$
232 String path = dialog.open();
233 if (path != null) {
234 CustomTraceDefinition[] defs = null;
235 if (txtButton.getSelection()) {
236 defs = CustomTxtTraceDefinition.loadAll(path);
237 } else if (xmlButton.getSelection()) {
238 defs = CustomXmlTraceDefinition.loadAll(path);
239 }
240 if (defs != null && defs.length > 0) {
241 for (CustomTraceDefinition def : defs) {
242 def.save();
243 }
244 fillParserList();
245 }
246 }
247 }
248 });
249
250 exportButton = new Button(buttonContainer, SWT.PUSH);
251 exportButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
252 exportButton.setText(Messages.ManageCustomParsersDialog_ExportButtonLabel);
253 exportButton.setEnabled(false);
254 exportButton.addSelectionListener(new SelectionListener() {
255 @Override
256 public void widgetDefaultSelected(SelectionEvent e) {}
257
258 @Override
259 public void widgetSelected(SelectionEvent e) {
260 FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
261 dialog.setText(Messages.ManageCustomParsersDialog_ExportParserSelection + parserList.getSelection()[0]);
262 dialog.setFilterExtensions(new String[] { "*.xml", "*" }); //$NON-NLS-1$ //$NON-NLS-2$
263 String path = dialog.open();
264 if (path != null) {
265 CustomTraceDefinition def = null;
266 if (txtButton.getSelection()) {
267 def = CustomTxtTraceDefinition.load(parserList.getSelection()[0]);
268 } else if (xmlButton.getSelection()) {
269 def = CustomXmlTraceDefinition.load(parserList.getSelection()[0]);
270 }
271 if (def != null) {
272 def.save(path);
273 }
274 }
275 }
276 });
277
278 fillParserList();
279
280 getShell().setMinimumSize(300, 275);
281 return composite;
282 }
283
284 @Override
285 protected void createButtonsForButtonBar(Composite parent) {
286 createButton(parent, IDialogConstants.OK_ID, IDialogConstants.CLOSE_LABEL, false);
287 }
288
289 private void fillParserList() {
290 parserList.removeAll();
291 if (txtButton.getSelection()) {
292 for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
293 parserList.add(def.definitionName);
294 }
295 } else if (xmlButton.getSelection()) {
296 for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
297 parserList.add(def.definitionName);
298 }
299 }
300 editButton.setEnabled(false);
301 deleteButton.setEnabled(false);
302 exportButton.setEnabled(false);
303 }
304
305 }
This page took 0.063283 seconds and 5 git commands to generate.