Commit | Line | Data |
---|---|---|
c3c5c786 FC |
1 | /*******************************************************************************\r |
2 | * Copyright (c) 2010 Ericsson\r | |
abbdd66a | 3 | *\r |
c3c5c786 FC |
4 | * All rights reserved. This program and the accompanying materials are\r |
5 | * made available under the terms of the Eclipse Public License v1.0 which\r | |
6 | * accompanies this distribution, and is available at\r | |
7 | * http://www.eclipse.org/legal/epl-v10.html\r | |
abbdd66a | 8 | *\r |
c3c5c786 FC |
9 | * Contributors:\r |
10 | * Patrick Tasse - Initial API and implementation\r | |
11 | *******************************************************************************/\r | |
12 | \r | |
d34665f9 | 13 | package org.eclipse.linuxtools.internal.tmf.ui.dialogs;\r |
c3c5c786 | 14 | \r |
c3c5c786 FC |
15 | import org.eclipse.jface.dialogs.Dialog;\r |
16 | import org.eclipse.jface.dialogs.IDialogConstants;\r | |
17 | import org.eclipse.jface.dialogs.MessageDialog;\r | |
abbdd66a | 18 | import org.eclipse.jface.window.Window;\r |
c3c5c786 | 19 | import org.eclipse.jface.wizard.WizardDialog;\r |
8fd82db5 | 20 | import org.eclipse.linuxtools.internal.tmf.ui.Activator;\r |
abbdd66a | 21 | import org.eclipse.linuxtools.internal.tmf.ui.Messages;\r |
d34665f9 FC |
22 | import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition;\r |
23 | import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition;\r | |
24 | import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition;\r | |
25 | import org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards.CustomTxtParserWizard;\r | |
26 | import org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards.CustomXmlParserWizard;\r | |
c3c5c786 FC |
27 | import org.eclipse.swt.SWT;\r |
28 | import org.eclipse.swt.events.SelectionEvent;\r | |
29 | import org.eclipse.swt.events.SelectionListener;\r | |
30 | import org.eclipse.swt.graphics.Image;\r | |
31 | import org.eclipse.swt.layout.GridData;\r | |
32 | import org.eclipse.swt.layout.GridLayout;\r | |
33 | import org.eclipse.swt.widgets.Button;\r | |
34 | import org.eclipse.swt.widgets.Composite;\r | |
35 | import org.eclipse.swt.widgets.Control;\r | |
36 | import org.eclipse.swt.widgets.Display;\r | |
37 | import org.eclipse.swt.widgets.FileDialog;\r | |
38 | import org.eclipse.swt.widgets.Label;\r | |
39 | import org.eclipse.swt.widgets.List;\r | |
40 | import org.eclipse.swt.widgets.Shell;\r | |
c3c5c786 FC |
41 | \r |
42 | public class ManageCustomParsersDialog extends Dialog {\r | |
43 | \r | |
8fd82db5 | 44 | private static final Image image = Activator.getDefault().getImageFromPath("/icons/etool16/customparser_wizard.gif"); //$NON-NLS-1$\r |
c3c5c786 FC |
45 | \r |
46 | Button txtButton;\r | |
47 | Button xmlButton;\r | |
48 | List parserList;\r | |
49 | Button newButton;\r | |
50 | Button editButton;\r | |
51 | Button deleteButton;\r | |
52 | Button importButton;\r | |
53 | Button exportButton;\r | |
abbdd66a | 54 | \r |
c3c5c786 FC |
55 | public ManageCustomParsersDialog(Shell parent) {\r |
56 | super(parent);\r | |
57 | setShellStyle(SWT.RESIZE | SWT.MAX | getShellStyle());\r | |
58 | }\r | |
59 | \r | |
60 | /* (non-Javadoc)\r | |
61 | * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)\r | |
62 | */\r | |
63 | @Override\r | |
64 | protected Control createDialogArea(Composite parent) {\r | |
b9763f53 | 65 | getShell().setText(Messages.ManageCustomParsersDialog_DialogHeader);\r |
c3c5c786 | 66 | getShell().setImage(image);\r |
abbdd66a | 67 | \r |
c3c5c786 FC |
68 | Composite composite = (Composite) super.createDialogArea(parent);\r |
69 | composite.setLayout(new GridLayout(2, false));\r | |
70 | \r | |
71 | Composite listContainer = new Composite(composite, SWT.NONE);\r | |
72 | listContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r | |
73 | GridLayout lcgl = new GridLayout();\r | |
74 | lcgl.marginHeight = 0;\r | |
75 | lcgl.marginWidth = 0;\r | |
76 | listContainer.setLayout(lcgl);\r | |
abbdd66a | 77 | \r |
c3c5c786 FC |
78 | Composite radioContainer = new Composite(listContainer, SWT.NONE);\r |
79 | GridLayout rcgl = new GridLayout(2, true);\r | |
80 | rcgl.marginHeight = 0;\r | |
81 | rcgl.marginWidth = 0;\r | |
82 | radioContainer.setLayout(rcgl);\r | |
abbdd66a | 83 | \r |
c3c5c786 | 84 | txtButton = new Button(radioContainer, SWT.RADIO);\r |
b9763f53 | 85 | txtButton.setText(Messages.ManageCustomParsersDialog_TextButtonLabel);\r |
c3c5c786 FC |
86 | txtButton.setSelection(true);\r |
87 | txtButton.addSelectionListener(new SelectionListener(){\r | |
d4011df2 FC |
88 | @Override\r |
89 | public void widgetDefaultSelected(SelectionEvent e) {}\r | |
90 | @Override\r | |
91 | public void widgetSelected(SelectionEvent e) {\r | |
c3c5c786 FC |
92 | fillParserList();\r |
93 | }});\r | |
abbdd66a | 94 | \r |
c3c5c786 | 95 | xmlButton = new Button(radioContainer, SWT.RADIO);\r |
3b38ea61 | 96 | xmlButton.setText("XML"); //$NON-NLS-1$\r |
c3c5c786 | 97 | xmlButton.addSelectionListener(new SelectionListener(){\r |
d4011df2 FC |
98 | @Override\r |
99 | public void widgetDefaultSelected(SelectionEvent e) {}\r | |
100 | @Override\r | |
101 | public void widgetSelected(SelectionEvent e) {\r | |
c3c5c786 FC |
102 | fillParserList();\r |
103 | }});\r | |
abbdd66a | 104 | \r |
c3c5c786 FC |
105 | parserList = new List(listContainer, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);\r |
106 | parserList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r | |
107 | parserList.addSelectionListener(new SelectionListener(){\r | |
d4011df2 FC |
108 | @Override\r |
109 | public void widgetDefaultSelected(SelectionEvent e) {}\r | |
110 | @Override\r | |
111 | public void widgetSelected(SelectionEvent e) {\r | |
c3c5c786 FC |
112 | if (parserList.getSelectionCount() == 0) {\r |
113 | editButton.setEnabled(false);\r | |
114 | deleteButton.setEnabled(false);\r | |
115 | exportButton.setEnabled(false);\r | |
c3c5c786 FC |
116 | } else {\r |
117 | editButton.setEnabled(true);\r | |
118 | deleteButton.setEnabled(true);\r | |
119 | exportButton.setEnabled(true);\r | |
c3c5c786 FC |
120 | }\r |
121 | }});\r | |
abbdd66a | 122 | \r |
c3c5c786 FC |
123 | Composite buttonContainer = new Composite(composite, SWT.NULL);\r |
124 | buttonContainer.setLayout(new GridLayout());\r | |
125 | buttonContainer.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, false, false));\r | |
126 | \r | |
127 | newButton = new Button(buttonContainer, SWT.PUSH);\r | |
128 | newButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));\r | |
b9763f53 | 129 | newButton.setText(Messages.ManageCustomParsersDialog_NewButtonLabel);\r |
c3c5c786 | 130 | newButton.addSelectionListener(new SelectionListener(){\r |
d4011df2 FC |
131 | @Override\r |
132 | public void widgetDefaultSelected(SelectionEvent e) {}\r | |
133 | @Override\r | |
134 | public void widgetSelected(SelectionEvent e) {\r | |
c3c5c786 FC |
135 | WizardDialog dialog = null;\r |
136 | if (txtButton.getSelection()) {\r | |
137 | dialog = new WizardDialog(getShell(), new CustomTxtParserWizard());\r | |
138 | } else if (xmlButton.getSelection()) {\r | |
139 | dialog = new WizardDialog(getShell(), new CustomXmlParserWizard());\r | |
140 | }\r | |
f9a8715c FC |
141 | if (dialog != null) {\r |
142 | dialog.open();\r | |
abbdd66a | 143 | if (dialog.getReturnCode() == Window.OK) {\r |
f9a8715c FC |
144 | fillParserList();\r |
145 | }\r | |
c3c5c786 FC |
146 | }\r |
147 | }});\r | |
abbdd66a | 148 | \r |
c3c5c786 FC |
149 | editButton = new Button(buttonContainer, SWT.PUSH);\r |
150 | editButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));\r | |
b9763f53 | 151 | editButton.setText(Messages.ManageCustomParsersDialog_EditButtonLabel);\r |
c3c5c786 FC |
152 | editButton.setEnabled(false);\r |
153 | editButton.addSelectionListener(new SelectionListener(){\r | |
d4011df2 FC |
154 | @Override\r |
155 | public void widgetDefaultSelected(SelectionEvent e) {}\r | |
156 | @Override\r | |
157 | public void widgetSelected(SelectionEvent e) {\r | |
c3c5c786 FC |
158 | WizardDialog dialog = null;\r |
159 | if (txtButton.getSelection()) {\r | |
160 | dialog = new WizardDialog(getShell(),\r | |
161 | new CustomTxtParserWizard(CustomTxtTraceDefinition.load(parserList.getSelection()[0])));\r | |
162 | } else if (xmlButton.getSelection()) {\r | |
163 | dialog = new WizardDialog(getShell(),\r | |
164 | new CustomXmlParserWizard(CustomXmlTraceDefinition.load(parserList.getSelection()[0])));\r | |
165 | }\r | |
f9a8715c FC |
166 | if (dialog != null) {\r |
167 | dialog.open();\r | |
abbdd66a | 168 | if (dialog.getReturnCode() == Window.OK) {\r |
f9a8715c FC |
169 | fillParserList();\r |
170 | }\r | |
c3c5c786 FC |
171 | }\r |
172 | }});\r | |
173 | \r | |
174 | deleteButton = new Button(buttonContainer, SWT.PUSH);\r | |
175 | deleteButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));\r | |
b9763f53 | 176 | deleteButton.setText(Messages.ManageCustomParsersDialog_DeleteButtonLabel);\r |
c3c5c786 FC |
177 | deleteButton.setEnabled(false);\r |
178 | deleteButton.addSelectionListener(new SelectionListener(){\r | |
d4011df2 FC |
179 | @Override\r |
180 | public void widgetDefaultSelected(SelectionEvent e) {}\r | |
181 | @Override\r | |
182 | public void widgetSelected(SelectionEvent e) {\r | |
c3c5c786 FC |
183 | boolean confirm = MessageDialog.openQuestion(\r |
184 | getShell(),\r | |
b9763f53 FC |
185 | Messages.ManageCustomParsersDialog_DeleteParserDialogHeader,\r |
186 | Messages.ManageCustomParsersDialog_DeleteConfirmation + parserList.getSelection()[0] + "?"); //$NON-NLS-1$\r | |
c3c5c786 FC |
187 | if (confirm) {\r |
188 | if (txtButton.getSelection()) {\r | |
189 | CustomTxtTraceDefinition.delete(parserList.getSelection()[0]);\r | |
190 | } else if (xmlButton.getSelection()) {\r | |
191 | CustomXmlTraceDefinition.delete(parserList.getSelection()[0]);\r | |
192 | }\r | |
193 | fillParserList();\r | |
194 | }\r | |
195 | }});\r | |
196 | \r | |
197 | new Label(buttonContainer, SWT.NONE); // filler\r | |
abbdd66a | 198 | \r |
c3c5c786 FC |
199 | importButton = new Button(buttonContainer, SWT.PUSH);\r |
200 | importButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));\r | |
b9763f53 | 201 | importButton.setText(Messages.ManageCustomParsersDialog_ImportButtonLabel);\r |
c3c5c786 | 202 | importButton.addSelectionListener(new SelectionListener(){\r |
d4011df2 FC |
203 | @Override\r |
204 | public void widgetDefaultSelected(SelectionEvent e) {}\r | |
205 | @Override\r | |
206 | public void widgetSelected(SelectionEvent e) {\r | |
c3c5c786 | 207 | FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.OPEN);\r |
b9763f53 | 208 | dialog.setText(Messages.ManageCustomParsersDialog_ImportParserSelection);\r |
3b38ea61 | 209 | dialog.setFilterExtensions(new String[] {"*.xml", "*"}); //$NON-NLS-1$ //$NON-NLS-2$\r |
c3c5c786 FC |
210 | String path = dialog.open();\r |
211 | if (path != null) {\r | |
212 | CustomTraceDefinition[] defs = null;\r | |
213 | if (txtButton.getSelection()) {\r | |
214 | defs = CustomTxtTraceDefinition.loadAll(path);\r | |
215 | } else if (xmlButton.getSelection()) {\r | |
216 | defs = CustomXmlTraceDefinition.loadAll(path);\r | |
217 | }\r | |
218 | if (defs != null && defs.length > 0) {\r | |
219 | for (CustomTraceDefinition def : defs) {\r | |
220 | def.save();\r | |
221 | }\r | |
222 | fillParserList();\r | |
223 | }\r | |
224 | }\r | |
225 | }});\r | |
226 | \r | |
227 | exportButton = new Button(buttonContainer, SWT.PUSH);\r | |
228 | exportButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));\r | |
b9763f53 | 229 | exportButton.setText(Messages.ManageCustomParsersDialog_ExportButtonLabel);\r |
c3c5c786 FC |
230 | exportButton.setEnabled(false);\r |
231 | exportButton.addSelectionListener(new SelectionListener(){\r | |
d4011df2 FC |
232 | @Override\r |
233 | public void widgetDefaultSelected(SelectionEvent e) {}\r | |
234 | @Override\r | |
235 | public void widgetSelected(SelectionEvent e) {\r | |
c3c5c786 | 236 | FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);\r |
b9763f53 | 237 | dialog.setText(Messages.ManageCustomParsersDialog_ExportParserSelection + parserList.getSelection()[0]);\r |
3b38ea61 | 238 | dialog.setFilterExtensions(new String[] {"*.xml", "*"}); //$NON-NLS-1$ //$NON-NLS-2$\r |
c3c5c786 FC |
239 | String path = dialog.open();\r |
240 | if (path != null) {\r | |
241 | CustomTraceDefinition def = null;\r | |
242 | if (txtButton.getSelection()) {\r | |
243 | def = CustomTxtTraceDefinition.load(parserList.getSelection()[0]);\r | |
244 | } else if (xmlButton.getSelection()) {\r | |
245 | def = CustomXmlTraceDefinition.load(parserList.getSelection()[0]);\r | |
246 | }\r | |
247 | if (def != null) {\r | |
248 | def.save(path);\r | |
249 | }\r | |
250 | }\r | |
251 | }});\r | |
252 | \r | |
c3c5c786 FC |
253 | fillParserList();\r |
254 | \r | |
255 | getShell().setMinimumSize(300, 275);\r | |
256 | return composite;\r | |
257 | }\r | |
258 | \r | |
259 | /* (non-Javadoc)\r | |
260 | * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)\r | |
261 | */\r | |
262 | @Override\r | |
263 | protected void createButtonsForButtonBar(Composite parent) {\r | |
264 | createButton(parent, IDialogConstants.OK_ID, IDialogConstants.CLOSE_LABEL, false);\r | |
265 | }\r | |
266 | \r | |
267 | private void fillParserList() {\r | |
268 | parserList.removeAll();\r | |
269 | if (txtButton.getSelection()) {\r | |
270 | for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {\r | |
271 | parserList.add(def.definitionName);\r | |
272 | }\r | |
273 | } else if (xmlButton.getSelection()) {\r | |
274 | for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {\r | |
275 | parserList.add(def.definitionName);\r | |
276 | }\r | |
277 | }\r | |
278 | editButton.setEnabled(false);\r | |
279 | deleteButton.setEnabled(false);\r | |
280 | exportButton.setEnabled(false);\r | |
c3c5c786 FC |
281 | }\r |
282 | \r | |
283 | }\r |