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
;
17 import org
.eclipse
.core
.resources
.IFile
;
18 import org
.eclipse
.core
.resources
.IWorkspace
;
19 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
20 import org
.eclipse
.core
.runtime
.CoreException
;
21 import org
.eclipse
.core
.runtime
.IPath
;
22 import org
.eclipse
.core
.runtime
.Path
;
23 import org
.eclipse
.jface
.dialogs
.Dialog
;
24 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
25 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
26 import org
.eclipse
.jface
.wizard
.WizardDialog
;
27 import org
.eclipse
.linuxtools
.tmf
.ui
.TmfUiPlugin
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.editors
.TmfEventsEditor
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.ParserProviderManager
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomTraceDefinition
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomTxtTrace
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomXmlTrace
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomXmlTraceDefinition
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.project
.ProjectView
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.wizards
.CustomTxtParserWizard
;
37 import org
.eclipse
.linuxtools
.tmf
.ui
.wizards
.CustomXmlParserWizard
;
38 import org
.eclipse
.swt
.SWT
;
39 import org
.eclipse
.swt
.events
.SelectionEvent
;
40 import org
.eclipse
.swt
.events
.SelectionListener
;
41 import org
.eclipse
.swt
.graphics
.Image
;
42 import org
.eclipse
.swt
.layout
.GridData
;
43 import org
.eclipse
.swt
.layout
.GridLayout
;
44 import org
.eclipse
.swt
.widgets
.Button
;
45 import org
.eclipse
.swt
.widgets
.Composite
;
46 import org
.eclipse
.swt
.widgets
.Control
;
47 import org
.eclipse
.swt
.widgets
.Display
;
48 import org
.eclipse
.swt
.widgets
.FileDialog
;
49 import org
.eclipse
.swt
.widgets
.Label
;
50 import org
.eclipse
.swt
.widgets
.List
;
51 import org
.eclipse
.swt
.widgets
.Shell
;
52 import org
.eclipse
.ui
.IEditorInput
;
53 import org
.eclipse
.ui
.IEditorPart
;
54 import org
.eclipse
.ui
.IReusableEditor
;
55 import org
.eclipse
.ui
.IWorkbench
;
56 import org
.eclipse
.ui
.IWorkbenchPage
;
57 import org
.eclipse
.ui
.PlatformUI
;
58 import org
.eclipse
.ui
.part
.FileEditorInput
;
60 public class ManageCustomParsersDialog
extends Dialog
{
62 private static final Image image
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/customparser_wizard.gif");
74 public ManageCustomParsersDialog(Shell parent
) {
76 setShellStyle(SWT
.RESIZE
| SWT
.MAX
| getShellStyle());
80 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
83 protected Control
createDialogArea(Composite parent
) {
84 getShell().setText("Manage Custom Parsers");
85 getShell().setImage(image
);
87 Composite composite
= (Composite
) super.createDialogArea(parent
);
88 composite
.setLayout(new GridLayout(2, false));
90 Composite listContainer
= new Composite(composite
, SWT
.NONE
);
91 listContainer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
92 GridLayout lcgl
= new GridLayout();
93 lcgl
.marginHeight
= 0;
95 listContainer
.setLayout(lcgl
);
97 Composite radioContainer
= new Composite(listContainer
, SWT
.NONE
);
98 GridLayout rcgl
= new GridLayout(2, true);
99 rcgl
.marginHeight
= 0;
100 rcgl
.marginWidth
= 0;
101 radioContainer
.setLayout(rcgl
);
103 txtButton
= new Button(radioContainer
, SWT
.RADIO
);
104 txtButton
.setText("Text");
105 txtButton
.setSelection(true);
106 txtButton
.addSelectionListener(new SelectionListener(){
108 public void widgetDefaultSelected(SelectionEvent e
) {}
110 public void widgetSelected(SelectionEvent e
) {
114 xmlButton
= new Button(radioContainer
, SWT
.RADIO
);
115 xmlButton
.setText("XML");
116 xmlButton
.addSelectionListener(new SelectionListener(){
118 public void widgetDefaultSelected(SelectionEvent e
) {}
120 public void widgetSelected(SelectionEvent e
) {
124 parserList
= new List(listContainer
, SWT
.SINGLE
| SWT
.BORDER
| SWT
.H_SCROLL
| SWT
.V_SCROLL
);
125 parserList
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
126 parserList
.addSelectionListener(new SelectionListener(){
128 public void widgetDefaultSelected(SelectionEvent e
) {}
130 public void widgetSelected(SelectionEvent e
) {
131 if (parserList
.getSelectionCount() == 0) {
132 editButton
.setEnabled(false);
133 deleteButton
.setEnabled(false);
134 exportButton
.setEnabled(false);
135 parseButton
.setEnabled(false);
137 editButton
.setEnabled(true);
138 deleteButton
.setEnabled(true);
139 exportButton
.setEnabled(true);
140 parseButton
.setEnabled(true);
144 Composite buttonContainer
= new Composite(composite
, SWT
.NULL
);
145 buttonContainer
.setLayout(new GridLayout());
146 buttonContainer
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.TOP
, false, false));
148 newButton
= new Button(buttonContainer
, SWT
.PUSH
);
149 newButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
150 newButton
.setText("New...");
151 newButton
.addSelectionListener(new SelectionListener(){
153 public void widgetDefaultSelected(SelectionEvent e
) {}
155 public void widgetSelected(SelectionEvent e
) {
156 WizardDialog dialog
= null;
157 if (txtButton
.getSelection()) {
158 dialog
= new WizardDialog(getShell(), new CustomTxtParserWizard());
159 } else if (xmlButton
.getSelection()) {
160 dialog
= new WizardDialog(getShell(), new CustomXmlParserWizard());
163 if (dialog
.getReturnCode() == Dialog
.OK
) {
168 editButton
= new Button(buttonContainer
, SWT
.PUSH
);
169 editButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
170 editButton
.setText("Edit...");
171 editButton
.setEnabled(false);
172 editButton
.addSelectionListener(new SelectionListener(){
174 public void widgetDefaultSelected(SelectionEvent e
) {}
176 public void widgetSelected(SelectionEvent e
) {
177 WizardDialog dialog
= null;
178 if (txtButton
.getSelection()) {
179 dialog
= new WizardDialog(getShell(),
180 new CustomTxtParserWizard(CustomTxtTraceDefinition
.load(parserList
.getSelection()[0])));
181 } else if (xmlButton
.getSelection()) {
182 dialog
= new WizardDialog(getShell(),
183 new CustomXmlParserWizard(CustomXmlTraceDefinition
.load(parserList
.getSelection()[0])));
186 if (dialog
.getReturnCode() == Dialog
.OK
) {
191 deleteButton
= new Button(buttonContainer
, SWT
.PUSH
);
192 deleteButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
193 deleteButton
.setText("Delete");
194 deleteButton
.setEnabled(false);
195 deleteButton
.addSelectionListener(new SelectionListener(){
197 public void widgetDefaultSelected(SelectionEvent e
) {}
199 public void widgetSelected(SelectionEvent e
) {
200 boolean confirm
= MessageDialog
.openQuestion(
202 "Delete Custom Parser",
203 "Are you sure you want to delete the " + parserList
.getSelection()[0] + " custom parser?");
205 if (txtButton
.getSelection()) {
206 CustomTxtTraceDefinition
.delete(parserList
.getSelection()[0]);
207 } else if (xmlButton
.getSelection()) {
208 CustomXmlTraceDefinition
.delete(parserList
.getSelection()[0]);
214 new Label(buttonContainer
, SWT
.NONE
); // filler
216 importButton
= new Button(buttonContainer
, SWT
.PUSH
);
217 importButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
218 importButton
.setText("Import...");
219 importButton
.addSelectionListener(new SelectionListener(){
221 public void widgetDefaultSelected(SelectionEvent e
) {}
223 public void widgetSelected(SelectionEvent e
) {
224 FileDialog dialog
= new FileDialog(Display
.getCurrent().getActiveShell(), SWT
.OPEN
);
225 dialog
.setText("Select custom parser file to import");
226 dialog
.setFilterExtensions(new String
[] {"*.xml", "*"});
227 String path
= dialog
.open();
229 CustomTraceDefinition
[] defs
= null;
230 if (txtButton
.getSelection()) {
231 defs
= CustomTxtTraceDefinition
.loadAll(path
);
232 } else if (xmlButton
.getSelection()) {
233 defs
= CustomXmlTraceDefinition
.loadAll(path
);
235 if (defs
!= null && defs
.length
> 0) {
236 for (CustomTraceDefinition def
: defs
) {
244 exportButton
= new Button(buttonContainer
, SWT
.PUSH
);
245 exportButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
246 exportButton
.setText("Export...");
247 exportButton
.setEnabled(false);
248 exportButton
.addSelectionListener(new SelectionListener(){
250 public void widgetDefaultSelected(SelectionEvent e
) {}
252 public void widgetSelected(SelectionEvent e
) {
253 FileDialog dialog
= new FileDialog(Display
.getCurrent().getActiveShell(), SWT
.SAVE
);
254 dialog
.setText("Select file to export the " + parserList
.getSelection()[0] + " custom parser");
255 dialog
.setFilterExtensions(new String
[] {"*.xml", "*"});
256 String path
= dialog
.open();
258 CustomTraceDefinition def
= null;
259 if (txtButton
.getSelection()) {
260 def
= CustomTxtTraceDefinition
.load(parserList
.getSelection()[0]);
261 } else if (xmlButton
.getSelection()) {
262 def
= CustomXmlTraceDefinition
.load(parserList
.getSelection()[0]);
270 parseButton
= new Button(buttonContainer
, SWT
.PUSH
);
271 parseButton
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
272 parseButton
.setText("Parse...");
273 parseButton
.setEnabled(false);
274 parseButton
.addSelectionListener(new SelectionListener(){
276 public void widgetDefaultSelected(SelectionEvent e
) {}
278 public void widgetSelected(SelectionEvent e
) {
279 FileDialog dialog
= new FileDialog(Display
.getCurrent().getActiveShell(), SWT
.OPEN
);
280 dialog
.setText("Select log file to parse using the " + parserList
.getSelection()[0] + " custom parser");
281 if (xmlButton
.getSelection()) {
282 dialog
.setFilterExtensions(new String
[] {"*.xml", "*"});
284 String path
= dialog
.open();
285 String parser
= null;
287 CustomTraceDefinition def
= null;
288 if (txtButton
.getSelection()) {
289 def
= CustomTxtTraceDefinition
.load(parserList
.getSelection()[0]);
290 parser
= CustomTxtTrace
.class.getCanonicalName() + "." + def
.definitionName
;
291 } else if (xmlButton
.getSelection()) {
292 def
= CustomXmlTraceDefinition
.load(parserList
.getSelection()[0]);
293 parser
= CustomXmlTrace
.class.getCanonicalName() + "." + def
.definitionName
;
297 IWorkspace workspace
= ResourcesPlugin
.getWorkspace();
298 IPath location
= Path
.fromOSString(path
);
299 IFile file
= workspace
.getRoot().getFileForLocation(location
);
301 file
= ProjectView
.createLink(new File(location
.toPortableString()).toURI());
303 file
.setPersistentProperty(ParserProviderManager
.PARSER_PROPERTY
, parser
);
304 IEditorInput editorInput
= new FileEditorInput(file
);
305 IWorkbench wb
= PlatformUI
.getWorkbench();
306 IWorkbenchPage activePage
= wb
.getActiveWorkbenchWindow().getActivePage();
308 String editorId
= TmfEventsEditor
.ID
;
309 IEditorPart editor
= activePage
.findEditor(editorInput
);
310 if (editor
!= null && editor
instanceof IReusableEditor
) {
311 activePage
.reuseEditor((IReusableEditor
)editor
, editorInput
);
312 activePage
.activate(editor
);
314 editor
= activePage
.openEditor(editorInput
, editorId
);
316 } catch (CoreException e1
) {
317 MessageDialog
.openError(getShell(), "Parse Error", e1
.getMessage());
325 getShell().setMinimumSize(300, 275);
330 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
333 protected void createButtonsForButtonBar(Composite parent
) {
334 createButton(parent
, IDialogConstants
.OK_ID
, IDialogConstants
.CLOSE_LABEL
, false);
337 private void fillParserList() {
338 parserList
.removeAll();
339 if (txtButton
.getSelection()) {
340 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
341 parserList
.add(def
.definitionName
);
343 } else if (xmlButton
.getSelection()) {
344 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
345 parserList
.add(def
.definitionName
);
348 editButton
.setEnabled(false);
349 deleteButton
.setEnabled(false);
350 exportButton
.setEnabled(false);
351 parseButton
.setEnabled(false);