\r
package org.eclipse.linuxtools.tmf.ui.dialogs;\r
\r
-import java.io.File;\r
-import java.net.URI;\r
-\r
-import org.eclipse.core.resources.IFile;\r
-import org.eclipse.core.resources.IFolder;\r
-import org.eclipse.core.resources.IProject;\r
-import org.eclipse.core.resources.IResource;\r
-import org.eclipse.core.resources.IWorkspace;\r
-import org.eclipse.core.resources.IWorkspaceRoot;\r
-import org.eclipse.core.resources.ResourcesPlugin;\r
-import org.eclipse.core.runtime.CoreException;\r
-import org.eclipse.core.runtime.IPath;\r
-import org.eclipse.core.runtime.Path;\r
-import org.eclipse.core.runtime.Status;\r
-import org.eclipse.core.runtime.preferences.IEclipsePreferences;\r
-import org.eclipse.core.runtime.preferences.InstanceScope;\r
import org.eclipse.jface.dialogs.Dialog;\r
import org.eclipse.jface.dialogs.IDialogConstants;\r
import org.eclipse.jface.dialogs.MessageDialog;\r
import org.eclipse.jface.wizard.WizardDialog;\r
import org.eclipse.linuxtools.tmf.ui.TmfUiPlugin;\r
-import org.eclipse.linuxtools.tmf.ui.TmfUiPreferenceInitializer;\r
-import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor;\r
import org.eclipse.linuxtools.tmf.ui.internal.Messages;\r
-import org.eclipse.linuxtools.tmf.ui.parsers.ParserProviderManager;\r
import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomTraceDefinition;\r
-import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomTxtTrace;\r
import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomTxtTraceDefinition;\r
-import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomXmlTrace;\r
import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomXmlTraceDefinition;\r
import org.eclipse.linuxtools.tmf.ui.parsers.wizards.CustomTxtParserWizard;\r
import org.eclipse.linuxtools.tmf.ui.parsers.wizards.CustomXmlParserWizard;\r
-import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;\r
import org.eclipse.swt.SWT;\r
import org.eclipse.swt.events.SelectionEvent;\r
import org.eclipse.swt.events.SelectionListener;\r
import org.eclipse.swt.widgets.Label;\r
import org.eclipse.swt.widgets.List;\r
import org.eclipse.swt.widgets.Shell;\r
-import org.eclipse.ui.IEditorInput;\r
-import org.eclipse.ui.IEditorPart;\r
-import org.eclipse.ui.IReusableEditor;\r
-import org.eclipse.ui.IWorkbench;\r
-import org.eclipse.ui.IWorkbenchPage;\r
-import org.eclipse.ui.PlatformUI;\r
-import org.eclipse.ui.part.FileEditorInput;\r
\r
public class ManageCustomParsersDialog extends Dialog {\r
\r
Button deleteButton;\r
Button importButton;\r
Button exportButton;\r
- Button parseButton;\r
\r
public ManageCustomParsersDialog(Shell parent) {\r
super(parent);\r
editButton.setEnabled(false);\r
deleteButton.setEnabled(false);\r
exportButton.setEnabled(false);\r
- parseButton.setEnabled(false);\r
} else {\r
editButton.setEnabled(true);\r
deleteButton.setEnabled(true);\r
exportButton.setEnabled(true);\r
- parseButton.setEnabled(true);\r
}\r
}});\r
\r
}\r
}});\r
\r
- parseButton = new Button(buttonContainer, SWT.PUSH);\r
- parseButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));\r
- parseButton.setText(Messages.ManageCustomParsersDialog_ParseButtonLabel);\r
- parseButton.setEnabled(false);\r
- parseButton.addSelectionListener(new SelectionListener(){\r
- @Override\r
- public void widgetDefaultSelected(SelectionEvent e) {}\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.OPEN);\r
- dialog.setText(Messages.ManageCustomParsersDialog_TraceSelection + parserList.getSelection()[0]);\r
- if (xmlButton.getSelection()) {\r
- dialog.setFilterExtensions(new String[] {"*.xml", "*"}); //$NON-NLS-1$ //$NON-NLS-2$\r
- }\r
- String path = dialog.open();\r
- String parser = null;\r
- if (path != null) {\r
- CustomTraceDefinition def = null;\r
- if (txtButton.getSelection()) {\r
- def = CustomTxtTraceDefinition.load(parserList.getSelection()[0]);\r
- parser = CustomTxtTrace.class.getCanonicalName() + "." + def.definitionName; //$NON-NLS-1$\r
- } else if (xmlButton.getSelection()) {\r
- def = CustomXmlTraceDefinition.load(parserList.getSelection()[0]);\r
- parser = CustomXmlTrace.class.getCanonicalName() + "." + def.definitionName; //$NON-NLS-1$\r
- }\r
- if (def != null) {\r
- try {\r
- IWorkspace workspace = ResourcesPlugin.getWorkspace();\r
- IPath location = Path.fromOSString(path);\r
- IFile file = workspace.getRoot().getFileForLocation(location);\r
- if (file == null) {\r
- file = createLink(new File(location.toPortableString()).toURI());\r
- }\r
- file.setPersistentProperty(ParserProviderManager.PARSER_PROPERTY, parser);\r
- IEditorInput editorInput = new FileEditorInput(file);\r
- IWorkbench wb = PlatformUI.getWorkbench();\r
- IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage();\r
- \r
- String editorId = TmfEventsEditor.ID;\r
- IEditorPart editor = activePage.findEditor(editorInput);\r
- if (editor != null && editor instanceof IReusableEditor) {\r
- activePage.reuseEditor((IReusableEditor)editor, editorInput);\r
- activePage.activate(editor);\r
- } else {\r
- editor = activePage.openEditor(editorInput, editorId);\r
- }\r
- } catch (CoreException e1) {\r
- MessageDialog.openError(getShell(), "Parse Error", e1.getMessage()); //$NON-NLS-1$\r
- }\r
- }\r
- }\r
- }});\r
-\r
fillParserList();\r
\r
getShell().setMinimumSize(300, 275);\r
return composite;\r
}\r
\r
- // /////////////////////////////////////////////////////////////////////////////\r
- // FIXME: Duplicated in TmfEventsEditor\r
- // From the legacy ProjectView\r
- // /////////////////////////////////////////////////////////////////////////////\r
-\r
- // ------------------------------------------------------------------------\r
- // Static methods\r
- // ------------------------------------------------------------------------\r
-\r
- static public IFolder getActiveProjectTracesFolder() {\r
- IEclipsePreferences node = new InstanceScope()\r
- .getNode(TmfUiPlugin.PLUGIN_ID);\r
- String activeProjectName = node.get(\r
- TmfUiPreferenceInitializer.ACTIVE_PROJECT_PREFERENCE,\r
- TmfUiPreferenceInitializer.ACTIVE_PROJECT_DEFAULT);\r
- IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();\r
- IProject[] projects = root.getProjects();\r
- for (IProject project : projects) {\r
- if (project.isAccessible()\r
- && project.getName().equals(activeProjectName)) {\r
- return project.getFolder(TmfTraceFolder.TRACE_FOLDER_NAME);\r
- }\r
- }\r
- return null;\r
- }\r
-\r
- static public IFile createLink(URI uri) throws CoreException {\r
- IFolder folder = getActiveProjectTracesFolder();\r
- if (folder == null || !folder.exists()) {\r
- throw new CoreException(new Status(Status.ERROR,\r
- TmfUiPlugin.PLUGIN_ID, "No active project set")); //$NON-NLS-1$\r
- }\r
- String path = uri.getPath();\r
- // TODO: support duplicate file names\r
- IFile file = folder.getFile(path.substring(path\r
- .lastIndexOf(Path.SEPARATOR)));\r
- if (!file.exists()) {\r
- file.createLink(uri, IResource.NONE, null);\r
- }\r
- return file;\r
- }\r
-\r
- // /////////////////////////////////////////////////////////////////////////////\r
-\r
/* (non-Javadoc)\r
* @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)\r
*/\r
editButton.setEnabled(false);\r
deleteButton.setEnabled(false);\r
exportButton.setEnabled(false);\r
- parseButton.setEnabled(false);\r
}\r
\r
}\r