ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / filter / FilterManager.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2012 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.tmf.ui.views.filter;
14
15 import java.io.FileNotFoundException;
16 import java.io.IOException;
17
18 import javax.xml.parsers.ParserConfigurationException;
19
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;
26
27 /**
28 * Central filter manager
29 *
30 * @version 1.0
31 * @author Patrick Tasse
32 */
33 public class FilterManager {
34
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();
38
39 private static ITmfFilterTreeNode fRoot = new TmfFilterRootNode();
40 static {
41 try {
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$
48 }
49 }
50
51 /**
52 * Retrieve the currently saved filters
53 *
54 * @return The array of filters
55 */
56 public static ITmfFilterTreeNode[] getSavedFilters() {
57 return fRoot.clone().getChildren();
58 }
59
60 /**
61 * Set the passed filters as the currently saved ones.
62 *
63 * @param filters
64 * The filters to save
65 */
66 public static void setSavedFilters(ITmfFilterTreeNode[] filters) {
67 fRoot = new TmfFilterRootNode();
68 for (ITmfFilterTreeNode filter : filters) {
69 fRoot.addChild(filter.clone());
70 }
71 try {
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$
76 }
77 }
78 }
This page took 0.035438 seconds and 5 git commands to generate.