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.views.filter;
15
import java.io.FileNotFoundException;
16
import java.io.IOException;
18
import javax.xml.parsers.ParserConfigurationException;
20
import org.eclipse.linuxtools.internal.tmf.ui.Activator;
21
import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;
22
import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterRootNode;
23
import org.eclipse.linuxtools.tmf.core.filter.xml.TmfFilterXMLParser;
24
import org.eclipse.linuxtools.tmf.core.filter.xml.TmfFilterXMLWriter;
25
import org.xml.sax.SAXException;
28
* Central filter manager
31
* @author Patrick Tasse
33
public class FilterManager {
35
private static final String SAVED_FILTERS_FILE_NAME = "saved_filters.xml"; //$NON-NLS-1$
36
private static final String SAVED_FILTERS_PATH_NAME =
37
Activator.getDefault().getStateLocation().addTrailingSeparator().append(SAVED_FILTERS_FILE_NAME).toString();
39
private static ITmfFilterTreeNode fRoot = new TmfFilterRootNode();
42
fRoot = new TmfFilterXMLParser(SAVED_FILTERS_PATH_NAME).getTree();
43
} catch (FileNotFoundException e) {
44
} catch (SAXException e) {
45
Activator.getDefault().logError("Error parsing saved filter xml file: " + SAVED_FILTERS_PATH_NAME, e); //$NON-NLS-1$
46
} catch (IOException e) {
47
Activator.getDefault().logError("Error parsing saved filter xml file: " + SAVED_FILTERS_PATH_NAME, e); //$NON-NLS-1$
51
public static ITmfFilterTreeNode[] getSavedFilters() {
52
return fRoot.clone().getChildren();
55
public static void setSavedFilters(ITmfFilterTreeNode[] filters) {
56
fRoot = new TmfFilterRootNode();
57
for (ITmfFilterTreeNode filter : filters) {
58
fRoot.addChild(filter.clone());
61
TmfFilterXMLWriter writerXML = new TmfFilterXMLWriter(fRoot);
62
writerXML.saveTree(SAVED_FILTERS_PATH_NAME);
63
} catch (IOException e) {
64
Activator.getDefault().logError("Error saving filter xml file: " + SAVED_FILTERS_PATH_NAME, e); //$NON-NLS-1$
65
} catch (ParserConfigurationException e) {
66
Activator.getDefault().logError("Error saving filter xml file: " + SAVED_FILTERS_PATH_NAME, e); //$NON-NLS-1$
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.views.filter;
15
import java.io.FileNotFoundException;
16
import java.io.IOException;
18
import javax.xml.parsers.ParserConfigurationException;
20
import org.eclipse.linuxtools.internal.tmf.ui.Activator;
21
import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;
22
import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterRootNode;
23
import org.eclipse.linuxtools.tmf.core.filter.xml.TmfFilterXMLParser;
24
import org.eclipse.linuxtools.tmf.core.filter.xml.TmfFilterXMLWriter;
25
import org.xml.sax.SAXException;
28
* Central filter manager
31
* @author Patrick Tasse
33
public class FilterManager {
35
private static final String SAVED_FILTERS_FILE_NAME = "saved_filters.xml"; //$NON-NLS-1$
36
private static final String SAVED_FILTERS_PATH_NAME =
37
Activator.getDefault().getStateLocation().addTrailingSeparator().append(SAVED_FILTERS_FILE_NAME).toString();
39
private static ITmfFilterTreeNode fRoot = new TmfFilterRootNode();
42
fRoot = new TmfFilterXMLParser(SAVED_FILTERS_PATH_NAME).getTree();
43
} catch (FileNotFoundException e) {
44
} catch (SAXException e) {
45
Activator.getDefault().logError("Error parsing saved filter xml file: " + SAVED_FILTERS_PATH_NAME, e); //$NON-NLS-1$
46
} catch (IOException e) {
47
Activator.getDefault().logError("Error parsing saved filter xml file: " + SAVED_FILTERS_PATH_NAME, e); //$NON-NLS-1$
52
* Retrieve the currently saved filters
54
* @return The array of filters
56
public static ITmfFilterTreeNode[] getSavedFilters() {
57
return fRoot.clone().getChildren();
61
* Set the passed filters as the currently saved ones.
66
public static void setSavedFilters(ITmfFilterTreeNode[] filters) {
67
fRoot = new TmfFilterRootNode();
68
for (ITmfFilterTreeNode filter : filters) {
69
fRoot.addChild(filter.clone());
72
TmfFilterXMLWriter writerXML = new TmfFilterXMLWriter(fRoot);
73
writerXML.saveTree(SAVED_FILTERS_PATH_NAME);
74
} catch (ParserConfigurationException e) {
75
Activator.getDefault().logError("Error saving filter xml file: " + SAVED_FILTERS_PATH_NAME, e); //$NON-NLS-1$